Skip to content

Commit

Permalink
Merge pull request #2 from andregri/season/2024
Browse files Browse the repository at this point in the history
Pronostici 2024
  • Loading branch information
andregri authored Sep 20, 2023
2 parents ff60720 + 477f21b commit a145414
Show file tree
Hide file tree
Showing 19 changed files with 11,077 additions and 22 deletions.
6 changes: 6 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
layout: home
---

<h1><a href="stagioni/2023_2024">Stagione 2023/2024</a></h1>

<ul>
<li><a href="2023_2024/pronostici/pronostici.html">Pronostici</a></li>
</ul>

<h1><a href="2022_2023/">Stagione 2022/2023</a></h1>

<ul>
Expand Down
44 changes: 44 additions & 0 deletions python/data/2023_2024/fantasquadre.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
4481779:
name: REAL DAVID
excel_row: 2
excel_col: 1
4485329:
name: Godopolisportiva Antonio Ricci
excel_row: 3
excel_col: 1
4483105:
name: Ire Framba United
excel_row: 3
excel_col: 0
5330685:
name: MedusaTeam WFC - IL BLOCCO
excel_row: 4
excel_col: 0
4480837:
name: Paris Saint Germano
excel_row: 2
excel_col: 0
4480737:
name: Patetico Mineiro
excel_row: 1
excel_col: 0
4480615:
name: Pompy FC
excel_row: 0
excel_col: 1
5332606:
name: Real Pollo
excel_row: 4
excel_col: 1
5332804:
name: Reggisenal
excel_row: 5
excel_col: 0
9242836:
name: Team Barco F.C.
excel_row: 5
excel_col: 1
4480565:
name: Owl City
10898860:
name: YRN F.C.
12 changes: 12 additions & 0 deletions python/data/2023_2024/pronostici-2023_2024.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Informazioni cronologiche,Nome utente,"1° classificato","2° classificato","3° classificato","4° classificato","5° classificato","6° classificato","7° classificato","8° classificato","9° classificato","10° classificato","11° classificato","12° classificato"
10/09/2023 19.58.28,5332606,Pompy FC,Godopolisportiva Antonio Ricci,Patetico Mineiro,Paris Saint Germano,Team Barco F.C.,Reggisenal,Ire Framba United,REAL DAVID,Owl City,YRN F.C.,MedusaTeam WFC - IL BLOCCO,Real Pollo
10/09/2023 20.13.45,5332804,Patetico Mineiro,Paris Saint Germano,Reggisenal,Real Pollo,Ire Framba United,Pompy FC,YRN F.C.,Godopolisportiva Antonio Ricci,Team Barco F.C.,Owl City,MedusaTeam WFC - IL BLOCCO,REAL DAVID
10/09/2023 20.14.37,4480565,Pompy FC,Godopolisportiva Antonio Ricci,Real Pollo,Ire Framba United,REAL DAVID,Paris Saint Germano,Patetico Mineiro,Owl City,MedusaTeam WFC - IL BLOCCO,Reggisenal,YRN F.C.,Team Barco F.C.
10/09/2023 20.17.24,4483105,Patetico Mineiro,Paris Saint Germano,Team Barco F.C.,Real Pollo,Owl City,Ire Framba United,Reggisenal,Pompy FC,YRN F.C.,REAL DAVID,MedusaTeam WFC - IL BLOCCO,Godopolisportiva Antonio Ricci
11/09/2023 11.56.38,4480737,Ire Framba United,YRN F.C.,Patetico Mineiro,Godopolisportiva Antonio Ricci,Reggisenal,Paris Saint Germano,MedusaTeam WFC - IL BLOCCO,Team Barco F.C.,Real Pollo,Pompy FC,Owl City,REAL DAVID
11/09/2023 14.03.45,4485329,Owl City,Patetico Mineiro,Godopolisportiva Antonio Ricci,Real Pollo,Reggisenal,Pompy FC,Paris Saint Germano,YRN F.C.,Team Barco F.C.,Reggisenal,MedusaTeam WFC - IL BLOCCO,REAL DAVID
11/09/2023 14.25.31,5330685,Godopolisportiva Antonio Ricci,Patetico Mineiro,Pompy FC,Ire Framba United,MedusaTeam WFC - IL BLOCCO,Real Pollo,Reggisenal,Team Barco F.C.,YRN F.C.,Owl City,Paris Saint Germano,REAL DAVID
11/09/2023 14.27.22,9242836,YRN F.C.,Patetico Mineiro,Owl City,Pompy FC,Paris Saint Germano,Godopolisportiva Antonio Ricci,Ire Framba United,Real Pollo,MedusaTeam WFC - IL BLOCCO,Reggisenal,REAL DAVID,Team Barco F.C.
12/09/2023 11.57.35,4480837,Owl City,Pompy FC,Real Pollo,Team Barco F.C.,Reggisenal,Patetico Mineiro,Paris Saint Germano,Ire Framba United,Godopolisportiva Antonio Ricci,MedusaTeam WFC - IL BLOCCO,YRN F.C.,REAL DAVID
12/09/2023 16.07.17,10898860,Paris Saint Germano,Godopolisportiva Antonio Ricci,Real Pollo,Pompy FC,Patetico Mineiro,REAL DAVID,Ire Framba United,MedusaTeam WFC - IL BLOCCO,Patetico Mineiro,Reggisenal,Owl City,YRN F.C.
18/09/2023 2.53.31,4481779,Real Pollo,Paris Saint Germano,Owl City,REAL DAVID,Team Barco F.C.,Pompy FC,Godopolisportiva Antonio Ricci,Patetico Mineiro,YRN F.C.,Ire Framba United,Reggisenal,MedusaTeam WFC - IL BLOCCO
61 changes: 42 additions & 19 deletions python/pronostici/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import jinja2
from pathlib import Path

