diff --git a/index.html b/index.html index d6a0945..f846861 100644 --- a/index.html +++ b/index.html @@ -80,6 +80,8 @@
+
+
@@ -117,6 +119,7 @@ + diff --git a/js/diagrams.js b/js/diagrams.js index c8c7ac5..0cd4f8f 100644 --- a/js/diagrams.js +++ b/js/diagrams.js @@ -13,6 +13,8 @@ function createLineGraph(containerId, raceData){ var enhancedLapData = processor.getEnhancedLapDataPerDriver(raceData); + attachRaceStatistics(enhancedLapData, raceData); + // Configuration var height = 720; var width = 1080; diff --git a/js/statistics.js b/js/statistics.js new file mode 100644 index 0000000..3e03249 --- /dev/null +++ b/js/statistics.js @@ -0,0 +1,38 @@ +"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($('
') + .addClass("row") + ); + } + + $(statisticsContainer + " .row").last().append($('
') + .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); + } +}