Team Strength Comparison

Click button to calculate...
import statistics home_team = { 'name': 'Home Team', 'position': 13, 'played': 28, 'points': 36, 'goals_for': 40, 'goals_against': 42, 'form_numbers': [2,5,6,3,9,6,1,1,4], 'home_wins': 7, 'home_draws': 2, 'home_losses': 5 } away_team = { 'name': 'Away Team', 'position': 3, 'played': 28, 'points': 51, 'goals_for': 50, 'goals_against': 38, 'form_numbers': [8,8,7,6,6,8,7,6,5], 'away_wins': 5, 'away_draws': 6, 'away_losses': 3 } def calculate_strength(team): ppg = team['points'] / team['played'] ppg_score = ppg / 3 gd = team['goals_for'] - team['goals_against'] gdpg = gd / team['played'] gd_score = (gdpg + 3) / 6 pos_score = (20 - team['position'] + 1) / 20 form_avg = statistics.mean(team['form_numbers']) form_score = form_avg / 10 if 'home_wins' in team: relevant = team['home_wins'] + team['home_draws'] + team['home_losses'] win_pct = team['home_wins'] / relevant if relevant > 0 else 0 else: relevant = team['away_wins'] + team['away_draws'] + team['away_losses'] win_pct = team['away_wins'] / relevant if relevant > 0 else 0 return ( 0.4 * ppg_score + 0.2 * gd_score + 0.2 * pos_score + 0.1 * form_score + 0.1 * win_pct ) def main(*args, **kwargs): hs = calculate_strength(home_team) aws = calculate_strength(away_team) if hs > aws + 0.01: winner = f"{home_team['name']} is stronger" elif aws > hs + 0.01: winner = f"{away_team['name']} is stronger" else: winner = "Very close match" output = f""" Home: {hs:.3f}
Away: {aws:.3f}

{winner} """ pyscript.write("output", output)