From a0e2915c3df09e3f5740d98870494a9bb7241ed7 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Thu, 30 Apr 2026 20:16:00 +0200 Subject: [PATCH] fix/match_collector: fix splitting of boots and first backs --- match_collector/src/champion_stat.ts | 55 ++++++++++++++++++++++++---- match_collector/src/types.ts | 1 + 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/match_collector/src/champion_stat.ts b/match_collector/src/champion_stat.ts index 58bc1c8..4196851 100644 --- a/match_collector/src/champion_stat.ts +++ b/match_collector/src/champion_stat.ts @@ -177,7 +177,7 @@ function handleMatchBuilds( participantIndex: number, builds: Builds, platform?: string -): Build { +): { build: Build; startItemId: number | undefined } { const timeline: Timeline = match.timeline // Find or create the build for this participant's rune configuration @@ -185,6 +185,7 @@ function handleMatchBuilds( build.count += 1 const items: Array<{ itemId: number; goldAdvantage: GoldAdvantageTag; platform?: string }> = [] + let startItemId: number | undefined = undefined for (const frame of timeline.info.frames) { for (const event of frame.events) { if (event.participantId != participantIndex) continue @@ -267,9 +268,11 @@ function handleMatchBuilds( // This tree includes start item as the root, then branching paths if (items.length > 0) { treeMerge(build.items, items) + // The first item is the starter item + startItemId = items[0].itemId } - return build + return { build, startItemId } } function handleMatch(match: Match, champions: Map, platform?: string) { @@ -365,14 +368,22 @@ function handleMatch(match: Match, champions: Map, platfor } // Items and runes (builds) - const build = handleMatchBuilds(match, participant, participantIndex, lane.builds, platform) + const { build, startItemId } = handleMatchBuilds( + match, + participant, + participantIndex, + lane.builds, + platform + ) - // First back data - store at build level + // First back data - store at build level with start item tracking const firstBackData = extractFirstBackFromMatch(match, participantIndex) if (firstBackData) { if (!build.firstBacksRaw) { build.firstBacksRaw = [] } + // Include the starter item ID for proper filtering when splitting builds + firstBackData.startItemId = startItemId build.firstBacksRaw.push(firstBackData) } } @@ -445,16 +456,44 @@ function splitMergeOnStarterItem(build: Build, championName: string): BuildWithS console.log(`Warning: for champion ${championName}, start item splits build variant.`) const builds = [] for (const c of build.items.children) { + // Calculate the ratio for proportional distribution + const ratio = c.count / build.count + + // Proportionally distribute boots counts + const scaledBoots = build.boots.map(b => ({ + data: b.data, + count: Math.round(b.count * ratio) + })) + + // Proportionally distribute suppItems counts + const scaledSuppItems = build.suppItems.map(s => ({ + data: s.data, + count: Math.round(s.count * ratio) + })) + + // Proportionally distribute bootsFirstCount + const scaledBootsFirstCount = Math.round(build.bootsFirstCount * ratio) + + // Filter firstBacksRaw by starter item + let filteredFirstBacksRaw: FirstBackData[] | undefined + if (build.firstBacksRaw && build.firstBacksRaw.length > 0) { + // Filter by the starter item ID that was tracked when storing firstBacksRaw + filteredFirstBacksRaw = build.firstBacksRaw.filter(fb => fb.startItemId === c.data) + if (filteredFirstBacksRaw.length === 0) { + filteredFirstBacksRaw = undefined + } + } + builds.push({ runeKeystone: build.runeKeystone, runes: build.runes, items: c, - bootsFirstCount: build.bootsFirstCount, + bootsFirstCount: scaledBootsFirstCount, count: c.count, startItems: [{ data: c.data!, count: c.count }], - suppItems: build.suppItems, - boots: build.boots, - firstBacksRaw: build.firstBacksRaw + suppItems: scaledSuppItems, + boots: scaledBoots, + firstBacksRaw: filteredFirstBacksRaw }) c.data = undefined } diff --git a/match_collector/src/types.ts b/match_collector/src/types.ts index 6175a7f..7786996 100644 --- a/match_collector/src/types.ts +++ b/match_collector/src/types.ts @@ -82,6 +82,7 @@ export interface ItemSet { export interface FirstBackData { timestamp: number itemSet: ItemSet + startItemId?: number } /**