From 48ff71eca86d2ec25d113ca818d5f15ed261853f Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Wed, 15 Nov 2017 20:19:15 +0100 Subject: [PATCH] Add a basic structure to store preprocessed data for read only access --- js/main.js | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/js/main.js b/js/main.js index af6c6cf..a32336b 100644 --- a/js/main.js +++ b/js/main.js @@ -1,11 +1,27 @@ "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 function fetchCircuits(callback) { d3.csv('data/circuits.csv', function(data) { // TODO: process data - var circuits = data; + circuits = data; callback(null); // Tell the queue we're done. }); } @@ -14,7 +30,7 @@ function fetchCircuits(callback) { function fetchConstructorResults(callback) { d3.csv('data/constructorResults.csv', function(data) { // TODO: process data - var constructorResults = data; + constructorResults = data; callback(null); // Tell the queue we're done. }); } @@ -23,7 +39,7 @@ function fetchConstructorResults(callback) { function fetchConstructors(callback) { d3.csv('data/constructors.csv', function(data) { // TODO: process data - var constructors = data; + constructors = data; callback(null); // Tell the queue we're done. }); } @@ -32,7 +48,7 @@ function fetchConstructors(callback) { function fetchConstructorStandings(callback) { d3.csv('data/constructorStandings.csv', function(data) { // TODO: process data - var constructorStandings = data; + constructorStandings = data; callback(null); // Tell the queue we're done. }); } @@ -41,7 +57,7 @@ function fetchConstructorStandings(callback) { function fetchDrivers(callback) { d3.csv('data/drivers.csv', function(data) { // TODO: process data - var drivers = data; + drivers = data; callback(null); // Tell the queue we're done. }); } @@ -50,7 +66,7 @@ function fetchDrivers(callback) { function fetchDriverStandings(callback) { d3.csv('data/driverStandings.csv', function(data) { // TODO: process data - var driverStandings = data; + driverStandings = data; callback(null); // Tell the queue we're done. }); } @@ -59,7 +75,7 @@ function fetchDriverStandings(callback) { function fetchLapTimes(callback) { d3.csv('data/lapTimes.csv', function(data) { // TODO: process data - var lapTimes = data; + lapTimes = data; callback(null); // Tell the queue we're done. }); } @@ -68,7 +84,7 @@ function fetchLapTimes(callback) { function fetchPitStops(callback) { d3.csv('data/pitStops.csv', function(data) { // TODO: process data - var pitStops = data; + pitStops = data; callback(null); // Tell the queue we're done. }); } @@ -77,7 +93,7 @@ function fetchPitStops(callback) { function fetchQualifying(callback) { d3.csv('data/qualifying.csv', function(data) { // TODO: process data - var qualifying = data; + qualifying = data; callback(null); // Tell the queue we're done. }); } @@ -86,7 +102,7 @@ function fetchQualifying(callback) { function fetchRaces(callback) { d3.csv('data/races.csv', function(data) { // TODO: process data - var races = data; + races = data; callback(null); // Tell the queue we're done. }); } @@ -95,7 +111,7 @@ function fetchRaces(callback) { function fetchResults(callback) { d3.csv('data/results.csv', function(data) { // TODO: process data - var results = data; + results = data; callback(null); // Tell the queue we're done. }); } @@ -104,7 +120,7 @@ function fetchResults(callback) { function fetchSeasons(callback) { d3.csv('data/seasons.csv', function(data) { // TODO: process data - var seasons = data; + seasons = data; 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."); // Create a queue, add all the fetch&process functions and await their results @@ -136,7 +153,10 @@ d3.queue() .defer(fetchSeasons) .defer(fetchStatus) .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(arguments); if(error) throw error; }); +