ibitfit/analytics.py

48 lines
1.4 KiB
Python

import argparse
import pathlib
import numpy as np
import matplotlib.pyplot as plt
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Analyze high score data",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
"data",
type=argparse.FileType("r"),
help="File containing score data")
parser.add_argument(
"--bins",
nargs="+",
type=int,
default=[10, 30, 60, 120],
help="Bins to sort data into. The min and max values will be added automatically. See matplotlib.pyplot.hist.")
cli = parser.parse_args()
scores: np.ndarray[tuple[int]] = np.array([])
for line in cli.data:
timestamp, score, initials = line.split()
scores = np.append(scores, int(score))
print(f"There are {scores.size} total scores recorded")
print(f"The highest score is {scores.max()}")
print(f"The lowest score is {scores.min()}")
print(f"The average score is {scores.mean()}")
print(f"The median score is {np.median(scores)}")
bins: list[int] = [scores.min()] + cli.bins + [scores.max()]
fig, ax = plt.subplots()
ax.set_xticks(bins)
ax.hist(scores, bins=bins, facecolor="gray", edgecolor="black", linewidth=4)
ax.set_ylabel("Count")
ax.set_xlabel("Score")
plt.title(f"BiTFiT scores MAGFest 2025 ({scores.size} total)")
plt.show()
# LocalWords: matplotlib pyplot