fussballgott package

Submodules

fussballgott.fussball module

fussballgott.fussball.penalty_shootout(penalty_scoring1, penalty_scoring2)[source]

Simulate a penalty shootout between two teams with given penalty scoring.

Parameters:
  • penalty_scoring1 – Penalty scoring of team 1 (between 0 and 1)

  • penalty_scoring2 – Penalty scoring of team 2 (between 0 and 1)

Returns:

home goals, away goals

fussballgott.fussball.simulate_game(AvGoalsF1, AvGoalsF2, AvGoalsA1=1, AvGoalsA2=1, include_goals_against=False, extra_time=False, penalty_scoring1=0.75, penalty_scoring2=0.75, return_when=False)[source]

Simulate a game between two teams with given average goals for and against.

Parameters:
  • AvGoalsF1 – Average goals for team 1

  • AvGoalsF2 – Average goals for team 2

  • AvGoalsA1 – Average goals against team 1

  • AvGoalsA2 – Average goals against team 2

  • include_goals_against – If True, the average goals against are included

  • extra_time – If True, extra time and penalty shootout are included

  • penalty_scoring1 – Penalty scoring of team 1 (between 0 and 1)

  • penalty_scoring2 – Penalty scoring of team 2 (between 0 and 1)

  • return_when – If True, the result is returned together with the time when the game was decided and the result before overtime

Returns:

home goals, away goals

Returns:

when, home goals and away goals after 90 minutes (if return_when=True)

fussballgott.fussball.simulate_game_from_teams(team1, team2, include_goals_against=False, extra_time=False, return_when=False)[source]

Simulate a game between two teams (with given team classes)

Parameters:
  • team1 – team class of team 1

  • team2 – team class of team 2

  • include_goals_against – If True, the average goals against are included

  • extra_time – If True, extra time and penalty shootout are included

  • return_when – If True, the result is returned together with the time when the game was decided and the result before overtime

Returns:

home goals, away goals

Returns:

when, home goals and away goals after 90 minutes (if return_when=True)

fussballgott.fussball.simulate_game_stats(AvGoalsF1, AvGoalsF2, AvGoalsA1, AvGoalsA2, n_sim=100000.0, include_goals_against=False, extra_time=False, extra_time_result=False, penalty_scoring1=0.75, penalty_scoring2=0.75, max_goals=10)[source]

Simulate the statistics of a game between two teams.

Parameters:
  • AvGoalsF1 – Average goals for team 1

  • AvGoalsF2 – Average goals for team 2

  • AvGoalsA1 – Average goals against team 1

  • AvGoalsA2 – Average goals against team 2

  • n_sim – Number of simulations

  • include_goals_against – If True, the average goals against are included

  • extra_time – If True, extra time and penalty shootout are included

  • extra_time_result – if True, result after extra time is included in return

  • penalty_scoring1 – Penalty scoring of team 1 (between 0 and 1)

  • penalty_scoring2 – Penalty scoring of team 2 (between 0 and 1)

  • max_goals – Maximum number of goals for the table

Returns:

table of results, win probabilities

fussballgott.fussball.simulate_game_stats_from_teams(team1, team2, include_goals_against=False, extra_time=False, extra_time_result=False, n_sim=100000.0)[source]

Simulate the statistics of a game between two teams.

Parameters:
  • team1 – team class of team 1

  • team2 – team class of team 2

  • include_goals_against – If True, the average goals against are included

  • extra_time – If True, extra time and penalty shootout are included

  • extra_time_result – if True, result after extra time is included in return

  • n_sim – Number of simulations

Returns:

table of result probabilities, win probabilities

fussballgott.fussball.simulate_game_wo_overtime(AvGoalsF1, AvGoalsF2, AvGoalsA1=1, AvGoalsA2=1, include_goals_against=False, multiplier=1)[source]

Simulate a game between two teams with given average goals for and against in 90 minutes.

Parameters:
  • AvGoalsF1 – Average goals for team 1

  • AvGoalsF2 – Average goals for team 2

  • AvGoalsA1 – Average goals against team 1

  • AvGoalsA2 – Average goals against team 2

  • include_goals_against – If True, the average goals against are included

  • multiplier – Multiplier for the average goals, e.g. 1/3 for overtime

Returns:

home goals, away goals

fussballgott.fussball.sort(table, sorting='standard')[source]

Sorts a table of results.

Parameters:
  • table – Table of results

  • sorting – Sorting method

Returns:

Sorted table, ranking

fussballgott.fussball.who_won(home, away)[source]

Returns who won the game. 0 if home won, 1 if draw and 2 if away won.

Parameters:
  • home – Home goals

  • away – Away goals

Returns:

0 if home won, 1 if draw and 2 if away won

fussballgott.league module

fussballgott.league.np_to_pd(table, dict_num2team)[source]

Convert numpy table to pandas table.

Parameters:
  • table – Table of the league

  • dict_num2team – Dictionary that maps indices to teams

Returns:

Table of the league as pandas table

fussballgott.league.pd_to_np(schedule, table)[source]

Convert pandas schedule and table to numpy arrays.

Parameters:
  • schedule – Schedule of the league

  • table – Table of the league

Returns:

schedule and table as numpy arrays

