From 7e8b5ed9a817e0245313d260a1873ea8b8ef5145 Mon Sep 17 00:00:00 2001 From: Andres Date: Sat, 19 Apr 2025 13:52:51 +0200 Subject: [PATCH] add money report to log parser --- src/app/(home)/log-parser/page.tsx | 139 ++++++++++++++++++++++++----- 1 file changed, 119 insertions(+), 20 deletions(-) diff --git a/src/app/(home)/log-parser/page.tsx b/src/app/(home)/log-parser/page.tsx index 8ca05ac..830076b 100644 --- a/src/app/(home)/log-parser/page.tsx +++ b/src/app/(home)/log-parser/page.tsx @@ -9,6 +9,14 @@ import { DropzoneUploadIcon, DropzoneZone, } from '@/components/ui/dropzone' +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from '@/components/ui/table' import { useState } from 'react' type LogLine = { @@ -30,6 +38,9 @@ type Game = { startDate: Date endDate: Date | null lastLives: number + opponentMoneySpent: number + moneySpentPerShop: (number | null)[] + moneySpentPerShopOpponent: (number | null)[] } type GameState = { @@ -48,9 +59,12 @@ const initGame = (): Game => ({ isHost: null, moneyGained: 0, moneySpent: 0, + opponentMoneySpent: 0, startDate: new Date(), endDate: null, lastLives: 4, + moneySpentPerShop: [], + moneySpentPerShopOpponent: [], }) const formatDuration = (seconds: number): string => { @@ -68,7 +82,14 @@ const formatDuration = (seconds: number): string => { export default function LogParser() { const [logLines, setLogLines] = useState([]) - + const [moneyReports, setMoneyReports] = useState< + { + totalSpent: number + totalSpentOpponent: number + spentPerShop: (number | null)[] + spentPerShopOpponent: (number | null)[] + }[] + >([]) const parseLogFile = async (file: File) => { const state: GameState = { currentGame: null, @@ -100,7 +121,27 @@ export default function LogParser() { } continue } - + if (line.includes(' Client got spentLastShop message')) { + const match = line.match(/amount: (\d+)/) + if (match) { + if (!state.currentGame) continue + const amount = match[1] ? Number.parseInt(match[1]) : 0 + state.currentGame.opponentMoneySpent += amount + state.currentGame.moneySpentPerShopOpponent.push(amount) + } + } + if (line.includes('Client sent message: action:spentLastShop')) { + const match = line.match(/amount:(\d+)/) + if (match) { + if (!state.currentGame) continue + const amount = match[1] ? Number.parseInt(match[1]) : 0 + state.currentGame.moneySpentPerShop.push(amount) + } + } + if (line.includes('Client sent message: action:skip')) { + if (!state.currentGame) continue + state.currentGame.moneySpentPerShop.push(null) + } if (lineLower.includes('lobbyinfo message')) { if (line.includes('host:')) { const hostMatch = line.match(/host: ([^ )]+)/) @@ -126,7 +167,6 @@ export default function LogParser() { console.log(deckMatch, seedTypeMatch) lastSeenDeck = deckMatch?.[1] || null - console.log({ lastSeenDeck }) continue } @@ -301,7 +341,7 @@ export default function LogParser() { const totalSpent = state.games.reduce((sum, g) => sum + g.moneySpent, 0) lines.unshift( - { text: `=== Overall Summary ===`, type: 'system' }, + { text: '=== Overall Summary ===', type: 'system' }, { text: `Total Games: ${state.games.length}`, type: 'system' }, { text: `Total Money Gained: $${totalGained}`, type: 'system' }, { text: `Total Money Spent: $${totalSpent}`, type: 'system' }, @@ -313,6 +353,14 @@ export default function LogParser() { { text: '', type: 'system' } ) + setMoneyReports( + state.games.map((game) => ({ + totalSpent: game.moneySpent, + totalSpentOpponent: game.opponentMoneySpent, + spentPerShop: game.moneySpentPerShop, + spentPerShopOpponent: game.moneySpentPerShopOpponent, + })) + ) setLogLines(lines) } catch (err) { console.error('Error parsing log:', err) @@ -323,7 +371,7 @@ export default function LogParser() { return (
-
- {logLines.map((line, i) => ( -
- {line.text} -
- ))} +
+
+ {logLines.map((line, i) => ( +
+ key={i} + className={`py-2 ${ + line.type === 'event' + ? 'text-blue-400' + : line.type === 'status' + ? 'text-green-400' + : 'font-mono text-gray-400' + }`} + > + {line.text} +
+ ))} +
+
+ {moneyReports.map((report, i) => ( + // biome-ignore lint/suspicious/noArrayIndexKey: +
+
Game {i + 1}
+ + + + + Shop # + + + Logs owner + + + Opponent + + + + + {report.spentPerShop.map((spent, j) => ( + // biome-ignore lint/suspicious/noArrayIndexKey: + + + {j + 1} + + + {spent ?? 'Skipped'} + + + {report.spentPerShopOpponent[j] ?? 'Skipped'} + + + ))} + + Total + + {report.totalSpent} + + + {report.totalSpentOpponent} + + + +
+
+ ))} +
)