fix/match_collector: change region tagging logic
This commit is contained in:
@@ -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) {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user