From c3b86d493e35fdca8fc1ade34752b0212e84b834 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Thu, 16 Nov 2017 23:32:20 +0100 Subject: [PATCH] Preprocessor now provides preprocessed data on its own --- js/main.js | 31 ++++--------------------------- js/preprocessor.js | 40 ++++++++++++++++++++++++++++++++++++++-- js/util.js | 2 -- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/js/main.js b/js/main.js index 7a0ee9c..f2e316d 100644 --- a/js/main.js +++ b/js/main.js @@ -6,30 +6,7 @@ console.log("Let's load and preprocess all data properly."); -// Show loading dialog -loadingDialog.show(13); - -// Create a queue, add all the fetch&process functions and await their results -d3.queue() - .defer(preprocessor.fetchCircuits) - .defer(preprocessor.fetchConstructorResults) - .defer(preprocessor.fetchConstructors) - .defer(preprocessor.fetchConstructorStandings) - .defer(preprocessor.fetchDrivers) - .defer(preprocessor.fetchDriverStandings) - .defer(preprocessor.fetchLapTimes) - .defer(preprocessor.fetchPitStops) - .defer(preprocessor.fetchQualifying) - .defer(preprocessor.fetchRaces) - .defer(preprocessor.fetchResults) - .defer(preprocessor.fetchSeasons) - .defer(preprocessor.fetchStatus) - .awaitAll(function(error) { - // All data loaded by the deferred functions, now we're ready for business - // (call more functions :D) - console.log("All done. Ready."); - // Throw errors so we can see them - if(error) throw error; - // Hide the loading dialog - loadingDialog.hide(); - }); +preprocessor.load(function(data) { + console.log("Results are in!"); + console.log(data); +}); \ No newline at end of file diff --git a/js/preprocessor.js b/js/preprocessor.js index 9669da7..6465b89 100644 --- a/js/preprocessor.js +++ b/js/preprocessor.js @@ -4,7 +4,9 @@ * In this file, functions for loading and preprocessing the data are defined. */ -/* Define the functions responsible for fetching+preprocessing data in a preprocessor object */ +/* + * Define the functions responsible for fetching+preprocessing data in a preprocessor object + */ var preprocessor = { // Structure that gets filled with results results: { @@ -248,4 +250,38 @@ var preprocessor = { }); }, -} + // Starts the fetch+preprocess step, calls back given function with results. + load: function(callback) { + // Show loading dialog + loadingDialog.show(13); + // Create a queue, add all the fetch&process functions and await their results + d3.queue() + .defer(preprocessor.fetchCircuits) + .defer(preprocessor.fetchConstructorResults) + .defer(preprocessor.fetchConstructors) + .defer(preprocessor.fetchConstructorStandings) + .defer(preprocessor.fetchDrivers) + .defer(preprocessor.fetchDriverStandings) + .defer(preprocessor.fetchLapTimes) + .defer(preprocessor.fetchPitStops) + .defer(preprocessor.fetchQualifying) + .defer(preprocessor.fetchRaces) + .defer(preprocessor.fetchResults) + .defer(preprocessor.fetchSeasons) + .defer(preprocessor.fetchStatus) + .awaitAll(function(error) { + // Throw errors so we can see them + if(error) throw error; + // Hide the loading dialog + loadingDialog.hide(); + // Callback with the results + callback(preprocessor.results); + }); + }, + + // Simple getter method to fetch the raw data + getResults: function() { + return preprocessor.results; + }, + +}; diff --git a/js/util.js b/js/util.js index a99ba62..3deaf50 100644 --- a/js/util.js +++ b/js/util.js @@ -34,5 +34,3 @@ var loadingDialog = { $(this.id + " .progress-bar").attr("style", "width: " + percentage + "%;"); }, }; - -