From 426d922b9bbb3cdbbdca9975b33bcaf4a6e80d6b Mon Sep 17 00:00:00 2001 From: sebastientromp Date: Fri, 17 Feb 2023 17:28:54 +0100 Subject: [PATCH] update stats building to better handle 10 tribes --- package.json | 2 +- src/build-battlegrounds-hero-stats-new.ts | 2 +- src/quests-v2/quests-v2.ts | 2 +- src/stats-v2/bgs-hero-stat.ts | 6 ++- src/stats-v2/stats-buikder.ts | 45 ++++++++++++++--------- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index fbdc770..bd1e99c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@firestone-hs/bgs-global-stats", - "version": "1.0.33", + "version": "1.0.35", "description": "", "scripts": { "lint": "eslint --color --fix --ext .ts .", diff --git a/src/build-battlegrounds-hero-stats-new.ts b/src/build-battlegrounds-hero-stats-new.ts index ca5eb89..c0064cd 100644 --- a/src/build-battlegrounds-hero-stats-new.ts +++ b/src/build-battlegrounds-hero-stats-new.ts @@ -339,7 +339,7 @@ const buildHeroStats = (rows: readonly InternalBgsRow[]): readonly BgsGlobalHero return result; }; -const buildWarbandStats = ( +export const buildWarbandStats = ( rows: readonly InternalBgsRow[], ): readonly { turn: number; dataPoints: number; totalStats: number }[] => { const data: { [turn: string]: { dataPoints: number; totalStats: number } } = {}; diff --git a/src/quests-v2/quests-v2.ts b/src/quests-v2/quests-v2.ts index 2aa77be..c40df35 100644 --- a/src/quests-v2/quests-v2.ts +++ b/src/quests-v2/quests-v2.ts @@ -18,7 +18,7 @@ export const handleQuestsV2 = async ( .filter(row => row.quests) .filter(row => !!row.bgsHeroQuestRewards?.length) .filter(row => !!row.bgsQuestsDifficulties?.length); - console.log('total relevant rows', rowsWithQuests?.length); + // console.log('total relevant rows', rowsWithQuests?.length); const statResult = await buildSplitStats(rowsWithQuests, timePeriod, lastPatch, (data: InternalBgsRow[]) => buildStats(data), diff --git a/src/stats-v2/bgs-hero-stat.ts b/src/stats-v2/bgs-hero-stat.ts index e4bbc83..d02203c 100644 --- a/src/stats-v2/bgs-hero-stat.ts +++ b/src/stats-v2/bgs-hero-stat.ts @@ -15,18 +15,20 @@ export interface BgsGlobalHeroStat { readonly averagePosition: number; readonly placementDistribution: readonly { rank: number; percentage: number }[]; readonly combatWinrate: readonly { turn: number; winrate: number }[]; - // // Same - // readonly warbandStats: readonly { turn: number; dataPoints: number; totalStats: number }[]; + readonly warbandStats: readonly { turn: number; averageStats: number }[]; readonly tribeStats: readonly BgsHeroTribeStat[]; } export interface BgsHeroTribeStat { readonly tribe: Race; readonly dataPoints: number; + readonly dataPointsOnMissingTribe: number; readonly averagePosition: number; readonly impactAveragePosition: number; readonly placementDistribution: readonly { rank: number; percentage: number }[]; readonly impactPlacementDistribution: readonly { rank: number; impact: number }[]; readonly combatWinrate: readonly { turn: number; winrate: number }[]; readonly impactCombatWinrate: readonly { turn: number; impact: number }[]; + readonly warbandStats: readonly { turn: number; averageStats: number }[]; + readonly impactWarbandStats: readonly { turn: number; impact: number }[]; } diff --git a/src/stats-v2/stats-buikder.ts b/src/stats-v2/stats-buikder.ts index 8deb866..197df8e 100644 --- a/src/stats-v2/stats-buikder.ts +++ b/src/stats-v2/stats-buikder.ts @@ -1,6 +1,6 @@ import { groupByFunction } from '@firestone-hs/aws-lambda-utils'; -import { AllCardsService, CardIds, Race } from '@firestone-hs/reference-data'; -import { buildCombatWinrate } from '../build-battlegrounds-hero-stats-new'; +import { AllCardsService, Race } from '@firestone-hs/reference-data'; +import { buildCombatWinrate, buildWarbandStats } from '../build-battlegrounds-hero-stats-new'; import { buildPlacementDistributionWithPercentages } from '../common'; import { InternalBgsRow } from '../internal-model'; import { normalizeHeroCardId } from '../utils/util-functions'; @@ -26,26 +26,20 @@ const buildStatsForSingleHero = (rows: readonly InternalBgsRow[]): BgsGlobalHero turn: info.turn, winrate: info.totalWinrate / info.dataPoints, })); + const rawWarbandStats = buildWarbandStats(rows); + const warbandStats: readonly { turn: number; averageStats: number }[] = rawWarbandStats.map(info => ({ + turn: info.turn, + averageStats: info.totalStats / info.dataPoints, + })); const result: BgsGlobalHeroStat = { heroCardId: ref.heroCardId, dataPoints: rows.length, averagePosition: averagePosition, placementDistribution: placementDistribution, combatWinrate: combatWinrate, - tribeStats: buildTribeStats(rows, averagePosition, placementDistribution, combatWinrate), + warbandStats: warbandStats, + tribeStats: buildTribeStats(rows, averagePosition, placementDistribution, combatWinrate, warbandStats), }; - if (ref.heroCardId === CardIds.PatchesThePirateBattlegrounds) { - console.debug('Patches sanity', result); - console.debug( - 'Patches sanity', - result.tribeStats.map(t => t.impactAveragePosition * t.dataPoints).reduce((a, b) => a + b, 0), - ); - console.debug( - 'Patches sanity', - rows.filter(r => !r.tribes.includes('' + Race.PIRATE)).length, - rows.filter(r => !r.tribes.includes('' + Race.PIRATE)), - ); - } return result; }; @@ -54,6 +48,7 @@ const buildTribeStats = ( refAveragePosition: number, refPlacementDistribution: readonly { rank: number; percentage: number }[], refCombatWinrate: readonly { turn: number; winrate: number }[], + refWarbandStats: readonly { turn: number; averageStats: number }[], ): readonly BgsHeroTribeStat[] => { const uniqueTribes: readonly Race[] = [...new Set(rows.flatMap(r => r.tribes.split(',')).map(r => parseInt(r)))]; return uniqueTribes.map(tribe => { @@ -66,6 +61,11 @@ const buildTribeStats = ( turn: info.turn, winrate: info.totalWinrate / info.dataPoints, })); + const rawWarbandStats = buildWarbandStats(rowsForTribe); + const warbandStats: readonly { turn: number; averageStats: number }[] = rawWarbandStats.map(info => ({ + turn: info.turn, + averageStats: info.totalStats / info.dataPoints, + })); return { tribe: tribe, dataPoints: rowsForTribe.length, @@ -77,7 +77,7 @@ const buildTribeStats = ( const newPlacementInfo = placementDistribution.find(p2 => p2.rank === p.rank); // Cna happen when there isn't a lot of data points, typically for high MMR if (!newPlacementInfo) { - console.log('missing placement info', placementDistribution, p); + // console.log('missing placement info', placementDistribution, p); } return { rank: p.rank, @@ -88,13 +88,24 @@ const buildTribeStats = ( impactCombatWinrate: refCombatWinrate.map(c => { const newCombatWinrate = combatWinrate.find(c2 => c2.turn === c.turn); if (!newCombatWinrate) { - console.debug('missing winrate info', combatWinrate); + // console.debug('missing winrate info', combatWinrate); } return { turn: c.turn, impact: (newCombatWinrate?.winrate ?? 0) - c.winrate, }; }), + warbandStats: warbandStats, + impactWarbandStats: refWarbandStats.map(c => { + const newWarbandStats = warbandStats.find(c2 => c2.turn === c.turn); + if (!newWarbandStats) { + // console.debug('missing warband info', warbandStats); + } + return { + turn: c.turn, + impact: (newWarbandStats?.averageStats ?? 0) - c.averageStats, + }; + }), }; }); };