2017-09-29 13:45:44 +00:00
|
|
|
% layout 'admin';
|
2017-09-29 14:52:34 +00:00
|
|
|
% title 'Transaction Report';
|
2017-09-29 13:45:44 +00:00
|
|
|
% content_for javascript => begin
|
|
|
|
<script src="//www.gstatic.com/charts/loader.js"></script>
|
|
|
|
<script>
|
|
|
|
var raw_data = <%== $transaction_rs %>;
|
|
|
|
var mapped_data = $.map(raw_data, function( val, i ) {
|
2017-09-29 14:52:34 +00:00
|
|
|
return [
|
|
|
|
[
|
2017-09-29 15:04:41 +00:00
|
|
|
new Date(val.quantised),
|
2017-09-29 14:52:34 +00:00
|
|
|
val.count,
|
|
|
|
val.average_value / 100000,
|
|
|
|
val.sum_value / 100000,
|
|
|
|
val.average_distance / 1000,
|
|
|
|
val.sum_distance / 1000,
|
|
|
|
]
|
|
|
|
];
|
2017-09-29 13:45:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
google.charts.load('current', {packages: ['corechart']});
|
|
|
|
google.charts.setOnLoadCallback(loadData);
|
|
|
|
|
|
|
|
function loadData() {
|
2017-09-29 14:52:34 +00:00
|
|
|
var data = new google.visualization.DataTable();
|
2017-09-29 13:45:44 +00:00
|
|
|
data.addColumn('datetime', 'Hours');
|
|
|
|
data.addColumn('number', 'Count');
|
|
|
|
data.addColumn('number', 'Average Value');
|
|
|
|
data.addColumn('number', 'Sum Value');
|
|
|
|
data.addColumn('number', 'Average Distance');
|
|
|
|
data.addColumn('number', 'Sum Distance');
|
|
|
|
|
|
|
|
data.addRows(mapped_data);
|
|
|
|
|
2017-09-29 14:52:34 +00:00
|
|
|
drawCountChart(data);
|
|
|
|
drawDistanceChart(data);
|
|
|
|
drawValueChart(data);
|
2017-09-29 13:45:44 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 14:52:34 +00:00
|
|
|
function drawCountChart(data) {
|
2017-09-29 13:45:44 +00:00
|
|
|
var options = {
|
|
|
|
title: 'Transaction Count',
|
|
|
|
height: 500,
|
|
|
|
series: {
|
|
|
|
0: {targetAxisIndex: 0},
|
|
|
|
},
|
|
|
|
vAxes: {
|
|
|
|
0: { title: 'Count' },
|
|
|
|
},
|
|
|
|
explorer: { axis: 'horizontal' }
|
|
|
|
};
|
|
|
|
|
|
|
|
var chart_data = new google.visualization.DataView(data);
|
|
|
|
chart_data.setColumns([0, 1]);
|
|
|
|
|
|
|
|
var chart = new google.visualization.LineChart(document.getElementById('count_chart_div'));
|
|
|
|
chart.draw(chart_data, options);
|
|
|
|
}
|
|
|
|
|
2017-09-29 14:52:34 +00:00
|
|
|
function drawDistanceChart(data) {
|
2017-09-29 13:45:44 +00:00
|
|
|
var options = {
|
|
|
|
title: 'Transaction Distance',
|
|
|
|
height: 500,
|
|
|
|
series: {
|
|
|
|
0: {targetAxisIndex: 0},
|
|
|
|
1: {targetAxisIndex: 0},
|
|
|
|
},
|
|
|
|
vAxes: {
|
|
|
|
0: { title: 'Distance (km)' },
|
|
|
|
},
|
|
|
|
explorer: { axis: 'horizontal' }
|
|
|
|
};
|
|
|
|
|
|
|
|
var chart_data = new google.visualization.DataView(data);
|
|
|
|
chart_data.setColumns([0, 4, 5]);
|
|
|
|
|
|
|
|
var chart = new google.visualization.LineChart(document.getElementById('distance_chart_div'));
|
|
|
|
chart.draw(chart_data, options);
|
|
|
|
}
|
|
|
|
|
2017-09-29 14:52:34 +00:00
|
|
|
function drawValueChart(data) {
|
2017-09-29 13:45:44 +00:00
|
|
|
var options = {
|
|
|
|
title: 'Transaction Value',
|
|
|
|
height: 500,
|
|
|
|
series: {
|
|
|
|
0: {targetAxisIndex: 0},
|
|
|
|
1: {targetAxisIndex: 0},
|
|
|
|
},
|
|
|
|
vAxes: {
|
|
|
|
0: { title: 'Value (GBP)' },
|
|
|
|
},
|
|
|
|
explorer: { axis: 'horizontal' }
|
|
|
|
};
|
|
|
|
|
|
|
|
var chart_data = new google.visualization.DataView(data);
|
|
|
|
chart_data.setColumns([0, 2, 3]);
|
|
|
|
|
|
|
|
var chart = new google.visualization.LineChart(document.getElementById('value_chart_div'));
|
|
|
|
chart.draw(chart_data, options);
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
% end
|
|
|
|
% if ( my $error = flash 'error' ) {
|
|
|
|
<div class="alert alert-danger" role="alert">
|
|
|
|
<strong>Error!</strong> <%= $error %>
|
|
|
|
</div>
|
|
|
|
% } elsif ( my $success = flash 'success' ) {
|
|
|
|
<div class="alert alert-success" role="alert">
|
|
|
|
<strong>Success!</strong> <%= $success %>
|
|
|
|
</div>
|
|
|
|
% }
|
2017-09-29 14:52:34 +00:00
|
|
|
<div class="card mb-3 text-center">
|
|
|
|
<div class="card-header">
|
|
|
|
Transaction Count
|
|
|
|
</div>
|
|
|
|
<div id="count_chart_div" class="card-body">
|
|
|
|
<div class="card-text">
|
|
|
|
<em>Loading...</em>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="card mb-3 text-center">
|
|
|
|
<div class="card-header">
|
|
|
|
Transaction Distance
|
|
|
|
</div>
|
|
|
|
<div id="distance_chart_div" class="card-body">
|
|
|
|
<div class="card-text">
|
|
|
|
<em>Loading...</em>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="card mb-3 text-center">
|
|
|
|
<div class="card-header">
|
|
|
|
Transaction Value
|
|
|
|
</div>
|
|
|
|
<div id="value_chart_div" class="card-body">
|
|
|
|
<div class="card-text">
|
|
|
|
<em>Loading...</em>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|