feat: add new fields to dataset_entry and update related components for processing and display

This commit is contained in:
averel10
2026-03-13 14:01:25 +01:00
parent 2b6d23c406
commit 4c9b4734e7
9 changed files with 667 additions and 35 deletions

View File

@@ -2,6 +2,7 @@
import db from '@/lib/db';
import { dataset_entry } from '@/lib/model/dataset_entry';
import { parseCSVLine } from '@/lib/csv-parser';
import { revalidatePath } from 'next/cache';
import { eq } from 'drizzle-orm';
import { writeFile, mkdir, readFile, rm } from 'fs/promises';
@@ -9,41 +10,6 @@ import { join } from 'path';
import { existsSync } from 'fs';
import { requireAdmin } from '@/lib/auth';
/**
* CSV parser that handles quoted fields
*/
function parseCSVLine(line: string): string[] {
const values: string[] = [];
let current = '';
let inQuotes = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
const nextChar = line[i + 1];
if (char === '"') {
if (inQuotes && nextChar === '"') {
// Escaped quote
current += '"';
i++;
} else {
// Toggle quote state
inQuotes = !inQuotes;
}
} else if (char === ',' && !inQuotes) {
// Field separator
values.push(current.trim());
current = '';
} else {
current += char;
}
}
// Add the last field
values.push(current.trim());
return values;
}
/**
* Step 2: Process the extracted ZIP data and insert into database
* Copies audio files and creates database entries
@@ -137,6 +103,10 @@ export async function processDatasetEntries(
dialect: row.dialect,
iteration: parseInt(row.iteration, 10),
durationMs: row.duration_ms ? parseInt(row.duration_ms, 10) : undefined,
rmsValue: row.rms_value ? parseFloat(row.rms_value) : undefined,
longestPause: row.longest_pause ? parseFloat(row.longest_pause) : undefined,
utmosScore: row.utmos_score ? parseFloat(row.utmos_score) : undefined,
werScore: row.wer_score ? parseFloat(row.wer_score) : undefined,
});
}
}