File size: 16,830 Bytes
b5dd7f4
 
 
db8dff1
3ebae97
db8dff1
9ae88b4
7df1475
627be83
3304f43
3ebae97
db8dff1
b5dd7f4
 
 
 
 
17c01dd
db8dff1
b5dd7f4
 
 
9ae88b4
 
 
 
3ebae97
9ae88b4
 
 
bf2ab49
3ebae97
db8dff1
627be83
 
 
7df1475
 
3ebae97
db8dff1
9ae88b4
 
 
 
bf2ab49
9ae88b4
 
 
 
 
 
 
 
b5dd7f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17c01dd
b5dd7f4
17c01dd
b5dd7f4
 
 
 
 
 
17c01dd
 
 
 
 
 
 
 
 
 
 
175afc3
 
17c01dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175afc3
 
17c01dd
 
 
 
 
 
 
 
 
 
 
 
175afc3
 
17c01dd
 
175afc3
17c01dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175afc3
17c01dd
 
 
9ae88b4
f2f4c2e
 
9ae88b4
f2f4c2e
 
 
 
 
 
 
 
 
 
 
 
 
9ae88b4
f2f4c2e
 
 
 
 
 
 
 
 
b5dd7f4
 
f2f4c2e
 
 
9ae88b4
 
 
 
 
b5dd7f4
 
 
 
 
 
 
 
 
 
 
 
 
9ae88b4
b5dd7f4
9ae88b4
 
f2f4c2e
 
 
 
 
 
 
 
 
b5dd7f4
f2f4c2e
 
 
 
 
 
175afc3
 
9ae88b4
 
 
 
 
 
 
 
3ebae97
9ae88b4
 
 
17c01dd
 
 
 
 
 
 
 
 
9ae88b4
 
17c01dd
 
 
 
 
 
9ae88b4
175afc3
17c01dd
9ae88b4
 
 
17c01dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71d192e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b5dd7f4
 
 
db8dff1
 
 
 
 
 
b5dd7f4
 
17c01dd
b5dd7f4
 
17c01dd
b5dd7f4
 
 
 
17c01dd
b5dd7f4
 
 
 
 
db8dff1
b5dd7f4
 
 
17c01dd
 
 
 
 
 
 
 
3ebae97
 
 
 
b5dd7f4
3ebae97
 
 
17c01dd
3ebae97
 
 
 
17c01dd
3ebae97
b5dd7f4
 
db8dff1
 
9ae88b4
 
 
 
3ebae97
 
 
9ae88b4
7df1475
3ebae97
 
71d192e
9ae88b4
 
f2f4c2e
 
3ebae97
 
9ae88b4
 
3ebae97
db8dff1
9ae88b4
 
db8dff1
9ae88b4
 
 
 
b5dd7f4
 
3ebae97
175afc3
 
 
 
 
 
 
 
 
9ae88b4
 
 
 
b5dd7f4
 
 
17c01dd
b5dd7f4
 
 
3ebae97
 
175afc3
 
 
b5dd7f4
 
 
 
 
 
3ebae97
 
 
 
 
b5dd7f4
 
 
 
 
 
 
 
 
 
17c01dd
 
 
 
 
b5dd7f4
 
 
3ebae97
175afc3
3ebae97
17c01dd
175afc3
3ebae97
17c01dd
db8dff1
 
3ebae97
 
 
 
 
7df1475
0aa0694
3ebae97
 
db8dff1
 
b5dd7f4
 
 
0aa0694
 
 
 
7df1475
 
 
 
 
17c01dd
 
 
 
 
 
 
 
7df1475
 
0aa0694
 
17c01dd
7df1475
 
 
 
 
 
 
 
 
17c01dd
7df1475
b5dd7f4
 
7df1475
 
 
 
 
 
 
 
 
 
 
db8dff1
 
7df1475
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
# =============================
# Imports & Extensions
# =============================
import pandas as pd
import hvplot.pandas  # noqa
import panel as pn
import holoviews as hv
import panel_material_ui as pmu
import fastparquet  # noqa

pn.extension("tabulator", autoreload=True)

