gistfile1.txt
· 2.1 KiB · Text
Originalformat
function buildRows(historyKey: TGKey): ResultRow[] {
const { slot, date } = TGKey.parse(historyKey);
let players: UserKey[] = Attendance.players(historyKey);
const rows: ResultRow[] = [];
const weekKey = WRank.weekKey(new Date(date));
// Fallback — read from history file directly
if (players.length === 0) {
const history = Store.read<{ scores: TGScore[] }>(TGKey.toHistoryPath(historyKey));
if (history?.scores) {
players = [...new Set(history.scores.map((s: TGScore) => s.userKey))];
}
}
for (const userKey of players) {
const chars = CharacterRegistry.forUser(userKey);
// Find which character this user played in this TG
// by checking score history
for (const char of chars) {
const score = Score.get({ character: char, slot, historyKey });
if (!score) continue; // skip chars with no score for this TG
const wrEntry = WRank.entry(char.name, char.nation, weekKey);
rows.push({
character: char,
score,
position: wrEntry ? {
currentRank: wrEntry.currentRank,
previousRank: wrEntry.previousRank,
} : undefined,
leavesCount: Leaves.countForChar({ characterName: char.name }),
});
break; // found the char for this user, move to the next user
}
if (!rows.find(r => r.character.ownerKey === userKey)) {
// Build from score directly
const history = Store.read<{ scores: TGScore[] }>(TGKey.toHistoryPath(historyKey));
const score = history?.scores.find((s: TGScore) => s.userKey === userKey);
if (score) {
const foundChar = CharacterRegistry.find(score.characterName);
const char: Character = foundChar ?? {
name: score.characterName,
class: CLASSES[score.class as ClassKey] ?? { key: score.class as ClassKey, name: score.class, shortName: score.class },
level: 0,
nation: score.nation,
ownerKey: score.userKey,
};
rows.push({ character: char, score, leavesCount: 0 });
}
}
}
return rows;
}
| 1 | function buildRows(historyKey: TGKey): ResultRow[] { |
| 2 | const { slot, date } = TGKey.parse(historyKey); |
| 3 | let players: UserKey[] = Attendance.players(historyKey); |
| 4 | const rows: ResultRow[] = []; |
| 5 | const weekKey = WRank.weekKey(new Date(date)); |
| 6 | |
| 7 | // Fallback — read from history file directly |
| 8 | if (players.length === 0) { |
| 9 | const history = Store.read<{ scores: TGScore[] }>(TGKey.toHistoryPath(historyKey)); |
| 10 | if (history?.scores) { |
| 11 | players = [...new Set(history.scores.map((s: TGScore) => s.userKey))]; |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | for (const userKey of players) { |
| 16 | const chars = CharacterRegistry.forUser(userKey); |
| 17 | // Find which character this user played in this TG |
| 18 | // by checking score history |
| 19 | for (const char of chars) { |
| 20 | const score = Score.get({ character: char, slot, historyKey }); |
| 21 | if (!score) continue; // skip chars with no score for this TG |
| 22 | |
| 23 | const wrEntry = WRank.entry(char.name, char.nation, weekKey); |
| 24 | |
| 25 | rows.push({ |
| 26 | character: char, |
| 27 | score, |
| 28 | position: wrEntry ? { |
| 29 | currentRank: wrEntry.currentRank, |
| 30 | previousRank: wrEntry.previousRank, |
| 31 | } : undefined, |
| 32 | leavesCount: Leaves.countForChar({ characterName: char.name }), |
| 33 | }); |
| 34 | break; // found the char for this user, move to the next user |
| 35 | } |
| 36 | |
| 37 | if (!rows.find(r => r.character.ownerKey === userKey)) { |
| 38 | // Build from score directly |
| 39 | const history = Store.read<{ scores: TGScore[] }>(TGKey.toHistoryPath(historyKey)); |
| 40 | const score = history?.scores.find((s: TGScore) => s.userKey === userKey); |
| 41 | if (score) { |
| 42 | const foundChar = CharacterRegistry.find(score.characterName); |
| 43 | const char: Character = foundChar ?? { |
| 44 | name: score.characterName, |
| 45 | class: CLASSES[score.class as ClassKey] ?? { key: score.class as ClassKey, name: score.class, shortName: score.class }, |
| 46 | level: 0, |
| 47 | nation: score.nation, |
| 48 | ownerKey: score.userKey, |
| 49 | }; |
| 50 | rows.push({ character: char, score, leavesCount: 0 }); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return rows; |
| 56 | } |