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:
@@ -218,7 +218,8 @@ function handleMatchBuilds(
|
||||
match: Match,
|
||||
participant: Participant,
|
||||
participantIndex: number,
|
||||
builds: Builds
|
||||
builds: Builds,
|
||||
platform?: string
|
||||
) {
|
||||
const timeline: Timeline = match.timeline
|
||||
|
||||
@@ -226,7 +227,7 @@ function handleMatchBuilds(
|
||||
const build = findOrCreateBuild(builds, participant)
|
||||
build.count += 1
|
||||
|
||||
const items: Array<{ itemId: number; goldAdvantage: GoldAdvantageTag }> = []
|
||||
const items: Array<{ itemId: number; goldAdvantage: GoldAdvantageTag; platform?: string }> = []
|
||||
for (const frame of timeline.info.frames) {
|
||||
for (const event of frame.events) {
|
||||
if (event.participantId != participantIndex) continue
|
||||
@@ -301,7 +302,7 @@ function handleMatchBuilds(
|
||||
|
||||
// Calculate gold advantage at time of purchase
|
||||
const goldAdvantage = calculateGoldAdvantage(match, frame, participantIndex)
|
||||
items.push({ itemId: event.itemId, goldAdvantage })
|
||||
items.push({ itemId: event.itemId, goldAdvantage, platform })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +313,7 @@ function handleMatchBuilds(
|
||||
}
|
||||
}
|
||||
|
||||
function handleMatch(match: Match, champions: Map<number, ChampionData>) {
|
||||
function handleMatch(match: Match, champions: Map<number, ChampionData>, platform?: string) {
|
||||
let participantIndex = 0
|
||||
for (const participant of match.info.participants) {
|
||||
participantIndex += 1
|
||||
@@ -395,17 +396,19 @@ function handleMatch(match: Match, champions: Map<number, ChampionData>) {
|
||||
}
|
||||
|
||||
// Items and runes (builds)
|
||||
handleMatchBuilds(match, participant, participantIndex, lane.builds)
|
||||
handleMatchBuilds(match, participant, participantIndex, lane.builds, platform)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleMatchList(
|
||||
client: MongoClient,
|
||||
patch: string,
|
||||
champions: Map<number, ChampionData>
|
||||
champions: Map<number, ChampionData>,
|
||||
platform?: string
|
||||
) {
|
||||
const database = client.db('matches')
|
||||
const matches = database.collection(patch)
|
||||
const collectionName = platform ? `${patch}_${platform}` : patch
|
||||
const matches = database.collection(collectionName)
|
||||
const allMatches = matches.find()
|
||||
const totalMatches: number = await matches.countDocuments()
|
||||
|
||||
@@ -415,7 +418,7 @@ async function handleMatchList(
|
||||
'\rComputing champion stats, game entry ' + currentMatch + '/' + totalMatches + ' ... '
|
||||
)
|
||||
currentMatch += 1
|
||||
handleMatch(match as unknown as Match, champions)
|
||||
handleMatch(match as unknown as Match, champions, platform)
|
||||
}
|
||||
|
||||
return totalMatches
|
||||
@@ -696,7 +699,7 @@ async function championList() {
|
||||
return list.slice(1)
|
||||
}
|
||||
|
||||
async function makeChampionsStats(client: MongoClient, patch: string) {
|
||||
async function makeChampionsStats(client: MongoClient, patch: string, platforms: string[] = []) {
|
||||
const globalItems = await itemList()
|
||||
for (const item of globalItems) {
|
||||
itemDict.set(item.id, item)
|
||||
@@ -705,7 +708,7 @@ async function makeChampionsStats(client: MongoClient, patch: string) {
|
||||
const list = await championList()
|
||||
console.log('Generating stats for ' + list.length + ' champions')
|
||||
|
||||
// Pre-generate list of champions
|
||||
// Pre-generate list of champions (shared across all platforms)
|
||||
const champions: Map<number, ChampionData> = new Map()
|
||||
for (const champion of list) {
|
||||
champions.set(champion.id, {
|
||||
@@ -716,10 +719,18 @@ async function makeChampionsStats(client: MongoClient, patch: string) {
|
||||
})
|
||||
}
|
||||
|
||||
// Loop through all matches to generate stats
|
||||
const totalMatches = await handleMatchList(client, patch, champions)
|
||||
// Process matches from all platforms, merging into the same champions map
|
||||
let totalMatches = 0
|
||||
for (const platform of platforms) {
|
||||
console.log(`\n=== Processing matches from platform: ${platform} ===`)
|
||||
const platformMatches = await handleMatchList(client, patch, champions, platform)
|
||||
totalMatches += platformMatches
|
||||
console.log(`Processed ${platformMatches} matches from ${platform}`)
|
||||
}
|
||||
|
||||
// Finalize and save stats for every champion
|
||||
console.log(`\n=== Total matches processed: ${totalMatches} ===`)
|
||||
|
||||
// Finalize and save stats to a single champions collection
|
||||
const database = client.db('champions')
|
||||
const collection = database.collection(patch)
|
||||
for (const champion of list) {
|
||||
@@ -729,6 +740,7 @@ async function makeChampionsStats(client: MongoClient, patch: string) {
|
||||
|
||||
// Create alias-index for better key-find
|
||||
await collection.createIndex({ alias: 1 })
|
||||
console.log(`Stats saved to collection: ${patch}`)
|
||||
}
|
||||
|
||||
export default { makeChampionsStats }
|
||||
|
||||
Reference in New Issue
Block a user