Skip to content

Commit

Permalink
compute summary chart from all the inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
andregri committed Sep 20, 2023
1 parent fa52f87 commit 477f21b
Show file tree
Hide file tree
Showing 14 changed files with 587 additions and 525 deletions.
30 changes: 26 additions & 4 deletions python/pronostici/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def generate_file(stagione, row, svg, stat):
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:
Expand All @@ -68,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 Down Expand Up @@ -165,7 +172,8 @@ 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):
Expand Down Expand Up @@ -228,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='2023_2024')
export_all_files(stagione='2023_2024', rows=rows)
export_summary_file(stagione='2023_2024', rows=rows)
export_summary_file(stagione='2023_2024', rows=rows)
11 changes: 10 additions & 1 deletion python/templates/pronostici_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
{% endfor %}
</div>

<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>
</div>
64 changes: 32 additions & 32 deletions stagioni/2023_2024/pronostici/10898860.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<cc:Work>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:date>2023-09-20T22:27:55.373153</dc:date>
<dc:date>2023-09-20T23:02:57.722981</dc:date>
<dc:format>image/svg+xml</dc:format>
<dc:creator>
<cc:Agent>
Expand Down Expand Up @@ -110,106 +110,106 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
L 95.843205 223.104
L 73.832727 223.104
z
" clip-path="url(#pdd247f2146)" style="fill: #1f77b4"/>
" clip-path="url(#p8404feef85)" style="fill: #1f77b4"/>
</g>
<g id="patch_4">
<path d="M 101.345824 307.584
L 123.356302 307.584
L 123.356302 223.104
L 101.345824 223.104
z
" clip-path="url(#pdd247f2146)" style="fill: #1f77b4"/>
" clip-path="url(#p8404feef85)" style="fill: #1f77b4"/>
</g>
<g id="patch_5">
<path d="M 128.858921 307.584
L 150.869399 307.584
L 150.869399 307.584
L 128.858921 307.584
z
" clip-path="url(#pdd247f2146)" style="fill: #1f77b4"/>
" clip-path="url(#p8404feef85)" style="fill: #1f77b4"/>
</g>
<g id="patch_6">
<path d="M 156.372018 307.584
L 178.382496 307.584
L 178.382496 307.584
L 156.372018 307.584
z
" clip-path="url(#pdd247f2146)" style="fill: #1f77b4"/>
" clip-path="url(#p8404feef85)" style="fill: #1f77b4"/>
</g>
<g id="patch_7">
<path d="M 183.885116 307.584
L 205.895593 307.584
L 205.895593 307.584
L 183.885116 307.584
z
" clip-path="url(#pdd247f2146)" style="fill: #1f77b4"/>
" clip-path="url(#p8404feef85)" style="fill: #1f77b4"/>
</g>
<g id="patch_8">
<path d="M 211.398213 307.584
L 233.40869 307.584
L 233.40869 307.584
L 211.398213 307.584
z
" clip-path="url(#pdd247f2146)" style="fill: #1f77b4"/>
" clip-path="url(#p8404feef85)" style="fill: #1f77b4"/>
</g>
<g id="patch_9">
<path d="M 238.91131 307.584
L 260.921787 307.584
L 260.921787 223.104
L 238.91131 223.104
z
" clip-path="url(#pdd247f2146)" style="fill: #1f77b4"/>
" clip-path="url(#p8404feef85)" style="fill: #1f77b4"/>
</g>
<g id="patch_10">
<path d="M 266.424407 307.584
L 288.434884 307.584
L 288.434884 223.104
L 266.424407 223.104
z
" clip-path="url(#pdd247f2146)" style="fill: #1f77b4"/>
" clip-path="url(#p8404feef85)" style="fill: #1f77b4"/>
</g>
<g id="patch_11">
<path d="M 293.937504 307.584
L 315.947982 307.584
L 315.947982 54.144
L 293.937504 54.144
z
" clip-path="url(#pdd247f2146)" style="fill: #1f77b4"/>
" clip-path="url(#p8404feef85)" style="fill: #1f77b4"/>
</g>
<g id="patch_12">
<path d="M 321.450601 307.584
L 343.461079 307.584
L 343.461079 223.104
L 321.450601 223.104
z
" clip-path="url(#pdd247f2146)" style="fill: #1f77b4"/>
" clip-path="url(#p8404feef85)" style="fill: #1f77b4"/>
</g>
<g id="patch_13">
<path d="M 348.963698 307.584
L 370.974176 307.584
L 370.974176 138.624
L 348.963698 138.624
z
" clip-path="url(#pdd247f2146)" style="fill: #1f77b4"/>
" clip-path="url(#p8404feef85)" style="fill: #1f77b4"/>
</g>
<g id="patch_14">
<path d="M 376.476795 307.584
L 398.487273 307.584
L 398.487273 223.104
L 376.476795 223.104
z
" clip-path="url(#pdd247f2146)" style="fill: #1f77b4"/>
" clip-path="url(#p8404feef85)" style="fill: #1f77b4"/>
</g>
<g id="matplotlib.axis_1">
<g id="xtick_1">
<g id="line2d_1">
<defs>
<path id="m2b95f16615" d="M 0 0
<path id="mee9be50a7d" d="M 0 0
L 0 3.5
" style="stroke: #000000; stroke-width: 0.8"/>
</defs>
<g>
<use xlink:href="#m2b95f16615" x="84.837966" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mee9be50a7d" x="84.837966" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_1">
Expand Down Expand Up @@ -238,7 +238,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="xtick_2">
<g id="line2d_2">
<g>
<use xlink:href="#m2b95f16615" x="112.351063" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mee9be50a7d" x="112.351063" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_2">
Expand Down Expand Up @@ -277,7 +277,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="xtick_3">
<g id="line2d_3">
<g>
<use xlink:href="#m2b95f16615" x="139.86416" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mee9be50a7d" x="139.86416" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_3">
Expand Down Expand Up @@ -324,7 +324,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="xtick_4">
<g id="line2d_4">
<g>
<use xlink:href="#m2b95f16615" x="167.377257" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mee9be50a7d" x="167.377257" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_4">
Expand Down Expand Up @@ -358,7 +358,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="xtick_5">
<g id="line2d_5">
<g>
<use xlink:href="#m2b95f16615" x="194.890354" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mee9be50a7d" x="194.890354" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_5">
Expand Down Expand Up @@ -398,7 +398,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="xtick_6">
<g id="line2d_6">
<g>
<use xlink:href="#m2b95f16615" x="222.403451" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mee9be50a7d" x="222.403451" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_6">
Expand Down Expand Up @@ -443,7 +443,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="xtick_7">
<g id="line2d_7">
<g>
<use xlink:href="#m2b95f16615" x="249.916549" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mee9be50a7d" x="249.916549" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_7">
Expand All @@ -468,7 +468,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="xtick_8">
<g id="line2d_8">
<g>
<use xlink:href="#m2b95f16615" x="277.429646" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mee9be50a7d" x="277.429646" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_8">
Expand Down Expand Up @@ -522,7 +522,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="xtick_9">
<g id="line2d_9">
<g>
<use xlink:href="#m2b95f16615" x="304.942743" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mee9be50a7d" x="304.942743" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_9">
Expand Down Expand Up @@ -567,7 +567,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="xtick_10">
<g id="line2d_10">
<g>
<use xlink:href="#m2b95f16615" x="332.45584" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mee9be50a7d" x="332.45584" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_10">
Expand Down Expand Up @@ -604,7 +604,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="xtick_11">
<g id="line2d_11">
<g>
<use xlink:href="#m2b95f16615" x="359.968937" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mee9be50a7d" x="359.968937" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_11">
Expand All @@ -618,7 +618,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="xtick_12">
<g id="line2d_12">
<g>
<use xlink:href="#m2b95f16615" x="387.482034" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mee9be50a7d" x="387.482034" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_12">
Expand All @@ -634,12 +634,12 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="ytick_1">
<g id="line2d_13">
<defs>
<path id="m615640bf77" d="M 0 0
<path id="mbbde0a242d" d="M 0 0
L -3.5 0
" style="stroke: #000000; stroke-width: 0.8"/>
</defs>
<g>
<use xlink:href="#m615640bf77" x="57.6" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mbbde0a242d" x="57.6" y="307.584" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_13">
Expand All @@ -652,7 +652,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="ytick_2">
<g id="line2d_14">
<g>
<use xlink:href="#m615640bf77" x="57.6" y="223.104" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mbbde0a242d" x="57.6" y="223.104" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_14">
Expand All @@ -665,7 +665,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="ytick_3">
<g id="line2d_15">
<g>
<use xlink:href="#m615640bf77" x="57.6" y="138.624" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mbbde0a242d" x="57.6" y="138.624" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_15">
Expand All @@ -678,7 +678,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
<g id="ytick_4">
<g id="line2d_16">
<g>
<use xlink:href="#m615640bf77" x="57.6" y="54.144" style="stroke: #000000; stroke-width: 0.8"/>
<use xlink:href="#mbbde0a242d" x="57.6" y="54.144" style="stroke: #000000; stroke-width: 0.8"/>
</g>
</g>
<g id="text_16">
Expand Down Expand Up @@ -712,7 +712,7 @@ <h1> Come è stato pronosticato YRN F.C.? </h1>
</g>
</g>
<defs>
<clipPath id="pdd247f2146">
<clipPath id="p8404feef85">
<rect x="57.6" y="41.472" width="357.12" height="266.112"/>
</clipPath>
</defs>
Expand Down
Loading

0 comments on commit 477f21b

Please sign in to comment.