Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
439 changes: 0 additions & 439 deletions data/seasons/midnight-s1/snapshot.json

This file was deleted.

6,395 changes: 0 additions & 6,395 deletions data/seasons/raid-46/snapshot.json

This file was deleted.

4,305 changes: 0 additions & 4,305 deletions data/seasons/raid-47/snapshot.json

This file was deleted.

1,075 changes: 0 additions & 1,075 deletions data/seasons/raid-50/snapshot.json

This file was deleted.

21 changes: 15 additions & 6 deletions scripts/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { createHash } from 'node:crypto';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { classifyKill, formatLocalTime, getIsoWeekForTimestamp } from '../src/lib/utils/lockout.js';
Expand Down Expand Up @@ -73,6 +73,17 @@ function loadJsonOr(relPath, fallback) {
return JSON.parse(readFileSync(full, 'utf-8'));
}

/** Load the most-recent weeks/*.json for a season, or null if none exist. */
function loadLatestWeek(seasonRelPath) {
const weeksDir = join(dataDir, seasonRelPath, 'weeks');
if (!existsSync(weeksDir)) return null;
const files = readdirSync(weeksDir)
.filter((f) => f.endsWith('.json'))
.sort();
if (!files.length) return null;
return loadJsonOr(`${seasonRelPath}/weeks/${files[files.length - 1]}`, null);
}

