Skip to content

Commit 5ba3cbc

Browse files
committed
🔧 Provide mapping to graph interval
1 parent 5bdd495 commit 5ba3cbc

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

‎src/Enums/Period.php‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ public function maxDataPoints(): int
7171
};
7272
}
7373

74+
/**
75+
* Function period.
76+
*/
77+
public function graphPeriod(): ?Period
78+
{
79+
return match ($this) {
80+
self::HOUR => null,
81+
self::SIXHOUR => self::HOUR,
82+
self::HALFDAY => self::HOUR,
83+
self::DAY => self::HOUR,
84+
self::WEEK => self::DAY,
85+
self::MONTH => self::DAY,
86+
self::QUARTER => self::DAY,
87+
self::HALFYEAR => self::MONTH,
88+
self::YEAR => self::MONTH,
89+
self::TAXYEAR => self::MONTH,
90+
};
91+
}
92+
7493
/**
7594
* Function period.
7695
*/

‎src/Storage/DatabaseStorage.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public function graph(array $types, string $aggregate, Period $interval): Collec
451451
throw new InvalidArgumentException("Invalid aggregate type [$aggregate], allowed types: [".implode(', ', $allowed).'].');
452452
}
453453

454-
$period = $interval->value;
454+
$period = $interval;
455455
$buckets = $interval->getBuckets();
456456
$padding = collect()
457457
->range(0, $interval->maxDataPoints() - 1)
@@ -463,7 +463,7 @@ public function graph(array $types, string $aggregate, Period $interval): Collec
463463
->select(['bucket', 'type', 'key', 'value'])
464464
->whereIn('type', $types)
465465
->where('aggregate', $aggregate)
466-
->where('period', $period - 1)
466+
->where('period', $period->graphPeriod()?->value)
467467
->where('bucket', '>=', $buckets[0]->getTimestamp())
468468
->orderBy('bucket')
469469
->get()

0 commit comments

Comments
 (0)