fixed the last of the logic errors! well one can dream
1 parent f68da0a commit f631f5ee9bfc82b2785fcc45080c1eb45e76be9d
0xRoM authored on 15 Jan 2024
Showing 2 changed files
View
52
habit.php
// Output the line whether the word is found or not
//echo ($wordFound) ? "+ found: $line\n" : $line . "\n";
}
 
$weekPrevStart = new DateTime($firstOccurrenceDate);
// Add one week to the date
$weekPrevStart->modify('-1 week');
// Format and print the new date
$weekPrevStart2 = $weekPrevStart->format('Y-m-d');
 
foreach ($dateOccurrences as $date => $count) {
// Convert each date to the format $year-$weekNo
$dateTime = new DateTime($date);
$yearWeek = $dateTime->format('Y-m-W');
}else{
$weeklyOccurrences[$yearWeek] = 0;
}
}
if($date < $firstOccurrenceDate)
if(strtotime($date) < strtotime($weekPrevStart2))
$weeklyOccurrences[$yearWeek] = "x";
}
 
// Remove entries with a value of 0
//$weeklyOccurrences = array_filter($weeklyOccurrences, function ($value) {
// return $value !== 0;
//});
//print_r($dateOccurrences);
//print_r($weeklyOccurrences);
 
// Convert keys to timestamps and print in a simple JSON format with surrounding {}
$i = 0;
$fileContent = file_get_contents($filename);
$lines = explode("\n", $fileContent);
$dateOccurrences = [];
$weeklyOccurrences = [];
$first = "";
 
foreach ($lines as $line) {
// Extract the date from the line
preg_match('/(\b\d{4}-\d{2}-\d{2}\b)/', $line, $matches);
foreach ($words as $wordInLine) {
// Check if the word contains "#takeout" (case-insensitive)
if (stripos($wordInLine, "#$word") !== false) {
$wordFound = true;
$first = $date; // $first will end up containging first instance of word
break;
}
}
 
$weeklyOccurrences[$yearWeek] = 1;
}
}
 
$today = new DateTime();
$currentDate = date('Y-m-d');
 
while (strtotime($first) <= strtotime($currentDate)) {
$dateTime = new DateTime($currentDate);
$yearWeekKey = $dateTime->format('Y-W');
$weeklyOccurrences[$yearWeekKey] = 0;
//echo $yearWeekKey;
$currentDate = date('Y-m-d', strtotime($currentDate . ' -1 day'));
}
 
 
$consecutiveCount = 0;
$maxConsecutiveCount = 0;
 
ksort($weeklyOccurrences);
//ksort($weeklyOccurrences);
 
foreach ($weeklyOccurrences as $week => $value) {
if ($value >= $multiplier) {
$consecutiveCount++;
$fileContent = file_get_contents($filename);
$lines = explode("\n", $fileContent);
$dateOccurrences = [];
$weeklyOccurrences = [];
$first = "";
 
foreach ($lines as $line) {
// Extract the date from the line
preg_match('/(\b\d{4}-\d{2}-\d{2}\b)/', $line, $matches);
foreach ($words as $wordInLine) {
// Check if the word contains "#takeout" (case-insensitive)
if (stripos($wordInLine, "#$word") !== false) {
$wordFound = true;
$first = $date;
break;
}
}
 
 
// Output the line whether the word is found or not
//echo ($wordFound) ? "+ found: $line\n" : $line . "\n";
}
 
$currentDate = date('Y-m-d');
while (strtotime($first) <= strtotime($currentDate)) {
$dateTime = new DateTime($currentDate);
$yearWeekKey = $dateTime->format('Y-W');
$weeklyOccurrences[$yearWeekKey] = 0;
//echo $yearWeekKey;
$currentDate = date('Y-m-d', strtotime($currentDate . ' -1 day'));
}
 
foreach ($dateOccurrences as $date => $count) {
// Convert each date to the format $year-$weekNo
$dateTime = new DateTime($date);
$jsonArray['buttonClass'] = 'button-good';
$jsonArray['buttonText'] = "";
}
}
if($weekCount == 0)
$jsonArray['buttonClass'] = '';
break;
}
}
 
if ($weekCount >= $multiplier) {
$jsonArray['buttonClass'] = 'button-good';
}
}
if($weekCount == 0)
$jsonArray['buttonClass'] = '';
 
$last10 = habit_last_10_weekly($section['Activity'], $moodlog);
foreach ($last10 as $key => $value) {
$jsonArray[$key] = "neut";
View
10
habit_ui.php
 
if ($weekCount >= $multiplier) {
$buttonClass = 'button-good';
}
}
}
if($weekCount == 0){
$buttonClass = '';
$buttText = "";
}
 
}
Buy Me A Coffee