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