Skip to content

Commit

Permalink
fix normalization of cards
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastientromp committed Oct 24, 2022
1 parent 001bea6 commit e86c8c1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
23 changes: 11 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dependencies": {
"@firestone-hs/aws-lambda-utils": "0.0.27",
"@firestone-hs/hs-replay-xml-parser": "0.0.78",
"@firestone-hs/reference-data": "^1.0.1",
"@firestone-hs/reference-data": "^1.0.29",
"@types/elementtree": "^0.1.0",
"JSONStream": "^1.3.5",
"aws-sdk": "^2.1040.0",
Expand Down
12 changes: 8 additions & 4 deletions src/build-battlegrounds-hero-stats-new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ const dispatchQuestsLambda = async (rows: readonly InternalBgsRow[], context: Co
.promise();
logger.log('\tinvocation result', result);
};

const dispatchNewLambdas = async (rows: readonly InternalBgsRow[], context: Context) => {
const allTribes = extractAllTribes(rows);
logger.log('all tribes', allTribes);
const tribePermutations: ('all' | Race[])[] = ['all', ...combine(allTribes, 5)];
logger.log('tribe permutations, should be 127 (126 + 1), because 9 tribes', tribePermutations.length);
for (const tribes of tribePermutations) {
logger.log('handling tribes', tribes, tribes !== 'all' && tribes.join('-'));
// if (tribes === 'all' || tribes.join('-') !== '17-20-23-43-92') {
// if (tribes !== 'all') {
// continue;
// }
const newEvent = {
Expand Down Expand Up @@ -122,11 +123,14 @@ const handlePermutation = async (
rows: readonly InternalBgsRow[],
lastPatch: PatchInfo,
) => {
console.log('total rows', rows.length);
const rowsForTimePeriod = filterRowsForTimePeriod(rows, timePeriod, lastPatch);
console.log('rows for time period', rowsForTimePeriod.length);
const tribesStr = tribes === 'all' ? null : tribes.join(',');
const rowsWithTribes = !!tribesStr
? rowsForTimePeriod.filter(row => !!row.tribes).filter(row => row.tribes === tribesStr)
: rowsForTimePeriod;
console.log('rowsWithTribes', rowsWithTribes.length);
const mmrPercentiles: readonly MmrPercentile[] = buildMmrPercentiles(rowsWithTribes);
logger.log('handling permutation', tribes, timePeriod, rows?.length, rowsWithTribes?.length);
const stats: readonly BgsGlobalHeroStat2[] = buildHeroes(rowsWithTribes, mmrPercentiles).map(stat => ({
Expand Down Expand Up @@ -254,7 +258,7 @@ const buildHeroes = (
const buildHeroStats = (rows: readonly InternalBgsRow[]): readonly BgsGlobalHeroStat2[] => {
const grouped: { [groupingKey: string]: readonly InternalBgsRow[] } = groupByFunction(
// (row: InternalBgsRow) => `${row.heroCardId}-${row.darkmoonPrizes}`,
(row: InternalBgsRow) => row.heroCardId,
(row: InternalBgsRow) => normalizeHeroCardId(row.heroCardId, allCards),
)(rows);
// logger.log('grouped', Object.keys(grouped).length);

Expand All @@ -264,7 +268,7 @@ const buildHeroStats = (rows: readonly InternalBgsRow[]): readonly BgsGlobalHero
const combatWinrate = buildCombatWinrate(groupedRows);
const warbandStats = buildWarbandStats(groupedRows);
return {
cardId: ref.heroCardId,
cardId: normalizeHeroCardId(ref.heroCardId, allCards),
totalMatches: groupedRows.length,
placementDistribution: placementDistribution,
combatWinrate: combatWinrate,
Expand Down Expand Up @@ -400,7 +404,7 @@ const loadRows = async (mysql: ServerlessMysql): Promise<readonly InternalBgsRow
)
.map(row => ({
...row,
heroCardId: normalizeHeroCardId(row.heroCardId),
heroCardId: normalizeHeroCardId(row.heroCardId, allCards),
}));
};

Expand Down
8 changes: 6 additions & 2 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ export const filterRowsForTimePeriod = (
new Date(row.creationDate) > new Date(new Date(lastPatch.date).getTime() + 24 * 60 * 60 * 1000),
);
case 'past-three':
return rows.filter(row => new Date(row.creationDate) > new Date(new Date().getTime() - 3 * 60 * 60 * 1000));
return rows.filter(
row => new Date(row.creationDate) > new Date(new Date().getTime() - 3 * 24 * 60 * 60 * 1000),
);
case 'past-seven':
return rows.filter(row => new Date(row.creationDate) > new Date(new Date().getTime() - 7 * 60 * 60 * 1000));
return rows.filter(
row => new Date(row.creationDate) > new Date(new Date().getTime() - 7 * 24 * 60 * 60 * 1000),
);
case 'all-time':
default:
return rows;
Expand Down
15 changes: 7 additions & 8 deletions src/utils/util-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ export const getCardFromCardId = (cardId: number | string, cards: AllCardsServic
return card;
};

export const normalizeHeroCardId = (heroCardId: string, allCards: AllCardsService = null): string => {
export const normalizeHeroCardId = (heroCardId: string, allCards: AllCardsService): string => {
if (!heroCardId) {
return heroCardId;
}

if (allCards) {
const heroCard = allCards.getCard(heroCardId);
if (!!heroCard?.battlegroundsHeroParentDbfId) {
const parentCard = allCards.getCardFromDbfId(heroCard.battlegroundsHeroParentDbfId);
if (!!parentCard) {
return parentCard.id;
}
const heroCard = allCards.getCard(heroCardId);
if (!!heroCard?.battlegroundsHeroParentDbfId) {
const parentCard = allCards.getCardFromDbfId(heroCard.battlegroundsHeroParentDbfId);
if (!!parentCard) {
return parentCard.id;
}
}

// Fallback to regex
const bgHeroSkinMatch = heroCardId.match(/(.*)_SKIN_.*/);
// logger.debug('normalizing', heroCardId, bgHeroSkinMatch);
Expand Down

0 comments on commit e86c8c1

Please sign in to comment.