Preprocessor now provides preprocessed data on its own
This commit is contained in:
		
							parent
							
								
									aed45a5365
								
							
						
					
					
						commit
						c3b86d493e
					
				
							
								
								
									
										31
									
								
								js/main.js
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								js/main.js
									
									
									
									
									
								
							@ -6,30 +6,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
console.log("Let's load and preprocess all data properly.");
 | 
					console.log("Let's load and preprocess all data properly.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Show loading dialog
 | 
					preprocessor.load(function(data) {
 | 
				
			||||||
loadingDialog.show(13);
 | 
					  console.log("Results are in!");
 | 
				
			||||||
 | 
					  console.log(data);
 | 
				
			||||||
// 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();
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
@ -4,7 +4,9 @@
 | 
				
			|||||||
 * In this file, functions for loading and preprocessing the data are defined.
 | 
					 * 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 = {
 | 
					var preprocessor = {
 | 
				
			||||||
  // Structure that gets filled with results
 | 
					  // Structure that gets filled with results
 | 
				
			||||||
  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;
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -34,5 +34,3 @@ var loadingDialog = {
 | 
				
			|||||||
    $(this.id + " .progress-bar").attr("style", "width: " + percentage + "%;");    
 | 
					    $(this.id + " .progress-bar").attr("style", "width: " + percentage + "%;");    
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user