Zuletzt aktiv 1 week ago

nuno hat die Gist bearbeitet 1 week ago. Zu Änderung gehen

1 file changed, 75 insertions

gistfile1.txt(Datei erstellt)

@@ -0,0 +1,75 @@
1 + function buildRows(historyKey: TGKey): ResultRow[] {
2 + const { slot, date } = TGKey.parse(historyKey);
3 + let players: UserKey[] = Attendance.players(historyKey);
4 +
5 + if (players.length === 0) {
6 + const history = Store.read<{ scores: TGScore[] }>(TGKey.toHistoryPath(historyKey));
7 + if (history?.scores) {
8 + players = [...new Set(history.scores.map((s: TGScore) => s.userKey))];
9 + }
10 + }
11 +
12 + const weekKey = WRank.weekKey(new Date(date));
13 + const addedUsers = new Set<UserKey>();
14 + const rows: ResultRow[] = [];
15 +
16 + for (const userKey of players) {
17 + const chars = CharacterRegistry.forUser(userKey);
18 +
19 + for (const char of chars) {
20 + const score = Score.get({ character: char, slot, historyKey });
21 + if (!score) continue;
22 +
23 + const wrEntry = WRank.entry(char.name, char.nation, weekKey);
24 + const position = score.wRankAtSubmission
25 + ? {
26 + currentRank: score.wRankAtSubmission.rank,
27 + previousRank: score.wRankAtSubmission.rank - score.wRankAtSubmission.delta,
28 + }
29 + : wrEntry
30 + ? { currentRank: wrEntry.currentRank, previousRank: wrEntry.previousRank }
31 + : undefined;
32 +
33 + rows.push({
34 + character: char,
35 + score,
36 + position,
37 + leavesCount: Leaves.countForChar({ characterName: char.name }),
38 + });
39 + addedUsers.add(userKey);
40 + break;
41 + }
42 +
43 + if (!addedUsers.has(userKey)) {
44 + const history = Store.read<{ scores: TGScore[] }>(TGKey.toHistoryPath(historyKey));
45 + const score = history?.scores.find((s: TGScore) => s.userKey === userKey);
46 + if (score) {
47 + const foundChar = CharacterRegistry.find(score.characterName);
48 + const classKey = (typeof score.class === "object"
49 + ? (score.class as any)?.key
50 + : score.class) as ClassKey;
51 + const char: Character = foundChar ?? {
52 + name: score.characterName,
53 + class: CLASSES[classKey] ?? { key: classKey, name: classKey, shortName: classKey },
54 + level: 0,
55 + nation: score.nation,
56 + ownerKey: score.userKey,
57 + };
58 + const wrEntry = WRank.entry(char.name, char.nation, weekKey);
59 + const position = score.wRankAtSubmission
60 + ? {
61 + currentRank: score.wRankAtSubmission.rank,
62 + previousRank: score.wRankAtSubmission.rank - score.wRankAtSubmission.delta,
63 + }
64 + : wrEntry
65 + ? { currentRank: wrEntry.currentRank, previousRank: wrEntry.previousRank }
66 + : undefined;
67 +
68 + rows.push({ character: char, score, position, leavesCount: 0 });
69 + addedUsers.add(userKey);
70 + }
71 + }
72 + }
73 +
74 + return rows;
75 + }
Neuer Älter