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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
import duckdb
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import matplotlib.dates as mdates
|
| 5 |
+
import matplotlib.ticker as ticker
|
| 6 |
+
import pandas as pd
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
ORPHANS_FILE = "datasets/inventory-not-in-buildstepoutputs-2025-12-05-17:38:30Z.parquet"
|
| 10 |
+
INVENTORY_FILE = "datasets/inventory-2026-01-06T01-13Z.parquet"
|
| 11 |
+
OUTPUT_DIR = Path("graphs")
|
| 12 |
+
|
| 13 |
+
# Pastel colors
|
| 14 |
+
PASTEL_GREEN = "#77dd77"
|
| 15 |
+
PASTEL_RED = "#ff6961"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def plot_bar(ax, df, x_col, y_col, title, ylabel, color="steelblue", width=2.0, is_percentage=False):
|
| 19 |
+
ax.bar(df[x_col], df[y_col], width=width, color=color)
|
| 20 |
+
ax.set_title(title)
|
| 21 |
+
ax.set_xlabel("Date")
|
| 22 |
+
ax.set_ylabel(ylabel)
|
| 23 |
+
ax.grid(True, alpha=0.3)
|
| 24 |
+
ax.tick_params(axis="x", rotation=45)
|
| 25 |
+
if is_percentage:
|
| 26 |
+
ax.set_ylim(-5, 105)
|
| 27 |
+
else:
|
| 28 |
+
ax.set_ylim(-df[y_col].max() * 0.05, df[y_col].max() * 1.1)
|
| 29 |
+
ax.yaxis.set_major_formatter(ticker.FuncFormatter(lambda x, p: format(int(x), ",")))
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def main():
|
| 33 |
+
OUTPUT_DIR.mkdir(exist_ok=True)
|
| 34 |
+
con = duckdb.connect()
|
| 35 |
+
|
| 36 |
+
# === MONTHLY GRAPHS ===
|
| 37 |
+
fig, axes = plt.subplots(3, 1, figsize=(14, 18))
|
| 38 |
+
|
| 39 |
+
df = con.execute(
|
| 40 |
+
"""
|
| 41 |
+
WITH orphans AS (
|
| 42 |
+
SELECT date_trunc('month', last_modified_date) as period, COUNT(*) as count
|
| 43 |
+
FROM read_parquet(?)
|
| 44 |
+
GROUP BY 1
|
| 45 |
+
),
|
| 46 |
+
inventory AS (
|
| 47 |
+
SELECT date_trunc('month', last_modified_date) as period, COUNT(*) as count
|
| 48 |
+
FROM read_parquet(?)
|
| 49 |
+
WHERE key LIKE '%.narinfo'
|
| 50 |
+
AND last_modified_date <= TIMESTAMP '2025-12-05 17:38:30Z'
|
| 51 |
+
GROUP BY 1
|
| 52 |
+
)
|
| 53 |
+
SELECT i.period,
|
| 54 |
+
COALESCE(o.count, 0) as orphan_count,
|
| 55 |
+
i.count as total_count,
|
| 56 |
+
ROUND(COALESCE(o.count, 0) * 100.0 / i.count, 2) as percentage
|
| 57 |
+
FROM inventory i
|
| 58 |
+
LEFT JOIN orphans o ON i.period = o.period
|
| 59 |
+
ORDER BY i.period
|
| 60 |
+
""",
|
| 61 |
+
[ORPHANS_FILE, INVENTORY_FILE],
|
| 62 |
+
).fetchdf()
|
| 63 |
+
|
| 64 |
+
plot_bar(axes[0], df, "period", "total_count", "Inventory Narinfo entries by Month", "Count", color=PASTEL_GREEN, width=25)
|
| 65 |
+
axes[0].xaxis.set_major_locator(mdates.YearLocator())
|
| 66 |
+
axes[0].xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
|
| 67 |
+
|
| 68 |
+
plot_bar(axes[1], df, "period", "orphan_count", "Inventory Narinfo entries not in buildstepoutputs by Month", "Count", color=PASTEL_RED, width=25)
|
| 69 |
+
axes[1].xaxis.set_major_locator(mdates.YearLocator())
|
| 70 |
+
axes[1].xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
|
| 71 |
+
|
| 72 |
+
plot_bar(axes[2], df, "period", "percentage", "Inventory Narinfo entries not in buildstepoutputs by Month (% of narinfos in inventory)", "Missing %", color=PASTEL_RED, width=25, is_percentage=True)
|
| 73 |
+
axes[2].xaxis.set_major_locator(mdates.YearLocator())
|
| 74 |
+
axes[2].xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
|
| 75 |
+
|
| 76 |
+
plt.tight_layout()
|
| 77 |
+
plt.savefig(OUTPUT_DIR / "inventory-not-in-buildstepoutputs-monthly.png", dpi=150)
|
| 78 |
+
plt.close()
|
| 79 |
+
|
| 80 |
+
# === DAILY GRAPHS ===
|
| 81 |
+
fig, axes = plt.subplots(3, 1, figsize=(14, 18))
|
| 82 |
+
|
| 83 |
+
df = con.execute(
|
| 84 |
+
"""
|
| 85 |
+
WITH orphans AS (
|
| 86 |
+
SELECT date_trunc('day', last_modified_date) as period, COUNT(*) as count
|
| 87 |
+
FROM read_parquet(?)
|
| 88 |
+
GROUP BY 1
|
| 89 |
+
),
|
| 90 |
+
inventory AS (
|
| 91 |
+
SELECT date_trunc('day', last_modified_date) as period, COUNT(*) as count
|
| 92 |
+
FROM read_parquet(?)
|
| 93 |
+
WHERE key LIKE '%.narinfo'
|
| 94 |
+
AND last_modified_date <= TIMESTAMP '2025-12-05 17:38:30Z'
|
| 95 |
+
GROUP BY 1
|
| 96 |
+
)
|
| 97 |
+
SELECT i.period,
|
| 98 |
+
COALESCE(o.count, 0) as orphan_count,
|
| 99 |
+
i.count as total_count,
|
| 100 |
+
ROUND(COALESCE(o.count, 0) * 100.0 / i.count, 2) as percentage
|
| 101 |
+
FROM inventory i
|
| 102 |
+
LEFT JOIN orphans o ON i.period = o.period
|
| 103 |
+
ORDER BY i.period
|
| 104 |
+
""",
|
| 105 |
+
[ORPHANS_FILE, INVENTORY_FILE],
|
| 106 |
+
).fetchdf()
|
| 107 |
+
|
| 108 |
+
plot_bar(axes[0], df, "period", "total_count", "Inventory Narinfo entries by Day", "Count", color=PASTEL_GREEN)
|
| 109 |
+
axes[0].xaxis.set_major_locator(mdates.YearLocator())
|
| 110 |
+
axes[0].xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
|
| 111 |
+
|
| 112 |
+
plot_bar(axes[1], df, "period", "orphan_count", "Inventory Narinfo entries not in buildstepoutputs by Day (Count)", "Count", color=PASTEL_RED)
|
| 113 |
+
axes[1].xaxis.set_major_locator(mdates.YearLocator())
|
| 114 |
+
axes[1].xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
|
| 115 |
+
|
| 116 |
+
plot_bar(axes[2], df, "period", "percentage", "Inventory Narinfo entries not in buildstepoutputs by Day (% of narinfos in inventory)", "Missing %", color=PASTEL_RED, is_percentage=True)
|
| 117 |
+
axes[2].xaxis.set_major_locator(mdates.YearLocator())
|
| 118 |
+
axes[2].xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
|
| 119 |
+
|
| 120 |
+
plt.tight_layout()
|
| 121 |
+
plt.savefig(OUTPUT_DIR / "inventory-not-in-buildstepoutputs-daily.png", dpi=150)
|
| 122 |
+
plt.close()
|
| 123 |
+
|
| 124 |
+
# === YEARLY COMPARISON GRAPH ===
|
| 125 |
+
fig, ax1 = plt.subplots(figsize=(14, 8))
|
| 126 |
+
|
| 127 |
+
df = con.execute(
|
| 128 |
+
"""
|
| 129 |
+
WITH orphans AS (
|
| 130 |
+
SELECT date_trunc('year', last_modified_date) as period, COUNT(*) as count
|
| 131 |
+
FROM read_parquet(?)
|
| 132 |
+
GROUP BY 1
|
| 133 |
+
),
|
| 134 |
+
inventory AS (
|
| 135 |
+
SELECT date_trunc('year', last_modified_date) as period, COUNT(*) as count
|
| 136 |
+
FROM read_parquet(?)
|
| 137 |
+
WHERE key LIKE '%.narinfo'
|
| 138 |
+
AND last_modified_date <= TIMESTAMP '2025-12-05 17:38:30Z'
|
| 139 |
+
GROUP BY 1
|
| 140 |
+
)
|
| 141 |
+
SELECT i.period,
|
| 142 |
+
COALESCE(o.count, 0) as orphan_count,
|
| 143 |
+
i.count as total_count,
|
| 144 |
+
ROUND(COALESCE(o.count, 0) * 100.0 / i.count, 2) as percentage
|
| 145 |
+
FROM inventory i
|
| 146 |
+
LEFT JOIN orphans o ON i.period = o.period
|
| 147 |
+
ORDER BY i.period
|
| 148 |
+
""",
|
| 149 |
+
[ORPHANS_FILE, INVENTORY_FILE],
|
| 150 |
+
).fetchdf()
|
| 151 |
+
|
| 152 |
+
# Primary axis: total narinfos (green bars)
|
| 153 |
+
bar_width = 100
|
| 154 |
+
ax1.bar(df["period"] - pd.Timedelta(days=60), df["total_count"], width=bar_width, color=PASTEL_GREEN, label="Narinfos in Inventory")
|
| 155 |
+
ax1.set_xlabel("Year")
|
| 156 |
+
ax1.set_ylabel("Total Narinfos")
|
| 157 |
+
ax1.tick_params(axis="x", rotation=45)
|
| 158 |
+
ax1.set_ylim(-df["total_count"].max() * 0.05, df["total_count"].max() * 1.1)
|
| 159 |
+
ax1.yaxis.set_major_formatter(ticker.FuncFormatter(lambda x, p: format(int(x), ",")))
|
| 160 |
+
ax1.xaxis.set_major_locator(mdates.YearLocator())
|
| 161 |
+
ax1.xaxis.set_major_formatter(mdates.DateFormatter("%Y"))
|
| 162 |
+
ax1.grid(True, alpha=0.3)
|
| 163 |
+
|
| 164 |
+
# Secondary axis: percentage missing (red bars)
|
| 165 |
+
ax2 = ax1.twinx()
|
| 166 |
+
ax2.bar(df["period"] + pd.Timedelta(days=60), df["percentage"], width=bar_width, color=PASTEL_RED, label="Narinfos not in buildstepoutputs (%)")
|
| 167 |
+
ax2.set_ylabel("Missing %")
|
| 168 |
+
ax2.set_ylim(-5, 105)
|
| 169 |
+
|
| 170 |
+
fig.suptitle("Yearly Comparison: Total Narinfos vs Missing Entries %")
|
| 171 |
+
fig.legend(loc="upper right", bbox_to_anchor=(0.9, 0.9))
|
| 172 |
+
plt.tight_layout()
|
| 173 |
+
plt.savefig(OUTPUT_DIR / "inventory-not-in-buildstepoutputs-yearly-comparison.png", dpi=150)
|
| 174 |
+
plt.close()
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
if __name__ == "__main__":
|
| 178 |
+
main()
|
graphs/inventory-not-in-buildstepoutputs-daily.png
ADDED
|
Git LFS Details
|
graphs/inventory-not-in-buildstepoutputs-monthly.png
ADDED
|
Git LFS Details
|
graphs/inventory-not-in-buildstepoutputs-yearly-comparison.png
ADDED
|
Git LFS Details
|
shell.nix
CHANGED
|
@@ -9,5 +9,10 @@ pkgs.mkShell {
|
|
| 9 |
packages = [
|
| 10 |
pkgs.git-lfs
|
| 11 |
pkgs.git-xet
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
];
|
| 13 |
}
|
|
|
|
| 9 |
packages = [
|
| 10 |
pkgs.git-lfs
|
| 11 |
pkgs.git-xet
|
| 12 |
+
(pkgs.python313.withPackages (ps: [
|
| 13 |
+
ps.duckdb
|
| 14 |
+
ps.matplotlib
|
| 15 |
+
ps.pandas
|
| 16 |
+
]))
|
| 17 |
];
|
| 18 |
}
|