From e86c8c11cb68ad72ab0faf00de63d0b3165b5520 Mon Sep 17 00:00:00 2001 From: sebastientromp Date: Mon, 24 Oct 2022 10:58:19 +0200 Subject: [PATCH] fix normalization of cards --- package-lock.json | 23 +++++++++++------------ package.json | 2 +- src/build-battlegrounds-hero-stats-new.ts | 12 ++++++++---- src/common.ts | 8 ++++++-- src/utils/util-functions.ts | 15 +++++++-------- 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index a35582f..37f3bca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -330,9 +330,9 @@ } }, "@firestone-hs/reference-data": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@firestone-hs/reference-data/-/reference-data-1.0.1.tgz", - "integrity": "sha512-Yf4P4VVHm6u3SwQQbU2Zzfu0XqPtp61TxzZI3tX2KB6Q3qZObhmGiy0zQMN9RPXyvZN0WtZ7oReli4z2M+3AGQ==", + "version": "1.0.29", + "resolved": "https://registry.npmjs.org/@firestone-hs/reference-data/-/reference-data-1.0.29.tgz", + "integrity": "sha512-vlAqymMKxra/pzSBTdzPLQIPCw5LUZGKhl+1WMgGSVENWMn3nFVvJS+yPjOn501iBa2e7xzOfo7Wnd50yuUwVQ==", "requires": { "cross-fetch": "^3.0.4", "rxjs": "~6.6.7", @@ -1294,9 +1294,9 @@ } }, "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, "base": { @@ -1908,7 +1908,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, "concat-stream": { @@ -3268,8 +3268,7 @@ }, "minimatch": { "version": "3.0.4", - "resolved": false, - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "resolved": "", "dev": true, "optional": true, "requires": { @@ -5298,9 +5297,9 @@ "dev": true }, "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, "requires": { "brace-expansion": "^1.1.7" diff --git a/package.json b/package.json index aab235a..0880737 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/build-battlegrounds-hero-stats-new.ts b/src/build-battlegrounds-hero-stats-new.ts index 4354dee..b5455e7 100644 --- a/src/build-battlegrounds-hero-stats-new.ts +++ b/src/build-battlegrounds-hero-stats-new.ts @@ -82,6 +82,7 @@ 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); @@ -89,7 +90,7 @@ const dispatchNewLambdas = async (rows: readonly InternalBgsRow[], context: Cont 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 = { @@ -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 => ({ @@ -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); @@ -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, @@ -400,7 +404,7 @@ const loadRows = async (mysql: ServerlessMysql): Promise ({ ...row, - heroCardId: normalizeHeroCardId(row.heroCardId), + heroCardId: normalizeHeroCardId(row.heroCardId, allCards), })); }; diff --git a/src/common.ts b/src/common.ts index d39d57e..385e5db 100644 --- a/src/common.ts +++ b/src/common.ts @@ -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; diff --git a/src/utils/util-functions.ts b/src/utils/util-functions.ts index f7183c5..cc2fb45 100644 --- a/src/utils/util-functions.ts +++ b/src/utils/util-functions.ts @@ -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);