Added simple Statistic structure.

This commit is contained in:
sirsandmann 2017-12-30 01:18:26 +01:00
parent a8a1f8f133
commit 002d8fcb90
3 changed files with 43 additions and 0 deletions

View File

@ -80,6 +80,8 @@
<div class="content-box chart-box">
<div id="lineGraphBox"></div>
<div id="race-statistics">
</div>
</div>
</div> <!-- card-body -->
@ -117,6 +119,7 @@
<script type="text/javascript" src="js/queries.js"></script>
<script type="text/javascript" src="js/diagrams.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript" src="js/statistics.js"></script>
</body>
</html>

View File

@ -13,6 +13,8 @@ function createLineGraph(containerId, raceData){
var enhancedLapData = processor.getEnhancedLapDataPerDriver(raceData);
attachRaceStatistics(enhancedLapData, raceData);
// Configuration
var height = 720;
var width = 1080;

38
js/statistics.js Normal file
View File

@ -0,0 +1,38 @@
"use strict";
function attachRaceStatistics(enhancedLapData, raceData){
var statisticsContainer = "#race-statistics";
var avgSymbol = "&#216;";
var textArr = [];
var statisticsPerRow = 3;
//console.log(raceData);
//console.log(enhancedLapData);
textArr.push(avgSymbol + " Pitstop time: " + getAvgPitStopTime(raceData) + " sec");
// TODO: Addd more statistics
textArr.forEach((elem, i) =>{
if(i % statisticsPerRow == 0){
$(statisticsContainer).append($('<div></div>')
.addClass("row")
);
}
$(statisticsContainer + " .row").last().append($('<div></div>')
.addClass("col")
.html(elem)
);
});
}
function getAvgPitStopTime(raceData){
if(raceData.pitStops.length > 0){
var sumAllPitStops = 0;
raceData.pitStops.map((current) => sumAllPitStops += current.milliseconds);
var avgPitStopTimes = sumAllPitStops / raceData.pitStops.length;
return ((avgPitStopTimes % 60000) / 1000).toFixed(2);
}
}