Spaces:
Running
Running
File size: 9,203 Bytes
c095e08 | 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | import { useState, useEffect } from 'react'
import { predictGame, getTeams } from '../api'
import { TeamLogo, getTeamName } from '../teamLogos'
function Predictions() {
const [teams, setTeams] = useState([])
const [homeTeam, setHomeTeam] = useState('LAL')
const [awayTeam, setAwayTeam] = useState('BOS')
const [prediction, setPrediction] = useState(null)
const [loading, setLoading] = useState(false)
useEffect(() => {
getTeams().then(data => {
setTeams(data.teams || [])
}).catch(console.error)
}, [])
const handlePredict = async () => {
if (!homeTeam || !awayTeam || homeTeam === awayTeam) return
setLoading(true)
try {
const result = await predictGame(homeTeam, awayTeam)
setPrediction(result)
} catch (err) {
console.error('Prediction failed:', err)
} finally {
setLoading(false)
}
}
const homeProb = prediction ? (prediction.home_win_probability * 100) : 50
const awayProb = prediction ? (prediction.away_win_probability * 100) : 50
return (
<div className="animate-fadeIn">
<div className="page-header">
<h1 className="page-title">Game Predictions</h1>
<p className="page-description">Select teams to get AI-powered win probabilities</p>
</div>
{/* Team Selector */}
<div className="card" style={{ marginBottom: 'var(--space-6)' }}>
<div style={{ display: 'grid', gridTemplateColumns: '1fr auto 1fr', gap: 'var(--space-6)', alignItems: 'end' }}>
{/* Away Team */}
<div className="form-group" style={{ marginBottom: 0 }}>
<label className="form-label">Away Team</label>
<div style={{ display: 'flex', alignItems: 'center', gap: 'var(--space-3)' }}>
<TeamLogo abbrev={awayTeam} size="md" />
<select
className="form-select"
value={awayTeam}
onChange={(e) => setAwayTeam(e.target.value)}
>
{teams.map(team => (
<option key={team.id} value={team.abbrev}>{team.abbrev} - {getTeamName(team.abbrev)}</option>
))}
</select>
</div>
</div>
<div style={{ color: 'var(--text-dim)', fontWeight: '600', paddingBottom: 'var(--space-3)' }}>@</div>
{/* Home Team */}
<div className="form-group" style={{ marginBottom: 0 }}>
<label className="form-label">Home Team</label>
<div style={{ display: 'flex', alignItems: 'center', gap: 'var(--space-3)' }}>
<TeamLogo abbrev={homeTeam} size="md" />
<select
className="form-select"
value={homeTeam}
onChange={(e) => setHomeTeam(e.target.value)}
>
{teams.map(team => (
<option key={team.id} value={team.abbrev}>{team.abbrev} - {getTeamName(team.abbrev)}</option>
))}
</select>
</div>
</div>
</div>
<button
className="btn btn-primary btn-lg btn-block"
onClick={handlePredict}
disabled={loading || homeTeam === awayTeam}
style={{ marginTop: 'var(--space-6)' }}
>
{loading ? 'Analyzing...' : 'Generate Prediction'}
</button>
</div>
{/* Prediction Result */}
{prediction && (
<div className="card animate-slideUp">
<div style={{ display: 'grid', gridTemplateColumns: '1fr auto 1fr', gap: 'var(--space-8)', alignItems: 'center' }}>
{/* Away Team */}
<div style={{ textAlign: 'center' }}>
<TeamLogo abbrev={prediction.away_team} size="xl" />
<div style={{ marginTop: 'var(--space-3)' }}>
<div style={{ fontSize: '1.25rem', fontWeight: '600' }}>{prediction.away_team}</div>
<div style={{ fontSize: '0.75rem', color: 'var(--text-muted)' }}>
ELO: {prediction.away_elo?.toFixed(0) || 'N/A'}
</div>
</div>
<div style={{ fontSize: '2.5rem', fontWeight: '700', color: 'var(--accent-secondary)', marginTop: 'var(--space-4)' }}>
{awayProb.toFixed(1)}%
</div>
</div>
{/* Prediction Center */}
<div style={{ textAlign: 'center' }}>
<div style={{ fontSize: '0.6875rem', fontWeight: '600', textTransform: 'uppercase', letterSpacing: '0.1em', color: 'var(--text-muted)', marginBottom: 'var(--space-2)' }}>
Predicted Winner
</div>
<div style={{ fontSize: '1.75rem', fontWeight: '700', color: 'var(--accent-primary)' }}>
{prediction.predicted_winner}
</div>
<span className={`badge confidence-${prediction.confidence}`} style={{ marginTop: 'var(--space-3)' }}>
{prediction.confidence?.toUpperCase()} CONFIDENCE
</span>
<div style={{ marginTop: 'var(--space-4)', fontSize: '0.75rem', color: 'var(--text-muted)' }}>
ELO Difference: {prediction.elo_diff > 0 ? '+' : ''}{prediction.elo_diff?.toFixed(0)}
</div>
</div>
{/* Home Team */}
<div style={{ textAlign: 'center' }}>
<TeamLogo abbrev={prediction.home_team} size="xl" />
<div style={{ marginTop: 'var(--space-3)' }}>
<div style={{ fontSize: '1.25rem', fontWeight: '600' }}>{prediction.home_team}</div>
<div style={{ fontSize: '0.75rem', color: 'var(--text-muted)' }}>
ELO: {prediction.home_elo?.toFixed(0) || 'N/A'}
</div>
</div>
<div style={{ fontSize: '2.5rem', fontWeight: '700', color: 'var(--accent-primary)', marginTop: 'var(--space-4)' }}>
{homeProb.toFixed(1)}%
</div>
</div>
</div>
{/* Probability Bar */}
<div className="probability-bar-container" style={{ marginTop: 'var(--space-8)' }}>
<div className="probability-bar" style={{ height: '8px' }}>
<div className="probability-fill-away" style={{ width: `${awayProb}%` }}></div>
<div className="probability-fill-home" style={{ width: `${homeProb}%` }}></div>
</div>
<div className="probability-labels" style={{ marginTop: 'var(--space-3)' }}>
<span>{prediction.away_team}: {awayProb.toFixed(1)}%</span>
<span>{prediction.home_team}: {homeProb.toFixed(1)}%</span>
</div>
</div>
{/* Factors */}
{prediction.factors && prediction.factors.length > 0 && (
<div style={{ marginTop: 'var(--space-6)', paddingTop: 'var(--space-6)', borderTop: 'var(--border-subtle)' }}>
<h4 style={{ marginBottom: 'var(--space-4)', color: 'var(--text-secondary)' }}>Key Factors</h4>
<ul style={{ listStyle: 'none' }}>
{prediction.factors.map((factor, idx) => (
<li key={idx} style={{
padding: 'var(--space-2) 0',
color: 'var(--text-muted)',
fontSize: '0.875rem'
}}>
• {factor}
</li>
))}
</ul>
</div>
)}
</div>
)}
</div>
)
}
export default Predictions
|