File size: 1,869 Bytes
c095e08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e6f1d3
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
 * API utilities for NBA ML Predictor
 */

// Use relative URL in production, localhost in development
const API_BASE = import.meta.env.DEV ? 'http://localhost:8000/api' : '/api';


/**
 * Generic fetch wrapper with error handling
 */
async function fetchAPI(endpoint, options = {}) {
    try {
        const response = await fetch(`${API_BASE}${endpoint}`, {
            ...options,
            headers: {
                'Content-Type': 'application/json',
                ...options.headers,
            },
        });

        if (!response.ok) {
            throw new Error(`API Error: ${response.status}`);
        }

        return await response.json();
    } catch (error) {
        console.error('API Error:', error);
        throw error;
    }
}

/**
 * Get live games with predictions
 */
export async function getLiveGames() {
    return fetchAPI('/games/live');
}

/**
 * Get upcoming games
 */
export async function getUpcomingGames(days = 7) {
    return fetchAPI(`/games/upcoming?days=${days}`);
}

/**
 * Get prediction for a single game
 */
export async function predictGame(home, away) {
    return fetchAPI(`/predict?home=${home}&away=${away}`);
}

/**
 * Get model accuracy stats
 */
export async function getAccuracy() {
    return fetchAPI('/accuracy');
}

/**
 * Get MVP race standings
 */
export async function getMvpRace() {
    return fetchAPI('/mvp');
}

/**
 * Get championship odds
 */
export async function getChampionshipOdds() {
    return fetchAPI('/championship');
}

/**
 * Get list of all teams
 */
export async function getTeams() {
    return fetchAPI('/teams');
}

/**
 * Health check
 */
export async function healthCheck() {
    return fetchAPI('/health');
}

/**
 * Get detailed team statistics for head-to-head comparison
 */
export async function getTeamStats(team) {
    return fetchAPI(`/team-stats?team=${team}`);
}