mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-08 22:59:52 +03:00
Merge pull request #290 from zkldi:zkldi/issue-50-GITADORA-HOT-charts-support
GITADORA HOT charts support
This commit is contained in:
+1
-1
@@ -71,7 +71,7 @@
|
||||
"redis": "3.1.2",
|
||||
"rimraf": "3.0.2",
|
||||
"safe-json-stringify": "1.2.0",
|
||||
"tachi-common": "^0.1.12",
|
||||
"tachi-common": "^0.1.14",
|
||||
"typescript": "4.3.4",
|
||||
"winston": "3.3.3"
|
||||
},
|
||||
|
||||
Generated
+302
-297
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,7 @@ import {
|
||||
ScoreCalculatedDataLookup,
|
||||
IDStrings,
|
||||
UserGameStats,
|
||||
PBScoreDocument,
|
||||
} from "tachi-common";
|
||||
import db from "external/mongo/db";
|
||||
import { KtLogger } from "lib/logger/logger";
|
||||
@@ -153,32 +154,18 @@ async function CalculateGitadoraSkill(
|
||||
userID: integer,
|
||||
logger: KtLogger
|
||||
) {
|
||||
const hotCharts = await db.charts.gitadora.find(
|
||||
{ "flags.HOT N-1": true },
|
||||
{ projection: { chartID: 1 } }
|
||||
);
|
||||
const hotSongIDs = (
|
||||
await db.songs.gitadora.find({ "data.isHot": true }, { projection: { id: 1 } })
|
||||
).map((e) => e.id);
|
||||
|
||||
const hotChartIDs = hotCharts.map((e) => e.chartID);
|
||||
// get it
|
||||
const coldSongIDs = (
|
||||
await db.songs.gitadora.find({ "data.isHot": false }, { projection: { id: 1 } })
|
||||
).map((e) => e.id);
|
||||
|
||||
const [bestHotScores, bestScores] = await Promise.all([
|
||||
db["personal-bests"].find(
|
||||
{ userID, chartID: { $in: hotChartIDs } },
|
||||
{
|
||||
sort: { "calculatedData.skill": -1 },
|
||||
limit: 25,
|
||||
projection: { "calculatedData.skill": 1 },
|
||||
}
|
||||
),
|
||||
// @inefficient
|
||||
// $nin is VERY expensive, there might be a better way to do this.
|
||||
db["personal-bests"].find(
|
||||
{ userID, chartID: { $nin: hotChartIDs } },
|
||||
{
|
||||
sort: { "calculatedData.skill": -1 },
|
||||
limit: 25,
|
||||
projection: { "calculatedData.skill": 1 },
|
||||
}
|
||||
),
|
||||
GetBestRatingOnSongs(hotSongIDs, userID, game, playtype, "skill"),
|
||||
GetBestRatingOnSongs(coldSongIDs, userID, game, playtype, "skill"),
|
||||
]);
|
||||
|
||||
let skill = 0;
|
||||
@@ -188,6 +175,42 @@ async function CalculateGitadoraSkill(
|
||||
return skill;
|
||||
}
|
||||
|
||||
export async function GetBestRatingOnSongs(
|
||||
songIDs: integer[],
|
||||
userID: integer,
|
||||
game: Game,
|
||||
playtype: Playtypes[Game],
|
||||
ratingProp: "skill",
|
||||
limit = 25
|
||||
): Promise<PBScoreDocument[]> {
|
||||
const r = await db["personal-bests"].aggregate([
|
||||
{
|
||||
$match: {
|
||||
game,
|
||||
playtype,
|
||||
userID,
|
||||
songID: { $in: songIDs },
|
||||
},
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
[`calculatedData.${ratingProp}`]: -1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: "$songID",
|
||||
doc: { $first: "$$ROOT" },
|
||||
},
|
||||
},
|
||||
{
|
||||
$limit: limit,
|
||||
},
|
||||
]);
|
||||
|
||||
return r.map((e: { _id: integer; doc: PBScoreDocument }) => e.doc);
|
||||
}
|
||||
|
||||
// async function CalculateJubility(
|
||||
// game: Game,
|
||||
// playtype: Playtypes[Game],
|
||||
|
||||
Reference in New Issue
Block a user