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.
[!NOTE] 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.8 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
-
Clone the repository:
git clone https://github.com/RiccardoSamaritan/FantacalcioSimulator
-
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fantacalciosimulator-0.1.2.tar.gz.
File metadata
- Download URL: fantacalciosimulator-0.1.2.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
058d55ac4965ea00e34126c0279cd0f727e4b355c968291e6fd06e351ec9955f
|
|
| MD5 |
1a96079ce8ec2d8c5a145a7d2fb3bd8a
|
|
| BLAKE2b-256 |
07acd5b526f01ed7255a8aab29bd571433a319de33d8061a1d3b222fe793d262
|
File details
Details for the file fantacalciosimulator-0.1.2-py3-none-any.whl.
File metadata
- Download URL: fantacalciosimulator-0.1.2-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcd404bb89fd1965fac378692f64d90ca3c1c4cb26816c5c3f64bdaa248f4481
|
|
| MD5 |
98ac1bd63fdf31b39c4baa33b93fa2b3
|
|
| BLAKE2b-256 |
5a1932903464512b8027ed47aa7e674c374ec6fe84dc251e0f80c55492f08950
|