Allow collecting data from EUNE, NA, KR on top of EUW
- 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:
@@ -137,7 +137,10 @@ if (route.path.startsWith('/tierlist/')) {
|
||||
<h3 style="font-size: 18px; font-weight: 200; opacity: 0.5">Loading stats...</h3>
|
||||
</template>
|
||||
<h3 style="font-size: 18px; font-weight: 200; margin-top: 10px; margin-bottom: 10px">
|
||||
EUW Challenger only
|
||||
Challenger only
|
||||
</h3>
|
||||
<h3 style="font-size: 18px; font-weight: 200; margin-top: 10px; margin-bottom: 10px">
|
||||
EUW/EUNE/NA/KR
|
||||
</h3>
|
||||
<NuxtLink to="/about"><h3>About</h3></NuxtLink>
|
||||
<h2 style="font-size: 10px; font-weight: 200; margin-top: 3px; margin-right: 10px">
|
||||
|
||||
@@ -1,19 +1,43 @@
|
||||
import type { MongoClient } from 'mongodb'
|
||||
import { connectToDatabase, fetchLatestPatch } from '../utils/mongo'
|
||||
import { connectToDatabase, fetchLatestPatch, getAvailablePlatforms } from '../utils/mongo'
|
||||
|
||||
async function fetchGameCount(client: MongoClient, patch: string) {
|
||||
const database = client.db('matches')
|
||||
|
||||
// Check for platform-specific collections
|
||||
const platforms = await getAvailablePlatforms(client, patch)
|
||||
|
||||
if (platforms.length > 0) {
|
||||
// Sum counts from all platform-specific collections
|
||||
let totalCount = 0
|
||||
const platformCounts: Record<string, number> = {}
|
||||
|
||||
for (const platform of platforms) {
|
||||
const collection = database.collection(`${patch}_${platform}`)
|
||||
const count = await collection.countDocuments()
|
||||
platformCounts[platform] = count
|
||||
totalCount += count
|
||||
}
|
||||
|
||||
return { total: totalCount, platforms: platformCounts }
|
||||
}
|
||||
|
||||
// Fall back to old format (single collection)
|
||||
const matches = database.collection(patch)
|
||||
const count = await matches.countDocuments()
|
||||
return count
|
||||
return { total: count, platforms: {} }
|
||||
}
|
||||
|
||||
export default defineEventHandler(async _ => {
|
||||
const client = await connectToDatabase()
|
||||
const latestPatch = await fetchLatestPatch(client)
|
||||
const gameCount = await fetchGameCount(client, latestPatch)
|
||||
const gameCountData = await fetchGameCount(client, latestPatch)
|
||||
|
||||
await client.close()
|
||||
|
||||
return { patch: latestPatch, count: gameCount }
|
||||
return {
|
||||
patch: latestPatch,
|
||||
count: gameCountData.total,
|
||||
platformCounts: gameCountData.platforms
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { MongoClient } from 'mongodb'
|
||||
|
||||
// Available platforms for region-specific match data
|
||||
const PLATFORMS = ['EUW1', 'EUN1', 'NA1', 'KR'] as const
|
||||
type Platform = (typeof PLATFORMS)[number]
|
||||
|
||||
async function connectToDatabase() {
|
||||
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
|
||||
let uri = `mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@${process.env.MONGO_HOST}`
|
||||
@@ -22,4 +26,25 @@ async function fetchLatestPatch(client: MongoClient) {
|
||||
return latestPatch!.patch as string
|
||||
}
|
||||
|
||||
export { connectToDatabase, fetchLatestPatch }
|
||||
/**
|
||||
* Get available platforms for a given patch by checking which match collections exist
|
||||
* Note: Match collections are platform-specific (e.g., "15.1_EUW1")
|
||||
* Champion collections are aggregated across all platforms (e.g., "15.1")
|
||||
*/
|
||||
async function getAvailablePlatforms(client: MongoClient, patch: string): Promise<Platform[]> {
|
||||
const matchesDb = client.db('matches')
|
||||
const collections = await matchesDb.listCollections().toArray()
|
||||
const collectionNames = collections.map(c => c.name)
|
||||
|
||||
const availablePlatforms: Platform[] = []
|
||||
for (const platform of PLATFORMS) {
|
||||
if (collectionNames.includes(`${patch}_${platform}`)) {
|
||||
availablePlatforms.push(platform)
|
||||
}
|
||||
}
|
||||
|
||||
return availablePlatforms
|
||||
}
|
||||
|
||||
export { connectToDatabase, fetchLatestPatch, getAvailablePlatforms, PLATFORMS }
|
||||
export type { Platform }
|
||||
|
||||
Reference in New Issue
Block a user