Added More Statistics. And remove them when new are added.

This commit is contained in:
sirsandmann 2017-12-30 13:03:43 +01:00
parent ecf4a56125
commit e93c083f2f
1 changed files with 70 additions and 3 deletions

View File

@ -6,10 +6,17 @@ function attachRaceStatistics(enhancedLapData, raceData){
var textArr = [];
var statisticsPerRow = 3;
//console.log(raceData);
//console.log(enhancedLapData);
// empty statistics Container before adding new Statistics
$(statisticsContainer).empty();
textArr.push(avgSymbol + " Pitstop time: " + getAvgPitStopTime(raceData) + " sec");
console.log(raceData);
console.log(enhancedLapData);
textArr.push(avgSymbol + " Pitstop time: " + getAvgPitStopTime(raceData));
textArr.push(avgSymbol + " Lap time: " + getAvgLapTime(raceData));
textArr.push(avgSymbol + " Pitstops per Driver: " + getAvgPitStopsPerDriver(raceData));
textArr.push("Fastest Lap: " + getFastestLapWithDriverCode(raceData));
textArr.push("Fastest Pitstop: " + getFastestPitStopTimeWithDriverCode(raceData));
// TODO: Addd more statistics
textArr.forEach((elem, i) =>{
@ -24,8 +31,48 @@ function attachRaceStatistics(enhancedLapData, raceData){
.html(elem)
);
});
}
function getFastestLapWithDriverCode(raceData){
if(raceData.lapTimes.size > 0){
var minLapTime = Number.POSITIVE_INFINITY;
var driverCode = "";
raceData.lapTimes.forEach((lap) => {
lap.forEach((driverInLap) => {
if( driverInLap.milliseconds < minLapTime ){
minLapTime = Math.min(minLapTime, driverInLap.milliseconds);
driverCode = getDriverCodeById(raceData, driverInLap.driverId);
}
});
});
var returnStr = ((minLapTime % 60000) / 1000).toFixed(2) + " " + driverCode;
if(Math.floor(minLapTime / 60000) > 0){
returnStr = Math.floor(minLapTime / 60000) + ":" + returnStr;
}
return returnStr;
}
}
function getFastestPitStopTimeWithDriverCode(raceData){
if(raceData.pitStops.length > 0){
var minPitStopTime = Number.POSITIVE_INFINITY;
var driverCode = "";
raceData.pitStops.forEach((current) => {
if( current.milliseconds < minPitStopTime ){
minPitStopTime = Math.min(minPitStopTime, current.milliseconds);
driverCode = getDriverCodeById(raceData, current.driverId);
}
});
return ((minPitStopTime % 60000) / 1000).toFixed(2) + " " + driverCode;
}
}
function getAvgPitStopsPerDriver(raceData){
if(raceData.pitStops.length > 0){
return (raceData.pitStops.length / raceData.drivers.length).toFixed(2);
}
}
function getAvgPitStopTime(raceData){
@ -36,3 +83,23 @@ function getAvgPitStopTime(raceData){
return ((avgPitStopTimes % 60000) / 1000).toFixed(2);
}
}
function getAvgLapTime(raceData){
if(raceData.lapTimes.size > 0){
var sumAllLapTimes = 0;
var amountLapsAllDriver = 0;
raceData.lapTimes.forEach((lap, lapInd) => {
lap.forEach((driverInLap, driverInLapInd) => {
sumAllLapTimes += driverInLap.milliseconds;
amountLapsAllDriver++;
});
});
var avgRoundTimes = sumAllLapTimes / amountLapsAllDriver;
var returnStr = ((avgRoundTimes % 60000) / 1000).toFixed(2);
if(Math.floor(avgRoundTimes / 60000) > 0){
returnStr = Math.floor(avgRoundTimes / 60000) + ":" + returnStr;
}
return returnStr;
}
}