2017-11-15 19:46:47 +01:00
|
|
|
"use strict";
|
2017-11-15 20:19:15 +01:00
|
|
|
|
|
|
|
/* Globally define the places where the preprocessed data is stored for READ ONLY ACCESS. */
|
|
|
|
|
2017-11-15 20:25:44 +01:00
|
|
|
var f1data = {
|
|
|
|
circuits: null,
|
|
|
|
constructorResults: null,
|
|
|
|
constructors: null,
|
|
|
|
constructorStandings: null,
|
|
|
|
drivers: null,
|
|
|
|
driverStandings: null,
|
|
|
|
lapTimes: null,
|
|
|
|
pitStops: null,
|
|
|
|
qualifying: null,
|
|
|
|
races: null,
|
|
|
|
results: null,
|
|
|
|
seasons: null
|
|
|
|
};
|
2017-11-15 20:19:15 +01:00
|
|
|
|
|
|
|
/* Define the functions responsible for fetching+preprocessing data */
|
2017-11-15 19:46:47 +01:00
|
|
|
|
|
|
|
// data/circuits.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchCircuits(callback) {
|
|
|
|
d3.csv('data/circuits.csv', function(data) {
|
2017-11-16 22:45:43 +01:00
|
|
|
// preprocess data
|
|
|
|
data.forEach(function(d, i) {
|
|
|
|
d["circuitId"] = parseInt(d["circuitId"]);
|
|
|
|
d["lat"] = parseFloat(d["lat"]);
|
|
|
|
d["lng"] = parseFloat(d["lng"]);
|
|
|
|
d["alt"] = parseInt(d["alt"]);
|
|
|
|
});
|
|
|
|
f1data.circuits = data; // Store results
|
2017-11-15 20:09:59 +01:00
|
|
|
callback(null); // Tell the queue we're done.
|
|
|
|
});
|
|
|
|
}
|
2017-11-15 19:46:47 +01:00
|
|
|
|
|
|
|
// data/constructorResults.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchConstructorResults(callback) {
|
|
|
|
d3.csv('data/constructorResults.csv', function(data) {
|
2017-11-16 22:45:43 +01:00
|
|
|
// preprocess data
|
|
|
|
data.forEach(function(d, i) {
|
|
|
|
d["constructorId"] = parseInt(d["constructorId"]);
|
|
|
|
d["constructorResultsId"] = parseInt(d["constructorResultsId"]);
|
|
|
|
d["points"] = parseInt(d["points"]);
|
|
|
|
d["raceId"] = parseInt(d["raceId"]);
|
|
|
|
d["status"] = parseInt(d["status"]);
|
|
|
|
});
|
|
|
|
f1data.constructorResults = data; // Store results
|
2017-11-15 20:09:59 +01:00
|
|
|
callback(null); // Tell the queue we're done.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:46:47 +01:00
|
|
|
// data/constructors.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchConstructors(callback) {
|
|
|
|
d3.csv('data/constructors.csv', function(data) {
|
2017-11-16 22:45:43 +01:00
|
|
|
// preprocess data
|
|
|
|
data.forEach(function(d, i) {
|
|
|
|
d["constructorId"] = parseInt(d["constructorId"]);
|
|
|
|
});
|
2017-11-15 20:25:44 +01:00
|
|
|
f1data.constructors = data;
|
2017-11-15 20:09:59 +01:00
|
|
|
callback(null); // Tell the queue we're done.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:46:47 +01:00
|
|
|
// data/constructorStandings.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchConstructorStandings(callback) {
|
|
|
|
d3.csv('data/constructorStandings.csv', function(data) {
|
2017-11-16 22:45:43 +01:00
|
|
|
// preprocess data
|
|
|
|
data.forEach(function(d, i) {
|
|
|
|
d["constructorId"] = parseInt(d["constructorId"]);
|
|
|
|
d["constructorStandingsId"] = parseInt(d["constructorStandingsId"]);
|
|
|
|
d["points"] = parseInt(d["points"]);
|
|
|
|
d["position"] = parseInt(d["position"]);
|
|
|
|
d["raceId"] = parseInt(d["raceId"]);
|
|
|
|
d["wins"] = parseInt(d["wins"]);
|
|
|
|
});
|
2017-11-15 20:25:44 +01:00
|
|
|
f1data.constructorStandings = data;
|
2017-11-15 20:09:59 +01:00
|
|
|
callback(null); // Tell the queue we're done.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:46:47 +01:00
|
|
|
// data/drivers.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchDrivers(callback) {
|
|
|
|
d3.csv('data/drivers.csv', function(data) {
|
2017-11-16 22:45:43 +01:00
|
|
|
// preprocess data
|
|
|
|
data.forEach(function(d, i) {
|
|
|
|
d["dob"] = new Date(d["dob"]);
|
|
|
|
d["driverId"] = parseInt(d["driverId"]);
|
|
|
|
d["number"] = parseInt(d["number"]);
|
|
|
|
});
|
2017-11-15 20:25:44 +01:00
|
|
|
f1data.drivers = data;
|
2017-11-15 20:09:59 +01:00
|
|
|
callback(null); // Tell the queue we're done.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:46:47 +01:00
|
|
|
// data/driverStandings.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchDriverStandings(callback) {
|
|
|
|
d3.csv('data/driverStandings.csv', function(data) {
|
2017-11-16 22:45:43 +01:00
|
|
|
// preprocess data
|
|
|
|
data.forEach(function(d, i) {
|
|
|
|
d["driverId"] = parseInt(d["driverId"]);
|
|
|
|
d["driverStandingsId"] = parseInt(d["driverStandingsId"]);
|
|
|
|
d["points"] = parseInt(d["points"]);
|
|
|
|
d["position"] = parseInt(d["position"]);
|
|
|
|
d["raceID"] = parseInt(d["raceId"]);
|
|
|
|
d["wins"] = parseInt(d["wins"]);
|
|
|
|
});
|
2017-11-15 20:25:44 +01:00
|
|
|
f1data.driverStandings = data;
|
2017-11-15 20:09:59 +01:00
|
|
|
callback(null); // Tell the queue we're done.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:46:47 +01:00
|
|
|
// data/lapTimes.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchLapTimes(callback) {
|
|
|
|
d3.csv('data/lapTimes.csv', function(data) {
|
2017-11-16 22:45:43 +01:00
|
|
|
// preprocess data
|
|
|
|
data.forEach(function(d, i) {
|
|
|
|
d["driverId"] = parseInt(d["driverId"]);
|
|
|
|
d["lap"] = parseInt(d["lap"]);
|
|
|
|
d["milliseconds"] = parseInt(d["milliseconds"]);
|
|
|
|
d["position"] = parseInt(d["position"]);
|
|
|
|
d["raceId"] = parseInt(d["raceId"]);
|
|
|
|
});
|
2017-11-15 20:25:44 +01:00
|
|
|
f1data.lapTimes = data;
|
2017-11-15 20:09:59 +01:00
|
|
|
callback(null); // Tell the queue we're done.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:46:47 +01:00
|
|
|
// data/pitStops.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchPitStops(callback) {
|
|
|
|
d3.csv('data/pitStops.csv', function(data) {
|
2017-11-16 22:45:43 +01:00
|
|
|
// preprocess data
|
|
|
|
data.forEach(function(d, i) {
|
|
|
|
d["driverId"] = parseInt(d["driverId"]);
|
|
|
|
d["duration"] = parseFloat(d["duration"]);
|
|
|
|
d["lap"] = parseInt(d["lap"]);
|
|
|
|
d["milliseconds"] = parseInt(d["milliseconds"]);
|
|
|
|
d["raceId"] = parseInt(d["raceId"]);
|
|
|
|
d["stop"] = parseInt(d["stop"]);
|
|
|
|
});
|
2017-11-15 20:25:44 +01:00
|
|
|
f1data.pitStops = data;
|
2017-11-15 20:09:59 +01:00
|
|
|
callback(null); // Tell the queue we're done.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:46:47 +01:00
|
|
|
// data/qualifying.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchQualifying(callback) {
|
|
|
|
d3.csv('data/qualifying.csv', function(data) {
|
2017-11-16 22:45:43 +01:00
|
|
|
// preprocess data
|
|
|
|
data.forEach(function(d, i) {
|
|
|
|
d["constructorId"] = parseInt(d["constructorId"]);
|
|
|
|
d["driverId"] = parseInt(d["driverId"]);
|
|
|
|
d["number"] = parseInt(d["number"]);
|
|
|
|
d["position"] = parseInt(d["position"]);
|
|
|
|
d["q1"] = new Date(d["q1"]);
|
|
|
|
d["q2"] = new Date(d["q2"]);
|
|
|
|
d["q3"] = new Date(d["q3"]);
|
|
|
|
d["qualifyId"] = parseInt(d["qualifyId"]);
|
|
|
|
d["raceId"] = parseInt(d["raceId"]);
|
|
|
|
});
|
2017-11-15 20:25:44 +01:00
|
|
|
f1data.qualifying = data;
|
2017-11-15 20:09:59 +01:00
|
|
|
callback(null); // Tell the queue we're done.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:46:47 +01:00
|
|
|
// data/races.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchRaces(callback) {
|
|
|
|
d3.csv('data/races.csv', function(data) {
|
2017-11-16 22:45:43 +01:00
|
|
|
// preprocess data
|
|
|
|
data.forEach(function(d, i) {
|
|
|
|
d["circuitId"] = parseInt(d["circuitId"]);
|
|
|
|
d["date"] = new Date(d["date"]);
|
|
|
|
d["raceId"] = parseInt(d["raceId"]);
|
|
|
|
d["round"] = parseInt(d["round"]);
|
|
|
|
d["time"] = new Date(d["time"]);
|
|
|
|
d["year"] = parseInt(d["year"]);
|
|
|
|
});
|
2017-11-15 20:25:44 +01:00
|
|
|
f1data.races = data;
|
2017-11-15 20:09:59 +01:00
|
|
|
callback(null); // Tell the queue we're done.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:46:47 +01:00
|
|
|
// data/results.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchResults(callback) {
|
|
|
|
d3.csv('data/results.csv', function(data) {
|
2017-11-16 22:45:43 +01:00
|
|
|
// preprocess data
|
|
|
|
data.forEach(function(d, i) {
|
|
|
|
d["constructorId"] = parseInt(d["constructorId"]);
|
|
|
|
d["driverId"] = parseInt(d["driverId"]);
|
|
|
|
d["fastestLap"] = parseInt(d["fastestLap"]);
|
|
|
|
d["fastestLapSpeed"] = parseFloat(d["fastestLapSpeed"]);
|
|
|
|
d["fastestLapTime"] = new Date(d["fastestLapTime"]);
|
|
|
|
d["grid"] = parseInt(d["grid"]);
|
|
|
|
d["laps"] = parseInt(d["laps"]);
|
|
|
|
d["milliseconds"] = parseInt(d["milliseconds"]);
|
|
|
|
d["number"] = parseInt(d["number"]);
|
|
|
|
d["points"] = parseInt(d["points"]);
|
|
|
|
d["position"] = parseInt(d["position"]);
|
|
|
|
d["positionOrder"] = parseInt(d["positionOrder"]);
|
|
|
|
d["raceId"] = parseInt(d["raceId"]);
|
|
|
|
d["rank"] = parseInt(d["rank"]);
|
|
|
|
d["resultId"] = parseInt(d["resultId"]);
|
|
|
|
d["statusId"] = parseInt(d["statusId"]);
|
|
|
|
d["time"] = new Date(d["time"]);
|
|
|
|
});
|
2017-11-15 20:25:44 +01:00
|
|
|
f1data.results = data;
|
2017-11-15 20:09:59 +01:00
|
|
|
callback(null); // Tell the queue we're done.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:46:47 +01:00
|
|
|
// data/seasons.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchSeasons(callback) {
|
|
|
|
d3.csv('data/seasons.csv', function(data) {
|
2017-11-16 22:45:43 +01:00
|
|
|
// preprocess data
|
|
|
|
data.forEach(function(d, i) {
|
|
|
|
d["year"] = parseInt(d["year"]);
|
|
|
|
});
|
2017-11-15 20:25:44 +01:00
|
|
|
f1data.seasons = data;
|
2017-11-15 20:09:59 +01:00
|
|
|
callback(null); // Tell the queue we're done.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:46:47 +01:00
|
|
|
// data/status.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchStatus(callback) {
|
|
|
|
d3.csv('data/status.csv', function(data) {
|
2017-11-16 22:45:43 +01:00
|
|
|
// preprocess data
|
|
|
|
data.forEach(function(d, i) {
|
|
|
|
d["statusId"] = parseInt(d["statusId"]);
|
|
|
|
});
|
2017-11-15 20:25:44 +01:00
|
|
|
f1data.status = data;
|
2017-11-15 20:09:59 +01:00
|
|
|
callback(null); // Tell the queue we're done.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-15 20:19:15 +01:00
|
|
|
/* This is where the actual control flow is defined */
|
2017-11-15 20:09:59 +01:00
|
|
|
console.log("Let's load and preprocess all data properly.");
|
2017-11-15 19:46:47 +01:00
|
|
|
|
2017-11-15 21:22:05 +01:00
|
|
|
// Enable loading modal
|
|
|
|
$("#loading-dialog").modal('show');
|
|
|
|
|
2017-11-15 20:09:59 +01:00
|
|
|
// Create a queue, add all the fetch&process functions and await their results
|
|
|
|
d3.queue()
|
|
|
|
.defer(fetchCircuits)
|
|
|
|
.defer(fetchConstructorResults)
|
|
|
|
.defer(fetchConstructors)
|
|
|
|
.defer(fetchConstructorStandings)
|
|
|
|
.defer(fetchDrivers)
|
|
|
|
.defer(fetchDriverStandings)
|
|
|
|
.defer(fetchLapTimes)
|
|
|
|
.defer(fetchPitStops)
|
|
|
|
.defer(fetchQualifying)
|
|
|
|
.defer(fetchRaces)
|
|
|
|
.defer(fetchResults)
|
|
|
|
.defer(fetchSeasons)
|
|
|
|
.defer(fetchStatus)
|
2017-11-15 20:25:44 +01:00
|
|
|
.awaitAll(function(error) {
|
2017-11-15 20:19:15 +01:00
|
|
|
// All data loaded by the deferred functions, now we're ready for business
|
|
|
|
// (call more functions :D)
|
2017-11-15 20:09:59 +01:00
|
|
|
console.log("All done. Ready.");
|
2017-11-15 20:41:46 +01:00
|
|
|
// Throw errors so we can see them
|
2017-11-15 20:09:59 +01:00
|
|
|
if(error) throw error;
|
2017-11-15 20:41:46 +01:00
|
|
|
// Hide the loadmask
|
2017-11-15 21:22:05 +01:00
|
|
|
$("#loading-dialog").modal('hide');
|
2017-11-15 20:09:59 +01:00
|
|
|
});
|
2017-11-15 20:19:15 +01:00
|
|
|
|