fix/match_collector: change region tagging logic

This commit is contained in:
2026-04-30 17:51:14 +02:00
parent 8ee981b949
commit c7d0d929be

View File

@@ -264,12 +264,8 @@ function deriveTags(node: ItemTree, expectedRegionDistribution?: PlatformCounts)
const totalExpected = REGION_KEYS.reduce((sum, key) => sum + expectedRegionDistribution[key], 0) const totalExpected = REGION_KEYS.reduce((sum, key) => sum + expectedRegionDistribution[key], 0)
if (totalExpected > 0) { if (totalExpected > 0) {
// Tag if the item is significantly more popular in a region (>= 1.5x expected rate) // Tag if one region accounts for >= 60% of the normalized distribution
// and has a minimum absolute percentage (>= 10%) // Normalized value = actual percentage / expected percentage ratio
const SIGNIFICANCE_THRESHOLD = 1.5
const MINIMUM_PCT = 0.1
// Loop through all regions to derive tags
const regionTags: Array<{ key: keyof PlatformCounts; tag: ItemTag }> = [ const regionTags: Array<{ key: keyof PlatformCounts; tag: ItemTag }> = [
{ key: 'euw', tag: 'region_euw' }, { key: 'euw', tag: 'region_euw' },
{ key: 'eun', tag: 'region_eun' }, { key: 'eun', tag: 'region_eun' },
@@ -277,12 +273,23 @@ function deriveTags(node: ItemTree, expectedRegionDistribution?: PlatformCounts)
{ key: 'kr', tag: 'region_kr' } { 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 expectedPct = expectedRegionDistribution[key] / totalExpected
const actualPct = node.platformCount[key] / totalRegionCount 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) { 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) tags.push(tag)
break // Only tag the most dominant region
}
} }
} }
} }