Files
FloatBackOfffice/application/views/report/view_surge_pricing_varaition.php
dev-chiefworks f76abffdcd first commit
2022-05-31 16:21:53 -04:00

550 lines
22 KiB
PHP

<link rel="stylesheet" type="text/css" href="/assets/css/reports/surge_pricing_varaition.css">
<div id="page">
<div id="loader">
Loading data
<div id="progress" class="progress-wrap progress"
data-progresspercent="0"
data-height="10px"
data-width="150px"
data-speed="1500"
data-color="3a9c23">
<div class="progress-bar progress"></div>
</div>
</div>
<div id="dfilter" style="display:none">
<form method="get" action="?">
<select name="t">
<?php foreach ($providers as $key=>$val) { ?>
<option value="<?php echo$key?>"<?php echo $key==$t ? ' selected' : '' ?>><?php echo$val?></option>
<?php } ?>
</select>
<select name="area1">
<?php foreach ($areas as $key=>$val) { ?>
<option value="<?php echo$key?>"<?php echo $key == $area1 ? ' selected' : '' ?>><?php echo$val?></option>
<?php } ?>
</select>
<select name="area2">
<?php foreach ($areas as $key=>$val) { ?>
<option value="<?php echo$key?>"<?php echo $key == $area2 ? ' selected' : '' ?>><?php echo$val?></option>
<?php } ?>
</select>
<input type="text" id="date1" class="date-picker" name="date1" value="<?php echo $date1 ?>" />
<input type="text" id="date2" class="date-picker" name="date2" value="<?php echo $date2 ?>" />
<input type="submit" value="filter"/>
</form>
<br/>
</div>
<div id="tabs" class="tv-tabs" style="display:none">
<label class="tv-tab" for="tv-tab-1"><?php echo $providers[$t] ?>: <?php echo $label1 ?></label>
<label class="tv-tab" for="tv-tab-2"><?php echo $providers[$t] ?>: <?php echo $label2 ?></label>
<label class="tv-tab" for="tv-tab-5">Map</label>
<label class="tv-tab" for="tv-tab-3">Comparison</label>
<label class="tv-tab" for="tv-tab-4">Data</label>
</div>
<input class="tv-radio" id="tv-tab-1" name="tv-group" type="radio" checked="checked"/>
<div class="tv-content">
<div style="max-width: 950px">
<canvas id="canvas1"></canvas>
</div>
</div>
</div>
<input class="tv-radio" id="tv-tab-2" name="tv-group" type="radio"/>
<div class="tv-content">
<div style="max-width: 950px">
<canvas id="canvas2"></canvas>
</div>
</div>
<input class="tv-radio" id="tv-tab-5" name="tv-group" type="radio"/>
<div class="tv-content">
<div id="map"></div>
</div>
<input class="tv-radio" id="tv-tab-3" name="tv-group" type="radio"/>
<div class="tv-content">
<div style="width:75%;color:#000000!important;">
<div id="dataRes1"></div>
<br/>
<div id="dataRes2"></div>
<br/>
<div style="max-width: 950px">
<canvas id="canvas3"></canvas>
</div>
<table style="margin-top: 50px">
<col>
<col>
<col>
<col>
<col>
<col>
<tr>
<th>NN</th>
<th>Travel Date</th>
<th>Time</th>
<th>Cost</th>
<th>Trend</th>
<th>Delta</th>
<th>Variation</th>
</tr>
<?php $j=1; $dMax = 0; $dMin = 0; $tVar = []; $tVar0 = []; foreach ($data1 as $i=>$f) { $d = variation($data1,$i,$f,$pub1, $dMin, $dMax, $tVar, $tVar0); ?>
<tr>
<td><?php echo $j++ ?></td>
<td><?php echo strtok($f['travel_date'],'+') ?></td>
<td><?php echo $f['time'] ?></td>
<td><?php echo sprintf("%0.02f", $f['cost']) ?></td>
<td><?php echo sprintf("%0.02f", $d[0]) ?></td>
<td><?php echo sprintf("%0.02f", $d[1]) ?></td>
<td><?php echo sprintf("%0.02f", $d[2]) ?></td>
</tr>
<?php } ?>
<tr>
<td colspan="7">
<div id="dataSrc1"><?php echo $label1.": ".sprintf("%0.02f",$dMin).' / '.sprintf("%0.02f",$dMax).' ~ '.stats_variance($tVar) ?></div>
</td>
</tr>
<?php $tVar1 = $tVar0; $dMax = 0; $dMin = 0; $tVar = []; $tVar0 = []; foreach ($data2 as $i=>$f) { $d = variation($data1,$i,$f,$pub2, $dMin, $dMax, $tVar, $tVar0); ?>
<tr>
<td><?php echo $j++ ?></td>
<td><?php echo strtok($f['travel_date'],'+') ?></td>
<td><?php echo $f['time'] ?></td>
<td><?php echo sprintf("%0.02f", $f['cost']) ?></td>
<td><?php echo sprintf("%0.02f", $d[0]) ?></td>
<td><?php echo sprintf("%0.02f", $d[1]) ?></td>
<td><?php echo sprintf("%0.02f", $d[2]) ?></td>
</tr>
<?php } ?>
<?php $tVar2 = $tVar0; ?>
<tr>
<td colspan="7">
<div id="dataSrc2"><?php echo $label2.": ".sprintf("%0.02f",$dMin).' / '.sprintf("%0.02f",$dMax).' ~ '.stats_variance($tVar) ?></div>
</td>
</tr>
</table>
</div>
</div>
<input class="tv-radio" id="tv-tab-4" name="tv-group" type="radio"/>
<div class="tv-content">
<table>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<tr>
<th>NN</th>
<th>Travel Date</th>
<th>Cost</th>
<th>GPS</th>
<th>Origin</th>
<th>GPS</th>
<th>Destination</th>
</tr>
<?php
$i = 1;
foreach ($data as $f) { ?>
<tr>
<td><?php echo $i ?></td>
<td><?php echo strtok($f['travel_date'],'+') ?></td>
<td><?php echo sprintf("%0.02f", $f['cost']) ?></td>
<td><?php echo $f['location_start_lat'].','.$f['location_end_lng']?></td>
<td><?php echo $f['origin'] ?></td>
<td><?php echo $f['location_end_lat'].','.$f['location_end_lng']?></td>
<td><?php echo $f['destination'] ?></td>
</tr>
<?php
$i++;
}
?>
</table>
</div>
<script src="/assets/js/plugins/pickers/datepicker.js"></script>
<script src="/assets/js/app.js" type="text/javascript"></script>
<script src="/assets/js/charts/chartjs/luxon.min.js"></script>
<script src="/assets/js/charts/chartjs/Chart.min.js"></script>
<script src="/assets/js/charts/chartjs/chartjs-adapter-luxon.js"></script>
<script src="/assets/js/charts/chartjs/chartjs-chart-financial.js" type="text/javascript"></script>
<script src="/assets/js/pages/reports/surge_pricing_varaition/utils.js"></script>
<script>
addDatePicker('.date-picker');
document.getElementById('dataRes1').innerHTML = document.getElementById('dataSrc1').innerHTML;
document.getElementById('dataRes2').innerHTML = document.getElementById('dataSrc2').innerHTML;
function updateProgress() {
var progress = $("#progress");
var getPercent = progress.attr("data-progresspercent");
var getSpeed = parseInt(progress.attr("data-speed"));
var getColor = progress.attr("data-color");
var getHeight = progress.attr("data-height");
var getWidth = progress.attr("data-width");
progress.css({"height":getHeight,"width":getWidth});
progress.find(".progress-bar").css({"background-color":"#"+getColor}).animate({ width:getPercent+'%' },getSpeed);
if (getPercent<100) setTimeout(updateProgress,500);
}
updateProgress();
var color = Chart.helpers.color;
var dataSets1 = [];
var dataSetTrends1 = [];
var dataSets2 = [];
var dataSetTrends2 = [];
var dataSets3 = [];
var dataSetTrends3 = [];
// Rideshare only
dataSets1[0] = []; dataSetTrends1[0] = [];
dataSets2[0] = []; dataSetTrends2[0] = [];
$("#progress").attr("data-progresspercent",25);
// Public transit and walking
dataSets1[1] = []; dataSetTrends1[1] = [];
<?php foreach ($pub2 as $f) { ?> dataSets1[1].push({x: <?php echo $f[0]; ?>000, y: <?php echo $f[1]; ?>});
dataSetTrends1[1].push({x: <?php echo $f[0]; ?>000, y: <?php echo $f[2]; ?>});
<?php } ?>
$("#progress").attr("data-progresspercent",27);
dataSets2[1] = []; dataSetTrends2[1] = [];
<?php foreach ($pub1 as $f) { ?> dataSets2[1].push({x: <?php echo $f[0]; ?>000, y: <?php echo $f[1]; ?>});
dataSetTrends2[1].push({x: <?php echo $f[0]; ?>000, y: <?php echo $f[2]; ?>});
<?php } ?>
dataSets3[0] = []; dataSetTrends3[0] = [];
<?php $tVar1a = []; foreach ($tVar1 as $k=>$v) { ?> dataSets3[0].push({x: <?php echo $k; ?>000, y: <?php echo $v; ?>});
<?php /* $tVar1a[] = $v;*/ } ?>
//dataSetTrends3[0] = [<?php echo implode(',',$tVar1a); ?>];
dataSets3[1] = []; dataSetTrends3[1] = [];
<?php $tVar2a = []; foreach ($tVar2 as $k=>$v) { ?> dataSets3[1].push({x: <?php echo $k; ?>000, y: <?php echo $v; ?>});
<?php /* $tVar2a[] = $v;*/ } ?>
//dataSetTrends3[1] = [<?php echo implode(',',$tVar2a); ?>];
$("#progress").attr("data-progresspercent",30);
// Public transit, walking and scooter
dataSets1[2] = []; dataSetTrends1[2] = [];
dataSets2[2] = []; dataSetTrends2[2] = [];
$("#progress").attr("data-progresspercent",35);
// Public transit, walking and bicycle
dataSets1[3] = []; dataSetTrends1[3] = [];
dataSets2[3] = []; dataSetTrends2[3] = [];
$("#progress").attr("data-progresspercent",40);
// Driving your own car
dataSets1[4] = []; dataSetTrends1[4] = [];
<?php if (isset($taxi)): ?>
<?php foreach ($taxi as $f) { if (!isset($f[2])) continue; ?> dataSets1[4].push({
x: <?php echo $f[0]; ?>,
y: <?php echo $f[1]; ?>});
dataSetTrends1[4].push({
x: <?php echo $f[0]; ?>,
y: <?php echo $f[2]; ?>});
<?php } ?>
<?php endif; ?>
$("#progress").attr("data-progresspercent",43);
dataSets2[4] = []; dataSetTrends2[4] = [];
<?php if (isset($taxi0)): ?>
<?php foreach ($taxi0 as $f) { if (!isset($f[2])) continue; ?> dataSets2[4].push({
x: <?php echo $f[0]; ?>,
y: <?php echo $f[1]; ?>});
dataSetTrends2[4].push({
x: <?php echo $f[0]; ?>,
y: <?php echo $f[2]; ?>});
<?php } ?>
<?php endif; ?>
$("#progress").attr("data-progresspercent",45);
// Car share (like Zipcar or BlueSG) and public transit, walking
dataSets1[5] = []; dataSetTrends1[5] = [];
dataSets2[5] = []; dataSetTrends2[5] = [];
$("#progress").attr("data-progresspercent",50);
var scatterChartData1 = {
datasets: [/*{
label: 'Rideshare only',
borderColor: window.chartColors.blue,
backgroundColor: color(window.chartColors.blue).alpha(0.2).rgbString(),
data: dataSets1[0]
},*/{
label: '<?php echo $providers[$t] ?>',
borderColor: window.chartColors.green,
backgroundColor: color(window.chartColors.green).alpha(0.2).rgbString(),
data: dataSets1[1]
}, {
label: '<?php echo $providers[$t] ?> trend line',
pointBorderColor: window.chartColors.black,
pointBackgroundColor: color(window.chartColors.black).alpha(0.2).rgbString(),
data: dataSetTrends1[1],
showLine: true,
borderWidth: 1,
fill: false,
tension: 0,
pointRadius: 3,
pointHoverRadius: 3
}/*,{
label: 'Public transit, walking and scooter',
borderColor: window.chartColors.red,
backgroundColor: color(window.chartColors.red).alpha(0.2).rgbString(),
data: dataSets1[2]
}, {
label: 'Public transit, walking and bicycle',
borderColor: window.chartColors.purple,
backgroundColor: color(window.chartColors.purple).alpha(0.2).rgbString(),
data: dataSets1[3]
}, {
label: 'Driving your own car',
borderColor: window.chartColors.orange,
backgroundColor: color(window.chartColors.orange).alpha(0.2).rgbString(),
data: dataSets1[4]
}, {
label: 'Driving your own car trend line',
pointBorderColor: window.chartColors.black,
pointBackgroundColor: color(window.chartColors.black).alpha(0.2).rgbString(),
data: dataSetTrends1[4],
showLine: true,
borderWidth: 1,
fill: false,
tension: 0,
pointRadius: 3,
pointHoverRadius: 3
}, {
label: 'Car share (like Zipcar or BlueSG) and public transit, walking',
borderColor: window.chartColors.yellow,
backgroundColor: color(window.chartColors.yellow).alpha(0.2).rgbString(),
Color: color(window.chartColors.yellow).alpha(0.2).rgbString(),
data: dataSets1[5]
}*/]
};
var scatterChartData2 = {
datasets: [/*{
label: 'Rideshare only',
borderColor: window.chartColors.blue,
backgroundColor: color(window.chartColors.blue).alpha(0.2).rgbString(),
data: dataSets2[0]
},*/ {
label: '<?php echo$providers[$t]?>',
borderColor: window.chartColors.green,
backgroundColor: color(window.chartColors.green).alpha(0.2).rgbString(),
data: dataSets2[1]
}, {
label: '<?php echo$providers[$t]?> trend line',
pointBorderColor: window.chartColors.black,
pointBackgroundColor: color(window.chartColors.black).alpha(0.2).rgbString(),
data: dataSetTrends2[1],
showLine: true,
borderWidth: 1,
fill: false,
tension: 0,
pointRadius: 3,
pointHoverRadius: 3
}/*,{
label: 'Public transit, walking and scooter',
borderColor: window.chartColors.red,
backgroundColor: color(window.chartColors.red).alpha(0.2).rgbString(),
data: dataSets2[2]
}, {
label: 'Public transit, walking and bicycle',
borderColor: window.chartColors.purple,
backgroundColor: color(window.chartColors.purple).alpha(0.2).rgbString(),
data: dataSets2[3]
}, {
label: 'Driving your own car',
borderColor: window.chartColors.orange,
backgroundColor: color(window.chartColors.orange).alpha(0.2).rgbString(),
data: dataSets2[4]
}, {
label: 'Driving your own car trend line',
pointBorderColor: window.chartColors.black,
pointBackgroundColor: color(window.chartColors.black).alpha(0.2).rgbString(),
data: dataSetTrends2[4],
showLine: true,
borderWidth: 1,
fill: false,
tension: 0,
pointRadius: 3,
pointHoverRadius: 3
}, {
label: 'Car share (like Zipcar or BlueSG) and public transit, walking',
borderColor: window.chartColors.yellow,
backgroundColor: color(window.chartColors.yellow).alpha(0.2).rgbString(),
Color: color(window.chartColors.yellow).alpha(0.2).rgbString(),
data: dataSets2[5]
}*/]
};
var scatterChartData3 = {
datasets: [{
label: '<?php echo $label1 ?>',
borderColor: window.chartColors.red,
backgroundColor: color(window.chartColors.red).alpha(0.2).rgbString(),
pointBorderColor: window.chartColors.red,
pointBackgroundColor: color(window.chartColors.red).alpha(0.2).rgbString(),
data: dataSets3[0],
pointHoverRadius: 5,
fill: false,
tension: 0,
showLine: true
}, {
label: '<?php echo $label2 ?>',
borderColor: window.chartColors.blue,
backgroundColor: color(window.chartColors.blue).alpha(0.2).rgbString(),
pointBorderColor: window.chartColors.blue,
pointBackgroundColor: color(window.chartColors.blue).alpha(0.2).rgbString(),
data: dataSets3[1],
pointHoverRadius: 5,
fill: false,
tension: 0,
showLine: true
}/*, {
label: '<?php echo $label1 ?> line',
data: dataSets3[0],
type: 'line'
}, {
label: '<?php echo $label2 ?> line',
data: dataSets3[1],
type: 'line'
}*/]
};
window.onload = function() {
var ctx1 = document.getElementById('canvas1').getContext('2d');
//window.myScatter = Chart.Scatter(ctx1, {
window.myScatter1 = new Chart(ctx1, {
type: 'scatter',
data: scatterChartData1,
options: {
title: {
display: true,
text: '<?php echo $providers[$t] ?>: <?php echo $label1 ?>'
},
scales: {
xAxes: [{
ticks: {
callback: function(value, index, values) {
return new Date(value).toLocaleDateString("en-US");
}
}
}]
}
}
});
var ctx2 = document.getElementById('canvas2').getContext('2d');
//window.myScatter = Chart.Scatter(ctx2, {
window.myScatter2 = new Chart(ctx2, {
type: 'scatter',
data: scatterChartData2,
options: {
title: {
display: true,
text: '<?php echo $providers[$t] ?>: <?php echo $label2 ?>'
},
scales: {
xAxes: [{
ticks: {
callback: function(value, index, values) {
return new Date(value).toLocaleDateString("en-US");
}
}
}]
}
}
});
var ctx3 = document.getElementById('canvas3').getContext('2d');
//window.myScatter = Chart.Scatter(ctx3, {
window.myScatter3 = new Chart(ctx3, {
type: 'scatter',
data: scatterChartData3,
options: {
title: {
display: true,
text: 'Statistical variance'
},
scales: {
xAxes: [{
ticks: {
callback: function(value, index, values) {
return new Date(value).toLocaleDateString("en-US");
}
}
}]
}
}
});
};
/*
document.getElementById('reloadData').addEventListener('click', function() {
var i = 0;
scatterChartData.datasets.forEach(function(dataset) {
dataset.data = dataSets[i];
i++;
});
window.myScatter.update();
});
*/
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: {lat: 1.313333, lng: 103.833333},
mapTypeId: 'roadmap'
});
<?php foreach ($data as $i=>$f) { ?>
var flightPlanCoordinates<?php echo $i ?> = [
{lat: <?php echo $f["location_start_lat"] ?>, lng: <?php echo $f["location_start_lng"] ?>},
{lat: <?php echo $f["location_end_lat"] ?>, lng: <?php echo $f["location_end_lng"] ?>}
];
var flightPath<?php echo $i ?> = new google.maps.Polyline({
path: flightPlanCoordinates<?php echo $i ?>,
geodesic: true,
strokeColor: '<?php echo $f['c'] ?>',
strokeOpacity: 0.06125,
strokeWeight: 2
});
flightPath<?php echo $i ?>.setMap(map);
<?php } ?>
var areaCoordinates1 = [
<?php foreach ($poly1 as $i=>$coord) { ?>{lat: <?php echo $coord[1] ?>, lng: <?php echo $coord[0] ?>},<?php } ?>
{lat:<?php echo$poly1[$i][1]?> ,lng:<?php echo$poly1[$i][0]?>}
];
var areaPath1 = new google.maps.Polyline({
path: areaCoordinates1,
geodesic: true,
strokeColor: '#009900',
strokeOpacity: 1.0,
strokeWeight: 2
});
areaPath1.setMap(map);
var areaCoordinates2 = [
<?php foreach ($poly2 as $i=>$coord) { ?>{lat: <?php echo $coord[1] ?>, lng: <?php echo $coord[0] ?>},<?php } ?>
{lat:<?php echo$poly2[$i][1]?> ,lng:<?php echo$poly2[$i][0]?>}
];
var areaPath2 = new google.maps.Polyline({
path: areaCoordinates2,
geodesic: true,
strokeColor: '#009900',
strokeOpacity: 1.0,
strokeWeight: 2
});
areaPath2.setMap(map);
}
</script>
<script>
$("#loader").hide();$("#tabs").show();$("#dfilter").show();
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=<?php echo$google_api_key?>&callback=initMap">
</script>