Skip to content

Commit 33f2d4b

Browse files
committed
Change "number of flags per value" to include the number of points total for flags of value X.
Fixes #41.
1 parent af1e8fd commit 33f2d4b

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

ctf/stats.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,38 @@ def stats(
213213
mpl_logger.setLevel(logging.INFO)
214214
os.makedirs(name=".charts", exist_ok=True)
215215
# Flag count per value barchart
216-
plt.bar(
217-
stats["flag_count_per_value"].keys(), stats["flag_count_per_value"].values()
218-
)
216+
217+
fig, ax1 = plt.subplots()
218+
width = 0.3
219+
220+
number_of_points = []
221+
for value, count in stats["flag_count_per_value"].items():
222+
number_of_points.append(value * count)
223+
224+
ax1.bar(list(stats["flag_count_per_value"].keys()), list(stats["flag_count_per_value"].values()), -width,
225+
label="Number of points", color="blue", align="edge")
226+
ax1.set_xlabel("Flag Value (points)")
227+
ax1.set_ylabel("Number of Flags", color="blue")
228+
ax1.tick_params(axis='y', labelcolor="blue")
229+
230+
ax2 = ax1.twinx()
231+
232+
ax2.bar(list(stats["flag_count_per_value"].keys()), number_of_points, width, label="Number of flags",
233+
color="orange",
234+
align="edge")
235+
ax2.set_xlabel("Flag Value")
236+
ax2.set_ylabel("Number of points", color="orange")
237+
ax2.tick_params(axis='y', labelcolor="orange")
238+
219239
plt.xticks(
220240
ticks=range(0, max(stats["flag_count_per_value"].keys()) + 1), rotation=45
221241
)
242+
222243
plt.grid(True, linestyle="--", alpha=0.3)
223244
plt.xlabel("Flag Value")
224-
plt.ylabel("Number of Flags")
225245
plt.title("Number of Flags per Value")
246+
fig.legend(loc='upper right')
247+
226248
plt.savefig(os.path.join(".charts", "flags_per_value.png"))
227249
plt.clf()
228250

0 commit comments

Comments
 (0)