Skip to content

Commit

Permalink
Merge pull request #5 from andregri/feature/season_arg
Browse files Browse the repository at this point in the history
Feature/season arg
  • Loading branch information
andregri authored Jan 28, 2024
2 parents 2d7c9df + 57c084e commit 31188b3
Show file tree
Hide file tree
Showing 168 changed files with 40,988 additions and 31 deletions.
File renamed without changes.
34 changes: 34 additions & 0 deletions _data/stagione_2023_2024/calendario.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
- giornata: 1
- giornata: 2
- giornata: 3
- giornata: 4
- giornata: 5
- giornata: 6
- giornata: 7
- giornata: 8
- giornata: 9
- giornata: 10
- giornata: 11
- giornata: 12
- giornata: 13
- giornata: 14
- giornata: 15
- giornata: 16
- giornata: 17
- giornata: 18
- giornata: 19
- giornata: 20
- giornata: 21
- giornata: 22
- giornata: 23
- giornata: 24
- giornata: 25
- giornata: 26
- giornata: 27
- giornata: 28
- giornata: 29
- giornata: 30
- giornata: 31
- giornata: 32
- giornata: 33
- giornata: 34
22 changes: 22 additions & 0 deletions _data/stagione_2023_2024/calendario_coppa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- giornata: 1
fase: gironi
- giornata: 2
fase: gironi
- giornata: 3
fase: gironi
- giornata: 4
fase: gironi
- giornata: 5
fase: gironi
- giornata: 6
fase: gironi
- giornata: 7
fase: quarti (andata)
- giornata: 8
fase: quarti (ritorno)
- giornata: 9
fase: semifinali (andata)
- giornata: 10
fase: semifinali (ritorno)
- giornata: 11
fase: finale
36 changes: 36 additions & 0 deletions _data/stagione_2023_2024/fantasquadre.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
1:
name: Real David
id: 4481779
2:
name: Godopolisportiva Antonio Ricci
id: 4485329
3:
name: Ire Framba United
id: 4483105
4:
name: MedusaTeam WFC IL BLOCCO
id: 5330685
5:
name: Paris Saint Germano
id: 4480837
6:
name: Patetico Mineiro
id: 4480737
7:
name: Pompy FC
id: 4480615
8:
name: Real Pollo
id: 5332606
9:
name: Reggisenal
id: 5332804
10:
name: Team Barco FC
id: 9242836
11:
name: YRN F.C.
id: 10898860
12:
name: Owl City
id: 4480565
2 changes: 2 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ layout: home

<ul>
<li><a href="2023_2024/pronostici/pronostici.html">Pronostici</a></li>
<li><a href="2023_2024/calendario">Campionato: calendario e risultati</a></li>
<li><a href="2023_2024/calendario-coppa">Coppa Box: calendario e risultati</a></li>
</ul>

<h1><a href="2022_2023/">Stagione 2022/2023</a></h1>
Expand Down
2 changes: 1 addition & 1 deletion python/data/2023_2024/fantasquadre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
excel_row: 3
excel_col: 0
5330685:
name: MedusaTeam WFC - IL BLOCCO
name: MedusaTeam WFC IL BLOCCO
excel_row: 4
excel_col: 0
4480837:
Expand Down
47 changes: 23 additions & 24 deletions python/giornate/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@
import jinja2
import os
import table
import teams


HERE_PATH = Path(__file__).parent.parent
OUTPUT_PATH = Path(__file__).parent.parent.parent / 'stagioni'

# Read map from ID to Fantasquadra name
id2fantasquadra = {}
with open('../../_data/fantasquadre.yml', 'r') as f:
data=yaml.safe_load(f)
id2fantasquadra = {d['id']: d['name'] for d in data.values()}


class Giornata():
def __init__(self, filename):
Expand Down Expand Up @@ -104,16 +99,16 @@ def parse_calciatore(self, data):
return calciatore


def get_title(self, id_partita):
def get_title(self, stagione, id_partita):
id_squadra_casa = self.partite[id_partita]['home']['id_squadra']
nome_squadra_casa = id2fantasquadra[id_squadra_casa]
nome_squadra_casa = teams.name_by_id(stagione, id_squadra_casa)
id_squadra_trasferta = self.partite[id_partita]['away']['id_squadra']
nome_squadra_trasferta = id2fantasquadra[id_squadra_trasferta]
nome_squadra_trasferta = teams.name_by_id(stagione, id_squadra_trasferta)
risultato = self.partite[id_partita]['risultato']
return nome_squadra_casa, nome_squadra_trasferta, risultato


