Skip to content

Commit

Permalink
improved 4o breathing app
Browse files Browse the repository at this point in the history
  • Loading branch information
ToonTalk committed Aug 30, 2024
1 parent 2907e93 commit 754ef45
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions apps/breathing/4o/script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

let isMonitoring = false;
let breathCount = 0;
let lastBreathTime = Date.now();
Expand All @@ -22,12 +21,15 @@ function stopMonitoring() {

function detectBreathing(event) {
const acceleration = event.acceleration.y; // Assuming the phone is vertical in the pocket
const threshold = 0.5; // Adjust this value based on testing
const threshold = 1.0; // Increased threshold to reduce false positives
const minTimeBetweenBreaths = 2000; // Minimum time in milliseconds between breaths (e.g., 2 seconds)

const currentTime = Date.now();
const timeDiff = currentTime - lastBreathTime;

if (Math.abs(acceleration) > threshold) {
const currentTime = Date.now();
const timeDiff = (currentTime - lastBreathTime) / 1000 / 60; // time difference in minutes
breathRates.push(1 / timeDiff);
if (Math.abs(acceleration) > threshold && timeDiff > minTimeBetweenBreaths) {
const timeDiffMinutes = timeDiff / 1000 / 60; // Convert time difference to minutes
breathRates.push(1 / timeDiffMinutes);
breathCount++;
lastBreathTime = currentTime;
calculateBreathingRate();
Expand Down

0 comments on commit 754ef45

Please sign in to comment.