From 33f2d4b61d62094c9c0fc9664dc673d12967da36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milio=20Gonzalez?= Date: Mon, 15 Sep 2025 16:36:21 -0400 Subject: [PATCH 1/2] Change "number of flags per value" to include the number of points total for flags of value X. Fixes #41. --- ctf/stats.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/ctf/stats.py b/ctf/stats.py index 762d0a4..4fceb0d 100644 --- a/ctf/stats.py +++ b/ctf/stats.py @@ -213,16 +213,38 @@ def stats( mpl_logger.setLevel(logging.INFO) os.makedirs(name=".charts", exist_ok=True) # Flag count per value barchart - plt.bar( - stats["flag_count_per_value"].keys(), stats["flag_count_per_value"].values() - ) + + fig, ax1 = plt.subplots() + width = 0.3 + + number_of_points = [] + for value, count in stats["flag_count_per_value"].items(): + number_of_points.append(value * count) + + ax1.bar(list(stats["flag_count_per_value"].keys()), list(stats["flag_count_per_value"].values()), -width, + label="Number of points", color="blue", align="edge") + ax1.set_xlabel("Flag Value (points)") + ax1.set_ylabel("Number of Flags", color="blue") + ax1.tick_params(axis='y', labelcolor="blue") + + ax2 = ax1.twinx() + + ax2.bar(list(stats["flag_count_per_value"].keys()), number_of_points, width, label="Number of flags", + color="orange", + align="edge") + ax2.set_xlabel("Flag Value") + ax2.set_ylabel("Number of points", color="orange") + ax2.tick_params(axis='y', labelcolor="orange") + plt.xticks( ticks=range(0, max(stats["flag_count_per_value"].keys()) + 1), rotation=45 ) + plt.grid(True, linestyle="--", alpha=0.3) plt.xlabel("Flag Value") - plt.ylabel("Number of Flags") plt.title("Number of Flags per Value") + fig.legend(loc='upper right') + plt.savefig(os.path.join(".charts", "flags_per_value.png")) plt.clf() From b98b23843cf122d95bebaa355d16976d02dbbc84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milio=20Gonzalez?= Date: Mon, 15 Sep 2025 16:39:19 -0400 Subject: [PATCH 2/2] fix + ruff format --- ctf/stats.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/ctf/stats.py b/ctf/stats.py index 4fceb0d..66aecfe 100644 --- a/ctf/stats.py +++ b/ctf/stats.py @@ -221,20 +221,31 @@ def stats( for value, count in stats["flag_count_per_value"].items(): number_of_points.append(value * count) - ax1.bar(list(stats["flag_count_per_value"].keys()), list(stats["flag_count_per_value"].values()), -width, - label="Number of points", color="blue", align="edge") + ax1.bar( + list(stats["flag_count_per_value"].keys()), + list(stats["flag_count_per_value"].values()), + -width, + label="Number of flags", + color="blue", + align="edge", + ) ax1.set_xlabel("Flag Value (points)") ax1.set_ylabel("Number of Flags", color="blue") - ax1.tick_params(axis='y', labelcolor="blue") + ax1.tick_params(axis="y", labelcolor="blue") ax2 = ax1.twinx() - ax2.bar(list(stats["flag_count_per_value"].keys()), number_of_points, width, label="Number of flags", - color="orange", - align="edge") + ax2.bar( + list(stats["flag_count_per_value"].keys()), + number_of_points, + width, + label="Number of points", + color="orange", + align="edge", + ) ax2.set_xlabel("Flag Value") ax2.set_ylabel("Number of points", color="orange") - ax2.tick_params(axis='y', labelcolor="orange") + ax2.tick_params(axis="y", labelcolor="orange") plt.xticks( ticks=range(0, max(stats["flag_count_per_value"].keys()) + 1), rotation=45 @@ -243,7 +254,7 @@ def stats( plt.grid(True, linestyle="--", alpha=0.3) plt.xlabel("Flag Value") plt.title("Number of Flags per Value") - fig.legend(loc='upper right') + fig.legend(loc="upper right") plt.savefig(os.path.join(".charts", "flags_per_value.png")) plt.clf()