sendou.ink/app/features/mmr/mmr-utils.server.ts
Kalle 218c854ffb
SendouQ match page show & save powers + plus tier status (#1519)
* Initial

* New group cards initial

* Remove unused prop

* Vc

* Styling for after the match is locked

* Team

* Impersonate always in dev

* Diff

* Fix crash if match has no memento when inserting skill
2023-10-03 21:25:03 +03:00

61 lines
1.4 KiB
TypeScript

import { rating } from "openskill";
import { findCurrentSkillByUserId } from "./queries/findCurrentSkillByUserId.server";
import { findCurrentTeamSkillByIdentifier } from "./queries/findCurrentTeamSkillByIdentifier.server";
import { identifierToUserIds } from "./mmr-utils";
export function queryCurrentUserRating({
userId,
season,
}: {
userId: number;
season: number;
}) {
const skill = findCurrentSkillByUserId({ userId, season: season ?? null });
if (!skill) {
return { rating: rating(), matchesCount: 0 };
}
return { rating: rating(skill), matchesCount: skill.matchesCount };
}
export function queryCurrentTeamRating({
identifier,
season,
}: {
identifier: string;
season: number;
}) {
const skill = findCurrentTeamSkillByIdentifier({
identifier,
season,
});
if (!skill) return { rating: rating(), matchesCount: 0 };
return { rating: rating(skill), matchesCount: skill.matchesCount };
}
export function queryTeamPlayerRatingAverage({
identifier,
season,
}: {
identifier: string;
season: number;
}) {
const playerRatings = identifierToUserIds(identifier).map(
(userId) => queryCurrentUserRating({ userId, season }).rating,
);
if (playerRatings.length === 0) return rating();
return {
mu:
playerRatings.reduce((acc, cur) => acc + cur.mu, 0) /
playerRatings.length,
sigma:
playerRatings.reduce((acc, cur) => acc + cur.sigma, 0) /
playerRatings.length,
};
}