Fix SendouQ full group skill sorting
Some checks are pending
E2E Tests / e2e (push) Waiting to run
Tests and checks on push / run-checks-and-tests (push) Waiting to run
Updates translation progress / update-translation-progress-issue (push) Waiting to run

This commit is contained in:
Kalle
2026-08-04 22:13:11 +03:00
parent 5adf4be0eb
commit d5fb30bf0c
2 changed files with 43 additions and 8 deletions

View File

@@ -673,6 +673,48 @@ describe("SendouQ", () => {
expect(groups[0].id).toBe(closerGroup);
});
test("full group one sub-tier away sorted above full group six sub-tiers away", async () => {
const mus = [
// own group -> DIAMOND
97, 96, 95, 94,
// adjacent group -> PLATINUM+ (one sub-tier below own)
93, 92, 91, 90,
// far group -> SILVER (six sub-tiers below own)
76, 75, 74, 73,
// rest of the ladder so every sub-tier cutoff lands on a distinct ordinal
99,
98, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 72, 71, 70,
69, 68, 67, 66, 65, 64, 63, 62, 61, 60,
];
await users.create(mus.length);
for (const [i, mu] of mus.entries()) {
await createSkill(i + 1, mu);
}
await refreshUserSkills(1);
await createGroup([1, 2, 3, 4]);
const adjacentTierGroupId = await createGroup([5, 6, 7, 8]);
const farTierGroupId = await createGroup([9, 10, 11, 12]);
await alignLatestActionAt([adjacentTierGroupId, farTierGroupId]);
await refreshSendouQInstance();
const groups = SendouQ.lookingGroups(users.id(1));
expect(groups).toHaveLength(2);
const adjacentTierGroup = groups.find(
(g) => g.id === adjacentTierGroupId,
)!;
const farTierGroup = groups.find((g) => g.id === farTierGroupId)!;
expect(adjacentTierGroup.tierRange?.diff).toEqual([-1, 1]);
expect(farTierGroup.tier).toMatchObject({
name: "SILVER",
isPlus: false,
});
expect(groups[0].id).toBe(adjacentTierGroupId);
});
test("newer groups sorted first when skill is equal", async () => {
await createSkill(1, 1000);
await createSkill(2, 1000);

View File

@@ -286,8 +286,8 @@ class SendouQClass {
}),
)
.map(this.#getGroupReplayMapper(userId))
.map(this.#getAddTierRangeMapper(ownGroup.tier))
.sort(this.#getSkillSortComparator(ownGroup.tier))
.map(this.#getAddTierRangeMapper(ownGroup.tier))
.map((group) => this.#censorGroup(group));
}
@@ -404,7 +404,6 @@ class SendouQClass {
return <
T extends {
members: unknown[];
tierRange: TierRange | null;
tier: TieredSkill["tier"] | null;
latestActionAt: number;
},
@@ -419,12 +418,6 @@ class SendouQClass {
return aIsFull ? 1 : -1;
}
if (a.tierRange && b.tierRange) {
if (a.tierRange.diff[1] !== b.tierRange.diff[1]) {
return a.tierRange.diff[1] - b.tierRange.diff[1];
}
}
const ownTierIndex = getTierIndex(ownTier, this.#isAccurateTiers);
if (typeof ownTierIndex === "number") {
const diffA = Math.abs(