style: replace Playtypes[Game] with Playtype

This commit is contained in:
zkldi
2022-04-23 05:55:37 +01:00
parent a5fd3bcb9a
commit 5757348dd6
34 changed files with 131 additions and 109 deletions
@@ -1,13 +1,13 @@
import db from "external/mongo/db";
import CreateLogCtx from "lib/logger/logger";
import { Game, integer, Playtypes } from "tachi-common";
import { Game, integer, Playtype, Playtypes } from "tachi-common";
const logger = CreateLogCtx(__filename);
/**
* Create GameSettings for a UGPT (which contains their preferences).
*/
export async function CreateGameSettings(userID: integer, game: Game, playtype: Playtypes[Game]) {
export async function CreateGameSettings(userID: integer, game: Game, playtype: Playtype) {
const exists = await db["game-settings"].findOne({
userID,
game,
@@ -1,5 +1,13 @@
import { KtLogger } from "lib/logger/logger";
import { ChartDocument, Game, GetGamePTConfig, IIDX_LAMPS, integer, Playtypes } from "tachi-common";
import {
ChartDocument,
Game,
GetGamePTConfig,
IIDX_LAMPS,
integer,
Playtype,
Playtypes,
} from "tachi-common";
import { DryScore } from "../common/types";
/**
@@ -133,7 +141,7 @@ const ratingParameters = {
export function CalculateKTRating(
dryScore: DryScore,
game: "ddr" | "museca",
playtype: Playtypes[Game],
playtype: Playtype,
chart: ChartDocument,
logger: KtLogger
) {
@@ -193,7 +201,7 @@ export function CalculateKTLampRatingIIDXDP(dryScore: DryScore, chart: ChartDocu
function LampRatingNoTierlistInfo(
dryScore: DryScore,
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
chart: ChartDocument
) {
const gptConfig = GetGamePTConfig(game, playtype);
@@ -7,7 +7,7 @@ import {
GetGamePTConfig,
Grades,
IDStrings,
Playtypes,
Playtype,
} from "tachi-common";
import { InternalFailure, InvalidScoreFailure } from "./converter-failures";
@@ -18,7 +18,7 @@ const logger = CreateLogCtx(__filename);
*/
export function GetGradeFromPercent<I extends IDStrings = IDStrings>(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
percent: number
): Grades[I] {
const gptConfig = GetGamePTConfig(game, playtype);
@@ -101,7 +101,7 @@ export function GenericCalculatePercent(game: Game, score: number, chart?: Chart
*/
export function ValidatePercent(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
percent: number,
chart: ChartDocument
) {
@@ -177,7 +177,7 @@ export function JubeatGetGrade(score: number): Grades["jubeat:Single"] {
*/
export function CalculateESDForGame(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
percent: number
): number | null {
const gptConfig = GetGamePTConfig(game, playtype);
@@ -1,9 +1,9 @@
import { Difficulties, Game, GetGamePTConfig, IDStrings, Playtypes } from "tachi-common";
import { Difficulties, Game, GetGamePTConfig, IDStrings, Playtype, Playtypes } from "tachi-common";
import { InvalidScoreFailure } from "./converter-failures";
export function AssertStrAsDifficulty(
strVal: string,
game: Game,
playtype: Playtypes[Game]
playtype: Playtype
): Difficulties[IDStrings] {
const validDifficulties = GetGamePTConfig(game, playtype).difficulties;
@@ -1,4 +1,4 @@
import { IDStrings, ScoreDocument, Playtypes, Game } from "tachi-common";
import { IDStrings, ScoreDocument, Playtype, Game } from "tachi-common";
/**
* An intermediate score format that will be filled out by
@@ -11,4 +11,4 @@ export type DryScore<I extends IDStrings = IDStrings> = Pick<
scoreData: Omit<ScoreDocument<I>["scoreData"], "gradeIndex" | "lampIndex" | "esd">;
};
export type ScorePlaytypeMap = Partial<Record<Playtypes[Game], ScoreDocument[]>>;
export type ScorePlaytypeMap = Partial<Record<Playtype, ScoreDocument[]>>;
@@ -8,7 +8,7 @@ import {
integer,
MilestoneDocument,
MilestoneImportInfo,
Playtypes,
Playtype,
MilestoneSubscriptionDocument,
} from "tachi-common";
import { CalculateMilestoneOutOf, GetGoalIDsFromMilestone } from "lib/targets/milestones";
@@ -52,7 +52,7 @@ export function ProcessMilestoneFromGII(
export async function UpdateUsersMilestones(
importGoalInfo: GoalImportInfo[],
game: Game,
playtypes: Playtypes[Game][],
playtypes: Playtype[],
userID: integer,
logger: KtLogger
) {
@@ -157,7 +157,7 @@ export async function UpdateUsersMilestones(
async function GetRelevantMilestones(
goalIDs: string[],
game: Game,
playtypes: Playtypes[Game][],
playtypes: Playtype[],
userID: integer,
logger: KtLogger
) {
@@ -9,7 +9,7 @@ import {
ImportProcessingInfo,
ImportTypes,
integer,
Playtypes,
Playtype,
PublicUserDocument,
} from "tachi-common";
import { GetMillisecondsSince } from "utils/misc";
@@ -303,7 +303,7 @@ export async function HandlePostImportSteps(
logger.debug(`PB Processing took ${pbTime} milliseconds (${pbTimeRel}ms/doc)`);
const playtypes = Object.keys(scorePlaytypeMap) as Playtypes[Game][];
const playtypes = Object.keys(scorePlaytypeMap) as Playtype[];
SetJobProgress(job, "Updating profile statistics.");
@@ -368,7 +368,7 @@ export async function HandlePostImportSteps(
*/
async function UpdateUsersGameStats(
game: Game,
modifiedPlaytypes: Playtypes[Game][],
modifiedPlaytypes: Playtype[],
userID: integer,
classHandler: ClassHandler | null,
logger: KtLogger
@@ -1,4 +1,4 @@
import { Game, Playtypes, ScoreDocument, SessionDocument } from "tachi-common";
import { Game, Playtype, Playtypes, ScoreDocument, SessionDocument } from "tachi-common";
type ScoreCalculatedDataOnly = Pick<ScoreDocument, "calculatedData">;
@@ -146,7 +146,7 @@ const CalculatedDataFunctions: CalculatedDataFunctions = {
export function CreateSessionCalcData(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
scoreCalcData: ScoreCalculatedDataOnly[]
): SessionDocument["calculatedData"] {
// @ts-expect-error standard game->pt stuff.
@@ -6,7 +6,7 @@ import {
ImportTypes,
integer,
PBScoreDocument,
Playtypes,
Playtype,
ScoreDocument,
SessionDocument,
SessionInfoReturn,
@@ -38,7 +38,7 @@ export async function CreateSessions(
importType,
scores,
game,
playtype as Playtypes[Game],
playtype as Playtype,
logger
);
@@ -112,7 +112,7 @@ function CreateSession(
groupInfo: SessionScoreInfo[],
groupScores: ScoreDocument[],
game: Game,
playtype: Playtypes[Game]
playtype: Playtype
): SessionDocument {
const name = GenerateRandomSessionName();
@@ -141,7 +141,7 @@ export async function LoadScoresIntoSessions(
importType: ImportTypes,
importScores: ScoreDocument[],
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
baseLogger: KtLogger
): Promise<SessionInfoReturn[]> {
const logger = AppendLogCtx("Session Generation", baseLogger);
@@ -7,12 +7,12 @@ import {
WACCA_COLOURS,
} from "lib/constants/classes";
import { KtLogger } from "lib/logger/logger";
import { Game, integer, Playtypes, ScoreCalculatedDataLookup } from "tachi-common";
import { Game, integer, Playtype, Playtypes, ScoreCalculatedDataLookup } from "tachi-common";
import { GameClasses } from "tachi-common/js/game-classes";
export function CalculateSDVXClass(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
ratings: Partial<Record<ScoreCalculatedDataLookup["sdvx:Single"], number>>,
logger: KtLogger
@@ -51,7 +51,7 @@ export function SDVXVF6ToClass(vf: number, logger: KtLogger) {
export function CalculateGitadoraColour(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
ratings: Record<string, number>,
logger: KtLogger
@@ -103,7 +103,7 @@ export function GitadoraSkillToColour(sk: number) {
export function CalculateWACCAColour(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
ratings: Record<string, number>
) {
@@ -136,7 +136,7 @@ function WACCARateToColour(rate: number) {
export function CalculatePopnClass(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
ratings: Record<string, number>
) {
@@ -167,7 +167,7 @@ function PopnClassPointsToClass(points: number) {
export function CalculateChunithmColour(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
ratings: Record<string, number>
) {
@@ -202,7 +202,7 @@ function ChuniRatingToColour(rating: number) {
export function CalculateJubeatColour(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
ratings: Record<string, number>
) {
@@ -2,7 +2,15 @@ import deepmerge from "deepmerge";
import db from "external/mongo/db";
import { KtLogger } from "lib/logger/logger";
import { EmitWebhookEvent } from "lib/webhooks/webhooks";
import { ClassDelta, Game, IDStrings, integer, Playtypes, UserGameStats } from "tachi-common";
import {
ClassDelta,
Game,
IDStrings,
integer,
Playtype,
Playtypes,
UserGameStats,
} from "tachi-common";
import { GameClasses } from "tachi-common/js/game-classes";
import { ReturnClassIfGreater } from "utils/class";
import {
@@ -84,7 +92,7 @@ const STATIC_CLASS_HANDLERS: ClassHandlerMap = {
*/
export async function UpdateUGSClasses(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
ratings: Record<string, number>,
ClassHandler: ClassHandler | null,
@@ -123,7 +131,7 @@ export async function UpdateUGSClasses(
*/
export async function ProcessClassDeltas(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
classes: ScoreClasses,
userGameStats: UserGameStats | null,
userID: integer,
@@ -6,6 +6,7 @@ import {
IDStrings,
UserGameStats,
PBScoreDocument,
Playtype,
} from "tachi-common";
import db from "external/mongo/db";
import { KtLogger } from "lib/logger/logger";
@@ -13,7 +14,7 @@ import { KtLogger } from "lib/logger/logger";
type CustomCalcNames = ScoreCalculatedDataLookup[IDStrings];
function LazySumAll(key: CustomCalcNames) {
return async (game: Game, playtype: Playtypes[Game], userID: integer) => {
return async (game: Game, playtype: Playtype, userID: integer) => {
const sc = await db["personal-bests"].find({
game: game,
playtype: playtype,
@@ -49,7 +50,7 @@ function LazyCalcN(
returnMean = false,
nullIfNotEnoughScores = false
) {
return async (game: Game, playtype: Playtypes[Game], userID: integer) => {
return async (game: Game, playtype: Playtype, userID: integer) => {
const sc = await db["personal-bests"].find(
{
game: game,
@@ -91,7 +92,7 @@ type RatingFunctions = {
[G in Game]: {
[P in Playtypes[G]]: (
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
logger: KtLogger
) => Promise<UserGameStats["ratings"]>;
@@ -194,7 +195,7 @@ const RatingFunctions: RatingFunctions = {
export function CalculateRatings(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
logger: KtLogger
): Promise<Partial<Record<CustomCalcNames, number>>> {
@@ -205,7 +206,7 @@ export function CalculateRatings(
// Wacca has a funny algorithm for rate involving gitadora-style latest chart bonuses,
async function CalculateWACCARate(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
logger: KtLogger
) {
@@ -267,7 +268,7 @@ async function CalculateWACCARate(
async function CalculateGitadoraSkill(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
logger: KtLogger
) {
@@ -300,7 +301,7 @@ export async function GetBestRatingOnSongs(
songIDs: integer[],
userID: integer,
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
ratingProp: "skill",
limit = 25
): Promise<PBScoreDocument[]> {
@@ -334,7 +335,7 @@ export async function GetBestRatingOnSongs(
async function CalculateJubility(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
logger: KtLogger
): Promise<number> {
@@ -1,5 +1,5 @@
import { KtLogger } from "lib/logger/logger";
import { Game, IDStrings, integer, Playtypes } from "tachi-common";
import { Game, IDStrings, integer, Playtype, Playtypes } from "tachi-common";
import { GameClasses } from "tachi-common/js/game-classes";
export type ScoreClasses = Partial<GameClasses<IDStrings>>;
@@ -7,7 +7,7 @@ export type ScoreClasses = Partial<GameClasses<IDStrings>>;
export interface ClassHandler {
(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
ratings: Record<string, number>,
logger: KtLogger
@@ -5,14 +5,14 @@
import db from "external/mongo/db";
import { CreateGameSettings } from "lib/game-settings/create-game-settings";
import { KtLogger } from "lib/logger/logger";
import { ClassDelta, Game, integer, Playtypes, UserGameStats } from "tachi-common";
import { ClassDelta, Game, integer, Playtype, UserGameStats } from "tachi-common";
import { ProcessClassDeltas, UpdateUGSClasses } from "./classes";
import { CalculateRatings } from "./rating";
import { ClassHandler } from "./types";
export async function UpdateUsersGamePlaytypeStats(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
userID: integer,
classHandler: ClassHandler | null,
logger: KtLogger
@@ -9,6 +9,7 @@ import {
GetGameConfig,
GetGamePTConfig,
ImportTypes,
Playtype,
Playtypes,
} from "tachi-common";
import { FormatPrError } from "utils/prudence";
@@ -39,7 +40,7 @@ const PR_DPRandom = (self: unknown) => {
return true;
};
const PR_ScoreMeta = (game: Game, playtype: Playtypes[Game]): PrudenceSchema => {
const PR_ScoreMeta = (game: Game, playtype: Playtype): PrudenceSchema => {
if (game === "iidx") {
const random =
playtype === "SP"
@@ -148,7 +149,7 @@ const PR_HitMeta = (game: Game): PrudenceSchema => {
return {};
};
const PR_BatchManualScore = (game: Game, playtype: Playtypes[Game]): PrudenceSchema => {
const PR_BatchManualScore = (game: Game, playtype: Playtype): PrudenceSchema => {
const gptConfig = GetGamePTConfig(game, playtype);
return {
score: p.isPositiveInteger,
@@ -228,7 +229,7 @@ const PR_BatchManualClasses = (game: Game): PrudenceSchema => {
}
};
const PR_BatchManual = (game: Game, playtype: Playtypes[Game]): PrudenceSchema => ({
const PR_BatchManual = (game: Game, playtype: Playtype): PrudenceSchema => ({
meta: {
service: p.isBoundedString(3, 15),
game: p.isIn(TachiConfig.GAMES),
@@ -302,7 +303,7 @@ export function ParseBatchManualFromObject(
);
}
const playtype: Playtypes[Game] = possiblyPlaytype;
const playtype: Playtype = possiblyPlaytype;
// now that we have the game, we can validate this against
// the prudence schema for batch-manual.
@@ -1,8 +1,8 @@
import { Game, GPTSupportedVersions, IDStrings, Playtypes } from "tachi-common";
import { Game, GPTSupportedVersions, IDStrings, Playtype, Playtypes } from "tachi-common";
export interface BatchManualContext {
game: Game;
playtype: Playtypes[Game];
playtype: Playtype;
service: string;
version: GPTSupportedVersions[IDStrings] | null;
}
@@ -53,7 +53,7 @@ t.test("#FerStaticClassHandler", (t) => {
t.test("Should skip if playtype is invalid", (t) => {
const fn = CreateFerStaticClassHandler({ sp_dan: 5, dp_dan: 7 });
const res = fn("iidx", "INVALID" as Playtypes[Game], 1, {}, logger);
const res = fn("iidx", "INVALID" as Playtype, 1, {}, logger);
t.equal(res, undefined, "Should skip over as a failsafe.");
@@ -4,7 +4,7 @@ import CreateLogCtx from "lib/logger/logger";
import { UpdateChartRanking } from "lib/score-import/framework/pb/create-pb-doc";
import { ProcessPBs } from "lib/score-import/framework/pb/process-pbs";
import { UpdateUsersGamePlaytypeStats } from "lib/score-import/framework/user-game-stats/update-ugs";
import { Game, Playtypes, ScoreDocument } from "tachi-common";
import { Game, Playtype, ScoreDocument } from "tachi-common";
const logger = CreateLogCtx(__filename);
@@ -216,7 +216,7 @@ export async function DeleteMultipleScores(scores: ScoreDocument[], blacklist =
const ugpts = [...new Set(scores.map((e) => `${e.game}-${e.playtype}-${e.userID}`))];
for (const ugpt of ugpts) {
const [game, playtype, strUserID] = ugpt.split("-") as [Game, Playtypes[Game], string];
const [game, playtype, strUserID] = ugpt.split("-") as [Game, Playtype, string];
const userID = Number(strUserID);
+3 -2
View File
@@ -8,6 +8,7 @@ import {
ChartDocument,
Game,
integer,
Playtype,
Playtypes,
PublicUserDocument,
SessionDocument,
@@ -77,7 +78,7 @@ export function SearchGameSongs(
export async function SearchGameSongsAndCharts(
game: Game,
search: string,
playtype?: Playtypes[Game],
playtype?: Playtype,
limit = 100
) {
const songs = await SearchGameSongs(game, search, limit);
@@ -98,7 +99,7 @@ export async function SearchGameSongsAndCharts(
export function SearchSessions(
search: string,
game?: Game,
playtype?: Playtypes[Game],
playtype?: Playtype,
userID?: integer,
limit = 100
) {
+2 -2
View File
@@ -1,5 +1,5 @@
import db from "external/mongo/db";
import { integer, Game, Playtypes, ShowcaseStatDetails } from "tachi-common";
import { integer, Game, Playtype, ShowcaseStatDetails } from "tachi-common";
import CreateLogCtx from "lib/logger/logger";
import { EvaluateShowcaseStat } from "./evaluator";
import { GetRelatedStatDocuments } from "./get-related";
@@ -14,7 +14,7 @@ const logger = CreateLogCtx(__filename);
export async function EvaluateUsersStatsShowcase(
userID: integer,
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
projectUserStats?: integer
) {
const getSettingsID = projectUserStats ?? userID;
+4 -3
View File
@@ -6,6 +6,7 @@ import {
Game,
GetGamePTConfig,
GoalDocument,
Playtype,
Playtypes,
} from "tachi-common";
import { GetFolderForIDGuaranteed, HumaniseChartID } from "utils/db";
@@ -16,7 +17,7 @@ export async function CreateGoalTitle(
charts: GoalDocument["charts"],
criteria: GoalDocument["criteria"],
game: Game,
playtype: Playtypes[Game]
playtype: Playtype
) {
const formattedCriteria = FormatCriteria(criteria, game, playtype);
@@ -83,7 +84,7 @@ async function FormatCharts(charts: GoalDocument["charts"], game: Game) {
}
}
function FormatCriteria(criteria: GoalDocument["criteria"], game: Game, playtype: Playtypes[Game]) {
function FormatCriteria(criteria: GoalDocument["criteria"], game: Game, playtype: Playtype) {
const gptConfig = GetGamePTConfig(game, playtype);
switch (criteria.key) {
@@ -109,7 +110,7 @@ export async function ValidateGoalChartsAndCriteria(
charts: GoalDocument["charts"],
criteria: GoalDocument["criteria"],
game: Game,
playtype: Playtypes[Game]
playtype: Playtype
) {
let chartCount = 0;
// Validating the charts supplied
+4 -4
View File
@@ -9,7 +9,7 @@ import {
GoalDocument,
integer,
PBScoreDocument,
Playtypes,
Playtype,
GoalSubscriptionDocument,
MilestoneSubscriptionDocument,
MilestoneDocument,
@@ -42,7 +42,7 @@ export function CreateGoalID(
charts: GoalDocument["charts"],
criteria: GoalDocument["criteria"],
game: Game,
playtype: Playtypes[Game]
playtype: Playtype
) {
return `G${fjsh.hash({ charts, criteria, game, playtype }, "sha256")}`;
}
@@ -218,7 +218,7 @@ type PBWithBadPoor = PBScoreDocument<
export function HumaniseGoalProgress(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
key: GoalKeys,
value: number,
userPB: PBScoreDocument | null
@@ -268,7 +268,7 @@ export async function ConstructGoal(
charts: GoalDocument["charts"],
criteria: GoalDocument["criteria"],
game: Game,
playtype: Playtypes[Game]
playtype: Playtype
): Promise<GoalDocument> {
// Throws if the charts or criteria are invalid somehow.
await ValidateGoalChartsAndCriteria(charts, criteria, game, playtype);
@@ -1,4 +1,4 @@
import { Game, GetGameConfig, Playtypes } from "tachi-common";
import { Game, GetGameConfig, Playtype, Playtypes } from "tachi-common";
import { RequestHandler } from "express";
import { SYMBOL_TachiData } from "lib/constants/tachi";
import { AssignToReqTachiData } from "utils/req-tachi-data";
@@ -8,14 +8,14 @@ export const ValidatePlaytypeFromParam: RequestHandler = (req, res, next) => {
const gameConfig = GetGameConfig(game);
if (!gameConfig.validPlaytypes.includes(req.params.playtype as Playtypes[Game])) {
if (!gameConfig.validPlaytypes.includes(req.params.playtype as Playtype)) {
return res.status(400).json({
success: false,
description: `The playtype ${req.params.playtype} is not supported.`,
});
}
AssignToReqTachiData(req, { playtype: req.params.playtype as Playtypes[Game] });
AssignToReqTachiData(req, { playtype: req.params.playtype as Playtype });
return next();
};
@@ -5,7 +5,15 @@ import { FindOptions } from "monk";
import NodeCache from "node-cache";
import p from "prudence";
import prValidate from "server/middleware/prudence-validate";
import { FormatGame, Game, GetGamePTConfig, integer, Playtypes, UserGameStats } from "tachi-common";
import {
FormatGame,
Game,
GetGamePTConfig,
integer,
Playtype,
Playtypes,
UserGameStats,
} from "tachi-common";
import { GetRelevantSongsAndCharts } from "utils/db";
import { IsString } from "utils/misc";
import { GetClassDistribution } from "utils/queries/stats";
@@ -32,7 +40,7 @@ const gptStatCache = new NodeCache();
async function GetGameStats(
game: Game,
playtype: Playtypes[Game]
playtype: Playtype
): Promise<{ scoreCount: integer; playerCount: integer; chartCount: integer }> {
const cacheRes = gptStatCache.get(`${game}:${playtype}`);
@@ -1,6 +1,6 @@
/* eslint-disable no-await-in-loop */
import db from "external/mongo/db";
import { Game, integer, Playtypes, PublicUserDocument } from "tachi-common";
import { Game, integer, Playtype, Playtypes, PublicUserDocument } from "tachi-common";
import CreateLogCtx from "lib/logger/logger";
import { CreateCalculatedData } from "lib/score-import/framework/calculated-data/calculated-data";
import { UpdateUsersGamePlaytypeStats } from "lib/score-import/framework/user-game-stats/update-ugs";
@@ -67,13 +67,13 @@ export async function RecalcAllScores(filter = {}) {
logger.info(`Updating Profiles for ${modifiedUsers.size} users...`);
for (const userInfo of modifiedUsers.values()) {
const [game, playtype, strUserID] = userInfo.split("-") as [Game, Playtypes[Game], string];
const [game, playtype, strUserID] = userInfo.split("-") as [Game, Playtype, string];
const userID = Number(strUserID);
await UpdateUsersGamePlaytypeStats(
game as Game,
playtype as Playtypes[Game],
playtype as Playtype,
userID,
null,
logger
+2 -2
View File
@@ -2,7 +2,7 @@ import db from "external/mongo/db";
import { CreateGameSettings } from "lib/game-settings/create-game-settings";
import CreateLogCtx from "lib/logger/logger";
import { EmitWebhookEvent } from "lib/webhooks/webhooks";
import { Game, IDStrings, integer, Playtypes, UserGameStats } from "tachi-common";
import { Game, IDStrings, integer, Playtype, UserGameStats } from "tachi-common";
import { GameClassSets } from "tachi-common/js/game-classes";
const logger = CreateLogCtx(__filename);
@@ -35,7 +35,7 @@ export function ReturnClassIfGreater(
export async function UpdateClassIfGreater(
userID: integer,
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
classSet: GameClassSets[IDStrings],
classVal: integer
) {
+3 -10
View File
@@ -10,6 +10,7 @@ import {
FolderDocument,
Playtypes,
Game,
Playtype,
} from "tachi-common";
import db from "external/mongo/db";
import CreateLogCtx from "lib/logger/logger";
@@ -264,19 +265,11 @@ export function GetGradeLampDistributionForFolders(userID: integer, folders: Fol
return Promise.all(folders.map((f) => GetGradeLampDistributionForFolder(userID, f)));
}
export function CreateFolderID(
query: Record<string, unknown>,
game: Game,
playtype: Playtypes[Game]
) {
export function CreateFolderID(query: Record<string, unknown>, game: Game, playtype: Playtype) {
return `F${fjsh.hash(Object.assign({ game, playtype }, query), "SHA256")}`;
}
export async function GetRecentlyViewedFolders(
userID: integer,
game: Game,
playtype: Playtypes[Game]
) {
export async function GetRecentlyViewedFolders(userID: integer, game: Game, playtype: Playtype) {
const views = await db["recent-folder-views"].find(
{
userID,
+3 -3
View File
@@ -2,7 +2,7 @@ import { exec } from "child_process";
import crypto from "crypto";
import { ONE_HOUR } from "lib/constants/time";
import { TachiConfig } from "lib/setup/config";
import { Game, GamePTConfig, GetGameConfig, integer, Playtypes } from "tachi-common";
import { Game, GamePTConfig, GetGameConfig, integer, Playtype, Playtypes } from "tachi-common";
import { URL } from "url";
// https://github.com/sindresorhus/escape-string-regexp/blob/main/index.js
@@ -68,8 +68,8 @@ export function IsValidGame(str: string): str is Game {
return !!TachiConfig.GAMES.includes(str as Game);
}
export function IsValidPlaytype(game: Game, str: string): str is Playtypes[Game] {
return GetGameConfig(game).validPlaytypes.includes(str as Playtypes[Game]);
export function IsValidPlaytype(game: Game, str: string): str is Playtype {
return GetGameConfig(game).validPlaytypes.includes(str as Playtype);
}
export function IsValidScoreAlg(
+8 -7
View File
@@ -7,6 +7,7 @@ import {
GPTSupportedVersions,
IDStrings,
integer,
Playtype,
Playtypes,
} from "tachi-common";
@@ -69,7 +70,7 @@ export function FindChartWithPTDFVersion<
export function FindDDRChartOnSongHash(
songHash: string,
// Technically both of these should be "ddr" instead of Game, but it proves hard to work with.
playtype: Playtypes[Game],
playtype: Playtype,
difficulty: Difficulties[IDStrings]
) {
// note: this only works on accident because monk
@@ -99,7 +100,7 @@ export function FindBMSChartOnHash(hash: string) {
export function FindChartOnInGameID(
game: Game,
inGameID: number,
playtype: Playtypes[Game],
playtype: Playtype,
difficulty: Difficulties[IDStrings]
) {
if (game === "bms" || game === "usc") {
@@ -119,7 +120,7 @@ export function FindChartOnInGameID(
*/
export function FindIIDXChartOnInGameID(
inGameID: number,
playtype: Playtypes[Game],
playtype: Playtype,
difficulty: Difficulties[IDStrings]
) {
return db.charts.iidx.findOne({
@@ -137,7 +138,7 @@ export function FindIIDXChartOnInGameID(
*/
export function FindIIDXChartOnInGameIDVersion(
inGameID: number,
playtype: Playtypes[Game],
playtype: Playtype,
difficulty: Difficulties[IDStrings],
version: GPTSupportedVersions[IDStrings]
) {
@@ -156,7 +157,7 @@ export function FindIIDXChartOnInGameIDVersion(
export function FindChartOnInGameIDVersion<I extends IDStrings = IDStrings>(
game: Game,
inGameID: number,
playtype: Playtypes[Game],
playtype: Playtype,
difficulty: Difficulties[I],
version: GPTSupportedVersions[I]
) {
@@ -243,7 +244,7 @@ export function FindChartOnSHA256(game: Game, hash: string) {
});
}
export function FindChartOnSHA256Playtype(game: Game, hash: string, playtype: Playtypes[Game]) {
export function FindChartOnSHA256Playtype(game: Game, hash: string, playtype: Playtype) {
if (game !== "bms" && game !== "usc" && game !== "iidx" && game !== "pms") {
throw new Error(`Cannot call FindChartOnSHA256 for game ${game}.`);
}
@@ -267,7 +268,7 @@ export function FindChartOnARCID(game: "iidx" | "ddr" | "jubeat" | "sdvx", arcID
*/
export async function FindChartsOnPopularity(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
songIDs?: integer[],
skip = 0,
limit = 100,
+2 -2
View File
@@ -1,13 +1,13 @@
import db from "external/mongo/db";
import { ONE_HOUR } from "lib/constants/time";
import NodeCache from "node-cache";
import { Game, gameClasses, IDStrings, integer, Playtypes } from "tachi-common";
import { Game, gameClasses, IDStrings, integer, Playtype, Playtypes } from "tachi-common";
const classDistCache = new NodeCache();
export async function GetClassDistribution(
game: Game,
playtype: Playtypes[Game],
playtype: Playtype,
className: gameClasses.GameClassSets[IDStrings]
) {
const cacheKey = `${game}:${playtype}:${className}`;
+2 -2
View File
@@ -1,5 +1,5 @@
import db from "external/mongo/db";
import { integer, Game, Playtypes } from "tachi-common";
import { integer, Game, Playtypes, Playtype } from "tachi-common";
import { UpdateAllPBs } from "utils/calculations/recalc-scores";
/**
@@ -10,7 +10,7 @@ import { UpdateAllPBs } from "utils/calculations/recalc-scores";
export default async function DestroyUserGamePlaytypeData(
userID: integer,
game: Game,
playtype: Playtypes[Game]
playtype: Playtype
) {
await db["game-stats-snapshots"].remove({
userID,
+4 -4
View File
@@ -1,4 +1,4 @@
import { Game, GamePTConfig, GetGamePTConfig, Playtypes } from "tachi-common";
import { Game, GamePTConfig, GetGamePTConfig, Playtype, Playtypes } from "tachi-common";
import { IsString } from "./misc";
const isIntegerRegex = /^-?\d+$/u;
@@ -47,7 +47,7 @@ export type ProfileRatingAlgs = GamePTConfig["defaultProfileRatingAlg"];
export type ScoreRatingAlgs = GamePTConfig["defaultScoreRatingAlg"];
export type SessionRatingAlgs = GamePTConfig["defaultSessionRatingAlg"];
export function CheckStrProfileAlg(game: Game, playtype: Playtypes[Game], strVal: string) {
export function CheckStrProfileAlg(game: Game, playtype: Playtype, strVal: string) {
const gptConfig = GetGamePTConfig(game, playtype);
// @hack
@@ -58,7 +58,7 @@ export function CheckStrProfileAlg(game: Game, playtype: Playtypes[Game], strVal
return strVal as ProfileRatingAlgs;
}
export function CheckStrScoreAlg(game: Game, playtype: Playtypes[Game], strVal: string) {
export function CheckStrScoreAlg(game: Game, playtype: Playtype, strVal: string) {
const gptConfig = GetGamePTConfig(game, playtype);
// @hack
@@ -69,7 +69,7 @@ export function CheckStrScoreAlg(game: Game, playtype: Playtypes[Game], strVal:
return strVal as ScoreRatingAlgs;
}
export function CheckStrSessionAlg(game: Game, playtype: Playtypes[Game], strVal: string) {
export function CheckStrSessionAlg(game: Game, playtype: Playtype, strVal: string) {
const gptConfig = GetGamePTConfig(game, playtype);
// @hack
+2 -2
View File
@@ -7,7 +7,7 @@ import {
PublicUserDocument,
UserGameStats,
Game,
Playtypes,
Playtype,
SongDocument,
UserSettings,
TachiAPIClientDocument,
@@ -61,7 +61,7 @@ export interface TachiRequestData {
requestedUser?: PublicUserDocument;
requestedUserGameStats?: UserGameStats;
game?: Game;
playtype?: Playtypes[Game];
playtype?: Playtype;
chartDoc?: ChartDocument;
songDoc?: SongDocument;
+2 -2
View File
@@ -6,7 +6,7 @@ import {
GetGamePTConfig,
IDStrings,
integer,
Playtypes,
Playtype,
PublicUserDocument,
UGSRatingsLookup,
UserGameStats,
@@ -171,7 +171,7 @@ export async function GetUsersRanking(stats: UserGameStats) {
return (aggRes[0].ranking + 1) as integer;
}
export function GetUGPTPlaycount(userID: integer, game: Game, playtype: Playtypes[Game]) {
export function GetUGPTPlaycount(userID: integer, game: Game, playtype: Playtype) {
return db.scores.count({ userID, game, playtype });
}