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
main
imspace 2022-12-21 02:49:30 +08:00 committed by GitHub
parent d2e0885fb2
commit 4c8fa4102e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 27 deletions

View File

@ -1,3 +1,7 @@
## 0.2.7
fix: RankTracker shouldn't return -1 rankPoint
## 0.2.6 ## 0.2.6
feat: add tri-color support feat: add tri-color support

View File

@ -113,7 +113,7 @@ Deno.test("RankTracker autotrack after promotion", async () => {
isPromo: true, isPromo: true,
isUdemaeUp: true, isUdemaeUp: true,
udemaeAfter: "A-", udemaeAfter: "A-",
earnedUdemaePoint: null, earnedUdemaePoint: -233,
}, },
historyDetails: { historyDetails: {
nodes: [{ nodes: [{
@ -146,7 +146,7 @@ Deno.test("RankTracker autotrack after promotion", async () => {
before: { before: {
gameId: await gameId(genId(0)), gameId: await gameId(genId(0)),
rank: "B+", rank: "B+",
rankPoint: -1, rankPoint: 433,
timestamp: 1640995200, timestamp: 1640995200,
}, },
after: { after: {
@ -176,10 +176,17 @@ Deno.test("RankTracker issue #36", async () => {
isPromo: true, isPromo: true,
isUdemaeUp: true, isUdemaeUp: true,
udemaeAfter: "S+20", udemaeAfter: "S+20",
earnedUdemaePoint: null, earnedUdemaePoint: -3450,
}, },
historyDetails: { historyDetails: {
nodes: [{ nodes: [{
id: genId(2),
udemae: "S+19",
judgement: "WIN",
bankaraMatch: {
earnedUdemaePoint: null,
},
}, {
id: genId(1), id: genId(1),
udemae: "S+19", udemae: "S+19",
judgement: "WIN", 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, { assertEquals(finalState, {
gameId: gameId1, gameId: gameId2,
rank: "S+20", rank: "S+20",
rankPoint: 300, rankPoint: 300,
timestamp: 1640995201, timestamp: 1640995202,
}); });
assertEquals(await tracker.getRankStateById(genId(0)), undefined); assertEquals(await tracker.getRankStateById(genId(0)), undefined);
assertEquals(await tracker.getRankStateById(genId(1)), { assertEquals(await tracker.getRankStateById(genId(1)), {
before: { before: {
gameId: await gameId(genId(0)), gameId: await gameId(genId(0)),
rank: "S+19", rank: "S+19",
rankPoint: -1, rankPoint: 3750,
timestamp: 1640995200, timestamp: 1640995200,
}, },
after: { 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", rank: "S+20",
rankPoint: 300, rankPoint: 300,
timestamp: 1640995201, timestamp: 1640995202,
}, },
}); });
}); });

View File

@ -5,7 +5,7 @@ import {
HistoryGroups, HistoryGroups,
RankParam, RankParam,
} from "./types.ts"; } from "./types.ts";
import { gameId, parseHistoryDetailId } from "./utils.ts"; import { gameId, nonNullable, parseHistoryDetailId } from "./utils.ts";
const splusParams = () => { const splusParams = () => {
const out: RankParam[] = []; const out: RankParam[] = [];
@ -234,19 +234,29 @@ function generateDeltaList(
function getRankState(i: FlattenItem): RankState { function getRankState(i: FlattenItem): RankState {
const rank = i.detail.udemae; const rank = i.detail.udemae;
if (!rank) { const nextRank = i.bankaraMatchChallenge?.udemaeAfter;
throw new Error("rank must be defined"); 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 param = RANK_PARAMS.find((i) => i.rank === rank);
const nextParam = RANK_PARAMS.find((i) => i.rank === nextRank);
if (!param) { if (!param || !nextParam) {
throw new Error(`Rank not found: ${rank}`); throw new Error(`Rank or nextRank not found: ${rank} ${nextRank}`);
} }
const oldRankPoint = nextParam.pointRange[0] -
earnedUdemaePoint;
return { return {
gameId: i.gameId, gameId: i.gameId,
timestamp: Math.floor(i.time.getTime() / 1000), timestamp: Math.floor(i.time.getTime() / 1000),
rank, rank,
rankPoint: -1, rankPoint: oldRankPoint,
}; };
} }

View File

@ -1,7 +1,7 @@
import type { StatInkPostBody, VsHistoryDetail } from "./types.ts"; import type { StatInkPostBody, VsHistoryDetail } from "./types.ts";
export const AGENT_NAME = "s3si.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 NSOAPP_VERSION = "2.4.0";
export const WEB_VIEW_VERSION = "2.0.0-bd36a652"; export const WEB_VIEW_VERSION = "2.0.0-bd36a652";
export const S3SI_LINK = "https://github.com/spacemeowx2/s3si.ts"; export const S3SI_LINK = "https://github.com/spacemeowx2/s3si.ts";

View File

@ -586,16 +586,6 @@ export class StatInkExporter implements GameExporter {
result.rank_exp_change === undefined result.rank_exp_change === undefined
) { ) {
result.rank_exp_change = result.rank_after_exp - result.rank_before_exp; 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) { if (!result.rank_after) {