Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/archive fixes #189

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions data/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface SeriesArchive {

export interface QuarterArchive {
name: string;
season: "w" | "s" | "u" | "f";
year: number;
series: SeriesArchive[];
}

Expand All @@ -19,7 +21,7 @@ for (const event of eventData) {
if (!event.type) continue;

const idComponents = event.id.split("-");
if (idComponents.length >= 2 && /^[fws]\d\d$/.test(idComponents[0])) {
if (idComponents.length >= 2 && /^[wsuf]\d\d$/.test(idComponents[0])) {
if (!quarters.has(idComponents[0])) {
quarters.set(idComponents[0], new Map());
}
Expand All @@ -36,22 +38,32 @@ for (const event of eventData) {
}
}

const SEASONS = { "w": 0, "s": 1, "u": 2, "f": 3 };

const archive: QuarterArchive[] = [...quarters.entries()].map(([quarterId, quarterMap]) => {
const seasonChar = quarterId.charAt(0);
let season;
switch (quarterId.charAt(0)) {
switch (seasonChar) {
case "f": season = "Fall"; break;
case "w": season = "Winter"; break;
case "s": season = "Spring"; break;
case "u": season = "Summer"; break;
default: throw `invalid season char '${quarterId.charAt(0)}' (this should never happen)`
}
const year = parseInt(quarterId.length === 3 ? `20${quarterId.slice(1)}` : quarterId);
return {
name: `${season} ${quarterId.length === 3 ? `20${quarterId.slice(1)}` : quarterId}`,
name: `${season} ${year}`,
season: seasonChar,
year: year,
series: [...quarterMap.entries()].map(([seriesId, events]) => ({
name: seriesId,
description: eventTypes.find(x => x.name === seriesId)!.description,
events,
}))
}
})
}).sort((a, b) => {
if (a.year == b.year) return SEASONS[a.season] - SEASONS[b.season];
return a.year - b.year;
}).reverse();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of .sort().reverse() just reverse the sort comparator


export default archive;