diff --git a/js/diagrams.js b/js/diagrams.js index d8eb4e2..cb1784c 100644 --- a/js/diagrams.js +++ b/js/diagrams.js @@ -56,4 +56,15 @@ function createLineGraph(containerId, raceData){ svg.append("g") .call(d3.axisRight(y)) .attr("transform", "translate( " + (width) + ", 0 )"); + +console.log(transformPitStopDataToPointData(raceData)); + // 12. Appends a circle for each datapoint + svg.selectAll(".dot") + .data(transformPitStopDataToPointData(raceData)) + .enter().append("circle") // Uses the enter().append() method + .attr("class", "dot") // Assign a class for styling + .attr("cx", function(d, i) { return x(d.lap) }) + .attr("cy", function(d) { return y(d.position) }) + .attr("r", 5); + } diff --git a/js/main.js b/js/main.js index 552ade6..b5ca1b2 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(1)); + createLineGraph("#lineGraphBox", processor.getRace(864)); }); diff --git a/js/processor.js b/js/processor.js index 1fb68d2..537c1a1 100644 --- a/js/processor.js +++ b/js/processor.js @@ -29,7 +29,7 @@ var processor = { //Gets the position of Driver with driverid in specific lap getPositionOfDriver: function(driver, lap, defaultReturn){ - var lapEntryWithDrivId =lap.filter( drivLap => drivLap.driverId == driver.driverId ); + var lapEntryWithDrivId = lap.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 c7e97c8..34cd5d1 100644 --- a/js/queries.js +++ b/js/queries.js @@ -11,7 +11,7 @@ var queries = { */ getDriversByNationality: function() { var rawData = preprocessor.getResults(); - + // Extract interesting data from raw data. var nationalities = {}; for(var i in rawData.drivers) { @@ -100,7 +100,7 @@ var queries = { myMap.set(lapNum,data); } var dt = myMap.get(lapNum); - dt.push(d); + dt.push(d); myMap.set(lapNum,dt); }); @@ -111,7 +111,7 @@ var queries = { getRaceById: function(raceId){ var rawData = preprocessor.getResults(); - return rawData.races[raceId]; + return rawData.races[raceId]; }, getRacesByYear: function(year){ @@ -126,7 +126,7 @@ var queries = { races.sort((o1,o2) => o1["round"] - o2["round"]); return races; - + }, getQualifingDataByRaceId: function(raceId) { diff --git a/js/util.js b/js/util.js index db4dcae..a977371 100644 --- a/js/util.js +++ b/js/util.js @@ -49,7 +49,7 @@ function transformRaceDataToLineData(raceData){ raceData.lapTimes.forEach((lap, lapIn) => { var drivPos = processor.getPositionOfDriver(driver, lap, raceData.drivers.length + 1 ); if( drivPos < raceData.drivers.length + 1 ){ - lapsOfDriverInLineDataFormat.push({ 'lap': lapIn, 'position': processor.getPositionOfDriver(driver, lap, raceData.drivers.length + 1 )}); + lapsOfDriverInLineDataFormat.push({ 'lap': lapIn, 'position': processor.getPositionOfDriver(driver, lap, raceData.drivers.length + 1 ), 'driverId': driver.driverId}); } }); lineData.splice(drivIn, 0, lapsOfDriverInLineDataFormat); @@ -57,11 +57,36 @@ function transformRaceDataToLineData(raceData){ return lineData; } +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}); + }); + return pointData; +} + function getPositionOfQualifying(raceData, driver){ var qualData = raceData.qualifying.filter( qualData => qualData.driverId == driver.driverId); return qualData[0].position; } +// eigentlich war für TickData gedacht +function getDriverCodeAndPositionArray(raceData, lapNumber){ + var posDriverCode = []; + if(lapNumber == 0){ + raceData.qualifying.forEach(qualData => { + posDriverCode.push(getDriverCodeById(raceData, qualData.driverId) + " " + qualData.position) + }); + } + return posDriverCode; +} + +function getDriverCodeById(raceData,driverId){ + return raceData.drivers.filter(driv=> driv.driverId == driverId)[0].code; +} + function getColorValue(index, all){ var r = 0; var g = 0;