-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
173 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import AsyncDelay from "../utilities/async_delay"; | ||
import VerificationCache from "./cache"; | ||
import Logger from "./logger"; | ||
import RobotEvent, { EventData, SeasonData } from "./robotevent"; | ||
|
||
export default class PreProcess { | ||
|
||
private static processed_season_data: SeasonDataEvents[] = []; | ||
|
||
// only process seasons with the following programs | ||
private static readonly SEASON_PROGRAM_CODES: string[] = ["VRC", "VEXU"]; | ||
|
||
public static get_event_season(event_id: number): any { | ||
|
||
} | ||
|
||
public static async preprocess_event_season(): Promise<void> { | ||
const seasons_list = (await RobotEvent.get_seasons()).filter(season_data => PreProcess.SEASON_PROGRAM_CODES.includes(season_data.season_program.program_code)); | ||
const seasons_events = [] as EventData[][]; | ||
for (const season_data of seasons_list) { | ||
const cache_exist = (await VerificationCache.cache_get(`ROBOTEVENT_SEASONEVENTS_${season_data.season_id}`)) !== undefined; | ||
seasons_events.push(await RobotEvent.get_season_events(season_data.season_id, season_data.season_date.date_end)); | ||
if (!cache_exist) await AsyncDelay.async_delay(10 * 1E3); | ||
} | ||
const seasons_result = seasons_list.map((season_data, season_index) => { | ||
const season_events_sorted = seasons_events[season_index].map(season_data => season_data.event_id).sort(); | ||
return { | ||
season_data: season_data, | ||
season_events: { | ||
id_all: season_events_sorted, | ||
id_min: ((season_events_sorted.length > 0) ? season_events_sorted[0] : null), | ||
id_max: ((season_events_sorted.length > 0) ? season_events_sorted[season_events_sorted.length - 1] : null) | ||
} | ||
} as SeasonDataEvents; | ||
}); | ||
PreProcess.processed_season_data = seasons_result; | ||
// log | ||
Logger.send_log([ | ||
"Completed Event Season Preprocess:", | ||
...seasons_result.map(result_data => `[${result_data.season_data.season_name}] Events: ${result_data.season_events.id_min}~${result_data.season_events.id_max}`) | ||
].join("\n")); | ||
} | ||
|
||
} | ||
|
||
interface SeasonDataEvents { | ||
season_data: SeasonData, | ||
season_events: { | ||
id_all: number[], | ||
id_min: number, | ||
id_max: number | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default class AsyncDelay { | ||
|
||
public static async async_delay(await_milliseconds: number): Promise<void> { | ||
await new Promise((resolve, reject) => setTimeout(resolve, await_milliseconds)); | ||
} | ||
|
||
} |