Added more Statistics

This commit is contained in:
sirsandmann 2017-12-30 14:09:18 +01:00
parent bf990a02c0
commit 969dd5a5ef

View File

@ -6,17 +6,26 @@ function attachRaceStatistics(enhancedLapData, raceData){
var textArr = []; var textArr = [];
var statisticsPerRow = 3; var statisticsPerRow = 3;
var selectionType = {
minimum : "min",
maximum : "max"
};
// empty statistics Container before adding new Statistics // empty statistics Container before adding new Statistics
$(statisticsContainer).empty(); $(statisticsContainer).empty();
console.log(raceData); console.log(raceData);
console.log(enhancedLapData); console.log(enhancedLapData);
textArr.push(avgSymbol + " Pitstop time: " + getAvgPitStopTime(raceData)); textArr.push(avgSymbol + " <b>Lap time:</b> " + getAvgLapTime(raceData));
textArr.push(avgSymbol + " Lap time: " + getAvgLapTime(raceData)); textArr.push(avgSymbol + " <b>Pitstop time:</b> " + getAvgPitStopTime(raceData));
textArr.push(avgSymbol + " Pitstops per Driver: " + getAvgPitStopsPerDriver(raceData)); textArr.push(avgSymbol + " <b>Pitstops per Driver:</b> " + getAvgPitStopsPerDriver(raceData));
textArr.push("Fastest Lap: " + getFastestLapWithDriverCode(raceData)); textArr.push("<b>Fastest Lap:</b> " + getFastestOrSlowestLapWithDriverCode(raceData, selectionType.minimum));
textArr.push("Fastest Pitstop: " + getFastestPitStopTimeWithDriverCode(raceData)); textArr.push("<b>Fastest Pitstop:</b> " + getFastestOrSlowestPitStopTimeWithDriverCode(raceData, selectionType.minimum));
textArr.push("<b>Most Pitstops:</b> " + getMostPitstops(raceData));
textArr.push("<b>Slowest Lap:</b> " + getFastestOrSlowestLapWithDriverCode(raceData, selectionType.maximum));
textArr.push("<b>Slowest Pitstop:</b> " + getFastestOrSlowestPitStopTimeWithDriverCode(raceData, selectionType.maximum));
textArr.push("")
// TODO: Addd more statistics // TODO: Addd more statistics
textArr.forEach((elem, i) =>{ textArr.forEach((elem, i) =>{
@ -31,75 +40,126 @@ function attachRaceStatistics(enhancedLapData, raceData){
.html(elem) .html(elem)
); );
}); });
}
function getFastestLapWithDriverCode(raceData){ function getFastestOrSlowestLapWithDriverCode(raceData, selecType){
if(raceData.lapTimes.size > 0){ if(raceData.lapTimes.size > 0){
var minLapTime = Number.POSITIVE_INFINITY; var lapTime;
var driverCode = ""; if(selecType == selectionType.minimum){
raceData.lapTimes.forEach((lap) => { lapTime = Number.POSITIVE_INFINITY;
lap.forEach((driverInLap) => { }else{
if( driverInLap.milliseconds < minLapTime ){ lapTime = 0;
minLapTime = Math.min(minLapTime, driverInLap.milliseconds); }
driverCode = getDriverCodeById(raceData, driverInLap.driverId); var driverCode = "";
raceData.lapTimes.forEach((lap) => {
lap.forEach((driverInLap) => {
if(selecType == selectionType.minimum){
if( driverInLap.milliseconds < lapTime ){
lapTime = Math.min(lapTime, driverInLap.milliseconds);
driverCode = getDriverCodeById(raceData, driverInLap.driverId);
}
}else{
if( driverInLap.milliseconds > lapTime ){
lapTime = Math.max(lapTime, driverInLap.milliseconds);
driverCode = getDriverCodeById(raceData, driverInLap.driverId);
}
}
});
});
var returnStr = ((lapTime % 60000) / 1000).toFixed(2) + " " + driverCode;
if(((lapTime % 60000) / 1000).toFixed(2) < 10){
returnStr = "0" + returnStr;
}
if(Math.floor(lapTime / 60000) > 0){
returnStr = Math.floor(lapTime / 60000) + ":" + returnStr;
}
return returnStr;
}
}
function getMostPitstops(raceData){
if(raceData.pitStops.length > 0){
var maxStops = 0;
var driverCode = "";
raceData.pitStops.forEach((current) =>{
if(current.stop > maxStops){
maxStops = current.stop;
driverCode = getDriverCodeById(raceData, current.driverId);
} }
}); });
}); return maxStops + " " + driverCode;
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){ function getFastestOrSlowestPitStopTimeWithDriverCode(raceData, selecType){
if(raceData.pitStops.length > 0){ if(raceData.pitStops.length > 0){
var minPitStopTime = Number.POSITIVE_INFINITY; var pitStopTime;
var driverCode = ""; if(selecType == selectionType.minimum){
raceData.pitStops.forEach((current) => { pitStopTime = Number.POSITIVE_INFINITY;
if( current.milliseconds < minPitStopTime ){ }else{
minPitStopTime = Math.min(minPitStopTime, current.milliseconds); pitStopTime = 0;
driverCode = getDriverCodeById(raceData, current.driverId);
} }
}); var driverCode = "";
return ((minPitStopTime % 60000) / 1000).toFixed(2) + " " + driverCode; raceData.pitStops.forEach((current) => {
} if(selecType == selectionType.minimum){
} if( current.milliseconds < pitStopTime ){
pitStopTime = Math.min(pitStopTime, current.milliseconds);
driverCode = getDriverCodeById(raceData, current.driverId);
function getAvgPitStopsPerDriver(raceData){ }
if(raceData.pitStops.length > 0){ }else{
return (raceData.pitStops.length / raceData.drivers.length).toFixed(2); if( current.milliseconds > pitStopTime ){
} pitStopTime = Math.max(pitStopTime, current.milliseconds);
} driverCode = getDriverCodeById(raceData, current.driverId);
}
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);
}
}
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 returnStr = ((pitStopTime % 60000) / 1000).toFixed(2) + " " + driverCode;
var avgRoundTimes = sumAllLapTimes / amountLapsAllDriver; if(((pitStopTime % 60000) / 1000).toFixed(2) < 10){
returnStr = "0" + returnStr;
var returnStr = ((avgRoundTimes % 60000) / 1000).toFixed(2); }
if(Math.floor(avgRoundTimes / 60000) > 0){ if(Math.floor(pitStopTime / 60000) > 0){
returnStr = Math.floor(avgRoundTimes / 60000) + ":" + returnStr; returnStr = Math.floor(pitStopTime / 60000) + ":" + returnStr;
}
return returnStr;
} }
return returnStr;
} }
function getAvgPitStopsPerDriver(raceData){
if(raceData.pitStops.length > 0){
return (raceData.pitStops.length / raceData.drivers.length).toFixed(2);
}
}
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);
}
}
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(((avgRoundTimes % 60000) / 1000).toFixed(2) < 10){
returnStr = "0" + returnStr;
}
if(Math.floor(avgRoundTimes / 60000) > 0){
returnStr = Math.floor(avgRoundTimes / 60000) + ":" + returnStr;
}
return returnStr;
}
}
} }