From e3d5d1a1924cfd92278263c133a91c68b5a34497 Mon Sep 17 00:00:00 2001 From: Francisco Salgueiro Date: Sat, 21 Oct 2023 17:44:00 +0100 Subject: [PATCH] only download rated non-variant games from lichess --- src/components/common/AccountCards.tsx | 46 +++++++++++++------------- src/utils/lichess.tsx | 28 ++++++++-------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/components/common/AccountCards.tsx b/src/components/common/AccountCards.tsx index 1737fa0f..7ef2573a 100644 --- a/src/components/common/AccountCards.tsx +++ b/src/components/common/AccountCards.tsx @@ -27,6 +27,27 @@ function AccountCards({ if (session.lichess && session.lichess.account) { const account = session.lichess.account; const lichessSession = session.lichess; + const totalGames = + (account.perfs.ultraBullet?.games ?? 0) + + (account.perfs.bullet?.games ?? 0) + + (account.perfs.blitz?.games ?? 0) + + (account.perfs.rapid?.games ?? 0) + + (account.perfs.classical?.games ?? 0); + + const stats = []; + const speeds = ["bullet", "blitz", "rapid", "classical"] as const; + + for (const speed of speeds) { + const perf = account.perfs[speed]; + if (perf) { + stats.push({ + value: perf.rating, + label: speed, + diff: perf.prog, + }); + } + } + return ( { setSessions((sessions) => sessions.filter((s) => s.lichess?.account.id !== account.id) @@ -67,28 +88,7 @@ function AccountCards({ ) ); }} - stats={[ - { - value: account.perfs.bullet.rating, - label: "Bullet", - diff: account.perfs.bullet.prog, - }, - { - value: account.perfs.blitz.rating, - label: "Blitz", - diff: account.perfs.blitz.prog, - }, - { - value: account.perfs.rapid.rating, - label: "Rapid", - diff: account.perfs.rapid.prog, - }, - { - value: account.perfs.classical.rating, - label: "Classical", - diff: account.perfs.classical.prog, - }, - ]} + stats={stats} /> ); } diff --git a/src/utils/lichess.tsx b/src/utils/lichess.tsx index 18783fde..d43bf138 100644 --- a/src/utils/lichess.tsx +++ b/src/utils/lichess.tsx @@ -30,19 +30,19 @@ export type LichessAccount = { id: string; username: string; perfs: { - chess960: LichessPerf; - atomic: LichessPerf; - racingKings: LichessPerf; - ultraBullet: LichessPerf; - blitz: LichessPerf; - kingOfTheHill: LichessPerf; - bullet: LichessPerf; - correspondence: LichessPerf; - horde: LichessPerf; - puzzle: LichessPerf; - classical: LichessPerf; - rapid: LichessPerf; - storm: { + chess960?: LichessPerf; + atomic?: LichessPerf; + racingKings?: LichessPerf; + ultraBullet?: LichessPerf; + blitz?: LichessPerf; + kingOfTheHill?: LichessPerf; + bullet?: LichessPerf; + correspondence?: LichessPerf; + horde?: LichessPerf; + puzzle?: LichessPerf; + classical?: LichessPerf; + rapid?: LichessPerf; + storm?: { runs: number; score: number; }; @@ -219,7 +219,7 @@ export async function downloadLichess( timestamp: number | null, token?: string ) { - let url = `${baseURL}/games/user/${player}`; + let url = `${baseURL}/games/user/${player}?perfType=ultraBullet,bullet,blitz,rapid,classical,correspondence&rated=true`; if (timestamp) { url += `?since=${timestamp}`; }