formula1.js
Version:
Formula 1 Ergast API Wrapper
42 lines (41 loc) • 1.63 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GrandPrix = void 0;
const Circuit_1 = require("./Circuit");
const Session_1 = require("./Session");
class GrandPrix {
constructor(schedule, data) {
this.name = data.raceName;
this.round = parseInt(data.round);
this.season = schedule.season;
this.sessions = {
race: new Session_1.Session(this, { date: data.date, time: data.time }, 'Race'),
};
if (data.FirstPractice && data.SecondPractice && data.Qualifying) {
this.sessions.fp1 = new Session_1.Session(this, data.FirstPractice, 'Free Practice 1');
this.sessions.fp2 = new Session_1.Session(this, data.SecondPractice, 'Free Practice 2');
this.sessions.qualifying = new Session_1.Session(this, data.Qualifying, 'Qualifying');
}
if (data.Sprint) {
this.sessions.sprint = new Session_1.Session(this, data.Sprint, 'Sprint Qualifying');
}
else if (data.ThirdPractice) {
this.sessions.fp3 = new Session_1.Session(this, data.ThirdPractice, 'Free Practice 3');
}
this.schedule = schedule;
this.sprintWeekend = this.sessions.sprint != null;
this.circuit = new Circuit_1.Circuit(this, data.Circuit);
}
name;
round;
season;
schedule;
sprintWeekend;
circuit;
sessions;
getSessionsArray() {
const { fp1, fp2, fp3, qualifying, sprint, race } = this.sessions;
return [fp1, fp2, fp3, qualifying, sprint, race].filter(Boolean);
}
}
exports.GrandPrix = GrandPrix;