From 4d6fc85ef21378f62129961c59c822ac6362dd4f Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Thu, 16 Jul 2020 00:07:08 +0200 Subject: [PATCH] BigBrother: Fix graphing edge-cases. --- BigBrother/bb/graph.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/BigBrother/bb/graph.py b/BigBrother/bb/graph.py index 7be4ee2..a2d88e0 100644 --- a/BigBrother/bb/graph.py +++ b/BigBrother/bb/graph.py @@ -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()