diff --git a/data/game_states/2025/gs-season.db b/data/game_states/2025/gs-season.db index 69be1b77..ec30dea4 100644 Binary files a/data/game_states/2025/gs-season.db and b/data/game_states/2025/gs-season.db differ diff --git a/pkg/gamestate/handler.go b/pkg/gamestate/handler.go index 8aaf0c5b..660762b0 100644 --- a/pkg/gamestate/handler.go +++ b/pkg/gamestate/handler.go @@ -581,6 +581,16 @@ func (handler *GameStateHandler) RefreshWeeklyStats() error { return err } + // Remove the weekly projections table from the game state + if err := handler.db.Exec(`DROP TABLE IF EXISTS weekly_projections;`).Error; err != nil { + return err + } + + // Remove the weekly injuries table from the game state + if err := handler.db.Exec(`DROP TABLE IF EXISTS weekly_injuries;`).Error; err != nil { + return err + } + // Attach the other DB attachQuery := fmt.Sprintf("ATTACH DATABASE '%s' AS other;", statsDBFile) println(attachQuery) @@ -592,6 +602,14 @@ func (handler *GameStateHandler) RefreshWeeklyStats() error { return err } + if err := handler.db.Exec(`CREATE TABLE weekly_projections AS SELECT * FROM other.weekly_projections;`).Error; err != nil { + return err + } + + if err := handler.db.Exec(`CREATE TABLE weekly_injuries AS SELECT * FROM other.weekly_injuries;`).Error; err != nil { + return err + } + if err := handler.db.Exec(`DETACH DATABASE other;`).Error; err != nil { return err } diff --git a/ux/src/App.js b/ux/src/App.js index b8267fca..312d416b 100644 --- a/ux/src/App.js +++ b/ux/src/App.js @@ -9,6 +9,8 @@ function App() { const [sortColumn, setSortColumn] = useState(null); const [sortDirection, setSortDirection] = useState("asc"); const [filterText, setFilterText] = useState(""); + const [selectedWeek, setSelectedWeek] = useState(null); + const [currentWeek, setCurrentWeek] = useState(null); // Theme: 'light' | 'dark' | 'system' const [themePref, setThemePref] = useState(() => { try { @@ -60,70 +62,72 @@ function App() { loadDb(); }, []); + // Fetch and initialize current week useEffect(() => { if (!db) return; - const fetchCurrentWeek = () => { - if (!db) return null; - try { - const result = db.exec( - "SELECT current_fantasy_week FROM game_statuses LIMIT 1;" - ); - if (result.length > 0 && result[0].values.length > 0) { - return result[0].values[0][0]; + try { + const result = db.exec( + "SELECT current_fantasy_week FROM game_statuses LIMIT 1;" + ); + if (result.length > 0 && result[0].values.length > 0) { + const week = result[0].values[0][0]; + setCurrentWeek(week); + if (selectedWeek === null) { + setSelectedWeek(week); } - } catch (err) { - console.error("Failed to fetch current week:", err); } - return null; - }; + } catch (err) { + console.error("Failed to fetch current week:", err); + } + }, [db, selectedWeek]); - const week = fetchCurrentWeek(); - if (week == null) return; + useEffect(() => { + if (!db || selectedWeek === null) return; const queries = { current: ` SELECT - week, - home_bot.name as home_bot_name, - home_score, + week, + home_bot.name as home_bot_name, + home_score, visitor_bot.name as visitor_bot_name, - visitor_score, - winning_bot.name as winning_bot_name + visitor_score, + winning_bot.name as winning_bot_name FROM matchups as m LEFT JOIN bots AS home_bot ON m.home_bot_id = home_bot.id LEFT JOIN bots AS visitor_bot ON m.visitor_bot_id = visitor_bot.id LEFT JOIN bots AS winning_bot ON m.winning_bot_id = winning_bot.id - WHERE week = ${week} + WHERE week = ${selectedWeek} `, last: ` SELECT - week, - home_bot.name as home_bot_name, - home_score, + week, + home_bot.name as home_bot_name, + home_score, visitor_bot.name as visitor_bot_name, - visitor_score, - winning_bot.name as winning_bot_name + visitor_score, + winning_bot.name as winning_bot_name FROM matchups as m LEFT JOIN bots AS home_bot ON m.home_bot_id = home_bot.id LEFT JOIN bots AS visitor_bot ON m.visitor_bot_id = visitor_bot.id LEFT JOIN bots AS winning_bot ON m.winning_bot_id = winning_bot.id - WHERE week = ${week - 1} + WHERE week = ${selectedWeek - 1} `, leaderboard: ` WITH botScores AS ( - SELECT + SELECT b.Name, SUM(IIF(b.id = m.home_bot_id, home_score, 0) + IIF(b.id = m.visitor_bot_id, visitor_score, 0)) AS totalPoints, SUM(IIF(b.id = m.winning_bot_id, 1, 0)) AS numWins, SUM(IIF(b.id != m.winning_bot_id, 1, 0)) AS numLosses FROM bots AS b INNER JOIN matchups AS m - ON (b.id = m.visitor_bot_id OR b.id = m.home_bot_id) - WHERE week < ${week} + ON (b.id = m.visitor_bot_id OR b.id = m.home_bot_id) + WHERE week < ${selectedWeek} GROUP BY 1 ) - SELECT + SELECT ROW_NUMBER() OVER (ORDER BY numWins DESC, totalPoints DESC) AS rank, * FROM botScores @@ -136,9 +140,18 @@ function App() { INNER JOIN weekly_stats AS wk ON p.id = wk.fantasypros_id GROUP BY 1,2,3,4 ) - SELECT p.id, p.full_name, p.allowed_positions, b.name AS teamName, totalPoints + SELECT + p.id, + p.full_name, + p.allowed_positions, + b.name AS teamName, + totalPoints, + wi.game_status AS injury_status, + wp.FPTS AS projected_points FROM playerPoints AS p LEFT JOIN bots AS b ON p.current_bot_id = b.id + LEFT JOIN weekly_injuries AS wi ON p.id = wi.fantasypros_id AND wi.week = ${selectedWeek} + LEFT JOIN weekly_projections AS wp ON p.id = wp.fantasypros_id AND wp.week = ${selectedWeek} ORDER BY b.name, p.full_name `, }; @@ -163,7 +176,7 @@ function App() { setColumns([]); setData([]); } - }, [db, activeTab]); + }, [db, activeTab, selectedWeek]); const lightVars = { background: "#ffffff", @@ -325,6 +338,29 @@ function App() {

Botblitz 2025

+
+ + +