isaac commited on
Commit ·
729ee5e
1
Parent(s): cdcf306
fix: drop NaN scores so ranking is deterministic
Browse filesNaN cells kept via str(nan) sorted arbitrarily under reverse=True,
scrambling finding order run to run. _score_case and the Vast
handler keep finite scores only (pd.notna); parseDataframe,
parseLabel and normalize skip null/empty before Number() so no
zero-scored phantom findings appear.
Verified: pyflakes clean; PARSER_NULL_OK; tsc clean; build green.
- app.py +5 -1
- backend/vastai/handler.py +1 -1
- frontend/src/lib/radar.ts +15 -3
app.py
CHANGED
|
@@ -88,7 +88,11 @@ def _score_case(tmpdir, outdir):
|
|
| 88 |
raise gr.Error("model skipped this volume (check dimensions/spacing)")
|
| 89 |
row = df.iloc[0]
|
| 90 |
scores = {
|
| 91 |
-
_english_name(col): float(row[col])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
}
|
| 93 |
ranked = sorted(scores.items(), key=lambda kv: kv[1], reverse=True)
|
| 94 |
table = pd.DataFrame(ranked, columns=["Finding", "Score"])
|
|
|
|
| 88 |
raise gr.Error("model skipped this volume (check dimensions/spacing)")
|
| 89 |
row = df.iloc[0]
|
| 90 |
scores = {
|
| 91 |
+
_english_name(col): float(row[col])
|
| 92 |
+
for col in df.columns[1:]
|
| 93 |
+
# NaN sorts arbitrarily under reverse=True and scrambles ranking —
|
| 94 |
+
# keep finite scores only (phantom/empty cells come back NaN).
|
| 95 |
+
if pd.notna(row[col]) and str(row[col]).strip() != ""
|
| 96 |
}
|
| 97 |
ranked = sorted(scores.items(), key=lambda kv: kv[1], reverse=True)
|
| 98 |
table = pd.DataFrame(ranked, columns=["Finding", "Score"])
|
backend/vastai/handler.py
CHANGED
|
@@ -147,7 +147,7 @@ async def score(ct_files: list[UploadFile]):
|
|
| 147 |
scores = {
|
| 148 |
_english_name(col): float(row[col])
|
| 149 |
for col in df.columns[1:]
|
| 150 |
-
if str(row[col]).strip() != ""
|
| 151 |
}
|
| 152 |
rows = [
|
| 153 |
{"finding": k, "score": v}
|
|
|
|
| 147 |
scores = {
|
| 148 |
_english_name(col): float(row[col])
|
| 149 |
for col in df.columns[1:]
|
| 150 |
+
if pd.notna(row[col]) and str(row[col]).strip() != ""
|
| 151 |
}
|
| 152 |
rows = [
|
| 153 |
{"finding": k, "score": v}
|
frontend/src/lib/radar.ts
CHANGED
|
@@ -40,6 +40,10 @@ export function parseDataframe(payload: unknown): FindingRow[] {
|
|
| 40 |
const rows: FindingRow[] = [];
|
| 41 |
for (const entry of data) {
|
| 42 |
if (Array.isArray(entry) && entry.length >= 2) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
const score = Number(entry[1]);
|
| 44 |
if (entry[0] != null && entry[0] !== "" && Number.isFinite(score)) {
|
| 45 |
rows.push({ finding: String(entry[0]), score });
|
|
@@ -57,7 +61,9 @@ export function parseLabel(payload: unknown): Record<string, number> {
|
|
| 57 |
const out: Record<string, number> = {};
|
| 58 |
for (const entry of confidences) {
|
| 59 |
const label = (entry as { label?: unknown }).label;
|
| 60 |
-
const
|
|
|
|
|
|
|
| 61 |
if (typeof label === "string" && label !== "" && Number.isFinite(confidence)) {
|
| 62 |
out[label] = confidence;
|
| 63 |
}
|
|
@@ -66,7 +72,10 @@ export function parseLabel(payload: unknown): Record<string, number> {
|
|
| 66 |
}
|
| 67 |
const rec = payload as Record<string, unknown>;
|
| 68 |
const vals = Object.values(rec);
|
| 69 |
-
if (
|
|
|
|
|
|
|
|
|
|
| 70 |
const out: Record<string, number> = {};
|
| 71 |
for (const [k, v] of Object.entries(rec)) out[k] = Number(v);
|
| 72 |
return out;
|
|
@@ -79,7 +88,10 @@ export function normalize(
|
|
| 79 |
rows: FindingRow[],
|
| 80 |
): DiagnoseResult {
|
| 81 |
const clean: Record<string, number> = {};
|
| 82 |
-
for (const [k,
|
|
|
|
|
|
|
|
|
|
| 83 |
const n = Number(v);
|
| 84 |
if (Number.isFinite(n)) clean[k] = n;
|
| 85 |
}
|
|
|
|
| 40 |
const rows: FindingRow[] = [];
|
| 41 |
for (const entry of data) {
|
| 42 |
if (Array.isArray(entry) && entry.length >= 2) {
|
| 43 |
+
// Null/empty scores must be skipped BEFORE Number(): Number(null) is
|
| 44 |
+
// 0, which would fabricate a zero-scored finding (NaN cells come back
|
| 45 |
+
// null over the API for empty CSV cells).
|
| 46 |
+
if (entry[1] === null || entry[1] === undefined || entry[1] === "") continue;
|
| 47 |
const score = Number(entry[1]);
|
| 48 |
if (entry[0] != null && entry[0] !== "" && Number.isFinite(score)) {
|
| 49 |
rows.push({ finding: String(entry[0]), score });
|
|
|
|
| 61 |
const out: Record<string, number> = {};
|
| 62 |
for (const entry of confidences) {
|
| 63 |
const label = (entry as { label?: unknown }).label;
|
| 64 |
+
const raw = (entry as { confidence?: unknown }).confidence;
|
| 65 |
+
if (raw === null || raw === undefined || raw === "") continue;
|
| 66 |
+
const confidence = Number(raw);
|
| 67 |
if (typeof label === "string" && label !== "" && Number.isFinite(confidence)) {
|
| 68 |
out[label] = confidence;
|
| 69 |
}
|
|
|
|
| 72 |
}
|
| 73 |
const rec = payload as Record<string, unknown>;
|
| 74 |
const vals = Object.values(rec);
|
| 75 |
+
if (
|
| 76 |
+
vals.length > 0 &&
|
| 77 |
+
vals.every((v) => v !== null && v !== "" && Number.isFinite(Number(v)))
|
| 78 |
+
) {
|
| 79 |
const out: Record<string, number> = {};
|
| 80 |
for (const [k, v] of Object.entries(rec)) out[k] = Number(v);
|
| 81 |
return out;
|
|
|
|
| 88 |
rows: FindingRow[],
|
| 89 |
): DiagnoseResult {
|
| 90 |
const clean: Record<string, number> = {};
|
| 91 |
+
for (const [k, raw] of Object.entries(scores ?? {})) {
|
| 92 |
+
if (raw === null || raw === undefined) continue;
|
| 93 |
+
const v: unknown = raw;
|
| 94 |
+
if (typeof v === "string" && v.trim() === "") continue;
|
| 95 |
const n = Number(v);
|
| 96 |
if (Number.isFinite(n)) clean[k] = n;
|
| 97 |
}
|