UNPKG

formula1.js

Version:
39 lines (38 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Schedule = void 0; const Request_1 = require("../Request"); const GrandPrix_1 = require("./GrandPrix"); class Schedule { constructor(year) { this.year = year; } async pop() { const data = (await (0, Request_1.Request)(this.year.toString())); const schedule = data.MRData; this.season = parseInt(schedule.RaceTable.season); this.rounds = schedule.RaceTable.Races.map(r => new GrandPrix_1.GrandPrix(this, r)); this.initialized = true; return this; } year; initialized = false; season; rounds; getAllSessions() { let ss = []; for (const g of this.rounds) { ss.push(...g.getSessionsArray()); } return ss; } findNextSession() { let ss = this.getAllSessions(); return ss.filter(s => !s.completed)[0]; } findLastSession() { let ss = this.getAllSessions(); return ss.filter(s => s.completed).at(-1); } } exports.Schedule = Schedule;