Preprocessor now provides preprocessed data on its own

This commit is contained in:
Jan Philipp Timme 2017-11-16 23:32:20 +01:00
parent aed45a5365
commit c3b86d493e
Signed by untrusted user: JPT
GPG Key ID: 5F2C85EC6F3754B7
3 changed files with 42 additions and 31 deletions

View File

@ -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);
});

View File

@ -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;
},
};

View File

@ -34,5 +34,3 @@ var loadingDialog = {
$(this.id + " .progress-bar").attr("style", "width: " + percentage + "%;");
},
};