Skip to content

Commit

Permalink
update stats building to better handle 10 tribes
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastientromp committed Feb 17, 2023
1 parent 88d0c70 commit 426d922
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 .",
Expand Down
2 changes: 1 addition & 1 deletion src/build-battlegrounds-hero-stats-new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } } = {};
Expand Down
2 changes: 1 addition & 1 deletion src/quests-v2/quests-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 4 additions & 2 deletions src/stats-v2/bgs-hero-stat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }[];
}
45 changes: 28 additions & 17 deletions src/stats-v2/stats-buikder.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
};

Expand All @@ -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 => {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
};
}),
};
});
};
Expand Down

0 comments on commit 426d922

Please sign in to comment.