@@ -20,7 +20,10 @@ tags: [remove-cell]
2020
2121import json
2222import functools
23+ import datetime
24+
2325import numpy as np
26+ import matplotlib.pyplot as plt
2427from myst_nb import glue
2528
2629glue = functools.partial(glue, display=False)
@@ -57,11 +60,45 @@ tags: [hide-input]
5760newly_created = [
5861 iss for iss in issues if np.datetime64(iss["createdAt"]) > query_date
5962]
60- num_closed = sum(iss["state"] == "CLOSED" for iss in newly_created)
63+ new_issues_closed = [iss for iss in newly_created if iss["state"] == "CLOSED"]
64+
65+ new_issue_lifetime = np.array(
66+ [
67+ np.datetime64(iss["closedAt"]) - np.datetime64(iss["createdAt"])
68+ for iss in new_issues_closed
69+ ],
70+ ).astype("m8[h]") # in hours
6171
6272glue("num_new_issues", len(newly_created))
63- glue("num_new_issues_closed", f"{num_closed} ({100 * num_closed / len(newly_created)}%)")
73+ glue(
74+ "num_new_issues_closed",
75+ f"{len(new_issues_closed)} ({100 * len(new_issues_closed) / len(newly_created)}%)"
76+ )
77+ glue("new_issue_avg_lifetime", f"{np.mean(new_issue_lifetime)}")
6478```
6579
66- {glue: text }` num_new_issues ` have been opened since {glue: text }` query_date ` , of
67- which {glue: text }` num_new_issues_closed ` have been closed.
80+ {glue: text }` num_new_issues ` new issues have been opened since
81+ {glue: text }` query_date ` , of which {glue: text }` num_new_issues_closed ` have been
82+ closed.
83+
84+ The average lifetime of new issues that were created and closed in this period
85+ is {glue: text }` new_issue_avg_lifetime ` .
86+
87+ % TODO: replace with bokeh or some other live-plot
88+ % TODO: for any remaining static/mpl plots, set default params for things
89+ % like fontsize in a mplstyle file.
90+
91+ ``` {code-cell} ipython3
92+ ---
93+ tags: [hide-input]
94+ ---
95+ fig, ax = plt.subplots(figsize=(16, 12))
96+ ax.hist(new_issue_lifetime.astype("m8[D]").astype(int), bins=np.arange(30))
97+ ax.set_title(
98+ f"Lifetime of issues created and closed in the last "
99+ f"{(np.datetime64(datetime.datetime.now()) - query_date).astype('m8[D]')}",
100+ fontsize=24
101+ )
102+ ax.set_xlabel("Issue lifetime (days)", fontsize=20)
103+ ax.set_ylabel(r"$\frac{issues}{day}$", fontsize=20);
104+ ```
0 commit comments