Job framework for ugs-snapshots

This commit is contained in:
zkldi
2021-07-24 02:59:47 +01:00
parent 51c68dabc1
commit dbb4570c81
8 changed files with 156 additions and 7 deletions
+34
View File
@@ -156,6 +156,40 @@ export function FormatUserDoc(userdoc: PublicUserDocument) {
export async function GetUsersRanking(stats: UserGameStats) {
const gptConfig = GetGamePTConfig(stats.game, stats.playtype);
const aggRes = await db["game-stats"].aggregate([
{
$match: {
game: stats.game,
playtype: stats.playtype,
},
},
{
$group: {
_id: null,
ranking: {
$sum: {
$cond: {
if: {
$gt: [
`$ratings.${gptConfig.defaultProfileRatingAlg}`,
stats.ratings[gptConfig.defaultProfileRatingAlg],
],
},
then: 1,
else: 0,
},
},
},
},
},
]);
return (aggRes[0].ranking + 1) as integer;
}
export async function GetUsersRankingAndOutOf(stats: UserGameStats) {
const gptConfig = GetGamePTConfig(stats.game, stats.playtype);
const aggRes = await db["game-stats"].aggregate([
{
$match: {