-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathgenerate_chart.py
More file actions
executable file
·789 lines (714 loc) · 25.4 KB
/
generate_chart.py
File metadata and controls
executable file
·789 lines (714 loc) · 25.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
#!/usr/bin/env python3
# PR‑tracker: generates a combo chart from the collected PR data.
# deps: pandas, matplotlib, numpy
from pathlib import Path
import pandas as pd
import matplotlib
matplotlib.use("Agg") # headless
import matplotlib.pyplot as plt
import numpy as np
import datetime as dt
import re
import json
from jinja2 import Environment, FileSystemLoader
TEMPLATE_DIR = Path("templates")
env = Environment(loader=FileSystemLoader(TEMPLATE_DIR))
env.filters["comma"] = lambda v: f"{int(v):,}" if isinstance(v, (int, float)) else v
AGENTS = [
{
"key": "copilot",
"display": "Copilot",
"long_name": "GitHub Copilot coding agent",
"color": "#2563eb",
"info_url": "https://docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent",
"total_query_url": "https://github.com/search?q=is:pr+head:copilot/&type=pullrequests",
"merged_query_url": "https://github.com/search?q=is:pr+head:copilot/+is:merged&type=pullrequests",
"ready_query_url": "https://github.com/search?q=is:pr+head:copilot/+-is:draft&type=pullrequests",
"draft_query_url": "https://github.com/search?q=is:pr+head:copilot/+is:draft&type=pullrequests",
},
{
"key": "codex",
"display": "Codex",
"long_name": "OpenAI Codex",
"color": "#dc2626",
"info_url": "https://openai.com/index/introducing-codex/",
"total_query_url": "https://github.com/search?q=is:pr+head:codex/&type=pullrequests",
"merged_query_url": "https://github.com/search?q=is:pr+head:codex/+is:merged&type=pullrequests",
"ready_query_url": "https://github.com/search?q=is:pr+head:codex/+-is:draft&type=pullrequests",
"draft_query_url": "https://github.com/search?q=is:pr+head:codex/+is:draft&type=pullrequests",
},
{
"key": "cursor",
"display": "Cursor",
"long_name": "Cursor Agents",
"color": "#7c3aed",
"info_url": "https://docs.cursor.com/background-agent",
"total_query_url": "https://github.com/search?q=is:pr+head:cursor/&type=pullrequests",
"merged_query_url": "https://github.com/search?q=is:pr+head:cursor/+is:merged&type=pullrequests",
"ready_query_url": "https://github.com/search?q=is:pr+head:cursor/+-is:draft&type=pullrequests",
"draft_query_url": "https://github.com/search?q=is:pr+head:cursor/+is:draft&type=pullrequests",
},
{
"key": "devin",
"display": "Devin",
"long_name": "Devin",
"color": "#059669",
"info_url": "https://devin.ai/pricing",
"total_query_url": "https://github.com/search?q=is:pr+author:devin-ai-integration[bot]&type=pullrequests",
"merged_query_url": "https://github.com/search?q=is:pr+author:devin-ai-integration[bot]+is:merged&type=pullrequests",
"ready_query_url": "https://github.com/search?q=is:pr+author:devin-ai-integration[bot]+-is:draft&type=pullrequests",
"draft_query_url": "https://github.com/search?q=is:pr+author:devin-ai-integration[bot]+is:draft&type=pullrequests",
},
{
"key": "codegen",
"display": "Codegen",
"long_name": "Codegen",
"color": "#d97706",
"info_url": "https://codegen.com/",
"total_query_url": "https://github.com/search?q=is:pr+author:codegen-sh[bot]&type=pullrequests",
"merged_query_url": "https://github.com/search?q=is:pr+author:codegen-sh[bot]+is:merged&type=pullrequests",
"ready_query_url": "https://github.com/search?q=is:pr+author:codegen-sh[bot]+-is:draft&type=pullrequests",
"draft_query_url": "https://github.com/search?q=is:pr+author:codegen-sh[bot]+is:draft&type=pullrequests",
},
{
"key": "jules",
"display": "Jules",
"long_name": "Google Labs Jules",
"color": "#0ea5e9",
"info_url": "https://labs.google/",
"total_query_url": "https://github.com/search?q=is:pr+author:google-labs-jules[bot]&type=pullrequests",
"merged_query_url": "https://github.com/search?q=is:pr+author:google-labs-jules[bot]+is:merged&type=pullrequests",
"ready_query_url": "https://github.com/search?q=is:pr+author:google-labs-jules[bot]+-is:draft&type=pullrequests",
"draft_query_url": "https://github.com/search?q=is:pr+author:google-labs-jules[bot]+is:draft&type=pullrequests",
},
]
def build_stats(latest, df=None):
stats = {}
# Get real data for each agent
for agent in AGENTS:
key = agent["key"]
total = int(latest[f"{key}_total"])
merged = int(latest[f"{key}_merged"])
nondraft = (
int(latest[f"{key}_nondraft"]) if f"{key}_nondraft" in latest else total
)
# Calculate rates for different PR types
total_rate = (merged / total * 100) if total > 0 else 0
ready_rate = (merged / nondraft * 100) if nondraft > 0 else 0
stats[key] = {
"total": total,
"merged": merged,
"nondraft": nondraft, # ready PRs (non-draft)
"rate": ready_rate, # Default to ready PR success rate
"total_rate": total_rate, # Success rate including drafts
"ready_rate": ready_rate, # Success rate for ready PRs only
}
return stats
def generate_chart(csv_file=None):
# Default to data.csv if no file specified
if csv_file is None:
csv_file = Path("data.csv")
# Ensure file exists
if not csv_file.exists():
print(f"Error: {csv_file} not found.")
print("Run collect_data.py first to collect data.")
return False
# Create chart
df = pd.read_csv(csv_file)
# Fix timestamp format - replace special dash characters with regular hyphens
df["timestamp"] = df["timestamp"].str.replace("‑", "-")
df["timestamp"] = pd.to_datetime(df["timestamp"])
# Check if data exists
if len(df) == 0:
print("Error: No data found in CSV file.")
return False
# Limit to 8 data points spread across the entire dataset to avoid chart getting too busy
total_points = len(df)
if total_points > 8:
# Create evenly spaced indices across the entire dataset
indices = np.linspace(0, total_points - 1, num=8, dtype=int)
df = df.iloc[indices]
print(
f"Limited chart to 8 data points evenly distributed across {total_points} total points."
)
# Calculate percentages with safety checks - both ready and total rates
# Ready rate (merged/nondraft) - default for chart display
df["copilot_percentage"] = df.apply(
lambda row: (
(row["copilot_merged"] / row["copilot_nondraft"] * 100)
if row["copilot_nondraft"] > 0
else 0
),
axis=1,
)
df["codex_percentage"] = df.apply(
lambda row: (
(row["codex_merged"] / row["codex_nondraft"] * 100)
if row["codex_nondraft"] > 0
else 0
),
axis=1,
)
df["cursor_percentage"] = df.apply(
lambda row: (
(row["cursor_merged"] / row["cursor_nondraft"] * 100)
if row["cursor_nondraft"] > 0
else 0
),
axis=1,
)
df["devin_percentage"] = df.apply(
lambda row: (
(row["devin_merged"] / row["devin_nondraft"] * 100)
if row["devin_nondraft"] > 0
else 0
),
axis=1,
)
df["codegen_percentage"] = df.apply(
lambda row: (
(row["codegen_merged"] / row["codegen_nondraft"] * 100)
if row["codegen_nondraft"] > 0
else 0
),
axis=1,
)
df["jules_percentage"] = df.apply(
lambda row: (
(row["jules_merged"] / row["jules_nondraft"] * 100)
if row["jules_nondraft"] > 0
else 0
),
axis=1,
)
# Total rate (merged/total) - for alternative view
df["copilot_total_percentage"] = df.apply(
lambda row: (
(row["copilot_merged"] / row["copilot_total"] * 100)
if row["copilot_total"] > 0
else 0
),
axis=1,
)
df["codex_total_percentage"] = df.apply(
lambda row: (
(row["codex_merged"] / row["codex_total"] * 100)
if row["codex_total"] > 0
else 0
),
axis=1,
)
df["cursor_total_percentage"] = df.apply(
lambda row: (
(row["cursor_merged"] / row["cursor_total"] * 100)
if row["cursor_total"] > 0
else 0
),
axis=1,
)
df["devin_total_percentage"] = df.apply(
lambda row: (
(row["devin_merged"] / row["devin_total"] * 100)
if row["devin_total"] > 0
else 0
),
axis=1,
)
df["codegen_total_percentage"] = df.apply(
lambda row: (
(row["codegen_merged"] / row["codegen_total"] * 100)
if row["codegen_total"] > 0
else 0
),
axis=1,
)
df["jules_total_percentage"] = df.apply(
lambda row: (
(row["jules_merged"] / row["jules_total"] * 100)
if row["jules_total"] > 0
else 0
),
axis=1,
)
# Adjust chart size based on data points, adding extra space for legends
num_points = len(df)
if num_points <= 3:
fig_width = max(12, num_points * 4) # Increased from 10 to 12
fig_height = 8 # Increased from 6 to 8
else:
fig_width = 16 # Increased from 14 to 16
fig_height = 10 # Increased from 8 to 10
# Create the combination chart
fig, ax1 = plt.subplots(figsize=(fig_width, fig_height))
ax2 = ax1.twinx()
# Prepare data
x = np.arange(len(df))
# Adjust bar width based on number of data points (5 groups now)
width = min(0.14, 0.84 / max(1, num_points * 0.6))
# Bar charts for totals and merged
bars_copilot_total = ax1.bar(
x - 2.5 * width,
df["copilot_total"],
width,
label="Copilot Total",
alpha=0.7,
color="#93c5fd",
)
bars_copilot_merged = ax1.bar(
x - 2.5 * width,
df["copilot_merged"],
width,
label="Copilot Merged",
alpha=1.0,
color="#2563eb",
)
bars_codex_total = ax1.bar(
x - 1.5 * width,
df["codex_total"],
width,
label="Codex Total",
alpha=0.7,
color="#fca5a5",
)
bars_codex_merged = ax1.bar(
x - 1.5 * width,
df["codex_merged"],
width,
label="Codex Merged",
alpha=1.0,
color="#dc2626",
)
bars_cursor_total = ax1.bar(
x - 0.5 * width,
df["cursor_total"],
width,
label="Cursor Total",
alpha=0.7,
color="#c4b5fd",
)
bars_cursor_merged = ax1.bar(
x - 0.5 * width,
df["cursor_merged"],
width,
label="Cursor Merged",
alpha=1.0,
color="#7c3aed",
)
bars_devin_total = ax1.bar(
x + 0.5 * width,
df["devin_total"],
width,
label="Devin Total",
alpha=0.7,
color="#86efac",
)
bars_devin_merged = ax1.bar(
x + 0.5 * width,
df["devin_merged"],
width,
label="Devin Merged",
alpha=1.0,
color="#059669",
)
bars_codegen_total = ax1.bar(
x + 1.5 * width,
df["codegen_total"],
width,
label="Codegen Total",
alpha=0.7,
color="#fed7aa",
)
bars_codegen_merged = ax1.bar(
x + 1.5 * width,
df["codegen_merged"],
width,
label="Codegen Merged",
alpha=1.0,
color="#d97706",
)
bars_jules_total = ax1.bar(
x + 2.5 * width,
df["jules_total"],
width,
label="Jules Total",
alpha=0.7,
color="#bae6fd",
)
bars_jules_merged = ax1.bar(
x + 2.5 * width,
df["jules_merged"],
width,
label="Jules Merged",
alpha=1.0,
color="#0ea5e9",
)
# Line charts for percentages (on secondary y-axis)
line_copilot = ax2.plot(
x,
df["copilot_percentage"],
"o-",
color="#1d4ed8",
linewidth=3,
markersize=10,
label="Copilot Success %",
markerfacecolor="white",
markeredgewidth=2,
markeredgecolor="#1d4ed8",
)
line_codex = ax2.plot(
x,
df["codex_percentage"],
"s-",
color="#b91c1c",
linewidth=3,
markersize=10,
label="Codex Success %",
markerfacecolor="white",
markeredgewidth=2,
markeredgecolor="#b91c1c",
)
line_cursor = ax2.plot(
x,
df["cursor_percentage"],
"d-",
color="#6d28d9",
linewidth=3,
markersize=10,
label="Cursor Success %",
markerfacecolor="white",
markeredgewidth=2,
markeredgecolor="#6d28d9",
)
line_devin = ax2.plot(
x,
df["devin_percentage"],
"^-",
color="#047857",
linewidth=3,
markersize=10,
label="Devin Success %",
markerfacecolor="white",
markeredgewidth=2,
markeredgecolor="#047857",
)
line_codegen = ax2.plot(
x,
df["codegen_percentage"],
"v-",
color="#b45309",
linewidth=3,
markersize=10,
label="Codegen Success %",
markerfacecolor="white",
markeredgewidth=2,
markeredgecolor="#b45309",
)
line_jules = ax2.plot(
x,
df["jules_percentage"],
"h-",
color="#0369a1",
linewidth=3,
markersize=10,
label="Jules Success %",
markerfacecolor="white",
markeredgewidth=2,
markeredgecolor="#0369a1",
)
# Customize the chart
ax1.set_xlabel("Data Points", fontsize=12, fontweight="bold")
ax1.set_ylabel(
"PR Counts (Total & Merged)", fontsize=12, fontweight="bold", color="black"
)
ax2.set_ylabel(
"Merge Success Rate (%)", fontsize=12, fontweight="bold", color="black"
)
title = "PR Analytics: Volume vs Success Rate Comparison"
ax1.set_title(title, fontsize=16, fontweight="bold", pad=20)
# Set x-axis labels with timestamps
timestamps = df["timestamp"].dt.strftime("%m-%d %H:%M")
ax1.set_xticks(x)
ax1.set_xticklabels(timestamps, rotation=45)
# Add legends - move name labels to top left, success % labels to bottom right
# Position legends further outside with more padding
legend1 = ax1.legend(loc="upper left", bbox_to_anchor=(-0.15, 1.15))
legend2 = ax2.legend(loc="lower right", bbox_to_anchor=(1.15, -0.15))
# Add grid
ax1.grid(True, alpha=0.3, linestyle="--")
# Set percentage axis range
ax2.set_ylim(0, 100)
# Add value labels on bars (with safety checks)
def add_value_labels(ax, bars, format_str="{:.0f}"):
for bar in bars:
height = bar.get_height()
if height > 0:
# Ensure the label fits within reasonable bounds
label_text = format_str.format(height)
if len(label_text) > 10: # Truncate very long numbers
if height >= 1000:
label_text = f"{height/1000:.1f}k"
elif height >= 1000000:
label_text = f"{height/1000000:.1f}M"
ax.text(
bar.get_x() + bar.get_width() / 2.0,
height,
label_text,
ha="center",
va="bottom",
fontsize=8,
fontweight="normal",
color="black",
)
add_value_labels(ax1, bars_copilot_total)
add_value_labels(ax1, bars_copilot_merged)
add_value_labels(ax1, bars_codex_total)
add_value_labels(ax1, bars_codex_merged)
add_value_labels(ax1, bars_cursor_total)
add_value_labels(ax1, bars_cursor_merged)
add_value_labels(ax1, bars_devin_total)
add_value_labels(ax1, bars_devin_merged)
add_value_labels(ax1, bars_codegen_total)
add_value_labels(ax1, bars_codegen_merged)
add_value_labels(ax1, bars_jules_total)
add_value_labels(ax1, bars_jules_merged)
# Add percentage labels on line points (with validation and skip 0.0%)
for i, (cop_pct, cod_pct, cur_pct, dev_pct, cg_pct, jul_pct) in enumerate(
zip(
df["copilot_percentage"],
df["codex_percentage"],
df["cursor_percentage"],
df["devin_percentage"],
df["codegen_percentage"],
df["jules_percentage"],
)
):
# Only add labels if percentages are valid numbers and not 0.0%
if (
pd.notna(cop_pct)
and pd.notna(cod_pct)
and pd.notna(cur_pct)
and pd.notna(dev_pct)
and pd.notna(cg_pct)
and pd.notna(jul_pct)
):
if cop_pct > 0.0:
ax2.annotate(
f"{cop_pct:.1f}%",
(i, cop_pct),
textcoords="offset points",
xytext=(0, 15),
ha="center",
fontsize=10,
fontweight="bold",
color="#1d4ed8",
)
if cod_pct > 0.0:
ax2.annotate(
f"{cod_pct:.1f}%",
(i, cod_pct),
textcoords="offset points",
xytext=(0, -20),
ha="center",
fontsize=10,
fontweight="bold",
color="#b91c1c",
)
if cur_pct > 0.0:
ax2.annotate(
f"{cur_pct:.1f}%",
(i, cur_pct),
textcoords="offset points",
xytext=(0, -35),
ha="center",
fontsize=10,
fontweight="bold",
color="#6d28d9",
)
if dev_pct > 0.0:
ax2.annotate(
f"{dev_pct:.1f}%",
(i, dev_pct),
textcoords="offset points",
xytext=(0, -50),
ha="center",
fontsize=10,
fontweight="bold",
color="#047857",
)
if cg_pct > 0.0:
ax2.annotate(
f"{cg_pct:.1f}%",
(i, cg_pct),
textcoords="offset points",
xytext=(0, -65),
ha="center",
fontsize=10,
fontweight="bold",
color="#b45309",
)
if jul_pct > 0.0:
ax2.annotate(
f"{jul_pct:.1f}%",
(i, jul_pct),
textcoords="offset points",
xytext=(0, -80),
ha="center",
fontsize=10,
fontweight="bold",
color="#0369a1",
)
plt.tight_layout(pad=6.0)
# Adjust subplot parameters to ensure legends fit entirely outside the chart
plt.subplots_adjust(left=0.2, right=0.88, top=0.85, bottom=0.2)
# Save chart to docs directory (single location for both README and GitHub Pages)
docs_dir = Path("docs")
docs_dir.mkdir(exist_ok=True) # Ensure docs directory exists
chart_file = docs_dir / "chart.png"
dpi = 150 if num_points <= 5 else 300
fig.savefig(chart_file, dpi=dpi, bbox_inches="tight", facecolor="white")
print(f"Chart generated: {chart_file}")
# Export chart data as JSON for interactive chart
export_chart_data_json(df)
# Update the README with latest statistics
update_readme(df)
# Update the GitHub Pages with latest statistics
update_github_pages(df)
return True
def export_chart_data_json(df):
"""Export chart data as JSON for interactive JavaScript chart"""
docs_dir = Path("docs")
docs_dir.mkdir(exist_ok=True)
# Prepare data for Chart.js
chart_data = {"labels": [], "datasets": []}
# Format timestamps for labels
for _, row in df.iterrows():
timestamp = row["timestamp"]
if isinstance(timestamp, str):
timestamp = pd.to_datetime(timestamp)
chart_data["labels"].append(timestamp.strftime("%m/%d %H:%M"))
# Color scheme matching the Python chart - elegant professional colors
colors = {
"copilot": {"total": "#93c5fd", "merged": "#2563eb", "line": "#1d4ed8"},
"codex": {"total": "#fca5a5", "merged": "#dc2626", "line": "#b91c1c"},
"cursor": {"total": "#c4b5fd", "merged": "#7c3aed", "line": "#6d28d9"},
"devin": {"total": "#86efac", "merged": "#059669", "line": "#047857"},
"codegen": {"total": "#fed7aa", "merged": "#d97706", "line": "#b45309"},
"jules": {"total": "#bae6fd", "merged": "#0ea5e9", "line": "#0369a1"},
}
# Add bar datasets for totals and merged PRs
for agent in ["copilot", "codex", "cursor", "devin", "codegen", "jules"]:
# Process data to replace leading zeros with None (null in JSON)
total_data = df[f"{agent}_total"].tolist()
merged_data = df[f"{agent}_merged"].tolist()
ready_percentage_data = df[f"{agent}_percentage"].tolist() # ready rate
total_percentage_data = df[f"{agent}_total_percentage"].tolist() # total rate
# Find first non-zero total value index
first_nonzero_idx = None
for i, total in enumerate(total_data):
if total > 0:
first_nonzero_idx = i
break
# Replace leading zeros with None
if first_nonzero_idx is not None:
for i in range(first_nonzero_idx):
total_data[i] = None
merged_data[i] = None
ready_percentage_data[i] = None
total_percentage_data[i] = None
# Total PRs
chart_data["datasets"].append(
{
"label": f"{agent.title()} Total",
"type": "bar",
"data": total_data,
"backgroundColor": colors[agent]["total"],
"borderColor": colors[agent]["total"],
"borderWidth": 1,
"yAxisID": "y",
"order": 2,
}
)
# Merged PRs
chart_data["datasets"].append(
{
"label": f"{agent.title()} Merged",
"type": "bar",
"data": merged_data,
"backgroundColor": colors[agent]["merged"],
"borderColor": colors[agent]["merged"],
"borderWidth": 1,
"yAxisID": "y",
"order": 2,
}
)
# Success rate line (ready PRs) - shown by default
chart_data["datasets"].append(
{
"label": f"{agent.title()} Success % (Ready)",
"type": "line",
"data": ready_percentage_data,
"borderColor": colors[agent]["line"],
"backgroundColor": "rgba(255, 255, 255, 0.8)",
"borderWidth": 3,
"pointRadius": 3,
"pointHoverRadius": 5,
"fill": False,
"yAxisID": "y1",
"order": 1,
"rateType": "ready",
}
)
# Success rate line (all PRs) - hidden by default
chart_data["datasets"].append(
{
"label": f"{agent.title()} Success % (All)",
"type": "line",
"data": total_percentage_data,
"borderColor": colors[agent]["line"],
"backgroundColor": "rgba(255, 255, 255, 0.8)",
"borderWidth": 3,
"pointRadius": 3,
"pointHoverRadius": 5,
"fill": False,
"yAxisID": "y1",
"order": 1,
"hidden": True, # Hidden by default
"rateType": "total",
}
)
# Write JSON file
json_file = docs_dir / "chart-data.json"
with open(json_file, "w") as f:
json.dump(chart_data, f, indent=2)
print(f"Chart data exported: {json_file}")
return True
def update_readme(df):
"""Render README.md from template with latest statistics"""
readme_path = Path("README.md")
if not readme_path.exists():
print(f"Warning: {readme_path} not found, skipping README update.")
return False
latest = df.iloc[-1]
stats = build_stats(latest)
context = {"agents": AGENTS, "stats": stats}
content = env.get_template("readme_template.md").render(context)
readme_path.write_text(content)
print("README.md updated with latest statistics.")
return True
def update_github_pages(df):
"""Render the GitHub Pages site from template with latest statistics"""
index_path = Path("docs/index.html")
if not index_path.exists():
print(f"Warning: {index_path} not found, skipping GitHub Pages update.")
return False
latest = df.iloc[-1]
stats = build_stats(latest)
timestamp = dt.datetime.now().strftime("%B %d, %Y %H:%M UTC")
# Simple context - just the essentials
context = {"agents": AGENTS, "stats": stats, "timestamp": timestamp}
content = env.get_template("index_template.html").render(context)
index_path.write_text(content)
print("GitHub Pages updated with latest statistics and enhanced analytics.")
return True
if __name__ == "__main__":
generate_chart()