Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
day-mon committed Aug 24, 2024
1 parent c664d88 commit 131a26f
Show file tree
Hide file tree
Showing 3 changed files with 623 additions and 595 deletions.
146 changes: 75 additions & 71 deletions ui/src/client/api.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,85 @@
import axios, { AxiosInstance } from 'axios';
import { Game } from '~/interface.ts';
import axios, {AxiosInstance} from 'axios';
import {Game} from '~/interface.ts';


interface DateResponse {
dates: string[];
model_name: string;
dates: string[];
model_name: string;
}

export class AccuribetAPI {
private client: AxiosInstance;
private static instance: AccuribetAPI;



static getInstance(): AccuribetAPI {
if (!AccuribetAPI.instance) {
AccuribetAPI.instance = new AccuribetAPI();
}
return AccuribetAPI.instance;
}
private constructor() {
this.client = axios.create({
baseURL: import.meta.env.VITE_API_BASE_URL as string,
validateStatus: (status: number) => {
return status < 500;
private client: AxiosInstance;
private static instance: AccuribetAPI;


static getInstance(): AccuribetAPI {
if (!AccuribetAPI.instance) {
AccuribetAPI.instance = new AccuribetAPI();
}
return AccuribetAPI.instance;
}

private constructor() {
this.client = axios.create({
baseURL: import.meta.env.VITE_API_BASE_URL as string,
validateStatus: (status: number) => {
return status < 500;
}
})

}


async getPredictedGames(
date: string,
model_name: string
) {
if (localStorage.getItem(`predictedGames-${date}-${model_name}`)) {
return JSON.parse(localStorage.getItem(`predictedGames-${date}-${model_name}`) as string);
}
const res = await this.client.get('/model/history', {
params: {
date,
model_name
}
})
localStorage.setItem(`predictedGames-${date}-${model_name}`, JSON.stringify(res.data));
return res.data;

}


async predict(
model: string
) {
const res = await this.client.get(`/model/predict/${model}`);
return res.data;
}

async dailyGames(
withOdds: boolean = false
): Promise<Game[]> {
const res = await this.client.get<Game[]>(`/games/daily?with_odds=${withOdds}`);
return res.data;
}

async listModels(): Promise<string[]> {
const res = await this.client.get<string[]>('/model/list');
return res.data;
}

async modelAccuracy(
modelName: string
): Promise<number> {
const res = await this.client.get<number>(`/model/accuracy/${modelName}`);
return res.data;
}


async getDates(): Promise<DateResponse[]> {
const res = await this.client.get<DateResponse[]>('/model/history/dates');
return res.data;
}
})

}


async getPredictedGames(
date: string,
model_name: string
) {
const res = await this.client.get('/model/history', {
params: {
date,
model_name
}
})
return res.data;

}


async predict(
model: string
) {
const res = await this.client.get(`/model/predict/${model}`);
return res.data;
}

async dailyGames(
withOdds: boolean = false
): Promise<Game[]> {
const res = await this.client.get<Game[]>(`/games/daily?with_odds=${withOdds}`);
return res.data;
}

async listModels(): Promise<string[]> {
const res = await this.client.get<string[]>('/model/list');
return res.data;
}

async modelAccuracy(
modelName: string
): Promise<number> {
const res = await this.client.get<number>(`/model/accuracy/${modelName}`);
return res.data;
}


async getDates(): Promise<DateResponse[]> {
const res = await this.client.get<DateResponse[]>('/model/history/dates');
return res.data;
}


}
Loading

0 comments on commit 131a26f

Please sign in to comment.