2024-04-09 22:18:52 +02:00
|
|
|
# This file is part of the uutils coreutils package.
|
|
|
|
|
#
|
|
|
|
|
# For the full copyright and license information, please view the LICENSE
|
|
|
|
|
# file that was distributed with this source code.
|
|
|
|
|
|
2021-05-20 15:11:06 +02:00
|
|
|
import sys
|
|
|
|
|
|
2021-05-19 21:02:32 +02:00
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
import pandas as pd
|
2026-01-07 22:50:22 +01:00
|
|
|
import seaborn as sns
|
2021-05-19 21:05:34 +02:00
|
|
|
|
2026-01-07 23:15:37 +01:00
|
|
|
from graph_common import (
|
|
|
|
|
COLORS,
|
|
|
|
|
setup_theme,
|
|
|
|
|
apply_smoothing,
|
|
|
|
|
style_axes,
|
|
|
|
|
add_title,
|
|
|
|
|
style_legend,
|
|
|
|
|
add_reference_lines,
|
2026-05-01 17:46:36 +02:00
|
|
|
add_gnu_release_markers,
|
2026-01-07 23:15:37 +01:00
|
|
|
)
|
2026-01-07 23:03:00 +01:00
|
|
|
|
2022-12-05 14:05:37 +01:00
|
|
|
if len(sys.argv) <= 2:
|
2026-01-07 23:15:37 +01:00
|
|
|
print("graph.py: <json file> <title>")
|
|
|
|
|
sys.exit()
|
2022-11-07 09:11:25 +01:00
|
|
|
|
2021-05-20 15:11:06 +02:00
|
|
|
d = pd.read_json(sys.argv[1], orient="index")
|
2021-05-19 21:02:32 +02:00
|
|
|
df = pd.DataFrame(d)
|
2022-12-05 14:05:37 +01:00
|
|
|
title = sys.argv[2]
|
2021-05-20 15:11:06 +02:00
|
|
|
|
|
|
|
|
df.columns.names = ["date"]
|
2025-05-05 06:56:35 -07:00
|
|
|
df.index = pd.to_datetime(df.index, utc=True)
|
2021-05-20 15:11:06 +02:00
|
|
|
|
2021-05-19 21:05:34 +02:00
|
|
|
print(df)
|
2021-05-19 21:02:32 +02:00
|
|
|
|
2026-01-07 23:03:00 +01:00
|
|
|
# Set up modern theme
|
|
|
|
|
setup_theme()
|
2026-01-07 22:50:22 +01:00
|
|
|
|
|
|
|
|
# Create figure with better proportions and higher DPI
|
|
|
|
|
fig, ax = plt.subplots(figsize=(18, 9), dpi=100)
|
|
|
|
|
|
|
|
|
|
# Prepare data for plotting - melt to long format for Seaborn
|
2026-01-07 23:15:37 +01:00
|
|
|
plot_columns = ["total", "pass", "fail"]
|
|
|
|
|
if "error" in df.columns and df["error"].notna().any():
|
|
|
|
|
plot_columns.append("error")
|
|
|
|
|
plot_columns.append("skip")
|
2026-01-07 22:50:22 +01:00
|
|
|
|
|
|
|
|
df_plot = df[plot_columns].copy()
|
|
|
|
|
df_plot = df_plot.reset_index()
|
2026-01-07 23:15:37 +01:00
|
|
|
df_plot.rename(columns={df_plot.columns[0]: "date"}, inplace=True)
|
|
|
|
|
df_plot_long = df_plot.melt(id_vars="date", var_name="metric", value_name="count")
|
2026-01-07 22:50:22 +01:00
|
|
|
|
|
|
|
|
# Convert string values to numeric
|
2026-01-07 23:15:37 +01:00
|
|
|
df_plot_long["count"] = pd.to_numeric(df_plot_long["count"], errors="coerce")
|
2026-01-07 22:50:22 +01:00
|
|
|
|
|
|
|
|
# Apply smoothing using rolling average (window of 15 for smoother lines)
|
2026-01-07 23:15:37 +01:00
|
|
|
df_plot_long["count_smooth"] = apply_smoothing(df_plot_long, "metric", "count")
|
2026-01-07 22:50:22 +01:00
|
|
|
|
2026-01-07 23:03:00 +01:00
|
|
|
# Use color palette from common module
|
2026-01-07 23:15:37 +01:00
|
|
|
palette = {k: COLORS[k] for k in ["total", "pass", "fail", "error", "skip"]}
|
2026-01-07 22:50:22 +01:00
|
|
|
|
|
|
|
|
# Add gradient-like area fills first (behind lines)
|
2026-01-07 23:15:37 +01:00
|
|
|
for metric in ["total", "pass", "fail"]:
|
2026-01-07 22:50:22 +01:00
|
|
|
if metric in df_plot.columns:
|
2026-01-07 23:15:37 +01:00
|
|
|
ax.fill_between(
|
|
|
|
|
df_plot["date"],
|
|
|
|
|
0,
|
|
|
|
|
df_plot[metric],
|
|
|
|
|
alpha=0.18,
|
|
|
|
|
color=palette[metric],
|
|
|
|
|
zorder=1,
|
|
|
|
|
linewidth=0,
|
|
|
|
|
)
|
2026-01-07 22:50:22 +01:00
|
|
|
|
|
|
|
|
# Use Seaborn's lineplot with enhanced styling and smoothed data
|
|
|
|
|
sns.lineplot(
|
|
|
|
|
data=df_plot_long,
|
2026-01-07 23:15:37 +01:00
|
|
|
x="date",
|
|
|
|
|
y="count_smooth",
|
|
|
|
|
hue="metric",
|
2026-01-07 22:50:22 +01:00
|
|
|
palette=palette,
|
|
|
|
|
linewidth=3.5,
|
|
|
|
|
ax=ax,
|
|
|
|
|
markers=False, # Disable markers for smoother look
|
|
|
|
|
dashes=False,
|
|
|
|
|
alpha=1,
|
2026-01-07 23:15:37 +01:00
|
|
|
zorder=3,
|
2026-01-07 22:50:22 +01:00
|
|
|
)
|
|
|
|
|
|
2026-01-07 23:03:00 +01:00
|
|
|
# Add title and subtitle
|
2026-01-07 23:15:37 +01:00
|
|
|
add_title(
|
|
|
|
|
ax,
|
|
|
|
|
f"uutils coreutils — {title} Test Suite Results",
|
|
|
|
|
"Tracking test results over time to measure progress and compatibility",
|
|
|
|
|
)
|
2026-01-07 22:50:22 +01:00
|
|
|
|
2026-01-07 23:03:00 +01:00
|
|
|
# Style axes with labels and grid
|
2026-01-07 23:15:37 +01:00
|
|
|
style_axes(ax, xlabel="Date", ylabel="Number of Tests")
|
2026-01-07 22:50:22 +01:00
|
|
|
|
2026-01-07 23:03:00 +01:00
|
|
|
# Add reference lines
|
2026-01-07 23:15:37 +01:00
|
|
|
y_max = df_plot_long["count_smooth"].max()
|
2026-01-07 23:03:00 +01:00
|
|
|
add_reference_lines(ax, y_max)
|
2026-01-07 22:50:22 +01:00
|
|
|
|
2026-05-01 17:46:36 +02:00
|
|
|
# Add vertical bars for GNU coreutils releases
|
|
|
|
|
if title.lower() == "gnu":
|
|
|
|
|
add_gnu_release_markers(ax, df_plot["date"].min(), df_plot["date"].max(), y_max)
|
|
|
|
|
|
2026-01-07 23:03:00 +01:00
|
|
|
# Style legend
|
2026-01-07 22:50:22 +01:00
|
|
|
handles, labels = ax.get_legend_handles_labels()
|
|
|
|
|
labels = [label.capitalize() for label in labels]
|
2026-01-07 23:15:37 +01:00
|
|
|
style_legend(ax, handles, labels, ncol=len(plot_columns), loc="upper left")
|
2026-01-07 22:50:22 +01:00
|
|
|
|
2026-01-19 17:28:15 +01:00
|
|
|
# Add percentage box on the top right
|
|
|
|
|
latest_data = df.iloc[-1]
|
|
|
|
|
total = pd.to_numeric(latest_data["total"], errors="coerce")
|
|
|
|
|
pass_count = pd.to_numeric(latest_data["pass"], errors="coerce")
|
|
|
|
|
fail_count = pd.to_numeric(latest_data["fail"], errors="coerce")
|
|
|
|
|
skip_count = pd.to_numeric(latest_data["skip"], errors="coerce")
|
|
|
|
|
|
|
|
|
|
pass_pct = (pass_count / total) * 100 if total > 0 else 0
|
|
|
|
|
fail_pct = (fail_count / total) * 100 if total > 0 else 0
|
|
|
|
|
skip_pct = (skip_count / total) * 100 if total > 0 else 0
|
|
|
|
|
|
|
|
|
|
# Create text box
|
2026-01-30 17:23:39 +01:00
|
|
|
textstr = "Latest Results:\n"
|
2026-01-19 17:28:15 +01:00
|
|
|
textstr += f"Pass: {pass_pct:.1f}%\n"
|
|
|
|
|
textstr += f"Fail: {fail_pct:.1f}%\n"
|
|
|
|
|
textstr += f"Skip: {skip_pct:.1f}%"
|
|
|
|
|
|
|
|
|
|
# Add text box on the top right
|
2026-01-30 17:32:55 +01:00
|
|
|
props = dict(
|
|
|
|
|
boxstyle="round,pad=0.8",
|
|
|
|
|
facecolor="#FFFFFF",
|
|
|
|
|
edgecolor="#D1D5DB",
|
|
|
|
|
linewidth=2,
|
|
|
|
|
alpha=0.95,
|
|
|
|
|
)
|
2026-01-19 17:28:15 +01:00
|
|
|
ax.text(
|
|
|
|
|
0.98,
|
|
|
|
|
1.15,
|
|
|
|
|
textstr,
|
|
|
|
|
transform=ax.transAxes,
|
|
|
|
|
fontsize=14,
|
|
|
|
|
verticalalignment="top",
|
|
|
|
|
horizontalalignment="right",
|
|
|
|
|
bbox=props,
|
|
|
|
|
color="#374151",
|
|
|
|
|
fontweight="600",
|
|
|
|
|
zorder=10,
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-07 22:50:22 +01:00
|
|
|
# Tight layout
|
|
|
|
|
plt.tight_layout()
|
|
|
|
|
|
|
|
|
|
# Save with high quality and optimized settings
|
2026-01-07 23:15:37 +01:00
|
|
|
plt.savefig(
|
|
|
|
|
f"{title.lower()}-results.svg",
|
|
|
|
|
format="svg",
|
|
|
|
|
dpi=300,
|
|
|
|
|
bbox_inches="tight",
|
|
|
|
|
facecolor="white",
|
|
|
|
|
edgecolor="none",
|
|
|
|
|
metadata={
|
|
|
|
|
"Creator": "uutils coreutils tracking",
|
|
|
|
|
"Title": f"{title} Test Suite Results",
|
|
|
|
|
},
|
|
|
|
|
)
|