added a new data structure

This commit is contained in:
Marcel 2017-12-15 14:00:44 +01:00
parent 75330865ce
commit 720bdb713d
6 changed files with 50 additions and 9 deletions

View File

@ -34,5 +34,5 @@ body {
.line {
fill: none;
stroke-width: 4px;
stroke-width: 2px;
}

View File

@ -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

View File

@ -10,5 +10,5 @@ preprocessor.load(function(data) {
var seasons = preprocessor.getResults().seasons;
for(var year in seasons) yearSelector.append("<option>" + year + "</option>");
createLineGraph("#lineGraphBox", processor.getRace(864));
createLineGraph("#lineGraphBox", processor.getRace(970));
});

View File

@ -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{

View File

@ -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;

View File

@ -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;
}