# =============================
# Constants & Theme Config
# =============================
HEADER_COLOR = "#4199DA"
PAPER_COLOR = "#f5f4ef"
INDICATOR_COLOR = "#221cd9"

# =============================
# Data Loading
# =============================
data_url = (
    "https://raw.githubusercontent.com/Azaya89/holoviz-insights/refs/heads/main/data/"
)

repo_files = {
    "HoloViews": data_url + "holoviews_metrics.parq",
    "hvPlot": data_url + "hvplot_metrics.parq",
    "Panel": data_url + "panel_metrics.parq",
    "Datashader": data_url + "datashader_metrics.parq",
}

repo_dfs = {
    name: pd.read_parquet(url, engine="fastparquet") for name, url in repo_files.items()
}
repo_selector = pmu.Select(
    label="Select Repository", options=list(repo_files.keys()), value="HoloViews"
)

release_files = {
    "HoloViews": data_url + "holoviews_releases.csv",
    "hvPlot": data_url + "hvplot_releases.csv",
    "Panel": data_url + "panel_releases.csv",
    "Datashader": data_url + "datashader_releases.csv",
}

release_dfs = {
    name: pd.read_csv(url, parse_dates=["published_at"])
    for name, url in release_files.items()
}


# =============================
# Helper Functions
# =============================
def format_issue_url(url):
    try:
        return f'<a href="{url}" target="_blank">{url.split("/")[-1]}</a>'
    except Exception:
        return url


# =============================
# Metric Computation
# =============================
def compute_metrics(df):
    metrics = {}
    metrics["first_month"] = df.index[-1].strftime("%B %Y")
    metrics["last_month"] = df.index[0].strftime("%B %Y")
    metrics["total_issues"] = len(df)
    open_issues = df[df["time_to_close"].isna()]
    metrics["still_open"] = len(open_issues)
    metrics["closed"] = len(df) - len(open_issues)
    metrics["avg_close_time"] = int(df["time_to_close"].mean().days)
    metrics["median_close_time"] = int(df["time_to_close"].median().days)
    if "maintainer_responded" in df.columns:
        awaiting = open_issues[~open_issues["maintainer_responded"].fillna(False)]
        metrics["no_maintainer_response"] = len(awaiting)
    else:
        metrics["no_maintainer_response"] = None
    return metrics


# =============================
# Plot Functions
# =============================


def create_comparison_plot(df):
    monthly_opened = df.resample("ME").size()
    monthly_closed = df.dropna(subset=["time_to_close"]).resample("ME").size()
    comparison_df = pd.DataFrame({"Opened": monthly_opened, "Closed": monthly_closed})
    return comparison_df.hvplot.line(
        xlabel="Month",
        ylabel="Number of Issues",
        title="Opened vs Closed Issues per Month",
        group_label="Issues",
        height=300,
        responsive=True,
    )


def create_issues_plot(df):
    # Calculate the number of open issues for each day
    df = df.copy()
    df["opened_date"] = df.index.normalize()
    df["closed_date"] = df["opened_date"] + df["time_to_close"]
    all_dates = pd.date_range(
        df["opened_date"].min(), pd.Timestamp.now().normalize(), freq="D"
    )
    open_counts = pd.Series(0, index=all_dates)
    for _, row in df.iterrows():
        start = row["opened_date"]
        end = row["closed_date"] if pd.notnull(row["closed_date"]) else all_dates[-1]
        # Use only the date part for the range
        open_range = pd.date_range(start, end, freq="D")
        open_counts.loc[open_range] += 1
    open_counts.name = "Open Issues"
    return open_counts.hvplot.line(
        xlabel="Date",
        ylabel="Number of Open Issues",
        title="Open Issues Over Time",
        height=300,
        responsive=True,
    )


def create_milestone_plot(df):
    # Filter to only include open issues
    df = df[df["time_to_close"].isna()]
    milestone_counts = df["milestone"].value_counts(dropna=False)
    milestone_counts.name = "Milestone Issues"
    return milestone_counts.hvplot.bar(
        title="Open Issues by Milestone",
        xlabel="Milestone",
        ylabel="Issue Count",
        logy=True,
        ylim=(1, None),
        rot=45,
        height=300,
        responsive=True,
    )


