weekly streak calculation logic error
1 parent 9cbec6d commit 8fa042d847c35209defc901f536932e38932fa4c
0xRoM authored on 9 Jan 2024
Showing 1 changed file
View
28
habit.php
}
}
 
$streak = 0;
$thisWeek = date('Y-W'); // Get the current week
 
while (isset($weeklyOccurrences[$thisWeek]) && $weeklyOccurrences[$thisWeek] >= $multiplier) {
$streak++;
$thisWeek = date('Y-W', strtotime($thisWeek . ' -1 week'));
}
$consecutiveCount = 0;
$maxConsecutiveCount = 0;
 
ksort($weeklyOccurrences);
 
foreach ($weeklyOccurrences as $week => $value) {
if ($value >= 2) {
$consecutiveCount++;
$maxConsecutiveCount = max($maxConsecutiveCount, $consecutiveCount);
} else {
$consecutiveCount = 0; // Reset count if the value is less than 2
}
}
 
//print_r($dateOccurrences);
//print_r($weeklyOccurrences);
 
return $streak;
return $consecutiveCount;
}
 
function habit_get_stat_missed($word, $filename) {
// Split the file content into an array of lines
Buy Me A Coffee