Allow collecting data from EUNE, NA, KR on top of EUW
All checks were successful
pipeline / lint-and-format (push) Successful in 4m44s
pipeline / build-and-push-images (push) Successful in 4m7s

- match_collector: query API and build collections for each platform
- match_collector: aggregate champion stats of each platform in one collection with platform annotations
- frontend: replace stats to count matches in platform-specific collections
- frontend: replace "EUW Challengers" with all supported platforms
- dev: adapted scripts to count match in platforms
This commit is contained in:
2026-04-17 16:25:19 +02:00
parent 0f84b9a707
commit dae65c8fa2
7 changed files with 342 additions and 104 deletions

View File

@@ -32,11 +32,28 @@ async function setupDatabase() {
console.log(`🎯 Latest patch version: ${latestPatch}`);
// Check if data directory exists and has files
// Support both old format (patch_matches.json) and new platform-specific format (patch_PLATFORM_matches.json)
console.log('🔍 Checking for data files...');
const platforms = ['EUW1', 'EUN1', 'NA1', 'KR'];
const dataFiles = [
{ path: 'patches.json', required: true, description: 'Patches data' },
{ path: `${latestPatch}_matches.json`, required: true, description: 'Match data' }
{ path: 'patches.json', required: true, description: 'Patches data' }
];
// Check for platform-specific match files
let foundPlatformFiles = [];
for (const platform of platforms) {
const platformFile = `${latestPatch}_${platform}_matches.json`;
const fullPath = path.join(dataDir, platformFile);
if (fs.existsSync(fullPath)) {
foundPlatformFiles.push(platform);
dataFiles.push({ path: platformFile, required: false, description: `Match data for ${platform}` });
}
}
// If no platform-specific files found, look for old format
if (foundPlatformFiles.length === 0) {
dataFiles.push({ path: `${latestPatch}_matches.json`, required: true, description: 'Match data' });
}
let filesExist = true;
for (const file of dataFiles) {
@@ -80,14 +97,36 @@ async function setupDatabase() {
// 6. Check existing matches count and import if needed
console.log('Checking existing matches count...');
const matchCount = await getMatchCount(latestPatch);
console.log(`📊 Current matches in database: ${matchCount}`);
if (matchCount < 100) {
console.log('📥 Importing matches (this may take a while)...');
await importMatchesData(latestPatch);
// Check for platform-specific collections or fall back to old format
const existingPlatforms = await getExistingPlatforms(latestPatch);
if (existingPlatforms.length > 0) {
console.log(`📊 Found platform-specific collections: ${existingPlatforms.join(', ')}`);
let totalMatches = 0;
for (const platform of existingPlatforms) {
const count = await getMatchCount(latestPatch, platform);
console.log(` ${platform}: ${count} matches`);
totalMatches += count;
}
console.log(`📊 Total matches in database: ${totalMatches}`);
if (totalMatches < 100) {
console.log('📥 Importing matches (this may take a while)...');
await importMatchesData(latestPatch, foundPlatformFiles);
} else {
console.log('✅ Skipping matches import - sufficient data already present');
}
} else {
console.log('✅ Skipping matches import - sufficient data already present');
const matchCount = await getMatchCount(latestPatch);
console.log(`📊 Current matches in database: ${matchCount}`);
if (matchCount < 100) {
console.log('📥 Importing matches (this may take a while)...');
await importMatchesData(latestPatch, foundPlatformFiles);
} else {
console.log('✅ Skipping matches import - sufficient data already present');
}
}
// 7. Fetch CDragon data for the current patch
@@ -277,19 +316,42 @@ async function importPatchesData() {
}
}
async function importMatchesData(patchVersion) {
const matchesFile = path.join(__dirname, '../data', `${patchVersion}_matches.json`);
const collectionName = patchVersion;
async function importMatchesData(patchVersion, foundPlatformFiles = []) {
const dataDir = path.join(__dirname, '../data');
try {
const result = execSync(
`node ${path.join(__dirname, 'process-matches.js')} ${matchesFile} ${collectionName} 1000`,
{
stdio: 'inherit',
env: { ...process.env, MONGO_URI: getMongoUri() }
// If platform-specific files were found, import each one
if (foundPlatformFiles.length > 0) {
for (const platform of foundPlatformFiles) {
const matchesFile = path.join(dataDir, `${patchVersion}_${platform}_matches.json`);
const collectionName = `${patchVersion}_${platform}`;
if (fs.existsSync(matchesFile)) {
console.log(`📥 Importing matches for ${platform}...`);
execSync(
`node ${path.join(__dirname, 'process-matches.js')} ${matchesFile} ${collectionName} 1000`,
{
stdio: 'inherit',
env: { ...process.env, MONGO_URI: getMongoUri() }
}
);
console.log(`✅ Matches import completed for ${platform}`);
}
}
);
console.log('✅ Matches import completed');
} else {
// Fall back to old format (single file without platform suffix)
const matchesFile = path.join(dataDir, `${patchVersion}_matches.json`);
const collectionName = patchVersion;
execSync(
`node ${path.join(__dirname, 'process-matches.js')} ${matchesFile} ${collectionName} 1000`,
{
stdio: 'inherit',
env: { ...process.env, MONGO_URI: getMongoUri() }
}
);
console.log('✅ Matches import completed');
}
} catch (error) {
console.error('❌ Failed to import matches:', error);
throw error;
@@ -344,13 +406,14 @@ async function fetchCDragonData() {
}
}
async function getMatchCount(patchVersion) {
async function getMatchCount(patchVersion, platform = null) {
const client = new MongoClient(getMongoUri());
await client.connect();
try {
const db = client.db('matches');
const collection = db.collection(patchVersion);
const collectionName = platform ? `${patchVersion}_${platform}` : patchVersion;
const collection = db.collection(collectionName);
const count = await collection.countDocuments();
return count;
} catch (error) {
@@ -361,6 +424,33 @@ async function getMatchCount(patchVersion) {
}
}
async function getExistingPlatforms(patchVersion) {
const client = new MongoClient(getMongoUri());
await client.connect();
try {
const db = client.db('matches');
const collections = await db.listCollections().toArray();
const collectionNames = collections.map(c => c.name);
const platforms = ['EUW1', 'EUN1', 'NA1', 'KR'];
const existingPlatforms = [];
for (const platform of platforms) {
if (collectionNames.includes(`${patchVersion}_${platform}`)) {
existingPlatforms.push(platform);
}
}
return existingPlatforms;
} catch (error) {
console.error('❌ Failed to get existing platforms:', error);
return [];
} finally {
await client.close();
}
}
function getMongoUri() {
return process.env.MONGO_URI || 'mongodb://root:password@localhost:27017/buildpath?authSource=admin';
}