mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-15 02:29:28 +03:00
add CreateGoalID
This commit is contained in:
@@ -4,6 +4,7 @@ import db from "../../external/mongo/db";
|
||||
import { KtLogger } from "../logger/logger";
|
||||
import { GetFolderChartIDs } from "../../utils/folder";
|
||||
import { FilterQuery } from "mongodb";
|
||||
import fjsh from "fast-json-stable-hash";
|
||||
|
||||
export interface EvaluatedGoalReturn {
|
||||
achieved: boolean;
|
||||
@@ -13,6 +14,21 @@ export interface EvaluatedGoalReturn {
|
||||
outOfHuman: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a goalID from a goals charts and criteria.
|
||||
*
|
||||
* This uses FJSH to stable-stringify the charts and criteria,
|
||||
* then hashes that string under sha256.
|
||||
*
|
||||
* @note We could do better here, by converting criteria
|
||||
* to 'similar' criteria - like 100% resolving to 1million score
|
||||
* but that proves very complex to implement when it comes
|
||||
* to multiple games.
|
||||
*/
|
||||
export function CreateGoalID(charts: GoalDocument["charts"], criteria: GoalDocument["criteria"]) {
|
||||
return fjsh.hash({ charts, criteria }, "sha256");
|
||||
}
|
||||
|
||||
export async function EvaluateGoalForUser(
|
||||
goal: GoalDocument,
|
||||
userID: integer,
|
||||
|
||||
Reference in New Issue
Block a user