From 720bdb713d347117e08fa8efe39e5908db27a69c Mon Sep 17 00:00:00 2001 From: Marcel Date: Fri, 15 Dec 2017 14:00:44 +0100 Subject: [PATCH] added a new data structure --- css/main.css | 2 +- js/diagrams.js | 3 ++- js/main.js | 2 +- js/processor.js | 37 ++++++++++++++++++++++++++++++++++--- js/queries.js | 1 + js/util.js | 14 +++++++++++--- 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/css/main.css b/css/main.css index cb71753..4d6404b 100644 --- a/css/main.css +++ b/css/main.css @@ -34,5 +34,5 @@ body { .line { fill: none; - stroke-width: 4px; + stroke-width: 2px; } diff --git a/js/diagrams.js b/js/diagrams.js index cb1784c..6901fc0 100644 --- a/js/diagrams.js +++ b/js/diagrams.js @@ -42,7 +42,8 @@ function createLineGraph(containerId, raceData){ .data([singleLineData]) .attr("class", "line") .attr("stroke", getColorValue(i, allLineData.length) ) - .attr("d", lineDataDefinition); + .attr("d", lineDataDefinition) + ; }); // Add the X Axis diff --git a/js/main.js b/js/main.js index b5ca1b2..0696f96 100644 --- a/js/main.js +++ b/js/main.js @@ -10,5 +10,5 @@ preprocessor.load(function(data) { var seasons = preprocessor.getResults().seasons; for(var year in seasons) yearSelector.append(""); - createLineGraph("#lineGraphBox", processor.getRace(864)); + createLineGraph("#lineGraphBox", processor.getRace(970)); }); diff --git a/js/processor.js b/js/processor.js index 537c1a1..cb1193b 100644 --- a/js/processor.js +++ b/js/processor.js @@ -9,7 +9,8 @@ var processor = { pitStops: null, qualifying: null, results: null, - raceInfo: null + raceInfo: null, + }; race.drivers = queries.getDriversByRaceId(raceId); @@ -22,14 +23,44 @@ var processor = { return race; }, +getEnhancedLapDataPerDriver: function(raceData) { + var result = []; + raceData.drivers.forEach((driver) => { + var lapData = { + driver: null, + laps: [], + }; + lapData.driver = driver; + raceData.lapTimes.forEach(lap => { + lap.forEach(curLap => { + if( curLap.driverId == driver.driverId ){ + var pitstop = raceData.pitStops.filter(pitstop => pitstop.driverId == driver.driverId && pitstop.lap == curLap.lap); + if(pitstop.length > 0){ + curLap.pitStop = pitstop[0]; + } + + lapData.laps.push(curLap); + } + }); + }); + + + + + result.push(lapData); + }); + return result; + }, + getRacesByYear: function(year) { var races = queries.getRacesByYear(year); return races.map(race => processor.getRace(race.raceId)); }, //Gets the position of Driver with driverid in specific lap - getPositionOfDriver: function(driver, lap, defaultReturn){ - var lapEntryWithDrivId = lap.filter( drivLap => drivLap.driverId == driver.driverId ); + // lapData: an array of the lap data for one lap + getPositionOfDriver: function(driver, lapData, defaultReturn){ + var lapEntryWithDrivId = lapData.filter( drivLap => drivLap.driverId == driver.driverId ); if(lapEntryWithDrivId.length > 0){ return lapEntryWithDrivId[0].position; }else{ diff --git a/js/queries.js b/js/queries.js index 34cd5d1..cc7d0b7 100644 --- a/js/queries.js +++ b/js/queries.js @@ -76,6 +76,7 @@ var queries = { } } + tempList.sort((o1,o2) => o1["stop"] - o2["stop"]); //var tempList = rawData.pitStops.filter(cur => cur.raceId == raceId); return tempList; diff --git a/js/util.js b/js/util.js index a977371..0ac7e4d 100644 --- a/js/util.js +++ b/js/util.js @@ -60,9 +60,17 @@ function transformRaceDataToLineData(raceData){ function transformPitStopDataToPointData(raceData){ var pointData = []; raceData.pitStops.forEach(pitStop => { - var driver = queries.getDriverById(pitStop.driverId); - var lap = raceData.lapTimes.get(pitStop.lap); - pointData.push({'position': processor.getPositionOfDriver(driver, lap , raceData.drivers.length + 1), "lap": pitStop.lap}); + + var randomData = raceData['lapTimes'].get(pitStop.lap); + var position = null; //TODO +for(var i = 0; i< randomData.length;i++){ + if(randomData[i].driverId == pitStop.driverId){ + position = randomData[i].position; + break; + } +} +//console.log(position); + pointData.push({'position': position, "lap": pitStop.lap}); }); return pointData; }