def genera_riepilogo_giornata(self, stagione, giornata, is_coppa=False):
def genera_riepilogo_giornata(self, stagione, giornata, num_squadre, is_coppa=False):
teamfile_path = HERE_PATH / 'data' / stagione / 'fantasquadre.yml'
fantasquadre_dict = {}
with open(teamfile_path.resolve(), 'r') as f:
Expand All @@ -124,7 +119,7 @@ def genera_riepilogo_giornata(self, stagione, giornata, is_coppa=False):
) for id in data}

table_json_path = HERE_PATH / 'data' / stagione / 'campionato' / f'classifica_{giornata}.json'
t = table.Table(10, table_json_path)
t = table.Table(stagione, num_squadre, table_json_path)

out_html_filepath = OUTPUT_PATH / stagione / 'giornate' / str(giornata) / f'{str(giornata)}.html'
with open(out_html_filepath.resolve(), 'w') as out_f:
Expand All @@ -150,15 +145,15 @@ def genera_riepilogo_giornata(self, stagione, giornata, is_coppa=False):
out_f.write(outputText)


def genera_riepilogo_giornata_coppa_gironi(self, stagione, giornata):
def genera_riepilogo_giornata_coppa_gironi(self, stagione, giornata, num_squadre_per_girone):
teamfile_path = HERE_PATH / 'data' / stagione / 'fantasquadre.yml'
fantasquadre_dict = {}
with open(teamfile_path.resolve(), 'r') as f:
data=yaml.safe_load(f)
fantasquadre_dict = {id: dict(name=data[id]['name']) for id in data}

table_json_path = HERE_PATH / 'data' / stagione / 'coppa' / f'classifica_{giornata}.json'
t = table.Table(5, table_json_path)
t = table.Table(stagione, num_squadre_per_girone, table_json_path)
group_tables = [{'group': group, 'table': t.by_group(group)} for group in t.groups()]

out_html_filepath = OUTPUT_PATH / stagione / 'coppa' / 'giornate' / str(giornata) / f'{str(giornata)}.html'
Expand Down Expand Up @@ -216,7 +211,7 @@ def genera_riepilogo_giornata_coppa_eliminazione(self, stagione, giornata):


def genera_partita(self, stagione, giornata, id_partita, is_coppa=False):
nome_squadra_casa, nome_squadra_trasferta, risultato = self.get_title(id_partita)
nome_squadra_casa, nome_squadra_trasferta, risultato = self.get_title(stagione, id_partita)
title = f'{nome_squadra_casa} ({risultato}) {nome_squadra_trasferta}'

permalink = f'{stagione}/giornate/{giornata}/partite/{id_partita}'
Expand All @@ -234,11 +229,11 @@ def genera_partita(self, stagione, giornata, id_partita, is_coppa=False):

# Titolari
f.write('<h1>Titolari</h1>\n')
self.genera_tabella_formazioni(f, id_partita, 0, 10, aggiungi_nomi_squadre=True)
self.genera_tabella_formazioni(f, stagione, id_partita, 0, 10, aggiungi_nomi_squadre=True)

# Panchina
f.write('<h1>Panchina</h1>\n')
self.genera_tabella_formazioni(f, id_partita, 11, 17, aggiungi_nomi_squadre=False)
self.genera_tabella_formazioni(f, stagione, id_partita, 11, 17, aggiungi_nomi_squadre=False)

f.write('<table>\n')
# MODIFICATORE DIFESA
Expand Down Expand Up @@ -294,12 +289,12 @@ def genera_navigazione(self, file, is_riepilogo, giornata, is_coppa):
file.write('{% endfor %}')


def genera_tabella_formazioni(self, f, id_partita, start_index, stop_index, aggiungi_nomi_squadre=False):
def genera_tabella_formazioni(self, f, stagione, id_partita, start_index, stop_index, aggiungi_nomi_squadre=False):
f.write('<table>\n')

