From c7d0d929be053a6879a979c2ca7a1737ada68d47 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Thu, 30 Apr 2026 17:51:14 +0200 Subject: [PATCH] fix/match_collector: change region tagging logic --- match_collector/src/item_tree.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/match_collector/src/item_tree.ts b/match_collector/src/item_tree.ts index 9f3638e..db2c754 100644 --- a/match_collector/src/item_tree.ts +++ b/match_collector/src/item_tree.ts @@ -264,12 +264,8 @@ function deriveTags(node: ItemTree, expectedRegionDistribution?: PlatformCounts) const totalExpected = REGION_KEYS.reduce((sum, key) => sum + expectedRegionDistribution[key], 0) if (totalExpected > 0) { - // Tag if the item is significantly more popular in a region (>= 1.5x expected rate) - // and has a minimum absolute percentage (>= 10%) - const SIGNIFICANCE_THRESHOLD = 1.5 - const MINIMUM_PCT = 0.1 - - // Loop through all regions to derive tags + // Tag if one region accounts for >= 60% of the normalized distribution + // Normalized value = actual percentage / expected percentage ratio const regionTags: Array<{ key: keyof PlatformCounts; tag: ItemTag }> = [ { key: 'euw', tag: 'region_euw' }, { key: 'eun', tag: 'region_eun' }, @@ -277,12 +273,23 @@ function deriveTags(node: ItemTree, expectedRegionDistribution?: PlatformCounts) { key: 'kr', tag: 'region_kr' } ] - for (const { key, tag } of regionTags) { + // Calculate normalized values (actual/expected ratio) for each region + const normalizedValues = regionTags.map(({ key, tag }) => { const expectedPct = expectedRegionDistribution[key] / totalExpected const actualPct = node.platformCount[key] / totalRegionCount + const normalizedValue = expectedPct > 0 ? actualPct / expectedPct : 0 + return { tag, value: normalizedValue } + }) - if (actualPct >= expectedPct * SIGNIFICANCE_THRESHOLD && actualPct >= MINIMUM_PCT) { - tags.push(tag) + const totalNormalized = normalizedValues.reduce((sum, { value }) => sum + value, 0) + + // Tag the region if it accounts for >= 60% of the normalized distribution + if (totalNormalized > 0) { + for (const { tag, value } of normalizedValues) { + if (value / totalNormalized >= 0.6) { + tags.push(tag) + break // Only tag the most dominant region + } } } }