def create_milestone_summary(df):
    df = df[df["time_to_close"].isna()]
    has_milestone = df["milestone"].notna().sum()
    no_milestone = df["milestone"].isna().sum()
    summary = pd.Series(
        [has_milestone, no_milestone], index=["Has Milestone", "No Milestone"]
    )
    return summary.hvplot.bar(
        title="Open Issues Milestone Coverage",
        ylabel="Issue Count",
        xlabel="Milestone Presence",
        height=300,
        responsive=True,
    )


def create_release_plot(df, repo_name):
    from packaging.version import parse

    df = df.copy()
    # Extract minor version (e.g., v1.15 from v1.15.0)
    df["minor_version"] = df["tag"].str.extract(r"(v?\d+\.\d+)")
    # Filter for the last 5 years only
    five_years_ago = pd.Timestamp.now(tz=df["published_at"].dt.tz) - pd.DateOffset(
        years=5
    )
    df = df[df["published_at"] >= five_years_ago]
    # Version-aware sort of minor versions
    unique_minors = df["minor_version"].dropna().unique()
    sorted_minors = sorted(unique_minors, key=lambda x: parse(x.lstrip("v")))
    # Sort by minor_version and published_at
    df["minor_version"] = pd.Categorical(
        df["minor_version"], categories=sorted_minors, ordered=True
    )
    df = df.sort_values(["minor_version", "published_at"]).reset_index(drop=True)
    # Use minor_version as y-axis (categorical, ordered)
    df["y"] = df["minor_version"]
    # Compute rectangle bounds: each bar spans from this release to the next (no overlap)
    df["x0"] = df["published_at"]
    df["x1"] = df["published_at"].shift(-1)
    # Set "x1" to now for the last release
    if not df.empty:
        df.loc[df.index[-1], "x1"] = pd.Timestamp.now(tz=df["published_at"].dt.tz)
    # Add release_span in days
    df["release_span"] = (df["x1"] - df["x0"]).dt.days
    df["y0"] = df["y"].cat.codes - 0.4
    df["y1"] = df["y"].cat.codes + 0.4
    last_release = df.iloc[-1]
    now = pd.Timestamp.now(tz=last_release["published_at"].tz)
    days_since = (now - last_release["published_at"]).days
    message = f"πŸ”” Last release was {days_since} days ago on {last_release['published_at'].date()} ({last_release['tag']})"

    rects = hv.Rectangles(
        df[
            [
                "x0",
                "y0",
                "x1",
                "y1",
                "tag",
                "type",
                "published_at",
                "minor_version",
                "release_span",
            ]
        ],
        kdims=["x0", "y0", "x1", "y1"],
        vdims=["tag", "type", "published_at", "minor_version", "release_span"],
    )
    rects = rects.opts(
        color="type",
        cmap={"major": "#eb2f40", "minor": "#0e9c24", "patch": "#0e67bb"},
        line_color="white",
        alpha=0.8,
        tools=["ycrosshair"],
        hover_tooltips=[
            ("Release Version", "@tag"),
            ("Release Type", "@type"),
            ("Release Date", "@published_at"),
            ("Release Span (days)", "@release_span"),
        ],
        xlabel="Date",
        ylabel="Minor Version",
        yticks=[(i, cat) for i, cat in enumerate(sorted_minors)],
        legend_position="bottom_right",
        title=f"{repo_name} Release Timeline for the last 5 years",
        height=300,
        responsive=True,
    )
    return pn.Column(
        pn.pane.Markdown(
            f"**{message}**", styles={"color": "gray", "margin-bottom": "16px"}
        ),
        rects,
    )


def create_releases_per_year_plot(release_df):
    release_df = release_df.copy()
    release_df["year"] = release_df["published_at"].dt.year
    releases_per_year_type = (
        release_df.groupby(["year", "type"]).size().reset_index(name="Releases")
    )
    return releases_per_year_type.hvplot.bar(
        x="year",
        y="Releases",
        by="type",
        stacked=True,
        cmap={"major": "#eb2f40", "minor": "#0e9c24", "patch": "#0e67bb"},
        xlabel="Year",
        ylabel="Number of Releases",
        title="Releases per Year (by Type)",
        hover_tooltips=[
            ("Year", "@year"),
            ("Type", "@type"),
            ("Releases", "@Releases"),
        ],
        height=300,
        responsive=True,
        legend="top_right",
    )


