From 4b35e2392eb0abbcd9715ea03c363406b83000d3 Mon Sep 17 00:00:00 2001 From: averel10 Date: Fri, 20 Mar 2026 06:51:49 +0100 Subject: [PATCH] added experiment-table: refactored all frontend pages and services --- drizzle/0008_dark_gauntlet.sql | 10 + drizzle/0009_mysterious_brother_voodoo.sql | 2 + drizzle/meta/0008_snapshot.json | 719 +++++++++++++++++ drizzle/meta/0009_snapshot.json | 733 ++++++++++++++++++ drizzle/meta/_journal.json | 14 + src/app/actions/annotations.ts | 61 +- src/app/actions/experiment.ts | 0 .../annotate/[datasetId]/[prototype]/page.tsx | 16 +- src/app/page.tsx | 30 +- .../AnnotationViews/SingleChoiceView.tsx | 12 +- src/lib/dialects.ts | 4 +- src/lib/model/annotation.ts | 14 +- src/lib/model/experiment.ts | 34 + 13 files changed, 1598 insertions(+), 51 deletions(-) create mode 100644 drizzle/0008_dark_gauntlet.sql create mode 100644 drizzle/0009_mysterious_brother_voodoo.sql create mode 100644 drizzle/meta/0008_snapshot.json create mode 100644 drizzle/meta/0009_snapshot.json create mode 100644 src/app/actions/experiment.ts create mode 100644 src/lib/model/experiment.ts diff --git a/drizzle/0008_dark_gauntlet.sql b/drizzle/0008_dark_gauntlet.sql new file mode 100644 index 0000000..0b1995e --- /dev/null +++ b/drizzle/0008_dark_gauntlet.sql @@ -0,0 +1,10 @@ +CREATE TABLE `experiment` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `dataset_id` integer NOT NULL, + `created_at` integer DEFAULT (unixepoch()) NOT NULL, + `updated_at` integer DEFAULT (unixepoch()) NOT NULL, + FOREIGN KEY (`dataset_id`) REFERENCES `dataset`(`id`) ON UPDATE no action ON DELETE no action +); +--> statement-breakpoint +ALTER TABLE `annotation` ADD `experiment_id` integer NOT NULL REFERENCES experiment(id);--> statement-breakpoint +ALTER TABLE `annotation` ADD `updated_at` integer DEFAULT (unixepoch()) NOT NULL; \ No newline at end of file diff --git a/drizzle/0009_mysterious_brother_voodoo.sql b/drizzle/0009_mysterious_brother_voodoo.sql new file mode 100644 index 0000000..ed3f8ef --- /dev/null +++ b/drizzle/0009_mysterious_brother_voodoo.sql @@ -0,0 +1,2 @@ +ALTER TABLE `experiment` ADD `name` text NOT NULL;--> statement-breakpoint +ALTER TABLE `experiment` ADD `description` text; \ No newline at end of file diff --git a/drizzle/meta/0008_snapshot.json b/drizzle/meta/0008_snapshot.json new file mode 100644 index 0000000..9e9f009 --- /dev/null +++ b/drizzle/meta/0008_snapshot.json @@ -0,0 +1,719 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "a3364cec-3ada-496b-8fcb-f339074b04d7", + "prevId": "071a0744-4d6e-4657-948b-7eda495b9756", + "tables": { + "annotation": { + "name": "annotation", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "dataset_entry_id": { + "name": "dataset_entry_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "experiment_id": { + "name": "experiment_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "rating": { + "name": "rating", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "dialect_label": { + "name": "dialect_label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + } + }, + "indexes": {}, + "foreignKeys": { + "annotation_dataset_entry_id_dataset_entry_id_fk": { + "name": "annotation_dataset_entry_id_dataset_entry_id_fk", + "tableFrom": "annotation", + "tableTo": "dataset_entry", + "columnsFrom": [ + "dataset_entry_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "annotation_experiment_id_experiment_id_fk": { + "name": "annotation_experiment_id_experiment_id_fk", + "tableFrom": "annotation", + "tableTo": "experiment", + "columnsFrom": [ + "experiment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "account": { + "name": "account", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "account_userId_idx": { + "name": "account_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "session_token_unique": { + "name": "session_token_unique", + "columns": [ + "token" + ], + "isUnique": true + }, + "session_userId_idx": { + "name": "session_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email_verified": { + "name": "email_verified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "admin": { + "name": "admin", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "user_email_unique": { + "name": "user_email_unique", + "columns": [ + "email" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "verification": { + "name": "verification", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "verification_identifier_idx": { + "name": "verification_identifier_idx", + "columns": [ + "identifier" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "dataset_entry": { + "name": "dataset_entry", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "speaker_id": { + "name": "speaker_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "model_name": { + "name": "model_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "utterance_id": { + "name": "utterance_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "utterance_text": { + "name": "utterance_text", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "dataset_id": { + "name": "dataset_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "dialect": { + "name": "dialect", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "iteration": { + "name": "iteration", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rms_value": { + "name": "rms_value", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "longest_pause": { + "name": "longest_pause", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "utmos_score": { + "name": "utmos_score", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wer_score": { + "name": "wer_score", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + } + }, + "indexes": {}, + "foreignKeys": { + "dataset_entry_dataset_id_dataset_id_fk": { + "name": "dataset_entry_dataset_id_dataset_id_fk", + "tableFrom": "dataset_entry", + "tableTo": "dataset", + "columnsFrom": [ + "dataset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "dataset": { + "name": "dataset", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "experiment": { + "name": "experiment", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "dataset_id": { + "name": "dataset_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + } + }, + "indexes": {}, + "foreignKeys": { + "experiment_dataset_id_dataset_id_fk": { + "name": "experiment_dataset_id_dataset_id_fk", + "tableFrom": "experiment", + "tableTo": "dataset", + "columnsFrom": [ + "dataset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/0009_snapshot.json b/drizzle/meta/0009_snapshot.json new file mode 100644 index 0000000..5ccb5f8 --- /dev/null +++ b/drizzle/meta/0009_snapshot.json @@ -0,0 +1,733 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "4773999c-10cb-4a54-b2e8-aec0988f7a7b", + "prevId": "a3364cec-3ada-496b-8fcb-f339074b04d7", + "tables": { + "annotation": { + "name": "annotation", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "dataset_entry_id": { + "name": "dataset_entry_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "experiment_id": { + "name": "experiment_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "rating": { + "name": "rating", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "dialect_label": { + "name": "dialect_label", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + } + }, + "indexes": {}, + "foreignKeys": { + "annotation_dataset_entry_id_dataset_entry_id_fk": { + "name": "annotation_dataset_entry_id_dataset_entry_id_fk", + "tableFrom": "annotation", + "tableTo": "dataset_entry", + "columnsFrom": [ + "dataset_entry_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "annotation_experiment_id_experiment_id_fk": { + "name": "annotation_experiment_id_experiment_id_fk", + "tableFrom": "annotation", + "tableTo": "experiment", + "columnsFrom": [ + "experiment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "account": { + "name": "account", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "account_userId_idx": { + "name": "account_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "session_token_unique": { + "name": "session_token_unique", + "columns": [ + "token" + ], + "isUnique": true + }, + "session_userId_idx": { + "name": "session_userId_idx", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email_verified": { + "name": "email_verified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "admin": { + "name": "admin", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "user_email_unique": { + "name": "user_email_unique", + "columns": [ + "email" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "verification": { + "name": "verification", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(cast(unixepoch('subsecond') * 1000 as integer))" + } + }, + "indexes": { + "verification_identifier_idx": { + "name": "verification_identifier_idx", + "columns": [ + "identifier" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "dataset_entry": { + "name": "dataset_entry", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "speaker_id": { + "name": "speaker_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "model_name": { + "name": "model_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "utterance_id": { + "name": "utterance_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "utterance_text": { + "name": "utterance_text", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "dataset_id": { + "name": "dataset_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "dialect": { + "name": "dialect", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "iteration": { + "name": "iteration", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rms_value": { + "name": "rms_value", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "longest_pause": { + "name": "longest_pause", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "utmos_score": { + "name": "utmos_score", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wer_score": { + "name": "wer_score", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + } + }, + "indexes": {}, + "foreignKeys": { + "dataset_entry_dataset_id_dataset_id_fk": { + "name": "dataset_entry_dataset_id_dataset_id_fk", + "tableFrom": "dataset_entry", + "tableTo": "dataset", + "columnsFrom": [ + "dataset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "dataset": { + "name": "dataset", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "experiment": { + "name": "experiment", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "dataset_id": { + "name": "dataset_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + }, + "updated_at": { + "name": "updated_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(unixepoch())" + } + }, + "indexes": {}, + "foreignKeys": { + "experiment_dataset_id_dataset_id_fk": { + "name": "experiment_dataset_id_dataset_id_fk", + "tableFrom": "experiment", + "tableTo": "dataset", + "columnsFrom": [ + "dataset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index a85e5e6..a543343 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -57,6 +57,20 @@ "when": 1773410584481, "tag": "0007_light_spiral", "breakpoints": true + }, + { + "idx": 8, + "version": "6", + "when": 1773984793043, + "tag": "0008_dark_gauntlet", + "breakpoints": true + }, + { + "idx": 9, + "version": "6", + "when": 1773985687853, + "tag": "0009_mysterious_brother_voodoo", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/app/actions/annotations.ts b/src/app/actions/annotations.ts index e1c9e36..27d0d6f 100644 --- a/src/app/actions/annotations.ts +++ b/src/app/actions/annotations.ts @@ -7,44 +7,58 @@ import { annotation } from '@/lib/model/annotation'; import { eq, and } from 'drizzle-orm'; import { auth } from '@/lib/auth'; import { headers } from 'next/headers'; -import type { AnnotationEntry } from '@/lib/dialects'; +import type { DatasetEntryForAnnotation } from '@/lib/dialects'; +import { experiment } from '@/lib/model/experiment'; /** * Returns unannotated entries for the given dataset and authenticated user. */ -export async function getAnnotationEntries(datasetId: number): Promise { +export async function getAnnotationEntries(experimentId: number): Promise { const session = await auth.api.getSession({ headers: await headers() }); if (!session) throw new Error('Nicht angemeldet'); - const allEntries = await db + const currentExperiments = await db + .select() + .from(experiment) + .where(eq(experiment.id, experimentId)) + .leftJoin(dataset, eq(experiment.datasetId, dataset.id)) + .limit(1); + + if (currentExperiments.length === 0) { + throw new Error('Experiment nicht gefunden'); + } + + if(!currentExperiments[0].dataset) { + throw new Error('Experiment hat kein zugeordnetes Dataset'); + } + + const allDatasetEntries = await db .select() .from(dataset_entry) - .where(eq(dataset_entry.datasetId, datasetId)); + .where(eq(dataset_entry.datasetId, currentExperiments[0].dataset.id)); - if (allEntries.length === 0) return []; + if (allDatasetEntries.length === 0) return []; // Find entries already annotated by this user in this dataset (via join) - const annotated = await db - .select({ entryId: annotation.datasetEntryId }) + const annotationEntries = await db + .select() .from(annotation) - .innerJoin(dataset_entry, eq(annotation.datasetEntryId, dataset_entry.id)) .where( and( eq(annotation.userId, session.user.id), - eq(dataset_entry.datasetId, datasetId) + eq(annotation.experimentId, experimentId) ) ); - const annotatedIds = new Set(annotated.map((a) => a.entryId)); - const remaining = allEntries.filter((e) => !annotatedIds.has(e.id)); - - const mapped: AnnotationEntry[] = remaining.map((e) => ({ + const mapped: DatasetEntryForAnnotation[] = allDatasetEntries.map((e) => ({ id: e.id, externalId: e.externalId, fileName: e.fileName, dialect: e.dialect, durationMs: e.durationMs, + experimentId: experimentId, datasetId: e.datasetId, + annotation: annotationEntries.find((a) => a.datasetEntryId === e.id)?.rating || null, })); return mapped; @@ -55,7 +69,8 @@ export async function getAnnotationEntries(datasetId: number): Promise { const session = await auth.api.getSession({ headers: await headers() }); if (!session) throw new Error('Nicht angemeldet'); @@ -65,22 +80,30 @@ export async function saveAnnotations( for (const { entryId, rating, dialectLabel } of ratings) { await db .insert(annotation) - .values({ datasetEntryId: entryId, userId: session.user.id, rating, dialectLabel }) + .values({experimentId, datasetEntryId: entryId, userId: session.user.id, rating, dialectLabel }) .onConflictDoNothing(); } } /** Returns all datasets (for the home page). */ -export async function getAllDatasets() { - return db.select().from(dataset).orderBy(dataset.name); +export async function getAllExperiments() { + return db.select().from(experiment).orderBy(experiment.id); } /** Returns annotation progress for the current user in a dataset. */ export async function getAnnotationProgress( - datasetId: number + experimentId: number ): Promise<{ total: number; done: number }> { const session = await auth.api.getSession({ headers: await headers() }); + const datasetIdResult = await db + .select({ datasetId: experiment.datasetId }) + .from(experiment) + .where(eq(experiment.id, experimentId)) + .limit(1); + + const datasetId = datasetIdResult[0]?.datasetId; + const allEntries = await db .select({ id: dataset_entry.id }) .from(dataset_entry) @@ -97,7 +120,7 @@ export async function getAnnotationProgress( .where( and( eq(annotation.userId, session.user.id), - eq(dataset_entry.datasetId, datasetId) + eq(annotation.experimentId, experimentId) ) ); diff --git a/src/app/actions/experiment.ts b/src/app/actions/experiment.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/app/annotate/[datasetId]/[prototype]/page.tsx b/src/app/annotate/[datasetId]/[prototype]/page.tsx index 7ffc3b8..199dde9 100644 --- a/src/app/annotate/[datasetId]/[prototype]/page.tsx +++ b/src/app/annotate/[datasetId]/[prototype]/page.tsx @@ -6,20 +6,20 @@ import { getAnnotationEntries } from '@/app/actions/annotations'; import SingleChoiceView from '@/components/AnnotationViews/SingleChoiceView'; interface Props { - params: Promise<{ datasetId: string; prototype: string }>; + params: Promise<{ experimentId: string; prototype: string }>; } export default async function AnnotatePage({ params }: Props) { const session = await auth.api.getSession({ headers: await headers() }); if (!session) redirect('/user/sign-in'); - const { datasetId: datasetIdStr, prototype } = await params; - const datasetId = parseInt(datasetIdStr, 10); + const { experimentId: experimentIdStr, prototype } = await params; + const experimentId = parseInt(experimentIdStr, 10); - if (isNaN(datasetId)) { + if (isNaN(experimentId)) { return (
-

Ungültige Dataset-ID.

+

Ungültige Experiment-ID.

← Startseite @@ -31,7 +31,7 @@ export default async function AnnotatePage({ params }: Props) { notFound(); } - const entries = await getAnnotationEntries(datasetId); + const entries = await getAnnotationEntries(experimentId); if (entries.length === 0) { return ( @@ -41,7 +41,7 @@ export default async function AnnotatePage({ params }: Props) { Alle Samples bewertet!

- Sie haben alle Samples in diesem Dataset bereits bewertet. Danke für Ihre Mitarbeit! + Sie haben alle Samples in diesem Experiment bereits bewertet. Danke für Ihre Mitarbeit!

; + return ; } diff --git a/src/app/page.tsx b/src/app/page.tsx index e86ee7e..2a8136d 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,7 +1,7 @@ import Link from 'next/link'; import { headers } from 'next/headers'; import { auth } from '@/lib/auth'; -import { getAllDatasets, getAnnotationProgress } from '@/app/actions/annotations'; +import { getAllExperiments, getAnnotationProgress } from '@/app/actions/annotations'; export default async function HomePage() { const session = await auth.api.getSession({ headers: await headers() }); @@ -25,49 +25,49 @@ export default async function HomePage() { ); } - const datasets = await getAllDatasets(); + const experiments = await getAllExperiments(); - if (datasets.length === 0) { + if (experiments.length === 0) { return (

- Keine Datasets verfügbar + Keine Experimente verfügbar

- Es wurden noch keine Datasets angelegt. Wenden Sie sich an einen Administrator. + Es wurden noch keine Experimente freigeschalten. Wenden Sie sich an einen Administrator.

); } - // Fetch progress for all datasets in parallel + // Fetch progress for all experiments in parallel const progressData = await Promise.all( - datasets.map((ds) => getAnnotationProgress(ds.id)) + experiments.map((exp) => getAnnotationProgress(exp.id)) ); return (
-

Datasets

+

Experimente

- Wählen Sie ein Dataset aus, um mit der Annotation zu beginnen oder fortzufahren. + Wählen Sie ein Experiment aus, um mit der Annotation zu beginnen oder fortzufahren.

- {datasets.map((ds, i) => { + {experiments.map((exp, i) => { const { total, done } = progressData[i]; const pct = total > 0 ? Math.round((done / total) * 100) : 0; const isFinished = total > 0 && done >= total; return (
-

{ds.name}

- {ds.description && ( -

{ds.description}

+

{exp.name}

+ {exp.description && ( +

{exp.description}

)} {/* Progress */} @@ -88,7 +88,7 @@ export default async function HomePage() {
[ ]; interface SingleChoiceViewProps { - entries: AnnotationEntry[]; - datasetId: number; + entries: DatasetEntryForAnnotation[]; + experimentId: number; } -export default function SingleChoiceView({ entries, datasetId }: SingleChoiceViewProps) { +export default function SingleChoiceView({ entries, experimentId }: SingleChoiceViewProps) { const [isPending, startTransition] = useTransition(); @@ -46,7 +46,7 @@ export default function SingleChoiceView({ entries, datasetId }: SingleChoiceVie const timer = setTimeout(() => { const batch = pageEntries.map((e) => ({ entryId: e.id, rating: answers[e.id], dialectLabel: e.dialect })); startTransition(async () => { - await saveAnnotations(batch); + await saveAnnotations(batch, experimentId); if (currentPage + 1 >= totalPages) { setIsComplete(true); } else { @@ -108,7 +108,7 @@ export default function SingleChoiceView({ entries, datasetId }: SingleChoiceVie {pageEntries.map((entry, idx) => { const dialectLabel = DIALECT_LABELS[entry.dialect] ?? entry.dialect; const fileExt = entry.fileName.substring(entry.fileName.lastIndexOf('.')); - const audioSrc = `/public/datasets/${datasetId}/${entry.externalId}${fileExt}`; + const audioSrc = `/public/datasets/${entry.datasetId}/${entry.externalId}${fileExt}`; const isListened = fullyPlayed.has(entry.id); const currentRating = answers[entry.id] ?? null; diff --git a/src/lib/dialects.ts b/src/lib/dialects.ts index faa3d66..c29c7c1 100644 --- a/src/lib/dialects.ts +++ b/src/lib/dialects.ts @@ -9,11 +9,13 @@ export const DIALECT_LABELS: Record = { de: 'Deutsch', }; -export type AnnotationEntry = { +export type DatasetEntryForAnnotation = { id: number; externalId: string; fileName: string; dialect: string; durationMs: number | null; datasetId: number; + experimentId: number; + annotation: number | null; }; diff --git a/src/lib/model/annotation.ts b/src/lib/model/annotation.ts index 47e0057..1fcb28a 100644 --- a/src/lib/model/annotation.ts +++ b/src/lib/model/annotation.ts @@ -1,24 +1,34 @@ import { sqliteTable, text, integer, uniqueIndex } from 'drizzle-orm/sqlite-core'; import { relations, sql } from 'drizzle-orm'; import { dataset_entry } from './dataset_entry'; +import { experiment } from './experiment'; export const annotation = sqliteTable( 'annotation', { id: integer('id').primaryKey({ autoIncrement: true }), - datasetEntryId: integer('dataset_entry_id') + datasetEntryId: integer('dataset_entry_id').notNull().references(() => dataset_entry.id), + experimentId: integer('experiment_id') .notNull() - .references(() => dataset_entry.id), + .references(() => experiment.id), userId: text('user_id').notNull(), rating: integer('rating').notNull(), // 1–5 dialectLabel: text('dialect_label').notNull(), // e.g. 'ch_be', 'ch_zh', … createdAt: integer('created_at', { mode: 'timestamp' }) .notNull() .default(sql`(unixepoch())`), + updatedAt: integer('updated_at', { mode: 'timestamp' }) + .notNull() + .default(sql`(unixepoch())`) + .$onUpdate(() => sql`(unixepoch())`), } ); export const annotationRelations = relations(annotation, ({ one }) => ({ + experiment: one(experiment, { + fields: [annotation.experimentId], + references: [experiment.id], + }), datasetEntry: one(dataset_entry, { fields: [annotation.datasetEntryId], references: [dataset_entry.id], diff --git a/src/lib/model/experiment.ts b/src/lib/model/experiment.ts new file mode 100644 index 0000000..bc2e734 --- /dev/null +++ b/src/lib/model/experiment.ts @@ -0,0 +1,34 @@ +import { sqliteTable, text, integer, uniqueIndex } from 'drizzle-orm/sqlite-core'; +import { relations, sql } from 'drizzle-orm'; +import { annotation } from './annotation'; +import { dataset } from './dataset'; + +export const experiment = sqliteTable( + 'experiment', + { + id: integer('id').primaryKey({ autoIncrement: true }), + name: text('name').notNull(), + description: text('description'), + datasetId: integer('dataset_id') + .notNull() + .references(() => dataset.id), + createdAt: integer('created_at', { mode: 'timestamp' }) + .notNull() + .default(sql`(unixepoch())`), + updatedAt: integer('updated_at', { mode: 'timestamp' }) + .notNull() + .default(sql`(unixepoch())`) + .$onUpdate(() => sql`(unixepoch())`), + } +); + +export const experimentRelations = relations(experiment, ({ one, many }) => ({ + dataset: one(dataset, { + fields: [experiment.datasetId], + references: [dataset.id], + }), + annotations: many(annotation), +})); + +export type Experiment = typeof experiment.$inferSelect; +export type NewExperiment = typeof experiment.$inferInsert;