NL
This commit is contained in:
parent
f0f5370b0b
commit
992164006a
@ -55,8 +55,7 @@ import networkx as nx
|
||||
import matplotlib.pyplot as plt
|
||||
from datetime import timedelta
|
||||
|
||||
# %%
|
||||
scenario = Scenario.objects.get(id=9541)
|
||||
# %%scenario = Scenario.objects.get(id=9541)
|
||||
season = scenario.season
|
||||
|
||||
teams = Team.objects.filter(season=season,active=True).order_by('pot')
|
||||
@ -81,13 +80,13 @@ for scenario in season.scenarios.all():
|
||||
teams_in_group_together[(t1,t2)] += 1
|
||||
for wish in EncWish.objects.filter(scenario=scenario).exclude(violation="").order_by('prio'):
|
||||
violated_wishes[f"{wish.reason}"]['violations'] += 1
|
||||
violated_wishes[f"{wish.reason}"]['comments'][wish.violation] += 1
|
||||
violated_wishes[f"{wish.reason}"]['comments'][wish.violation.strip()] += 1
|
||||
for wish in HAWish.objects.filter(scenario=scenario).exclude(violation="").order_by('prio'):
|
||||
violated_wishes[f"{wish.reason}"]['violations'] += 1
|
||||
violated_wishes[f"{wish.reason}"]['comments'][wish.violation] += 1
|
||||
violated_wishes[f"{wish.reason}"]['comments'][wish.violation.strip()] += 1
|
||||
for wish in Pairing.objects.filter(scenario=scenario).exclude(violation="").order_by('prio'):
|
||||
violated_wishes[f"{wish.comment}"]['violations'] += 1
|
||||
violated_wishes[f"{wish.comment}"]['comments'][wish.violation] += 1
|
||||
violated_wishes[f"{wish.comment}"]['comments'][wish.violation.strip()] += 1
|
||||
for game in scenario.solutionlist():
|
||||
blockings = Blocking.objects.filter(scenario=scenario,day__id=game[0]).filter(Q(team=game[1],type="Home") | Q(team=game[1],type="Away"))
|
||||
if blockings:
|
||||
@ -95,17 +94,24 @@ for scenario in season.scenarios.all():
|
||||
violated_blockings[b.team]['violations'] += 1
|
||||
violated_blockings[b.team]['comments'][f"{b.type} - {b.day}"] += 1
|
||||
|
||||
|
||||
for key,val in violated_wishes.items():
|
||||
for k,v in val['comments'].items():
|
||||
suffix = ""
|
||||
for i in k.split("<br>"):
|
||||
if i == "":
|
||||
continue
|
||||
elif i in ["1 too many","1 too few"]:
|
||||
suffix = f": {i}"
|
||||
continue
|
||||
elementary_violations[key][f"{i}{suffix}"] += v
|
||||
for key,val in violated_wishes.items():
|
||||
for k,v in val['comments'].items():
|
||||
suffix = ""
|
||||
for i in k.split("<br>"):
|
||||
if i == "":
|
||||
continue
|
||||
elif i in ["1 too many","1 too few"]:
|
||||
suffix = f": {i}"
|
||||
continue
|
||||
else:
|
||||
split_vio = i.split(":")
|
||||
try:
|
||||
day_str = datetime.datetime.strptime(split_vio[0].strip(),"%a, %b %d, %Y")
|
||||
vio = ":".join(split_vio[1:])
|
||||
except:
|
||||
vio = ":".join(split_vio[0:])
|
||||
|
||||
elementary_violations[key][f"{vio}{suffix}"] += v
|
||||
|
||||
|
||||
|
||||
@ -132,7 +138,7 @@ def heatmap_color_for(value):
|
||||
if value > 0.5:
|
||||
g = 2*(1-min(1,value))*256
|
||||
r = 256
|
||||
return f"rgb({r},{g},{0})"
|
||||
return f"rgb({r},{g},{0},0.5)"
|
||||
|
||||
|
||||
def percentage(value):
|
||||
@ -164,7 +170,7 @@ sol += " \
|
||||
"
|
||||
sol += "</head><body>"
|
||||
sol += "<h2>Probabilities of games</h2>"
|
||||
sol += "<table id='etable' style='border:5px solid black'>\n"
|
||||
sol += "<table id='etable' style='border:5px solid black;background-color:whitesmoke'>\n"
|
||||
sol += "<thead>\n"
|
||||
sol += "<tr>"
|
||||
sol += f"<th>{nSimulations}</th>"
|
||||
@ -185,10 +191,12 @@ for t1 in teams:
|
||||
sol += f"<td>{t1.shortname}</td>"
|
||||
for t2 in teams:
|
||||
color = heatmap_color_for((abs(teams_in_group_together[(t1,t2)]-(maxVal+minVal)/2))/((maxVal-minVal)/2 or 1))
|
||||
opacity = "1"
|
||||
if teams_in_group_together[(t1,t2)] == 0:
|
||||
color = 'grey'
|
||||
color = 'Gainsboro'
|
||||
opacity = "0.7"
|
||||
val = f"{percentage(teams_in_group_together[(t1,t2)])}"
|
||||
sol += f"<td style='background-color:{color}'>{val}</td>"
|
||||
sol += f"<td style='background-color:{color};opacity:{opacity}'>{val}</td>"
|
||||
sol += "</tr>\n"
|
||||
|
||||
sol += "</tbody>\n"
|
||||
@ -258,6 +266,10 @@ sol += "</tbody>\n"
|
||||
sol += "</table>\n"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
with open(f'analytics.html', 'w') as f:
|
||||
f.write(sol)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user