def create_issues_sankey(df):
    metrics = compute_metrics(df)
    # total = metrics["total_issues"]
    still_open = metrics["still_open"]
    closed = metrics["closed"]
    no_maint_resp = metrics["no_maintainer_response"]
    maint_resp = still_open - no_maint_resp if no_maint_resp is not None else 0
    # Sankey data: sources, targets, values
    sources = [
        "Total Issues Opened",
        "Total Issues Opened",
        "Issues still open",
        "Issues still open",
    ]
    targets = [
        "Issues still open",
        "Issues closed",
        "No Maintainer Response",
        "Maintainer Responded",
    ]
    values = [still_open, closed, no_maint_resp or 0, maint_resp]
    sankey_data = pd.DataFrame({"source": sources, "target": targets, "value": values})
    sankey = hv.Sankey(sankey_data)
    sankey = sankey.opts(
        label_position="left",
        cmap="Set1",
        node_color="index",
        edge_color="source",
        title="Issue Status Flow",
    )
    return sankey


def create_first_response_trend_plot(df):
    df = df.copy()
    # Only consider issues with a recorded first response time
    df = df[df["time_to_first_response"].notna()]
    df["first_response_days"] = df["time_to_first_response"].dt.days
    monthly = df.resample("ME").agg(
        avg_response=("first_response_days", "mean"),
        median_response=("first_response_days", "median"),
        count=("first_response_days", "count"),
    )
    return monthly[["avg_response", "median_response"]].hvplot.line(
        xlabel="Month",
        ylabel="Days to First Response",
        title="Time to First Response Trend",
        height=300,
        responsive=True,
        legend="top_right",
    )


# =============================
# UI Components (Filters, Selectors, etc.)
# =============================
styles = {
    "box-shadow": "rgba(50, 50, 93, 0.25) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px",
    "border-radius": "5px",
    "padding": "10px",
}

maintainer_filter = pmu.RadioButtonGroup(
    label="Maintainer Response",
    options=["All", "No Maintainer Response", "Maintainer Responded"],
    value="All",
    size="small",
    button_type="success",
)

status_filter = pmu.RadioButtonGroup(
    label="Issue Status",
    options=["All Issues", "Open Issues", "Closed Issues"],
    value="All Issues",
    size="small",
    button_type="success",
)


# =============================
# Views (Indicators, Plots, Table, Header)
# =============================
indicator_kwargs = dict(
    # font_size="25pt",
    # title_size="14pt",
    default_color=INDICATOR_COLOR,
    styles=styles,
)


@pn.depends(repo_selector)
def indicators_view(repo):
    df = repo_dfs[repo]
    metrics = compute_metrics(df)
    indicators = [
        pn.indicators.Number(
            value=metrics["avg_close_time"],
            name="Avg. time to close (days)",
            **indicator_kwargs,
        ),
        pn.indicators.Number(
            value=metrics["median_close_time"],
            name="Median time to close (days)",
            **indicator_kwargs,
        ),
    ]
    return pmu.FlexBox(*indicators)


# State variable to store the active tab index
active_tab_index = [0]


@pn.depends(repo_selector)
def plots_view(repo):
    df = repo_dfs[repo]
    release_df = release_dfs[repo]
    tabs = pmu.Tabs(
        ("Open vs Closed Issues", create_comparison_plot(df)),
        ("Open Issues over time", create_issues_plot(df)),
        ("First Response Trend", create_first_response_trend_plot(df)),
        ("Release History", create_release_plot(release_df, repo)),
        ("Releases per Year", create_releases_per_year_plot(release_df)),
        ("Issues by Milestone", create_milestone_plot(df)),
        ("Milestone Coverage", create_milestone_summary(df)),
        sizing_mode="scale_both",
        margin=10,
        dynamic=True,
        active=active_tab_index[0],
    )

    def on_tab_change(event):
        active_tab_index[0] = event.new

    tabs.param.watch(on_tab_change, "active")
    return tabs


