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. */
|
|
|
|
|
|
|
|
var circuits = null;
|
|
|
|
var constructorResults = null;
|
|
|
|
var constructors = null;
|
|
|
|
var constructorStandings = null;
|
|
|
|
var drivers = null;
|
|
|
|
var driverStandings = null;
|
|
|
|
var lapTimes = null;
|
|
|
|
var pitStops = null;
|
|
|
|
var qualifying = null;
|
|
|
|
var races = null;
|
|
|
|
var results = null;
|
|
|
|
var seasons = null;
|
|
|
|
|
|
|
|
/* 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) {
|
|
|
|
// TODO: process data
|
2017-11-15 20:19:15 +01:00
|
|
|
circuits = 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/constructorResults.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchConstructorResults(callback) {
|
|
|
|
d3.csv('data/constructorResults.csv', function(data) {
|
|
|
|
// TODO: process data
|
2017-11-15 20:19:15 +01:00
|
|
|
constructorResults = 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/constructors.csv
|
2017-11-15 20:09:59 +01:00
|
|
|
function fetchConstructors(callback) {
|
|
|
|
d3.csv('data/constructors.csv', function(data) {
|
|
|
|
// TODO: process data
|
2017-11-15 20:19:15 +01:00
|
|
|
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) {
|
|
|
|
// TODO: process data
|
2017-11-15 20:19:15 +01:00
|
|
|
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) {
|
|
|
|
// TODO: process data
|
2017-11-15 20:19:15 +01:00
|
|
|
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) {
|
|
|
|
// TODO: process data
|
2017-11-15 20:19:15 +01:00
|
|
|
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) {
|
|
|
|
// TODO: process data
|
2017-11-15 20:19:15 +01:00
|
|
|
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) {
|
|
|
|
// TODO: process data
|
2017-11-15 20:19:15 +01:00
|
|
|
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) {
|
|
|
|
// TODO: process data
|
2017-11-15 20:19:15 +01:00
|
|
|
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) {
|
|
|
|
// TODO: process data
|
2017-11-15 20:19:15 +01:00
|
|
|
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) {
|
|
|
|
// TODO: process data
|
2017-11-15 20:19:15 +01:00
|
|
|
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) {
|
|
|
|
// TODO: process data
|
2017-11-15 20:19:15 +01:00
|
|
|
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) {
|
|
|
|
// TODO: process data
|
|
|
|
var status = data;
|
|
|
|
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 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)
|
|
|
|
.await(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.");
|
|
|
|
console.log(arguments);
|
|
|
|
if(error) throw error;
|
|
|
|
});
|
2017-11-15 20:19:15 +01:00
|
|
|
|