Better dev experience, better front page
All checks were successful
pipeline / build-and-push-images (push) Successful in 5m30s
All checks were successful
pipeline / build-and-push-images (push) Successful in 5m30s
This commit is contained in:
@@ -219,7 +219,7 @@ async function handleMatchList(client: MongoClient, patch: string, champions: Ma
|
||||
|
||||
let currentMatch = 0;
|
||||
for await (let match of allMatches) {
|
||||
console.log("Computing champion stats, game entry " + currentMatch + "/" + totalMatches + " ...")
|
||||
process.stdout.write("\rComputing champion stats, game entry " + currentMatch + "/" + totalMatches + " ... ")
|
||||
currentMatch += 1;
|
||||
handleMatch(match, champions)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,14 @@ import champion_stat from "./champion_stat"
|
||||
main()
|
||||
|
||||
async function main() {
|
||||
// Check if we're in development mode with pre-loaded data
|
||||
if (process.env.NODE_ENV === 'development' && process.env.USE_IMPORTED_DATA === 'true') {
|
||||
console.log("MatchCollector - Development mode with pre-loaded data");
|
||||
await runWithPreloadedData();
|
||||
return;
|
||||
}
|
||||
|
||||
// Original production mode
|
||||
console.log("MatchCollector - Hello !");
|
||||
const client = await connectToDatabase();
|
||||
const [latestPatch, latestPatchTime] = await fetchLatestPatchDate(client);
|
||||
@@ -152,3 +160,48 @@ async function saveMatch(client, match, latestPatch) {
|
||||
const matches = database.collection(latestPatch)
|
||||
await matches.insertOne(match)
|
||||
}
|
||||
|
||||
/**
|
||||
* Development mode function that generates stats from pre-loaded data
|
||||
*/
|
||||
async function runWithPreloadedData() {
|
||||
console.log("Using pre-loaded match data for development");
|
||||
|
||||
const client = await connectToDatabase();
|
||||
try {
|
||||
const [latestPatch] = await fetchLatestPatchDate(client);
|
||||
console.log(`Latest patch: ${latestPatch}`);
|
||||
|
||||
// Check if we have matches for this patch
|
||||
const matchesDb = client.db("matches");
|
||||
const collections = await matchesDb.listCollections().toArray();
|
||||
const patchCollections = collections
|
||||
.map(c => c.name)
|
||||
.filter(name => name === latestPatch);
|
||||
|
||||
if (patchCollections.length === 0) {
|
||||
console.error(`❌ No match data found for patch ${latestPatch}`);
|
||||
console.log("💡 Please run the data import script first:");
|
||||
console.log(" node dev/scripts/setup-db.js");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Found ${patchCollections.length} match collection(s)`);
|
||||
|
||||
// Generate stats for each patch with data
|
||||
for (const patch of patchCollections) {
|
||||
console.log(`Generating stats for patch ${patch}...`);
|
||||
await champion_stat.makeChampionsStats(client, patch);
|
||||
console.log(`Stats generated for patch ${patch}`);
|
||||
}
|
||||
|
||||
console.log("🎉 All stats generated successfully!");
|
||||
console.log("🚀 Your development database is ready for frontend testing!");
|
||||
|
||||
} catch (error) {
|
||||
console.error("❌ Error in development mode:", error);
|
||||
throw error;
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user