Rename ugptstats to showcase stats

This commit is contained in:
zkldi
2021-07-24 03:11:00 +01:00
parent 78ca5d22c8
commit 75f16d84c6
9 changed files with 41 additions and 41 deletions
+4 -4
View File
@@ -84,7 +84,7 @@ dependencies:
redis: 3.1.2
rimraf: 3.0.2
safe-json-stringify: 1.2.0
tachi-common: github.com/zkldi/tachi-common/dbfc3f67f73fb16e00adfaf5ec713f4e43cec2f9_ts-node@10.0.0+typescript@4.3.4
tachi-common: github.com/zkldi/tachi-common/21c3bb4cc4407601a902e049fb1e1b774b793e40_ts-node@10.0.0+typescript@4.3.4
typescript: 4.3.4
winston: 3.3.3
@@ -4226,9 +4226,9 @@ packages:
engines: {node: '>=6'}
dev: true
github.com/zkldi/tachi-common/dbfc3f67f73fb16e00adfaf5ec713f4e43cec2f9_ts-node@10.0.0+typescript@4.3.4:
resolution: {tarball: https://codeload.github.com/zkldi/tachi-common/tar.gz/dbfc3f67f73fb16e00adfaf5ec713f4e43cec2f9}
id: github.com/zkldi/tachi-common/dbfc3f67f73fb16e00adfaf5ec713f4e43cec2f9
github.com/zkldi/tachi-common/21c3bb4cc4407601a902e049fb1e1b774b793e40_ts-node@10.0.0+typescript@4.3.4:
resolution: {tarball: https://codeload.github.com/zkldi/tachi-common/tar.gz/21c3bb4cc4407601a902e049fb1e1b774b793e40}
id: github.com/zkldi/tachi-common/21c3bb4cc4407601a902e049fb1e1b774b793e40
name: tachi-common
version: 0.1.0
dependencies:
@@ -1,6 +1,6 @@
import deepmerge from "deepmerge";
import t from "tap";
import { EvaluateUGPTStat } from "./evaluator";
import { EvaluateShowcaseStat } from "./evaluator";
import { CloseAllConnections } from "../../test-utils/close-connections";
import ResetDBState from "../../test-utils/resets";
import {
@@ -19,9 +19,9 @@ t.beforeEach(ResetDBState);
t.beforeEach(async () => await CreateFolderChartLookup(TestingIIDXFolderSP10));
t.beforeEach(async () => await db["personal-bests"].insert(deepmerge(TestingIIDXSPScorePB, {})));
t.test("#EvaluateUGPTStat", (t) => {
t.test("#EvaluateShowcaseStat", (t) => {
t.test("Should evaluate a folder stat.", async (t) => {
const data = await EvaluateUGPTStat(
const data = await EvaluateShowcaseStat(
{
folderID: TestingIIDXFolderSP10.folderID,
mode: "folder",
@@ -40,7 +40,7 @@ t.test("#EvaluateUGPTStat", (t) => {
});
t.test("Should evaluate a multi-folder stat.", async (t) => {
const data = await EvaluateUGPTStat(
const data = await EvaluateShowcaseStat(
{
folderID: [TestingIIDXFolderSP10.folderID],
mode: "folder",
@@ -59,7 +59,7 @@ t.test("#EvaluateUGPTStat", (t) => {
});
t.test("Should evaluate a chart stat.", async (t) => {
const data = await EvaluateUGPTStat(
const data = await EvaluateShowcaseStat(
{
chartID: Testing511SPA.chartID,
mode: "chart",
@@ -76,7 +76,7 @@ t.test("#EvaluateUGPTStat", (t) => {
});
t.test("Should return null if the user has no score on this chart.", async (t) => {
const data = await EvaluateUGPTStat(
const data = await EvaluateShowcaseStat(
{
chartID: "nonsense",
mode: "chart",
@@ -1,25 +1,25 @@
import { integer, UGPTStatDetails, UGPTStatChart, UGPTStatFolder } from "tachi-common";
import { integer, ShowcaseStatDetails, ShowcaseStatChart, ShowcaseStatFolder } from "tachi-common";
import db from "../../external/mongo/db";
import { GetFolderChartIDs } from "../../utils/folder";
export function EvaluateUGPTStat(
details: UGPTStatDetails,
export function EvaluateShowcaseStat(
details: ShowcaseStatDetails,
userID: integer
): Promise<{
value: number | null;
outOf?: number;
}> {
if (details.mode === "chart") {
return EvaluateUGPTChartStat(details, userID);
return EvaluateShowcaseChartStat(details, userID);
} else if (details.mode === "folder") {
return EvaluateUGPTFolderStat(details, userID);
return EvaluateShowcaseFolderStat(details, userID);
}
// @ts-expect-error This should never happen anyway.
throw new Error(`Invalid mode of ${details.mode} as details mode?`);
}
async function EvaluateUGPTChartStat(details: UGPTStatChart, userID: integer) {
async function EvaluateShowcaseChartStat(details: ShowcaseStatChart, userID: integer) {
// requires special handling
if (details.property === "playcount") {
return { value: await db.scores.count({ chartID: details.chartID, userID }) };
@@ -41,7 +41,7 @@ async function EvaluateUGPTChartStat(details: UGPTStatChart, userID: integer) {
return { value: pb.scoreData[scProp] };
}
async function EvaluateUGPTFolderStat(details: UGPTStatFolder, userID: integer) {
async function EvaluateShowcaseFolderStat(details: ShowcaseStatFolder, userID: integer) {
let chartIDs;
if (Array.isArray(details.folderID)) {
chartIDs = (await Promise.all(details.folderID.map(GetFolderChartIDs))).flat(1);
@@ -1,10 +1,10 @@
import db from "external/mongo/db";
import CreateLogCtx from "lib/logger/logger";
import { Game, UGPTStatDetails } from "tachi-common";
import { Game, ShowcaseStatDetails } from "tachi-common";
const logger = CreateLogCtx(__filename);
export async function GetRelatedStatDocuments(stat: UGPTStatDetails, game: Game) {
export async function GetRelatedStatDocuments(stat: ShowcaseStatDetails, game: Game) {
if (stat.mode === "chart") {
const chart = await db.charts[game].findOne({ chartID: stat.chartID });
@@ -8,7 +8,7 @@ import {
TestingIIDXSPScorePB,
} from "../../test-utils/test-data";
import { IIDX_LAMPS } from "../constants/game";
import { EvaluateUsersGPTStats } from "./get-stats";
import { EvaluateUsersStatsShowcase } from "./get-stats";
import deepmerge from "deepmerge";
import { CreateFolderChartLookup } from "../../utils/folder";
@@ -47,9 +47,9 @@ t.beforeEach(async () => {
await db["personal-bests"].insert(deepmerge(TestingIIDXSPScorePB, {}));
});
t.test("#EvalulateUsersGPTStats", (t) => {
t.test("#EvalulateUsersStatsShowcase", (t) => {
t.test("Should evaluate a user's preferred stats.", async (t) => {
const res = await EvaluateUsersGPTStats(1, "iidx", "SP");
const res = await EvaluateUsersStatsShowcase(1, "iidx", "SP");
t.hasStrict(res, [
{
@@ -89,7 +89,7 @@ t.test("#EvalulateUsersGPTStats", (t) => {
t.test("Should throw an error if the user does not have game-settings.", async (t) => {
await db["game-settings"].remove({});
t.rejects(() => EvaluateUsersGPTStats(1, "iidx", "SP"));
t.rejects(() => EvaluateUsersStatsShowcase(1, "iidx", "SP"));
t.end();
});
@@ -105,7 +105,7 @@ t.test("#EvalulateUsersGPTStats", (t) => {
})
);
const res = await EvaluateUsersGPTStats(2, "iidx", "SP", 1);
const res = await EvaluateUsersStatsShowcase(2, "iidx", "SP", 1);
t.hasStrict(res, [
{
@@ -1,17 +1,17 @@
import db from "../../external/mongo/db";
import { integer, Game, Playtypes, UGPTStatDetails } from "tachi-common";
import { integer, Game, Playtypes, ShowcaseStatDetails } from "tachi-common";
import CreateLogCtx from "../logger/logger";
import { EvaluateUGPTStat } from "./evaluator";
import { EvaluateShowcaseStat } from "./evaluator";
import { GetRelatedStatDocuments } from "./get-related";
const logger = CreateLogCtx(__filename);
/**
* Evaluate a users set GPT Stats.
* @param projectUserStats - Optionally, provide another users ID here. Their set stats will be
* Evaluate a users set Stats Showcase.
* @param projectUserStats - Optionally, provide another users ID here. Their stats showcase will be
* used instead.
*/
export async function EvaluateUsersGPTStats(
export async function EvaluateUsersStatsShowcase(
userID: integer,
game: Game,
playtype: Playtypes[Game],
@@ -26,11 +26,11 @@ export async function EvaluateUsersGPTStats(
if (!settings) {
logger.error(
`User ${getSettingsID} has no game-settings, yet a call to EvalulateUsersGPTStats was made.`
`User ${getSettingsID} has no game-settings, yet a call to EvaluateUsersStatsShowcase was made.`
);
throw new Error(
`User ${getSettingsID} has no game-settings, yet a call to EvalulateUsersGPTStats was made.`
`User ${getSettingsID} has no game-settings, yet a call to EvaluateUsersStatsShowcase was made.`
);
}
@@ -41,9 +41,9 @@ export async function EvaluateUsersGPTStats(
return results;
}
async function EvaluateStats(details: UGPTStatDetails, userID: integer, game: Game) {
async function EvaluateStats(details: ShowcaseStatDetails, userID: integer, game: Game) {
const [result, related] = await Promise.all([
EvaluateUGPTStat(details, userID),
EvaluateShowcaseStat(details, userID),
GetRelatedStatDocuments(details, game),
]);
@@ -20,7 +20,7 @@ import pbsRouter from "./pbs/router";
import sessionsRouter from "./sessions/router";
import foldersFolderIDRouter from "./folders/_folderID/router";
import tablesRouter from "./tables/router";
import statsRouter from "./stats/router";
import statsRouter from "./showcase/router";
import settingsRouter from "./settings/router";
const router: Router = Router({ mergeParams: true });
@@ -1,15 +1,15 @@
import { Router } from "express";
import { SYMBOL_TachiData } from "../../../../../../../../../../lib/constants/tachi";
import { EvaluateUsersGPTStats } from "../../../../../../../../../../lib/ugpt-stat/get-stats";
import { EvaluateUsersStatsShowcase } from "../../../../../../../../../../lib/showcase-stats/get-stats";
import { ResolveUser } from "../../../../../../../../../../utils/user";
import p from "prudence";
import { FormatPrError } from "../../../../../../../../../../utils/prudence";
import { UGPTStatDetails, GetGamePTConfig } from "tachi-common";
import { EvaluateUGPTStat } from "../../../../../../../../../../lib/ugpt-stat/evaluator";
import { ShowcaseStatDetails, GetGamePTConfig } from "tachi-common";
import { EvaluateShowcaseStat } from "../../../../../../../../../../lib/showcase-stats/evaluator";
import db from "../../../../../../../../../../external/mongo/db";
import { RequirePermissions } from "../../../../../../../../../middleware/auth";
import { RequireAuthedAsUser } from "../../../../middleware";
import { GetRelatedStatDocuments } from "lib/ugpt-stat/get-related";
import { GetRelatedStatDocuments } from "lib/showcase-stats/get-related";
const router: Router = Router({ mergeParams: true });
/**
@@ -39,7 +39,7 @@ router.get("/", async (req, res) => {
projectUser = user.id;
}
const results = await EvaluateUsersGPTStats(user.id, game, playtype, projectUser);
const results = await EvaluateUsersStatsShowcase(user.id, game, playtype, projectUser);
return res.status(200).json({
success: true,
@@ -65,7 +65,7 @@ router.get("/custom", async (req, res) => {
const user = req[SYMBOL_TachiData]!.requestedUser!;
const game = req[SYMBOL_TachiData]!.game!;
let stat: UGPTStatDetails;
let stat: ShowcaseStatDetails;
if (req.query.mode === "folder") {
const err = p(
@@ -127,7 +127,7 @@ router.get("/custom", async (req, res) => {
});
}
const result = await EvaluateUGPTStat(stat, user.id);
const result = await EvaluateShowcaseStat(stat, user.id);
const related = await GetRelatedStatDocuments(stat, game);