From 4c8fa4102e466e7029a1d77045965e18b14724e8 Mon Sep 17 00:00:00 2001 From: imspace Date: Wed, 21 Dec 2022 02:49:30 +0800 Subject: [PATCH] fix: RankTracker shouldn't return -1 rankPoint (#58) * fix: RankTracker returns wrong rankPoint * fix: remove rank exp change calc * test: fix RankTracker test * build: bump version --- CHANGELOG.md | 4 ++++ src/RankTracker.test.ts | 41 +++++++++++++++++++++++++++++---------- src/RankTracker.ts | 22 +++++++++++++++------ src/constant.ts | 2 +- src/exporters/stat.ink.ts | 10 ---------- 5 files changed, 52 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0787a0d..7967b54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.7 + +fix: RankTracker shouldn't return -1 rankPoint + ## 0.2.6 feat: add tri-color support diff --git a/src/RankTracker.test.ts b/src/RankTracker.test.ts index 738ca87..ead7185 100644 --- a/src/RankTracker.test.ts +++ b/src/RankTracker.test.ts @@ -113,7 +113,7 @@ Deno.test("RankTracker autotrack after promotion", async () => { isPromo: true, isUdemaeUp: true, udemaeAfter: "A-", - earnedUdemaePoint: null, + earnedUdemaePoint: -233, }, historyDetails: { nodes: [{ @@ -146,7 +146,7 @@ Deno.test("RankTracker autotrack after promotion", async () => { before: { gameId: await gameId(genId(0)), rank: "B+", - rankPoint: -1, + rankPoint: 433, timestamp: 1640995200, }, after: { @@ -176,10 +176,17 @@ Deno.test("RankTracker issue #36", async () => { isPromo: true, isUdemaeUp: true, udemaeAfter: "S+20", - earnedUdemaePoint: null, + earnedUdemaePoint: -3450, }, historyDetails: { nodes: [{ + id: genId(2), + udemae: "S+19", + judgement: "WIN", + bankaraMatch: { + earnedUdemaePoint: null, + }, + }, { id: genId(1), udemae: "S+19", judgement: "WIN", @@ -197,28 +204,42 @@ Deno.test("RankTracker issue #36", async () => { }, }]); - const gameId1 = await gameId(genId(1)); + const gameId2 = await gameId(genId(2)); assertEquals(finalState, { - gameId: gameId1, + gameId: gameId2, rank: "S+20", rankPoint: 300, - timestamp: 1640995201, + timestamp: 1640995202, }); assertEquals(await tracker.getRankStateById(genId(0)), undefined); - assertEquals(await tracker.getRankStateById(genId(1)), { before: { gameId: await gameId(genId(0)), rank: "S+19", - rankPoint: -1, + rankPoint: 3750, timestamp: 1640995200, }, after: { - gameId: gameId1, + gameId: await gameId(genId(1)), + rank: "S+19", + rankPoint: 3750, + timestamp: 1640995201, + }, + }); + + assertEquals(await tracker.getRankStateById(genId(2)), { + before: { + gameId: await gameId(genId(1)), + rank: "S+19", + rankPoint: 3750, + timestamp: 1640995201, + }, + after: { + gameId: gameId2, rank: "S+20", rankPoint: 300, - timestamp: 1640995201, + timestamp: 1640995202, }, }); }); diff --git a/src/RankTracker.ts b/src/RankTracker.ts index 022f08a..cc33f00 100644 --- a/src/RankTracker.ts +++ b/src/RankTracker.ts @@ -5,7 +5,7 @@ import { HistoryGroups, RankParam, } from "./types.ts"; -import { gameId, parseHistoryDetailId } from "./utils.ts"; +import { gameId, nonNullable, parseHistoryDetailId } from "./utils.ts"; const splusParams = () => { const out: RankParam[] = []; @@ -234,19 +234,29 @@ function generateDeltaList( function getRankState(i: FlattenItem): RankState { const rank = i.detail.udemae; - if (!rank) { - throw new Error("rank must be defined"); + const nextRank = i.bankaraMatchChallenge?.udemaeAfter; + const earnedUdemaePoint = i.bankaraMatchChallenge?.earnedUdemaePoint; + if (!nonNullable(earnedUdemaePoint)) { + throw new TypeError("earnedUdemaePoint must be defined"); + } + if (!rank || !nextRank) { + throw new Error("rank and nextRank must be defined"); } const param = RANK_PARAMS.find((i) => i.rank === rank); + const nextParam = RANK_PARAMS.find((i) => i.rank === nextRank); - if (!param) { - throw new Error(`Rank not found: ${rank}`); + if (!param || !nextParam) { + throw new Error(`Rank or nextRank not found: ${rank} ${nextRank}`); } + + const oldRankPoint = nextParam.pointRange[0] - + earnedUdemaePoint; + return { gameId: i.gameId, timestamp: Math.floor(i.time.getTime() / 1000), rank, - rankPoint: -1, + rankPoint: oldRankPoint, }; } diff --git a/src/constant.ts b/src/constant.ts index b41bd0f..328271b 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -1,7 +1,7 @@ import type { StatInkPostBody, VsHistoryDetail } from "./types.ts"; export const AGENT_NAME = "s3si.ts"; -export const S3SI_VERSION = "0.2.6"; +export const S3SI_VERSION = "0.2.7"; export const NSOAPP_VERSION = "2.4.0"; export const WEB_VIEW_VERSION = "2.0.0-bd36a652"; export const S3SI_LINK = "https://github.com/spacemeowx2/s3si.ts"; diff --git a/src/exporters/stat.ink.ts b/src/exporters/stat.ink.ts index dac22fa..e69d55c 100644 --- a/src/exporters/stat.ink.ts +++ b/src/exporters/stat.ink.ts @@ -586,16 +586,6 @@ export class StatInkExporter implements GameExporter { result.rank_exp_change === undefined ) { result.rank_exp_change = result.rank_after_exp - result.rank_before_exp; - } else if ( - bankaraMatchChallenge?.isUdemaeUp && - bankaraMatchChallenge.earnedUdemaePoint - ) { - // If the before state is generated by auto promotion, the rank_before_exp is wrong. - // And `earnedUdemaePoint` from splatnet3 is -xxx. - // So we calcuate `rank_before_exp` and remove `rank_exp_change` here - result.rank_before_exp = result.rank_after_exp - - bankaraMatchChallenge.earnedUdemaePoint; - result.rank_exp_change = undefined; } if (!result.rank_after) {