BigBrother: Fix graphing edge-cases.

This commit is contained in:
Casper V. Kristensen 2020-07-16 00:07:08 +02:00
parent fd14622a36
commit 4d6fc85ef2
Signed by: caspervk
GPG key ID: 289CA03790535054

View file

@ -1,11 +1,11 @@
import base64 import base64
import io import io
from collections import defaultdict from collections import defaultdict
from contextlib import suppress
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import List from typing import List
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np
from . import config from . import config
@ -32,11 +32,10 @@ def graph(raid: List[dict]) -> None:
for class_name, players in encounter["buffs"].items(): for class_name, players in encounter["buffs"].items():
for player_name, buffs in sorted(players.items()): for player_name, buffs in sorted(players.items()):
real_class_name = config.class_overrides.get(player_name, str.title(class_name)) real_class_name = config.class_overrides.get(player_name, str.title(class_name))
classes[real_class_name][player_name] # ensure player is added, irregardless if they have any buffs
for buff_id in buffs: for buff_id in buffs:
try: with suppress(KeyError): # KeyError on buff_id => buff not tracked
buff_name = buff_ids[buff_id] buff_name = buff_ids[buff_id]
except KeyError:
continue # buff not tracked
classes[real_class_name][player_name][buff_name].append( classes[real_class_name][player_name][buff_name].append(
(previous_encounter_date, (encounter_date - previous_encounter_date)) (previous_encounter_date, (encounter_date - previous_encounter_date))
) )
@ -54,7 +53,7 @@ def graph(raid: List[dict]) -> None:
for b, (buff_name, buff) in enumerate(required_class_buffs.items()): for b, (buff_name, buff) in enumerate(required_class_buffs.items()):
bar_color = "#{color}".format(**buff) bar_color = "#{color}".format(**buff)
#legend_handles.append(Patch(label=buff_name, color=bar_color)) #legend_handles.append(Patch(label=buff_name, color=bar_color))
for y0, (player_name, player_buffs) in zip(np.arange(len(players)), players.items()): for y0, (player_name, player_buffs) in enumerate(players.items()):
ax.broken_barh( ax.broken_barh(
player_buffs[buff_name], player_buffs[buff_name],
(bar_width/2 + y0 + b * bar_width, bar_width), (bar_width/2 + y0 + b * bar_width, bar_width),
@ -75,12 +74,12 @@ def graph(raid: List[dict]) -> None:
color=annotation_color color=annotation_color
) )
for y0 in np.arange(len(players)): for y0 in range(len(players) + 1):
ax.axhline(y=y0, linewidth=1.0, color="black") ax.axhline(y=y0, linewidth=1.0, color="black")
plt.xticks(*zip(*xticks), rotation=30, ha="right") plt.xticks(*zip(*xticks), rotation=30, ha="right")
plt.yticks( plt.yticks(
[x for x in np.arange(len(players))], list(range(len(players))),
players players
) )
ax.invert_yaxis() ax.invert_yaxis()
@ -89,7 +88,7 @@ def graph(raid: List[dict]) -> None:
plt.title(class_name, fontweight="bold", fontsize=16) plt.title(class_name, fontweight="bold", fontsize=16)
#plt.legend(handles=legend_handles, bbox_to_anchor=(1, 1)) #plt.legend(handles=legend_handles, bbox_to_anchor=(1, 1))
fig.set_size_inches(15, 2*len(players)) fig.set_size_inches(15, 2 + len(players) * 2)
plt.tight_layout() plt.tight_layout()
#plt.show() #plt.show()