Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/Admin/StatsController.php
Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | protected function chartIncome(): array | ||||
// TODO: exclude refunds/chargebacks | // TODO: exclude refunds/chargebacks | ||||
$empty = array_fill_keys($labels, 0); | $empty = array_fill_keys($labels, 0); | ||||
$payments = array_values(array_merge($empty, $payments->all())); | $payments = array_values(array_merge($empty, $payments->all())); | ||||
// $payments = [1000, 1200.25, 3000, 1897.50, 2000, 1900, 2134, 3330]; | // $payments = [1000, 1200.25, 3000, 1897.50, 2000, 1900, 2134, 3330]; | ||||
$avg = collect($payments)->avg(); | $avg = collect($payments)->slice(0, count($labels) - 1)->avg(); | ||||
// See https://frappe.io/charts/docs for format/options description | // See https://frappe.io/charts/docs for format/options description | ||||
return [ | return [ | ||||
'title' => 'Income in CHF - last 8 weeks', | 'title' => 'Income in CHF - last 8 weeks', | ||||
'type' => 'bar', | 'type' => 'bar', | ||||
'colors' => [self::COLOR_BLUE], | 'colors' => [self::COLOR_BLUE], | ||||
'axisOptions' => [ | 'axisOptions' => [ | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | protected function chartUsers(): array | ||||
$empty = array_fill_keys($labels, 0); | $empty = array_fill_keys($labels, 0); | ||||
$created = array_values(array_merge($empty, $created->pluck('cnt', 'period')->all())); | $created = array_values(array_merge($empty, $created->pluck('cnt', 'period')->all())); | ||||
$deleted = array_values(array_merge($empty, $deleted->pluck('cnt', 'period')->all())); | $deleted = array_values(array_merge($empty, $deleted->pluck('cnt', 'period')->all())); | ||||
// $created = [5, 2, 4, 2, 0, 5, 2, 4]; | // $created = [5, 2, 4, 2, 0, 5, 2, 4]; | ||||
// $deleted = [1, 2, 3, 1, 2, 1, 2, 3]; | // $deleted = [1, 2, 3, 1, 2, 1, 2, 3]; | ||||
$avg = collect($created)->avg(); | $avg = collect($created)->slice(0, count($labels) - 1)->avg(); | ||||
// See https://frappe.io/charts/docs for format/options description | // See https://frappe.io/charts/docs for format/options description | ||||
return [ | return [ | ||||
'title' => 'Users - last 8 weeks', | 'title' => 'Users - last 8 weeks', | ||||
// 'type' => 'axis-mixed', | // 'type' => 'axis-mixed', | ||||
'colors' => [self::COLOR_GREEN, self::COLOR_RED], | 'colors' => [self::COLOR_GREEN, self::COLOR_RED], | ||||
'axisOptions' => [ | 'axisOptions' => [ | ||||
▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines |