2017-11-16 23:08:14 +01:00
|
|
|
"use strict";
|
|
|
|
|
2017-12-11 01:26:27 +01:00
|
|
|
/*
|
2017-11-16 23:08:14 +01:00
|
|
|
* This file contains utility functions, data structures and
|
|
|
|
* stuff not related to what this project actually does.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Define global structure for the loading dialog */
|
|
|
|
var loadingDialog = {
|
|
|
|
id: "#loading-dialog",
|
|
|
|
progressItems: 1,
|
|
|
|
progressItemsDone: 0,
|
|
|
|
// Initialize+Show the loading dialog with a number of items to progress
|
|
|
|
show: function(progressItems = 1) {
|
2017-12-01 14:04:32 +01:00
|
|
|
console.log("show");
|
2017-11-16 23:08:14 +01:00
|
|
|
this.progressItems = progressItems;
|
|
|
|
this.progressItemsDone = 0;
|
|
|
|
this._updateProgressBar();
|
|
|
|
$(this.id).modal('show');
|
|
|
|
},
|
|
|
|
// Function to signal that another item was progressed
|
|
|
|
itemFinished: function() {
|
2017-12-01 14:04:32 +01:00
|
|
|
|
2017-11-16 23:08:14 +01:00
|
|
|
this.progressItemsDone++;
|
|
|
|
this._updateProgressBar();
|
|
|
|
},
|
|
|
|
// Hide the dialog
|
|
|
|
hide: function() {
|
2017-12-01 14:04:32 +01:00
|
|
|
console.log("hide");
|
2017-11-16 23:08:14 +01:00
|
|
|
$(this.id).modal('hide');
|
|
|
|
},
|
|
|
|
// Private function to update the progress bar shown
|
|
|
|
_updateProgressBar: function() {
|
|
|
|
var percentage = (this.progressItemsDone / this.progressItems) * 100;
|
|
|
|
if(percentage < 0 || isNaN(percentage)) percentage = 0;
|
|
|
|
if(percentage > 100) percentage = 100;
|
2017-12-11 01:26:27 +01:00
|
|
|
$(this.id + " .progress-bar").attr("style", "width: " + percentage + "%;");
|
2017-11-16 23:08:14 +01:00
|
|
|
},
|
|
|
|
};
|
2017-12-11 01:26:27 +01:00
|
|
|
|
|
|
|
//Gets the position of Driver with driverid in specific lap
|
|
|
|
function getPositionOfDriver(driver, lap, defaultReturn){
|
|
|
|
var lapEntryWithDrivId =lap.filter( drivLap => drivLap.driverId == driver.driverId );
|
|
|
|
if(lapEntryWithDrivId.length > 0){
|
|
|
|
return lapEntryWithDrivId[0].position;
|
|
|
|
}else{
|
|
|
|
return defaultReturn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// transforms the raceData to a format, with which lineDataDefinition can work
|
|
|
|
function raceDataToLineData(raceData){
|
|
|
|
// define the lines
|
|
|
|
var lineData = [];
|
|
|
|
raceData.drivers.forEach((driver, drivIn)=>{
|
|
|
|
lineData.push();
|
|
|
|
var lapsOfDriverInLineDataFormat = [];
|
|
|
|
raceData.lapTimes.forEach((lap, lapIn) => {
|
|
|
|
lapsOfDriverInLineDataFormat.push({ 'lap': lapIn, 'position': getPositionOfDriver(driver, lap, raceData.drivers.length)});
|
|
|
|
});
|
|
|
|
lineData.splice(drivIn, 0, lapsOfDriverInLineDataFormat);
|
|
|
|
});
|
|
|
|
return lineData;
|
|
|
|
}
|