/** SHA-256 hash of an object (deterministic JSON). */
function hashRoster(roster) {
return createHash('sha256').update(JSON.stringify(roster)).digest('hex');
Expand Down Expand Up @@ -241,7 +252,7 @@ async function processMplusSeason({
const { season_id } = season;
const prefix = `seasons/${season_id}`;

const existingMplusSnapshot = loadJsonOr(`${prefix}/snapshot.json`, null);
const existingMplusSnapshot = loadLatestWeek(prefix);
const prevMplusSnapByRaider = new Map(
(existingMplusSnapshot?.raiders ?? []).map((r) => [r.raider_id, r]),
);
Expand Down Expand Up @@ -348,7 +359,6 @@ async function processMplusSeason({

const weeklyData = { season_id, week: currentWeek, fetched_at: fetchedAt, raiders };
writeJson(`${prefix}/weeks/${currentWeek}.json`, weeklyData);
writeJson(`${prefix}/snapshot.json`, weeklyData);

console.log(`[fetch] M+ season ${season_id}: wrote ${raiders.length} raider(s).`);
}
Expand Down Expand Up @@ -468,8 +478,8 @@ async function processRaidZone({
const bossNames = new Map((zone.encounters ?? []).map((e) => [e.id, e.name]));
const difficulties = roster.raid_difficulties ?? ['heroic', 'mythic'];

// Read existing snapshot to detect character switches on this run
const existingRaidSnapshot = loadJsonOr(`${prefix}/snapshot.json`, null);
// Read existing latest week to detect character switches on this run
const existingRaidSnapshot = loadLatestWeek(prefix);
const prevRaidSnapByRaider = new Map(
(existingRaidSnapshot?.raiders ?? []).map((r) => [r.raider_id, r]),
);
Expand Down Expand Up @@ -981,7 +991,6 @@ async function processRaidZone({
}

writeJson(`${prefix}/weeks/${currentWeek}.json`, weeklyData);
writeJson(`${prefix}/snapshot.json`, weeklyData);

console.log(`[fetch] Raid zone ${zone.name}: wrote ${raiders.length} raider(s).`);
}
Expand Down
16 changes: 13 additions & 3 deletions src/routes/+page.server.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
export const prerender = true;

import { existsSync, readFileSync } from 'node:fs';
import { existsSync, readdirSync, readFileSync } from 'node:fs';
import { join } from 'node:path';

/** @param {string} weeksDir */
function latestWeekSnapshot(weeksDir) {
if (!existsSync(weeksDir)) return null;
const files = readdirSync(weeksDir)
.filter((f) => f.endsWith('.json'))
.sort();
if (!files.length) return null;
return safeJson(join(weeksDir, files[files.length - 1]));
}

/** @param {string} path */
function safeJson(path) {
try {
Expand All @@ -25,7 +35,7 @@ export function load() {

const activeMplusSeasonId = seasonsIndex.active_mplus_season ?? '';
const mplusSnapshot = activeMplusSeasonId
? safeJson(join(dataDir, 'seasons', activeMplusSeasonId, 'snapshot.json'))
? latestWeekSnapshot(join(dataDir, 'seasons', activeMplusSeasonId, 'weeks'))
: null;
const mplusCompliance = activeMplusSeasonId
? safeJson(join(dataDir, 'seasons', activeMplusSeasonId, 'compliance.json'))
Expand All @@ -36,7 +46,7 @@ export function load() {
const raidZones = [];
for (const zone of seasonsIndex.all_raid_zones ?? []) {
const meta = safeJson(join(dataDir, 'seasons', zone.season_id, 'meta.json'));
const snapshot = safeJson(join(dataDir, 'seasons', zone.season_id, 'snapshot.json'));
const snapshot = latestWeekSnapshot(join(dataDir, 'seasons', zone.season_id, 'weeks'));
if (meta) raidZones.push({ meta, snapshot, season_id: zone.season_id, label: zone.label });
}

Expand Down
14 changes: 12 additions & 2 deletions src/routes/raider/[uuid]/+page.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ export function entries() {
return E2E_FIXTURES.map((/** @type {any} */ f) => ({ uuid: f.raider_id }));
}

/** @param {string} weeksDir */
function latestWeekSnapshot(weeksDir) {
if (!existsSync(weeksDir)) return null;
const files = readdirSync(weeksDir)
.filter((f) => f.endsWith('.json'))
.sort();
if (!files.length) return null;
return safeJson(join(weeksDir, files[files.length - 1]));
}

/** @param {string} path */
function safeJson(path) {
try {
Expand Down Expand Up @@ -43,7 +53,7 @@ export function load({ params }) {
const raiderCompliance = complianceFile?.raiders?.[/** @type {string} */ (params.uuid)] ?? null;

const mplusSnapshotFile = activeMplusSeasonId
? safeJson(join(dataDir, 'seasons', activeMplusSeasonId, 'snapshot.json'))
? latestWeekSnapshot(join(dataDir, 'seasons', activeMplusSeasonId, 'weeks'))
: null;
const mplusSnapshot =
mplusSnapshotFile?.raiders?.find((/** @type {any} */ r) => r.raider_id === params.uuid) ?? null;
Expand All @@ -53,7 +63,7 @@ export function load({ params }) {
const allRaidSnapshots = [];
for (const zone of seasonsIndex.all_raid_zones ?? []) {
const meta = safeJson(join(dataDir, 'seasons', zone.season_id, 'meta.json'));
const snapshotFile = safeJson(join(dataDir, 'seasons', zone.season_id, 'snapshot.json'));
const snapshotFile = latestWeekSnapshot(join(dataDir, 'seasons', zone.season_id, 'weeks'));
const raiderData =
snapshotFile?.raiders?.find((/** @type {any} */ r) => r.raider_id === params.uuid) ?? null;
if (meta) allRaidSnapshots.push({ meta, raiderData, season_id: zone.season_id });
Expand Down
14 changes: 12 additions & 2 deletions src/routes/season/[season_id]/+page.server.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
export const prerender = true;

import { existsSync, readFileSync } from 'node:fs';
import { existsSync, readdirSync, readFileSync } from 'node:fs';
import { join } from 'node:path';

/** @param {string} weeksDir */
function latestWeekSnapshot(weeksDir) {
if (!existsSync(weeksDir)) return null;
const files = readdirSync(weeksDir)
.filter((f) => f.endsWith('.json'))
.sort();
if (!files.length) return null;
return safeJson(join(weeksDir, files[files.length - 1]));
}

/** @param {string} path */
function safeJson(path) {
try {
Expand All @@ -29,7 +39,7 @@ export function load({ params }) {
null;

const sid = params.season_id ?? '';
const snapshot = safeJson(join(dataDir, 'seasons', sid, 'snapshot.json'));
const snapshot = latestWeekSnapshot(join(dataDir, 'seasons', sid, 'weeks'));
const compliance = safeJson(join(dataDir, 'seasons', sid, 'compliance.json'));
const meta = safeJson(join(dataDir, 'seasons', sid, 'meta.json'));

Expand Down