Add a basic structure to store preprocessed data for read only access
This commit is contained in:
parent
d6c9a6650c
commit
48ff71eca8
46
js/main.js
46
js/main.js
|
@ -1,11 +1,27 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
console.log("Main script running.");
|
|
||||||
|
/* 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 */
|
||||||
|
|
||||||
// data/circuits.csv
|
// data/circuits.csv
|
||||||
function fetchCircuits(callback) {
|
function fetchCircuits(callback) {
|
||||||
d3.csv('data/circuits.csv', function(data) {
|
d3.csv('data/circuits.csv', function(data) {
|
||||||
// TODO: process data
|
// TODO: process data
|
||||||
var circuits = data;
|
circuits = data;
|
||||||
callback(null); // Tell the queue we're done.
|
callback(null); // Tell the queue we're done.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -14,7 +30,7 @@ function fetchCircuits(callback) {
|
||||||
function fetchConstructorResults(callback) {
|
function fetchConstructorResults(callback) {
|
||||||
d3.csv('data/constructorResults.csv', function(data) {
|
d3.csv('data/constructorResults.csv', function(data) {
|
||||||
// TODO: process data
|
// TODO: process data
|
||||||
var constructorResults = data;
|
constructorResults = data;
|
||||||
callback(null); // Tell the queue we're done.
|
callback(null); // Tell the queue we're done.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -23,7 +39,7 @@ function fetchConstructorResults(callback) {
|
||||||
function fetchConstructors(callback) {
|
function fetchConstructors(callback) {
|
||||||
d3.csv('data/constructors.csv', function(data) {
|
d3.csv('data/constructors.csv', function(data) {
|
||||||
// TODO: process data
|
// TODO: process data
|
||||||
var constructors = data;
|
constructors = data;
|
||||||
callback(null); // Tell the queue we're done.
|
callback(null); // Tell the queue we're done.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -32,7 +48,7 @@ function fetchConstructors(callback) {
|
||||||
function fetchConstructorStandings(callback) {
|
function fetchConstructorStandings(callback) {
|
||||||
d3.csv('data/constructorStandings.csv', function(data) {
|
d3.csv('data/constructorStandings.csv', function(data) {
|
||||||
// TODO: process data
|
// TODO: process data
|
||||||
var constructorStandings = data;
|
constructorStandings = data;
|
||||||
callback(null); // Tell the queue we're done.
|
callback(null); // Tell the queue we're done.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -41,7 +57,7 @@ function fetchConstructorStandings(callback) {
|
||||||
function fetchDrivers(callback) {
|
function fetchDrivers(callback) {
|
||||||
d3.csv('data/drivers.csv', function(data) {
|
d3.csv('data/drivers.csv', function(data) {
|
||||||
// TODO: process data
|
// TODO: process data
|
||||||
var drivers = data;
|
drivers = data;
|
||||||
callback(null); // Tell the queue we're done.
|
callback(null); // Tell the queue we're done.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -50,7 +66,7 @@ function fetchDrivers(callback) {
|
||||||
function fetchDriverStandings(callback) {
|
function fetchDriverStandings(callback) {
|
||||||
d3.csv('data/driverStandings.csv', function(data) {
|
d3.csv('data/driverStandings.csv', function(data) {
|
||||||
// TODO: process data
|
// TODO: process data
|
||||||
var driverStandings = data;
|
driverStandings = data;
|
||||||
callback(null); // Tell the queue we're done.
|
callback(null); // Tell the queue we're done.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -59,7 +75,7 @@ function fetchDriverStandings(callback) {
|
||||||
function fetchLapTimes(callback) {
|
function fetchLapTimes(callback) {
|
||||||
d3.csv('data/lapTimes.csv', function(data) {
|
d3.csv('data/lapTimes.csv', function(data) {
|
||||||
// TODO: process data
|
// TODO: process data
|
||||||
var lapTimes = data;
|
lapTimes = data;
|
||||||
callback(null); // Tell the queue we're done.
|
callback(null); // Tell the queue we're done.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -68,7 +84,7 @@ function fetchLapTimes(callback) {
|
||||||
function fetchPitStops(callback) {
|
function fetchPitStops(callback) {
|
||||||
d3.csv('data/pitStops.csv', function(data) {
|
d3.csv('data/pitStops.csv', function(data) {
|
||||||
// TODO: process data
|
// TODO: process data
|
||||||
var pitStops = data;
|
pitStops = data;
|
||||||
callback(null); // Tell the queue we're done.
|
callback(null); // Tell the queue we're done.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -77,7 +93,7 @@ function fetchPitStops(callback) {
|
||||||
function fetchQualifying(callback) {
|
function fetchQualifying(callback) {
|
||||||
d3.csv('data/qualifying.csv', function(data) {
|
d3.csv('data/qualifying.csv', function(data) {
|
||||||
// TODO: process data
|
// TODO: process data
|
||||||
var qualifying = data;
|
qualifying = data;
|
||||||
callback(null); // Tell the queue we're done.
|
callback(null); // Tell the queue we're done.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -86,7 +102,7 @@ function fetchQualifying(callback) {
|
||||||
function fetchRaces(callback) {
|
function fetchRaces(callback) {
|
||||||
d3.csv('data/races.csv', function(data) {
|
d3.csv('data/races.csv', function(data) {
|
||||||
// TODO: process data
|
// TODO: process data
|
||||||
var races = data;
|
races = data;
|
||||||
callback(null); // Tell the queue we're done.
|
callback(null); // Tell the queue we're done.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -95,7 +111,7 @@ function fetchRaces(callback) {
|
||||||
function fetchResults(callback) {
|
function fetchResults(callback) {
|
||||||
d3.csv('data/results.csv', function(data) {
|
d3.csv('data/results.csv', function(data) {
|
||||||
// TODO: process data
|
// TODO: process data
|
||||||
var results = data;
|
results = data;
|
||||||
callback(null); // Tell the queue we're done.
|
callback(null); // Tell the queue we're done.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -104,7 +120,7 @@ function fetchResults(callback) {
|
||||||
function fetchSeasons(callback) {
|
function fetchSeasons(callback) {
|
||||||
d3.csv('data/seasons.csv', function(data) {
|
d3.csv('data/seasons.csv', function(data) {
|
||||||
// TODO: process data
|
// TODO: process data
|
||||||
var seasons = data;
|
seasons = data;
|
||||||
callback(null); // Tell the queue we're done.
|
callback(null); // Tell the queue we're done.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -118,6 +134,7 @@ function fetchStatus(callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is where the actual control flow is defined */
|
||||||
console.log("Let's load and preprocess all data properly.");
|
console.log("Let's load and preprocess all data properly.");
|
||||||
|
|
||||||
// Create a queue, add all the fetch&process functions and await their results
|
// Create a queue, add all the fetch&process functions and await their results
|
||||||
|
@ -136,7 +153,10 @@ d3.queue()
|
||||||
.defer(fetchSeasons)
|
.defer(fetchSeasons)
|
||||||
.defer(fetchStatus)
|
.defer(fetchStatus)
|
||||||
.await(function(error) {
|
.await(function(error) {
|
||||||
|
// All data loaded by the deferred functions, now we're ready for business
|
||||||
|
// (call more functions :D)
|
||||||
console.log("All done. Ready.");
|
console.log("All done. Ready.");
|
||||||
console.log(arguments);
|
console.log(arguments);
|
||||||
if(error) throw error;
|
if(error) throw error;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue