174 lines
9.1 KiB
TypeScript
174 lines
9.1 KiB
TypeScript
import { Database } from "bun:sqlite";
|
|
|
|
const db = new Database("/Users/fei/.streamline/data.sqlite", { readonly: true });
|
|
|
|
type Row = Record<string, any>;
|
|
const bugs = db.query("SELECT * FROM tasks").all() as Row[];
|
|
const feats = db.query("SELECT * FROM features").all() as Row[];
|
|
|
|
// ---- replicate shared/src/types.ts logic ----
|
|
function meegoIsClosed(m: string | null) {
|
|
const s = (m || "").toLowerCase();
|
|
return s === "close" || s === "closed" || s === "done";
|
|
}
|
|
function comboTaskStateOf(mrState: string | null, meegoState: string | null): "merged" | "awaiting_merge" | "awaiting_qa" | null {
|
|
const mr = (mrState || "").toLowerCase();
|
|
const meego = (meegoState || "").toLowerCase();
|
|
if (mr.startsWith("merg")) return "merged";
|
|
if (meego === "resolved" || meego === "open") return "awaiting_qa";
|
|
if (meego === "close" || meego === "closed" || meego === "done") {
|
|
if (mr === "closed" || mr === "close") return "merged";
|
|
return "awaiting_merge";
|
|
}
|
|
return null;
|
|
}
|
|
function isConfirmedUnrepro(status: string, meegoState: string | null) {
|
|
return status === "unreproducible" && meegoIsClosed(meegoState);
|
|
}
|
|
function bucketOfBug(t: Row): string {
|
|
const s = t.status;
|
|
if (s === "fixing") return "running";
|
|
if (s === "initializing" || s === "info_required" || s === "pending_confirmation") return "confirm";
|
|
if (s === "awaiting_fix") return "queued";
|
|
if (s === "manual_review") return "review";
|
|
if (s === "unreproducible") return isConfirmedUnrepro(s, t.meegoState) ? "confirmed_unrepro" : "unreproducible";
|
|
if (s === "fix_failed" || s === "cancelled") return "failed";
|
|
if (s === "fix_succeeded") {
|
|
const combo = comboTaskStateOf(t.mrState, t.meegoState);
|
|
if (combo === "merged") return "merged";
|
|
if (combo === "awaiting_merge") return "awaiting_merge";
|
|
return "awaiting_qa";
|
|
}
|
|
return "failed";
|
|
}
|
|
function bucketOfFeat(f: Row): string {
|
|
const s = f.status;
|
|
if (s === "implementing") return "running";
|
|
if (s === "initializing" || s === "info_required" || s === "pending_confirmation") return "confirm";
|
|
if (s === "awaiting_implementation") return "queued";
|
|
if (s === "manual_review") return "review";
|
|
if (s === "implementation_failed" || s === "cancelled") return "failed";
|
|
if (s === "completed") return "merged";
|
|
return "failed";
|
|
}
|
|
|
|
const pct = (n: number, d: number) => (d ? ((n / d) * 100).toFixed(1) : "0.0");
|
|
function median(arr: number[]) {
|
|
if (!arr.length) return 0;
|
|
const a = [...arr].sort((x, y) => x - y);
|
|
const m = Math.floor(a.length / 2);
|
|
return a.length % 2 ? a[m] : (a[m - 1] + a[m]) / 2;
|
|
}
|
|
function mean(arr: number[]) { return arr.length ? arr.reduce((s, x) => s + x, 0) / arr.length : 0; }
|
|
const fmtH = (ms: number) => (ms / 3600000).toFixed(2) + "h";
|
|
const fmtM = (ms: number) => (ms / 60000).toFixed(1) + "m";
|
|
|
|
// ===== 1. Totals by status =====
|
|
console.log("\n========== RAW STATUS COUNTS ==========");
|
|
const bugStatus: Record<string, number> = {};
|
|
for (const b of bugs) bugStatus[b.status] = (bugStatus[b.status] || 0) + 1;
|
|
const featStatus: Record<string, number> = {};
|
|
for (const f of feats) featStatus[f.status] = (featStatus[f.status] || 0) + 1;
|
|
console.log("BUGS total:", bugs.length, bugStatus);
|
|
console.log("FEATURES total:", feats.length, featStatus);
|
|
|
|
// ===== bucket counts =====
|
|
const bugBucket: Record<string, number> = {};
|
|
for (const b of bugs) { const k = bucketOfBug(b); bugBucket[k] = (bugBucket[k] || 0) + 1; }
|
|
const featBucket: Record<string, number> = {};
|
|
for (const f of feats) { const k = bucketOfFeat(f); featBucket[k] = (featBucket[k] || 0) + 1; }
|
|
console.log("\n========== BUCKETS ==========");
|
|
console.log("BUG buckets:", bugBucket);
|
|
console.log("FEATURE buckets:", featBucket);
|
|
|
|
// ===== 2. Completed = awaiting_merge + awaiting_qa + merged =====
|
|
const completedBuckets = new Set(["awaiting_merge", "awaiting_qa", "merged"]);
|
|
const bugCompleted = bugs.filter((b) => completedBuckets.has(bucketOfBug(b)));
|
|
const featCompleted = feats.filter((f) => completedBuckets.has(bucketOfFeat(f)));
|
|
const allCompleted = [...bugCompleted, ...featCompleted];
|
|
|
|
const bugMerged = bugs.filter((b) => bucketOfBug(b) === "merged");
|
|
const featMerged = feats.filter((f) => bucketOfFeat(f) === "merged");
|
|
|
|
console.log("\n========== COMPLETED (await-merge + await-qa + merged) ==========");
|
|
console.log("Total tasks (bugs+features):", bugs.length + feats.length);
|
|
console.log("Completed bugs:", bugCompleted.length, "/ bugs", bugs.length, `(${pct(bugCompleted.length, bugs.length)}%)`);
|
|
console.log("Completed features:", featCompleted.length, "/ features", feats.length, `(${pct(featCompleted.length, feats.length)}%)`);
|
|
console.log("Completed ALL:", allCompleted.length, `(${pct(allCompleted.length, bugs.length + feats.length)}% of all tasks)`);
|
|
console.log(" of which awaiting_merge:", (bugBucket.awaiting_merge||0)+(featBucket.awaiting_merge||0));
|
|
console.log(" of which awaiting_qa:", (bugBucket.awaiting_qa||0)+(featBucket.awaiting_qa||0));
|
|
console.log(" of which MERGED:", bugMerged.length + featMerged.length, `(bug ${bugMerged.length}, feat ${featMerged.length})`);
|
|
|
|
// ===== 3. Execution rounds (attempts) for completed =====
|
|
function roundDist(rows: Row[]) {
|
|
const d: Record<number, number> = {};
|
|
for (const r of rows) { const a = r.attempts ?? 0; d[a] = (d[a] || 0) + 1; }
|
|
return d;
|
|
}
|
|
// NOTE: rounds = attempts (runner sets attempts = prev+1 each fix round). first-pass = attempts==1
|
|
console.log("\n========== EXECUTION ROUNDS (rounds = attempts; 1 = first-pass) ==========");
|
|
function roundPct(rows: Row[]) {
|
|
const d = roundDist(rows); const tot = rows.length;
|
|
return Object.entries(d).sort((a,b)=>+a[0]-+b[0]).map(([k,v])=>`R${k}:${v}(${pct(v,tot)}%)`).join(" ");
|
|
}
|
|
console.log("Completed ALL:", roundPct(allCompleted));
|
|
console.log("Completed BUGS:", roundPct(bugCompleted));
|
|
console.log("Completed FEATURES:", roundPct(featCompleted));
|
|
const firstPassAll = allCompleted.filter((r) => (r.attempts ?? 0) === 1).length;
|
|
console.log(`First-pass (R1) ALL: ${firstPassAll}/${allCompleted.length} = ${pct(firstPassAll, allCompleted.length)}%`);
|
|
const le2 = allCompleted.filter((r)=>(r.attempts??0)<=2).length;
|
|
console.log(`Within 2 rounds ALL: ${le2}/${allCompleted.length} = ${pct(le2, allCompleted.length)}%`);
|
|
|
|
for (const plat of ["android", "ios"]) {
|
|
const rows = allCompleted.filter((r) => r.platform === plat);
|
|
const fp = rows.filter((r) => (r.attempts ?? 0) === 1).length;
|
|
console.log(` ${plat} (all): completed=${rows.length}, first-pass=${fp} (${pct(fp, rows.length)}%) ${roundPct(rows)}`);
|
|
}
|
|
for (const plat of ["android", "ios"]) {
|
|
const rows = bugCompleted.filter((r) => r.platform === plat);
|
|
const fp = rows.filter((r) => (r.attempts ?? 0) === 1).length;
|
|
console.log(` ${plat} (bugs): completed=${rows.length}, first-pass=${fp} (${pct(fp, rows.length)}%)`);
|
|
}
|
|
|
|
// ===== 4. Unreproducible =====
|
|
const unrepro = bugs.filter((b) => b.status === "unreproducible");
|
|
const unreproConfirmed = unrepro.filter((b) => meegoIsClosed(b.meegoState));
|
|
console.log("\n========== AUTO-JUDGED UNREPRODUCIBLE ==========");
|
|
console.log("Total unreproducible:", unrepro.length, `(${pct(unrepro.length, bugs.length)}% of bugs)`);
|
|
console.log(" accepted/confirmed (meego closed):", unreproConfirmed.length, `(${pct(unreproConfirmed.length, unrepro.length)}%)`);
|
|
console.log(" unconfirmed/pending:", unrepro.length - unreproConfirmed.length, `(${pct(unrepro.length - unreproConfirmed.length, unrepro.length)}%)`);
|
|
console.log(" by platform:", "android", unrepro.filter(b=>b.platform==="android").length, "ios", unrepro.filter(b=>b.platform==="ios").length);
|
|
|
|
// ===== 5. Execution time for completed (totalDurationMs) =====
|
|
console.log("\n========== EXECUTION TIME (completed tasks) ==========");
|
|
function durStats(rows: Row[], field: string) {
|
|
const vals = rows.map((r) => r[field]).filter((v) => typeof v === "number" && v > 0) as number[];
|
|
return { n: vals.length, mean: mean(vals), median: median(vals), vals };
|
|
}
|
|
for (const field of ["totalDurationMs", "durationMs"]) {
|
|
console.log(`\n-- field=${field} --`);
|
|
const all = durStats(allCompleted, field);
|
|
console.log(`ALL completed: n=${all.n} mean=${fmtH(all.mean)} (${fmtM(all.mean)}) median=${fmtH(all.median)} (${fmtM(all.median)})`);
|
|
for (const plat of ["android", "ios"]) {
|
|
const s = durStats(allCompleted.filter((r) => r.platform === plat), field);
|
|
console.log(` ${plat}: n=${s.n} mean=${fmtH(s.mean)} (${fmtM(s.mean)}) median=${fmtH(s.median)} (${fmtM(s.median)})`);
|
|
}
|
|
// bugs only
|
|
const sb = durStats(bugCompleted, field);
|
|
console.log(` bugs-only: n=${sb.n} mean=${fmtH(sb.mean)} median=${fmtH(sb.median)}`);
|
|
}
|
|
|
|
// ===== platform split of all tasks =====
|
|
console.log("\n========== PLATFORM SPLIT (all tasks) ==========");
|
|
for (const plat of ["android", "ios"]) {
|
|
console.log(`${plat}: bugs=${bugs.filter(b=>b.platform===plat).length} features=${feats.filter(f=>f.platform===plat).length}`);
|
|
}
|
|
|
|
// first-pass per platform bugs-only too
|
|
console.log("\n========== FIRST-PASS by platform (bugs only, completed) ==========");
|
|
for (const plat of ["android", "ios"]) {
|
|
const rows = bugCompleted.filter((r) => r.platform === plat);
|
|
const fp = rows.filter((r) => (r.attempts ?? 0) === 0).length;
|
|
console.log(` ${plat}: ${fp}/${rows.length} = ${pct(fp, rows.length)}%`);
|
|
}
|