NUM_SQUADRE = 12


HERE_PATH = Path(__file__).parent.parent
OUTPUT_PATH = Path(__file__).parent.parent.parent / 'stagioni'
Expand Down Expand Up @@ -40,21 +42,21 @@ def generate_file(stagione, row, svg, stat):
title=title, permalink=permalink, stagione=stagione,
summary_link="{{ site.baseurl }}" + f"/{stagione}/pronostici/pronostici.html",
who=who, fantasquadre=fantasquadre_dict, svg=svg,
classifica=[row[f'{i}° classificato'] for i in range(1,11)],
average=stat["avg"], mediana=stat["mediana"])
classifica=[row[f'{i}° classificato'] for i in range(1,NUM_SQUADRE+1)],
average="{:.1f}".format(stat["avg"]), mediana=stat["mediana"])

out_f.write(outputText)


def generate_summary_file(stagione, svg):
def generate_summary_file(stagione, svg, classifica):
teamfile_path = HERE_PATH / 'data' / stagione / 'fantasquadre.yml'
fantasquadre_list = []
with open(teamfile_path.resolve(), 'r') as f:
data=yaml.safe_load(f)
fantasquadre_list = [dict(
id=id,
name=data[id]['name'],
link="{{ site.baseurl }}"+f"/stagione/pronostici/{id}.html"
link="{{ site.baseurl }}"+f"/{stagione}/pronostici/{id}.html"
) for id in data]

htmlfile_path = OUTPUT_PATH / stagione / 'pronostici' / 'pronostici.html'
Expand All @@ -66,7 +68,14 @@ def generate_summary_file(stagione, svg):

title = f"I pronostici della stagione {stagione}"
permalink = f'/{stagione}/pronostici/pronostici.html'
outputText = template.render(title=title, permalink=permalink, stagione=stagione, fantasquadre=fantasquadre_list, svg=svg)
outputText = template.render(
title=title,
permalink=permalink,
stagione=stagione,
fantasquadre=fantasquadre_list,
svg=svg,
classifica=classifica,
)

out_f.write(outputText)

Expand All @@ -83,15 +92,15 @@ def position2team(stagione, rows):
fantasquadre_dict = {id: data[id]['name'] for id in data}

freq_dict = {}
for position in range(1, 11):
for position in range(1, NUM_SQUADRE+1):
freq_dict[position] = {}
for row in rows:
id = int(row['Nome utente'])
fantasquadra = fantasquadre_dict[id]
freq_dict[position][fantasquadra] = 0

for row in rows:
for i in range(1,11):
for i in range(1,NUM_SQUADRE+1):
key = f'{i}° classificato'
fantasquadra = row[key]
freq_dict[i][fantasquadra] += 1
Expand All @@ -111,15 +120,14 @@ def team2position(stagione, rows):
fantasquadre_dict = {id: data[id]['name'] for id in data}