fussballgott.league.simulate(teams, schedule=2, table=None, missing_games=None, n_sim=1, include_goals_against=True, sorting='standard', progressbar=True, tournament_mode=False)[source]

Simulate a league with given teams and schedule.

Parameters:
  • teams – Dictionary with teams as keys and team objects as values

  • schedule – Schedule of the league. If int, all teams play against each other schedule times. If pd.DataFrame, the schedule is given as a table with columns “Home” and “Away”.

  • table – Table of the league. If None, a new table is created

  • missing_games – List of games that are not played

  • n_sim – Number of simulations

  • include_goals_against – If True, the average goals against are included

  • sorting – Sorting of the table

  • progressbar – If True, a progressbar is shown

  • tournament_mode – If True, the table is returned, if False, the ranking table is returned

Returns:

table (if tournament_mode) or ranking table (if not tournament_mode)

fussballgott.league.simulate_once(schedule, table, teams, missing_games, dict_num2team, include_goals_against=True)[source]

Simulate a league with given teams and schedule.

Parameters:
  • schedule – numpy array with schedule

  • table – numpy array with table

  • teams – Dictionary with teams as keys and team objects as values

  • missing_games – List of games that are not played

  • dict_num2team – Dictionary that maps indices to teams

  • include_goals_against – If True, the average goals against are included

Returns:

changed table

fussballgott.load module

fussballgott.load.create_table(sched_n_r, teams)[source]

Create the table from the schedule and results

Parameters:
  • sched_n_r – Schedule and results

  • teams – List of teams

Returns:

Table, missing games

fussballgott.load.get_missing_games(table, schedule)[source]

Get the missing games from the schedule

Parameters:
  • table – Table

  • schedule – Schedule

Returns:

Boolean array with missing games

fussballgott.load.get_teams_from_df(df, columns=['Home', 'Away'])[source]

Get all teams from a DataFrame with a schedule.

Parameters:
  • df – DataFrame with schedule

  • columns – Columns of the DataFrame that contain the teams

Returns:

Array with all teams

fussballgott.load.league(files, delimiter=';')[source]

Load a league from a file or a list of files. Setups the teams classes, the schedule, the table and the missing games.

Input can be: - One file with the schedule and results of the games played so far - Two files, one with the schedule and one with the table

Parameters:
  • files – File or list of files

  • delimiter – Delimiter of the files

Returns:

teams, schedule, table, missing_games

fussballgott.load.tiebreaker(table, rule='Goal Difference')[source]

Sort the table according to the tiebreaker rule

Parameters:
  • table – Table to be sorted

  • rule – Tiebreaker rule

Returns:

Sorted table

fussballgott.load.tournament(filename, path='', delimiter=';')[source]

Load the tournament plan from file and setup team classes. Assuming your filename is tournament_, you should have the following files in your path:

  • tournament_mode.CSV to describe the mode of the tournament

  • tournament_teams.CSV to describe the teams playing

  • tournament_{n}.CSV with n ranging from 2 to 2**x, where x is the number of rounds played in the tournament. The files contain the schedule of the games played in the knockout round.

  • tournament_special_rule.CSV if there is a special rule for the tournament (e.g. some of the best third placed teams qualify for the next round)

Parameters:
  • filename – Name of the file

  • path – Path to the file

  • delimiter – Delimiter of the file

Returns:

teams, schedule, table, missing_games

fussballgott.plot module

fussballgott.plot.game_stat(sim, winprob=None, team1='home', team2='away')[source]

Plot the game statistics in a heatmap.

Parameters:
  • sim – DataFrame with the simulation results

  • winprob – Array with the win probabilities

  • team1 – Name of the first team

  • team2 – Name of the second team

fussballgott.plot.league(sim)[source]

Plot the league table in a heatmap.

Parameters:

sim – DataFrame with the simulation results

fussballgott.plot.tournament(sim, sort_for=None, save=None, prob_style='standard')[source]

Plot the tournament table in a heatmap.

Parameters:
  • sim – DataFrame with the simulation results

  • sort_for – Column to sort for

  • save – Path to save the plot

  • prob_style – “standard” or “cumulative”

fussballgott.team module

class fussballgott.team.Team(name, GoalsF, GoalsA=None, played=1, penalty_scoring=0.75)[source]

Bases: object

Class for a team.

Parameters:
  • name – Name of the team

  • GoalsF – Goals scored

  • GoalsA – Goals conceded

  • played – Number of games played

  • penalty_scoring – Factor for penalty scoring

property AvGoalsA

Average goals conceded per game

property AvGoalsF

Average goals scored per game

fussballgott.tournament module

fussballgott.tournament.simulate(mode, ko_round, teams, groups=None, n_sim=1, include_goals_against=True, sorting='standard', small_final=False, progressbar=True)[source]

Simulate a tournament with given teams and schedule.

Parameters:
  • mode – Dictionary with the mode of the tournament

  • ko_round – List of pandas DataFrames with the knockout rounds

  • teams – Dictionary with teams as keys and team objects as values

  • groups – Dictionary with groups as keys and teams as values

  • n_sim – Number of simulations

  • include_goals_against – If True, the average goals against are included

  • sorting – Sorting of the table

  • small_final – If True, the tournament ends has a small final

  • progressbar – If True, a progressbar is shown

Returns:

simlated tournament table

Module contents