Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Larsklopstra committed Oct 7, 2021
1 parent 921292b commit 6fda6e4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Trend.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,22 @@ public function count(string $column = '*'): Collection

public function mapValuesToDates(Collection $values): Collection
{
return $this->getDatePeriod()
->flatMap(fn (Carbon $date) => [$date->format($this->getCarbonDateFormat()) => 0])
->merge($values->flatMap(fn ($value) => [$value->date => $value->aggregate]))
->sortKeys();
$values = $values->map(fn ($value) => new TrendValue(
date: $value->date,
aggregate: $value->aggregate,
));

$placeholders = $this->getDatePeriod()->map(
fn (Carbon $date) => new TrendValue(
date: $date->format($this->getCarbonDateFormat()),
aggregate: 0,
)
);

return $values
->merge($placeholders)
->unique('date')
->flatten();
}

protected function getDatePeriod(): Collection
Expand Down
12 changes: 12 additions & 0 deletions src/TrendValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Flowframe\Trend;

class TrendValue
{
public function __construct(
public string $date,
public mixed $aggregate,
) {
}
}

0 comments on commit 6fda6e4

Please sign in to comment.