Skip to main content

A python tool to simulate an entire Fantacalcio season

Project description

About

A comprehensive Python library for simulating Italian fantasy football (Fantacalcio) seasons with probabilistic algorithms, multi-season support, and flexible team management.

Purpose: This library is designed to support data science and machine learning projects in the fantasy football domain. It provides realistic season simulations and statistical analysis tools for research, not to replace the original game experience.

Features

  • Multi-Season Support: Simulate different seasons (2024-25, 2023-24, 2022-23, 2021-22) with automatic data directory management
  • Multiple Input Formats: Load teams from JSON, CSV files, or pandas DataFrames
  • Probabilistic Simulation: Probabilistic algorithms eliminate luck factor for realistic season outcomes
  • Flexible Configuration: Support for various team compositions and formation rules.

The app takes as input a given number of teams (usually a multiple of 2 in a range between 8 and 12) with 25 players (3 goalkeepers, 8 defenders, 8 midfielders and 6 forwards), which is the most common format used in the game.

Game Rules

Formation

To simplify the implementation, the following rules have been applied to fantasy football by default:

  • The only allowed formation is 4-3-3, which means 1 goalkeeper, 4 defenders, 3 midfielders and 3 forwards. If there are not enough players in a role with a valid vote, a player with a null vote will be fielded anyway.

  • The user doesn't field players; instead, they are automatically selected based on the highest "fantavoto", while respecting positional requirements.

Bonus and Malus

The following bonus and malus are applied to a player's vote in order to calculate his "fantavoto":

  • +3 for each goal or penalty scored;
  • +1 for each assist;
  • -1 for each goal taken (applied only to goalkeepers);
  • -3 for each missed penalty;
  • +3 for each saved penalty (applied only to goalkeepers);
  • -0,5 if he gets a yellow card;
  • -1 if he gets a red card;
  • -2 for each autogoal;
  • +1 if he keeps a clean sheet (applied only to goalkeepers).

Defense Modifier

The defense modifier is used, which awards bonus points to the team based on the average rating of the 4 defenders:

  • If the average rating is < 6, bonus +1
  • If the average rating is ≥ 6 and < 6.25, bonus +2
  • If the average rating is ≥ 6.25 and < 6.5, bonus +3
  • If the average rating is ≥ 6.5 and < 6.75, bonus +4
  • If the average rating is ≥ 6.75 and < 7, bonus +5
  • If the average rating is ≥ 7 and < 7.25, bonus +6
  • If the average rating is ≥ 7.25, bonus +7 The modifier is applied only if 4 defenders are fielded.

Installation

Before installing the package, make sure you have Python 3. or higher installed on your system. In case you want to avoid any conflicts with your system's Python packages, you might want to create (and activate) a dedicated virtual environment:

python -m venv /path/to/fantacalciosimulator_env
source /path/to/fantacalciosimulator_env/bin/activate

Install via PIP

You can install the package from the Python Package Index (PyPI) using pip:

pip install fantacalciosimulator

Installing from source

  1. Clone the repository:

    git clone https://github.com/RiccardoSamaritan/FantacalcioSimulator
    
  2. Move into the repository directory and install the package with:

    cd FantacalcioSimulator/
    pip install .
    

Quick Start

Basic Usage

from fantacalciosimulator import FantacalcioSimulator

# Initialize simulator with season and teams file
simulator = FantacalcioSimulator(
    season_year="2024-25",
    teams_file="teams_input_example.csv"
)

# Simulate complete season
results = simulator.simulate_season("My Fantasy League 2024-25")

# Display final table
print(simulator.get_final_table())

Using Different Input Formats

CSV Format

# CSV with format: team_name,player_name,role
simulator = FantacalcioSimulator("2024-25", "teams.csv")

JSON Format

# JSON with nested team structure
simulator = FantacalcioSimulator("2024-25", "teams.json")

Pandas DataFrame

import pandas as pd
from fantacalciosimulator import FantacalcioSimulator

df = pd.read_csv("teams.csv")
simulator = FantacalcioSimulator.from_dataframe("2024-25", df)

Configuration Options

# Disable defense modifier
simulator = FantacalcioSimulator(
    season_year="2024-25",
    teams_file="teams.csv",
    defense_modifier=False
)

# Custom data directory
simulator = FantacalcioSimulator(
    season_year="2024-25", 
    teams_file="teams.csv",
    data_dir="custom_data_path"
)

Advanced Usage Examples

Complete Analysis Workflow

from fantacalciosimulator import FantacalcioSimulator

# Initialize and simulate
simulator = FantacalcioSimulator("2024-25", "teams.csv")
results = simulator.simulate_season("My League")

# Get detailed team information
teams_info = simulator.get_teams_info()
for team in teams_info:
    print(f"{team['name']}: {team['total_players']} players, Valid: {team['valid_composition']}")

# Analyze specific team progression
team_progression = simulator.get_team_progression("Team Alpha")
print(f"Final points: {team_progression['final_total']}")

# Display championship results
print(f"Champion: {results['champion']} with {results['champion_points']} points")
print(f"Highest fantasy score: {results['highest_fantasy_score']} by {results['highest_fantasy_team']}")

Quick Simulation Function

from fantacalciosimulator import quick_simulation

# One-line season simulation
results = quick_simulation(
    season_year="2024-25",
    teams_file="teams.csv",
    season_name="Championship 2025"
)

Team Validation

from fantacalciosimulator import load_and_validate_teams

# Validate teams before simulation
teams_info = load_and_validate_teams("2024-25", "teams.csv")
valid_teams = [t for t in teams_info if t['valid_composition']]
print(f"{len(valid_teams)} valid teams out of {len(teams_info)}")

Data Sources

FantacalcioSimulator matchday statistics are taken from Fantacalcio.it, one of the most popular Italian fantasy football platforms.

Other useful resources from the same site are:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fantacalciosimulator-0.1.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fantacalciosimulator-0.1.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file fantacalciosimulator-0.1.0.tar.gz.

File metadata

  • Download URL: fantacalciosimulator-0.1.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for fantacalciosimulator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 29d890447cb91d8b6ee3823e45e0df00f8814eb77b5d43bb364c77c2c2e00e8d
MD5 9e0e88ce737fa56f01ed91035dbb4fd8
BLAKE2b-256 55a60ca0e83a019f15e1778eafe91a2fb6fbeb4bd94ef2194563cc3e7daad44c

See more details on using hashes here.

File details

Details for the file fantacalciosimulator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fantacalciosimulator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d3276628a83af39f9fbe635321d7013020f4a27fafbb3655a7dee9d359ca1eb
MD5 bb0fe6cf7ad5655b0ed310262c5956bb
BLAKE2b-256 05490a02206ee9636b643bdfb992a1cc08c544f840fbd05e7a20a23d0acba4d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page