Skip to content

Commit

Permalink
## 14.14.0 - 2023-09-22
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Sep 22, 2023
1 parent d22c052 commit 710ffc5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 55 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 14.14.0 - 2023-09-22

### Changed
- Revert `percent` value from `Charts`

## 14.13.0 - 2023-09-21

### Changed
Expand Down
5 changes: 1 addition & 4 deletions src/Metrics/Chartable.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ private function groupByDays(Builder $builder, string $value, $startDate = null,

$days = $startDate->diffInDays($stopDate) + 1;

$sumValues = $query->sum('value');

return TimeCollection::times($days, function () use ($startDate, $query, $sumValues) {
return TimeCollection::times($days, function () use ($startDate, $query) {
$found = $query->firstWhere(
'label',
$startDate->startOfDay()->toDateString()
Expand All @@ -64,7 +62,6 @@ private function groupByDays(Builder $builder, string $value, $startDate = null,
$result = [
'value' => ($found ? $found->value : 0),
'label' => $startDate->toDateString(),
'percent' => ($found ? round($found->value / $sumValues * 100, 2) : 0),
];

$startDate->addDay();
Expand Down
1 change: 0 additions & 1 deletion src/Metrics/TimeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public function toChart(string $name, \Closure $closure = null): array
'name' => $name,
'labels' => $this->pluck('label')->map($closure)->toArray(),
'values' => $this->pluck('value')->toArray(),
'percent' => $this->pluck('percent')->toArray(),
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Platform/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Dashboard
/**
* ORCHID Version.
*/
public const VERSION = '14.13.0';
public const VERSION = '14.14.0';

/**
* @deprecated
Expand Down
49 changes: 0 additions & 49 deletions tests/Unit/MetricsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public function testPeriod(): void
'name' => 'Users',
'labels' => $period->pluck('label')->toArray(),
'values' => $period->pluck('value')->toArray(),
'percent' => $period->pluck('percent')->toArray(),
], $period->toChart('Users'));
}

Expand Down Expand Up @@ -109,7 +108,6 @@ public function testMaxValuesPeriod(): void
'name' => 'Users',
'labels' => $period->pluck('label')->toArray(),
'values' => $period->pluck('value')->toArray(),
'percent' => $period->pluck('percent')->toArray(),
], $period->toChart('Users'));
}

Expand Down Expand Up @@ -140,7 +138,6 @@ public function testMinValuesPeriod(): void
'name' => 'Users',
'labels' => $period->pluck('label')->toArray(),
'values' => $period->pluck('value')->toArray(),
'percent' => $period->pluck('percent')->toArray(),
], $period->toChart('Users'));
}

Expand Down Expand Up @@ -170,7 +167,6 @@ public function testSumPeriod(): void
'name' => 'Users',
'labels' => $period->pluck('label')->toArray(),
'values' => $period->pluck('value')->toArray(),
'percent' => $period->pluck('percent')->toArray(),
], $period->toChart('Users'));
}

Expand Down Expand Up @@ -200,7 +196,6 @@ public function testAvgPeriod(): void
'name' => 'Users',
'labels' => $period->pluck('label')->toArray(),
'values' => $period->pluck('value')->toArray(),
'percent' => $period->pluck('percent')->toArray(),
], $period->toChart('Users'));
}

Expand Down Expand Up @@ -265,50 +260,6 @@ public function testPeriodWithoutZero(): void
'name' => 'Users',
'labels' => $period->pluck('label')->toArray(),
'values' => $period->pluck('value')->toArray(),
'percent' => $period->pluck('percent')->toArray(),
], $period->toChart('Users'));
}

public function testPercentValues(): void
{
$current = Carbon::now();
$start = (clone $current)->subDays(2);
$end = (clone $current)->subDay();

User::factory()->count(1)->create([
'created_at' => $start,
]);

User::factory()->count(2)->create([
'created_at' => $end,
]);

$period = User::countByDays($start);

$expected = [
[
'value' => 1,
'label' => $start->toDateString(),
'percent' => 33.33,
],
[
'value' => 2,
'label' => $end->toDateString(),
'percent' => 66.67,
],
[
'value' => 0,
'label' => $end->copy()->addDay()->toDateString(),
'percent' => 0,
],
];

$actual = $period->all();

$this->assertEquals($expected, $actual);

$user = $period->toChart('Users');

$this->assertSame([33.33, 66.67, 0], $user['percent']);
}
}

0 comments on commit 710ffc5

Please sign in to comment.