@pn.depends(repo_selector, status_filter, maintainer_filter)
def table_view(repo, status, maintainer_resp):
    df = repo_dfs[repo].copy()
    # Convert assignees column from list to comma-separated string for Tabulator filtering
    if "assignees" in df.columns:
        df["assignees"] = df["assignees"].apply(
            lambda x: ", ".join(x)
            if isinstance(x, list)
            else str(x)
            if pd.notnull(x)
            else ""
        )
    if status == "Open Issues":
        df = df[df["time_to_close"].isna()]
    elif status == "Closed Issues":
        df = df[df["time_to_close"].notna()]
    # Filter by maintainer response
    if "maintainer_responded" in df.columns and maintainer_resp != "All":
        mask = df["maintainer_responded"].fillna(False)
        if maintainer_resp == "No Maintainer Response":
            df = df[~mask]
        elif maintainer_resp == "Maintainer Responded":
            df = df[mask]
    df["issue_no"] = df["html_url"].apply(format_issue_url)
    for col in ["time_to_first_response", "time_to_close"]:
        # Replace NaT with empty string
        df[col] = df[col].astype(str).replace("NaT", "")
        df[f"{col}_str"] = df[col]
    # Show maintainer_responded as a column
    if "maintainer_responded" in df.columns:
        df["Maintainer Responded"] = df["maintainer_responded"].map(
            {True: "Yes", False: "No"}
        )
        hidden_cols = [
            "html_url",
            "time_to_answer",
            "time_in_draft",
            "time_to_first_response",
            "time_to_close",
            "maintainer_responded",
        ]
    else:
        hidden_cols = [
            "html_url",
            "time_to_answer",
            "time_in_draft",
            "time_to_first_response",
            "time_to_close",
        ]
    # Reorder columns: prioritize 'title', 'issue_no', 'author' first
    priority_cols = ["title", "issue_no", "author"]
    rest_cols = [c for c in df.columns if c not in priority_cols]
    df = df[priority_cols + rest_cols]
    table = pn.widgets.Tabulator(
        df,
        name="Table",
        hidden_columns=hidden_cols,
        pagination="remote",
        page_size=10,
        formatters={"issue_no": "html"},
        widths={"title": 300},
        header_filters=True,
    )
    return pn.Column(pn.pane.Markdown(f"### Length of table: {len(df)} rows"), table)


@pn.depends(repo_selector)
def header_text(repo):
    df = repo_dfs[repo]
    metrics = compute_metrics(df)
    text = f"""
    ## {repo} Dashboard
    **Issue Metrics from {metrics["first_month"]} to {metrics["last_month"]}**
    """
    return text


# =============================
# Page Layout & App Launch
# =============================
note = """
The issue metrics shown here are not a full historical record, but represent a snapshot collected automatically at the start of each month.\n
Data covers issues from the start of the stated month up to the end of stated month, and is refreshed at the beginning of every new month.
"""
icon = pn.widgets.TooltipIcon(value=note)
logo = "https://holoviz.org/_static/holoviz-logo.svg"

logo_pane = pn.pane.Image(logo, width=200, align="center", margin=(10, 0, 10, 0))


# Define the issues_sankey_view function before the page layout
@pn.depends(repo_selector)
def issues_sankey_view(repo):
    df = repo_dfs[repo]
    return create_issues_sankey(df)


page = pmu.Page(
    main=[
        pn.Row(header_text, icon),
        "## Summary Insights",
        issues_sankey_view,
        indicators_view,
        "## Data Table",
        table_view,
        "## Plots",
        plots_view,
    ],
    sidebar=[
        logo_pane,
        repo_selector,
        "## Issue  Status",
        status_filter,
        "## Maintainer Response",
        maintainer_filter,
    ],
    title="HoloViz Issue Metrics Dashboard",
    theme_config={
        "palette": {
            "primary": {"main": HEADER_COLOR},
            "background": {
                "paper": PAPER_COLOR,
            },
        }
    },
    theme_toggle=False,
)

page.servable()