get random line for tagging

trunk
HeNine 3 years ago
parent ec2929c99f
commit 0c43bcb714

@ -62,6 +62,13 @@ CREATE TABLE buscribe_line_speakers
PRIMARY KEY (line, speaker, verifier) PRIMARY KEY (line, speaker, verifier)
); );
CREATE TABLE buscribe_line_inferred_speakers
(
line BIGINT NOT NULL REFERENCES buscribe_transcriptions,
speaker BIGINT NOT NULL REFERENCES buscribe_speakers,
PRIMARY KEY (line, speaker)
);
CREATE TABLE buscribe_verified_lines CREATE TABLE buscribe_verified_lines
( (
-- id BIGSERIAL PRIMARY KEY, -- id BIGSERIAL PRIMARY KEY,
@ -107,12 +114,18 @@ SELECT id,
start_time, start_time,
end_time, end_time,
null AS verifier, null AS verifier,
null AS names, names,
transcription_line, transcription_line,
to_tsvector('english', transcription_line) AS transcription_line_ts, to_tsvector('english', transcription_line) AS transcription_line_ts,
null AS names_ts, null AS names_ts,
transcription_json transcription_json
FROM buscribe_transcriptions; FROM buscribe_transcriptions
LEFT OUTER JOIN (
SELECT line, array_agg(name) AS names
FROM buscribe_line_inferred_speakers
INNER JOIN buscribe_speakers ON buscribe_line_inferred_speakers.speaker = buscribe_speakers.id
GROUP BY line
) AS speakers ON id = speakers.line;
ROLLBACK; ROLLBACK;

@ -1,6 +1,7 @@
import re import re
import urllib.parse import urllib.parse
from functools import wraps from functools import wraps
from random import randrange
import flask import flask
import gevent import gevent
@ -63,7 +64,27 @@ def get_line(line_id):
if line is None: if line is None:
return "Line not found.", 404 return "Line not found.", 404
else: else:
return {"start_time": line.start_time.isoformat(), return {"id": line.id,
"start_time": line.start_time.isoformat(),
"end_time": line.end_time.isoformat(),
"line_data": line.transcription_json}
@app.route('/professor/line/random', methods=["GET"])
def get_random_line():
db_conn = app.db_manager.get_conn()
n_lines = database.query(db_conn, "SELECT count(*) AS n_lines FROM buscribe_transcriptions;").fetchone().n_lines
row = randrange(n_lines)
line = database.query(db_conn, "SELECT * FROM buscribe_transcriptions OFFSET %(row)s LIMIT 1;", row=row).fetchone()
if line is None:
return "Line not found.", 404
else:
return {"id": line.id,
"start_time": line.start_time.isoformat(),
"end_time": line.end_time.isoformat(), "end_time": line.end_time.isoformat(),
"line_data": line.transcription_json} "line_data": line.transcription_json}

@ -1,7 +1,13 @@
function pageReady() { function pageReady() {
const params = new URLSearchParams(document.location.search.substring(1)); const params = new URLSearchParams(document.location.search.substring(1));
let line_id;
if (params.get("line") !== "random") {
line_id = parseInt(params.get("line"), 10); line_id = parseInt(params.get("line"), 10);
} else {
line_id = "random"
}
videojs("player", { videojs("player", {
// src: "test.m3u8", // src: "test.m3u8",
@ -74,7 +80,8 @@ function loggedIn(response) {
} }
function fillLineInfo(line_json) { function fillLineInfo(line_json) {
// document.getElementById("original_transcription").innerText = line_json.line_data.text; line_id = line_json.id
line = line_json line = line_json
document.getElementById("original_transcription").innerHTML = line_json.line_data.result document.getElementById("original_transcription").innerHTML = line_json.line_data.result
.map(word => `<span style="opacity: ${word.conf}">${word.word}</span>`).join(" "); .map(word => `<span style="opacity: ${word.conf}">${word.word}</span>`).join(" ");

Loading…
Cancel
Save