-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
623 additions
and
595 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.