Skip to content

Commit 1b4d4d0

Browse files
Julien NahumJulien Nahum
Julien Nahum
authored and
Julien Nahum
committed
Fix bug in modelstats logic
1 parent 1cad636 commit 1b4d4d0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Services/ModelStats.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getDailyHistogram(
4343

4444
$cumulatedSum = null;
4545
if ($cumulated) {
46-
$cumulatedSum = $this->class::where($dateFieldName, '>=', $from->copy()->startOfDay())->count();
46+
$cumulatedSum = $this->class::where($dateFieldName, '<=', $from->copy()->startOfDay())->count();
4747
}
4848

4949
return self::fillMissingDays($data, $from, $to, 0, $cumulatedSum);
@@ -81,12 +81,12 @@ public static function fillMissingDays($data, Carbon $since, Carbon $to, $defaul
8181
$daysSince = $since->diffInDays($to);
8282

8383
foreach (array_reverse(range(0, $daysSince)) as $number) {
84-
$dateKey = Carbon::now()->subDays($number)->format('Y-m-d');
84+
$dateKey = $to->copy()->subDays($number)->format('Y-m-d');
8585
if (! isset($data[$dateKey])) {
8686
$data[$dateKey] = $defaultValue;
8787
}
8888

89-
if ($cumulatedSum != null) {
89+
if (! is_null($cumulatedSum) ) {
9090
$data[$dateKey] += $cumulatedSum;
9191
$cumulatedSum = $data[$dateKey];
9292
}

0 commit comments

Comments
 (0)