Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/jamstats_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.5.1
3.5.2
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='jamstats',
version='3.5.1',
version='3.5.2',
description='Data processing, stats and plots on roller derby scoreboard JSON files',
author='Damon May',
package_dir={"":"src"},
Expand Down
2 changes: 1 addition & 1 deletion setup_nogui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='jamstats-nogui',
version='3.5.1',
version='3.5.2',
description='Data processing, stats and plots on roller derby scoreboard JSON files. No-GUI version.',
author='Damon May',
package_dir={"":"src"},
Expand Down
13 changes: 7 additions & 6 deletions src/jamstats/plots/advanced_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import pandas as pd
from jamstats.plots.plot_util import (
make_team_color_palette,
wordwrap_x_labels
wordwrap_x_labels,
remove_ax_legend
)
from jamstats.plots.plot_util import DerbyPlot
import matplotlib.patches as mpatches
Expand Down Expand Up @@ -56,7 +57,7 @@ def plot(self, derby_game: DerbyGame) -> Figure:
sum(pdf_jammer_jamcounts.team == derby_game.team_2_name)]
}), hue="team",
ax=ax, palette=team_color_palette)
ax.get_legend().remove()
remove_ax_legend(ax)
# word-wrap too-long team names
wordwrap_x_labels(ax)
ax.set_title("Jammers per team")
Expand All @@ -65,7 +66,7 @@ def plot(self, derby_game: DerbyGame) -> Figure:
sns.violinplot(x="team", y="jam_count", data=pdf_jammer_jamcounts, cut=0, ax=ax,
hue="team",
palette=team_color_palette, inner="stick")
ax.get_legend().remove()
remove_ax_legend(ax)
ax.set_title("Jams per jammer")
ax.set_ylabel("Jams per jammer")
# word-wrap too-long team names
Expand All @@ -90,7 +91,7 @@ def plot(self, derby_game: DerbyGame) -> Figure:
ax.set_xlabel("# jams")
# word-wrap too-long team names
wordwrap_x_labels(ax)
ax.legend().remove()
remove_ax_legend(ax)

f.set_size_inches(14,6)
f.tight_layout()
Expand Down Expand Up @@ -181,7 +182,7 @@ def plot(self, derby_game: DerbyGame) -> Figure:
for i in range(len(pdf_jambools.columns)):
ax.text(i + 0.25, -.5, pdf_jambools.columns[i], rotation=90, size="large")

ax.get_legend().remove()
remove_ax_legend(ax)
ax.set_xlabel("")
ax.set_ylabel("")
ax.set_xticks([x+.5 for x in range(len(pdf_jambool_heatmap.columns))])
Expand Down Expand Up @@ -295,7 +296,7 @@ def plot(self, derby_game: DerbyGame) -> Figure:
inner="stick", palette=team_color_palette)
ax.set_ylabel("Time to Initial (s)")
ax.set_title("Time to Initial per jam")
ax.get_legend().remove()
remove_ax_legend(ax)
# word-wrap too-long team names
wordwrap_x_labels(ax)

Expand Down
25 changes: 16 additions & 9 deletions src/jamstats/plots/basic_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import logging
from jamstats.plots.plot_util import (
make_team_color_palette,
wordwrap_x_labels
wordwrap_x_labels,
remove_ax_legend,
add_number_to_barplot
)
import matplotlib.patches as mpatches
from matplotlib.pyplot import Figure
Expand Down Expand Up @@ -62,38 +64,43 @@ def plot(self, derby_game: DerbyGame) -> Figure:
ax = ax0
sns.barplot(y="Jammer", x="Jams", hue="Jammer",
data=pdf_jammer_data, ax=ax, palette=mypalette)
add_number_to_barplot(ax, pdf_jammer_data, "Jams")
ax.set_ylabel("")
ax.get_legend().remove()
remove_ax_legend(ax)

ax = ax1
sns.barplot(y="Jammer", x="Total Score", hue="Jammer",
data=pdf_jammer_data, ax=ax, palette=mypalette)
add_number_to_barplot(ax, pdf_jammer_data, "Total Score")
ax.set_yticks([])
ax.set_ylabel("")
ax.get_legend().remove()
remove_ax_legend(ax)

