Skip to content

Commit dd2b756

Browse files
committed
fix: add clean sheets calculation to team performance backend
- Track clean sheets (matches where team conceded 0 goals) - Replace Defense metric with Clean Sheets in backend API - Update chart labels from Defense to Clean Sheets - Fixes issue where chart had no data for this metric
1 parent 3c1d550 commit dd2b756

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

backend/api/dashboard.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,15 @@ async def get_chart_data(
323323
if team and team not in teams_data:
324324
teams_data[team] = {
325325
"wins": 0, "points": 0, "goals": 0,
326-
"goals_against": 0, "matches": 0
326+
"goals_against": 0, "matches": 0, "clean_sheets": 0
327327
}
328328

329329
if home_team:
330330
teams_data[home_team]["matches"] += 1
331331
teams_data[home_team]["goals"] += home_score
332332
teams_data[home_team]["goals_against"] += away_score
333+
if away_score == 0: # Clean sheet for home team
334+
teams_data[home_team]["clean_sheets"] += 1
333335
if home_score > away_score:
334336
teams_data[home_team]["wins"] += 1
335337
teams_data[home_team]["points"] += 3
@@ -340,6 +342,8 @@ async def get_chart_data(
340342
teams_data[away_team]["matches"] += 1
341343
teams_data[away_team]["goals"] += away_score
342344
teams_data[away_team]["goals_against"] += home_score
345+
if home_score == 0: # Clean sheet for away team
346+
teams_data[away_team]["clean_sheets"] += 1
343347
if away_score > home_score:
344348
teams_data[away_team]["wins"] += 1
345349
teams_data[away_team]["points"] += 3
@@ -361,15 +365,15 @@ async def get_chart_data(
361365
stats["wins"] * 2, # Wins scaled
362366
(stats["points"] / matches_played) * 10, # Points per game
363367
(stats["goals"] / matches_played) * 15, # Goals per game
364-
max(0, 20 - (stats["goals_against"] / matches_played * 10)), # Defense
368+
stats["clean_sheets"] * 2, # Clean sheets scaled
365369
max(0, min(goal_diff * 2, 20)) # Form based on goal difference
366370
],
367371
"borderColor": colors[idx],
368372
"backgroundColor": colors[idx] + "30"
369373
})
370374

371375
chart_data = ChartData(
372-
labels=['Wins', 'Points/Game', 'Goals/Game', 'Defense', 'Form'],
376+
labels=['Wins', 'Points/Game', 'Goals/Game', 'Clean Sheets', 'Form'],
373377
datasets=datasets,
374378
type="radar"
375379
)

0 commit comments

Comments
 (0)