f1vis/js/statistics.js

39 lines
994 B
JavaScript
Raw Normal View History

2017-12-30 01:18:26 +01:00
"use strict";
function attachRaceStatistics(enhancedLapData, raceData){
var statisticsContainer = "#race-statistics";
var avgSymbol = "Ø";
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);
}
}