ax = ax2
sns.barplot(y="Jammer", x="Mean Net Points", hue="Jammer",
data=pdf_jammer_data, ax=ax, palette=mypalette)
add_number_to_barplot(ax, pdf_jammer_data, "Mean Net Points")
ax.set_xlabel("Mean Net Points/Jam\n(own - opposing)")
ax.set_yticks([])
ax.set_ylabel("")
ax.get_legend().remove()
remove_ax_legend(ax)

ax = ax3
sns.barplot(y="Jammer", x="Proportion Lead", hue="Jammer",
data=pdf_jammer_data, ax=ax, palette=mypalette)
add_number_to_barplot(ax, pdf_jammer_data, "Proportion Lead")
ax.set_xlim(0,1)
ax.set_yticks([])
ax.set_ylabel("")
ax.get_legend().remove()
remove_ax_legend(ax)

ax = ax4
sns.barplot(y="Jammer", x="Mean Time to Initial", hue="Jammer",
data=pdf_jammer_data, ax=ax, palette=mypalette)
add_number_to_barplot(ax, pdf_jammer_data, "Mean Time to Initial")
ax.set_yticks([])
ax.set_ylabel("")
ax.get_legend().remove()
remove_ax_legend(ax)

f.set_size_inches(16, min(2 + len(pdf_jammer_data), 11))
f.suptitle(f"Jammer Stats: {team_name}")
Expand Down Expand Up @@ -216,7 +223,7 @@ def plot(self, derby_game: DerbyGame) -> Figure:
sns.barplot(y="prd_jam", x="Team with Lead", hue="Team with Lead",
data=pdf_for_plot_lost, ax=ax, palette='dark:black')
if ax.get_legend() is not None:
ax.get_legend().remove()
remove_ax_legend(ax)

ax.set_ylabel("Jams")
ax.set_title("Jams with Lead\n(black=lost, gray=not called)")
Expand Down Expand Up @@ -426,8 +433,8 @@ def plot(self, derby_game: DerbyGame) -> Figure:

penalty_plot_is_go = True
except Exception as e:
logger.warn(f"Failed to make skater penalty subplot:")
logger.warn(traceback.format_exc())
logger.warning(f"Failed to make skater penalty subplot:")
logger.warning(traceback.format_exc())

f, dummy_axis = plt.subplots()
dummy_axis.set_xticks([])
Expand Down
41 changes: 41 additions & 0 deletions src/jamstats/plots/plot_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from matplotlib.pyplot import Figure
from pandas.api.types import CategoricalDtype
from PIL import ImageColor
import pandas as pd

from abc import ABC, abstractmethod

Expand Down Expand Up @@ -209,6 +210,46 @@ def build_anonymizer_map(names: Iterable[str]) -> Dict[str, str]:
for i in range(len(names_set_list))
}

def remove_ax_legend(ax):
"""Utility method to remove a legend from an ax, and fail silently.

Args:
ax: _description_
"""
try:
ax.get_legend().remove()
except Exception:
pass

def add_number_to_barplot(ax, pdf: pd.DataFrame, column: str):
"""Utility method to add a number to a barplot, derived
from a column in a pdf

Args:
ax: ax containing a barplot
pdf (pd.DataFrame): dataframe
column (str): column name
"""
numbers = list(pdf[column])
max_val = max(numbers)
text_x_pos = max_val / 10

vals_are_ints = True
for number in numbers:
if int(number) != number:
vals_are_ints = False
break
if vals_are_ints:
number_strs = [str(x) for x in numbers]
else:
number_strs = [f"{x:.1f}" for x in numbers]
for i in range(len(numbers)):
if number_strs[i] == "nan":
number_strs[i] = ""
ax.text(text_x_pos, i, number_strs[i], size="small",
horizontalalignment="left",
verticalalignment="center")


ANONYMIZED_SKATER_NAMES = [
"Middle Skull Crush",
Expand Down
2 changes: 1 addition & 1 deletion src/jamstats/resources/jamstats_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.5.1
3.5.2