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 io
from collections import defaultdict
from contextlib import suppress
from datetime import datetime, timedelta
from typing import List
import matplotlib.pyplot as plt
import numpy as np
from . import config
@ -32,14 +32,13 @@ def graph(raid: List[dict]) -> None:
for class_name, players in encounter["buffs"].items():
for player_name, buffs in sorted(players.items()):
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:
try:
with suppress(KeyError): # KeyError on buff_id => buff not tracked
buff_name = buff_ids[buff_id]
except KeyError:
continue # buff not tracked
classes[real_class_name][player_name][buff_name].append(
(previous_encounter_date, (encounter_date - previous_encounter_date))
)
classes[real_class_name][player_name][buff_name].append(
(previous_encounter_date, (encounter_date - previous_encounter_date))
)
previous_encounter_date = encounter_date
for class_name, players in sorted(classes.items()):
@ -54,7 +53,7 @@ def graph(raid: List[dict]) -> None:
for b, (buff_name, buff) in enumerate(required_class_buffs.items()):
bar_color = "#{color}".format(**buff)
#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(
player_buffs[buff_name],
(bar_width/2 + y0 + b * bar_width, bar_width),
@ -75,12 +74,12 @@ def graph(raid: List[dict]) -> None:
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")
plt.xticks(*zip(*xticks), rotation=30, ha="right")
plt.yticks(
[x for x in np.arange(len(players))],
list(range(len(players))),
players
)
ax.invert_yaxis()
@ -89,7 +88,7 @@ def graph(raid: List[dict]) -> None:
plt.title(class_name, fontweight="bold", fontsize=16)
#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.show()