Skip to content

Commit 0e9c2aa

Browse files
Copilotxadupre
andauthored
Add line chart comparing weekly PR counts across repos
Agent-Logs-Url: https://github.com/sdpython/teachpyx/sessions/78df380d-d74e-4801-8672-455b68860a6a Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
1 parent 75689ae commit 0e9c2aa

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

_doc/practice/years/2026/github_stat_pr.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
3131
* ``github_stat_pr_bar.png`` — diagramme empilé (toutes repos confondues)
3232
* ``github_stat_pr_heatmap.png`` — heatmap (toutes repos confondues)
33+
* ``github_stat_pr_lines.png`` — graphe en lignes comparant les dépôts
3334
* ``github_stat_pr_bar_{owner}_{repo}.png`` — diagramme empilé par dépôt
3435
* ``github_stat_pr_heatmap_{owner}_{repo}.png`` — heatmap par dépôt
3536
"""
@@ -320,6 +321,46 @@ def plot_heatmap(pivot: pd.DataFrame, title: str, output_path: pathlib.Path) ->
320321
print(f" → {output_path}")
321322

322323

324+
def plot_lines_by_repo(
325+
weekly: pd.DataFrame, title: str, output_path: pathlib.Path
326+
) -> None:
327+
"""Graphe en lignes : total de PR fusionnées par semaine pour chaque dépôt.
328+
329+
Chaque dépôt est représenté par une ligne, ce qui permet de comparer
330+
visuellement l'activité entre dépôts.
331+
"""
332+
repo_weekly = (
333+
weekly.groupby(["repo", "week"])["pr_count"].sum().reset_index()
334+
)
335+
all_weeks = sorted(repo_weekly["week"].unique())
336+
337+
fig, ax = plt.subplots(figsize=(14, 5))
338+
for repo_name, grp in repo_weekly.groupby("repo"):
339+
grp_indexed = grp.set_index("week").reindex(all_weeks, fill_value=0)
340+
week_nums = mdates.date2num(
341+
pd.to_datetime(grp_indexed.index).to_pydatetime()
342+
)
343+
ax.plot(
344+
week_nums,
345+
grp_indexed["pr_count"].values,
346+
marker="o",
347+
markersize=3,
348+
label=repo_name,
349+
)
350+
351+
ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y-%m-%d"))
352+
ax.xaxis.set_major_locator(mdates.WeekdayLocator(byweekday=mdates.MO, interval=4))
353+
plt.xticks(rotation=45, ha="right")
354+
ax.set_xlabel("Semaine")
355+
ax.set_ylabel("Nombre de PR fusionnées")
356+
ax.set_title(title)
357+
ax.legend(loc="upper left", bbox_to_anchor=(1, 1), title="Dépôt")
358+
plt.tight_layout()
359+
plt.savefig(output_path, dpi=150)
360+
plt.close(fig)
361+
print(f" → {output_path}")
362+
363+
323364
# ---------------------------------------------------------------------------
324365
# Point d'entrée
325366
# ---------------------------------------------------------------------------
@@ -365,6 +406,14 @@ def main() -> None:
365406
OUTPUT_DIR / "github_stat_pr_heatmap.png",
366407
)
367408

409+
# 4b. Graphe en lignes comparant les dépôts (toujours affiché si plusieurs repos)
410+
if len(REPOS) > 1:
411+
plot_lines_by_repo(
412+
weekly,
413+
"PR fusionnées par semaine — comparaison entre dépôts",
414+
OUTPUT_DIR / "github_stat_pr_lines.png",
415+
)
416+
368417
# 5. Graphiques par dépôt (si plusieurs dépôts)
369418
if len(REPOS) > 1:
370419
print("\nGénération des graphiques par dépôt…")

_doc/practice/years/2026/github_stat_pr.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Images générées :
2424

2525
* ``github_stat_pr_bar.png`` — diagramme empilé (toutes repos confondues)
2626
* ``github_stat_pr_heatmap.png`` — heatmap (toutes repos confondues)
27+
* ``github_stat_pr_lines.png`` — graphe en lignes comparant les dépôts
2728
* ``github_stat_pr_bar_{owner}_{repo}.png`` — diagramme empilé par dépôt
2829
* ``github_stat_pr_heatmap_{owner}_{repo}.png`` — heatmap par dépôt
2930

0 commit comments

Comments
 (0)