Skip to content

Commit

Permalink
Issue #1 Show both total counts and constituency counts on chart1.
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed Mar 23, 2019
1 parent 2722722 commit 6c620e5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
32 changes: 25 additions & 7 deletions app/Http/Controllers/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,42 @@ public function simpleOverview($petitionNumber = null)
$chart1data = $chartData->get('chart1');

// The time is formatted without seconds and rounded to
// the nearest five minutes.
// the nearest five minutes, just to make it easier to read.

$chart1->labels($chart1data->get('labels'));

// Total counts dataset.

$chart1->dataset(
$chart1data->get('action'),
$chart1data->get('type'),
$chart1data->get('dataset')
);
)->options([
'color' => ['#66aa33'],
'backgroundColor' => 'rgba(255, 180, 20, 0.2)',
]);

// Constituency counts dataset.

if ($chart1data->get('dataset2')) {
$chart1->dataset(
'UK Constituency Signature Count',
'line',
$chart1data->get('dataset2')
)->options([
'color' => ['#6633ff'],
'backgroundColor' => 'rgba(255, 20, 132, 0.2)',
]);
}

$chart1->options([
'scales' => [
'yAxes' => [
'ticks' => ['beginAtZero' => false],
]
],
'color' => ['#66aa66'],
'backgroundColor' => ['#bbffbb'],
//'color' => ['#66aa66'],
//'backgroundColor' => ['#bbffbb'],
]);

$chart2 = new SimpleOverview;
Expand All @@ -59,8 +77,8 @@ public function simpleOverview($petitionNumber = null)
$chart2data->get('type'),
$chart2data->get('dataset')
)->options([
'color' => ['#aa6666'],
'backgroundColor' => ['#ffbbbb'],
'color' => '#aa6666',
'backgroundColor' => '#ffbbbb',
]);
}
} else {
Expand All @@ -86,7 +104,7 @@ public function simpleOverview($petitionNumber = null)
'chart1' => $chart1 ?? null,
'chart2' => $chart2 ?? null,
'petitionList' => $petitionList,
'petition' => $petition ?? null,
'petition' => $petition,
'petitionData' => $petition ? $petition->getPetitionData() : null,
'totalCount' => $totalCount,
'constituencyCount' => $constituencyCount,
Expand Down
12 changes: 10 additions & 2 deletions app/Petition.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public function getJobFetchCount(Carbon $fromTime = null, Carbon $toTime = null)
return $query->count('count_time');
}

/**
* @return collect|null Collection of App\FetchJob
*/
public function getJobFetchRange(
Carbon $fromTime = null,
Carbon $toTime = null,
Expand Down Expand Up @@ -166,14 +169,16 @@ public function getJobFetchRange(

return $this
->fetchJobs()
//->with('constituencySignatures')
->whereNotNull('count')
->where('count_time', '>=', $fromTime)
->where('count_time', '<=', $toTime)
->select([
DB::raw('date_format(count_time, "'.$groupPattern.'") as count_time_group'),
DB::raw('max(count) as count'),
DB::raw('max(id) as id'),
])
->groupBy('count_time_group')
->groupBy(['count_time_group'])
->orderBy('count_time_group')
->get()
->each(function ($item) {
Expand All @@ -186,7 +191,7 @@ public function getJobFetchRange(
->whereNotNull('count')
->where('count_time', '>=', $fromTime)
->where('count_time', '<=', $toTime)
->select(['count_time', 'count'])
->select(['count_time', 'count', 'id'])
->orderBy('count_time')
->get();
}
Expand Down Expand Up @@ -230,6 +235,9 @@ public function getChartData(bool $withCache = true)
'type' => 'line',
'labels' => $allOverviewCounts->pluck(['count_time_five_minute']),
'dataset' => $allOverviewCounts->pluck(['count']),
'dataset2' => $allOverviewCounts->map(function ($item) {
return $item->constituencySignatures()->sum('count');
}),
]);

// Now calculate the derivative (chart2).
Expand Down
Binary file modified public/favicon.ico
Binary file not shown.

0 comments on commit 6c620e5

Please sign in to comment.