# Aggiungi i nomi delle squadre all'inizio della tabella
if aggiungi_nomi_squadre:
nomi_squadre = self.get_title(id_partita=id_partita)
nomi_squadre = self.get_title(stagione=stagione, id_partita=id_partita)
f.write(f' <tr>\n')
for i, field in zip(range(2), ['home', 'away']):
modulo = self.partite[id_partita][field]["modulo_iniziale"]
Expand Down Expand Up @@ -424,13 +419,16 @@ def genera_tabella_formazioni(self, f, id_partita, start_index, stop_index, aggi
Genera i file per una stagione
es. Per generare i file della stagione 2022_2023
python main.py 2022_2023
python main.py 2023_2024 --num-squadre 12
es. Per generare i file della coppa
python main.py 2022_2023 --coppa gironi
python main.py 2023_2024 --coppa gironi --coppa-girone-giornate 6 --coppa-girone-squadre 3
''')
parser.add_argument('stagione', type=str, help='stagione e.g. 2022_2023')
parser.add_argument('--coppa', type=str, help='fase della coppa, e.g. gironi')
parser.add_argument('--num-squadre', type=int, help='numero di squadre e.g. 10')
parser.add_argument('--coppa', type=str, help='fase della coppa - possible values: [gironi]')
parser.add_argument('--coppa-girone-giornate', type=int, help='numero di giornate dei gironi in coppa e.g. 6')
parser.add_argument('--coppa-girone-squadre', type=int, help='numero di squadre per girone in coppa e.g. 3')
args = parser.parse_args()

if args.coppa:
Expand All @@ -453,12 +451,13 @@ def genera_tabella_formazioni(self, f, id_partita, start_index, stop_index, aggi
giornata = Giornata(day_file)

if args.coppa:
if day_number > 5:
if day_number > args.coppa_girone_giornate:
giornata.genera_riepilogo_giornata_coppa_eliminazione(stagione=args.stagione, giornata=day_number)
else:
giornata.genera_riepilogo_giornata_coppa_gironi(stagione=args.stagione, giornata=day_number)
giornata.genera_riepilogo_giornata_coppa_gironi(
stagione=args.stagione, giornata=day_number, num_squadre_per_girone=args.coppa_girone_squadre)
else:
giornata.genera_riepilogo_giornata(stagione=args.stagione, giornata=day_number)
giornata.genera_riepilogo_giornata(stagione=args.stagione, giornata=day_number, num_squadre=args.num_squadre)

for i in range(len(giornata.partite)):
giornata.genera_partita(stagione=args.stagione, giornata=day_number, id_partita=i+1, is_coppa=args.coppa)
5 changes: 5 additions & 0 deletions python/giornate/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
campionato_2023_2024:
python main.py 2023_2024 --num-squadre 12

coppa_2023_2024:
python main.py 2023_2024 --coppa gironi --coppa-girone-giornate 6 --coppa-girone-squadre 3
8 changes: 4 additions & 4 deletions python/giornate/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import teams

class TableRow():
def __init__(self, position, data):
def __init__(self, stagione, position, data):
self.position = position
self.team = teams.name_by_id(data.get('id'))
self.team = teams.name_by_id(stagione, data.get('id'))
self.played = data.get('g')
self.won = data.get('v')
self.draw = data.get('n')
Expand All @@ -18,7 +18,7 @@ def __init__(self, position, data):


class Table():
def __init__(self, teams_per_group, json_path):
def __init__(self, stagione, teams_per_group, json_path):
self.rows = []

with open(json_path, 'r') as f:
Expand All @@ -27,7 +27,7 @@ def __init__(self, teams_per_group, json_path):

for i, row in enumerate(table):
pos = (i % teams_per_group) + 1
self.rows.append(TableRow(pos, row))
self.rows.append(TableRow(stagione, pos, row))

def groups(self):
return sorted(set((row.group for row in self.rows)))
Expand Down
4 changes: 2 additions & 2 deletions python/giornate/teams.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import yaml


def name_by_id(id):
def name_by_id(stagione, id):
# Read map from ID to Fantasquadra name
id2fantasquadra = {}
with open('../../_data/fantasquadre.yml', 'r') as f:
with open(f'../../_data/stagione_{stagione}/fantasquadre.yml', 'r') as f:
data=yaml.safe_load(f)
id2fantasquadra = {d['id']: d['name'] for d in data.values()}

Expand Down
Loading

0 comments on commit 31188b3

Please sign in to comment.