Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Commit ccd7588

Browse files
committed
add support for stacked bar plots in GH activity
1 parent cca9e07 commit ccd7588

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed

scripts/parse_github.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ def event_name_to_kind(event: str) -> GHIssueEventKind:
165165
case "ready_for_review":
166166
return GHIssueEventKind.READY_FOR_REVIEW
167167

168+
case "demilestoned":
169+
return GHIssueEventKind.DEMILESTONED
170+
168171
case _:
169172
assert False, event
170173

scripts/parse_github_sql_schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class GHIssueEventKind(IntEnum):
8484
MILESTONED = 22
8585
COMMENT_DELETED = 23
8686
READY_FOR_REVIEW = 24
87+
DEMILESTONED = 25
8788

8889

8990
class GHIssueEvent(SQLBase):

scripts/repository_activity.py

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,36 @@ def impl(args):
3333
session = Session()
3434
meta = SQLBase.metadata
3535
con = engine.connect()
36+
times = {}
3637

37-
times = {"comment": [], "pull": [], "issue": []}
38+
if True:
39+
# TODO add configuration argument to implement different
40+
# mapping strategies
41+
times = {"comment": [], "pull": [], "issue": [], "issue_event": []}
3842

39-
for name, time in times.items():
40-
for it in con.execute(sqa.select(meta.tables["comment"])):
41-
time.append(it.created_at)
43+
for name, time in times.items():
44+
for it in con.execute(sqa.select(meta.tables["comment"])):
45+
time.append(it.created_at)
46+
47+
elif False:
48+
created = []
49+
closed = []
50+
for it in con.execute(sqa.select(meta.tables["issue"])):
51+
created.append(it.created_at)
52+
if it.closed_at:
53+
closed.append(it.closed_at)
54+
55+
times = {"created": created, "closed": closed}
56+
57+
else:
58+
created = []
59+
closed = []
60+
for it in con.execute(sqa.select(meta.tables["pull"])):
61+
created.append(it.created_at)
62+
if it.closed_at:
63+
closed.append(it.closed_at)
64+
65+
times = {"created": created, "closed": closed}
4266

4367
for name, time in times.items():
4468
time = sorted(time)
@@ -60,15 +84,37 @@ def impl(args):
6084
)
6185

6286
fig, ax = plt.subplots(figsize=(12, 12))
63-
ax.stackplot(
64-
histogram_data[0][1][:-1],
65-
[it[0] for it in histogram_data],
66-
labels=[name for name, _ in times.items()],
67-
)
87+
label = [name for name, _ in times.items()]
88+
value = [it[0] for it in histogram_data]
89+
xdata = histogram_data[0][1][:-1]
90+
items = len(times)
91+
width = np.min(np.diff(xdata)) * 0.7
92+
93+
if False:
94+
for idx in range(items):
95+
if 0 < idx:
96+
value[idx] += value[idx - 1]
97+
98+
ax.stackplot(xdata, value, labels=label)
99+
100+
else:
101+
bottom = np.cumsum(
102+
[np.zeros(len(value[0])).astype(int)] + value, axis=0
103+
)
104+
105+
for idx in range(items):
106+
ax.bar(
107+
x=xdata,
108+
height=value[idx],
109+
bottom=bottom[idx],
110+
label=label[idx],
111+
width=width,
112+
edgecolor="black",
113+
)
68114

69115
ax.grid(True)
70116
cli.format_x_dates(ax)
71-
fig.legend()
117+
ax.legend(loc="upper left")
72118
fig.savefig(args.outfile, dpi=300, bbox_inches="tight")
73119

74120

scripts/table_per_period.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ def name_period(period: int) -> str:
166166
barplot.bar(
167167
index, # Indices for each sample point
168168
samples, # New sample information
169-
width=1.0, # Full width, otherwise bars will be misalingned with table change_periods
169+
width=1.0, # Full width, otherwise bars will be misalingned with
170+
# table change_periods
170171
bottom=y_offset, # baseline for bars
171172
color=colors[commit_idx], # Each comit period has it's own unique color
172173
edgecolor="black", # Distinct borders in case there are many periods

0 commit comments

Comments
 (0)