freq_dict = {}
for row in rows:
id = int(row['Nome utente'])
for id in fantasquadre_dict:
fantasquadra = fantasquadre_dict[id]
freq_dict[fantasquadra] = {}
for position in range(1, 11):
for position in range(1, NUM_SQUADRE+1):
freq_dict[fantasquadra][position] = 0

for row in rows:
for i in range(1,11):
for i in range(1,NUM_SQUADRE+1):
key = f'{i}° classificato'
fantasquadra = row[key]
freq_dict[fantasquadra][i] += 1
Expand Down Expand Up @@ -164,14 +172,15 @@ def export_all_files(stagione, rows):
def export_summary_file(stagione, rows):
svg = generate_histogram_svg_summary(stagione, rows)
clean_svg = svg.split("\n", 3)
generate_summary_file(stagione, clean_svg[3])
classifica = compute_classifica_totale(team2position(stagione, rows))
generate_summary_file(stagione, clean_svg[3], classifica)


def generate_histogram_svg(x, y):
# Return svg of the histogram x,y
f = io.BytesIO()
plt.figure()
plt.xticks(range(1,11))
plt.xticks(range(1,NUM_SQUADRE+1))
plt.yticks(range(0,max(y)+1))
plt.bar(x,y)
plt.savefig(f, format = "svg")
Expand All @@ -185,12 +194,12 @@ def generate_histogram_svg_summary(stagione, rows):

fig, (ax, lax) = plt.subplots(ncols=2, gridspec_kw={"width_ratios":[4, 1]})

x = list(range(1,11))
x = list(range(1,NUM_SQUADRE+1))
ax.set_xticks(x)
ax.set_xlabel('Posizione in classifica')

y = []
y_prev = [0 for i in range(10)]
y_prev = [0 for i in range(NUM_SQUADRE)]

for team, d in data.items():
y = list(d.values())
Expand All @@ -211,7 +220,7 @@ def stats(freqs):
res = {}

# weighted average
pos_freq = list(zip(range(1,11), freqs))
pos_freq = list(zip(range(1,NUM_SQUADRE+1), freqs))
inner_prod = map(lambda item: item[0]*item[1], pos_freq)
tot = sum((p for p in inner_prod))
res['avg'] = tot / len(freqs)
Expand All @@ -227,7 +236,21 @@ def stats(freqs):
return res


def compute_classifica_totale(freqs):
avg = {}
mediana = {}
for fantasquadra, f in freqs.items():
s = stats(f.values())
avg[fantasquadra] = s['avg']
mediana[fantasquadra] = s['mediana']

# sort teams based on this custom formula: mediana + avg / 10
index = {fs: mediana[fs] + avg[fs] / 10 for fs in freqs}
sorted_index = sorted(index.items(), key=lambda x:x[1])
return [f[0] for f in sorted_index]


if __name__ == "__main__":
rows = read_csv(stagione='2022_2023')
export_all_files(stagione='2022_2023', rows=rows)
export_summary_file(stagione='2022_2023', rows=rows)
rows = read_csv(stagione='2023_2024')
export_all_files(stagione='2023_2024', rows=rows)
export_summary_file(stagione='2023_2024', rows=rows)
2 changes: 1 addition & 1 deletion python/templates/pronostici_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- <a href="{{ fantasquadre[id].link }}">{{ fantasquadre[id].name }}</a>
{% endfor %}

<h1> I pronostici </h1>
<h1> I pronostici secondo {{ who }}</h1>
<ol>
{% for fantasquadra in classifica %}
<li>{{ fantasquadra }}</li>
Expand Down
17 changes: 15 additions & 2 deletions python/templates/pronostici_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@
permalink: {{ permalink }}
---

<div>
{% for fantasquadra in fantasquadre %}
- <a href="{{ fantasquadra.link }}">{{ fantasquadra.name }}</a>
<a href="{{ fantasquadra.link }}">{{ fantasquadra.name }}</a> -
{% endfor %}
</div>

{{ svg }}
<h1>La classifica statistica secondo i pronostici</h1>
<ol>
{% for fantasquadra in classifica %}
<li>{{ fantasquadra }}</li>
{% endfor %}
</ol>

<h1>Grafico dei pronostici</h1>
<p>Bello ma illeggibile...</p>
<div>
{{ svg }}
</div>
5 changes: 5 additions & 0 deletions stagioni/2023_2024/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: stagione
title: Stagione 2023_2024
---

Loading

0 comments on commit a145414

Please sign in to comment.