Update and stabilise BPI synchronisation

This commit is contained in:
zkldi
2021-10-15 23:09:50 +01:00
parent 274646cfef
commit 6980322cf4
9 changed files with 59 additions and 18 deletions
@@ -1,7 +1,10 @@
import db from "external/mongo/db";
import CreateLogCtx from "lib/logger/logger";
import { CreateCalculatedData } from "lib/score-import/framework/calculated-data/calculated-data";
import { ProcessPBs } from "lib/score-import/framework/pb/process-pbs";
import { updateLanguageServiceSourceFile } from "typescript";
import { EfficientDBIterate } from "../../util/efficient-db-iterate";
import { UpdateAllPBs } from "./update-all-pbs";
const logger = CreateLogCtx(__filename);
@@ -43,6 +46,9 @@ export async function RecalcAllScores(filter = {}) {
filter
);
logger.info("Reprocessing PBs...");
await UpdateAllPBs(filter);
logger.info(`Done!`);
}
@@ -9,6 +9,7 @@ import CreateLogCtx from "lib/logger/logger";
import { config } from "process";
import { FindChartWithPTDFVersion } from "utils/queries/charts";
import { FindSongOnTitle } from "utils/queries/songs";
import { RecalcAllScores } from "../__KT_DATABASE_MIGRATION/state-sync/recalc-all-scores";
const program = new Command();
@@ -35,9 +36,7 @@ async function UpdatePoyashiData() {
if (options.fetch) {
// lol!
logger.info("Fetching data from github...");
const rj = await fetch(
"https://raw.githubusercontent.com/potakusan/bpim-score-repo/master/output/release.json"
).then((r) => r.json());
const rj = await fetch("https://proxy.poyashi.me/?type=bpi").then((r) => r.json());
logger.info("Fetched data.");
fs.writeFileSync(dataLoc, JSON.stringify(rj));
@@ -71,7 +70,7 @@ async function UpdatePoyashiData() {
tachiSong.id,
playtype as "SP" | "DP",
diff as Difficulties["iidx:DP" | "iidx:SP"],
"28"
"27"
)) as ChartDocument<"iidx:SP" | "iidx:DP">;
if (!tachiChart) {
@@ -90,6 +89,11 @@ async function UpdatePoyashiData() {
continue;
}
if (d.removed) {
logger.info(`Skipping removed chart ${tachiSong.title}.`);
continue;
}
realData.push({
coef: d.coef === -1 ? null : d.coef,
kavg: Number(d.avg),
@@ -102,6 +106,14 @@ async function UpdatePoyashiData() {
await db["iidx-bpi-data"].insert(realData);
logger.info(`Removed all, and inserted ${realData.length} documents.`);
logger.info(`Triggering IIDX Recalc.`);
await RecalcAllScores({ game: "iidx" });
logger.info(`Done.`);
}
UpdatePoyashiData();
if (require.main === module) {
UpdatePoyashiData();
}
@@ -53,6 +53,21 @@ t.test("#CalculateBPI", (t) => {
t.end();
});
t.test("COLOSSEUM BPI Tests", (t) => {
const WR_AFT = 2312;
const KAVG_CL = 2131;
const MAX_CL = 2318;
const COEF_CL = -1;
function CL_BPI(yourEx: number) {
return CalculateBPI(KAVG_CL, WR_AFT, yourEx, MAX_CL, COEF_CL);
}
isApproximately(CL_BPI(2307), 79.63);
t.end();
});
// This song has both no co-efficient and is an sp11, so it serves
// as another interesting test.
t.test("Afterimage d'automne BPI tests", (t) => {
@@ -6,7 +6,6 @@ import {
Game,
Playtypes,
GetGamePTConfig,
IDStrings,
} from "tachi-common";
import { KtLogger } from "lib/logger/logger";
import { DryScore } from "../common/types";
@@ -78,7 +77,11 @@ export function CalculateBPI(
max: integer,
pc: number | null
) {
const powCoef = pc ?? 1.175;
let powCoef = pc ?? 1.175;
if (powCoef === -1) {
powCoef = 1.175;
}
const yourPGF = BPIPikaGreatFn(yourEx, max);
const kaidenPGF = BPIPikaGreatFn(kaidenEx, max);
const wrPGF = BPIPikaGreatFn(wrEx, max);
@@ -90,8 +93,7 @@ export function CalculateBPI(
const isBetterThanKavg = yourEx >= kaidenEx;
// this line of code isn't mine, and that's why it's *really* bad here.
return Math.max(
-15,
const bpi =
Math.round(
(isBetterThanKavg ? 100 : -100) *
Math.pow(
@@ -99,8 +101,13 @@ export function CalculateBPI(
powCoef
) *
100
) / 100
);
) / 100;
if (bpi < -15) {
return -15;
}
return bpi;
}
/**
@@ -11,7 +11,7 @@ t.test("GET /api/v1/users/:userID/banner", (t) => {
t.beforeEach(ResetDBState);
t.test("Should return the default profile banner if user has no custom banner", async (t) => {
await CDNStoreOrOverwrite("/users/default/banner.png", "test");
await CDNStoreOrOverwrite("/users/default/banner", "test");
const res = await mockApi.get("/api/v1/users/1/banner").redirects(1);
t.equal(res.body.toString(), "test");
@@ -86,7 +86,7 @@ router.get("/", (req, res) => {
if (!user.customBanner) {
res.setHeader("Content-Type", "image/png");
return CDNRedirect(res, "/users/default/banner.png");
return CDNRedirect(res, "/users/default/banner");
}
// express sniffs whether this is a png or jpg **and** browsers dont care either.
@@ -11,7 +11,7 @@ t.test("GET /api/v1/users/:userID/pfp", (t) => {
t.beforeEach(ResetDBState);
t.test("Should return the default profile picture if user has no custom pfp", async (t) => {
await CDNStoreOrOverwrite("/users/default/pfp.png", "test");
await CDNStoreOrOverwrite("/users/default/pfp", "test");
// we have to follow redirs here lol
const res = await mockApi.get("/api/v1/users/1/pfp").redirects(1);
@@ -84,7 +84,7 @@ router.get("/", (req, res) => {
if (!user.customPfp) {
res.setHeader("Content-Type", "image/png");
return CDNRedirect(res, "/users/default/pfp.png");
return CDNRedirect(res, "/users/default/pfp");
}
return CDNRedirect(res, GetProfilePictureURL(user.id));
+4 -3
View File
@@ -1,14 +1,15 @@
import { rootLogger } from "lib/logger/logger";
import Prudence, { PrudenceSchema } from "prudence";
import t from "tap";
export function isApproximately(number: number, target: number, message: string, lenience = 0.01) {
export function isApproximately(number: number, target: number, message?: string, lenience = 0.01) {
const result = t.ok(Math.abs(number - target) < lenience, message);
if (!result) {
throw new Error(`${number} was not close enough to ${target}`);
rootLogger.error(`${number} was not close enough to ${target}`);
}
return true;
// return true;
}
export function prAssert(