Add basic data preprocessing code

This commit is contained in:
Jan Philipp Timme 2017-11-16 22:45:43 +01:00
parent daf2eae8d5
commit dac3ddf27c
Signed by untrusted user: JPT
GPG Key ID: 5F2C85EC6F3754B7

View File

@ -22,8 +22,14 @@ var f1data = {
// data/circuits.csv
function fetchCircuits(callback) {
d3.csv('data/circuits.csv', function(data) {
// TODO: process data
f1data.circuits = data;
// preprocess data
data.forEach(function(d, i) {
d["circuitId"] = parseInt(d["circuitId"]);
d["lat"] = parseFloat(d["lat"]);
d["lng"] = parseFloat(d["lng"]);
d["alt"] = parseInt(d["alt"]);
});
f1data.circuits = data; // Store results
callback(null); // Tell the queue we're done.
});
}
@ -31,8 +37,15 @@ function fetchCircuits(callback) {
// data/constructorResults.csv
function fetchConstructorResults(callback) {
d3.csv('data/constructorResults.csv', function(data) {
// TODO: process data
f1data.constructorResults = data;
// preprocess data
data.forEach(function(d, i) {
d["constructorId"] = parseInt(d["constructorId"]);
d["constructorResultsId"] = parseInt(d["constructorResultsId"]);
d["points"] = parseInt(d["points"]);
d["raceId"] = parseInt(d["raceId"]);
d["status"] = parseInt(d["status"]);
});
f1data.constructorResults = data; // Store results
callback(null); // Tell the queue we're done.
});
}
@ -40,7 +53,10 @@ function fetchConstructorResults(callback) {
// data/constructors.csv
function fetchConstructors(callback) {
d3.csv('data/constructors.csv', function(data) {
// TODO: process data
// preprocess data
data.forEach(function(d, i) {
d["constructorId"] = parseInt(d["constructorId"]);
});
f1data.constructors = data;
callback(null); // Tell the queue we're done.
});
@ -49,7 +65,15 @@ function fetchConstructors(callback) {
// data/constructorStandings.csv
function fetchConstructorStandings(callback) {
d3.csv('data/constructorStandings.csv', function(data) {
// TODO: process data
// preprocess data
data.forEach(function(d, i) {
d["constructorId"] = parseInt(d["constructorId"]);
d["constructorStandingsId"] = parseInt(d["constructorStandingsId"]);
d["points"] = parseInt(d["points"]);
d["position"] = parseInt(d["position"]);
d["raceId"] = parseInt(d["raceId"]);
d["wins"] = parseInt(d["wins"]);
});
f1data.constructorStandings = data;
callback(null); // Tell the queue we're done.
});
@ -58,7 +82,12 @@ function fetchConstructorStandings(callback) {
// data/drivers.csv
function fetchDrivers(callback) {
d3.csv('data/drivers.csv', function(data) {
// TODO: process data
// preprocess data
data.forEach(function(d, i) {
d["dob"] = new Date(d["dob"]);
d["driverId"] = parseInt(d["driverId"]);
d["number"] = parseInt(d["number"]);
});
f1data.drivers = data;
callback(null); // Tell the queue we're done.
});
@ -67,7 +96,15 @@ function fetchDrivers(callback) {
// data/driverStandings.csv
function fetchDriverStandings(callback) {
d3.csv('data/driverStandings.csv', function(data) {
// TODO: process data
// preprocess data
data.forEach(function(d, i) {
d["driverId"] = parseInt(d["driverId"]);
d["driverStandingsId"] = parseInt(d["driverStandingsId"]);
d["points"] = parseInt(d["points"]);
d["position"] = parseInt(d["position"]);
d["raceID"] = parseInt(d["raceId"]);
d["wins"] = parseInt(d["wins"]);
});
f1data.driverStandings = data;
callback(null); // Tell the queue we're done.
});
@ -76,7 +113,14 @@ function fetchDriverStandings(callback) {
// data/lapTimes.csv
function fetchLapTimes(callback) {
d3.csv('data/lapTimes.csv', function(data) {
// TODO: process data
// preprocess data
data.forEach(function(d, i) {
d["driverId"] = parseInt(d["driverId"]);
d["lap"] = parseInt(d["lap"]);
d["milliseconds"] = parseInt(d["milliseconds"]);
d["position"] = parseInt(d["position"]);
d["raceId"] = parseInt(d["raceId"]);
});
f1data.lapTimes = data;
callback(null); // Tell the queue we're done.
});
@ -85,7 +129,15 @@ function fetchLapTimes(callback) {
// data/pitStops.csv
function fetchPitStops(callback) {
d3.csv('data/pitStops.csv', function(data) {
// TODO: process data
// preprocess data
data.forEach(function(d, i) {
d["driverId"] = parseInt(d["driverId"]);
d["duration"] = parseFloat(d["duration"]);
d["lap"] = parseInt(d["lap"]);
d["milliseconds"] = parseInt(d["milliseconds"]);
d["raceId"] = parseInt(d["raceId"]);
d["stop"] = parseInt(d["stop"]);
});
f1data.pitStops = data;
callback(null); // Tell the queue we're done.
});
@ -94,7 +146,18 @@ function fetchPitStops(callback) {
// data/qualifying.csv
function fetchQualifying(callback) {
d3.csv('data/qualifying.csv', function(data) {
// TODO: process data
// preprocess data
data.forEach(function(d, i) {
d["constructorId"] = parseInt(d["constructorId"]);
d["driverId"] = parseInt(d["driverId"]);
d["number"] = parseInt(d["number"]);
d["position"] = parseInt(d["position"]);
d["q1"] = new Date(d["q1"]);
d["q2"] = new Date(d["q2"]);
d["q3"] = new Date(d["q3"]);
d["qualifyId"] = parseInt(d["qualifyId"]);
d["raceId"] = parseInt(d["raceId"]);
});
f1data.qualifying = data;
callback(null); // Tell the queue we're done.
});
@ -103,7 +166,15 @@ function fetchQualifying(callback) {
// data/races.csv
function fetchRaces(callback) {
d3.csv('data/races.csv', function(data) {
// TODO: process data
// preprocess data
data.forEach(function(d, i) {
d["circuitId"] = parseInt(d["circuitId"]);
d["date"] = new Date(d["date"]);
d["raceId"] = parseInt(d["raceId"]);
d["round"] = parseInt(d["round"]);
d["time"] = new Date(d["time"]);
d["year"] = parseInt(d["year"]);
});
f1data.races = data;
callback(null); // Tell the queue we're done.
});
@ -112,7 +183,26 @@ function fetchRaces(callback) {
// data/results.csv
function fetchResults(callback) {
d3.csv('data/results.csv', function(data) {
// TODO: process data
// preprocess data
data.forEach(function(d, i) {
d["constructorId"] = parseInt(d["constructorId"]);
d["driverId"] = parseInt(d["driverId"]);
d["fastestLap"] = parseInt(d["fastestLap"]);
d["fastestLapSpeed"] = parseFloat(d["fastestLapSpeed"]);
d["fastestLapTime"] = new Date(d["fastestLapTime"]);
d["grid"] = parseInt(d["grid"]);
d["laps"] = parseInt(d["laps"]);
d["milliseconds"] = parseInt(d["milliseconds"]);
d["number"] = parseInt(d["number"]);
d["points"] = parseInt(d["points"]);
d["position"] = parseInt(d["position"]);
d["positionOrder"] = parseInt(d["positionOrder"]);
d["raceId"] = parseInt(d["raceId"]);
d["rank"] = parseInt(d["rank"]);
d["resultId"] = parseInt(d["resultId"]);
d["statusId"] = parseInt(d["statusId"]);
d["time"] = new Date(d["time"]);
});
f1data.results = data;
callback(null); // Tell the queue we're done.
});
@ -121,7 +211,10 @@ function fetchResults(callback) {
// data/seasons.csv
function fetchSeasons(callback) {
d3.csv('data/seasons.csv', function(data) {
// TODO: process data
// preprocess data
data.forEach(function(d, i) {
d["year"] = parseInt(d["year"]);
});
f1data.seasons = data;
callback(null); // Tell the queue we're done.
});
@ -130,7 +223,10 @@ function fetchSeasons(callback) {
// data/status.csv
function fetchStatus(callback) {
d3.csv('data/status.csv', function(data) {
// TODO: process data
// preprocess data
data.forEach(function(d, i) {
d["statusId"] = parseInt(d["statusId"]);
});
f1data.status = data;
callback(null); // Tell the queue we're done.
});