Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c26b218

Browse files
authored
Merge pull request #43 from nsec/bettergraph
Change "number of flags per value" to include the number of points to…
2 parents af1e8fd + b98b238 commit c26b218

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

ctf/stats.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,49 @@ 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()
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(
225+
list(stats["flag_count_per_value"].keys()),
226+
list(stats["flag_count_per_value"].values()),
227+
-width,
228+
label="Number of flags",
229+
color="blue",
230+
align="edge",
231+
)
232+
ax1.set_xlabel("Flag Value (points)")
233+
ax1.set_ylabel("Number of Flags", color="blue")
234+
ax1.tick_params(axis="y", labelcolor="blue")
235+
236+
ax2 = ax1.twinx()
237+
238+
ax2.bar(
239+
list(stats["flag_count_per_value"].keys()),
240+
number_of_points,
241+
width,
242+
label="Number of points",
243+
color="orange",
244+
align="edge",
218245
)
246+
ax2.set_xlabel("Flag Value")
247+
ax2.set_ylabel("Number of points", color="orange")
248+
ax2.tick_params(axis="y", labelcolor="orange")
249+
219250
plt.xticks(
220251
ticks=range(0, max(stats["flag_count_per_value"].keys()) + 1), rotation=45
221252
)
253+
222254
plt.grid(True, linestyle="--", alpha=0.3)
223255
plt.xlabel("Flag Value")
224-
plt.ylabel("Number of Flags")
225256
plt.title("Number of Flags per Value")
257+
fig.legend(loc="upper right")
258+
226259
plt.savefig(os.path.join(".charts", "flags_per_value.png"))
227260
plt.clf()
228261

0 commit comments

Comments
 (0)