Benjamin Bossan commited on
Commit
75938bf
·
1 Parent(s): a6ed441

First commit, 36 months backfilled

Browse files
Files changed (3) hide show
  1. app.py +147 -0
  2. metrics.csv +37 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+ import gradio as gr
4
+ import pandas as pd
5
+ import plotly.express as px
6
+ import plotly.graph_objects as go
7
+
8
+
9
+ CSV_PATH = Path("metrics.csv")
10
+
11
+
12
+ def load_data() -> pd.DataFrame:
13
+ df = pd.read_csv(CSV_PATH)
14
+ # Normalize/parse columns
15
+ if "date" not in df.columns:
16
+ raise ValueError("Expected a 'date' column in metrics.csv")
17
+ df["date"] = pd.to_datetime(df["date"], errors="coerce")
18
+ df = df.sort_values("date").reset_index(drop=True)
19
+ # Ensure numeric columns are numeric
20
+ for c in df.columns:
21
+ if c == "date":
22
+ continue
23
+ df[c] = pd.to_numeric(df[c], errors="coerce")
24
+ return df
25
+
26
+
27
+ def line_figure(df: pd.DataFrame, cols: list[str], title: str, yaxis_title: str = "") -> go.Figure:
28
+ if not cols:
29
+ # Empty placeholder so the UI doesn't error
30
+ fig = go.Figure()
31
+ fig.update_layout(title=f"{title} (no series selected)")
32
+ return fig
33
+ fig = px.line(
34
+ df,
35
+ x="date",
36
+ y=cols,
37
+ markers=True,
38
+ title=title,
39
+ )
40
+ # Improve layout for time series
41
+ fig.update_layout(
42
+ legend_title_text="Series",
43
+ xaxis_title="Date",
44
+ yaxis_title=yaxis_title,
45
+ hovermode="x unified",
46
+ margin={"l": 50, "r": 20, "t": 50, "b": 40},
47
+ )
48
+ return fig
49
+
50
+
51
+ TAB_SPEC = {
52
+ "Docstrings": [
53
+ "docstring coverage",
54
+ "docstring missing",
55
+ ],
56
+ "Size (Lines/Statements/Expressions/Parameters)": [
57
+ "lines mean",
58
+ "lines max",
59
+ "lines 90th-percentile",
60
+ "statements mean",
61
+ "statements max",
62
+ "statements 90th-percentile",
63
+ "expressions mean",
64
+ "expressions max",
65
+ "expressions 90th-percentile",
66
+ "parameters mean",
67
+ "parameters max",
68
+ "parameters 90th-percentile",
69
+ ],
70
+ "Complexity": [
71
+ "cyclomatic_complexity mean",
72
+ "cyclomatic_complexity max",
73
+ "cyclomatic_complexity 90th-percentile",
74
+ ],
75
+ "Typing": [
76
+ "type_coverage mean",
77
+ "type_coverage min",
78
+ "type_coverage 50th-percentile",
79
+ ],
80
+ "Duplication": [
81
+ "duplication.score mean",
82
+ "duplication.score max",
83
+ "duplication.score 90th-percentile",
84
+ "duplication.score 50th-percentile",
85
+ "duplication.duplicated-lines total",
86
+ ],
87
+ "TODOs": [
88
+ "todo_comments total",
89
+ ],
90
+ "CLOC (Repository scope)": [
91
+ "files",
92
+ "lines blank",
93
+ "lines comment",
94
+ "lines code",
95
+ ],
96
+ }
97
+
98
+ Y_LABELS = {
99
+ "Docstrings": "value",
100
+ "Size (Lines/Statements/Expressions/Parameters)": "count",
101
+ "Complexity": "complexity",
102
+ "Typing": "fraction / coverage",
103
+ "Duplication": "score / lines",
104
+ "TODOs": "count",
105
+ "CLOC (Repository scope)": "lines / files",
106
+ }
107
+
108
+ DF = load_data()
109
+
110
+ with gr.Blocks(title="Code Metrics – Time Series", fill_height=True) as demo:
111
+ gr.Markdown(
112
+ "## Transformers Code Metrics Over Time (excluding models/)\n"
113
+ f"Loaded **{CSV_PATH}** with {len(DF)} rows spanning "
114
+ f"{DF['date'].min().date()} → {DF['date'].max().date()}.\n\n"
115
+ "Use each tab to pick the series you want to plot."
116
+ )
117
+
118
+ with gr.Tabs():
119
+ tab_controls = []
120
+ tab_plots = []
121
+
122
+ for tab_name, series in TAB_SPEC.items():
123
+ available = [s for s in series if s in DF.columns] # guard against missing cols
124
+ with gr.Tab(tab_name):
125
+ with gr.Row():
126
+ sel = gr.CheckboxGroup(
127
+ choices=available,
128
+ value=available,
129
+ label="Series",
130
+ )
131
+ plot = gr.Plot(
132
+ value=line_figure(DF, available, tab_name, Y_LABELS.get(tab_name, "")),
133
+ show_label=False,
134
+ )
135
+
136
+ sel.change(
137
+ fn=lambda cols, t=tab_name: line_figure(DF, cols, t, Y_LABELS.get(t, "")),
138
+ inputs=sel,
139
+ outputs=plot,
140
+ )
141
+
142
+ tab_controls.append(sel)
143
+ tab_plots.append(plot)
144
+
145
+
146
+ if __name__ == "__main__":
147
+ demo.launch()
metrics.csv ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ date,docstring coverage,docstring missing,lines mean,lines max,lines 90th-percentile,statements mean,statements max,statements 90th-percentile,expressions mean,expressions max,expressions 90th-percentile,cyclomatic_complexity mean,cyclomatic_complexity max,cyclomatic_complexity 90th-percentile,parameters mean,parameters max,parameters 90th-percentile,type_coverage mean,type_coverage min,type_coverage 50th-percentile,todo_comments total,duplication.score mean,duplication.score max,duplication.score 90th-percentile,duplication.score 50th-percentile,duplication.duplicated-lines total,files,lines blank,lines comment,lines code
2
+ 2022-10-31,0.2629,2778,15.6705,787,37,6.3659,205,15,40.9602,1250,102,3.0207,98,6,1.969,45,4,0.2072,0,0,67,0.1274,1.0,0.7612000000000003,0.0,11524,989,90335,127886,344285
3
+ 2022-12-01,0.2617,2898,15.6456,795,37,6.3376,207,15,40.7954,1250,101,3.0125,99,6,1.9524,45,4,0.2073,0,0,71,0.13,1.0,0.7696,0.0,12504,1072,95443,137215,365143
4
+ 2023-01-02,0.2577,2961,15.2632,770,37,6.2206,221,15,39.8496,1275,99,2.9724,108,6,1.911,33,4,0.2046,0,0,70,0.1246,1.0,0.755,0.0,12144,1118,99078,141513,378757
5
+ 2023-02-01,0.2555,3021,15.1831,802,36,6.2151,224,15,39.8903,1371,99,2.9795,110,6,1.8884,20,4,0.2044,0,0,73,0.1248,1.0,0.757,0.0,12731,1164,104300,149203,399586
6
+ 2023-03-01,0.2551,3096,15.2902,860,37,6.2377,240,14,40.1126,1509,99,2.9894,118,6,1.8898,20,4,0.2039,0,0,75,0.1251,1.0,0.761,0.0,12493,1211,107555,154942,415793
7
+ 2023-04-03,0.2551,3174,15.2305,889,37,6.1931,250,14,39.7686,1612,98,2.9678,122,6,1.901,20,4,0.2058,0,0,76,0.1241,1.0,0.757,0.0,12526,1250,111081,160304,429102
8
+ 2023-05-01,0.2563,3227,15.2909,940,36,6.2178,276,14,39.8889,1727,98,2.9841,137,6,1.9009,20,4,0.2042,0,0,75,0.123,1.0,0.7476000000000022,0.0,12670,1275,113550,163679,438879
9
+ 2023-06-01,0.2575,3360,15.3215,986,37,6.2869,294,15,40.0278,1821,98,3.0186,155,6,1.9182,20,4,0.2017,0,0,72,0.1213,1.0,0.744,0.0,12747,1304,114987,166100,444138
10
+ 2023-07-01,0.2556,3428,15.2632,1049,36,6.2725,308,14,39.9142,1925,97,3.0169,164,6,1.9262,20,4,0.1998,0,0,71,0.1235,1.0,0.7588000000000011,0.0,13539,1329,116986,168718,451427
11
+ 2023-08-01,0.254,3478,15.2632,1051,36,6.2767,309,14,39.9123,1930,96,3.0225,165,6,1.9185,20,4,0.1994,0,0,72,0.1222,1.0,0.7529000000000006,0.0,13544,1364,119802,171757,461839
12
+ 2023-09-01,0.2547,3543,15.3418,1190,36,6.2724,368,14,39.9323,2247,96,3.0259,195,6,1.9239,20,4,0.2007,0,0,72,0.1216,1.0,0.751,0.0,13732,1398,122263,176221,472458
13
+ 2023-10-02,0.255,3590,15.3326,1194,36,6.2766,375,15,39.9151,2271,96,3.0434,197,6,1.9174,20,4,0.2003,0,0,72,0.1232,1.0,0.757,0.0,13888,1423,123825,178521,478559
14
+ 2023-11-01,0.2556,3634,15.278,1222,36,6.2513,387,14,39.6934,2351,96,3.0281,205,6,1.917,20,4,0.2007,0,0,72,0.1238,1.0,0.757,0.0,14366,1449,125497,182650,487054
15
+ 2023-12-01,0.2542,3680,15.2268,1282,36,6.2302,414,14,39.5709,2479,96,3.0217,223,6,1.9149,20,4,0.1992,0,0,70,0.1229,1.0,0.7494999999999991,0.0,14549,1483,129367,188765,500858
16
+ 2024-01-02,0.2572,3722,15.3073,1327,36,6.2538,430,14,39.7737,2614,97,3.0261,238,6,1.9216,20,4,0.2025,0,0,75,0.1214,1.0,0.736,0.0,14408,1504,132113,191948,518133
17
+ 2024-02-01,0.2548,3819,15.151,1006,37,6.1897,297,14,39.2273,1862,96,2.9965,157,6,1.9179,20,4,0.2042,0,0,82,0.1237,1.0,0.7546000000000004,0.0,14676,1541,134593,195451,527675
18
+ 2024-03-01,0.254,3873,15.156,1010,37,6.1951,298,14,39.1552,1870,95,3.0052,162,6,1.9187,20,4,0.2037,0,0,82,0.1228,1.0,0.7387000000000016,0.0,14877,1563,136236,197952,536164
19
+ 2024-04-01,0.2539,3946,15.1531,1045,37,6.194,306,14,39.1282,1947,95,3.0096,164,6,1.9155,20,4,0.2033,0,0,91,0.1231,1.0,0.7429999999999982,0.0,14704,1602,139895,202764,545185
20
+ 2024-05-01,0.2538,4004,15.1469,1048,37,6.1951,307,14,39.1683,1949,96,3.0095,172,6,1.9191,20,4,0.2047,0,0,95,0.1233,1.0,0.7535000000000001,0.0,14873,1634,143662,208738,561012
21
+ 2024-06-03,0.2553,4112,15.0464,1106,37,6.2666,324,15,39.6126,2084,97,3.0319,171,6,1.9125,20,4,0.2099,0,0,91,0.1199,1.0,0.7269000000000005,0.0,13677,1654,143756,212025,565793
22
+ 2024-07-01,0.2567,4146,15.2185,1110,37,6.324,326,15,39.9857,2093,98,3.0579,173,7,1.9191,20,4,0.2122,0,0,89,0.12,1.0,0.7273000000000002,0.0,14112,1685,146231,216553,577297
23
+ 2024-08-01,0.2587,4199,15.4204,1131,38,6.4017,328,15,40.6109,2135,100,3.0927,179,7,1.9329,20,4,0.2155,0,0,98,0.1208,1.0,0.734,0.0,14472,1705,147618,218791,581260
24
+ 2024-09-01,0.259,4254,15.3503,1131,38,6.3647,328,15,40.3679,2139,99,3.0787,179,7,1.9289,20,4,0.2166,0,0,106,0.1217,1.0,0.734,0.0,14769,1735,150203,222942,591389
25
+ 2024-10-01,0.2612,4294,15.5583,1136,38,6.4513,331,15,40.674,2165,100,3.1204,179,7,1.9484,21,4,0.218,0,0,106,0.1208,1.0,0.732,0.0,14743,1781,154189,230242,608021
26
+ 2024-11-01,0.2633,4412,15.7694,1148,39,6.5472,334,16,41.3984,2186,103,3.1359,186,7,1.9806,21,4,0.2197,0,0,110,0.1239,1.0,0.752,0.0,15563,1809,155880,233785,615550
27
+ 2024-12-02,0.2623,4425,15.8496,1190,39,6.576,353,16,41.6074,2309,104,3.148,186,7,1.987,21,4,0.2186,0,0,113,0.1191,1.0,0.7233000000000002,0.0,15259,1818,156244,234699,618046
28
+ 2025-01-02,0.2618,4509,15.8407,1201,39,6.5527,354,16,41.6842,2316,104,3.1383,186,7,1.9928,21,4,0.2198,0,0,114,0.1191,1.0,0.723,0.0,15461,1873,159076,239433,628007
29
+ 2025-02-03,0.2619,4531,15.7622,1238,39,6.5279,379,16,41.5159,2430,104,3.1411,197,7,1.9849,23,4,0.2141,0,0,109,0.1173,1.0,0.705,0.0,15376,1930,163242,247146,637180
30
+ 2025-03-01,0.2659,4594,15.9605,1249,39,6.593,391,16,42.059,2492,105,3.1529,205,7,2.0046,24,4,0.218,0,0,108,0.1197,1.0,0.716,0.0,15940,1979,166504,252357,650068
31
+ 2025-04-01,0.2678,4714,15.9418,760,39,6.5652,268,16,41.9397,1856,106,3.1412,186,7,2.0214,24,4,0.2201,0,0,114,0.1181,1.0,0.715,0.0,15240,2034,170150,258287,665008
32
+ 2025-05-01,0.4158,2396,23.6791,810,54,9.5491,262,21,62.2982,1799,145,4.2941,181,10,2.5903,24,5,0.342,0,0,119,0.183,1.0,0.868,0.0,14928,2113,170552,269014,676410
33
+ 2025-06-02,0.4315,2449,23.8612,801,55,9.5662,262,21,62.4359,1799,146,4.2862,181,10,2.6123,24,5,0.3557,0,0,135,0.1865,1.0,0.87,0.0,16511,2153,168730,257469,681526
34
+ 2025-07-01,0.4249,2530,23.6376,815,55,9.4906,270,21,62.8031,1835,146,4.2635,188,10,2.6992,24,5,0.3678,0,0,137,0.1987,1.0,0.895,0.0,16889,2239,174352,262965,708135
35
+ 2025-08-01,0.4304,2579,23.7418,806,55,9.4536,268,21,62.568,1827,145,4.2549,187,10,2.7215,28,5,0.3747,0,0,140,0.2015,1.0,0.905,0.0,18317,2342,177467,269996,724031
36
+ 2025-09-01,0.4273,2623,23.5183,803,55,9.3631,268,21,62.0624,1827,144,4.2197,187,10,2.719,28,5,0.4063,0,0,152,0.2018,1.0,0.905,0.0,18365,2438,182724,279400,749252
37
+ 2025-10-01,0.4312,2397,22.444,733,55,9.0088,238,20,59.0888,1594,142,4.0527,164,9,2.6849,28,5,0.4124,0,0,149,0.1963,1.0,0.892,0.0,14189,2373,160861,252654,656914
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ pandas
3
+ plotly