mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-28 14:18:04 -05:00
Make tournament summary give set win for rosters of 4
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
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,
|
||||
@@ -57,7 +58,3 @@ export function queryTeamPlayerRatingAverage({
|
||||
playerRatings.length,
|
||||
};
|
||||
}
|
||||
|
||||
export function identifierToUserIds(identifier: string) {
|
||||
return identifier.split("-").map(Number);
|
||||
}
|
||||
|
||||
@@ -72,3 +72,7 @@ export function userIdsToIdentifier(userIds: number[]) {
|
||||
invariant(userIds.length === 4, "userIds for identifier must be length 4");
|
||||
return [...userIds].sort((a, b) => a - b).join("-");
|
||||
}
|
||||
|
||||
export function identifierToUserIds(identifier: string) {
|
||||
return identifier.split("-").map(Number);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ordinal } from "openskill";
|
||||
import { sql } from "~/db/sql";
|
||||
import type { Skill } from "~/db/types";
|
||||
import { identifierToUserIds } from "~/features/mmr/mmr-utils.server";
|
||||
import { identifierToUserIds } from "~/features/mmr/mmr-utils";
|
||||
|
||||
const getStm = (type: "user" | "team") =>
|
||||
sql.prepare(/* sql */ `
|
||||
|
||||
@@ -10,7 +10,11 @@ import invariant from "tiny-invariant";
|
||||
import { removeDuplicates } from "~/utils/arrays";
|
||||
import type { FinalStanding } from "./finalStandings.server";
|
||||
import type { Rating } from "openskill/dist/types";
|
||||
import { rate, userIdsToIdentifier } from "~/features/mmr/mmr-utils";
|
||||
import {
|
||||
rate,
|
||||
userIdsToIdentifier,
|
||||
identifierToUserIds,
|
||||
} from "~/features/mmr/mmr-utils";
|
||||
import shuffle from "just-shuffle";
|
||||
import type { Unpacked } from "~/utils/types";
|
||||
|
||||
@@ -393,10 +397,33 @@ function playerResultDeltas({
|
||||
}
|
||||
}
|
||||
|
||||
const allUserIds = removeDuplicates(match.maps.flatMap((m) => m.userIds));
|
||||
const mostPopularUserIds = (() => {
|
||||
const alphaIdentifiers: string[] = [];
|
||||
const bravoIdentifiers: string[] = [];
|
||||
|
||||
for (const ownerUserId of allUserIds) {
|
||||
for (const otherUserId of allUserIds) {
|
||||
for (const map of match.maps) {
|
||||
const alphaUserIds = map.userIds.filter(
|
||||
(userId) => userIdsToTeamId[userId] === match.opponentOne.id
|
||||
);
|
||||
const bravoUserIds = map.userIds.filter(
|
||||
(userId) => userIdsToTeamId[userId] === match.opponentTwo.id
|
||||
);
|
||||
|
||||
alphaIdentifiers.push(userIdsToIdentifier(alphaUserIds));
|
||||
bravoIdentifiers.push(userIdsToIdentifier(bravoUserIds));
|
||||
}
|
||||
|
||||
const alphaIdentifier = selectMostPopular(alphaIdentifiers);
|
||||
const bravoIdentifier = selectMostPopular(bravoIdentifiers);
|
||||
|
||||
return [
|
||||
...identifierToUserIds(alphaIdentifier),
|
||||
...identifierToUserIds(bravoIdentifier),
|
||||
];
|
||||
})();
|
||||
|
||||
for (const ownerUserId of mostPopularUserIds) {
|
||||
for (const otherUserId of mostPopularUserIds) {
|
||||
if (ownerUserId === otherUserId) continue;
|
||||
|
||||
const ownTournamentTeamId = userIdsToTeamId[ownerUserId];
|
||||
|
||||
@@ -267,6 +267,25 @@ TournamentSummary(
|
||||
}
|
||||
);
|
||||
|
||||
TournamentSummary(
|
||||
"In the case of sub calculates player results based on the most common roster",
|
||||
() => {
|
||||
const summary = summarize({
|
||||
results: resultsWithSubbedRoster,
|
||||
});
|
||||
|
||||
assert.not.ok(
|
||||
summary.playerResultDeltas.find(
|
||||
(p) =>
|
||||
p.ownerUserId === 5 &&
|
||||
p.otherUserId === 20 &&
|
||||
(p.setWins > 0 || p.setLosses > 0)
|
||||
),
|
||||
"player 5 should not have a result against player 20 (sub for only one game)"
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
TournamentSummary("calculates results of mates", () => {
|
||||
const summary = summarize();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { sql } from "~/db/sql";
|
||||
import type { TournamentSummary } from "../core/summarizer.server";
|
||||
import { ordinal } from "openskill";
|
||||
import type { Skill } from "~/db/types";
|
||||
import { identifierToUserIds } from "~/features/mmr/mmr-utils.server";
|
||||
import { identifierToUserIds } from "~/features/mmr/mmr-utils";
|
||||
|
||||
const addSkillStm = sql.prepare(/* sql */ `
|
||||
insert into "Skill" (
|
||||
|
||||
Reference in New Issue
Block a user