nexus963-dev commited on
Commit
507e0f6
·
1 Parent(s): 85f4341

InitialCopavision AI deployment

Browse files
.gitignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .ipynb_checkpoints/
5
+ .DS_Store
6
+ .env
app.py ADDED
@@ -0,0 +1,1352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ╔══════════════════════════════════════════════════════════════════════════════╗
3
+ ║ CopaVision AI | Match Outcome Predictor | Phase 1 ║
4
+ ║ Streamlit Dashboard — Production Ready ║
5
+ ╚══════════════════════════════════════════════════════════════════════════════╝
6
+
7
+ Run:
8
+ streamlit run app.py
9
+
10
+ Dependencies:
11
+ pip install streamlit pandas numpy scikit-learn plotly joblib
12
+
13
+ File structure expected:
14
+ app.py ← this file
15
+ models/
16
+ copavision_rf.pkl
17
+ copavision_lr.pkl
18
+ team_stats.json ← pre-computed Elo + form stats per team
19
+ """
20
+
21
+ # ─────────────────────────────────────────────────────────────────────────────
22
+ # IMPORTS
23
+ # ─────────────────────────────────────────────────────────────────────────────
24
+ import json
25
+ import time
26
+ from pathlib import Path
27
+
28
+ import joblib
29
+ import numpy as np
30
+ import pandas as pd
31
+ import plotly.graph_objects as go
32
+ import plotly.express as px
33
+ import streamlit as st
34
+
35
+ # ─────────────────────────────────────────────────────────────────────────────
36
+ # PAGE CONFIG — must be first Streamlit call
37
+ # ─────────────────────────────────────────────────────────────────────────────
38
+ st.set_page_config(
39
+ page_title="CopaVision AI",
40
+ page_icon="⚽",
41
+ layout="wide",
42
+ initial_sidebar_state="expanded",
43
+ )
44
+
45
+ # ─────────────────────────────────────────────────────────────────────────────
46
+ # CUSTOM CSS — dark football analytics theme
47
+ # ─────────────────────────────────────────────────────────────────────────────
48
+ CUSTOM_CSS = """
49
+ <style>
50
+ /* ── Google Fonts ── */
51
+ @import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@400;600;700;900&family=DM+Sans:wght@300;400;500;600&display=swap');
52
+
53
+ /* ── Global theme ── */
54
+ :root {
55
+ --bg-deep: #050b14;
56
+ --bg-card: #0e1621;
57
+ --bg-panel: #121d2e;
58
+ --border: #1e3050;
59
+ --accent: #00d4ff;
60
+ --accent2: #00ff9d;
61
+ --accent3: #ff6b35;
62
+ --gold: #ffd700;
63
+ --text: #e8f1ff;
64
+ --muted: #5a7a9a;
65
+ --win: #00ff9d;
66
+ --loss: #ff4560;
67
+ --draw: #00d4ff;
68
+ }
69
+
70
+ /* ── App background ── */
71
+ .stApp {
72
+ background-color: var(--bg-deep);
73
+ background-image:
74
+ radial-gradient(ellipse at 20% 0%, rgba(0,212,255,0.06) 0%, transparent 50%),
75
+ radial-gradient(ellipse at 80% 100%, rgba(0,255,157,0.04) 0%, transparent 50%);
76
+ font-family: 'DM Sans', sans-serif;
77
+ color: var(--text);
78
+ }
79
+
80
+ /* ── Hide default Streamlit chrome ── */
81
+ #MainMenu, footer, header {visibility: hidden;}
82
+ .block-container {padding-top: 1.5rem; padding-bottom: 2rem;}
83
+
84
+ /* ── Sidebar ── */
85
+ [data-testid="stSidebar"] {
86
+ background: var(--bg-panel) !important;
87
+ border-right: 1px solid var(--border) !important;
88
+ }
89
+ [data-testid="stSidebar"] * {color: var(--text) !important;}
90
+
91
+ /* ── Metric cards ── */
92
+ [data-testid="stMetric"] {
93
+ background: var(--bg-card);
94
+ border: 1px solid var(--border);
95
+ border-radius: 12px;
96
+ padding: 16px 20px !important;
97
+ transition: border-color 0.2s;
98
+ }
99
+ [data-testid="stMetric"]:hover {border-color: var(--accent);}
100
+ [data-testid="stMetricValue"] {
101
+ font-family: 'Barlow Condensed', sans-serif !important;
102
+ font-size: 2rem !important;
103
+ font-weight: 700 !important;
104
+ color: var(--accent) !important;
105
+ }
106
+ [data-testid="stMetricLabel"] {color: var(--muted) !important; font-size: 0.75rem !important;}
107
+ [data-testid="stMetricDelta"] {font-size: 0.8rem !important;}
108
+
109
+ /* ── Selectbox & inputs ── */
110
+ [data-testid="stSelectbox"] > div > div {
111
+ background: var(--bg-card) !important;
112
+ border: 1px solid var(--border) !important;
113
+ border-radius: 8px !important;
114
+ color: var(--text) !important;
115
+ }
116
+ [data-testid="stSelectbox"] > div > div:focus-within {border-color: var(--accent) !important;}
117
+
118
+ /* ── Buttons ── */
119
+ .stButton > button {
120
+ background: linear-gradient(135deg, #00d4ff 0%, #0099cc 100%);
121
+ color: #050b14 !important;
122
+ border: none !important;
123
+ border-radius: 8px !important;
124
+ font-family: 'Barlow Condensed', sans-serif !important;
125
+ font-size: 1.1rem !important;
126
+ font-weight: 700 !important;
127
+ letter-spacing: 1px !important;
128
+ padding: 0.6rem 2rem !important;
129
+ transition: all 0.2s !important;
130
+ text-transform: uppercase !important;
131
+ }
132
+ .stButton > button:hover {
133
+ transform: translateY(-2px) !important;
134
+ box-shadow: 0 6px 24px rgba(0,212,255,0.3) !important;
135
+ }
136
+ .stButton > button:active {transform: translateY(0px) !important;}
137
+
138
+ /* ── Tabs ── */
139
+ [data-testid="stTab"] {
140
+ font-family: 'Barlow Condensed', sans-serif !important;
141
+ font-size: 1rem !important;
142
+ letter-spacing: 0.5px;
143
+ color: var(--muted) !important;
144
+ }
145
+ [data-testid="stTab"][aria-selected="true"] {
146
+ color: var(--accent) !important;
147
+ border-bottom-color: var(--accent) !important;
148
+ }
149
+
150
+ /* ── Dividers ── */
151
+ hr {border-color: var(--border) !important; margin: 1.2rem 0 !important;}
152
+
153
+ /* ── Info/warning boxes ── */
154
+ .stAlert {background: var(--bg-card) !important; border-radius: 10px !important;}
155
+
156
+ /* ── Custom card class (used via markdown/html) ── */
157
+ .cv-card {
158
+ background: var(--bg-card);
159
+ border: 1px solid var(--border);
160
+ border-radius: 14px;
161
+ padding: 1.4rem 1.6rem;
162
+ margin-bottom: 1rem;
163
+ }
164
+ .cv-card-accent {border-left: 3px solid var(--accent);}
165
+ .cv-card-win {border-left: 3px solid var(--win);}
166
+ .cv-card-draw {border-left: 3px solid var(--draw);}
167
+ .cv-card-loss {border-left: 3px solid var(--loss);}
168
+
169
+ /* ── Section headings ── */
170
+ .cv-heading {
171
+ font-family: 'Barlow Condensed', sans-serif;
172
+ font-size: 1.6rem;
173
+ font-weight: 700;
174
+ letter-spacing: 1px;
175
+ color: var(--text);
176
+ text-transform: uppercase;
177
+ margin-bottom: 0.4rem;
178
+ }
179
+ .cv-subheading {
180
+ font-family: 'Barlow Condensed', sans-serif;
181
+ font-size: 1.05rem;
182
+ color: var(--muted);
183
+ letter-spacing: 0.5px;
184
+ margin-bottom: 1.2rem;
185
+ }
186
+
187
+ /* ── Result badge ── */
188
+ .result-badge {
189
+ display: inline-block;
190
+ font-family: 'Barlow Condensed', sans-serif;
191
+ font-size: 1.8rem;
192
+ font-weight: 900;
193
+ letter-spacing: 2px;
194
+ text-transform: uppercase;
195
+ padding: 10px 28px;
196
+ border-radius: 8px;
197
+ margin: 0.5rem 0;
198
+ }
199
+ .badge-home {background: rgba(0,255,157,0.15); color: #00ff9d; border: 1px solid #00ff9d;}
200
+ .badge-away {background: rgba(255,107,53,0.15); color: #ff6b35; border: 1px solid #ff6b35;}
201
+ .badge-draw {background: rgba(0,212,255,0.15); color: #00d4ff; border: 1px solid #00d4ff;}
202
+
203
+ /* ── Spinner override ── */
204
+ .stSpinner > div {border-top-color: var(--accent) !important;}
205
+
206
+ /* ── Expanders ── */
207
+ [data-testid="stExpander"] {
208
+ background: var(--bg-card) !important;
209
+ border: 1px solid var(--border) !important;
210
+ border-radius: 10px !important;
211
+ }
212
+ [data-testid="stExpanderToggleIcon"] {color: var(--accent) !important;}
213
+ </style>
214
+ """
215
+ st.markdown(CUSTOM_CSS, unsafe_allow_html=True)
216
+
217
+
218
+ # ─────────────────────────────────────────────────────────────────────────────
219
+ # CONSTANTS & CONFIG
220
+ # ─────────────────────────────────────────────────────────────────────────────
221
+ FEATURE_COLS = [
222
+ "home_recent_points", "away_recent_points",
223
+ "home_avg_goals_scored", "away_avg_goals_scored",
224
+ "home_avg_goals_conceded", "away_avg_goals_conceded",
225
+ "home_rolling_gd", "away_rolling_gd",
226
+ "elo_diff", "home_elo", "away_elo",
227
+ "neutral_venue", "tournament_importance",
228
+ ]
229
+
230
+ TOURNAMENT_IMPORTANCE_MAP = {
231
+ "FIFA World Cup": 5,
232
+ "UEFA Euro (EURO)": 5,
233
+ "Copa America": 5,
234
+ "AFC Asian Cup": 4,
235
+ "African Cup of Nations": 4,
236
+ "Gold Cup (CONCACAF)": 4,
237
+ "FIFA World Cup Qualification": 3,
238
+ "UEFA Euro Qualification": 3,
239
+ "UEFA Nations League": 3,
240
+ "CONMEBOL Qualifying": 3,
241
+ "CAF Qualification": 2,
242
+ "Regional Tournament": 2,
243
+ "International Friendly": 1,
244
+ }
245
+
246
+ # Plotly dark theme base
247
+ PLOTLY_TEMPLATE = "plotly_dark"
248
+ COLORS = {
249
+ "home": "#00ff9d",
250
+ "away": "#ff6b35",
251
+ "draw": "#00d4ff",
252
+ "bg": "#0e1621",
253
+ "panel": "#121d2e",
254
+ "border":"#1e3050",
255
+ "muted": "#5a7a9a",
256
+ "text": "#e8f1ff",
257
+ }
258
+
259
+
260
+ # ─────────────────────��───────────────────────────────────────────────────────
261
+ # DATA & MODEL LOADING
262
+ # ─────────────────────────────────────────────────────────────────────────────
263
+ BASE_DIR = Path(__file__).parent
264
+
265
+ @st.cache_resource(show_spinner=False)
266
+ def load_models():
267
+ """Load trained ML models. Cached so they only load once per session."""
268
+ models = {}
269
+ model_dir = BASE_DIR / "models"
270
+ for name, fname in [("Random Forest", "copavision_rf.pkl"),
271
+ ("Logistic Regression", "copavision_lr.pkl")]:
272
+ path = model_dir / fname
273
+ if path.exists():
274
+ models[name] = joblib.load(path)
275
+ else:
276
+ st.error(f"Model not found: {path}")
277
+ return models
278
+
279
+
280
+ @st.cache_data(show_spinner=False)
281
+ def load_team_stats() -> dict:
282
+ """Load pre-computed Elo + form stats per team."""
283
+ path = BASE_DIR / "team_stats.json"
284
+ if not path.exists():
285
+ st.error("team_stats.json not found. Run the Phase 1 pipeline first.")
286
+ return {}
287
+ with open(path) as f:
288
+ return json.load(f)
289
+
290
+
291
+ # ─────────────────────────────────────────────────────────────────────────────
292
+ # FEATURE GENERATION
293
+ # ─────────────────────────────────────────────────────────────────────────────
294
+ def get_team_features(team: str, stats: dict) -> dict:
295
+ """Return a team's feature dict, with safe defaults for unknown teams."""
296
+ if team in stats:
297
+ s = stats[team]
298
+ return {
299
+ "elo": s["elo"],
300
+ "recent_points": s["recent_points"],
301
+ "avg_scored": s["avg_scored"],
302
+ "avg_conceded": s["avg_conceded"],
303
+ "rolling_gd": s["rolling_gd"],
304
+ "matches_played": s.get("matches_played", 0),
305
+ }
306
+ # Fallback for teams with no history
307
+ return {
308
+ "elo": 1500.0, "recent_points": 1.0,
309
+ "avg_scored": 1.0, "avg_conceded": 1.0,
310
+ "rolling_gd": 0.0, "matches_played": 0,
311
+ }
312
+
313
+
314
+ def build_feature_vector(home_team: str, away_team: str,
315
+ neutral: bool, tournament: str,
316
+ stats: dict) -> np.ndarray:
317
+ """
318
+ Construct the 13-feature vector that matches the training pipeline exactly.
319
+ Feature order MUST match FEATURE_COLS — any reordering breaks the model.
320
+ """
321
+ h = get_team_features(home_team, stats)
322
+ a = get_team_features(away_team, stats)
323
+ imp = TOURNAMENT_IMPORTANCE_MAP.get(tournament, 2)
324
+
325
+ vector = [
326
+ h["recent_points"], # home_recent_points
327
+ a["recent_points"], # away_recent_points
328
+ h["avg_scored"], # home_avg_goals_scored
329
+ a["avg_scored"], # away_avg_goals_scored
330
+ h["avg_conceded"], # home_avg_goals_conceded
331
+ a["avg_conceded"], # away_avg_goals_conceded
332
+ h["rolling_gd"], # home_rolling_gd
333
+ a["rolling_gd"], # away_rolling_gd
334
+ h["elo"] - a["elo"], # elo_diff
335
+ h["elo"], # home_elo
336
+ a["elo"], # away_elo
337
+ int(neutral), # neutral_venue
338
+ imp, # tournament_importance
339
+ ]
340
+ return np.array(vector, dtype=float).reshape(1, -1)
341
+
342
+
343
+ # ─────────────────────────────────────────────────────────────────────────────
344
+ # PLOTLY CHART HELPERS
345
+ # ─────────────────────────────────────────────────────────────────────────────
346
+ def make_probability_donut(home_prob: float, draw_prob: float,
347
+ away_prob: float, home_team: str,
348
+ away_team: str) -> go.Figure:
349
+ """Donut chart showing Home / Draw / Away probability breakdown."""
350
+ fig = go.Figure(go.Pie(
351
+ labels=[f"{home_team} Win", "Draw", f"{away_team} Win"],
352
+ values=[home_prob, draw_prob, away_prob],
353
+ hole=0.62,
354
+ marker_colors=[COLORS["home"], COLORS["draw"], COLORS["away"]],
355
+ textinfo="label+percent",
356
+ textfont=dict(family="Barlow Condensed", size=14, color=COLORS["text"]),
357
+ hovertemplate="<b>%{label}</b><br>Probability: %{percent}<extra></extra>",
358
+ direction="clockwise",
359
+ sort=False,
360
+ ))
361
+ fig.update_layout(
362
+ template=PLOTLY_TEMPLATE,
363
+ paper_bgcolor="rgba(0,0,0,0)",
364
+ plot_bgcolor="rgba(0,0,0,0)",
365
+ margin=dict(t=20, b=20, l=20, r=20),
366
+ height=300,
367
+ showlegend=False,
368
+ annotations=[dict(
369
+ text=f"<b>{max(home_prob, draw_prob, away_prob)*100:.0f}%</b>",
370
+ x=0.5, y=0.5, font=dict(size=30, family="Barlow Condensed",
371
+ color=COLORS["text"]),
372
+ showarrow=False,
373
+ )],
374
+ )
375
+ return fig
376
+
377
+
378
+ def make_probability_bars(home_prob: float, draw_prob: float,
379
+ away_prob: float, home_team: str,
380
+ away_team: str) -> go.Figure:
381
+ """Horizontal probability bar chart."""
382
+ labels = [f"{home_team} Win", "Draw", f"{away_team} Win"]
383
+ values = [home_prob * 100, draw_prob * 100, away_prob * 100]
384
+ bar_colors = [COLORS["home"], COLORS["draw"], COLORS["away"]]
385
+
386
+ fig = go.Figure(go.Bar(
387
+ x=values,
388
+ y=labels,
389
+ orientation="h",
390
+ marker=dict(
391
+ color=bar_colors,
392
+ line=dict(color="rgba(0,0,0,0)", width=0),
393
+ ),
394
+ text=[f"{v:.1f}%" for v in values],
395
+ textposition="outside",
396
+ textfont=dict(family="Barlow Condensed", size=16, color=COLORS["text"]),
397
+ hovertemplate="<b>%{y}</b><br>%{x:.1f}%<extra></extra>",
398
+ ))
399
+ fig.update_layout(
400
+ template=PLOTLY_TEMPLATE,
401
+ paper_bgcolor="rgba(0,0,0,0)",
402
+ plot_bgcolor="rgba(0,0,0,0)",
403
+ xaxis=dict(range=[0, 105], showgrid=False, visible=False),
404
+ yaxis=dict(showgrid=False, tickfont=dict(family="Barlow Condensed",
405
+ size=14, color=COLORS["text"])),
406
+ margin=dict(t=10, b=10, l=10, r=70),
407
+ height=200,
408
+ bargap=0.35,
409
+ )
410
+ return fig
411
+
412
+
413
+ def make_team_radar(h_feats: dict, a_feats: dict,
414
+ home_team: str, away_team: str) -> go.Figure:
415
+ """Radar chart comparing two teams across key metrics (normalised 0–1)."""
416
+ categories = ["Elo Rating", "Recent Form", "Attack", "Defence\n(inverted)", "Goal Diff"]
417
+
418
+ def norm(val, lo, hi):
419
+ return max(0.0, min(1.0, (val - lo) / (hi - lo + 1e-9)))
420
+
421
+ h_vals = [
422
+ norm(h_feats["elo"], 1200, 2200),
423
+ norm(h_feats["recent_points"], 0, 3),
424
+ norm(h_feats["avg_scored"], 0, 4),
425
+ norm(1 / (h_feats["avg_conceded"] + 0.5), 0, 2), # lower conceded → better
426
+ norm(h_feats["rolling_gd"], -3, 3),
427
+ ]
428
+ a_vals = [
429
+ norm(a_feats["elo"], 1200, 2200),
430
+ norm(a_feats["recent_points"], 0, 3),
431
+ norm(a_feats["avg_scored"], 0, 4),
432
+ norm(1 / (a_feats["avg_conceded"] + 0.5), 0, 2),
433
+ norm(a_feats["rolling_gd"], -3, 3),
434
+ ]
435
+
436
+ fig = go.Figure()
437
+ for name, vals, color in [
438
+ (home_team, h_vals, COLORS["home"]),
439
+ (away_team, a_vals, COLORS["away"]),
440
+ ]:
441
+ fig.add_trace(go.Scatterpolar(
442
+ r=vals + [vals[0]],
443
+ theta=categories + [categories[0]],
444
+ fill="toself",
445
+ fillcolor=color.replace(")", ", 0.15)").replace("rgb", "rgba") if color.startswith("rgb") else "rgba(0,255,157,0.15)" if color == COLORS["home"] else "rgba(255,107,53,0.15)",
446
+ line=dict(color=color, width=2),
447
+ name=name,
448
+ hovertemplate=f"<b>{name}</b><br>%{{theta}}: %{{r:.2f}}<extra></extra>",
449
+ ))
450
+
451
+ fig.update_layout(
452
+ template=PLOTLY_TEMPLATE,
453
+ paper_bgcolor="rgba(0,0,0,0)",
454
+ plot_bgcolor="rgba(0,0,0,0)",
455
+ polar=dict(
456
+ bgcolor="rgba(14,22,33,0.6)",
457
+ radialaxis=dict(visible=True, range=[0, 1],
458
+ showticklabels=False, gridcolor=COLORS["border"]),
459
+ angularaxis=dict(
460
+ tickfont=dict(family="Barlow Condensed", size=12, color=COLORS["text"]),
461
+ gridcolor=COLORS["border"],
462
+ ),
463
+ ),
464
+ legend=dict(
465
+ font=dict(family="Barlow Condensed", color=COLORS["text"], size=13),
466
+ bgcolor="rgba(0,0,0,0)",
467
+ ),
468
+ height=380,
469
+ margin=dict(t=30, b=30, l=30, r=30),
470
+ )
471
+ return fig
472
+
473
+
474
+ def make_feature_importance_chart(model) -> go.Figure:
475
+ """Horizontal bar chart for RF feature importances."""
476
+ if not hasattr(model, "feature_importances_"):
477
+ return None
478
+
479
+ importances = model.feature_importances_
480
+ idx = np.argsort(importances)
481
+ labels = [FEATURE_COLS[i].replace("_", " ").title() for i in idx]
482
+ vals = importances[idx]
483
+
484
+ # Colour by feature group
485
+ palette = []
486
+ for i in idx:
487
+ col = FEATURE_COLS[i]
488
+ if "elo" in col: palette.append(COLORS["draw"])
489
+ elif "points" in col: palette.append(COLORS["home"])
490
+ elif "goal" in col or "gd" in col: palette.append("#d2a8ff")
491
+ else: palette.append(COLORS["muted"])
492
+
493
+ fig = go.Figure(go.Bar(
494
+ x=vals,
495
+ y=labels,
496
+ orientation="h",
497
+ marker=dict(color=palette),
498
+ text=[f"{v:.3f}" for v in vals],
499
+ textposition="outside",
500
+ textfont=dict(size=11, color=COLORS["text"], family="DM Sans"),
501
+ hovertemplate="<b>%{y}</b><br>Importance: %{x:.4f}<extra></extra>",
502
+ ))
503
+ fig.update_layout(
504
+ template=PLOTLY_TEMPLATE,
505
+ paper_bgcolor="rgba(0,0,0,0)",
506
+ plot_bgcolor="rgba(0,0,0,0)",
507
+ xaxis=dict(showgrid=False, visible=False, range=[0, vals.max() * 1.2]),
508
+ yaxis=dict(tickfont=dict(family="DM Sans", size=11, color=COLORS["text"])),
509
+ margin=dict(t=10, b=10, l=10, r=70),
510
+ height=420,
511
+ )
512
+ return fig
513
+
514
+
515
+ def make_elo_gauge(elo: float, team: str, color: str) -> go.Figure:
516
+ """Gauge chart displaying Elo rating."""
517
+ fig = go.Figure(go.Indicator(
518
+ mode="gauge+number",
519
+ value=elo,
520
+ number=dict(font=dict(family="Barlow Condensed", size=36, color=COLORS["text"])),
521
+ gauge=dict(
522
+ axis=dict(range=[1000, 2300], tickwidth=1,
523
+ tickcolor=COLORS["muted"],
524
+ tickfont=dict(color=COLORS["muted"], size=10)),
525
+ bar=dict(color=color, thickness=0.3),
526
+ bgcolor=COLORS["bg"],
527
+ borderwidth=0,
528
+ steps=[
529
+ dict(range=[1000, 1400], color="rgba(90,122,154,0.1)"),
530
+ dict(range=[1400, 1700], color="rgba(90,122,154,0.15)"),
531
+ dict(range=[1700, 2300], color="rgba(90,122,154,0.2)"),
532
+ ],
533
+ threshold=dict(line=dict(color=color, width=3), thickness=0.7, value=elo),
534
+ ),
535
+ title=dict(text=team, font=dict(family="Barlow Condensed",
536
+ size=16, color=COLORS["muted"])),
537
+ domain=dict(x=[0, 1], y=[0, 1]),
538
+ ))
539
+ fig.update_layout(
540
+ paper_bgcolor="rgba(0,0,0,0)",
541
+ height=220,
542
+ margin=dict(t=40, b=10, l=30, r=30),
543
+ )
544
+ return fig
545
+
546
+
547
+ # ─────────────────────────────────────────────────────────────────────────────
548
+ # RESULT FORMATTING HELPERS
549
+ # ─────────────────────────────────────────────────────────────────────────────
550
+ def get_result_badge(prediction: int, home_team: str, away_team: str) -> str:
551
+ if prediction == 0:
552
+ return f'<span class="result-badge badge-home">⚽ {home_team} Win</span>'
553
+ elif prediction == 1:
554
+ return f'<span class="result-badge badge-away">⚽ {away_team} Win</span>'
555
+ else:
556
+ return f'<span class="result-badge badge-draw">🤝 Draw</span>'
557
+
558
+
559
+ def confidence_label(prob: float) -> str:
560
+ if prob >= 0.70: return "🔥 High Confidence"
561
+ if prob >= 0.50: return "📊 Moderate Confidence"
562
+ if prob >= 0.35: return "⚖️ Low Confidence"
563
+ return "🎲 Uncertain"
564
+
565
+
566
+ def form_bar(recent_points: float) -> str:
567
+ """Generate a simple emoji form representation."""
568
+ # recent_points is avg of last 5 games; 3=W, 1=D, 0=L
569
+ filled = int(round(recent_points / 3 * 5))
570
+ return "🟢" * filled + "⚫" * (5 - filled)
571
+
572
+
573
+ # ─────────────────────────────────────────────────────────────────────────────
574
+ # SIDEBAR
575
+ # ─────────────────────────────────────────────────────────────────────────────
576
+ def render_sidebar(team_stats: dict, models: dict):
577
+ with st.sidebar:
578
+ # Logo / brand
579
+ st.markdown("""
580
+ <div style="text-align:center; padding: 1rem 0 1.5rem;">
581
+ <div style="font-family:'Barlow Condensed',sans-serif;
582
+ font-size:2rem; font-weight:900; color:#00d4ff;
583
+ letter-spacing:3px;">COPA<span style="color:#00ff9d;">VISION</span></div>
584
+ <div style="font-family:'Barlow Condensed',sans-serif;
585
+ font-size:0.85rem; color:#5a7a9a; letter-spacing:4px;">
586
+ A I · P H A S E 1</div>
587
+ </div>
588
+ <hr style="border-color:#1e3050; margin:0 0 1.5rem;">
589
+ """, unsafe_allow_html=True)
590
+
591
+ # Navigation
592
+ st.markdown('<p style="font-family:\'Barlow Condensed\',sans-serif; '
593
+ 'font-size:0.7rem; color:#5a7a9a; letter-spacing:3px; '
594
+ 'text-transform:uppercase; margin-bottom:0.5rem;">NAVIGATION</p>',
595
+ unsafe_allow_html=True)
596
+
597
+ page = st.radio(
598
+ label="page",
599
+ options=["⚽ Match Predictor", "📊 Team Explorer",
600
+ "🧠 Model Insights", "ℹ️ About"],
601
+ label_visibility="collapsed",
602
+ )
603
+
604
+ st.markdown("<hr>", unsafe_allow_html=True)
605
+
606
+ # Model selector
607
+ st.markdown('<p style="font-family:\'Barlow Condensed\',sans-serif; '
608
+ 'font-size:0.7rem; color:#5a7a9a; letter-spacing:3px; '
609
+ 'text-transform:uppercase; margin-bottom:0.5rem;">ML MODEL</p>',
610
+ unsafe_allow_html=True)
611
+ model_choice = st.selectbox(
612
+ "Select Model",
613
+ options=list(models.keys()),
614
+ label_visibility="collapsed",
615
+ )
616
+
617
+ st.markdown("<hr>", unsafe_allow_html=True)
618
+
619
+ # Stats strip
620
+ st.markdown(f"""
621
+ <div style="text-align:center;">
622
+ <p style="font-family:'Barlow Condensed',sans-serif; font-size:0.7rem;
623
+ color:#5a7a9a; letter-spacing:3px; text-transform:uppercase; margin-bottom:0.8rem;">
624
+ DATABASE</p>
625
+ <div style="display:flex; justify-content:space-around;">
626
+ <div>
627
+ <div style="font-family:'Barlow Condensed',sans-serif;
628
+ font-size:1.6rem; font-weight:700; color:#00d4ff;">
629
+ {len(team_stats)}</div>
630
+ <div style="font-size:0.7rem; color:#5a7a9a;">Teams</div>
631
+ </div>
632
+ <div>
633
+ <div style="font-family:'Barlow Condensed',sans-serif;
634
+ font-size:1.6rem; font-weight:700; color:#00ff9d;">
635
+ 19k+</div>
636
+ <div style="font-size:0.7rem; color:#5a7a9a;">Matches</div>
637
+ </div>
638
+ <div>
639
+ <div style="font-family:'Barlow Condensed',sans-serif;
640
+ font-size:1.6rem; font-weight:700; color:#d2a8ff;">
641
+ 2020</div>
642
+ <div style="font-size:0.7rem; color:#5a7a9a;">Latest</div>
643
+ </div>
644
+ </div>
645
+ </div>
646
+ """, unsafe_allow_html=True)
647
+
648
+ st.markdown("<hr>", unsafe_allow_html=True)
649
+
650
+ # Phase roadmap
651
+ st.markdown("""
652
+ <p style="font-family:'Barlow Condensed',sans-serif; font-size:0.7rem;
653
+ color:#5a7a9a; letter-spacing:3px; text-transform:uppercase; margin-bottom:0.8rem;">
654
+ ROADMAP</p>
655
+ <div style="font-size:0.82rem; line-height:2;">
656
+ <span style="color:#00ff9d;">✓</span> Phase 1 · Match Predictor<br>
657
+ <span style="color:#5a7a9a;">○</span> Phase 2 · Player Dashboard<br>
658
+ <span style="color:#5a7a9a;">○</span> Phase 3 · Sentiment Tracker<br>
659
+ <span style="color:#5a7a9a;">○</span> Phase 4 · Live Match Feed
660
+ </div>
661
+ """, unsafe_allow_html=True)
662
+
663
+ return page, model_choice
664
+
665
+
666
+ # ─────────────────────────────────────────────────────────────────────────────
667
+ # PAGE 1 — MATCH PREDICTOR
668
+ # ─────────────────────────────────────────────────────────────────────────────
669
+ def page_match_predictor(models: dict, team_stats: dict, model_choice: str):
670
+ # ── Header ────────────────────────────────────────────────────────────────
671
+ st.markdown("""
672
+ <div class="cv-heading">⚽ Match Outcome Predictor</div>
673
+ <div class="cv-subheading">
674
+ Select two international teams and get AI-powered match predictions powered by Elo ratings and ML
675
+ </div>
676
+ """, unsafe_allow_html=True)
677
+
678
+ st.markdown('<hr style="border-color:#1e3050;">', unsafe_allow_html=True)
679
+
680
+ # ── Input Section ─────────────────────────────────────────────────────────
681
+ all_teams = sorted(team_stats.keys())
682
+ popular = ["Brazil", "Argentina", "France", "Germany", "Spain",
683
+ "England", "Portugal", "Italy", "Netherlands", "Belgium",
684
+ "Croatia", "Uruguay", "Mexico", "USA", "Japan",
685
+ "South Korea", "Senegal", "Morocco", "Australia", "Poland"]
686
+ # Put popular teams first in the dropdown
687
+ ordered_teams = [t for t in popular if t in all_teams] + \
688
+ [t for t in all_teams if t not in popular]
689
+
690
+ col_l, col_mid, col_r = st.columns([5, 1, 5])
691
+
692
+ with col_l:
693
+ st.markdown('<p style="font-family:\'Barlow Condensed\',sans-serif; '
694
+ 'font-size:0.75rem; color:#5a7a9a; letter-spacing:2px; '
695
+ 'text-transform:uppercase;">HOME TEAM</p>', unsafe_allow_html=True)
696
+ home_team = st.selectbox("Home Team", ordered_teams,
697
+ index=ordered_teams.index("Brazil"),
698
+ label_visibility="collapsed", key="home")
699
+
700
+ with col_mid:
701
+ st.markdown("<br><br>", unsafe_allow_html=True)
702
+ st.markdown('<div style="text-align:center; font-family:\'Barlow Condensed\','
703
+ 'sans-serif; font-size:1.8rem; color:#5a7a9a; padding-top:0.3rem;">VS</div>',
704
+ unsafe_allow_html=True)
705
+
706
+ with col_r:
707
+ st.markdown('<p style="font-family:\'Barlow Condensed\',sans-serif; '
708
+ 'font-size:0.75rem; color:#5a7a9a; letter-spacing:2px; '
709
+ 'text-transform:uppercase;">AWAY TEAM</p>', unsafe_allow_html=True)
710
+ away_default = ordered_teams.index("Argentina") if "Argentina" in ordered_teams else 1
711
+ away_team = st.selectbox("Away Team", ordered_teams,
712
+ index=away_default,
713
+ label_visibility="collapsed", key="away")
714
+
715
+ # Same-team guard
716
+ if home_team == away_team:
717
+ st.warning("⚠️ Home and Away teams must be different. Please select two distinct teams.")
718
+ return
719
+
720
+ # Tournament & venue row
721
+ col_t, col_n = st.columns([3, 1])
722
+ with col_t:
723
+ st.markdown('<p style="font-family:\'Barlow Condensed\',sans-serif; '
724
+ 'font-size:0.75rem; color:#5a7a9a; letter-spacing:2px; '
725
+ 'text-transform:uppercase; margin-top:0.6rem;">TOURNAMENT</p>',
726
+ unsafe_allow_html=True)
727
+ tournament = st.selectbox(
728
+ "Tournament",
729
+ list(TOURNAMENT_IMPORTANCE_MAP.keys()),
730
+ index=0,
731
+ label_visibility="collapsed",
732
+ )
733
+ with col_n:
734
+ st.markdown('<p style="font-family:\'Barlow Condensed\',sans-serif; '
735
+ 'font-size:0.75rem; color:#5a7a9a; letter-spacing:2px; '
736
+ 'text-transform:uppercase; margin-top:0.6rem;">NEUTRAL VENUE</p>',
737
+ unsafe_allow_html=True)
738
+ neutral = st.toggle("Neutral Ground", value=False)
739
+
740
+ st.markdown("<br>", unsafe_allow_html=True)
741
+
742
+ # ── Predict Button ─────────────────────────────────────────────────────────
743
+ col_btn, _ = st.columns([2, 5])
744
+ with col_btn:
745
+ predict_clicked = st.button("🔮 Generate Prediction", use_container_width=True)
746
+
747
+ st.markdown('<hr style="border-color:#1e3050;">', unsafe_allow_html=True)
748
+
749
+ # ── Prediction Output ─────────────────────────────────────────────────────
750
+ if predict_clicked:
751
+ model = models[model_choice]
752
+ h_feats = get_team_features(home_team, team_stats)
753
+ a_feats = get_team_features(away_team, team_stats)
754
+
755
+ with st.spinner("⚙️ Running prediction engine…"):
756
+ time.sleep(0.6) # Small delay for UX polish
757
+ X = build_feature_vector(home_team, away_team, neutral, tournament, team_stats)
758
+ probs = model.predict_proba(X)[0]
759
+ prediction = int(np.argmax(probs))
760
+
761
+ home_prob, away_prob, draw_prob = probs[0], probs[1], probs[2]
762
+ max_prob = max(home_prob, draw_prob, away_prob)
763
+
764
+ # ── Result headline ────────────────────────────────────────────────────
765
+ badge = get_result_badge(prediction, home_team, away_team)
766
+ conf = confidence_label(max_prob)
767
+ venue_label = "🌐 Neutral Ground" if neutral else "🏟️ Home Advantage"
768
+ imp = TOURNAMENT_IMPORTANCE_MAP.get(tournament, 2)
769
+
770
+ st.markdown(f"""
771
+ <div class="cv-card cv-card-accent" style="text-align:center; padding: 1.8rem 2rem;">
772
+ <div style="font-family:'Barlow Condensed',sans-serif; font-size:0.8rem;
773
+ color:#5a7a9a; letter-spacing:3px; text-transform:uppercase; margin-bottom:0.6rem;">
774
+ PREDICTED OUTCOME</div>
775
+ {badge}
776
+ <div style="margin-top:0.8rem; font-size:1.0rem; color:#e8f1ff;">
777
+ {conf} &nbsp;·&nbsp;
778
+ <span style="color:#00d4ff;">{max_prob*100:.1f}%</span> confidence
779
+ </div>
780
+ <div style="margin-top:0.4rem; font-size:0.82rem; color:#5a7a9a;">
781
+ {venue_label} &nbsp;·&nbsp; Tournament Weight: {'⭐' * imp}
782
+ </div>
783
+ </div>
784
+ """, unsafe_allow_html=True)
785
+
786
+ # ── Probability breakdown ──────────────────────────────────────────────
787
+ st.markdown("<br>", unsafe_allow_html=True)
788
+ tab_prob, tab_radar, tab_insights = st.tabs(
789
+ ["📊 Probabilities", "🕸️ Team Radar", "🔍 Match Insights"]
790
+ )
791
+
792
+ with tab_prob:
793
+ c1, c2 = st.columns([1, 1])
794
+ with c1:
795
+ st.plotly_chart(
796
+ make_probability_donut(home_prob, draw_prob, away_prob,
797
+ home_team, away_team),
798
+ use_container_width=True, config={"displayModeBar": False},
799
+ )
800
+ with c2:
801
+ st.markdown("<br>", unsafe_allow_html=True)
802
+ st.plotly_chart(
803
+ make_probability_bars(home_prob, draw_prob, away_prob,
804
+ home_team, away_team),
805
+ use_container_width=True, config={"displayModeBar": False},
806
+ )
807
+
808
+ # Metric cards row
809
+ m1, m2, m3 = st.columns(3)
810
+ m1.metric(f"⚽ {home_team} Win", f"{home_prob*100:.1f}%",
811
+ delta=f"{'+' if home_prob > 0.33 else ''}{(home_prob-0.33)*100:.1f}% vs base")
812
+ m2.metric("🤝 Draw", f"{draw_prob*100:.1f}%",
813
+ delta=f"{(draw_prob-0.33)*100:.1f}% vs base")
814
+ m3.metric(f"⚽ {away_team} Win", f"{away_prob*100:.1f}%",
815
+ delta=f"{'+' if away_prob > 0.33 else ''}{(away_prob-0.33)*100:.1f}% vs base")
816
+
817
+ with tab_radar:
818
+ st.plotly_chart(
819
+ make_team_radar(h_feats, a_feats, home_team, away_team),
820
+ use_container_width=True, config={"displayModeBar": False},
821
+ )
822
+ # Elo gauges
823
+ g1, g2 = st.columns(2)
824
+ with g1:
825
+ st.plotly_chart(make_elo_gauge(h_feats["elo"], home_team, COLORS["home"]),
826
+ use_container_width=True, config={"displayModeBar": False})
827
+ with g2:
828
+ st.plotly_chart(make_elo_gauge(a_feats["elo"], away_team, COLORS["away"]),
829
+ use_container_width=True, config={"displayModeBar": False})
830
+
831
+ with tab_insights:
832
+ _render_match_insights(home_team, away_team, h_feats, a_feats,
833
+ neutral, tournament, home_prob, away_prob, draw_prob)
834
+
835
+ else:
836
+ # Pre-prediction state: show team quick-stats if both selected
837
+ if home_team and away_team and home_team != away_team:
838
+ _render_team_preview(home_team, away_team, team_stats)
839
+
840
+
841
+ def _render_team_preview(home_team: str, away_team: str, team_stats: dict):
842
+ """Show a lightweight preview card for both teams before prediction."""
843
+ h = get_team_features(home_team, team_stats)
844
+ a = get_team_features(away_team, team_stats)
845
+
846
+ st.markdown('<div class="cv-subheading" style="margin-top:0.5rem;">'
847
+ 'Team Overview — click Generate Prediction to run the model</div>',
848
+ unsafe_allow_html=True)
849
+
850
+ c1, c2 = st.columns(2)
851
+ for col, team, feats, color in [
852
+ (c1, home_team, h, COLORS["home"]),
853
+ (c2, away_team, a, COLORS["away"]),
854
+ ]:
855
+ with col:
856
+ st.markdown(f"""
857
+ <div class="cv-card" style="border-left: 3px solid {color};">
858
+ <div style="font-family:'Barlow Condensed',sans-serif; font-size:1.3rem;
859
+ font-weight:700; color:{color}; letter-spacing:1px;">{team}</div>
860
+ <div style="font-size:0.8rem; color:#5a7a9a; margin-bottom:1rem;">
861
+ {feats['matches_played']} international matches on record</div>
862
+ <table style="width:100%; font-size:0.9rem; border-collapse:collapse;">
863
+ <tr><td style="color:#5a7a9a; padding:3px 0;">🏆 Elo Rating</td>
864
+ <td style="text-align:right; color:#e8f1ff; font-family:'Barlow Condensed',sans-serif;
865
+ font-weight:600;">{feats['elo']:.0f}</td></tr>
866
+ <tr><td style="color:#5a7a9a; padding:3px 0;">📈 Recent Form (avg pts)</td>
867
+ <td style="text-align:right; color:#e8f1ff;">{feats['recent_points']:.2f} / 3.00</td></tr>
868
+ <tr><td style="color:#5a7a9a; padding:3px 0;">⚽ Avg Goals Scored</td>
869
+ <td style="text-align:right; color:#00ff9d;">{feats['avg_scored']:.2f}</td></tr>
870
+ <tr><td style="color:#5a7a9a; padding:3px 0;">🛡️ Avg Goals Conceded</td>
871
+ <td style="text-align:right; color:#ff6b35;">{feats['avg_conceded']:.2f}</td></tr>
872
+ <tr><td style="color:#5a7a9a; padding:3px 0;">📊 Rolling Goal Diff</td>
873
+ <td style="text-align:right; color:#00d4ff;">{feats['rolling_gd']:+.2f}</td></tr>
874
+ <tr><td style="color:#5a7a9a; padding:3px 0;">⚡ Form Strip (last 5)</td>
875
+ <td style="text-align:right;">{form_bar(feats['recent_points'])}</td></tr>
876
+ </table>
877
+ </div>
878
+ """, unsafe_allow_html=True)
879
+
880
+
881
+ def _render_match_insights(home_team, away_team, h, a,
882
+ neutral, tournament,
883
+ home_prob, away_prob, draw_prob):
884
+ """Qualitative narrative insights about the match-up."""
885
+ elo_diff = h["elo"] - a["elo"]
886
+ imp = TOURNAMENT_IMPORTANCE_MAP.get(tournament, 2)
887
+
888
+ # Strength insight
889
+ if abs(elo_diff) > 200:
890
+ strength = (f"{'**' + home_team + '**'} holds a commanding Elo advantage "
891
+ f"of **{abs(elo_diff):.0f}** points — a significant gap "
892
+ f"that historically translates to a win probability above 65%.")
893
+ elif abs(elo_diff) > 80:
894
+ stronger = home_team if elo_diff > 0 else away_team
895
+ strength = (f"**{stronger}** edges the Elo comparison by "
896
+ f"**{abs(elo_diff):.0f}** points — a moderate advantage "
897
+ f"that typically gives them a 10–15% edge.")
898
+ else:
899
+ strength = (f"The teams are **evenly matched** on Elo "
900
+ f"(difference: {abs(elo_diff):.0f} pts). This fixture is a genuine "
901
+ f"coin-toss — expect a competitive, tight contest.")
902
+
903
+ # Form insight
904
+ form_diff = h["recent_points"] - a["recent_points"]
905
+ if abs(form_diff) > 0.8:
906
+ hotter = home_team if form_diff > 0 else away_team
907
+ form_msg = f"**{hotter}** is in significantly better recent form."
908
+ elif abs(form_diff) > 0.3:
909
+ hotter = home_team if form_diff > 0 else away_team
910
+ form_msg = f"**{hotter}** has a slight recent form edge."
911
+ else:
912
+ form_msg = "Both teams are in comparable recent form."
913
+
914
+ # Venue insight
915
+ venue_msg = ("On a **neutral ground**, home advantage is eliminated — "
916
+ "this levels the playing field slightly for the away side."
917
+ if neutral else
918
+ f"**{home_team}** benefits from home advantage, "
919
+ f"historically worth ~0.5 goals and a 5–8% boost in win probability.")
920
+
921
+ # Tournament context
922
+ imp_text = {1: "low-stakes friendly", 2: "regional tournament",
923
+ 3: "competitive qualifier", 4: "major continental cup",
924
+ 5: "elite world-stage competition"}
925
+ tourn_msg = (f"This is a **{imp_text.get(imp, 'competitive')}** "
926
+ f"(importance tier {imp}/5). Higher-stakes matches "
927
+ f"tend to be more conservative — draw probability often "
928
+ f"rises slightly as teams protect leads.")
929
+
930
+ # Uncertainty
931
+ entropy = -sum(p * np.log(p + 1e-9) for p in [home_prob, away_prob, draw_prob])
932
+ max_entropy = np.log(3)
933
+ uncertainty_pct = (entropy / max_entropy) * 100
934
+
935
+ st.markdown(f"""
936
+ <div class="cv-card cv-card-accent" style="margin-bottom:0.8rem;">
937
+ <div style="font-family:'Barlow Condensed',sans-serif; font-size:0.75rem;
938
+ color:#5a7a9a; letter-spacing:2px; text-transform:uppercase;
939
+ margin-bottom:0.6rem;">⚡ STRENGTH ANALYSIS</div>
940
+ <p style="color:#e8f1ff; font-size:0.92rem; line-height:1.6;">{strength}</p>
941
+ </div>
942
+ <div class="cv-card" style="margin-bottom:0.8rem;">
943
+ <div style="font-family:'Barlow Condensed',sans-serif; font-size:0.75rem;
944
+ color:#5a7a9a; letter-spacing:2px; text-transform:uppercase;
945
+ margin-bottom:0.6rem;">📈 RECENT FORM</div>
946
+ <p style="color:#e8f1ff; font-size:0.92rem; line-height:1.6;">{form_msg}</p>
947
+ </div>
948
+ <div class="cv-card" style="margin-bottom:0.8rem;">
949
+ <div style="font-family:'Barlow Condensed',sans-serif; font-size:0.75rem;
950
+ color:#5a7a9a; letter-spacing:2px; text-transform:uppercase;
951
+ margin-bottom:0.6rem;">🏟️ VENUE CONTEXT</div>
952
+ <p style="color:#e8f1ff; font-size:0.92rem; line-height:1.6;">{venue_msg}</p>
953
+ </div>
954
+ <div class="cv-card" style="margin-bottom:0.8rem;">
955
+ <div style="font-family:'Barlow Condensed',sans-serif; font-size:0.75rem;
956
+ color:#5a7a9a; letter-spacing:2px; text-transform:uppercase;
957
+ margin-bottom:0.6rem;">🏆 TOURNAMENT CONTEXT</div>
958
+ <p style="color:#e8f1ff; font-size:0.92rem; line-height:1.6;">{tourn_msg}</p>
959
+ </div>
960
+ <div class="cv-card" style="border-left: 3px solid #ffd700;">
961
+ <div style="font-family:'Barlow Condensed',sans-serif; font-size:0.75rem;
962
+ color:#5a7a9a; letter-spacing:2px; text-transform:uppercase;
963
+ margin-bottom:0.6rem;">🎲 MODEL UNCERTAINTY</div>
964
+ <p style="color:#e8f1ff; font-size:0.92rem; line-height:1.6;">
965
+ Prediction entropy is <b style="color:#ffd700;">{uncertainty_pct:.0f}%</b> of maximum uncertainty.
966
+ {('The model is confident in this prediction.' if uncertainty_pct < 50
967
+ else 'The model sees this as a genuinely open contest — treat probabilities as a guide, not a guarantee.')}
968
+ </p>
969
+ </div>
970
+ """, unsafe_allow_html=True)
971
+
972
+
973
+ # ─────────────────────────────────────────────────────────────────────────────
974
+ # PAGE 2 — TEAM EXPLORER
975
+ # ─────────────────────────────────────────────────────────────────────────────
976
+ def page_team_explorer(team_stats: dict):
977
+ st.markdown("""
978
+ <div class="cv-heading">📊 Team Explorer</div>
979
+ <div class="cv-subheading">Browse Elo ratings, form, and stats for all 298 international teams</div>
980
+ """, unsafe_allow_html=True)
981
+ st.markdown('<hr style="border-color:#1e3050;">', unsafe_allow_html=True)
982
+
983
+ # Build dataframe
984
+ rows = []
985
+ for team, s in team_stats.items():
986
+ rows.append({
987
+ "Team": team,
988
+ "Elo Rating": s["elo"],
989
+ "Recent Form (avg pts)": s["recent_points"],
990
+ "Goals Scored": s["avg_scored"],
991
+ "Goals Conceded": s["avg_conceded"],
992
+ "Goal Difference": s["rolling_gd"],
993
+ "Matches Played": s.get("matches_played", 0),
994
+ })
995
+ df = pd.DataFrame(rows).sort_values("Elo Rating", ascending=False).reset_index(drop=True)
996
+ df.index += 1 # 1-indexed ranking
997
+
998
+ # Top 15 Elo chart
999
+ top15 = df.head(15)
1000
+ fig_top = go.Figure(go.Bar(
1001
+ x=top15["Team"],
1002
+ y=top15["Elo Rating"],
1003
+ marker=dict(
1004
+ color=top15["Elo Rating"],
1005
+ colorscale=[[0, "#1e3050"], [0.5, "#00d4ff"], [1.0, "#00ff9d"]],
1006
+ showscale=False,
1007
+ ),
1008
+ text=top15["Elo Rating"].round(0).astype(int),
1009
+ textposition="outside",
1010
+ textfont=dict(family="Barlow Condensed", size=12, color=COLORS["text"]),
1011
+ hovertemplate="<b>%{x}</b><br>Elo: %{y:.0f}<extra></extra>",
1012
+ ))
1013
+ fig_top.update_layout(
1014
+ template=PLOTLY_TEMPLATE, paper_bgcolor="rgba(0,0,0,0)",
1015
+ plot_bgcolor="rgba(0,0,0,0)", height=380,
1016
+ xaxis=dict(tickfont=dict(family="Barlow Condensed", size=12, color=COLORS["text"]),
1017
+ gridcolor="rgba(0,0,0,0)"),
1018
+ yaxis=dict(range=[df["Elo Rating"].min() * 0.95, df["Elo Rating"].max() * 1.05],
1019
+ gridcolor=COLORS["border"],
1020
+ tickfont=dict(color=COLORS["muted"])),
1021
+ margin=dict(t=20, b=20, l=20, r=20),
1022
+ title=dict(text="Top 15 Teams by Elo Rating", font=dict(
1023
+ family="Barlow Condensed", size=16, color=COLORS["text"])),
1024
+ )
1025
+ st.plotly_chart(fig_top, use_container_width=True, config={"displayModeBar": False})
1026
+
1027
+ # Scatter: Elo vs Goals Scored
1028
+ with st.expander("🔍 Elo vs. Attack Strength (scatter)", expanded=False):
1029
+ fig_scatter = px.scatter(
1030
+ df, x="Elo Rating", y="Goals Scored",
1031
+ hover_name="Team",
1032
+ size="Matches Played", size_max=18,
1033
+ color="Goal Difference",
1034
+ color_continuous_scale=[[0,"#ff4560"],[0.5,"#5a7a9a"],[1,"#00ff9d"]],
1035
+ template=PLOTLY_TEMPLATE,
1036
+ labels={"Goals Scored": "Avg Goals Scored (last 5)", "Elo Rating": "Elo Rating"},
1037
+ )
1038
+ fig_scatter.update_layout(
1039
+ paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)",
1040
+ height=420, margin=dict(t=20, b=20),
1041
+ coloraxis_colorbar=dict(tickfont=dict(color=COLORS["muted"])),
1042
+ )
1043
+ st.plotly_chart(fig_scatter, use_container_width=True, config={"displayModeBar": False})
1044
+
1045
+ # Filterable table
1046
+ st.markdown("<br>", unsafe_allow_html=True)
1047
+ search = st.text_input("🔎 Search team", placeholder="e.g. Brazil, Germany, Japan…")
1048
+ filtered = df[df["Team"].str.contains(search, case=False)] if search else df
1049
+
1050
+ st.dataframe(
1051
+ filtered.style.background_gradient(
1052
+ subset=["Elo Rating"], cmap="Blues"
1053
+ ).format({
1054
+ "Elo Rating": "{:.0f}",
1055
+ "Recent Form (avg pts)": "{:.2f}",
1056
+ "Goals Scored": "{:.2f}",
1057
+ "Goals Conceded": "{:.2f}",
1058
+ "Goal Difference": "{:+.2f}",
1059
+ }),
1060
+ use_container_width=True,
1061
+ height=420,
1062
+ )
1063
+
1064
+
1065
+ # ─────────────────────────────────────────────────────────────────────────────
1066
+ # PAGE 3 — MODEL INSIGHTS
1067
+ # ─────────────────────────────────────────────────────────────────────────────
1068
+ def page_model_insights(models: dict, model_choice: str):
1069
+ st.markdown("""
1070
+ <div class="cv-heading">🧠 Model Insights</div>
1071
+ <div class="cv-subheading">Feature importance, model architecture, and performance metrics</div>
1072
+ """, unsafe_allow_html=True)
1073
+ st.markdown('<hr style="border-color:#1e3050;">', unsafe_allow_html=True)
1074
+
1075
+ model = models[model_choice]
1076
+
1077
+ # Performance cards
1078
+ st.markdown('<div class="cv-subheading">Model Performance on 2017–2020 Test Set</div>',
1079
+ unsafe_allow_html=True)
1080
+ perf_data = {
1081
+ "Random Forest": {"accuracy": 54.5, "f1": 0.510, "params": "300 trees, depth 8"},
1082
+ "Logistic Regression": {"accuracy": 57.7, "f1": 0.433, "params": "C=0.1, L2, lbfgs"},
1083
+ }
1084
+ m1, m2, m3, m4 = st.columns(4)
1085
+ d = perf_data.get(model_choice, {"accuracy": 0, "f1": 0, "params": "N/A"})
1086
+ m1.metric("Accuracy", f"{d['accuracy']:.1f}%")
1087
+ m2.metric("Macro F1", f"{d['f1']:.3f}")
1088
+ m3.metric("Train Size", "16,113 matches")
1089
+ m4.metric("Test Size", "3,025 matches")
1090
+
1091
+ st.markdown("<br>", unsafe_allow_html=True)
1092
+
1093
+ # Feature importance (RF only)
1094
+ if hasattr(model, "feature_importances_"):
1095
+ st.markdown('<div class="cv-subheading">Feature Importance — Random Forest (Gini)</div>',
1096
+ unsafe_allow_html=True)
1097
+ fig = make_feature_importance_chart(model)
1098
+ if fig:
1099
+ st.plotly_chart(fig, use_container_width=True, config={"displayModeBar": False})
1100
+
1101
+ # Feature legend
1102
+ with st.expander("📖 Why These Features?"):
1103
+ st.markdown("""
1104
+ | Feature | Why It Matters |
1105
+ |---|---|
1106
+ | **elo_diff / home_elo / away_elo** | Elo is the gold standard for continuous team strength. It adjusts for opponent quality and recency. The single most predictive signal. |
1107
+ | **home/away_recent_points** | Recent form (last 5 matches, pts basis) captures momentum and current squad fitness. |
1108
+ | **home/away_avg_goals_scored** | Offensive firepower. Teams that score more tend to win more — obvious but quantifiably significant. |
1109
+ | **home/away_avg_goals_conceded** | Defensive solidity. Conceding fewer goals is as important as scoring them. |
1110
+ | **home/away_rolling_gd** | Net goal difference over 5 games — combined attacking + defensive signal. |
1111
+ | **neutral_venue** | Eliminates home advantage, which is worth roughly 0.3–0.5 Elo points of expected improvement. |
1112
+ | **tournament_importance** | World Cup games are played differently from friendlies. Stakes affect tactics and effort. |
1113
+ """)
1114
+ else:
1115
+ # Logistic Regression — show coefficients
1116
+ st.markdown('<div class="cv-subheading">Logistic Regression Coefficients</div>',
1117
+ unsafe_allow_html=True)
1118
+ coef_df = pd.DataFrame(
1119
+ model.coef_,
1120
+ columns=FEATURE_COLS,
1121
+ index=["Home Win", "Away Win", "Draw"],
1122
+ ).T
1123
+ fig_coef = go.Figure()
1124
+ for cls, color in [("Home Win", COLORS["home"]),
1125
+ ("Away Win", COLORS["away"]),
1126
+ ("Draw", COLORS["draw"])]:
1127
+ fig_coef.add_trace(go.Bar(
1128
+ name=cls, x=coef_df.index, y=coef_df[cls], marker_color=color,
1129
+ hovertemplate=f"<b>%{{x}}</b><br>{cls}: %{{y:.3f}}<extra></extra>",
1130
+ ))
1131
+ fig_coef.update_layout(
1132
+ template=PLOTLY_TEMPLATE, barmode="group",
1133
+ paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)",
1134
+ height=400,
1135
+ xaxis=dict(tickangle=-35, tickfont=dict(size=10, color=COLORS["text"])),
1136
+ yaxis=dict(gridcolor=COLORS["border"]),
1137
+ legend=dict(font=dict(color=COLORS["text"])),
1138
+ margin=dict(t=20, b=80),
1139
+ )
1140
+ st.plotly_chart(fig_coef, use_container_width=True, config={"displayModeBar": False})
1141
+
1142
+ # Architecture explainer
1143
+ with st.expander("🏗️ Model Architecture & Training Details"):
1144
+ st.markdown(f"""
1145
+ **Model selected:** `{model_choice}`
1146
+
1147
+ **Training period:** 2000–2016 (16,113 matches)
1148
+ **Test period:** 2017–2020 (3,025 matches)
1149
+ **Split strategy:** Chronological — never random (prevents data leakage)
1150
+
1151
+ **Why time-based split?**
1152
+ A random split would let the model see 2019 matches during training and then predict
1153
+ 2010 matches — a form of temporal leakage. In sports analytics, we always train on the
1154
+ past and test on the future, exactly mirroring deployment conditions.
1155
+
1156
+ **No-leakage guarantee:**
1157
+ Every feature is computed using only matches *before* the current match date.
1158
+ The Elo engine processes matches sequentially, updating ratings only after
1159
+ feature extraction. This is the most common mistake in sports ML pipelines.
1160
+
1161
+ **Class balance:**
1162
+ Home Win ~48% | Away Win ~28% | Draw ~24%.
1163
+ Random Forest uses `class_weight='balanced'` to compensate for the draw minority.
1164
+ """)
1165
+
1166
+
1167
+ # ─────────────────────────────────────────────────────────────────────────────
1168
+ # PAGE 4 — ABOUT
1169
+ # ─────────────────────────────────────────────────────────────────────────────
1170
+ def page_about():
1171
+ st.markdown("""
1172
+ <div class="cv-heading">ℹ️ About CopaVision AI</div>
1173
+ <div class="cv-subheading">Phase 1 — International Football Match Predictor</div>
1174
+ """, unsafe_allow_html=True)
1175
+ st.markdown('<hr style="border-color:#1e3050;">', unsafe_allow_html=True)
1176
+
1177
+ c1, c2 = st.columns([3, 2])
1178
+
1179
+ with c1:
1180
+ st.markdown("""
1181
+ <div class="cv-card cv-card-accent">
1182
+ <div style="font-family:'Barlow Condensed',sans-serif; font-size:0.75rem;
1183
+ color:#5a7a9a; letter-spacing:2px; text-transform:uppercase;
1184
+ margin-bottom:0.8rem;">PROJECT OVERVIEW</div>
1185
+ <p style="color:#e8f1ff; line-height:1.7;">
1186
+ CopaVision AI is a football analytics platform that uses machine learning
1187
+ to predict international match outcomes. Phase 1 covers the core prediction
1188
+ engine trained on 41,500+ historical matches from 1872–2020.
1189
+ </p>
1190
+ <p style="color:#e8f1ff; line-height:1.7;">
1191
+ The model combines <b style="color:#00d4ff;">Elo ratings</b>,
1192
+ <b style="color:#00ff9d;">rolling form metrics</b>, and
1193
+ <b style="color:#d2a8ff;">tournament context</b>
1194
+ to generate probabilistic win/draw/loss predictions for any pair of
1195
+ international teams.
1196
+ </p>
1197
+ </div>
1198
+ """, unsafe_allow_html=True)
1199
+
1200
+ st.markdown("""
1201
+ <div class="cv-card">
1202
+ <div style="font-family:'Barlow Condensed',sans-serif; font-size:0.75rem;
1203
+ color:#5a7a9a; letter-spacing:2px; text-transform:uppercase;
1204
+ margin-bottom:0.8rem;">HOW TO RUN</div>
1205
+ <pre style="background:#050b14; color:#00ff9d; padding:1rem;
1206
+ border-radius:8px; font-size:0.85rem; overflow-x:auto;">
1207
+ # Install dependencies
1208
+ pip install streamlit pandas numpy \\
1209
+ scikit-learn plotly joblib
1210
+
1211
+ # Launch app
1212
+ streamlit run app.py</pre>
1213
+ </div>
1214
+ """, unsafe_allow_html=True)
1215
+
1216
+ st.markdown("""
1217
+ <div class="cv-card">
1218
+ <div style="font-family:'Barlow Condensed',sans-serif; font-size:0.75rem;
1219
+ color:#5a7a9a; letter-spacing:2px; text-transform:uppercase;
1220
+ margin-bottom:0.8rem;">DEPLOY ON STREAMLIT CLOUD</div>
1221
+ <ol style="color:#e8f1ff; line-height:2; font-size:0.9rem;">
1222
+ <li>Push your project to a <b>public GitHub repo</b></li>
1223
+ <li>Go to <a href="https://share.streamlit.io" style="color:#00d4ff;">share.streamlit.io</a> and sign in</li>
1224
+ <li>Click <b>New App</b> → select your repo and branch</li>
1225
+ <li>Set <b>Main file path</b> to <code>app.py</code></li>
1226
+ <li>Add a <code>requirements.txt</code> (see right column)</li>
1227
+ <li>Click <b>Deploy</b> — live in ~2 minutes 🚀</li>
1228
+ </ol>
1229
+ </div>
1230
+ """, unsafe_allow_html=True)
1231
+
1232
+ with c2:
1233
+ st.markdown("""
1234
+ <div class="cv-card" style="margin-bottom:0.8rem;">
1235
+ <div style="font-family:'Barlow Condensed',sans-serif; font-size:0.75rem;
1236
+ color:#5a7a9a; letter-spacing:2px; text-transform:uppercase;
1237
+ margin-bottom:0.8rem;">FILE STRUCTURE</div>
1238
+ <pre style="background:#050b14; color:#e8f1ff; padding:1rem;
1239
+ border-radius:8px; font-size:0.82rem;">
1240
+ copavision-ai/
1241
+ │
1242
+ ├── app.py ← this file
1243
+ ├── requirements.txt
1244
+ ├── team_stats.json ← Elo + form data
1245
+ │
1246
+ ├── models/
1247
+ │ ├── copavision_rf.pkl
1248
+ │ └── copavision_lr.pkl
1249
+ │
1250
+ ├── data/
1251
+ │ └── results.csv ← raw dataset
1252
+ │
1253
+ └── utils/ ← (Phase 2+)
1254
+ ├── features.py
1255
+ ├── elo.py
1256
+ └── viz.py</pre>
1257
+ </div>
1258
+ """, unsafe_allow_html=True)
1259
+
1260
+ st.markdown("""
1261
+ <div class="cv-card" style="margin-bottom:0.8rem;">
1262
+ <div style="font-family:'Barlow Condensed',sans-serif; font-size:0.75rem;
1263
+ color:#5a7a9a; letter-spacing:2px; text-transform:uppercase;
1264
+ margin-bottom:0.8rem;">REQUIREMENTS.TXT</div>
1265
+ <pre style="background:#050b14; color:#00ff9d; padding:1rem;
1266
+ border-radius:8px; font-size:0.85rem;">
1267
+ streamlit>=1.32
1268
+ pandas>=2.0
1269
+ numpy>=1.26
1270
+ scikit-learn>=1.4
1271
+ plotly>=5.20
1272
+ joblib>=1.3</pre>
1273
+ </div>
1274
+ """, unsafe_allow_html=True)
1275
+
1276
+ st.markdown("""
1277
+ <div class="cv-card cv-card-accent">
1278
+ <div style="font-family:'Barlow Condensed',sans-serif; font-size:0.75rem;
1279
+ color:#5a7a9a; letter-spacing:2px; text-transform:uppercase;
1280
+ margin-bottom:0.8rem;">PHASE ROADMAP</div>
1281
+ <div style="font-size:0.88rem; line-height:2.2; color:#e8f1ff;">
1282
+ <span style="color:#00ff9d;">✓ Phase 1</span> &nbsp;Match Outcome Predictor<br>
1283
+ <span style="color:#00d4ff;">→ Phase 2</span> &nbsp;Player Dashboard<br>
1284
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add a <code>pages/02_players.py</code> file with<br>
1285
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FIFA/Transfermarkt player stats<br><br>
1286
+ <span style="color:#5a7a9a;">○ Phase 3</span> &nbsp;Sentiment Tracker<br>
1287
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Twitter/Reddit API + VADER/BERT<br>
1288
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sentiment pre-match signals<br><br>
1289
+ <span style="color:#5a7a9a;">○ Phase 4</span> &nbsp;Live Match Feed<br>
1290
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rapid API football → real-time<br>
1291
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;score updates & live Elo shifts
1292
+ </div>
1293
+ </div>
1294
+ """, unsafe_allow_html=True)
1295
+
1296
+ # Accuracy expectations
1297
+ st.markdown("<br>", unsafe_allow_html=True)
1298
+ with st.expander("📉 Realistic Accuracy Expectations & Limitations"):
1299
+ st.markdown("""
1300
+ | Benchmark | Accuracy |
1301
+ |---|---|
1302
+ | Random guessing (3 classes) | 33.3% |
1303
+ | Always predict Home Win | ~48% |
1304
+ | **CopaVision AI Phase 1** | **54–58%** |
1305
+ | State-of-the-art (squad data + deep learning) | 60–65% |
1306
+ | Human football experts | ~60% |
1307
+
1308
+ **Why football is hard to predict:**
1309
+ - Individual brilliance and errors are genuinely stochastic
1310
+ - Injuries and suspensions aren't in historical data
1311
+ - Tactics adapt match-to-match (chess, not poker)
1312
+ - Home crowd effects vary enormously by stadium
1313
+ - VAR and referee decisions introduce randomness
1314
+
1315
+ **Phase 1 limitations:**
1316
+ - No player-level data (squad strength, injury list)
1317
+ - No head-to-head historical records
1318
+ - Friendly matches dilute the training signal
1319
+ - Model trained up to 2020 — club-level Elo not factored in
1320
+ """)
1321
+
1322
+
1323
+ # ─────────────────────────────────────────────────────────────────────────────
1324
+ # MAIN APP
1325
+ # ─────────────────────────────────────────────────────────────────────────────
1326
+ def main():
1327
+ # Load data
1328
+ with st.spinner("Loading CopaVision AI…"):
1329
+ models = load_models()
1330
+ team_stats = load_team_stats()
1331
+
1332
+ if not models or not team_stats:
1333
+ st.error("Critical files missing. Ensure models/ and team_stats.json exist.")
1334
+ st.stop()
1335
+
1336
+ # Sidebar (returns page & model choice)
1337
+ page, model_choice = render_sidebar(team_stats, models)
1338
+
1339
+ # Page routing
1340
+ page_key = page.split(" ")[-1].strip()
1341
+ if page_key == "Match Predictor":
1342
+ page_match_predictor(models, team_stats, model_choice)
1343
+ elif page_key == "Team Explorer":
1344
+ page_team_explorer(team_stats)
1345
+ elif page_key == "Model Insights":
1346
+ page_model_insights(models, model_choice)
1347
+ elif page_key == "About":
1348
+ page_about()
1349
+
1350
+
1351
+ if __name__ == "__main__":
1352
+ main()
data/clustered_player_features.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/player_per90.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/player_stats.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/results.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/similarity_features.csv ADDED
The diff for this file is too large to render. See raw diff
 
models/copavision_lr.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:613a10b31a8a5df83f2ff655247c7be12dd42b9de3837199f10d1bd9d50a4dca
3
+ size 1215
models/copavision_rf.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:895e57a303e665aebe29063d74bbef8ba21a13de5d8ccdd2dcb04fcdeacf81c4
3
+ size 6779489
pages/02_Player_Dashboard.py ADDED
@@ -0,0 +1,1736 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ╔══════════════════════════════════════════════════════════════════════════════╗
3
+ ║ CopaVision AI | Phase 2: Player Performance Intelligence ║
4
+ ║ Rebuilt for Beginner-Friendly UX — v2 ║
5
+ ╚══════════════════════════════════════════════════════════════════════════════╝
6
+
7
+ Save as: pages/02_Player_Dashboard.py
8
+
9
+ Data files required (in data/ folder next to app.py):
10
+ data/player_stats.csv
11
+ data/player_per90.csv
12
+ data/similarity_features.csv
13
+ data/clustered_player_features.csv
14
+ """
15
+
16
+ import warnings
17
+ warnings.filterwarnings("ignore")
18
+
19
+ from pathlib import Path
20
+ import numpy as np
21
+ import pandas as pd
22
+ import plotly.graph_objects as go
23
+ import plotly.express as px
24
+ from sklearn.cluster import KMeans
25
+ from sklearn.decomposition import PCA
26
+ from sklearn.manifold import TSNE
27
+ from sklearn.metrics.pairwise import cosine_similarity
28
+ import streamlit as st
29
+
30
+ # ─────────────────────────────────────────────────────────────────────────────
31
+ # PAGE CONFIG
32
+ # ─────────────────────────────────────────────────────────────────────────────
33
+ st.set_page_config(
34
+ page_title="Player Intelligence | CopaVision AI",
35
+ page_icon="🧠",
36
+ layout="wide",
37
+ initial_sidebar_state="expanded",
38
+ )
39
+
40
+ # ─────────────────────────────────────────────────────────────────────────────
41
+ # CSS — same dark football theme as Phase 1 + new helper classes
42
+ # ─────────────────────────────────────────────────────────────────────────────
43
+ st.markdown("""
44
+ <style>
45
+ @import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@400;600;700;900&family=DM+Sans:wght@300;400;500;600&display=swap');
46
+
47
+ :root {
48
+ --bg-deep:#050b14; --bg-card:#0e1621; --bg-panel:#121d2e;
49
+ --border:#1e3050; --accent:#00d4ff; --green:#00ff9d;
50
+ --orange:#ff6b35; --gold:#ffd700; --purple:#d2a8ff;
51
+ --text:#e8f1ff; --muted:#5a7a9a;
52
+ }
53
+ .stApp {
54
+ background-color:var(--bg-deep);
55
+ background-image:
56
+ radial-gradient(ellipse at 15% 0%,rgba(0,212,255,0.06) 0%,transparent 50%),
57
+ radial-gradient(ellipse at 85% 100%,rgba(0,255,157,0.04) 0%,transparent 50%);
58
+ font-family:'DM Sans',sans-serif; color:var(--text);
59
+ }
60
+ #MainMenu,footer,header{visibility:hidden;}
61
+ .block-container{padding-top:1.2rem;padding-bottom:2rem;}
62
+
63
+ /* Sidebar */
64
+ [data-testid="stSidebar"]{background:var(--bg-panel)!important;border-right:1px solid var(--border)!important;}
65
+ [data-testid="stSidebar"] *{color:var(--text)!important;}
66
+
67
+ /* Metrics */
68
+ [data-testid="stMetric"]{background:var(--bg-card);border:1px solid var(--border);border-radius:12px;padding:14px 18px!important;}
69
+ [data-testid="stMetricValue"]{font-family:'Barlow Condensed',sans-serif!important;font-size:1.8rem!important;font-weight:700!important;color:var(--accent)!important;}
70
+ [data-testid="stMetricLabel"]{color:var(--muted)!important;font-size:0.74rem!important;}
71
+
72
+ /* Inputs */
73
+ [data-testid="stSelectbox"]>div>div{background:var(--bg-card)!important;border:1px solid var(--border)!important;border-radius:8px!important;}
74
+ [data-testid="stMultiSelect"]>div>div{background:var(--bg-card)!important;border:1px solid var(--border)!important;border-radius:8px!important;}
75
+
76
+ /* Buttons */
77
+ .stButton>button{
78
+ background:linear-gradient(135deg,#00d4ff,#0099cc);
79
+ color:#050b14!important;border:none!important;border-radius:8px!important;
80
+ font-family:'Barlow Condensed',sans-serif!important;font-size:1.05rem!important;
81
+ font-weight:700!important;letter-spacing:1px!important;padding:0.5rem 1.6rem!important;
82
+ text-transform:uppercase!important;transition:all 0.2s!important;
83
+ }
84
+ .stButton>button:hover{transform:translateY(-2px)!important;box-shadow:0 6px 24px rgba(0,212,255,0.3)!important;}
85
+
86
+ /* Tabs */
87
+ [data-testid="stTab"]{font-family:'Barlow Condensed',sans-serif!important;font-size:0.95rem!important;color:var(--muted)!important;}
88
+ [data-testid="stTab"][aria-selected="true"]{color:var(--accent)!important;}
89
+
90
+ /* Expanders */
91
+ [data-testid="stExpander"]{background:var(--bg-card)!important;border:1px solid var(--border)!important;border-radius:10px!important;}
92
+ hr{border-color:var(--border)!important;margin:1rem 0!important;}
93
+ .stAlert{background:var(--bg-card)!important;border-radius:10px!important;}
94
+ .stSpinner>div{border-top-color:var(--accent)!important;}
95
+
96
+ /* ── Custom components ── */
97
+ .cv-card{background:var(--bg-card);border:1px solid var(--border);border-radius:14px;padding:1.2rem 1.4rem;margin-bottom:0.8rem;}
98
+ .cv-card-blue {border-left:3px solid var(--accent);}
99
+ .cv-card-green {border-left:3px solid var(--green);}
100
+ .cv-card-orange{border-left:3px solid var(--orange);}
101
+ .cv-card-gold {border-left:3px solid var(--gold);}
102
+ .cv-card-purple{border-left:3px solid var(--purple);}
103
+
104
+ .cv-heading{font-family:'Barlow Condensed',sans-serif;font-size:1.5rem;font-weight:700;letter-spacing:1px;color:var(--text);text-transform:uppercase;margin-bottom:0.2rem;}
105
+ .cv-sub{font-family:'Barlow Condensed',sans-serif;font-size:0.95rem;color:var(--muted);letter-spacing:0.4px;margin-bottom:0.9rem;}
106
+ .cv-label{font-family:'Barlow Condensed',sans-serif;font-size:0.7rem;color:var(--muted);letter-spacing:2.5px;text-transform:uppercase;margin-bottom:0.3rem;display:block;}
107
+
108
+ /* Onboarding / how-to banner */
109
+ .howto-banner{
110
+ background:linear-gradient(135deg,rgba(0,212,255,0.08) 0%,rgba(0,255,157,0.05) 100%);
111
+ border:1px solid rgba(0,212,255,0.25);border-radius:14px;
112
+ padding:1.2rem 1.6rem;margin-bottom:1.2rem;
113
+ }
114
+ .howto-step{
115
+ display:flex;align-items:flex-start;gap:12px;margin-bottom:10px;
116
+ }
117
+ .howto-num{
118
+ font-family:'Barlow Condensed',sans-serif;font-size:1.4rem;font-weight:900;
119
+ color:var(--accent);min-width:28px;line-height:1;
120
+ }
121
+ .howto-text{font-size:0.88rem;color:var(--text);line-height:1.5;}
122
+ .howto-text b{color:var(--accent);}
123
+
124
+ /* Player header badge */
125
+ .player-badge{
126
+ background:linear-gradient(135deg,var(--bg-card) 0%,#0a1828 100%);
127
+ border:1px solid var(--border);border-left:4px solid var(--accent);
128
+ border-radius:14px;padding:1.4rem 1.8rem;margin-bottom:1rem;
129
+ }
130
+ .player-name-big{font-family:'Barlow Condensed',sans-serif;font-size:2rem;font-weight:900;color:var(--text);letter-spacing:1px;}
131
+ .player-meta{font-size:0.85rem;color:var(--muted);margin-top:0.3rem;line-height:1.8;}
132
+
133
+ /* Glossary pill */
134
+ .gloss{display:inline-block;background:rgba(0,212,255,0.1);border:1px solid rgba(0,212,255,0.3);
135
+ color:var(--accent);font-size:0.75rem;padding:2px 9px;border-radius:20px;margin:2px 3px 2px 0;}
136
+
137
+ /* Archetype chip */
138
+ .arch-chip{display:inline-block;font-family:'Barlow Condensed',sans-serif;font-size:0.9rem;
139
+ font-weight:700;letter-spacing:1px;text-transform:uppercase;
140
+ padding:5px 14px;border-radius:6px;margin:3px 3px 3px 0;}
141
+
142
+ /* Percentile bar */
143
+ .pct-row{margin:6px 0;}
144
+ .pct-label-row{display:flex;justify-content:space-between;align-items:center;margin-bottom:3px;}
145
+ .pct-name{font-size:0.82rem;color:var(--muted);}
146
+ .pct-val{font-size:0.82rem;font-weight:600;color:var(--text);}
147
+ .pct-track{background:#1e3050;border-radius:4px;height:9px;}
148
+ .pct-fill{height:9px;border-radius:4px;}
149
+
150
+ /* Stat table row */
151
+ .stat-row{display:flex;justify-content:space-between;padding:5px 0;border-bottom:1px solid #1e3050;}
152
+ .stat-label{font-size:0.83rem;color:var(--muted);}
153
+ .stat-val{font-size:0.83rem;font-weight:600;}
154
+
155
+ /* Tooltip definition box */
156
+ .def-box{background:#0a1422;border-left:3px solid var(--gold);border-radius:8px;
157
+ padding:10px 14px;margin:6px 0;font-size:0.82rem;color:var(--text);line-height:1.6;}
158
+ .def-term{font-family:'Barlow Condensed',sans-serif;font-size:1rem;font-weight:700;
159
+ color:var(--gold);margin-bottom:3px;}
160
+
161
+ /* Section step badge */
162
+ .step-badge{display:inline-flex;align-items:center;justify-content:center;
163
+ background:var(--accent);color:#050b14;font-family:'Barlow Condensed',sans-serif;
164
+ font-size:1rem;font-weight:900;width:26px;height:26px;border-radius:50%;
165
+ margin-right:8px;flex-shrink:0;}
166
+ </style>
167
+ """, unsafe_allow_html=True)
168
+
169
+ # ─────────────────────────────────────────────────────────────────────────────
170
+ # CONSTANTS
171
+ # ─────────────────────────────────────────────────────────────────────────────
172
+ DATA_DIR = Path(__file__).parent.parent / "data"
173
+ MIN_MINUTES = 450
174
+
175
+ C = { # colour palette shorthand
176
+ "accent": "#00d4ff", "green": "#00ff9d", "orange": "#ff6b35",
177
+ "gold": "#ffd700", "purple": "#d2a8ff", "muted": "#5a7a9a",
178
+ "bg": "#0e1621", "border": "#1e3050", "text": "#e8f1ff",
179
+ }
180
+
181
+ POSITION_GROUPS = {
182
+ "⛳ Goalkeeper": ["Goalkeeper"],
183
+ "🛡️ Defender": ["Center Back","Left Back","Right Back","Left Center Back",
184
+ "Right Center Back","Left Wing Back","Right Wing Back"],
185
+ "⚙️ Midfielder": ["Center Midfield","Left Center Midfield","Right Center Midfield",
186
+ "Center Defensive Midfield","Left Defensive Midfield",
187
+ "Right Defensive Midfield","Left Midfield","Right Midfield"],
188
+ "🌪️ Attacking Mid / Winger": ["Center Attacking Midfield","Left Attacking Midfield",
189
+ "Right Attacking Midfield","Left Wing","Right Wing"],
190
+ "⚡ Forward": ["Center Forward","Left Center Forward","Right Center Forward",
191
+ "Secondary Striker"],
192
+ }
193
+
194
+ # Plain-English position group names (strip emoji for internal logic)
195
+ def _pos_group_key(label):
196
+ return label.split(" ", 1)[1] if " " in label else label
197
+
198
+ CLUSTER_ARCHETYPES = {
199
+ 0: {"name":"Defensive Anchor", "color":"#ff6b35","icon":"🛡️",
200
+ "desc":"Wins headers, blocks shots, makes last-ditch tackles. The rock at the back."},
201
+ 1: {"name":"Ball Winner", "color":"#d2a8ff","icon":"⚔️",
202
+ "desc":"Hunts the ball relentlessly. High in duels, interceptions, and pressing intensity."},
203
+ 2: {"name":"Deep-Lying Playmaker", "color":"#00d4ff","icon":"🎯",
204
+ "desc":"The conductor. Passes the most, most accurately, and moves the ball forward."},
205
+ 3: {"name":"Clinical Finisher", "color":"#ffd700","icon":"⚡",
206
+ "desc":"Lives in the box. High xG, shots on target, and lethal conversion rate."},
207
+ 4: {"name":"Box-to-Box Engine", "color":"#00ff9d","icon":"🔄",
208
+ "desc":"Covers every blade of grass. Contributes in both attack and defence equally."},
209
+ 5: {"name":"Creative Winger", "color":"#ff6b35","icon":"🌪️",
210
+ "desc":"Takes on defenders 1v1, creates from wide areas, and delivers assists."},
211
+ 6: {"name":"High Press Striker", "color":"#ffd700","icon":"🎯",
212
+ "desc":"Scores goals AND pressures defenders. A nightmare to play against."},
213
+ 7: {"name":"Possession Carrier", "color":"#00d4ff","icon":"🎪",
214
+ "desc":"Drives forward with the ball, beats players, and progresses play."},
215
+ }
216
+
217
+ FEATURE_COLS_SIM = [
218
+ "goals_per90_scaled","assists_per90_scaled","shots_per90_scaled",
219
+ "shots_on_target_per90_scaled","xg_per90_scaled",
220
+ "passes_attempted_per90_scaled","passes_completed_per90_scaled",
221
+ "progressive_passes_per90_scaled","dribbles_attempted_per90_scaled",
222
+ "dribbles_completed_per90_scaled","carries_per90_scaled",
223
+ "tackles_per90_scaled","tackles_won_per90_scaled","interceptions_per90_scaled",
224
+ "pressures_per90_scaled","aerial_duels_per90_scaled","aerial_duels_won_per90_scaled",
225
+ "duels_per90_scaled","duels_won_per90_scaled","pass_accuracy_scaled",
226
+ "dribble_success_rate_scaled","tackle_success_rate_scaled",
227
+ "aerial_success_rate_scaled","duel_success_rate_scaled",
228
+ ]
229
+
230
+ # ─────────────────────────────────────────────────────────────────────────────
231
+ # DATA LOADING
232
+ # ─────────────────────────────────────────────────────────────────────────────
233
+ @st.cache_data(show_spinner=False)
234
+ def load_player_stats():
235
+ df = pd.read_csv(DATA_DIR / "player_stats.csv")
236
+ nickname = df["player_nickname"].replace(["0", 0, "", "nan", "None"], np.nan)
237
+ df["display_name"] = nickname.fillna(df["player_name"])
238
+ df = df[df["position"] != "0"].copy()
239
+ # Attach readable position group label
240
+ def _group(pos):
241
+ for label, positions in POSITION_GROUPS.items():
242
+ if pos in positions:
243
+ return label
244
+ return "Other"
245
+ df["pos_group"] = df["position"].apply(_group)
246
+ return df
247
+
248
+ @st.cache_data(show_spinner=False)
249
+ def load_per90():
250
+ df = pd.read_csv(DATA_DIR / "player_per90.csv")
251
+ nickname = df["player_nickname"].replace(["0", 0, "", "nan", "None"], np.nan)
252
+ df["display_name"] = nickname.fillna(df["player_name"])
253
+ df = df[df["position"] != "0"].copy()
254
+ return df
255
+
256
+ @st.cache_data(show_spinner=False)
257
+ def load_similarity():
258
+ df = pd.read_csv(DATA_DIR / "similarity_features.csv").fillna(0)
259
+ display_lookup = load_player_stats()[["player_id", "display_name"]].drop_duplicates("player_id")
260
+ df = df.merge(display_lookup, on="player_id", how="left")
261
+ df["display_name"] = df["display_name"].fillna(df["player_name"])
262
+ return df
263
+
264
+ @st.cache_data(show_spinner=False)
265
+ def load_clusters():
266
+ REQUIRED = {"player_id","cluster","pca_x","pca_y","tsne_x","tsne_y"}
267
+ path = DATA_DIR / "clustered_player_features.csv"
268
+ if path.exists():
269
+ df = pd.read_csv(path)
270
+ if REQUIRED.issubset(set(df.columns)):
271
+ display_lookup = load_player_stats()[["player_id", "display_name"]].drop_duplicates("player_id")
272
+ df = df.merge(display_lookup, on="player_id", how="left")
273
+ df["display_name"] = df["display_name"].fillna(df["player_name"])
274
+ return df
275
+ return _build_clusters()
276
+
277
+ @st.cache_data(show_spinner=False)
278
+ def _build_clusters():
279
+ sim = load_similarity()
280
+ X = sim[FEATURE_COLS_SIM].values
281
+ cl = sim[["player_id","player_name","primary_position","team_name","competition_name"]].copy()
282
+ cl["cluster"] = KMeans(n_clusters=8, random_state=42, n_init=10).fit_predict(X)
283
+ pca = PCA(n_components=2, random_state=42).fit_transform(X)
284
+ tsne = TSNE(n_components=2, random_state=42, perplexity=30).fit_transform(X)
285
+ cl["pca_x"], cl["pca_y"] = pca[:,0], pca[:,1]
286
+ cl["tsne_x"], cl["tsne_y"] = tsne[:,0], tsne[:,1]
287
+ display_lookup = load_player_stats()[["player_id", "display_name"]].drop_duplicates("player_id")
288
+ cl = cl.merge(display_lookup, on="player_id", how="left")
289
+ cl["display_name"] = cl["display_name"].fillna(cl["player_name"])
290
+ try:
291
+ cl.to_csv(DATA_DIR / "clustered_player_features.csv", index=False)
292
+ except Exception:
293
+ pass
294
+ return cl
295
+
296
+ # ─────────────────────────────────────────────────────────────────────────────
297
+ # SMALL HELPERS
298
+ # ─────────────────────────────────────────────────────────────────────────────
299
+ def fmt(val, dec=2, suffix=""):
300
+ if pd.isna(val): return "—"
301
+ if isinstance(val, float): return f"{val:.{dec}f}{suffix}"
302
+ return f"{val}{suffix}"
303
+
304
+ def pct_rank(series, val):
305
+ s = series.dropna()
306
+ if s.std() == 0: return 50.0
307
+ return float((s < val).mean() * 100)
308
+
309
+ def pct_color(p):
310
+ if p >= 85: return C["green"]
311
+ if p >= 65: return C["accent"]
312
+ if p >= 40: return C["gold"]
313
+ return C["orange"]
314
+
315
+ def pct_bar(label, pct, raw="", explain=""):
316
+ col = pct_color(pct)
317
+ badge = ("🔥 Elite" if pct>=85 else "✅ Good" if pct>=65 else
318
+ "➡️ Average" if pct>=40 else "📉 Below Avg")
319
+ tip = f" · <span style='color:{C['muted']};font-size:0.75rem;'>{explain}</span>" if explain else ""
320
+ return f"""
321
+ <div class="pct-row">
322
+ <div class="pct-label-row">
323
+ <span class="pct-name">{label}{tip}</span>
324
+ <span class="pct-val" style="color:{col};">
325
+ {raw}&nbsp;<span style="font-size:0.75rem;opacity:0.8;">{pct:.0f}th · {badge}</span>
326
+ </span>
327
+ </div>
328
+ <div class="pct-track"><div class="pct-fill" style="width:{min(pct,100):.0f}%;background:{col};"></div></div>
329
+ </div>"""
330
+
331
+ def stat_row(label, val, color=None, tooltip=""):
332
+ color = color or C["text"]
333
+ return (f'<div class="stat-row">'
334
+ f'<span class="stat-label">{label}</span>'
335
+ f'<span class="stat-val" style="color:{color};">{val}</span>'
336
+ f'</div>')
337
+
338
+ def _PLOT_BASE():
339
+ return dict(template="plotly_dark", paper_bgcolor="rgba(0,0,0,0)",
340
+ plot_bgcolor="rgba(0,0,0,0)")
341
+
342
+ # ─────────────────────────────────────────────────────────────────────────────
343
+ # GLOSSARY COMPONENT (shown inline wherever metrics appear)
344
+ # ─────────────────────────────────────────────────────────────────────────────
345
+ GLOSSARY = {
346
+ "xG (Expected Goals)":
347
+ "A probability score (0–1) for each shot — how likely it was to go in based on position, angle, and body part. "
348
+ "Higher xG = better quality chances. A striker with xG 20 but only 10 goals is under-performing; 25 goals = over-performing.",
349
+ "xA (Expected Assists)":
350
+ "Same idea as xG but for passes that led to shots. Measures the quality of chances created, not just whether the finish went in.",
351
+ "Per 90 (p90)":
352
+ "Stats divided by 90 minutes played, so you can fairly compare a player who played 900 mins to one who played 3,600 mins.",
353
+ "Percentile Rank":
354
+ "Your rank vs ALL players in the database. 90th percentile = better than 90% of players at that stat. 50th = exactly average.",
355
+ "Progressive Passes":
356
+ "Passes that move the ball at least 10 metres closer to the opponent's goal. Measures forward intent in build-up play.",
357
+ "Pressures":
358
+ "How often the player actively tries to win the ball back by pressuring the opponent in possession. A key pressing metric.",
359
+ "Duel Success Rate":
360
+ "% of 1v1 physical battles won. High rate = dominant in physical contests.",
361
+ }
362
+
363
+ def glossary_expander():
364
+ with st.expander("📖 Glossary — What do these numbers mean?", expanded=False):
365
+ for term, definition in GLOSSARY.items():
366
+ st.markdown(f"""
367
+ <div class="def-box">
368
+ <div class="def-term">{term}</div>
369
+ {definition}
370
+ </div>""", unsafe_allow_html=True)
371
+
372
+ # ─────────────────────────────────────────────────────────────────────────────
373
+ # SIDEBAR
374
+ # ─────────────────────────────────────────────────────────────────────────────
375
+ def render_sidebar():
376
+ with st.sidebar:
377
+ # Brand
378
+ st.markdown("""
379
+ <div style="text-align:center;padding:0.8rem 0 1rem;">
380
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:1.8rem;
381
+ font-weight:900;color:#00d4ff;letter-spacing:3px;">
382
+ COPA<span style="color:#00ff9d;">VISION</span></div>
383
+ <div style="font-size:0.75rem;color:#5a7a9a;letter-spacing:4px;">A I · P H A S E 2</div>
384
+ </div><hr>""", unsafe_allow_html=True)
385
+
386
+ # Navigation with plain labels
387
+ st.markdown('<span class="cv-label">CHOOSE A TOOL</span>', unsafe_allow_html=True)
388
+ page = st.radio("nav", [
389
+ "🔍 Search a Player",
390
+ "⚖️ Compare Two Players",
391
+ "🗺️ Explore Player Types",
392
+ "🔗 Find Similar Players",
393
+ ], label_visibility="collapsed")
394
+
395
+ st.markdown("<hr>", unsafe_allow_html=True)
396
+
397
+ # How-to guide in sidebar
398
+ st.markdown('<span class="cv-label">HOW TO USE THIS TOOL</span>', unsafe_allow_html=True)
399
+ st.markdown("""
400
+ <div style="font-size:0.82rem;line-height:1.8;color:#8a9ab0;">
401
+ <b style="color:#e8f1ff;">1.</b> Pick a tool above<br>
402
+ <b style="color:#e8f1ff;">2.</b> Use dropdowns to filter<br>
403
+ <b style="color:#e8f1ff;">3.</b> Select a player from the list<br>
404
+ <b style="color:#e8f1ff;">4.</b> Read the charts &amp; cards<br>
405
+ <br>
406
+ <span style="color:#5a7a9a;font-size:0.78rem;">
407
+ Tip: Hover over any chart for exact values.
408
+ Open the Glossary to learn what stats mean.
409
+ </span>
410
+ </div>""", unsafe_allow_html=True)
411
+
412
+ st.markdown("<hr>", unsafe_allow_html=True)
413
+ st.markdown("""
414
+ <div style="font-size:0.8rem;line-height:2;">
415
+ <span style="color:#00ff9d;">✓</span> Phase 1 · Match Predictor<br>
416
+ <span style="color:#00d4ff;">✓</span> Phase 2 · Player Intelligence<br>
417
+ <span style="color:#5a7a9a;">○</span> Phase 3 · Sentiment Tracker
418
+ </div>""", unsafe_allow_html=True)
419
+
420
+ # Strip emoji prefix for routing
421
+ return page.strip().split(" ")[-1].strip()
422
+
423
+
424
+ # ─────────────────────────────────────────────────────────────────────────────
425
+ # ── SHARED: STEP-BY-STEP PLAYER PICKER (used on 3 pages)
426
+ # ─────────────────────────────────────────────────────────────────────────────
427
+ def player_picker(ps_df, pp_df, key_prefix="pp", min_mins=MIN_MINUTES,
428
+ show_howto=True, label_override=None):
429
+ """
430
+ Guided 3-step player picker:
431
+ Step 1 — choose position group
432
+ Step 2 — choose competition (optionally also team)
433
+ Step 3 — choose player from the filtered shortlist
434
+
435
+ Returns: (player_row from ps_df, per90_row from pp_df, player_id)
436
+ """
437
+ # ── Onboarding banner ─────────────────────────────────────────────────────
438
+ if show_howto:
439
+ st.markdown("""
440
+ <div class="howto-banner">
441
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:1.1rem;
442
+ font-weight:700;color:#00d4ff;letter-spacing:1px;margin-bottom:10px;">
443
+ 🧭 HOW TO PICK A PLAYER — 3 EASY STEPS</div>
444
+ <div class="howto-step">
445
+ <div class="howto-num">1</div>
446
+ <div class="howto-text">
447
+ <b>Choose a position group</b> — are you looking for a goalkeeper, defender, midfielder, or forward?
448
+ Leave it on <b>"All positions"</b> to browse everyone.
449
+ </div>
450
+ </div>
451
+ <div class="howto-step">
452
+ <div class="howto-num">2</div>
453
+ <div class="howto-text">
454
+ <b>Pick a competition</b> (league/tournament) and optionally a <b>team</b>.
455
+ This narrows the player list so it's not overwhelming.
456
+ </div>
457
+ </div>
458
+ <div class="howto-step">
459
+ <div class="howto-num">3</div>
460
+ <div class="howto-text">
461
+ <b>Select the player</b> from the dropdown. Stats load instantly below.
462
+ </div>
463
+ </div>
464
+ </div>
465
+ """, unsafe_allow_html=True)
466
+
467
+ # ── STEP 1: Position ──────────────────────────────────────────────────────
468
+ st.markdown("""
469
+ <div style="display:flex;align-items:center;margin-bottom:4px;">
470
+ <div class="step-badge">1</div>
471
+ <span style="font-family:'Barlow Condensed',sans-serif;font-size:1.05rem;
472
+ font-weight:700;color:#e8f1ff;">Choose a position group</span>
473
+ </div>""", unsafe_allow_html=True)
474
+
475
+ pos_options = ["All positions"] + list(POSITION_GROUPS.keys())
476
+ pos_labels = {opt: opt for opt in pos_options}
477
+
478
+ pos_choice = st.selectbox(
479
+ "position group",
480
+ pos_options,
481
+ index=0,
482
+ format_func=lambda x: x,
483
+ label_visibility="collapsed",
484
+ key=f"{key_prefix}_pos",
485
+ help="Pick the type of player you want to explore. Select 'All positions' to see every player.",
486
+ )
487
+
488
+ # Filter by position
489
+ if pos_choice == "All positions":
490
+ filtered = ps_df.copy()
491
+ else:
492
+ allowed = POSITION_GROUPS.get(pos_choice, [])
493
+ filtered = ps_df[ps_df["position"].isin(allowed)].copy()
494
+
495
+ st.markdown("<br>", unsafe_allow_html=True)
496
+
497
+ # ── STEP 2: Competition + Team ─────────────────────────────────────────────
498
+ st.markdown("""
499
+ <div style="display:flex;align-items:center;margin-bottom:4px;">
500
+ <div class="step-badge">2</div>
501
+ <span style="font-family:'Barlow Condensed',sans-serif;font-size:1.05rem;
502
+ font-weight:700;color:#e8f1ff;">Narrow by competition, team &amp; nationality <span style="color:#5a7a9a;font-size:0.85rem;">(optional)</span></span>
503
+ </div>""", unsafe_allow_html=True)
504
+
505
+ col_comp, col_team, col_country = st.columns(3)
506
+ with col_comp:
507
+ comps = ["All competitions"] + sorted(filtered["competition"].unique())
508
+ comp_choice = st.selectbox(
509
+ "competition", comps, index=0,
510
+ label_visibility="collapsed",
511
+ key=f"{key_prefix}_comp",
512
+ help="e.g. 'Premier League', 'FIFA World Cup', 'La Liga'",
513
+ )
514
+ if comp_choice != "All competitions":
515
+ filtered = filtered[filtered["competition"] == comp_choice]
516
+
517
+ with col_team:
518
+ teams = ["All teams"] + sorted(filtered["team"].unique())
519
+ team_choice = st.selectbox(
520
+ "team", teams, index=0,
521
+ label_visibility="collapsed",
522
+ key=f"{key_prefix}_team",
523
+ help="Filter to one club or national team",
524
+ )
525
+ if team_choice != "All teams":
526
+ filtered = filtered[filtered["team"] == team_choice]
527
+
528
+ with col_country:
529
+ countries = ["All nationalities"] + sorted(filtered["country"].dropna().astype(str).unique())
530
+ country_choice = st.selectbox(
531
+ "nationality", countries, index=0,
532
+ label_visibility="collapsed",
533
+ key=f"{key_prefix}_country",
534
+ help="Filter by player nationality when available",
535
+ )
536
+ if country_choice != "All nationalities":
537
+ filtered = filtered[filtered["country"].astype(str) == country_choice]
538
+
539
+ if "age" in filtered.columns and filtered["age"].notna().any():
540
+ min_age = int(np.nanmin(filtered["age"]))
541
+ max_age = int(np.nanmax(filtered["age"]))
542
+ if min_age < max_age:
543
+ age_range = st.slider(
544
+ "Age range",
545
+ min_age, max_age, (min_age, max_age),
546
+ key=f"{key_prefix}_age",
547
+ help="Only shown when the processed dataset includes an age column.",
548
+ )
549
+ filtered = filtered[filtered["age"].between(age_range[0], age_range[1])]
550
+
551
+ # Minimum minutes guard
552
+ filtered = filtered[filtered["minutes_played"] >= min_mins]
553
+
554
+ # How many players remain
555
+ n_avail = filtered["display_name"].nunique()
556
+ if n_avail == 0:
557
+ st.warning("⚠️ No players match these filters. Try choosing 'All competitions' or a different position.")
558
+ return None, None, None
559
+
560
+ st.markdown(f"""
561
+ <div style="font-size:0.82rem;color:{C['muted']};margin:6px 0 12px;">
562
+ ✅ <b style="color:{C['text']};">{n_avail}</b> players available with ≥{min_mins} minutes played
563
+ </div>""", unsafe_allow_html=True)
564
+
565
+ # ── STEP 3: Player ─────────────────────────────────────────────────────────
566
+ label = label_override or "3"
567
+ st.markdown(f"""
568
+ <div style="display:flex;align-items:center;margin-bottom:4px;">
569
+ <div class="step-badge">{label}</div>
570
+ <span style="font-family:'Barlow Condensed',sans-serif;font-size:1.05rem;
571
+ font-weight:700;color:#e8f1ff;">Select the player</span>
572
+ </div>""", unsafe_allow_html=True)
573
+
574
+ player_names = sorted(filtered["display_name"].unique())
575
+ selected = st.selectbox(
576
+ "player", player_names,
577
+ label_visibility="collapsed",
578
+ key=f"{key_prefix}_player",
579
+ help="Type a name to search, or scroll through the list.",
580
+ )
581
+
582
+ # Resolve rows
583
+ ps_rows = filtered[filtered["display_name"] == selected]
584
+ player_row = ps_rows.sort_values("minutes_played", ascending=False).iloc[0]
585
+ pid = player_row["player_id"]
586
+
587
+ pp_rows = pp_df[pp_df["player_id"] == pid]
588
+ if pp_rows.empty:
589
+ pp_rows = pp_df[pp_df["display_name"] == selected]
590
+ per90_row = (pp_rows.sort_values("minutes_played", ascending=False).iloc[0]
591
+ if not pp_rows.empty else pd.Series(dtype=float))
592
+
593
+ return player_row, per90_row, int(pid)
594
+
595
+
596
+ # ─────────────────────────────────────────────────────────────────────────────
597
+ # PROFILE HEADER CARD
598
+ # ─────────────────────────────────────────────────────────────────────────────
599
+ def render_profile_header(player_row, cl_df):
600
+ arch = {}
601
+ if cl_df is not None:
602
+ cl_rows = cl_df[cl_df["player_id"] == player_row["player_id"]]
603
+ if not cl_rows.empty:
604
+ try:
605
+ arch = CLUSTER_ARCHETYPES.get(int(cl_rows.iloc[0]["cluster"]), {})
606
+ except Exception:
607
+ arch = {}
608
+
609
+ ac = arch.get("color", C["accent"])
610
+ an = arch.get("name", "Unknown")
611
+ ai = arch.get("icon", "⚽")
612
+ ad = arch.get("desc", "")
613
+
614
+ mins = player_row.get("minutes_played", 0)
615
+ match = player_row.get("matches_played", 0)
616
+ comp = player_row.get("competition", "—")
617
+ team = player_row.get("team", "—")
618
+ pos = player_row.get("position", "—")
619
+ nat = player_row.get("country", "—")
620
+ name = player_row.get("display_name", player_row.get("player_name","?"))
621
+
622
+ st.markdown(f"""
623
+ <div class="player-badge">
624
+ <div style="display:flex;justify-content:space-between;align-items:flex-start;flex-wrap:wrap;gap:10px;">
625
+ <div>
626
+ <div class="player-name-big">{name}</div>
627
+ <div class="player-meta">
628
+ 🏟️ <b style="color:{C['text']};">{team}</b>
629
+ &nbsp;·&nbsp; 📍 {pos}
630
+ &nbsp;·&nbsp; 🌍 {nat}
631
+ &nbsp;·&nbsp; 🏆 {comp}
632
+ </div>
633
+ <div class="player-meta" style="margin-top:4px;font-size:0.8rem;">
634
+ ⏱️ {fmt(mins,0)} minutes played across {fmt(match,0)} matches
635
+ </div>
636
+ </div>
637
+ <div style="text-align:right;">
638
+ <span class="arch-chip"
639
+ style="background:rgba(255,255,255,0.07);color:{ac};border:1px solid {ac};">
640
+ {ai}&nbsp;{an}
641
+ </span>
642
+ <div style="font-size:0.78rem;color:{C['muted']};max-width:200px;margin-top:6px;
643
+ text-align:right;line-height:1.4;">{ad}</div>
644
+ </div>
645
+ </div>
646
+ </div>""", unsafe_allow_html=True)
647
+
648
+
649
+ # ─────────────────────────────────────────────────────────────────────────────
650
+ # PERCENTILE BAR CHART (Plotly — beginner friendly labels)
651
+ # ─────────────────────────────────────────────────────────────────────────────
652
+ def make_pct_chart(per90_row, pp_df, title=""):
653
+ METRICS = [
654
+ ("Goals per 90 min", "goals_per90", "Goals scored per 90 min"),
655
+ ("Assists per 90 min", "assists_per90", "Goal assists per 90 min"),
656
+ ("Expected Goals (xG) / 90", "xg_per90", "Shot quality score / 90"),
657
+ ("Expected Assists (xA) / 90", "xassists_per90", "Chance creation quality"),
658
+ ("Progressive Passes / 90", "progressive_passes_per90", "Forward-moving passes / 90"),
659
+ ("Completed Dribbles / 90", "dribbles_completed_per90", "Dribbles won / 90"),
660
+ ("Tackles / 90", "tackles_per90", "Tackles attempted / 90"),
661
+ ("Interceptions / 90", "interceptions_per90", "Passes cut out / 90"),
662
+ ("Pressures / 90", "pressures_per90", "Press attempts / 90"),
663
+ ("Pass Accuracy %", "pass_accuracy", "% passes reaching teammate"),
664
+ ]
665
+ labels, pcts, colors, raws = [], [], [], []
666
+ for lbl, col, _ in METRICS:
667
+ if col in pp_df.columns and col in per90_row.index:
668
+ p = pct_rank(pp_df[col], per90_row.get(col, 0))
669
+ labels.append(lbl); pcts.append(p)
670
+ colors.append(pct_color(p))
671
+ raws.append(fmt(per90_row.get(col, 0)))
672
+
673
+ fig = go.Figure(go.Bar(
674
+ x=pcts, y=labels, orientation="h",
675
+ marker=dict(color=colors, line=dict(width=0)),
676
+ text=[f"{p:.0f}th percentile" for p in pcts],
677
+ textposition="outside",
678
+ textfont=dict(family="Barlow Condensed", size=11, color=C["text"]),
679
+ customdata=raws,
680
+ hovertemplate="<b>%{y}</b><br>Value: %{customdata}<br>Percentile: %{x:.0f}th<extra></extra>",
681
+ ))
682
+ # Add a vertical "Average" line at 50th percentile
683
+ fig.add_vline(x=50, line=dict(color=C["muted"], dash="dash", width=1),
684
+ annotation_text="Average (50th)", annotation_position="top",
685
+ annotation_font=dict(color=C["muted"], size=10))
686
+
687
+ fig.update_layout(
688
+ **_PLOT_BASE(),
689
+ xaxis=dict(range=[0,118], showgrid=False, visible=False),
690
+ yaxis=dict(tickfont=dict(family="DM Sans", size=11, color=C["text"])),
691
+ height=400, margin=dict(t=30,b=10,l=10,r=80),
692
+ title=dict(text=title or "How does this player rank vs all players?",
693
+ font=dict(family="Barlow Condensed", size=13, color=C["text"])),
694
+ )
695
+ return fig
696
+
697
+
698
+ # ─────────────────────────────────────────────────────────────────────────────
699
+ # RADAR CHART
700
+ # ─────────────────────────────────────────────────────────────────────────────
701
+ RADAR_CATS = {
702
+ "⚽ Finishing": ["goals_per90","xg_per90","shot_accuracy"],
703
+ "🎨 Creativity": ["assists_per90","xassists_per90","progressive_passes_per90"],
704
+ "🚗 Ball Carrying": ["dribbles_completed_per90","carries_per90"],
705
+ "🛡️ Defending": ["tackles_per90","interceptions_per90","clearances_per90"],
706
+ "💪 Physicality": ["aerial_duels_per90","duels_won_per90"],
707
+ "📨 Passing": ["passes_completed_per90","pass_accuracy"],
708
+ }
709
+
710
+ def make_radar(r1, r2, n1, n2, pp_df):
711
+ labels, v1, v2 = [], [], []
712
+
713
+ for cat, cols in RADAR_CATS.items():
714
+ for col in cols:
715
+ if col in pp_df.columns:
716
+ labels.append(
717
+ f"{cat}\n{col.replace('_per90','').replace('_',' ').title()}"
718
+ )
719
+
720
+ v1.append(pct_rank(pp_df[col], r1.get(col, 0)))
721
+ v2.append(pct_rank(pp_df[col], r2.get(col, 0)))
722
+
723
+ fig = go.Figure()
724
+
725
+ for nm, vals, col, fill_col in [
726
+ (n1, v1, C["green"], "rgba(0,255,157,0.20)"),
727
+ (n2, v2, C["accent"], "rgba(0,212,255,0.15)")
728
+ ]:
729
+ fig.add_trace(go.Scatterpolar(
730
+ r=vals + [vals[0]],
731
+ theta=labels + [labels[0]],
732
+ fill="toself",
733
+ fillcolor=fill_col,
734
+ line=dict(color=col, width=2),
735
+ name=nm,
736
+ hovertemplate="<b>%{theta}</b><br>Percentile: %{r:.0f}<extra></extra>",
737
+ ))
738
+
739
+ fig.update_layout(
740
+ **_PLOT_BASE(),
741
+ polar=dict(
742
+ bgcolor="rgba(14,22,33,0.6)",
743
+
744
+ radialaxis=dict(
745
+ visible=True,
746
+ range=[0,100],
747
+ showticklabels=False,
748
+ gridcolor=C["border"]
749
+ ),
750
+
751
+ angularaxis=dict(
752
+ tickfont=dict(
753
+ family="DM Sans",
754
+ size=9,
755
+ color=C["text"]
756
+ ),
757
+ gridcolor=C["border"]
758
+ ),
759
+ ),
760
+
761
+ legend=dict(
762
+ font=dict(
763
+ family="Barlow Condensed",
764
+ color=C["text"],
765
+ size=13
766
+ ),
767
+ bgcolor="rgba(0,0,0,0)"
768
+ ),
769
+
770
+ height=420,
771
+ margin=dict(t=40,b=40,l=50,r=50),
772
+ )
773
+
774
+ return fig
775
+
776
+ # ─────────────────────────────────────────────────────────────────────────────
777
+ # CLUSTER SCATTER
778
+ # ─────────────────────────────────────────────────────────────────────────────
779
+ def make_cluster_scatter(cl_df, highlight_id=None, mode="pca"):
780
+ x_col, y_col = (("tsne_x", "tsne_y") if mode == "tsne" else ("pca_x", "pca_y"))
781
+ title = "t-SNE player style map" if mode == "tsne" else "PCA player style map"
782
+
783
+ plot_df = cl_df.copy()
784
+ plot_df["cluster"] = plot_df["cluster"].astype(int)
785
+ plot_df["archetype"] = plot_df["cluster"].apply(
786
+ lambda cid: CLUSTER_ARCHETYPES.get(cid, {}).get("name", f"Cluster {cid}")
787
+ )
788
+ plot_df["hover_team"] = plot_df.get("team_name", "Unknown")
789
+ plot_df["hover_comp"] = plot_df.get("competition_name", "Unknown")
790
+ plot_df["hover_pos"] = plot_df.get("primary_position", "Unknown")
791
+
792
+ fig = go.Figure()
793
+ for cid in sorted(plot_df["cluster"].unique()):
794
+ subset = plot_df[plot_df["cluster"] == cid]
795
+ arch = CLUSTER_ARCHETYPES.get(int(cid), {})
796
+ name = arch.get("name", f"Cluster {cid}")
797
+ color = arch.get("color", C["accent"])
798
+ fig.add_trace(go.Scattergl(
799
+ x=subset[x_col],
800
+ y=subset[y_col],
801
+ mode="markers",
802
+ name=name,
803
+ marker=dict(
804
+ size=8,
805
+ color=color,
806
+ opacity=0.68,
807
+ line=dict(width=0.5, color="rgba(232,241,255,0.25)"),
808
+ ),
809
+ customdata=np.stack([
810
+ subset["display_name"].astype(str),
811
+ subset["hover_pos"].astype(str),
812
+ subset["hover_team"].astype(str),
813
+ subset["hover_comp"].astype(str),
814
+ ], axis=-1),
815
+ hovertemplate=(
816
+ "<b>%{customdata[0]}</b><br>"
817
+ "Type: " + name + "<br>"
818
+ "Position: %{customdata[1]}<br>"
819
+ "Team: %{customdata[2]}<br>"
820
+ "Competition: %{customdata[3]}<extra></extra>"
821
+ ),
822
+ ))
823
+
824
+ if highlight_id is not None:
825
+ highlighted = plot_df[plot_df["player_id"] == highlight_id]
826
+ if not highlighted.empty:
827
+ row = highlighted.iloc[0]
828
+ fig.add_trace(go.Scattergl(
829
+ x=[row[x_col]],
830
+ y=[row[y_col]],
831
+ mode="markers+text",
832
+ name="Highlighted player",
833
+ text=[row["display_name"]],
834
+ textposition="top center",
835
+ textfont=dict(family="Barlow Condensed", size=13, color=C["gold"]),
836
+ marker=dict(
837
+ size=18,
838
+ color=C["gold"],
839
+ symbol="star",
840
+ line=dict(width=2, color=C["text"]),
841
+ ),
842
+ hovertemplate=(
843
+ f"<b>{row['display_name']}</b><br>"
844
+ f"Type: {row['archetype']}<br>"
845
+ f"Position: {row['hover_pos']}<br>"
846
+ f"Team: {row['hover_team']}<extra></extra>"
847
+ ),
848
+ ))
849
+
850
+ fig.update_layout(
851
+ **_PLOT_BASE(),
852
+ title=dict(
853
+ text=title,
854
+ font=dict(family="Barlow Condensed", size=16, color=C["text"]),
855
+ ),
856
+ xaxis=dict(
857
+ title="Style dimension 1",
858
+ showgrid=True,
859
+ gridcolor=C["border"],
860
+ zeroline=False,
861
+ tickfont=dict(color=C["muted"]),
862
+ title_font=dict(color=C["muted"]),
863
+ ),
864
+ yaxis=dict(
865
+ title="Style dimension 2",
866
+ showgrid=True,
867
+ gridcolor=C["border"],
868
+ zeroline=False,
869
+ tickfont=dict(color=C["muted"]),
870
+ title_font=dict(color=C["muted"]),
871
+ ),
872
+ legend=dict(
873
+ orientation="h",
874
+ yanchor="bottom",
875
+ y=1.02,
876
+ xanchor="left",
877
+ x=0,
878
+ font=dict(family="Barlow Condensed", size=11, color=C["text"]),
879
+ bgcolor="rgba(0,0,0,0)",
880
+ ),
881
+ height=560,
882
+ margin=dict(t=92, b=40, l=20, r=20),
883
+ )
884
+ return fig
885
+
886
+
887
+ def _comparison_bars(r1, r2, n1, n2, pp_df):
888
+
889
+ METRICS = [
890
+ ("Goals / 90", "goals_per90"),
891
+ ("Assists / 90", "assists_per90"),
892
+ ("xG / 90", "xg_per90"),
893
+ ("xA / 90", "xassists_per90"),
894
+ ("Prog. Passes / 90","progressive_passes_per90"),
895
+ ("Dribbles / 90", "dribbles_completed_per90"),
896
+ ("Tackles / 90", "tackles_per90"),
897
+ ("Interceptions / 90","interceptions_per90"),
898
+ ("Pass Accuracy", "pass_accuracy"),
899
+ ("Pressures / 90", "pressures_per90"),
900
+ ]
901
+
902
+ labels, v1, v2 = [], [], []
903
+
904
+ for lbl, col in METRICS:
905
+ if col in pp_df.columns:
906
+ labels.append(lbl)
907
+
908
+ v1.append(
909
+ pct_rank(pp_df[col], r1.get(col, 0))
910
+ )
911
+
912
+ v2.append(
913
+ pct_rank(pp_df[col], r2.get(col, 0))
914
+ )
915
+
916
+ st.markdown("""
917
+ <div class="cv-card cv-card-blue" style="margin-bottom:0.8rem;">
918
+ <b style="color:#00d4ff;">Reading this chart</b> —
919
+ bars show <b>percentile rank</b> (0–100).
920
+ Longer bar = better than more players at that stat.
921
+ 50 = average.
922
+ </div>
923
+ """, unsafe_allow_html=True)
924
+
925
+ fig = go.Figure()
926
+
927
+ fig.add_trace(go.Bar(
928
+ name=n1,
929
+ x=labels,
930
+ y=v1,
931
+ marker_color=C["green"],
932
+ text=[f"{v:.0f}" for v in v1],
933
+ textposition="outside",
934
+ textfont=dict(
935
+ size=10,
936
+ color=C["text"]
937
+ ),
938
+ hovertemplate="<b>%{x}</b><br>" + n1 + ": %{y:.0f}th percentile<extra></extra>"
939
+ ))
940
+
941
+ fig.add_trace(go.Bar(
942
+ name=n2,
943
+ x=labels,
944
+ y=v2,
945
+ marker_color=C["accent"],
946
+ text=[f"{v:.0f}" for v in v2],
947
+ textposition="outside",
948
+ textfont=dict(
949
+ size=10,
950
+ color=C["text"]
951
+ ),
952
+ hovertemplate="<b>%{x}</b><br>" + n2 + ": %{y:.0f}th percentile<extra></extra>"
953
+ ))
954
+
955
+ fig.add_hline(
956
+ y=50,
957
+ line=dict(
958
+ color=C["muted"],
959
+ dash="dash",
960
+ width=1
961
+ ),
962
+ annotation_text="Average",
963
+ annotation_position="right",
964
+ annotation_font=dict(
965
+ color=C["muted"],
966
+ size=10
967
+ )
968
+ )
969
+
970
+ fig.update_layout(
971
+ **_PLOT_BASE(),
972
+ barmode="group",
973
+
974
+ xaxis=dict(
975
+ tickfont=dict(
976
+ family="Barlow Condensed",
977
+ size=10,
978
+ color=C["text"]
979
+ )
980
+ ),
981
+
982
+ yaxis=dict(
983
+ range=[0,125],
984
+ gridcolor=C["border"],
985
+
986
+ title=dict(
987
+ text="Percentile Rank",
988
+ font=dict(
989
+ color=C["muted"]
990
+ )
991
+ )
992
+ ),
993
+
994
+ legend=dict(
995
+ font=dict(
996
+ family="Barlow Condensed",
997
+ color=C["text"],
998
+ size=13
999
+ ),
1000
+ bgcolor="rgba(0,0,0,0)"
1001
+ ),
1002
+
1003
+ height=380,
1004
+ margin=dict(t=20,b=20,l=50,r=20)
1005
+ )
1006
+
1007
+ st.plotly_chart(
1008
+ fig,
1009
+ use_container_width=True,
1010
+ config={"displayModeBar": False}
1011
+ )
1012
+
1013
+ # ─────────────────────────────────────────────────────────────────────────────
1014
+ # PAGE 1 — SEARCH A PLAYER
1015
+ # ─────────────────────────────────────────────────────────────────────────────
1016
+ def page_search(ps_df, pp_df, cl_df):
1017
+ st.markdown('<div class="cv-heading">🔍 Search a Player</div>', unsafe_allow_html=True)
1018
+ st.markdown('<div class="cv-sub">Pick any player from the database and explore their full performance report</div>', unsafe_allow_html=True)
1019
+ st.markdown("<hr>", unsafe_allow_html=True)
1020
+
1021
+ # Guided picker
1022
+ player_row, per90_row, pid = player_picker(ps_df, pp_df, key_prefix="s")
1023
+ if player_row is None:
1024
+ return
1025
+
1026
+ st.markdown("<hr>", unsafe_allow_html=True)
1027
+
1028
+ # ── Profile header ────────────────────────────────────────────────────────
1029
+ render_profile_header(player_row, cl_df)
1030
+
1031
+ # ── Key numbers strip ─────────────────────────────────────────────────────
1032
+ st.markdown("""
1033
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:0.75rem;
1034
+ color:#5a7a9a;letter-spacing:2px;text-transform:uppercase;margin-bottom:6px;">
1035
+ KEY NUMBERS AT A GLANCE</div>""", unsafe_allow_html=True)
1036
+ m1,m2,m3,m4,m5,m6 = st.columns(6)
1037
+ m1.metric("⚽ Goals", fmt(player_row.get("goals",0), 0),
1038
+ help="Total goals scored")
1039
+ m2.metric("🎯 Assists", fmt(player_row.get("assists",0), 0),
1040
+ help="Total goal assists")
1041
+ m3.metric("📈 xG", fmt(player_row.get("xg",0)),
1042
+ help="Expected Goals — how many goals the shots were worth")
1043
+ m4.metric("✨ xA", fmt(player_row.get("xassists",0)),
1044
+ help="Expected Assists — quality of chances created")
1045
+ m5.metric("⏱️ Minutes", fmt(player_row.get("minutes_played",0), 0),
1046
+ help="Total minutes played")
1047
+ m6.metric("🏁 Matches", fmt(player_row.get("matches_played",0), 0),
1048
+ help="Total matches appeared in")
1049
+
1050
+ # Glossary always available
1051
+ st.markdown("<br>", unsafe_allow_html=True)
1052
+ glossary_expander()
1053
+ st.markdown("<br>", unsafe_allow_html=True)
1054
+
1055
+ # ── Tabs ──────────────────────────────────────────────────────────────────
1056
+ t1, t2, t3 = st.tabs([
1057
+ "📊 How do they rank?",
1058
+ "📋 All Statistics",
1059
+ "🎭 Playing Style",
1060
+ ])
1061
+
1062
+ with t1:
1063
+ st.markdown("""
1064
+ <div class="cv-card cv-card-blue" style="margin-bottom:1rem;">
1065
+ <b style="color:#00d4ff;">What am I looking at?</b><br>
1066
+ <span style="font-size:0.85rem;color:#8a9ab0;">
1067
+ Each bar shows how this player ranks compared to <b>every other player</b> in our database.
1068
+ A bar at <b>90th percentile</b> means they are better than 90% of players at that stat.
1069
+ 50th = perfectly average. The dashed line marks the average.
1070
+ </span>
1071
+ </div>""", unsafe_allow_html=True)
1072
+
1073
+ c1, c2 = st.columns([3, 2])
1074
+ with c1:
1075
+ st.plotly_chart(make_pct_chart(per90_row, pp_df), use_container_width=True,
1076
+ config={"displayModeBar": False})
1077
+ with c2:
1078
+ # Strengths & weaknesses
1079
+ _render_strengths_weaknesses(per90_row, pp_df)
1080
+
1081
+ with t2:
1082
+ _render_full_stats_beginner(player_row, per90_row)
1083
+
1084
+ with t3:
1085
+ _render_playing_style(player_row, per90_row, pp_df, cl_df)
1086
+
1087
+
1088
+ def _render_strengths_weaknesses(per90_row, pp_df):
1089
+ CHECKS = {
1090
+ "Goals/90": "goals_per90",
1091
+ "Assists/90": "assists_per90",
1092
+ "xG/90": "xg_per90",
1093
+ "Prog. Passes/90": "progressive_passes_per90",
1094
+ "Dribbles/90": "dribbles_completed_per90",
1095
+ "Tackles/90": "tackles_per90",
1096
+ "Interceptions/90": "interceptions_per90",
1097
+ "Pressures/90": "pressures_per90",
1098
+ "Pass Accuracy": "pass_accuracy",
1099
+ "Aerial Duels/90": "aerial_duels_per90",
1100
+ }
1101
+ ranked = sorted(
1102
+ [(l, pct_rank(pp_df[c], per90_row.get(c,0)))
1103
+ for l,c in CHECKS.items() if c in pp_df.columns and c in per90_row.index],
1104
+ key=lambda x: x[1], reverse=True
1105
+ )
1106
+ strong = ranked[:3]
1107
+ weak = ranked[-3:][::-1]
1108
+
1109
+ st.markdown(f"""
1110
+ <div class="cv-card cv-card-green">
1111
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:0.85rem;
1112
+ color:#00ff9d;letter-spacing:1.5px;text-transform:uppercase;margin-bottom:8px;">
1113
+ 💪 BIGGEST STRENGTHS</div>
1114
+ {''.join(f'''<div class="stat-row">
1115
+ <span class="stat-label">✅ {l}</span>
1116
+ <span class="stat-val" style="color:#00ff9d;">{p:.0f}th percentile</span>
1117
+ </div>''' for l,p in strong)}
1118
+ </div>
1119
+ <div class="cv-card cv-card-orange" style="margin-top:0.6rem;">
1120
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:0.85rem;
1121
+ color:#ff6b35;letter-spacing:1.5px;text-transform:uppercase;margin-bottom:8px;">
1122
+ ⚠️ RELATIVE WEAKNESSES</div>
1123
+ <div style="font-size:0.78rem;color:{C['muted']};margin-bottom:8px;">
1124
+ These are still compared to ALL players — even a "weakness" can be fine for their position.
1125
+ </div>
1126
+ {''.join(f'''<div class="stat-row">
1127
+ <span class="stat-label">△ {l}</span>
1128
+ <span class="stat-val" style="color:#ff6b35;">{p:.0f}th percentile</span>
1129
+ </div>''' for l,p in weak)}
1130
+ </div>""", unsafe_allow_html=True)
1131
+
1132
+
1133
+ def _render_full_stats_beginner(player_row, per90_row):
1134
+ st.markdown("""
1135
+ <div class="cv-card cv-card-blue" style="margin-bottom:1rem;">
1136
+ <b style="color:#00d4ff;">Reading this table</b><br>
1137
+ <span style="font-size:0.85rem;color:#8a9ab0;">
1138
+ The left column shows <b>career totals</b>. The right shows <b>per-90-minute rates</b>
1139
+ — this is more useful for comparing players who played different amounts of time.
1140
+ </span>
1141
+ </div>""", unsafe_allow_html=True)
1142
+
1143
+ c1,c2,c3 = st.columns(3)
1144
+ with c1:
1145
+ st.markdown(f"""
1146
+ <div class="cv-card cv-card-blue">
1147
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:0.85rem;
1148
+ color:{C['accent']};text-transform:uppercase;letter-spacing:1.5px;
1149
+ margin-bottom:10px;">⚽ ATTACKING</div>
1150
+ {stat_row("Goals (total)", fmt(player_row.get("goals",0),0), C["green"])}
1151
+ {stat_row("Shots (total)", fmt(player_row.get("shots",0),0))}
1152
+ {stat_row("Shots on Target", fmt(player_row.get("shots_on_target",0),0))}
1153
+ {stat_row("Shot Accuracy %", fmt(player_row.get("shot_accuracy",0)) + "%")}
1154
+ {stat_row("xG — total", fmt(player_row.get("xg",0)), C["gold"])}
1155
+ <div style="font-size:0.75rem;color:{C['muted']};margin:8px 0 4px;font-style:italic;">Per 90 minutes:</div>
1156
+ {stat_row("Goals / 90 min", fmt(per90_row.get("goals_per90",0)), C["green"])}
1157
+ {stat_row("Shots / 90 min", fmt(per90_row.get("shots_per90",0)))}
1158
+ {stat_row("xG / 90 min", fmt(per90_row.get("xg_per90",0)), C["gold"])}
1159
+ </div>""", unsafe_allow_html=True)
1160
+
1161
+ with c2:
1162
+ st.markdown(f"""
1163
+ <div class="cv-card cv-card-green">
1164
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:0.85rem;
1165
+ color:{C['green']};text-transform:uppercase;letter-spacing:1.5px;
1166
+ margin-bottom:10px;">🎯 CREATING &amp; PASSING</div>
1167
+ {stat_row("Assists (total)", fmt(player_row.get("assists",0),0), C["green"])}
1168
+ {stat_row("xA — total", fmt(player_row.get("xassists",0)), C["gold"])}
1169
+ {stat_row("Passes Attempted", fmt(player_row.get("passes_attempted",0),0))}
1170
+ {stat_row("Passes Completed", fmt(player_row.get("passes_completed",0),0))}
1171
+ {stat_row("Pass Accuracy %", fmt(player_row.get("pass_accuracy",0)) + "%", C["accent"])}
1172
+ {stat_row("Progressive Passes", fmt(player_row.get("progressive_passes",0),0))}
1173
+ {stat_row("Dribbles Won/Tried",
1174
+ f"{fmt(player_row.get('dribbles_completed',0),0)} / {fmt(player_row.get('dribbles_attempted',0),0)}")}
1175
+ {stat_row("Dribble Success %", fmt(player_row.get("dribble_success_rate",0)) + "%")}
1176
+ <div style="font-size:0.75rem;color:{C['muted']};margin:8px 0 4px;font-style:italic;">Per 90 minutes:</div>
1177
+ {stat_row("Assists / 90", fmt(per90_row.get("assists_per90",0)), C["green"])}
1178
+ {stat_row("Prog. Passes / 90", fmt(per90_row.get("progressive_passes_per90",0)))}
1179
+ </div>""", unsafe_allow_html=True)
1180
+
1181
+ with c3:
1182
+ st.markdown(f"""
1183
+ <div class="cv-card cv-card-orange">
1184
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:0.85rem;
1185
+ color:{C['orange']};text-transform:uppercase;letter-spacing:1.5px;
1186
+ margin-bottom:10px;">🛡️ DEFENDING</div>
1187
+ {stat_row("Tackles (total)", fmt(player_row.get("tackles",0),0))}
1188
+ {stat_row("Tackles Won", fmt(player_row.get("tackles_won",0),0))}
1189
+ {stat_row("Tackle Success %", fmt(player_row.get("tackle_success_rate",0)) + "%", C["accent"])}
1190
+ {stat_row("Interceptions", fmt(player_row.get("interceptions",0),0), C["accent"])}
1191
+ {stat_row("Pressures", fmt(player_row.get("pressures",0),0))}
1192
+ {stat_row("Clearances", fmt(player_row.get("clearances",0),0))}
1193
+ {stat_row("Aerial Duels Won/Total",
1194
+ f"{fmt(player_row.get('aerial_duels_won',0),0)} / {fmt(player_row.get('aerial_duels',0),0)}")}
1195
+ {stat_row("Aerial Success %", fmt(player_row.get("aerial_success_rate",0)) + "%")}
1196
+ <div style="font-size:0.75rem;color:{C['muted']};margin:8px 0 4px;font-style:italic;">Per 90 minutes:</div>
1197
+ {stat_row("Tackles / 90", fmt(per90_row.get("tackles_per90",0)))}
1198
+ {stat_row("Interceptions / 90", fmt(per90_row.get("interceptions_per90",0)))}
1199
+ </div>""", unsafe_allow_html=True)
1200
+
1201
+
1202
+ def _render_playing_style(player_row, per90_row, pp_df, cl_df):
1203
+ arch = {}
1204
+ if cl_df is not None:
1205
+ cl_rows = cl_df[cl_df["player_id"] == player_row["player_id"]]
1206
+ if not cl_rows.empty:
1207
+ try: arch = CLUSTER_ARCHETYPES.get(int(cl_rows.iloc[0]["cluster"]), {})
1208
+ except Exception: pass
1209
+
1210
+ ac = arch.get("color", C["accent"])
1211
+ an = arch.get("name", "Unknown")
1212
+ ai = arch.get("icon", "⚽")
1213
+ ad = arch.get("desc", "")
1214
+
1215
+ def idx(cols):
1216
+ scores = [pct_rank(pp_df[c], per90_row.get(c,0))
1217
+ for c in cols if c in pp_df.columns and c in per90_row.index]
1218
+ return np.mean(scores) if scores else 50.0
1219
+
1220
+ att = idx(["goals_per90","shots_per90","xg_per90","shot_accuracy"])
1221
+ cre = idx(["assists_per90","progressive_passes_per90","dribbles_completed_per90","pass_accuracy"])
1222
+ dfe = idx(["tackles_per90","interceptions_per90","pressures_per90","clearances_per90"])
1223
+
1224
+ def index_bar(label, val, desc):
1225
+ col = pct_color(val)
1226
+ badge = ("Elite" if val>=85 else "Strong" if val>=65 else "Average" if val>=40 else "Low")
1227
+ return f"""
1228
+ <div style="margin-bottom:14px;">
1229
+ <div style="display:flex;justify-content:space-between;margin-bottom:4px;">
1230
+ <span style="font-size:0.88rem;color:{C['text']};font-weight:600;">{label}</span>
1231
+ <span style="font-size:0.88rem;color:{col};font-weight:700;">{val:.0f} / 100 — {badge}</span>
1232
+ </div>
1233
+ <div style="font-size:0.78rem;color:{C['muted']};margin-bottom:5px;">{desc}</div>
1234
+ <div class="pct-track">
1235
+ <div class="pct-fill" style="width:{min(val,100):.0f}%;background:{col};"></div>
1236
+ </div>
1237
+ </div>"""
1238
+
1239
+ st.markdown(f"""
1240
+ <div class="cv-card cv-card-gold" style="margin-bottom:1rem;">
1241
+ <div style="display:flex;align-items:center;gap:12px;margin-bottom:8px;">
1242
+ <span style="font-size:2rem;">{ai}</span>
1243
+ <div>
1244
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:1.4rem;
1245
+ font-weight:700;color:{ac};letter-spacing:1px;">Player Type: {an}</div>
1246
+ <div style="font-size:0.85rem;color:{C['text']};margin-top:3px;">{ad}</div>
1247
+ </div>
1248
+ </div>
1249
+ <div style="font-size:0.78rem;color:{C['muted']};">
1250
+ Determined by machine learning — comparing their statistical fingerprint to 7,000+ players.
1251
+ </div>
1252
+ </div>
1253
+ <div class="cv-card">
1254
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:0.85rem;color:{C['muted']};
1255
+ text-transform:uppercase;letter-spacing:1.5px;margin-bottom:14px;">
1256
+ PLAYING STYLE INDICES — scored out of 100 vs all players</div>
1257
+ {index_bar("⚽ Attacking Threat", att, "Goals, shots, and xG quality")}
1258
+ {index_bar("🎨 Creative Influence", cre, "Assists, progressive passes, dribbles, passing accuracy")}
1259
+ {index_bar("🛡️ Defensive Work", dfe, "Tackles, interceptions, pressures, clearances")}
1260
+ </div>""", unsafe_allow_html=True)
1261
+
1262
+
1263
+ # ─────────────────────────────────────────────────────────────────────────────
1264
+ # PAGE 2 — COMPARE TWO PLAYERS
1265
+ # ─────────────────────────────────────────────────────────────────────────────
1266
+ def page_compare(ps_df, pp_df, cl_df):
1267
+ st.markdown('<div class="cv-heading">⚖️ Compare Two Players</div>', unsafe_allow_html=True)
1268
+ st.markdown('<div class="cv-sub">Pick any two players and see how they stack up side-by-side</div>', unsafe_allow_html=True)
1269
+ st.markdown("<hr>", unsafe_allow_html=True)
1270
+
1271
+ # Explanation banner
1272
+ st.markdown("""
1273
+ <div class="howto-banner">
1274
+ <b style="color:#00d4ff;">How comparison works</b><br>
1275
+ <span style="font-size:0.85rem;color:#8a9ab0;">
1276
+ Use the filters below to find <b>Player 1</b>, then scroll down to find <b>Player 2</b>.
1277
+ The radar chart shows each player's <b>percentile rank</b> (0–100) — so a bigger shape means
1278
+ a stronger all-round player. The bar chart lets you compare individual stats head-to-head.
1279
+ </span>
1280
+ </div>""", unsafe_allow_html=True)
1281
+
1282
+ # Player 1 picker
1283
+ st.markdown("""
1284
+ <div style="background:rgba(0,255,157,0.06);border:1px solid rgba(0,255,157,0.2);
1285
+ border-radius:10px;padding:1rem 1.2rem;margin-bottom:0.8rem;">
1286
+ <span style="font-family:'Barlow Condensed',sans-serif;font-size:1.1rem;
1287
+ font-weight:700;color:#00ff9d;letter-spacing:1px;">👤 PLAYER 1 (Green)</span>
1288
+ </div>""", unsafe_allow_html=True)
1289
+ p1_row, p1_pp, p1_id = player_picker(ps_df, pp_df, key_prefix="cmp1", show_howto=False)
1290
+
1291
+ st.markdown("<br>", unsafe_allow_html=True)
1292
+
1293
+ # Player 2 picker
1294
+ st.markdown("""
1295
+ <div style="background:rgba(0,212,255,0.06);border:1px solid rgba(0,212,255,0.2);
1296
+ border-radius:10px;padding:1rem 1.2rem;margin-bottom:0.8rem;">
1297
+ <span style="font-family:'Barlow Condensed',sans-serif;font-size:1.1rem;
1298
+ font-weight:700;color:#00d4ff;letter-spacing:1px;">👤 PLAYER 2 (Blue)</span>
1299
+ </div>""", unsafe_allow_html=True)
1300
+ p2_row, p2_pp, p2_id = player_picker(ps_df, pp_df, key_prefix="cmp2", show_howto=False)
1301
+
1302
+ if p1_row is None or p2_row is None:
1303
+ return
1304
+
1305
+ n1 = p1_row.get("display_name", "Player 1")
1306
+ n2 = p2_row.get("display_name", "Player 2")
1307
+
1308
+ if p1_id == p2_id:
1309
+ st.warning("⚠️ You selected the same player twice. Please choose two different players.")
1310
+ return
1311
+
1312
+ st.markdown("<hr>", unsafe_allow_html=True)
1313
+
1314
+ # Side-by-side header cards
1315
+ col1, col2 = st.columns(2)
1316
+ with col1:
1317
+ _mini_card(p1_row, cl_df, C["green"])
1318
+ with col2:
1319
+ _mini_card(p2_row, cl_df, C["accent"])
1320
+
1321
+ st.markdown("<br>", unsafe_allow_html=True)
1322
+ glossary_expander()
1323
+ st.markdown("<br>", unsafe_allow_html=True)
1324
+
1325
+ t1, t2, t3 = st.tabs(["🕸️ Radar Chart", "📊 Side-by-Side Stats", "📋 Full Table"])
1326
+
1327
+ with t1:
1328
+ st.markdown("""
1329
+ <div class="cv-card cv-card-blue" style="margin-bottom:0.8rem;">
1330
+ <b style="color:#00d4ff;">Reading the radar</b> — Each point on the web = a stat category.
1331
+ <b>Further from centre = higher percentile</b>. A bigger overall shape = stronger player in that area.
1332
+ Numbers shown are percentile ranks (0–100), not raw stat values.
1333
+ </div>""", unsafe_allow_html=True)
1334
+ st.plotly_chart(make_radar(p1_pp, p2_pp, n1, n2, pp_df),
1335
+ use_container_width=True, config={"displayModeBar": False})
1336
+
1337
+ with t2:
1338
+ _comparison_bars(p1_pp, p2_pp, n1, n2, pp_df)
1339
+
1340
+ with t3:
1341
+ _comparison_table(p1_row, p2_row, p1_pp, p2_pp, n1, n2, pp_df)
1342
+
1343
+
1344
+ def _mini_card(ps_row, cl_df, color):
1345
+ arch = {}
1346
+ if cl_df is not None:
1347
+ cl_rows = cl_df[cl_df["player_id"] == ps_row["player_id"]]
1348
+ if not cl_rows.empty:
1349
+ try: arch = CLUSTER_ARCHETYPES.get(int(cl_rows.iloc[0]["cluster"]), {})
1350
+ except Exception: pass
1351
+ ac = arch.get("color", color)
1352
+ an = arch.get("name", "—")
1353
+ ai = arch.get("icon", "⚽")
1354
+ name = ps_row.get("display_name", ps_row.get("player_name","?"))
1355
+ st.markdown(f"""
1356
+ <div class="cv-card" style="border-left:4px solid {color};">
1357
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:1.4rem;
1358
+ font-weight:800;color:{color};margin-bottom:4px;">{name}</div>
1359
+ <div style="font-size:0.82rem;color:{C['muted']};margin-bottom:10px;">
1360
+ {ps_row.get('team','—')} · {ps_row.get('position','—')} · {ps_row.get('competition','—')}
1361
+ </div>
1362
+ <div style="display:grid;grid-template-columns:1fr 1fr;gap:4px;font-size:0.85rem;">
1363
+ <div>⚽ Goals: <b style="color:{C['text']};">{fmt(ps_row.get('goals',0),0)}</b></div>
1364
+ <div>🎯 Assists: <b style="color:{C['text']};">{fmt(ps_row.get('assists',0),0)}</b></div>
1365
+ <div>📈 xG: <b style="color:{C['text']};">{fmt(ps_row.get('xg',0))}</b></div>
1366
+ <div>⏱️ Mins: <b style="color:{C['text']};">{fmt(ps_row.get('minutes_played',0),0)}</b></div>
1367
+ </div>
1368
+ <div style="margin-top:8px;">
1369
+ <span class="arch-chip"
1370
+ style="background:rgba(255,255,255,0.06);color:{ac};border:1px solid {ac};
1371
+ font-size:0.8rem;padding:4px 12px;">
1372
+ {ai} {an}</span>
1373
+ </div>
1374
+ </div>""", unsafe_allow_html=True)
1375
+
1376
+
1377
+ def _comparison_bars(r1, r2, n1, n2, pp_df):
1378
+ METRICS = [
1379
+ ("Goals / 90", "goals_per90"),
1380
+ ("Assists / 90", "assists_per90"),
1381
+ ("xG / 90", "xg_per90"),
1382
+ ("xA / 90", "xassists_per90"),
1383
+ ("Prog. Passes / 90","progressive_passes_per90"),
1384
+ ("Dribbles / 90", "dribbles_completed_per90"),
1385
+ ("Tackles / 90", "tackles_per90"),
1386
+ ("Interceptions / 90","interceptions_per90"),
1387
+ ("Pass Accuracy", "pass_accuracy"),
1388
+ ("Pressures / 90", "pressures_per90"),
1389
+ ]
1390
+ labels, v1, v2 = [], [], []
1391
+ for lbl, col in METRICS:
1392
+ if col in pp_df.columns:
1393
+ labels.append(lbl)
1394
+ v1.append(pct_rank(pp_df[col], r1.get(col, 0)))
1395
+ v2.append(pct_rank(pp_df[col], r2.get(col, 0)))
1396
+
1397
+ st.markdown("""
1398
+ <div class="cv-card cv-card-blue" style="margin-bottom:0.8rem;">
1399
+ <b style="color:#00d4ff;">Reading this chart</b> — bars show <b>percentile rank</b> (0–100).
1400
+ Longer bar = better than more players at that stat. 50 = average.
1401
+ </div>""", unsafe_allow_html=True)
1402
+
1403
+ fig = go.Figure()
1404
+ fig.add_trace(go.Bar(name=n1, x=labels, y=v1, marker_color=C["green"],
1405
+ text=[f"{v:.0f}" for v in v1], textposition="outside",
1406
+ textfont=dict(size=10, color=C["text"]),
1407
+ hovertemplate="<b>%{x}</b><br>" + n1 + ": %{y:.0f}th percentile<extra></extra>"))
1408
+ fig.add_trace(go.Bar(name=n2, x=labels, y=v2, marker_color=C["accent"],
1409
+ text=[f"{v:.0f}" for v in v2], textposition="outside",
1410
+ textfont=dict(size=10, color=C["text"]),
1411
+ hovertemplate="<b>%{x}</b><br>" + n2 + ": %{y:.0f}th percentile<extra></extra>"))
1412
+ fig.add_hline(y=50, line=dict(color=C["muted"], dash="dash", width=1),
1413
+ annotation_text="Average", annotation_position="right",
1414
+ annotation_font=dict(color=C["muted"], size=10))
1415
+ fig.update_layout(**_PLOT_BASE(), barmode="group",
1416
+ xaxis=dict(tickfont=dict(family="Barlow Condensed",size=10,color=C["text"])),
1417
+ yaxis=dict(range=[0,125], gridcolor=C["border"],
1418
+ title="Percentile Rank",
1419
+ titlefont=dict(color=C["muted"])),
1420
+ legend=dict(font=dict(family="Barlow Condensed",color=C["text"],size=13),
1421
+ bgcolor="rgba(0,0,0,0)"),
1422
+ height=380, margin=dict(t=20,b=20,l=50,r=20))
1423
+ st.plotly_chart(fig, use_container_width=True, config={"displayModeBar": False})
1424
+
1425
+
1426
+ def _comparison_table(ps1, ps2, pp1, pp2, n1, n2, pp_df):
1427
+ st.markdown("""
1428
+ <div class="cv-card cv-card-blue" style="margin-bottom:0.8rem;">
1429
+ <b style="color:#00d4ff;">Reading this table</b> —
1430
+ <span style="color:#00ff9d;">Green</span> = that player wins this stat.
1431
+ Numbers in brackets e.g. <span style="color:#5a7a9a;">(82nd)</span> = percentile rank.
1432
+ </div>""", unsafe_allow_html=True)
1433
+
1434
+ rows = []
1435
+ STATS = [
1436
+ ("Goals (total)", "goals", ps1,ps2, False),
1437
+ ("Assists (total)", "assists", ps1,ps2, False),
1438
+ ("xG (total)", "xg", ps1,ps2, False),
1439
+ ("xA (total)", "xassists", ps1,ps2, False),
1440
+ ("Pass Accuracy %", "pass_accuracy", ps1,ps2, False),
1441
+ ("Goals / 90", "goals_per90", pp1,pp2, True),
1442
+ ("Assists / 90", "assists_per90", pp1,pp2, True),
1443
+ ("xG / 90", "xg_per90", pp1,pp2, True),
1444
+ ("Prog. Passes / 90","progressive_passes_per90", pp1,pp2, True),
1445
+ ("Dribbles / 90", "dribbles_completed_per90", pp1,pp2, True),
1446
+ ("Tackles / 90", "tackles_per90", pp1,pp2, True),
1447
+ ("Interceptions / 90","interceptions_per90", pp1,pp2, True),
1448
+ ("Pressures / 90", "pressures_per90", pp1,pp2, True),
1449
+ ]
1450
+ for label, col, src1, src2, is_per90 in STATS:
1451
+ v1 = src1.get(col, np.nan); v2 = src2.get(col, np.nan)
1452
+ if pd.isna(v1) and pd.isna(v2): continue
1453
+ pct_col = col if is_per90 else col
1454
+ p1 = pct_rank(pp_df[pct_col], v1) if pct_col in pp_df.columns and not pd.isna(v1) else None
1455
+ p2 = pct_rank(pp_df[pct_col], v2) if pct_col in pp_df.columns and not pd.isna(v2) else None
1456
+ rows.append({
1457
+ "Stat": label,
1458
+ n1: f"{fmt(v1)} {'('+str(int(p1))+'th)' if p1 is not None else ''}",
1459
+ n2: f"{fmt(v2)} {'('+str(int(p2))+'th)' if p2 is not None else ''}",
1460
+ "_v1": float(v1) if not pd.isna(v1) else -999,
1461
+ "_v2": float(v2) if not pd.isna(v2) else -999,
1462
+ })
1463
+
1464
+ df = pd.DataFrame(rows)
1465
+ display = df[["Stat", n1, n2]].copy()
1466
+
1467
+ def highlight(row):
1468
+ original = df[df["Stat"] == row["Stat"]]
1469
+ if original.empty: return ["","",""]
1470
+ v1 = original["_v1"].values[0]; v2 = original["_v2"].values[0]
1471
+ if v1 > v2:
1472
+ return ["","background-color:rgba(0,255,157,0.12);color:#00ff9d;",
1473
+ "background-color:rgba(255,107,53,0.06);color:#8a9ab0;"]
1474
+ elif v2 > v1:
1475
+ return ["","background-color:rgba(255,107,53,0.06);color:#8a9ab0;",
1476
+ "background-color:rgba(0,212,255,0.12);color:#00d4ff;"]
1477
+ return ["","",""]
1478
+
1479
+ st.dataframe(display.style.apply(highlight, axis=1),
1480
+ use_container_width=True, height=480)
1481
+
1482
+
1483
+ # ─────────────────────────────────────────────────────────────────────────────
1484
+ # PAGE 3 — EXPLORE PLAYER TYPES
1485
+ # ─────────────────────────────────────────────────────────────────────────────
1486
+ def page_clusters(ps_df, cl_df):
1487
+ st.markdown('<div class="cv-heading">🗺️ Explore Player Types</div>', unsafe_allow_html=True)
1488
+ st.markdown('<div class="cv-sub">Our AI grouped 7,000+ players into 8 playing styles using machine learning — explore them here</div>', unsafe_allow_html=True)
1489
+ st.markdown("<hr>", unsafe_allow_html=True)
1490
+
1491
+ # Explanation
1492
+ st.markdown("""
1493
+ <div class="howto-banner">
1494
+ <b style="color:#00d4ff;">What is this?</b><br>
1495
+ <span style="font-size:0.85rem;color:#8a9ab0;">
1496
+ We analysed 24 statistics for every player and used a machine-learning technique
1497
+ called <b>KMeans clustering</b> to automatically group players by how they play.
1498
+ Players in the same group have similar statistical fingerprints — not the same team or nationality,
1499
+ just a similar <b>playing style</b>.<br><br>
1500
+ The chart below shows every player as a dot. <b>Dots close together = players who play similarly.</b>
1501
+ Hover over any dot to see the player name.
1502
+ </span>
1503
+ </div>""", unsafe_allow_html=True)
1504
+
1505
+ # Controls row
1506
+ c1, c2, c3 = st.columns([3,2,2])
1507
+ with c1:
1508
+ st.markdown('<span class="cv-label">Highlight a specific player (optional)</span>',
1509
+ unsafe_allow_html=True)
1510
+ eligible_ids = set(ps_df.loc[ps_df["minutes_played"] >= MIN_MINUTES, "player_id"])
1511
+ highlight_df = cl_df[cl_df["player_id"].isin(eligible_ids)].copy()
1512
+ all_names = ["— Don't highlight anyone —"] + sorted(highlight_df["display_name"].dropna().unique())
1513
+ hl_name = st.selectbox("hl", all_names, label_visibility="collapsed",
1514
+ help="Search for a player to mark them with a gold star on the chart")
1515
+ with c2:
1516
+ st.markdown('<span class="cv-label">Filter to one player type</span>',
1517
+ unsafe_allow_html=True)
1518
+ type_opts = ["Show all types"] + [f"{a['icon']} {a['name']}" for a in CLUSTER_ARCHETYPES.values()]
1519
+ type_filter = st.selectbox("tf", type_opts, label_visibility="collapsed")
1520
+ with c3:
1521
+ st.markdown('<span class="cv-label">Chart style</span>', unsafe_allow_html=True)
1522
+ proj = st.radio("proj", ["PCA (faster)", "t-SNE (richer)"],
1523
+ horizontal=True, label_visibility="collapsed")
1524
+
1525
+ # Resolve highlight
1526
+ hl_id = None
1527
+ if hl_name != "— Don't highlight anyone —":
1528
+ rows = highlight_df[highlight_df["display_name"] == hl_name]
1529
+ if not rows.empty:
1530
+ hl_id = int(rows.iloc[0]["player_id"])
1531
+
1532
+ # Filter by type
1533
+ plot_df = cl_df.copy()
1534
+ if type_filter != "Show all types":
1535
+ target_name = type_filter.split(" ", 1)[1] # strip emoji
1536
+ cid = next((k for k,v in CLUSTER_ARCHETYPES.items() if v["name"] == target_name), None)
1537
+ if cid is not None:
1538
+ plot_df = plot_df[plot_df["cluster"] == cid]
1539
+
1540
+ mode = "tsne" if "t-SNE" in proj else "pca"
1541
+ st.plotly_chart(make_cluster_scatter(plot_df, hl_id, mode),
1542
+ use_container_width=True, config={"displayModeBar": False})
1543
+
1544
+ st.markdown('<hr style="border-color:#1e3050;">', unsafe_allow_html=True)
1545
+
1546
+ # Archetype cards — in a 4-column grid
1547
+ st.markdown("""
1548
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:1rem;font-weight:700;
1549
+ color:#e8f1ff;text-transform:uppercase;letter-spacing:1px;margin-bottom:12px;">
1550
+ THE 8 PLAYER TYPES EXPLAINED</div>""", unsafe_allow_html=True)
1551
+
1552
+ for row_items in [list(CLUSTER_ARCHETYPES.items())[i:i+4] for i in range(0,8,4)]:
1553
+ cols = st.columns(4)
1554
+ for col, (cid, arch) in zip(cols, row_items):
1555
+ count = len(cl_df[cl_df["cluster"] == cid])
1556
+ with col:
1557
+ st.markdown(f"""
1558
+ <div class="cv-card" style="border-top:3px solid {arch['color']};min-height:170px;">
1559
+ <div style="font-size:1.8rem;margin-bottom:4px;">{arch['icon']}</div>
1560
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:1rem;
1561
+ font-weight:700;color:{arch['color']};margin-bottom:4px;">{arch['name']}</div>
1562
+ <div style="font-size:0.76rem;color:{C['muted']};margin-bottom:8px;">
1563
+ {count:,} players in this group</div>
1564
+ <div style="font-size:0.82rem;color:{C['text']};line-height:1.5;">
1565
+ {arch['desc']}</div>
1566
+ </div>""", unsafe_allow_html=True)
1567
+
1568
+ # Top 10 players in selected type
1569
+ if type_filter != "Show all types":
1570
+ target_name = type_filter.split(" ", 1)[1]
1571
+ cid = next((k for k,v in CLUSTER_ARCHETYPES.items() if v["name"] == target_name), None)
1572
+ if cid is not None:
1573
+ st.markdown(f"""
1574
+ <div style="font-family:'Barlow Condensed',sans-serif;font-size:1rem;font-weight:700;
1575
+ color:#e8f1ff;text-transform:uppercase;letter-spacing:1px;
1576
+ margin:16px 0 10px;">Top Players — {type_filter}</div>""", unsafe_allow_html=True)
1577
+ pids = cl_df[cl_df["cluster"]==cid]["player_id"].tolist()
1578
+ top = (ps_df[ps_df["player_id"].isin(pids)]
1579
+ .sort_values("minutes_played", ascending=False)
1580
+ .drop_duplicates("display_name")
1581
+ .head(15)[["display_name","team","competition","position",
1582
+ "goals","assists","minutes_played"]])
1583
+ top.columns = ["Player","Team","Competition","Position","Goals","Assists","Minutes"]
1584
+ st.dataframe(top.reset_index(drop=True), use_container_width=True, height=420)
1585
+
1586
+
1587
+ # ─────────────────────────────────────────────────────────────────────────────
1588
+ # PAGE 4 — FIND SIMILAR PLAYERS
1589
+ # ─────────────────────────────────────────────────────────────────────────────
1590
+ def page_similar(ps_df, pp_df, sim_df, cl_df):
1591
+ st.markdown('<div class="cv-heading">🔗 Find Similar Players</div>', unsafe_allow_html=True)
1592
+ st.markdown('<div class="cv-sub">Pick any player and we\'ll find the players who play most like them — great for scouting alternatives</div>', unsafe_allow_html=True)
1593
+ st.markdown("<hr>", unsafe_allow_html=True)
1594
+
1595
+ st.markdown("""
1596
+ <div class="howto-banner">
1597
+ <b style="color:#00d4ff;">How this works</b><br>
1598
+ <span style="font-size:0.85rem;color:#8a9ab0;">
1599
+ We compare the player's statistical profile across 24 metrics against every other player
1600
+ using a technique called <b>cosine similarity</b>. A score of <b>100% = statistically identical</b>.
1601
+ A score of <b>80%+ = very similar playing style</b>.
1602
+ This doesn't mean they're equally talented — just that they play in a similar way.
1603
+ </span>
1604
+ </div>""", unsafe_allow_html=True)
1605
+
1606
+ # Reference player picker
1607
+ player_row, per90_row, pid = player_picker(ps_df, pp_df, key_prefix="sim", show_howto=False)
1608
+ if player_row is None:
1609
+ return
1610
+
1611
+ c1,c2 = st.columns([2,1])
1612
+ with c1:
1613
+ n_results = st.slider("How many similar players to show?", 5, 20, 10,
1614
+ help="Slide to see more or fewer results")
1615
+ with c2:
1616
+ same_pos = st.toggle("Same position only",
1617
+ help="Turn this ON to only see players in the same position")
1618
+
1619
+ if st.button("🔍 Find Similar Players", use_container_width=False):
1620
+ with st.spinner("Comparing against 7,000+ players…"):
1621
+ sim_rows = sim_df[sim_df["player_id"] == pid]
1622
+ if sim_rows.empty:
1623
+ st.error("Player not found in similarity dataset.")
1624
+ return
1625
+ X = sim_df[FEATURE_COLS_SIM].values
1626
+ idx_val = sim_rows.index[0]
1627
+ sims = cosine_similarity(X[idx_val].reshape(1,-1), X)[0]
1628
+ result = sim_df.copy(); result["similarity"] = sims
1629
+ result = result[result["player_id"] != pid]
1630
+ if same_pos:
1631
+ my_pos = sim_rows.iloc[0]["primary_position"]
1632
+ result = result[result["primary_position"] == my_pos]
1633
+ eligible_ids = set(ps_df.loc[ps_df["minutes_played"] >= MIN_MINUTES, "player_id"])
1634
+ result = result[result["player_id"].isin(eligible_ids)]
1635
+ result = result.nlargest(n_results, "similarity").reset_index(drop=True)
1636
+
1637
+ st.markdown("<hr>", unsafe_allow_html=True)
1638
+
1639
+ # Reference card
1640
+ render_profile_header(player_row, cl_df)
1641
+ st.markdown(f"""
1642
+ <div style="font-size:0.82rem;color:{C['muted']};margin-bottom:16px;">
1643
+ Showing the <b style="color:{C['text']};">{len(result)}</b> most statistically similar players
1644
+ {'in the same position' if same_pos else 'from all positions'}
1645
+ </div>""", unsafe_allow_html=True)
1646
+
1647
+ # Result cards in 2-column grid
1648
+ for i in range(0, len(result), 2):
1649
+ cols = st.columns(2)
1650
+ for j, col in enumerate(cols):
1651
+ idx2 = i+j
1652
+ if idx2 >= len(result): break
1653
+ row = result.iloc[idx2]
1654
+ score = int(row["similarity"] * 100)
1655
+ scol = (C["green"] if score>=90 else C["accent"] if score>=75 else C["gold"])
1656
+
1657
+ # Archetype
1658
+ cl_rows = cl_df[cl_df["player_id"] == row["player_id"]] if cl_df is not None else pd.DataFrame()
1659
+ arch = {}
1660
+ if not cl_rows.empty:
1661
+ try: arch = CLUSTER_ARCHETYPES.get(int(cl_rows.iloc[0]["cluster"]), {})
1662
+ except Exception: pass
1663
+
1664
+ # Plain English similarity label
1665
+ sim_label = ("🟢 Virtually identical" if score>=92 else
1666
+ "✅ Very similar" if score>=80 else
1667
+ "🔵 Somewhat similar" if score>=65 else
1668
+ "⚪ Loosely similar")
1669
+
1670
+ with col:
1671
+ st.markdown(f"""
1672
+ <div class="cv-card" style="border-left:3px solid {scol};">
1673
+ <div style="display:flex;justify-content:space-between;align-items:flex-start;">
1674
+ <div>
1675
+ <div style="font-family:'Barlow Condensed',sans-serif;
1676
+ font-size:1.1rem;font-weight:700;color:{C['text']};">
1677
+ #{idx2+1} &nbsp; {row['display_name']}</div>
1678
+ <div style="font-size:0.8rem;color:{C['muted']};margin-top:2px;">
1679
+ {row['primary_position']} · {row['team_name']}</div>
1680
+ <div style="font-size:0.76rem;color:{C['muted']};">
1681
+ {row['competition_name']}</div>
1682
+ </div>
1683
+ <div style="text-align:right;flex-shrink:0;margin-left:10px;">
1684
+ <div style="font-family:'Barlow Condensed',sans-serif;
1685
+ font-size:2rem;font-weight:900;color:{scol};
1686
+ line-height:1;">{score}%</div>
1687
+ <div style="font-size:0.68rem;color:{C['muted']};">SIMILARITY</div>
1688
+ </div>
1689
+ </div>
1690
+ <div style="margin:8px 0 4px;">
1691
+ <div style="background:#1e3050;border-radius:4px;height:6px;">
1692
+ <div style="width:{score}%;height:6px;border-radius:4px;
1693
+ background:{scol};"></div>
1694
+ </div>
1695
+ </div>
1696
+ <div style="font-size:0.8rem;color:{scol};margin-top:6px;">{sim_label}</div>
1697
+ <div style="margin-top:6px;">
1698
+ <span class="arch-chip"
1699
+ style="font-size:0.75rem;padding:3px 10px;
1700
+ background:rgba(255,255,255,0.05);
1701
+ color:{arch.get('color',C['muted'])};
1702
+ border:1px solid {arch.get('color',C['border'])};">
1703
+ {arch.get('icon','⚽')} {arch.get('name','—')}</span>
1704
+ </div>
1705
+ </div>""", unsafe_allow_html=True)
1706
+ else:
1707
+ st.markdown(f"""
1708
+ <div style="text-align:center;padding:2.5rem;color:{C['muted']};font-size:0.95rem;">
1709
+ 👆 Select a player above, then click <b style="color:{C['accent']};">Find Similar Players</b>
1710
+ </div>""", unsafe_allow_html=True)
1711
+
1712
+
1713
+ # ─────────────────────────────────────────────────────────────────────────────
1714
+ # MAIN
1715
+ # ─────────────────────────────────────────────────────────────────────────────
1716
+ def main():
1717
+ with st.spinner("Loading player data…"):
1718
+ ps_df = load_player_stats()
1719
+ pp_df = load_per90()
1720
+ sim_df = load_similarity()
1721
+ cl_df = load_clusters()
1722
+
1723
+ page = render_sidebar()
1724
+
1725
+ if "Search" in page:
1726
+ page_search(ps_df, pp_df, cl_df)
1727
+ elif "Compare" in page:
1728
+ page_compare(ps_df, pp_df, cl_df)
1729
+ elif "Explore" in page or "Types" in page:
1730
+ page_clusters(ps_df, cl_df)
1731
+ elif "Similar" in page:
1732
+ page_similar(ps_df, pp_df, sim_df, cl_df)
1733
+
1734
+
1735
+ if __name__ == "__main__":
1736
+ main()
src/streamlit_app.py DELETED
@@ -1,40 +0,0 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
- import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
team_stats.json ADDED
@@ -0,0 +1,2386 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "Egypt": {
3
+ "elo": 1653.3,
4
+ "recent_points": 1.6,
5
+ "avg_scored": 0.6,
6
+ "avg_conceded": 0.4,
7
+ "rolling_gd": 0.2,
8
+ "matches_played": 271
9
+ },
10
+ "Togo": {
11
+ "elo": 1435.5,
12
+ "recent_points": 0.4,
13
+ "avg_scored": 0.6,
14
+ "avg_conceded": 1.4,
15
+ "rolling_gd": -0.8,
16
+ "matches_played": 184
17
+ },
18
+ "Tunisia": {
19
+ "elo": 1693.1,
20
+ "recent_points": 2.6,
21
+ "avg_scored": 1.6,
22
+ "avg_conceded": 0.4,
23
+ "rolling_gd": 1.2,
24
+ "matches_played": 258
25
+ },
26
+ "Trinidad and Tobago": {
27
+ "elo": 1465.6,
28
+ "recent_points": 0.6,
29
+ "avg_scored": 3.0,
30
+ "avg_conceded": 2.2,
31
+ "rolling_gd": 0.8,
32
+ "matches_played": 286
33
+ },
34
+ "Canada": {
35
+ "elo": 1662.8,
36
+ "recent_points": 1.8,
37
+ "avg_scored": 2.2,
38
+ "avg_conceded": 1.4,
39
+ "rolling_gd": 0.8,
40
+ "matches_played": 172
41
+ },
42
+ "Burkina Faso": {
43
+ "elo": 1589.6,
44
+ "recent_points": 1.6,
45
+ "avg_scored": 0.6,
46
+ "avg_conceded": 0.4,
47
+ "rolling_gd": 0.2,
48
+ "matches_played": 218
49
+ },
50
+ "Gabon": {
51
+ "elo": 1589.5,
52
+ "recent_points": 2.6,
53
+ "avg_scored": 1.8,
54
+ "avg_conceded": 0.6,
55
+ "rolling_gd": 1.2,
56
+ "matches_played": 185
57
+ },
58
+ "Guatemala": {
59
+ "elo": 1587.5,
60
+ "recent_points": 2.6,
61
+ "avg_scored": 4.6,
62
+ "avg_conceded": 0.0,
63
+ "rolling_gd": 4.6,
64
+ "matches_played": 206
65
+ },
66
+ "Armenia": {
67
+ "elo": 1410.8,
68
+ "recent_points": 0.8,
69
+ "avg_scored": 1.2,
70
+ "avg_conceded": 3.2,
71
+ "rolling_gd": -2.0,
72
+ "matches_played": 164
73
+ },
74
+ "Ivory Coast": {
75
+ "elo": 1604.2,
76
+ "recent_points": 1.8,
77
+ "avg_scored": 1.2,
78
+ "avg_conceded": 1.0,
79
+ "rolling_gd": 0.2,
80
+ "matches_played": 247
81
+ },
82
+ "Mexico": {
83
+ "elo": 1939.4,
84
+ "recent_points": 3.0,
85
+ "avg_scored": 3.0,
86
+ "avg_conceded": 0.6,
87
+ "rolling_gd": 2.4,
88
+ "matches_played": 361
89
+ },
90
+ "Iran": {
91
+ "elo": 1754.7,
92
+ "recent_points": 1.4,
93
+ "avg_scored": 3.6,
94
+ "avg_conceded": 0.8,
95
+ "rolling_gd": 2.8,
96
+ "matches_played": 288
97
+ },
98
+ "Bermuda": {
99
+ "elo": 1522.6,
100
+ "recent_points": 0.8,
101
+ "avg_scored": 1.0,
102
+ "avg_conceded": 2.2,
103
+ "rolling_gd": -1.2,
104
+ "matches_played": 84
105
+ },
106
+ "Cameroon": {
107
+ "elo": 1615.6,
108
+ "recent_points": 1.2,
109
+ "avg_scored": 0.6,
110
+ "avg_conceded": 0.6,
111
+ "rolling_gd": 0.0,
112
+ "matches_played": 242
113
+ },
114
+ "Senegal": {
115
+ "elo": 1781.2,
116
+ "recent_points": 2.0,
117
+ "avg_scored": 1.6,
118
+ "avg_conceded": 0.6,
119
+ "rolling_gd": 1.0,
120
+ "matches_played": 229
121
+ },
122
+ "China PR": {
123
+ "elo": 1617.2,
124
+ "recent_points": 0.8,
125
+ "avg_scored": 0.8,
126
+ "avg_conceded": 1.0,
127
+ "rolling_gd": -0.2,
128
+ "matches_played": 277
129
+ },
130
+ "New Zealand": {
131
+ "elo": 1643.0,
132
+ "recent_points": 1.2,
133
+ "avg_scored": 1.0,
134
+ "avg_conceded": 1.4,
135
+ "rolling_gd": -0.4,
136
+ "matches_played": 129
137
+ },
138
+ "Jamaica": {
139
+ "elo": 1699.6,
140
+ "recent_points": 2.6,
141
+ "avg_scored": 3.0,
142
+ "avg_conceded": 0.2,
143
+ "rolling_gd": 2.8,
144
+ "matches_played": 257
145
+ },
146
+ "United States": {
147
+ "elo": 1822.6,
148
+ "recent_points": 2.4,
149
+ "avg_scored": 3.2,
150
+ "avg_conceded": 0.6,
151
+ "rolling_gd": 2.6,
152
+ "matches_played": 324
153
+ },
154
+ "Ghana": {
155
+ "elo": 1711.0,
156
+ "recent_points": 1.6,
157
+ "avg_scored": 0.8,
158
+ "avg_conceded": 0.4,
159
+ "rolling_gd": 0.4,
160
+ "matches_played": 247
161
+ },
162
+ "Morocco": {
163
+ "elo": 1780.5,
164
+ "recent_points": 1.6,
165
+ "avg_scored": 1.8,
166
+ "avg_conceded": 0.8,
167
+ "rolling_gd": 1.0,
168
+ "matches_played": 239
169
+ },
170
+ "Panama": {
171
+ "elo": 1585.7,
172
+ "recent_points": 0.6,
173
+ "avg_scored": 1.0,
174
+ "avg_conceded": 2.0,
175
+ "rolling_gd": -1.0,
176
+ "matches_played": 265
177
+ },
178
+ "Algeria": {
179
+ "elo": 1813.4,
180
+ "recent_points": 2.0,
181
+ "avg_scored": 2.0,
182
+ "avg_conceded": 0.8,
183
+ "rolling_gd": 1.2,
184
+ "matches_played": 217
185
+ },
186
+ "Malta": {
187
+ "elo": 1161.8,
188
+ "recent_points": 0.0,
189
+ "avg_scored": 0.2,
190
+ "avg_conceded": 3.0,
191
+ "rolling_gd": -2.8,
192
+ "matches_played": 184
193
+ },
194
+ "Qatar": {
195
+ "elo": 1811.0,
196
+ "recent_points": 1.8,
197
+ "avg_scored": 2.4,
198
+ "avg_conceded": 1.0,
199
+ "rolling_gd": 1.4,
200
+ "matches_played": 328
201
+ },
202
+ "South Korea": {
203
+ "elo": 1817.5,
204
+ "recent_points": 2.0,
205
+ "avg_scored": 0.8,
206
+ "avg_conceded": 0.6,
207
+ "rolling_gd": 0.2,
208
+ "matches_played": 326
209
+ },
210
+ "Nigeria": {
211
+ "elo": 1764.3,
212
+ "recent_points": 2.0,
213
+ "avg_scored": 2.0,
214
+ "avg_conceded": 1.6,
215
+ "rolling_gd": 0.4,
216
+ "matches_played": 263
217
+ },
218
+ "Philippines": {
219
+ "elo": 1434.2,
220
+ "recent_points": 1.4,
221
+ "avg_scored": 1.6,
222
+ "avg_conceded": 1.6,
223
+ "rolling_gd": 0.0,
224
+ "matches_played": 161
225
+ },
226
+ "Zambia": {
227
+ "elo": 1524.9,
228
+ "recent_points": 1.0,
229
+ "avg_scored": 1.4,
230
+ "avg_conceded": 2.2,
231
+ "rolling_gd": -0.8,
232
+ "matches_played": 305
233
+ },
234
+ "South Africa": {
235
+ "elo": 1550.1,
236
+ "recent_points": 1.2,
237
+ "avg_scored": 1.0,
238
+ "avg_conceded": 1.8,
239
+ "rolling_gd": -0.8,
240
+ "matches_played": 292
241
+ },
242
+ "Vietnam": {
243
+ "elo": 1649.2,
244
+ "recent_points": 2.2,
245
+ "avg_scored": 1.0,
246
+ "avg_conceded": 0.2,
247
+ "rolling_gd": 0.8,
248
+ "matches_played": 167
249
+ },
250
+ "Guam": {
251
+ "elo": 1077.7,
252
+ "recent_points": 0.0,
253
+ "avg_scored": 0.4,
254
+ "avg_conceded": 3.8,
255
+ "rolling_gd": -3.4,
256
+ "matches_played": 79
257
+ },
258
+ "DR Congo": {
259
+ "elo": 1599.2,
260
+ "recent_points": 1.2,
261
+ "avg_scored": 1.6,
262
+ "avg_conceded": 1.4,
263
+ "rolling_gd": 0.2,
264
+ "matches_played": 214
265
+ },
266
+ "Bosnia and Herzegovina": {
267
+ "elo": 1570.1,
268
+ "recent_points": 1.2,
269
+ "avg_scored": 2.0,
270
+ "avg_conceded": 2.0,
271
+ "rolling_gd": 0.0,
272
+ "matches_played": 186
273
+ },
274
+ "Congo": {
275
+ "elo": 1533.8,
276
+ "recent_points": 1.6,
277
+ "avg_scored": 1.4,
278
+ "avg_conceded": 1.0,
279
+ "rolling_gd": 0.4,
280
+ "matches_played": 157
281
+ },
282
+ "Uganda": {
283
+ "elo": 1598.6,
284
+ "recent_points": 2.6,
285
+ "avg_scored": 1.8,
286
+ "avg_conceded": 0.0,
287
+ "rolling_gd": 1.8,
288
+ "matches_played": 288
289
+ },
290
+ "Libya": {
291
+ "elo": 1508.9,
292
+ "recent_points": 1.0,
293
+ "avg_scored": 1.0,
294
+ "avg_conceded": 1.6,
295
+ "rolling_gd": -0.6,
296
+ "matches_played": 193
297
+ },
298
+ "Spain": {
299
+ "elo": 1975.2,
300
+ "recent_points": 2.2,
301
+ "avg_scored": 3.6,
302
+ "avg_conceded": 0.4,
303
+ "rolling_gd": 3.2,
304
+ "matches_played": 262
305
+ },
306
+ "Poland": {
307
+ "elo": 1818.4,
308
+ "recent_points": 2.6,
309
+ "avg_scored": 2.0,
310
+ "avg_conceded": 0.6,
311
+ "rolling_gd": 1.4,
312
+ "matches_played": 251
313
+ },
314
+ "Costa Rica": {
315
+ "elo": 1703.1,
316
+ "recent_points": 1.2,
317
+ "avg_scored": 0.8,
318
+ "avg_conceded": 0.8,
319
+ "rolling_gd": 0.0,
320
+ "matches_played": 312
321
+ },
322
+ "U.S. Virgin Islands": {
323
+ "elo": 1116.9,
324
+ "recent_points": 0.6,
325
+ "avg_scored": 0.6,
326
+ "avg_conceded": 1.8,
327
+ "rolling_gd": -1.2,
328
+ "matches_played": 51
329
+ },
330
+ "Saint Lucia": {
331
+ "elo": 1313.8,
332
+ "recent_points": 0.8,
333
+ "avg_scored": 0.4,
334
+ "avg_conceded": 1.4,
335
+ "rolling_gd": -1.0,
336
+ "matches_played": 99
337
+ },
338
+ "Chile": {
339
+ "elo": 1774.1,
340
+ "recent_points": 1.0,
341
+ "avg_scored": 1.0,
342
+ "avg_conceded": 1.2,
343
+ "rolling_gd": -0.2,
344
+ "matches_played": 257
345
+ },
346
+ "Faroe Islands": {
347
+ "elo": 1233.6,
348
+ "recent_points": 0.6,
349
+ "avg_scored": 0.2,
350
+ "avg_conceded": 2.8,
351
+ "rolling_gd": -2.6,
352
+ "matches_played": 137
353
+ },
354
+ "Finland": {
355
+ "elo": 1604.1,
356
+ "recent_points": 1.2,
357
+ "avg_scored": 1.8,
358
+ "avg_conceded": 1.6,
359
+ "rolling_gd": 0.2,
360
+ "matches_played": 223
361
+ },
362
+ "Kuwait": {
363
+ "elo": 1542.8,
364
+ "recent_points": 1.8,
365
+ "avg_scored": 3.2,
366
+ "avg_conceded": 1.4,
367
+ "rolling_gd": 1.8,
368
+ "matches_played": 275
369
+ },
370
+ "Syria": {
371
+ "elo": 1703.5,
372
+ "recent_points": 3.0,
373
+ "avg_scored": 2.8,
374
+ "avg_conceded": 0.8,
375
+ "rolling_gd": 2.0,
376
+ "matches_played": 250
377
+ },
378
+ "Iceland": {
379
+ "elo": 1722.7,
380
+ "recent_points": 2.6,
381
+ "avg_scored": 1.2,
382
+ "avg_conceded": 0.2,
383
+ "rolling_gd": 1.0,
384
+ "matches_played": 205
385
+ },
386
+ "Norway": {
387
+ "elo": 1738.6,
388
+ "recent_points": 1.8,
389
+ "avg_scored": 1.8,
390
+ "avg_conceded": 0.8,
391
+ "rolling_gd": 1.0,
392
+ "matches_played": 218
393
+ },
394
+ "British Virgin Islands": {
395
+ "elo": 1055.5,
396
+ "recent_points": 0.0,
397
+ "avg_scored": 1.2,
398
+ "avg_conceded": 3.4,
399
+ "rolling_gd": -2.2,
400
+ "matches_played": 63
401
+ },
402
+ "Moldova": {
403
+ "elo": 1178.6,
404
+ "recent_points": 0.0,
405
+ "avg_scored": 0.4,
406
+ "avg_conceded": 2.0,
407
+ "rolling_gd": -1.6,
408
+ "matches_played": 186
409
+ },
410
+ "Cyprus": {
411
+ "elo": 1403.5,
412
+ "recent_points": 1.2,
413
+ "avg_scored": 1.6,
414
+ "avg_conceded": 2.8,
415
+ "rolling_gd": -1.2,
416
+ "matches_played": 167
417
+ },
418
+ "Lithuania": {
419
+ "elo": 1277.3,
420
+ "recent_points": 0.6,
421
+ "avg_scored": 0.6,
422
+ "avg_conceded": 3.0,
423
+ "rolling_gd": -2.4,
424
+ "matches_played": 186
425
+ },
426
+ "Romania": {
427
+ "elo": 1644.7,
428
+ "recent_points": 1.4,
429
+ "avg_scored": 1.0,
430
+ "avg_conceded": 1.6,
431
+ "rolling_gd": -0.6,
432
+ "matches_played": 214
433
+ },
434
+ "Latvia": {
435
+ "elo": 1260.9,
436
+ "recent_points": 0.6,
437
+ "avg_scored": 0.4,
438
+ "avg_conceded": 1.8,
439
+ "rolling_gd": -1.4,
440
+ "matches_played": 205
441
+ },
442
+ "Saint Kitts and Nevis": {
443
+ "elo": 1393.4,
444
+ "recent_points": 1.0,
445
+ "avg_scored": 1.4,
446
+ "avg_conceded": 1.2,
447
+ "rolling_gd": 0.2,
448
+ "matches_played": 115
449
+ },
450
+ "Georgia": {
451
+ "elo": 1557.5,
452
+ "recent_points": 1.0,
453
+ "avg_scored": 0.8,
454
+ "avg_conceded": 1.0,
455
+ "rolling_gd": -0.2,
456
+ "matches_played": 183
457
+ },
458
+ "Sweden": {
459
+ "elo": 1861.6,
460
+ "recent_points": 2.6,
461
+ "avg_scored": 1.6,
462
+ "avg_conceded": 0.2,
463
+ "rolling_gd": 1.4,
464
+ "matches_played": 270
465
+ },
466
+ "Japan": {
467
+ "elo": 1851.8,
468
+ "recent_points": 2.4,
469
+ "avg_scored": 2.4,
470
+ "avg_conceded": 0.4,
471
+ "rolling_gd": 2.0,
472
+ "matches_played": 320
473
+ },
474
+ "Azerbaijan": {
475
+ "elo": 1336.9,
476
+ "recent_points": 0.8,
477
+ "avg_scored": 0.8,
478
+ "avg_conceded": 1.6,
479
+ "rolling_gd": -0.8,
480
+ "matches_played": 194
481
+ },
482
+ "Cayman Islands": {
483
+ "elo": 1249.1,
484
+ "recent_points": 1.8,
485
+ "avg_scored": 1.0,
486
+ "avg_conceded": 1.6,
487
+ "rolling_gd": -0.6,
488
+ "matches_played": 50
489
+ },
490
+ "Albania": {
491
+ "elo": 1513.6,
492
+ "recent_points": 1.4,
493
+ "avg_scored": 2.0,
494
+ "avg_conceded": 1.4,
495
+ "rolling_gd": 0.6,
496
+ "matches_played": 182
497
+ },
498
+ "Andorra": {
499
+ "elo": 1184.4,
500
+ "recent_points": 0.8,
501
+ "avg_scored": 0.6,
502
+ "avg_conceded": 1.8,
503
+ "rolling_gd": -1.2,
504
+ "matches_played": 145
505
+ },
506
+ "Singapore": {
507
+ "elo": 1430.4,
508
+ "recent_points": 0.8,
509
+ "avg_scored": 0.6,
510
+ "avg_conceded": 1.8,
511
+ "rolling_gd": -1.2,
512
+ "matches_played": 242
513
+ },
514
+ "Malaysia": {
515
+ "elo": 1545.9,
516
+ "recent_points": 2.4,
517
+ "avg_scored": 2.2,
518
+ "avg_conceded": 0.4,
519
+ "rolling_gd": 1.8,
520
+ "matches_played": 232
521
+ },
522
+ "North Korea": {
523
+ "elo": 1543.0,
524
+ "recent_points": 1.6,
525
+ "avg_scored": 0.8,
526
+ "avg_conceded": 0.6,
527
+ "rolling_gd": 0.2,
528
+ "matches_played": 210
529
+ },
530
+ "Czech Republic": {
531
+ "elo": 1703.6,
532
+ "recent_points": 1.8,
533
+ "avg_scored": 1.8,
534
+ "avg_conceded": 1.2,
535
+ "rolling_gd": 0.6,
536
+ "matches_played": 220
537
+ },
538
+ "Bulgaria": {
539
+ "elo": 1545.0,
540
+ "recent_points": 0.8,
541
+ "avg_scored": 0.4,
542
+ "avg_conceded": 2.0,
543
+ "rolling_gd": -1.6,
544
+ "matches_played": 184
545
+ },
546
+ "Slovakia": {
547
+ "elo": 1688.5,
548
+ "recent_points": 1.6,
549
+ "avg_scored": 1.4,
550
+ "avg_conceded": 1.2,
551
+ "rolling_gd": 0.2,
552
+ "matches_played": 211
553
+ },
554
+ "Australia": {
555
+ "elo": 1786.7,
556
+ "recent_points": 2.4,
557
+ "avg_scored": 3.2,
558
+ "avg_conceded": 0.4,
559
+ "rolling_gd": 2.8,
560
+ "matches_played": 235
561
+ },
562
+ "Honduras": {
563
+ "elo": 1698.7,
564
+ "recent_points": 2.6,
565
+ "avg_scored": 2.0,
566
+ "avg_conceded": 0.4,
567
+ "rolling_gd": 1.6,
568
+ "matches_played": 288
569
+ },
570
+ "El Salvador": {
571
+ "elo": 1603.5,
572
+ "recent_points": 2.4,
573
+ "avg_scored": 1.4,
574
+ "avg_conceded": 0.2,
575
+ "rolling_gd": 1.2,
576
+ "matches_played": 221
577
+ },
578
+ "Hong Kong": {
579
+ "elo": 1419.5,
580
+ "recent_points": 0.8,
581
+ "avg_scored": 0.4,
582
+ "avg_conceded": 1.8,
583
+ "rolling_gd": -1.4,
584
+ "matches_played": 155
585
+ },
586
+ "Turkmenistan": {
587
+ "elo": 1479.0,
588
+ "recent_points": 1.4,
589
+ "avg_scored": 1.4,
590
+ "avg_conceded": 1.2,
591
+ "rolling_gd": 0.2,
592
+ "matches_played": 105
593
+ },
594
+ "Nepal": {
595
+ "elo": 1205.5,
596
+ "recent_points": 0.6,
597
+ "avg_scored": 0.4,
598
+ "avg_conceded": 3.2,
599
+ "rolling_gd": -2.8,
600
+ "matches_played": 118
601
+ },
602
+ "Yemen": {
603
+ "elo": 1385.8,
604
+ "recent_points": 0.8,
605
+ "avg_scored": 0.4,
606
+ "avg_conceded": 2.2,
607
+ "rolling_gd": -1.8,
608
+ "matches_played": 171
609
+ },
610
+ "Haiti": {
611
+ "elo": 1677.8,
612
+ "recent_points": 0.6,
613
+ "avg_scored": 0.8,
614
+ "avg_conceded": 1.4,
615
+ "rolling_gd": -0.6,
616
+ "matches_played": 203
617
+ },
618
+ "Bhutan": {
619
+ "elo": 1001.5,
620
+ "recent_points": 0.6,
621
+ "avg_scored": 0.4,
622
+ "avg_conceded": 2.8,
623
+ "rolling_gd": -2.4,
624
+ "matches_played": 79
625
+ },
626
+ "Colombia": {
627
+ "elo": 1948.5,
628
+ "recent_points": 1.6,
629
+ "avg_scored": 0.4,
630
+ "avg_conceded": 0.6,
631
+ "rolling_gd": -0.2,
632
+ "matches_played": 248
633
+ },
634
+ "Dominican Republic": {
635
+ "elo": 1401.8,
636
+ "recent_points": 1.4,
637
+ "avg_scored": 0.8,
638
+ "avg_conceded": 0.6,
639
+ "rolling_gd": 0.2,
640
+ "matches_played": 79
641
+ },
642
+ "Macau": {
643
+ "elo": 1051.3,
644
+ "recent_points": 1.4,
645
+ "avg_scored": 1.0,
646
+ "avg_conceded": 1.6,
647
+ "rolling_gd": -0.6,
648
+ "matches_played": 83
649
+ },
650
+ "Brunei": {
651
+ "elo": 1095.1,
652
+ "recent_points": 1.2,
653
+ "avg_scored": 0.8,
654
+ "avg_conceded": 2.0,
655
+ "rolling_gd": -1.2,
656
+ "matches_played": 47
657
+ },
658
+ "Peru": {
659
+ "elo": 1830.1,
660
+ "recent_points": 0.8,
661
+ "avg_scored": 0.4,
662
+ "avg_conceded": 0.8,
663
+ "rolling_gd": -0.4,
664
+ "matches_played": 217
665
+ },
666
+ "Maldives": {
667
+ "elo": 1267.1,
668
+ "recent_points": 1.2,
669
+ "avg_scored": 1.2,
670
+ "avg_conceded": 2.0,
671
+ "rolling_gd": -0.8,
672
+ "matches_played": 138
673
+ },
674
+ "Lebanon": {
675
+ "elo": 1587.0,
676
+ "recent_points": 1.6,
677
+ "avg_scored": 1.0,
678
+ "avg_conceded": 0.4,
679
+ "rolling_gd": 0.6,
680
+ "matches_played": 190
681
+ },
682
+ "Barbados": {
683
+ "elo": 1294.1,
684
+ "recent_points": 1.2,
685
+ "avg_scored": 1.8,
686
+ "avg_conceded": 1.8,
687
+ "rolling_gd": 0.0,
688
+ "matches_played": 131
689
+ },
690
+ "Dominica": {
691
+ "elo": 1277.3,
692
+ "recent_points": 0.6,
693
+ "avg_scored": 0.4,
694
+ "avg_conceded": 2.4,
695
+ "rolling_gd": -2.0,
696
+ "matches_played": 79
697
+ },
698
+ "Antigua and Barbuda": {
699
+ "elo": 1412.0,
700
+ "recent_points": 1.2,
701
+ "avg_scored": 1.2,
702
+ "avg_conceded": 3.6,
703
+ "rolling_gd": -2.4,
704
+ "matches_played": 117
705
+ },
706
+ "Oman": {
707
+ "elo": 1652.1,
708
+ "recent_points": 2.0,
709
+ "avg_scored": 1.6,
710
+ "avg_conceded": 1.0,
711
+ "rolling_gd": 0.6,
712
+ "matches_played": 303
713
+ },
714
+ "Switzerland": {
715
+ "elo": 1873.3,
716
+ "recent_points": 2.4,
717
+ "avg_scored": 2.6,
718
+ "avg_conceded": 0.4,
719
+ "rolling_gd": 2.2,
720
+ "matches_played": 208
721
+ },
722
+ "United Arab Emirates": {
723
+ "elo": 1596.4,
724
+ "recent_points": 0.6,
725
+ "avg_scored": 1.2,
726
+ "avg_conceded": 1.8,
727
+ "rolling_gd": -0.6,
728
+ "matches_played": 281
729
+ },
730
+ "Slovenia": {
731
+ "elo": 1529.8,
732
+ "recent_points": 1.2,
733
+ "avg_scored": 1.4,
734
+ "avg_conceded": 1.6,
735
+ "rolling_gd": -0.2,
736
+ "matches_played": 188
737
+ },
738
+ "Thailand": {
739
+ "elo": 1574.1,
740
+ "recent_points": 1.6,
741
+ "avg_scored": 1.4,
742
+ "avg_conceded": 0.8,
743
+ "rolling_gd": 0.6,
744
+ "matches_played": 262
745
+ },
746
+ "Kernow": {
747
+ "elo": 1546.7,
748
+ "recent_points": 2.6,
749
+ "avg_scored": 2.8,
750
+ "avg_conceded": 0.8,
751
+ "rolling_gd": 2.0,
752
+ "matches_played": 7
753
+ },
754
+ "Guernsey": {
755
+ "elo": 1695.4,
756
+ "recent_points": 2.4,
757
+ "avg_scored": 3.2,
758
+ "avg_conceded": 1.0,
759
+ "rolling_gd": 2.2,
760
+ "matches_played": 51
761
+ },
762
+ "Lesotho": {
763
+ "elo": 1420.2,
764
+ "recent_points": 0.6,
765
+ "avg_scored": 1.0,
766
+ "avg_conceded": 1.8,
767
+ "rolling_gd": -0.8,
768
+ "matches_played": 183
769
+ },
770
+ "Eswatini": {
771
+ "elo": 1242.3,
772
+ "recent_points": 0.4,
773
+ "avg_scored": 0.6,
774
+ "avg_conceded": 2.0,
775
+ "rolling_gd": -1.4,
776
+ "matches_played": 168
777
+ },
778
+ "Turkey": {
779
+ "elo": 1802.5,
780
+ "recent_points": 2.2,
781
+ "avg_scored": 1.6,
782
+ "avg_conceded": 0.2,
783
+ "rolling_gd": 1.4,
784
+ "matches_played": 238
785
+ },
786
+ "Brazil": {
787
+ "elo": 2043.9,
788
+ "recent_points": 1.2,
789
+ "avg_scored": 1.4,
790
+ "avg_conceded": 1.0,
791
+ "rolling_gd": 0.4,
792
+ "matches_played": 293
793
+ },
794
+ "Wales": {
795
+ "elo": 1770.3,
796
+ "recent_points": 2.2,
797
+ "avg_scored": 1.4,
798
+ "avg_conceded": 0.4,
799
+ "rolling_gd": 1.0,
800
+ "matches_played": 173
801
+ },
802
+ "North Macedonia": {
803
+ "elo": 1574.2,
804
+ "recent_points": 1.8,
805
+ "avg_scored": 1.2,
806
+ "avg_conceded": 1.0,
807
+ "rolling_gd": 0.2,
808
+ "matches_played": 189
809
+ },
810
+ "Serbia": {
811
+ "elo": 1792.5,
812
+ "recent_points": 2.6,
813
+ "avg_scored": 2.2,
814
+ "avg_conceded": 1.2,
815
+ "rolling_gd": 1.0,
816
+ "matches_played": 222
817
+ },
818
+ "Luxembourg": {
819
+ "elo": 1366.5,
820
+ "recent_points": 0.0,
821
+ "avg_scored": 0.6,
822
+ "avg_conceded": 3.0,
823
+ "rolling_gd": -2.4,
824
+ "matches_played": 178
825
+ },
826
+ "Northern Ireland": {
827
+ "elo": 1679.5,
828
+ "recent_points": 0.8,
829
+ "avg_scored": 1.0,
830
+ "avg_conceded": 2.6,
831
+ "rolling_gd": -1.6,
832
+ "matches_played": 172
833
+ },
834
+ "Jordan": {
835
+ "elo": 1610.4,
836
+ "recent_points": 1.6,
837
+ "avg_scored": 1.6,
838
+ "avg_conceded": 0.2,
839
+ "rolling_gd": 1.4,
840
+ "matches_played": 292
841
+ },
842
+ "Italy": {
843
+ "elo": 1955.6,
844
+ "recent_points": 3.0,
845
+ "avg_scored": 4.2,
846
+ "avg_conceded": 0.4,
847
+ "rolling_gd": 3.8,
848
+ "matches_played": 252
849
+ },
850
+ "Netherlands": {
851
+ "elo": 1925.4,
852
+ "recent_points": 2.6,
853
+ "avg_scored": 2.8,
854
+ "avg_conceded": 0.4,
855
+ "rolling_gd": 2.4,
856
+ "matches_played": 243
857
+ },
858
+ "Germany": {
859
+ "elo": 1941.7,
860
+ "recent_points": 2.6,
861
+ "avg_scored": 3.4,
862
+ "avg_conceded": 0.6,
863
+ "rolling_gd": 2.8,
864
+ "matches_played": 276
865
+ },
866
+ "Republic of Ireland": {
867
+ "elo": 1736.7,
868
+ "recent_points": 1.6,
869
+ "avg_scored": 1.4,
870
+ "avg_conceded": 1.0,
871
+ "rolling_gd": 0.4,
872
+ "matches_played": 215
873
+ },
874
+ "Hungary": {
875
+ "elo": 1602.7,
876
+ "recent_points": 0.6,
877
+ "avg_scored": 0.6,
878
+ "avg_conceded": 1.8,
879
+ "rolling_gd": -1.2,
880
+ "matches_played": 202
881
+ },
882
+ "Greece": {
883
+ "elo": 1632.1,
884
+ "recent_points": 2.0,
885
+ "avg_scored": 1.2,
886
+ "avg_conceded": 1.0,
887
+ "rolling_gd": 0.2,
888
+ "matches_played": 220
889
+ },
890
+ "Austria": {
891
+ "elo": 1688.0,
892
+ "recent_points": 2.0,
893
+ "avg_scored": 1.2,
894
+ "avg_conceded": 0.6,
895
+ "rolling_gd": 0.6,
896
+ "matches_played": 185
897
+ },
898
+ "France": {
899
+ "elo": 2012.3,
900
+ "recent_points": 2.6,
901
+ "avg_scored": 1.8,
902
+ "avg_conceded": 0.4,
903
+ "rolling_gd": 1.4,
904
+ "matches_played": 271
905
+ },
906
+ "Israel": {
907
+ "elo": 1443.0,
908
+ "recent_points": 0.6,
909
+ "avg_scored": 1.4,
910
+ "avg_conceded": 2.0,
911
+ "rolling_gd": -0.6,
912
+ "matches_played": 160
913
+ },
914
+ "Russia": {
915
+ "elo": 1847.9,
916
+ "recent_points": 2.4,
917
+ "avg_scored": 3.2,
918
+ "avg_conceded": 0.8,
919
+ "rolling_gd": 2.4,
920
+ "matches_played": 212
921
+ },
922
+ "Estonia": {
923
+ "elo": 1373.9,
924
+ "recent_points": 0.2,
925
+ "avg_scored": 0.0,
926
+ "avg_conceded": 2.6,
927
+ "rolling_gd": -2.6,
928
+ "matches_played": 251
929
+ },
930
+ "England": {
931
+ "elo": 1906.0,
932
+ "recent_points": 2.4,
933
+ "avg_scored": 4.6,
934
+ "avg_conceded": 1.0,
935
+ "rolling_gd": 3.6,
936
+ "matches_played": 237
937
+ },
938
+ "Argentina": {
939
+ "elo": 1894.4,
940
+ "recent_points": 1.8,
941
+ "avg_scored": 2.8,
942
+ "avg_conceded": 1.0,
943
+ "rolling_gd": 1.8,
944
+ "matches_played": 259
945
+ },
946
+ "Croatia": {
947
+ "elo": 1876.2,
948
+ "recent_points": 2.2,
949
+ "avg_scored": 2.0,
950
+ "avg_conceded": 0.8,
951
+ "rolling_gd": 1.2,
952
+ "matches_played": 228
953
+ },
954
+ "Belgium": {
955
+ "elo": 2115.4,
956
+ "recent_points": 3.0,
957
+ "avg_scored": 5.0,
958
+ "avg_conceded": 0.4,
959
+ "rolling_gd": 4.6,
960
+ "matches_played": 211
961
+ },
962
+ "Portugal": {
963
+ "elo": 1929.9,
964
+ "recent_points": 2.4,
965
+ "avg_scored": 3.4,
966
+ "avg_conceded": 0.6,
967
+ "rolling_gd": 2.8,
968
+ "matches_played": 255
969
+ },
970
+ "Anguilla": {
971
+ "elo": 1065.8,
972
+ "recent_points": 0.0,
973
+ "avg_scored": 0.4,
974
+ "avg_conceded": 7.2,
975
+ "rolling_gd": -6.8,
976
+ "matches_played": 43
977
+ },
978
+ "Botswana": {
979
+ "elo": 1401.8,
980
+ "recent_points": 0.4,
981
+ "avg_scored": 0.0,
982
+ "avg_conceded": 0.6,
983
+ "rolling_gd": -0.6,
984
+ "matches_played": 217
985
+ },
986
+ "Uzbekistan": {
987
+ "elo": 1661.7,
988
+ "recent_points": 2.4,
989
+ "avg_scored": 3.0,
990
+ "avg_conceded": 1.0,
991
+ "rolling_gd": 2.0,
992
+ "matches_played": 224
993
+ },
994
+ "Mongolia": {
995
+ "elo": 1154.8,
996
+ "recent_points": 0.2,
997
+ "avg_scored": 0.4,
998
+ "avg_conceded": 2.2,
999
+ "rolling_gd": -1.8,
1000
+ "matches_played": 69
1001
+ },
1002
+ "Cura\u00e7ao": {
1003
+ "elo": 1545.5,
1004
+ "recent_points": 1.0,
1005
+ "avg_scored": 0.6,
1006
+ "avg_conceded": 0.8,
1007
+ "rolling_gd": -0.2,
1008
+ "matches_played": 103
1009
+ },
1010
+ "Nicaragua": {
1011
+ "elo": 1345.5,
1012
+ "recent_points": 0.8,
1013
+ "avg_scored": 1.0,
1014
+ "avg_conceded": 0.8,
1015
+ "rolling_gd": 0.2,
1016
+ "matches_played": 101
1017
+ },
1018
+ "Zimbabwe": {
1019
+ "elo": 1514.7,
1020
+ "recent_points": 2.2,
1021
+ "avg_scored": 1.6,
1022
+ "avg_conceded": 0.6,
1023
+ "rolling_gd": 1.0,
1024
+ "matches_played": 232
1025
+ },
1026
+ "Saint Vincent and the Grenadines": {
1027
+ "elo": 1461.6,
1028
+ "recent_points": 2.0,
1029
+ "avg_scored": 1.0,
1030
+ "avg_conceded": 0.6,
1031
+ "rolling_gd": 0.4,
1032
+ "matches_played": 54
1033
+ },
1034
+ "Suriname": {
1035
+ "elo": 1476.6,
1036
+ "recent_points": 2.0,
1037
+ "avg_scored": 2.8,
1038
+ "avg_conceded": 0.8,
1039
+ "rolling_gd": 2.0,
1040
+ "matches_played": 103
1041
+ },
1042
+ "Belize": {
1043
+ "elo": 1360.2,
1044
+ "recent_points": 1.2,
1045
+ "avg_scored": 1.2,
1046
+ "avg_conceded": 1.8,
1047
+ "rolling_gd": -0.6,
1048
+ "matches_played": 70
1049
+ },
1050
+ "Montserrat": {
1051
+ "elo": 1316.3,
1052
+ "recent_points": 1.0,
1053
+ "avg_scored": 0.4,
1054
+ "avg_conceded": 0.8,
1055
+ "rolling_gd": -0.4,
1056
+ "matches_played": 30
1057
+ },
1058
+ "Bahamas": {
1059
+ "elo": 1357.8,
1060
+ "recent_points": 2.0,
1061
+ "avg_scored": 2.0,
1062
+ "avg_conceded": 1.2,
1063
+ "rolling_gd": 0.8,
1064
+ "matches_played": 29
1065
+ },
1066
+ "Bolivia": {
1067
+ "elo": 1654.2,
1068
+ "recent_points": 0.6,
1069
+ "avg_scored": 1.2,
1070
+ "avg_conceded": 2.8,
1071
+ "rolling_gd": -1.6,
1072
+ "matches_played": 175
1073
+ },
1074
+ "Grenada": {
1075
+ "elo": 1433.6,
1076
+ "recent_points": 2.2,
1077
+ "avg_scored": 1.2,
1078
+ "avg_conceded": 0.6,
1079
+ "rolling_gd": 0.6,
1080
+ "matches_played": 116
1081
+ },
1082
+ "Cuba": {
1083
+ "elo": 1402.9,
1084
+ "recent_points": 0.8,
1085
+ "avg_scored": 0.2,
1086
+ "avg_conceded": 2.4,
1087
+ "rolling_gd": -2.2,
1088
+ "matches_played": 176
1089
+ },
1090
+ "Ethiopia": {
1091
+ "elo": 1457.0,
1092
+ "recent_points": 0.8,
1093
+ "avg_scored": 0.6,
1094
+ "avg_conceded": 1.0,
1095
+ "rolling_gd": -0.4,
1096
+ "matches_played": 172
1097
+ },
1098
+ "Sudan": {
1099
+ "elo": 1428.8,
1100
+ "recent_points": 1.4,
1101
+ "avg_scored": 1.2,
1102
+ "avg_conceded": 0.6,
1103
+ "rolling_gd": 0.6,
1104
+ "matches_played": 224
1105
+ },
1106
+ "Ecuador": {
1107
+ "elo": 1663.6,
1108
+ "recent_points": 1.8,
1109
+ "avg_scored": 1.6,
1110
+ "avg_conceded": 1.4,
1111
+ "rolling_gd": 0.2,
1112
+ "matches_played": 237
1113
+ },
1114
+ "Aruba": {
1115
+ "elo": 1229.5,
1116
+ "recent_points": 0.0,
1117
+ "avg_scored": 1.0,
1118
+ "avg_conceded": 3.4,
1119
+ "rolling_gd": -2.4,
1120
+ "matches_played": 50
1121
+ },
1122
+ "Puerto Rico": {
1123
+ "elo": 1272.3,
1124
+ "recent_points": 1.2,
1125
+ "avg_scored": 1.2,
1126
+ "avg_conceded": 3.2,
1127
+ "rolling_gd": -2.0,
1128
+ "matches_played": 60
1129
+ },
1130
+ "Malawi": {
1131
+ "elo": 1484.8,
1132
+ "recent_points": 1.6,
1133
+ "avg_scored": 0.6,
1134
+ "avg_conceded": 0.6,
1135
+ "rolling_gd": 0.0,
1136
+ "matches_played": 221
1137
+ },
1138
+ "Venezuela": {
1139
+ "elo": 1810.4,
1140
+ "recent_points": 2.0,
1141
+ "avg_scored": 1.8,
1142
+ "avg_conceded": 0.8,
1143
+ "rolling_gd": 1.0,
1144
+ "matches_played": 233
1145
+ },
1146
+ "Turks and Caicos Islands": {
1147
+ "elo": 1267.3,
1148
+ "recent_points": 1.4,
1149
+ "avg_scored": 2.0,
1150
+ "avg_conceded": 3.8,
1151
+ "rolling_gd": -1.8,
1152
+ "matches_played": 25
1153
+ },
1154
+ "Bahrain": {
1155
+ "elo": 1681.8,
1156
+ "recent_points": 1.6,
1157
+ "avg_scored": 1.4,
1158
+ "avg_conceded": 1.2,
1159
+ "rolling_gd": 0.2,
1160
+ "matches_played": 328
1161
+ },
1162
+ "Kazakhstan": {
1163
+ "elo": 1323.0,
1164
+ "recent_points": 0.6,
1165
+ "avg_scored": 1.0,
1166
+ "avg_conceded": 1.8,
1167
+ "rolling_gd": -0.8,
1168
+ "matches_played": 166
1169
+ },
1170
+ "Namibia": {
1171
+ "elo": 1457.7,
1172
+ "recent_points": 1.2,
1173
+ "avg_scored": 0.8,
1174
+ "avg_conceded": 1.2,
1175
+ "rolling_gd": -0.4,
1176
+ "matches_played": 168
1177
+ },
1178
+ "Gambia": {
1179
+ "elo": 1432.1,
1180
+ "recent_points": 1.2,
1181
+ "avg_scored": 1.6,
1182
+ "avg_conceded": 1.4,
1183
+ "rolling_gd": 0.2,
1184
+ "matches_played": 92
1185
+ },
1186
+ "Mauritania": {
1187
+ "elo": 1546.4,
1188
+ "recent_points": 1.2,
1189
+ "avg_scored": 0.4,
1190
+ "avg_conceded": 0.4,
1191
+ "rolling_gd": 0.0,
1192
+ "matches_played": 109
1193
+ },
1194
+ "Tanzania": {
1195
+ "elo": 1428.0,
1196
+ "recent_points": 1.4,
1197
+ "avg_scored": 1.0,
1198
+ "avg_conceded": 1.0,
1199
+ "rolling_gd": 0.0,
1200
+ "matches_played": 228
1201
+ },
1202
+ "Chinese Taipei": {
1203
+ "elo": 1209.9,
1204
+ "recent_points": 0.0,
1205
+ "avg_scored": 0.4,
1206
+ "avg_conceded": 5.0,
1207
+ "rolling_gd": -4.6,
1208
+ "matches_played": 83
1209
+ },
1210
+ "Uruguay": {
1211
+ "elo": 1945.5,
1212
+ "recent_points": 1.8,
1213
+ "avg_scored": 1.4,
1214
+ "avg_conceded": 1.0,
1215
+ "rolling_gd": 0.4,
1216
+ "matches_played": 244
1217
+ },
1218
+ "Scotland": {
1219
+ "elo": 1627.2,
1220
+ "recent_points": 1.8,
1221
+ "avg_scored": 2.2,
1222
+ "avg_conceded": 2.0,
1223
+ "rolling_gd": 0.2,
1224
+ "matches_played": 171
1225
+ },
1226
+ "Denmark": {
1227
+ "elo": 1872.6,
1228
+ "recent_points": 2.2,
1229
+ "avg_scored": 2.4,
1230
+ "avg_conceded": 0.2,
1231
+ "rolling_gd": 2.2,
1232
+ "matches_played": 215
1233
+ },
1234
+ "Paraguay": {
1235
+ "elo": 1746.2,
1236
+ "recent_points": 1.6,
1237
+ "avg_scored": 1.2,
1238
+ "avg_conceded": 0.8,
1239
+ "rolling_gd": 0.4,
1240
+ "matches_played": 239
1241
+ },
1242
+ "Belarus": {
1243
+ "elo": 1424.9,
1244
+ "recent_points": 0.2,
1245
+ "avg_scored": 0.2,
1246
+ "avg_conceded": 1.8,
1247
+ "rolling_gd": -1.6,
1248
+ "matches_played": 189
1249
+ },
1250
+ "Palestine": {
1251
+ "elo": 1453.2,
1252
+ "recent_points": 0.8,
1253
+ "avg_scored": 0.6,
1254
+ "avg_conceded": 1.0,
1255
+ "rolling_gd": -0.4,
1256
+ "matches_played": 159
1257
+ },
1258
+ "Kenya": {
1259
+ "elo": 1490.5,
1260
+ "recent_points": 0.8,
1261
+ "avg_scored": 0.6,
1262
+ "avg_conceded": 0.8,
1263
+ "rolling_gd": -0.2,
1264
+ "matches_played": 250
1265
+ },
1266
+ "Pakistan": {
1267
+ "elo": 1099.9,
1268
+ "recent_points": 0.0,
1269
+ "avg_scored": 0.6,
1270
+ "avg_conceded": 2.2,
1271
+ "rolling_gd": -1.6,
1272
+ "matches_played": 93
1273
+ },
1274
+ "Burma": {
1275
+ "elo": 1374.2,
1276
+ "recent_points": 1.4,
1277
+ "avg_scored": 1.2,
1278
+ "avg_conceded": 1.8,
1279
+ "rolling_gd": -0.6,
1280
+ "matches_played": 146
1281
+ },
1282
+ "Laos": {
1283
+ "elo": 1048.4,
1284
+ "recent_points": 1.0,
1285
+ "avg_scored": 1.0,
1286
+ "avg_conceded": 1.4,
1287
+ "rolling_gd": -0.4,
1288
+ "matches_played": 128
1289
+ },
1290
+ "Djibouti": {
1291
+ "elo": 1198.7,
1292
+ "recent_points": 1.2,
1293
+ "avg_scored": 1.4,
1294
+ "avg_conceded": 1.4,
1295
+ "rolling_gd": 0.0,
1296
+ "matches_played": 65
1297
+ },
1298
+ "Guinea": {
1299
+ "elo": 1545.8,
1300
+ "recent_points": 1.4,
1301
+ "avg_scored": 1.4,
1302
+ "avg_conceded": 1.2,
1303
+ "rolling_gd": 0.2,
1304
+ "matches_played": 181
1305
+ },
1306
+ "S\u00e3o Tom\u00e9 and Pr\u00edncipe": {
1307
+ "elo": 1265.5,
1308
+ "recent_points": 1.2,
1309
+ "avg_scored": 1.2,
1310
+ "avg_conceded": 1.8,
1311
+ "rolling_gd": -0.6,
1312
+ "matches_played": 31
1313
+ },
1314
+ "Sierra Leone": {
1315
+ "elo": 1482.4,
1316
+ "recent_points": 1.0,
1317
+ "avg_scored": 0.6,
1318
+ "avg_conceded": 1.0,
1319
+ "rolling_gd": -0.4,
1320
+ "matches_played": 94
1321
+ },
1322
+ "Seychelles": {
1323
+ "elo": 1048.8,
1324
+ "recent_points": 0.0,
1325
+ "avg_scored": 0.2,
1326
+ "avg_conceded": 3.2,
1327
+ "rolling_gd": -3.0,
1328
+ "matches_played": 90
1329
+ },
1330
+ "Madagascar": {
1331
+ "elo": 1606.1,
1332
+ "recent_points": 1.8,
1333
+ "avg_scored": 2.0,
1334
+ "avg_conceded": 1.4,
1335
+ "rolling_gd": 0.6,
1336
+ "matches_played": 133
1337
+ },
1338
+ "Guinea-Bissau": {
1339
+ "elo": 1446.4,
1340
+ "recent_points": 1.8,
1341
+ "avg_scored": 1.2,
1342
+ "avg_conceded": 1.4,
1343
+ "rolling_gd": -0.2,
1344
+ "matches_played": 64
1345
+ },
1346
+ "Fiji": {
1347
+ "elo": 1481.6,
1348
+ "recent_points": 1.6,
1349
+ "avg_scored": 4.8,
1350
+ "avg_conceded": 1.4,
1351
+ "rolling_gd": 3.4,
1352
+ "matches_played": 90
1353
+ },
1354
+ "Papua New Guinea": {
1355
+ "elo": 1410.4,
1356
+ "recent_points": 2.0,
1357
+ "avg_scored": 3.6,
1358
+ "avg_conceded": 0.6,
1359
+ "rolling_gd": 3.0,
1360
+ "matches_played": 45
1361
+ },
1362
+ "New Caledonia": {
1363
+ "elo": 1637.8,
1364
+ "recent_points": 3.0,
1365
+ "avg_scored": 4.4,
1366
+ "avg_conceded": 0.0,
1367
+ "rolling_gd": 4.4,
1368
+ "matches_played": 94
1369
+ },
1370
+ "Solomon Islands": {
1371
+ "elo": 1500.8,
1372
+ "recent_points": 1.4,
1373
+ "avg_scored": 6.0,
1374
+ "avg_conceded": 1.8,
1375
+ "rolling_gd": 4.2,
1376
+ "matches_played": 94
1377
+ },
1378
+ "Angola": {
1379
+ "elo": 1472.3,
1380
+ "recent_points": 1.4,
1381
+ "avg_scored": 1.2,
1382
+ "avg_conceded": 1.4,
1383
+ "rolling_gd": -0.2,
1384
+ "matches_played": 234
1385
+ },
1386
+ "Mozambique": {
1387
+ "elo": 1524.8,
1388
+ "recent_points": 2.6,
1389
+ "avg_scored": 1.6,
1390
+ "avg_conceded": 0.4,
1391
+ "rolling_gd": 1.2,
1392
+ "matches_played": 169
1393
+ },
1394
+ "Rwanda": {
1395
+ "elo": 1401.7,
1396
+ "recent_points": 1.0,
1397
+ "avg_scored": 0.4,
1398
+ "avg_conceded": 0.8,
1399
+ "rolling_gd": -0.4,
1400
+ "matches_played": 212
1401
+ },
1402
+ "Mali": {
1403
+ "elo": 1617.8,
1404
+ "recent_points": 1.6,
1405
+ "avg_scored": 1.4,
1406
+ "avg_conceded": 0.8,
1407
+ "rolling_gd": 0.6,
1408
+ "matches_played": 209
1409
+ },
1410
+ "Central African Republic": {
1411
+ "elo": 1445.7,
1412
+ "recent_points": 1.2,
1413
+ "avg_scored": 1.0,
1414
+ "avg_conceded": 1.6,
1415
+ "rolling_gd": -0.6,
1416
+ "matches_played": 59
1417
+ },
1418
+ "Eritrea": {
1419
+ "elo": 1195.4,
1420
+ "recent_points": 0.0,
1421
+ "avg_scored": 0.4,
1422
+ "avg_conceded": 2.0,
1423
+ "rolling_gd": -1.6,
1424
+ "matches_played": 59
1425
+ },
1426
+ "Equatorial Guinea": {
1427
+ "elo": 1360.5,
1428
+ "recent_points": 0.4,
1429
+ "avg_scored": 0.8,
1430
+ "avg_conceded": 1.4,
1431
+ "rolling_gd": -0.6,
1432
+ "matches_played": 104
1433
+ },
1434
+ "Chad": {
1435
+ "elo": 1341.8,
1436
+ "recent_points": 0.8,
1437
+ "avg_scored": 0.4,
1438
+ "avg_conceded": 1.0,
1439
+ "rolling_gd": -0.6,
1440
+ "matches_played": 71
1441
+ },
1442
+ "Liberia": {
1443
+ "elo": 1429.7,
1444
+ "recent_points": 0.8,
1445
+ "avg_scored": 0.2,
1446
+ "avg_conceded": 0.6,
1447
+ "rolling_gd": -0.4,
1448
+ "matches_played": 111
1449
+ },
1450
+ "Cape Verde": {
1451
+ "elo": 1477.8,
1452
+ "recent_points": 1.2,
1453
+ "avg_scored": 1.0,
1454
+ "avg_conceded": 1.0,
1455
+ "rolling_gd": 0.0,
1456
+ "matches_played": 114
1457
+ },
1458
+ "Benin": {
1459
+ "elo": 1591.3,
1460
+ "recent_points": 1.4,
1461
+ "avg_scored": 1.2,
1462
+ "avg_conceded": 1.2,
1463
+ "rolling_gd": 0.0,
1464
+ "matches_played": 141
1465
+ },
1466
+ "Vanuatu": {
1467
+ "elo": 1504.6,
1468
+ "recent_points": 1.4,
1469
+ "avg_scored": 5.0,
1470
+ "avg_conceded": 1.6,
1471
+ "rolling_gd": 3.4,
1472
+ "matches_played": 84
1473
+ },
1474
+ "Somalia": {
1475
+ "elo": 1128.3,
1476
+ "recent_points": 0.6,
1477
+ "avg_scored": 0.8,
1478
+ "avg_conceded": 2.4,
1479
+ "rolling_gd": -1.6,
1480
+ "matches_played": 63
1481
+ },
1482
+ "Mauritius": {
1483
+ "elo": 1118.1,
1484
+ "recent_points": 0.0,
1485
+ "avg_scored": 0.6,
1486
+ "avg_conceded": 2.2,
1487
+ "rolling_gd": -1.6,
1488
+ "matches_played": 121
1489
+ },
1490
+ "Liechtenstein": {
1491
+ "elo": 1165.7,
1492
+ "recent_points": 0.4,
1493
+ "avg_scored": 0.4,
1494
+ "avg_conceded": 2.6,
1495
+ "rolling_gd": -2.2,
1496
+ "matches_played": 155
1497
+ },
1498
+ "San Marino": {
1499
+ "elo": 851.8,
1500
+ "recent_points": 0.0,
1501
+ "avg_scored": 0.2,
1502
+ "avg_conceded": 5.4,
1503
+ "rolling_gd": -5.2,
1504
+ "matches_played": 118
1505
+ },
1506
+ "Ukraine": {
1507
+ "elo": 1900.1,
1508
+ "recent_points": 2.2,
1509
+ "avg_scored": 1.8,
1510
+ "avg_conceded": 1.0,
1511
+ "rolling_gd": 0.8,
1512
+ "matches_played": 207
1513
+ },
1514
+ "Sint Maarten": {
1515
+ "elo": 1313.4,
1516
+ "recent_points": 0.6,
1517
+ "avg_scored": 2.0,
1518
+ "avg_conceded": 3.6,
1519
+ "rolling_gd": -1.6,
1520
+ "matches_played": 13
1521
+ },
1522
+ "Jersey": {
1523
+ "elo": 1705.1,
1524
+ "recent_points": 2.4,
1525
+ "avg_scored": 3.6,
1526
+ "avg_conceded": 0.8,
1527
+ "rolling_gd": 2.8,
1528
+ "matches_played": 52
1529
+ },
1530
+ "Sri Lanka": {
1531
+ "elo": 1025.1,
1532
+ "recent_points": 0.0,
1533
+ "avg_scored": 0.0,
1534
+ "avg_conceded": 4.0,
1535
+ "rolling_gd": -4.0,
1536
+ "matches_played": 128
1537
+ },
1538
+ "Bangladesh": {
1539
+ "elo": 1152.1,
1540
+ "recent_points": 1.4,
1541
+ "avg_scored": 1.6,
1542
+ "avg_conceded": 1.6,
1543
+ "rolling_gd": 0.0,
1544
+ "matches_played": 122
1545
+ },
1546
+ "India": {
1547
+ "elo": 1381.2,
1548
+ "recent_points": 0.6,
1549
+ "avg_scored": 0.6,
1550
+ "avg_conceded": 1.0,
1551
+ "rolling_gd": -0.4,
1552
+ "matches_played": 181
1553
+ },
1554
+ "Saudi Arabia": {
1555
+ "elo": 1709.5,
1556
+ "recent_points": 1.8,
1557
+ "avg_scored": 1.4,
1558
+ "avg_conceded": 1.0,
1559
+ "rolling_gd": 0.4,
1560
+ "matches_played": 322
1561
+ },
1562
+ "Kyrgyzstan": {
1563
+ "elo": 1473.7,
1564
+ "recent_points": 1.4,
1565
+ "avg_scored": 2.2,
1566
+ "avg_conceded": 1.4,
1567
+ "rolling_gd": 0.8,
1568
+ "matches_played": 121
1569
+ },
1570
+ "Iraq": {
1571
+ "elo": 1773.7,
1572
+ "recent_points": 1.8,
1573
+ "avg_scored": 1.2,
1574
+ "avg_conceded": 0.6,
1575
+ "rolling_gd": 0.6,
1576
+ "matches_played": 300
1577
+ },
1578
+ "Tonga": {
1579
+ "elo": 1195.2,
1580
+ "recent_points": 0.0,
1581
+ "avg_scored": 0.6,
1582
+ "avg_conceded": 6.4,
1583
+ "rolling_gd": -5.8,
1584
+ "matches_played": 38
1585
+ },
1586
+ "Cook Islands": {
1587
+ "elo": 1254.9,
1588
+ "recent_points": 1.4,
1589
+ "avg_scored": 1.2,
1590
+ "avg_conceded": 1.0,
1591
+ "rolling_gd": 0.2,
1592
+ "matches_played": 28
1593
+ },
1594
+ "American Samoa": {
1595
+ "elo": 1229.0,
1596
+ "recent_points": 0.8,
1597
+ "avg_scored": 1.8,
1598
+ "avg_conceded": 5.8,
1599
+ "rolling_gd": -4.0,
1600
+ "matches_played": 34
1601
+ },
1602
+ "Tahiti": {
1603
+ "elo": 1475.9,
1604
+ "recent_points": 1.2,
1605
+ "avg_scored": 2.4,
1606
+ "avg_conceded": 2.6,
1607
+ "rolling_gd": -0.2,
1608
+ "matches_played": 77
1609
+ },
1610
+ "Burundi": {
1611
+ "elo": 1344.0,
1612
+ "recent_points": 0.2,
1613
+ "avg_scored": 0.2,
1614
+ "avg_conceded": 2.4,
1615
+ "rolling_gd": -2.2,
1616
+ "matches_played": 150
1617
+ },
1618
+ "Niger": {
1619
+ "elo": 1430.2,
1620
+ "recent_points": 0.2,
1621
+ "avg_scored": 0.6,
1622
+ "avg_conceded": 2.2,
1623
+ "rolling_gd": -1.6,
1624
+ "matches_played": 107
1625
+ },
1626
+ "Guyana": {
1627
+ "elo": 1438.1,
1628
+ "recent_points": 1.4,
1629
+ "avg_scored": 2.2,
1630
+ "avg_conceded": 2.0,
1631
+ "rolling_gd": 0.2,
1632
+ "matches_played": 106
1633
+ },
1634
+ "Indonesia": {
1635
+ "elo": 1307.1,
1636
+ "recent_points": 0.0,
1637
+ "avg_scored": 0.6,
1638
+ "avg_conceded": 3.2,
1639
+ "rolling_gd": -2.6,
1640
+ "matches_played": 179
1641
+ },
1642
+ "Zanzibar": {
1643
+ "elo": 1508.5,
1644
+ "recent_points": 1.6,
1645
+ "avg_scored": 1.2,
1646
+ "avg_conceded": 1.0,
1647
+ "rolling_gd": 0.2,
1648
+ "matches_played": 77
1649
+ },
1650
+ "Cambodia": {
1651
+ "elo": 1207.1,
1652
+ "recent_points": 0.2,
1653
+ "avg_scored": 0.2,
1654
+ "avg_conceded": 4.4,
1655
+ "rolling_gd": -4.2,
1656
+ "matches_played": 133
1657
+ },
1658
+ "Tajikistan": {
1659
+ "elo": 1396.3,
1660
+ "recent_points": 0.8,
1661
+ "avg_scored": 1.0,
1662
+ "avg_conceded": 1.8,
1663
+ "rolling_gd": -0.8,
1664
+ "matches_played": 122
1665
+ },
1666
+ "Andalusia": {
1667
+ "elo": 1575.3,
1668
+ "recent_points": 2.6,
1669
+ "avg_scored": 2.2,
1670
+ "avg_conceded": 0.6,
1671
+ "rolling_gd": 1.6,
1672
+ "matches_played": 9
1673
+ },
1674
+ "Catalonia": {
1675
+ "elo": 1588.6,
1676
+ "recent_points": 1.2,
1677
+ "avg_scored": 1.8,
1678
+ "avg_conceded": 1.4,
1679
+ "rolling_gd": 0.4,
1680
+ "matches_played": 21
1681
+ },
1682
+ "Basque Country": {
1683
+ "elo": 1626.4,
1684
+ "recent_points": 2.2,
1685
+ "avg_scored": 1.8,
1686
+ "avg_conceded": 0.8,
1687
+ "rolling_gd": 1.0,
1688
+ "matches_played": 22
1689
+ },
1690
+ "Saint Martin": {
1691
+ "elo": 1230.9,
1692
+ "recent_points": 1.8,
1693
+ "avg_scored": 1.4,
1694
+ "avg_conceded": 0.8,
1695
+ "rolling_gd": 0.6,
1696
+ "matches_played": 40
1697
+ },
1698
+ "Martinique": {
1699
+ "elo": 1550.0,
1700
+ "recent_points": 0.6,
1701
+ "avg_scored": 1.2,
1702
+ "avg_conceded": 1.6,
1703
+ "rolling_gd": -0.4,
1704
+ "matches_played": 131
1705
+ },
1706
+ "Guadeloupe": {
1707
+ "elo": 1477.1,
1708
+ "recent_points": 2.4,
1709
+ "avg_scored": 4.0,
1710
+ "avg_conceded": 0.6,
1711
+ "rolling_gd": 3.4,
1712
+ "matches_played": 108
1713
+ },
1714
+ "Samoa": {
1715
+ "elo": 1302.9,
1716
+ "recent_points": 0.6,
1717
+ "avg_scored": 0.4,
1718
+ "avg_conceded": 6.4,
1719
+ "rolling_gd": -6.0,
1720
+ "matches_played": 35
1721
+ },
1722
+ "Greenland": {
1723
+ "elo": 1518.3,
1724
+ "recent_points": 1.6,
1725
+ "avg_scored": 1.4,
1726
+ "avg_conceded": 1.8,
1727
+ "rolling_gd": -0.4,
1728
+ "matches_played": 41
1729
+ },
1730
+ "Tibet": {
1731
+ "elo": 1352.8,
1732
+ "recent_points": 0.2,
1733
+ "avg_scored": 0.8,
1734
+ "avg_conceded": 4.0,
1735
+ "rolling_gd": -3.2,
1736
+ "matches_played": 13
1737
+ },
1738
+ "Isle of Man": {
1739
+ "elo": 1685.2,
1740
+ "recent_points": 2.4,
1741
+ "avg_scored": 5.2,
1742
+ "avg_conceded": 1.0,
1743
+ "rolling_gd": 4.2,
1744
+ "matches_played": 36
1745
+ },
1746
+ "Falkland Islands": {
1747
+ "elo": 1301.8,
1748
+ "recent_points": 0.0,
1749
+ "avg_scored": 0.8,
1750
+ "avg_conceded": 3.0,
1751
+ "rolling_gd": -2.2,
1752
+ "matches_played": 29
1753
+ },
1754
+ "Isle of Wight": {
1755
+ "elo": 1572.5,
1756
+ "recent_points": 2.0,
1757
+ "avg_scored": 2.2,
1758
+ "avg_conceded": 1.0,
1759
+ "rolling_gd": 1.2,
1760
+ "matches_played": 22
1761
+ },
1762
+ "Ynys M\u00f4n": {
1763
+ "elo": 1611.2,
1764
+ "recent_points": 3.0,
1765
+ "avg_scored": 2.0,
1766
+ "avg_conceded": 0.8,
1767
+ "rolling_gd": 1.2,
1768
+ "matches_played": 37
1769
+ },
1770
+ "Saare County": {
1771
+ "elo": 1375.5,
1772
+ "recent_points": 1.6,
1773
+ "avg_scored": 2.4,
1774
+ "avg_conceded": 2.0,
1775
+ "rolling_gd": 0.4,
1776
+ "matches_played": 31
1777
+ },
1778
+ "Orkney": {
1779
+ "elo": 1387.2,
1780
+ "recent_points": 1.2,
1781
+ "avg_scored": 1.4,
1782
+ "avg_conceded": 2.4,
1783
+ "rolling_gd": -1.0,
1784
+ "matches_played": 21
1785
+ },
1786
+ "Shetland": {
1787
+ "elo": 1451.7,
1788
+ "recent_points": 0.6,
1789
+ "avg_scored": 1.8,
1790
+ "avg_conceded": 2.6,
1791
+ "rolling_gd": -0.8,
1792
+ "matches_played": 30
1793
+ },
1794
+ "Gibraltar": {
1795
+ "elo": 1147.8,
1796
+ "recent_points": 0.0,
1797
+ "avg_scored": 0.6,
1798
+ "avg_conceded": 4.0,
1799
+ "rolling_gd": -3.4,
1800
+ "matches_played": 79
1801
+ },
1802
+ "Rhodes": {
1803
+ "elo": 1567.0,
1804
+ "recent_points": 1.8,
1805
+ "avg_scored": 1.8,
1806
+ "avg_conceded": 0.8,
1807
+ "rolling_gd": 1.0,
1808
+ "matches_played": 14
1809
+ },
1810
+ "Monaco": {
1811
+ "elo": 1502.2,
1812
+ "recent_points": 2.0,
1813
+ "avg_scored": 1.4,
1814
+ "avg_conceded": 4.4,
1815
+ "rolling_gd": -3.0,
1816
+ "matches_played": 12
1817
+ },
1818
+ "Mayotte": {
1819
+ "elo": 1439.3,
1820
+ "recent_points": 1.2,
1821
+ "avg_scored": 1.0,
1822
+ "avg_conceded": 1.8,
1823
+ "rolling_gd": -0.8,
1824
+ "matches_played": 18
1825
+ },
1826
+ "Canary Islands": {
1827
+ "elo": 1502.2,
1828
+ "recent_points": 1.5,
1829
+ "avg_scored": 1.0,
1830
+ "avg_conceded": 1.0,
1831
+ "rolling_gd": 0.0,
1832
+ "matches_played": 2
1833
+ },
1834
+ "R\u00e9union": {
1835
+ "elo": 1634.1,
1836
+ "recent_points": 2.6,
1837
+ "avg_scored": 3.8,
1838
+ "avg_conceded": 0.8,
1839
+ "rolling_gd": 3.0,
1840
+ "matches_played": 21
1841
+ },
1842
+ "French Guiana": {
1843
+ "elo": 1469.7,
1844
+ "recent_points": 1.0,
1845
+ "avg_scored": 1.0,
1846
+ "avg_conceded": 1.2,
1847
+ "rolling_gd": -0.2,
1848
+ "matches_played": 87
1849
+ },
1850
+ "Vatican City": {
1851
+ "elo": 1458.3,
1852
+ "recent_points": 0.2,
1853
+ "avg_scored": 0.4,
1854
+ "avg_conceded": 3.0,
1855
+ "rolling_gd": -2.6,
1856
+ "matches_played": 6
1857
+ },
1858
+ "Afghanistan": {
1859
+ "elo": 1356.6,
1860
+ "recent_points": 0.8,
1861
+ "avg_scored": 0.4,
1862
+ "avg_conceded": 2.2,
1863
+ "rolling_gd": -1.8,
1864
+ "matches_played": 94
1865
+ },
1866
+ "East Timor": {
1867
+ "elo": 924.2,
1868
+ "recent_points": 0.8,
1869
+ "avg_scored": 0.6,
1870
+ "avg_conceded": 1.8,
1871
+ "rolling_gd": -1.2,
1872
+ "matches_played": 51
1873
+ },
1874
+ "Tuvalu": {
1875
+ "elo": 1266.2,
1876
+ "recent_points": 0.2,
1877
+ "avg_scored": 0.4,
1878
+ "avg_conceded": 8.4,
1879
+ "rolling_gd": -8.0,
1880
+ "matches_played": 29
1881
+ },
1882
+ "Fr\u00f8ya": {
1883
+ "elo": 1306.9,
1884
+ "recent_points": 0.2,
1885
+ "avg_scored": 1.4,
1886
+ "avg_conceded": 4.6,
1887
+ "rolling_gd": -3.2,
1888
+ "matches_played": 20
1889
+ },
1890
+ "Gotland": {
1891
+ "elo": 1412.5,
1892
+ "recent_points": 1.2,
1893
+ "avg_scored": 3.8,
1894
+ "avg_conceded": 1.6,
1895
+ "rolling_gd": 2.2,
1896
+ "matches_played": 25
1897
+ },
1898
+ "Alderney": {
1899
+ "elo": 1340.7,
1900
+ "recent_points": 1.2,
1901
+ "avg_scored": 1.6,
1902
+ "avg_conceded": 3.4,
1903
+ "rolling_gd": -1.8,
1904
+ "matches_played": 19
1905
+ },
1906
+ "Sark": {
1907
+ "elo": 1426.1,
1908
+ "recent_points": 0.0,
1909
+ "avg_scored": 0.0,
1910
+ "avg_conceded": 17.5,
1911
+ "rolling_gd": -17.5,
1912
+ "matches_played": 4
1913
+ },
1914
+ "Kiribati": {
1915
+ "elo": 1359.3,
1916
+ "recent_points": 0.0,
1917
+ "avg_scored": 0.4,
1918
+ "avg_conceded": 12.8,
1919
+ "rolling_gd": -12.4,
1920
+ "matches_played": 8
1921
+ },
1922
+ "Micronesia": {
1923
+ "elo": 1422.6,
1924
+ "recent_points": 0.0,
1925
+ "avg_scored": 0.0,
1926
+ "avg_conceded": 13.0,
1927
+ "rolling_gd": -13.0,
1928
+ "matches_played": 4
1929
+ },
1930
+ "\u00c5land Islands": {
1931
+ "elo": 1534.0,
1932
+ "recent_points": 1.8,
1933
+ "avg_scored": 1.0,
1934
+ "avg_conceded": 0.4,
1935
+ "rolling_gd": 0.6,
1936
+ "matches_played": 26
1937
+ },
1938
+ "Western Isles": {
1939
+ "elo": 1428.5,
1940
+ "recent_points": 0.8,
1941
+ "avg_scored": 1.0,
1942
+ "avg_conceded": 2.6,
1943
+ "rolling_gd": -1.6,
1944
+ "matches_played": 28
1945
+ },
1946
+ "Galicia": {
1947
+ "elo": 1543.7,
1948
+ "recent_points": 1.8,
1949
+ "avg_scored": 1.8,
1950
+ "avg_conceded": 1.4,
1951
+ "rolling_gd": 0.4,
1952
+ "matches_played": 5
1953
+ },
1954
+ "Northern Cyprus": {
1955
+ "elo": 1677.8,
1956
+ "recent_points": 2.2,
1957
+ "avg_scored": 3.2,
1958
+ "avg_conceded": 1.0,
1959
+ "rolling_gd": 2.2,
1960
+ "matches_played": 31
1961
+ },
1962
+ "Kosovo": {
1963
+ "elo": 1595.0,
1964
+ "recent_points": 1.2,
1965
+ "avg_scored": 0.8,
1966
+ "avg_conceded": 1.4,
1967
+ "rolling_gd": -0.6,
1968
+ "matches_played": 39
1969
+ },
1970
+ "Republic of St. Pauli": {
1971
+ "elo": 1478.6,
1972
+ "recent_points": 1.0,
1973
+ "avg_scored": 2.5,
1974
+ "avg_conceded": 1.25,
1975
+ "rolling_gd": 1.25,
1976
+ "matches_played": 4
1977
+ },
1978
+ "G\u0103g\u0103uzia": {
1979
+ "elo": 1454.1,
1980
+ "recent_points": 0.333,
1981
+ "avg_scored": 0.667,
1982
+ "avg_conceded": 3.0,
1983
+ "rolling_gd": -2.333,
1984
+ "matches_played": 3
1985
+ },
1986
+ "Crimea": {
1987
+ "elo": 1521.7,
1988
+ "recent_points": 1.8,
1989
+ "avg_scored": 1.4,
1990
+ "avg_conceded": 2.2,
1991
+ "rolling_gd": -0.8,
1992
+ "matches_played": 5
1993
+ },
1994
+ "Occitania": {
1995
+ "elo": 1553.6,
1996
+ "recent_points": 1.8,
1997
+ "avg_scored": 1.0,
1998
+ "avg_conceded": 0.6,
1999
+ "rolling_gd": 0.4,
2000
+ "matches_played": 18
2001
+ },
2002
+ "S\u00e1pmi": {
2003
+ "elo": 1464.2,
2004
+ "recent_points": 0.6,
2005
+ "avg_scored": 1.0,
2006
+ "avg_conceded": 2.8,
2007
+ "rolling_gd": -1.8,
2008
+ "matches_played": 26
2009
+ },
2010
+ "Silesia": {
2011
+ "elo": 1505.8,
2012
+ "recent_points": 1.0,
2013
+ "avg_scored": 1.0,
2014
+ "avg_conceded": 1.0,
2015
+ "rolling_gd": 0.0,
2016
+ "matches_played": 1
2017
+ },
2018
+ "Comoros": {
2019
+ "elo": 1387.3,
2020
+ "recent_points": 1.6,
2021
+ "avg_scored": 0.6,
2022
+ "avg_conceded": 0.6,
2023
+ "rolling_gd": 0.0,
2024
+ "matches_played": 60
2025
+ },
2026
+ "Montenegro": {
2027
+ "elo": 1458.9,
2028
+ "recent_points": 0.8,
2029
+ "avg_scored": 0.4,
2030
+ "avg_conceded": 2.4,
2031
+ "rolling_gd": -2.0,
2032
+ "matches_played": 104
2033
+ },
2034
+ "Northern Mariana Islands": {
2035
+ "elo": 1102.9,
2036
+ "recent_points": 0.2,
2037
+ "avg_scored": 0.4,
2038
+ "avg_conceded": 5.0,
2039
+ "rolling_gd": -4.6,
2040
+ "matches_played": 21
2041
+ },
2042
+ "Menorca": {
2043
+ "elo": 1578.7,
2044
+ "recent_points": 1.6,
2045
+ "avg_scored": 2.2,
2046
+ "avg_conceded": 1.0,
2047
+ "rolling_gd": 1.2,
2048
+ "matches_played": 21
2049
+ },
2050
+ "Brittany": {
2051
+ "elo": 1513.5,
2052
+ "recent_points": 1.8,
2053
+ "avg_scored": 1.2,
2054
+ "avg_conceded": 1.0,
2055
+ "rolling_gd": 0.2,
2056
+ "matches_played": 5
2057
+ },
2058
+ "Iraqi Kurdistan": {
2059
+ "elo": 1607.2,
2060
+ "recent_points": 1.8,
2061
+ "avg_scored": 1.8,
2062
+ "avg_conceded": 0.6,
2063
+ "rolling_gd": 1.2,
2064
+ "matches_played": 27
2065
+ },
2066
+ "Provence": {
2067
+ "elo": 1429.9,
2068
+ "recent_points": 1.2,
2069
+ "avg_scored": 4.8,
2070
+ "avg_conceded": 2.4,
2071
+ "rolling_gd": 2.4,
2072
+ "matches_played": 15
2073
+ },
2074
+ "Padania": {
2075
+ "elo": 1634.4,
2076
+ "recent_points": 1.4,
2077
+ "avg_scored": 2.0,
2078
+ "avg_conceded": 1.0,
2079
+ "rolling_gd": 1.0,
2080
+ "matches_played": 43
2081
+ },
2082
+ "Arameans Suryoye": {
2083
+ "elo": 1541.2,
2084
+ "recent_points": 2.0,
2085
+ "avg_scored": 1.8,
2086
+ "avg_conceded": 1.2,
2087
+ "rolling_gd": 0.6,
2088
+ "matches_played": 10
2089
+ },
2090
+ "Corsica": {
2091
+ "elo": 1543.6,
2092
+ "recent_points": 1.8,
2093
+ "avg_scored": 1.0,
2094
+ "avg_conceded": 0.6,
2095
+ "rolling_gd": 0.4,
2096
+ "matches_played": 7
2097
+ },
2098
+ "Gozo": {
2099
+ "elo": 1429.7,
2100
+ "recent_points": 0.6,
2101
+ "avg_scored": 1.2,
2102
+ "avg_conceded": 3.4,
2103
+ "rolling_gd": -2.2,
2104
+ "matches_played": 6
2105
+ },
2106
+ "Two Sicilies": {
2107
+ "elo": 1465.4,
2108
+ "recent_points": 0.75,
2109
+ "avg_scored": 0.5,
2110
+ "avg_conceded": 2.0,
2111
+ "rolling_gd": -1.5,
2112
+ "matches_played": 4
2113
+ },
2114
+ "Saint Pierre and Miquelon": {
2115
+ "elo": 1383.5,
2116
+ "recent_points": 0.0,
2117
+ "avg_scored": 0.4,
2118
+ "avg_conceded": 12.0,
2119
+ "rolling_gd": -11.6,
2120
+ "matches_played": 7
2121
+ },
2122
+ "Bonaire": {
2123
+ "elo": 1335.1,
2124
+ "recent_points": 2.0,
2125
+ "avg_scored": 2.4,
2126
+ "avg_conceded": 1.8,
2127
+ "rolling_gd": 0.6,
2128
+ "matches_played": 21
2129
+ },
2130
+ "Darfur": {
2131
+ "elo": 1381.7,
2132
+ "recent_points": 0.0,
2133
+ "avg_scored": 0.2,
2134
+ "avg_conceded": 13.2,
2135
+ "rolling_gd": -13.0,
2136
+ "matches_played": 7
2137
+ },
2138
+ "Raetia": {
2139
+ "elo": 1417.4,
2140
+ "recent_points": 0.2,
2141
+ "avg_scored": 0.6,
2142
+ "avg_conceded": 5.4,
2143
+ "rolling_gd": -4.8,
2144
+ "matches_played": 8
2145
+ },
2146
+ "Western Sahara": {
2147
+ "elo": 1481.7,
2148
+ "recent_points": 1.2,
2149
+ "avg_scored": 2.2,
2150
+ "avg_conceded": 3.2,
2151
+ "rolling_gd": -1.0,
2152
+ "matches_played": 5
2153
+ },
2154
+ "Tamil Eelam": {
2155
+ "elo": 1423.0,
2156
+ "recent_points": 0.6,
2157
+ "avg_scored": 0.8,
2158
+ "avg_conceded": 3.6,
2159
+ "rolling_gd": -2.8,
2160
+ "matches_played": 17
2161
+ },
2162
+ "South Sudan": {
2163
+ "elo": 1226.5,
2164
+ "recent_points": 1.2,
2165
+ "avg_scored": 0.8,
2166
+ "avg_conceded": 1.0,
2167
+ "rolling_gd": -0.2,
2168
+ "matches_played": 43
2169
+ },
2170
+ "Abkhazia": {
2171
+ "elo": 1611.3,
2172
+ "recent_points": 1.8,
2173
+ "avg_scored": 1.2,
2174
+ "avg_conceded": 0.6,
2175
+ "rolling_gd": 0.6,
2176
+ "matches_played": 28
2177
+ },
2178
+ "Artsakh": {
2179
+ "elo": 1556.1,
2180
+ "recent_points": 2.0,
2181
+ "avg_scored": 1.8,
2182
+ "avg_conceded": 1.6,
2183
+ "rolling_gd": 0.2,
2184
+ "matches_played": 11
2185
+ },
2186
+ "Madrid": {
2187
+ "elo": 1491.9,
2188
+ "recent_points": 0.0,
2189
+ "avg_scored": 1.0,
2190
+ "avg_conceded": 2.0,
2191
+ "rolling_gd": -1.0,
2192
+ "matches_played": 1
2193
+ },
2194
+ "Ellan Vannin": {
2195
+ "elo": 1528.9,
2196
+ "recent_points": 1.6,
2197
+ "avg_scored": 2.0,
2198
+ "avg_conceded": 1.4,
2199
+ "rolling_gd": 0.6,
2200
+ "matches_played": 17
2201
+ },
2202
+ "County of Nice": {
2203
+ "elo": 1589.9,
2204
+ "recent_points": 2.0,
2205
+ "avg_scored": 2.2,
2206
+ "avg_conceded": 1.6,
2207
+ "rolling_gd": 0.6,
2208
+ "matches_played": 9
2209
+ },
2210
+ "South Ossetia": {
2211
+ "elo": 1493.9,
2212
+ "recent_points": 2.2,
2213
+ "avg_scored": 1.4,
2214
+ "avg_conceded": 0.8,
2215
+ "rolling_gd": 0.6,
2216
+ "matches_played": 14
2217
+ },
2218
+ "Sz\u00e9kely Land": {
2219
+ "elo": 1433.7,
2220
+ "recent_points": 0.2,
2221
+ "avg_scored": 1.0,
2222
+ "avg_conceded": 3.2,
2223
+ "rolling_gd": -2.2,
2224
+ "matches_played": 23
2225
+ },
2226
+ "Romani people": {
2227
+ "elo": 1492.5,
2228
+ "recent_points": 1.0,
2229
+ "avg_scored": 2.333,
2230
+ "avg_conceded": 2.667,
2231
+ "rolling_gd": -0.333,
2232
+ "matches_played": 3
2233
+ },
2234
+ "Felvid\u00e9k": {
2235
+ "elo": 1498.4,
2236
+ "recent_points": 1.4,
2237
+ "avg_scored": 0.8,
2238
+ "avg_conceded": 0.8,
2239
+ "rolling_gd": 0.0,
2240
+ "matches_played": 8
2241
+ },
2242
+ "Hitra": {
2243
+ "elo": 1442.5,
2244
+ "recent_points": 1.4,
2245
+ "avg_scored": 1.8,
2246
+ "avg_conceded": 2.8,
2247
+ "rolling_gd": -1.0,
2248
+ "matches_played": 11
2249
+ },
2250
+ "Somaliland": {
2251
+ "elo": 1489.0,
2252
+ "recent_points": 1.2,
2253
+ "avg_scored": 2.4,
2254
+ "avg_conceded": 3.6,
2255
+ "rolling_gd": -1.2,
2256
+ "matches_played": 5
2257
+ },
2258
+ "Chagos Islands": {
2259
+ "elo": 1385.4,
2260
+ "recent_points": 0.0,
2261
+ "avg_scored": 1.4,
2262
+ "avg_conceded": 6.0,
2263
+ "rolling_gd": -4.6,
2264
+ "matches_played": 11
2265
+ },
2266
+ "United Koreans in Japan": {
2267
+ "elo": 1480.6,
2268
+ "recent_points": 1.2,
2269
+ "avg_scored": 1.4,
2270
+ "avg_conceded": 0.8,
2271
+ "rolling_gd": 0.6,
2272
+ "matches_played": 11
2273
+ },
2274
+ "Western Armenia": {
2275
+ "elo": 1483.1,
2276
+ "recent_points": 1.0,
2277
+ "avg_scored": 1.6,
2278
+ "avg_conceded": 1.0,
2279
+ "rolling_gd": 0.6,
2280
+ "matches_played": 16
2281
+ },
2282
+ "Panjab": {
2283
+ "elo": 1528.2,
2284
+ "recent_points": 1.0,
2285
+ "avg_scored": 2.6,
2286
+ "avg_conceded": 2.2,
2287
+ "rolling_gd": 0.4,
2288
+ "matches_played": 12
2289
+ },
2290
+ "Barawa": {
2291
+ "elo": 1422.4,
2292
+ "recent_points": 0.6,
2293
+ "avg_scored": 0.4,
2294
+ "avg_conceded": 5.0,
2295
+ "rolling_gd": -4.6,
2296
+ "matches_played": 12
2297
+ },
2298
+ "K\u00e1rp\u00e1talja": {
2299
+ "elo": 1592.8,
2300
+ "recent_points": 2.6,
2301
+ "avg_scored": 2.8,
2302
+ "avg_conceded": 0.8,
2303
+ "rolling_gd": 2.0,
2304
+ "matches_played": 10
2305
+ },
2306
+ "Yorkshire": {
2307
+ "elo": 1546.1,
2308
+ "recent_points": 2.4,
2309
+ "avg_scored": 4.0,
2310
+ "avg_conceded": 2.0,
2311
+ "rolling_gd": 2.0,
2312
+ "matches_played": 7
2313
+ },
2314
+ "Surrey": {
2315
+ "elo": 1508.7,
2316
+ "recent_points": 3.0,
2317
+ "avg_scored": 3.0,
2318
+ "avg_conceded": 1.0,
2319
+ "rolling_gd": 2.0,
2320
+ "matches_played": 1
2321
+ },
2322
+ "Kabylia": {
2323
+ "elo": 1465.1,
2324
+ "recent_points": 1.0,
2325
+ "avg_scored": 1.6,
2326
+ "avg_conceded": 1.4,
2327
+ "rolling_gd": 0.2,
2328
+ "matches_played": 6
2329
+ },
2330
+ "Matabeleland": {
2331
+ "elo": 1498.6,
2332
+ "recent_points": 1.4,
2333
+ "avg_scored": 1.0,
2334
+ "avg_conceded": 2.4,
2335
+ "rolling_gd": -1.4,
2336
+ "matches_played": 5
2337
+ },
2338
+ "Cascadia": {
2339
+ "elo": 1527.6,
2340
+ "recent_points": 2.0,
2341
+ "avg_scored": 4.0,
2342
+ "avg_conceded": 1.8,
2343
+ "rolling_gd": 2.2,
2344
+ "matches_played": 7
2345
+ },
2346
+ "Timor-Leste": {
2347
+ "elo": 1287.3,
2348
+ "recent_points": 0.0,
2349
+ "avg_scored": 1.2,
2350
+ "avg_conceded": 4.8,
2351
+ "rolling_gd": -3.6,
2352
+ "matches_played": 9
2353
+ },
2354
+ "Myanmar": {
2355
+ "elo": 1407.6,
2356
+ "recent_points": 1.2,
2357
+ "avg_scored": 1.0,
2358
+ "avg_conceded": 2.6,
2359
+ "rolling_gd": -1.6,
2360
+ "matches_played": 16
2361
+ },
2362
+ "Parishes of Jersey": {
2363
+ "elo": 1506.3,
2364
+ "recent_points": 2.0,
2365
+ "avg_scored": 3.667,
2366
+ "avg_conceded": 1.333,
2367
+ "rolling_gd": 2.333,
2368
+ "matches_played": 3
2369
+ },
2370
+ "Chameria": {
2371
+ "elo": 1528.0,
2372
+ "recent_points": 1.6,
2373
+ "avg_scored": 1.8,
2374
+ "avg_conceded": 0.8,
2375
+ "rolling_gd": 1.0,
2376
+ "matches_played": 5
2377
+ },
2378
+ "Saint Helena": {
2379
+ "elo": 1436.8,
2380
+ "recent_points": 0.0,
2381
+ "avg_scored": 1.0,
2382
+ "avg_conceded": 6.0,
2383
+ "rolling_gd": -5.0,
2384
+ "matches_played": 4
2385
+ }
2386
+ }