From 4d96fbf4145e3f05ad1e63243197fd11996e7f49 Mon Sep 17 00:00:00 2001 From: quarterback Date: Wed, 12 Mar 2025 21:54:35 -0700 Subject: [PATCH] Create page.jsx --- app/autosummary/page.jsx | 107 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 app/autosummary/page.jsx diff --git a/app/autosummary/page.jsx b/app/autosummary/page.jsx new file mode 100644 index 0000000..9b8eef8 --- /dev/null +++ b/app/autosummary/page.jsx @@ -0,0 +1,107 @@ +// pages/index.tsx +import { useState } from 'react'; +import { Textarea } from '@/components/ui/textarea'; +import { Button } from '@/components/ui/button'; +import { Card, CardContent } from '@/components/ui/card'; + +const parseBNN = (text: string) => { + const lines = text.split('\n'); + const summary: any = { + name: '', + team: '', + position: '', + isPitcher: false, + advancedStats: {}, + leaderboards: [] + }; + + for (const line of lines) { + if (line.includes('AGE:')) { + summary.name = line.split('AGE:')[0].trim(); + summary.position = line.split(' ')[0]; + } + if (line.includes('MLB')) { + const [_, nameLine] = line.split('MLB'); + summary.team = nameLine?.trim(); + } + if (line.includes('WAR')) { + const match = line.match(/WAR\s+(\d+\.\d)/); + if (match) summary.advancedStats.WAR = parseFloat(match[1]); + } + if (line.includes('wRC+')) { + const match = line.match(/wRC\+\s+(\d+)/); + if (match) summary.advancedStats.wRC = parseInt(match[1]); + } + if (line.includes('FIP')) { + const match = line.match(/FIP\s+(\d+\.\d+)/); + if (match) summary.advancedStats.FIP = parseFloat(match[1]); + } + if (line.includes('ERA')) { + const match = line.match(/ERA\s+(\d+\.\d+)/); + if (match) summary.advancedStats.ERA = parseFloat(match[1]); + } + if (line.includes('OPS')) { + const match = line.match(/OPS\s+(\d+\.\d+)/); + if (match) summary.advancedStats.OPS = parseFloat(match[1]); + } + if (line.includes('ISO')) { + const match = line.match(/ISO\s+(\d+\.\d+)/); + if (match) summary.advancedStats.ISO = parseFloat(match[1]); + } + if (line.includes('LEADERBOARD APPEARANCES')) { + summary.leaderboards.push(...lines.slice(lines.indexOf(line) + 1).filter(l => l.trim() !== '')); + } + } + summary.isPitcher = !!summary.advancedStats.FIP; + return summary; +}; + +export default function Home() { + const [text, setText] = useState(''); + const [summary, setSummary] = useState(null); + + const handleAnalyze = () => { + const result = parseBNN(text); + setSummary(result); + }; + + return ( +
+

OOTP Auto Summary Generator

+