diff --git a/ui/src/client/api.ts b/ui/src/client/api.ts index e3426fd..f61e190 100644 --- a/ui/src/client/api.ts +++ b/ui/src/client/api.ts @@ -32,12 +32,12 @@ export class AccuribetAPI { async getPredictedGames( date: string, - model: string + model_name: string ) { const res = await this.client.get('/model/history', { params: { date, - model + model_name } }) return res.data; diff --git a/ui/src/interface.ts b/ui/src/interface.ts index de1a079..e2b98da 100644 --- a/ui/src/interface.ts +++ b/ui/src/interface.ts @@ -11,6 +11,25 @@ export interface Game { odds: Odds[]; } +export interface HistoryGame { + game_id: string; + date: string; + home_team_name: string; + home_team_score: number; + away_team_name: string; + away_team_score: number; + model_name: string; + prediction: string; + winner: string; + confidence: number; + prediction_was_correct: boolean; +} + +export interface HistoryDate { + model_name: string; + dates: string[]; +} + export interface GameWithPrediction extends Game { prediction?: Prediction; } diff --git a/ui/src/pages/History.tsx b/ui/src/pages/History.tsx index f38e28b..10f2801 100644 --- a/ui/src/pages/History.tsx +++ b/ui/src/pages/History.tsx @@ -1,7 +1,8 @@ -import { AccuribetAPI } from '~/client/api.ts'; -import { createResource, createSignal, For, Match, Show, Switch } from 'solid-js'; -import { AnimationDiv } from '~/components/animated-div.tsx'; -import { Loading } from '~/components/loading.tsx'; +import { AccuribetAPI } from "~/client/api.ts"; +import { createResource, createSignal, For, Match, Show, Switch } from "solid-js"; +import { AnimationDiv } from "~/components/animated-div.tsx"; +import { Loading } from "~/components/loading.tsx"; +import { HistoryDate, HistoryGame } from "~/interface.ts"; async function fetchHistory() { const instance = AccuribetAPI.getInstance(); @@ -11,17 +12,48 @@ async function fetchHistory() { async function fetchHistoryForModelOnDate(model: string, date: string) { const instance = AccuribetAPI.getInstance(); return await instance.getPredictedGames(date, model); - } - export function History() { + const [dates] = createResource(fetchHistory); + const [selectedModel, setSelectedModel] = createSignal(""); + const [selectedDate, setSelectedDate] = createSignal(""); + const [history, setHistory] = createSignal([]); + const [error, setError] = createSignal(""); + + const handleDateChange = (e: Event) => { + let target = e.target as HTMLInputElement; + setSelectedDate(target.value); + setHistory([]); + + updateHistory().then(() => { + setError(""); + }); + }; + + const updateHistory = async () => { + const data = await fetchHistoryForModelOnDate(selectedModel(), selectedDate()); - const [dates] = createResource(fetchHistory); - const [selectedModel, setSelectedModel] = createSignal('') - const [selectedDate, setSelectedDate] = createSignal('') + console.log("oldest date", oldestDateForModel()); + if (data) { + setHistory(data as HistoryGame[]); + console.log(history()); + } else { + setHistory([]); + setError("No data found for this model on this date"); + } + }; + const oldestDateForModel = () => { + if (!dates.error && dates()) { + // @ts-ignore + const datesForModel = dates().find(date => date.model_name === selectedModel()); + if (datesForModel) { + return datesForModel.dates[datesForModel.dates.length - 1]; + } + } + }; return ( @@ -33,32 +65,63 @@ export function History() {

Error fetching dates

- - + + I would like to see the history of the + model + + + Error! {error()} + + + + + + + {game => ( +
+ + {game.home_team_name} vs {game.away_team_name} + + + {game.home_team_score} - {game.away_team_score} + + {game.date} +
+ )} +
+
- ) + ); }