2017-12-08 13:37:04 +01:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var processor = {
|
|
|
|
|
|
|
|
getRace: function(raceId) {
|
|
|
|
var race = {
|
2017-12-12 21:20:09 +01:00
|
|
|
drivers: null,
|
2017-12-08 13:37:04 +01:00
|
|
|
lapTimes: null,
|
|
|
|
pitStops: null,
|
|
|
|
qualifying: null,
|
2017-12-08 13:50:59 +01:00
|
|
|
results: null,
|
2017-12-15 14:00:44 +01:00
|
|
|
raceInfo: null,
|
2017-12-16 01:18:24 +01:00
|
|
|
|
2017-12-08 13:37:04 +01:00
|
|
|
};
|
2017-12-12 21:20:09 +01:00
|
|
|
|
2017-12-08 13:37:04 +01:00
|
|
|
race.drivers = queries.getDriversByRaceId(raceId);
|
|
|
|
race.lapTimes = queries.getLapDataByRaceId(raceId);
|
|
|
|
race.qualifying = queries.getQualifingDataByRaceId(raceId);
|
|
|
|
race.pitStops = queries.getPitStopsByRaceId(raceId);
|
|
|
|
race.results = queries.getResultsByRaceId(raceId);
|
2017-12-08 13:50:59 +01:00
|
|
|
race.raceInfo = queries.getRaceById(raceId);
|
2017-12-08 13:37:04 +01:00
|
|
|
|
|
|
|
return race;
|
|
|
|
},
|
2017-12-08 13:50:59 +01:00
|
|
|
|
2017-12-15 14:00:44 +01:00
|
|
|
getEnhancedLapDataPerDriver: function(raceData) {
|
|
|
|
var result = [];
|
|
|
|
raceData.drivers.forEach((driver) => {
|
|
|
|
var lapData = {
|
|
|
|
driver: null,
|
|
|
|
laps: [],
|
|
|
|
};
|
|
|
|
lapData.driver = driver;
|
2017-12-16 01:18:24 +01:00
|
|
|
//Attach Qualifying Data
|
|
|
|
lapData.qualifying = processor.getQualifyingForDriver(raceData, driver);
|
|
|
|
//add Qualifying Data to the Laps
|
|
|
|
lapData.laps.push({'driverId': driver.driverId, 'lap': 0, 'position': lapData.qualifying.position})
|
2017-12-15 14:00:44 +01:00
|
|
|
raceData.lapTimes.forEach(lap => {
|
|
|
|
lap.forEach(curLap => {
|
|
|
|
if( curLap.driverId == driver.driverId ){
|
2017-12-16 01:18:24 +01:00
|
|
|
var pitstop = raceData.pitStops.filter(pitstop => pitstop.driverId == driver.driverId && pitstop.lap == curLap.lap);
|
2017-12-15 14:00:44 +01:00
|
|
|
if(pitstop.length > 0){
|
|
|
|
curLap.pitStop = pitstop[0];
|
|
|
|
}
|
|
|
|
lapData.laps.push(curLap);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
result.push(lapData);
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2017-12-08 13:50:59 +01:00
|
|
|
getRacesByYear: function(year) {
|
|
|
|
var races = queries.getRacesByYear(year);
|
|
|
|
return races.map(race => processor.getRace(race.raceId));
|
2017-12-12 21:20:09 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
//Gets the position of Driver with driverid in specific lap
|
2017-12-16 01:18:24 +01:00
|
|
|
// lapData: an array of the lap data for one lap
|
2017-12-15 14:00:44 +01:00
|
|
|
getPositionOfDriver: function(driver, lapData, defaultReturn){
|
|
|
|
var lapEntryWithDrivId = lapData.filter( drivLap => drivLap.driverId == driver.driverId );
|
2017-12-12 21:20:09 +01:00
|
|
|
if(lapEntryWithDrivId.length > 0){
|
|
|
|
return lapEntryWithDrivId[0].position;
|
|
|
|
}else{
|
|
|
|
return defaultReturn;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-12-16 01:18:24 +01:00
|
|
|
getQualifyingForDriver: function(raceData, driver){
|
|
|
|
var qualData = raceData.qualifying.filter( qualData => qualData.driverId == driver.driverId);
|
|
|
|
return qualData[0];
|
|
|
|
}
|
|
|
|
|
2017-12-08 13:37:04 +01:00
|
|
|
};
|