bstein: serve direct-duration digital RCT reference runs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0e05c0cd38
commit
d2f4e920ff
@ -1,33 +1,39 @@
|
|||||||
import {attachSpeech} from './speech-watch.js';
|
import {attachSpeech} from './speech-watch.js';
|
||||||
import {STAGE_MINUTES, TRIAL_SECONDS} from './acoustic-pattern.js';
|
import {STAGE_MINUTES, TRIAL_SECONDS} from './acoustic-pattern.js';
|
||||||
|
|
||||||
export const phoneTest = new URLSearchParams(location.search).get('test') === 'phone';
|
const query = new URLSearchParams(location.search);
|
||||||
|
// test=digital: direct duration, no staging/unlock, for a digitally injected reference.
|
||||||
|
export const digitalTest = query.get('test') === 'digital';
|
||||||
|
export const phoneTest = query.get('test') === 'phone' || digitalTest;
|
||||||
|
const DIGITAL_MINUTES = [1, 5, 10, 15, 20, 30, 60];
|
||||||
|
const MINUTES = digitalTest ? DIGITAL_MINUTES : STAGE_MINUTES;
|
||||||
export const speechMode = new URLSearchParams(location.search).get('signal') !== 'tones';
|
export const speechMode = new URLSearchParams(location.search).get('signal') !== 'tones';
|
||||||
const status = document.getElementById('path-state');
|
const status = document.getElementById('path-state');
|
||||||
const detail = document.getElementById('path-detail');
|
const detail = document.getElementById('path-detail');
|
||||||
const duration = document.getElementById('stage-duration');
|
const duration = document.getElementById('stage-duration');
|
||||||
const timing = document.getElementById('path-timing');
|
const timing = document.getElementById('path-timing');
|
||||||
let stageIndex = 0, unlockedIndex = 0, device = null, attempt = 0;
|
const requested = MINUTES.indexOf(Number(query.get('minutes')));
|
||||||
|
let stageIndex = digitalTest ? Math.max(0, requested) : 0, unlockedIndex = 0, device = null, attempt = 0;
|
||||||
function renderStage() {
|
function renderStage() {
|
||||||
for (const [index, option] of Array.from(duration.options).entries()) {
|
for (const [index, option] of Array.from(duration.options).entries()) {
|
||||||
option.disabled = index > unlockedIndex;
|
option.disabled = !digitalTest && index > unlockedIndex;
|
||||||
}
|
}
|
||||||
duration.selectedIndex = stageIndex;
|
duration.selectedIndex = stageIndex;
|
||||||
document.getElementById('start').textContent = 'Start ' + STAGE_MINUTES[stageIndex] + '-minute receiver';
|
document.getElementById('start').textContent = 'Start ' + MINUTES[stageIndex] + '-minute receiver';
|
||||||
}
|
}
|
||||||
export function selectStageInput(input) {
|
export function selectStageInput(input) {
|
||||||
if (device === input) return;
|
if (device === input) return;
|
||||||
device = input; stageIndex = 0; unlockedIndex = 0; attempt++;
|
device = input; if (!digitalTest) stageIndex = 0; unlockedIndex = 0; attempt++;
|
||||||
renderStage();
|
renderStage();
|
||||||
}
|
}
|
||||||
export function beginStage(input) {
|
export function beginStage(input) {
|
||||||
selectStageInput(input);
|
selectStageInput(input);
|
||||||
unlockedIndex = stageIndex;
|
unlockedIndex = stageIndex;
|
||||||
renderStage();
|
renderStage();
|
||||||
return {minutes:STAGE_MINUTES[stageIndex], attempt:++attempt};
|
return {minutes:MINUTES[stageIndex], attempt:++attempt};
|
||||||
}
|
}
|
||||||
export async function reviewStage(run, reason, delivered) {
|
export async function reviewStage(run, reason, delivered) {
|
||||||
if (reason !== 'phone test complete') return;
|
if (reason !== 'phone test complete' || digitalTest) return;
|
||||||
const ok = await delivered;
|
const ok = await delivered;
|
||||||
if (attempt !== run.stage.attempt) return;
|
if (attempt !== run.stage.attempt) return;
|
||||||
if (!ok) { status.textContent = 'Stage held · Atlas receipt unavailable'; return; }
|
if (!ok) { status.textContent = 'Stage held · Atlas receipt unavailable'; return; }
|
||||||
@ -41,15 +47,15 @@ const clock = ms => {
|
|||||||
|
|
||||||
export function setupPhoneMode() {
|
export function setupPhoneMode() {
|
||||||
if (!phoneTest) return;
|
if (!phoneTest) return;
|
||||||
document.title = 'RCT microphone path test';
|
document.title = digitalTest ? 'RCT digital reference run' : 'RCT microphone path test';
|
||||||
document.querySelector('h1').textContent = document.title;
|
document.querySelector('h1').textContent = document.title;
|
||||||
for (const minutes of STAGE_MINUTES) duration.add(new Option(minutes+' min',String(minutes)));
|
for (const minutes of MINUTES) duration.add(new Option(minutes+' min',String(minutes)));
|
||||||
document.getElementById('stage-label').hidden = false;
|
document.getElementById('stage-label').hidden = false;
|
||||||
renderStage();
|
renderStage();
|
||||||
document.getElementById('local-review').hidden = !speechMode;
|
document.getElementById('local-review').hidden = !speechMode;
|
||||||
if (speechMode) status.title='Compare received speech to the phone phrase';
|
if (speechMode) status.title='Compare received speech to the phone phrase';
|
||||||
duration.onchange = () => {
|
duration.onchange = () => {
|
||||||
if (!duration.disabled && duration.selectedIndex>=0 && duration.selectedIndex<=unlockedIndex) {
|
if (!duration.disabled && duration.selectedIndex>=0 && (digitalTest || duration.selectedIndex<=unlockedIndex)) {
|
||||||
stageIndex = duration.selectedIndex;
|
stageIndex = duration.selectedIndex;
|
||||||
}
|
}
|
||||||
renderStage();
|
renderStage();
|
||||||
|
|||||||
@ -14,7 +14,7 @@ http {
|
|||||||
}
|
}
|
||||||
map $http_x_av_stage $av_annotation {
|
map $http_x_av_stage $av_annotation {
|
||||||
default "";
|
default "";
|
||||||
'~^(1|5|10|15|20|30)(,[0-9]{1,7}){6},(0|[0-9]{13}),[0-9]{1,5}(,-?[0-9]{1,7}){7}$' $http_x_av_stage;
|
'~^(1|5|10|15|20|30|60)(,[0-9]{1,7}){6},(0|[0-9]{13}),[0-9]{1,5}(,-?[0-9]{1,7}){7}$' $http_x_av_stage;
|
||||||
}
|
}
|
||||||
map "$uri|$upstream_status|$av_identity|$av_annotation" $av_ack {
|
map "$uri|$upstream_status|$av_identity|$av_annotation" $av_ack {
|
||||||
default "";
|
default "";
|
||||||
@ -22,11 +22,11 @@ http {
|
|||||||
}
|
}
|
||||||
map $http_x_av_speech $av_speech {
|
map $http_x_av_speech $av_speech {
|
||||||
default "";
|
default "";
|
||||||
'~^1,[0-9]{1,7},-?[0-9]{1,4},-?[0-9]{1,7},[0-9]{1,6},-?[0-9]{1,7}(;[0-9]{1,6},[1-4],[0-9]{1,7},[0-9]{1,7},-?[0-9]{1,7},-?[0-9]{1,4}){0,16}$' $http_x_av_speech;
|
'~^[12],[0-9]{1,7},-?[0-9]{1,4},-?[0-9]{1,7},[0-9]{1,6},-?[0-9]{1,7}(;[0-9]{1,6},[1-4],[0-9]{1,7},[0-9]{1,7},-?[0-9]{1,7},-?[0-9]{1,4}){0,16}$' $http_x_av_speech;
|
||||||
}
|
}
|
||||||
map "$av_ack|$av_speech" $av_speech_ack {
|
map "$av_ack|$av_speech" $av_speech_ack {
|
||||||
default "";
|
default "";
|
||||||
'~^1[|]1,' 1;
|
'~^1[|][12],' 1;
|
||||||
}
|
}
|
||||||
map $http_x_av_watch $av_watch {
|
map $http_x_av_watch $av_watch {
|
||||||
default "";
|
default "";
|
||||||
|
|||||||
@ -43,32 +43,32 @@ export function stopState(reason) {
|
|||||||
// Only fixed, bounded integers supplement an authenticated acoustic receipt.
|
// Only fixed, bounded integers supplement an authenticated acoustic receipt.
|
||||||
// First-event offsets use offset+1, reserving zero for no event.
|
// First-event offsets use offset+1, reserving zero for no event.
|
||||||
export function acousticReceipt(path, clock) {
|
export function acousticReceipt(path, clock) {
|
||||||
if (!path || ![1,5,10,15,20,30].includes(path.stageMinutes)) return null;
|
if (!path || ![1,5,10,15,20,30,60].includes(path.stageMinutes)) return null;
|
||||||
const offset = value => value === null ? 0 : Math.round(value) + 1;
|
const offset = value => value === null ? 0 : Math.round(value) + 1;
|
||||||
const timing = [path.stageMinutes,Math.round(path.observedMs),offset(path.firstLevelDropMs),
|
const timing = [path.stageMinutes,Math.round(path.observedMs),offset(path.firstLevelDropMs),
|
||||||
Math.round(path.longestLevelDropMs),offset(path.firstUnclearMs),Math.round(path.gapMaxMs),
|
Math.round(path.longestLevelDropMs),offset(path.firstUnclearMs),Math.round(path.gapMaxMs),
|
||||||
path.discontinuities];
|
path.discontinuities];
|
||||||
if (!timing.every(v=>Number.isSafeInteger(v) && v>=0 && v<=1800011)) return null;
|
if (!timing.every(v=>Number.isSafeInteger(v) && v>=0 && v<=3600011)) return null;
|
||||||
const end = clock && Number.isFinite(path.observedAtMono) ? Math.round(path.observedAtMono + clock.offset) : 0;
|
const end = clock && Number.isFinite(path.observedAtMono) ? Math.round(path.observedAtMono + clock.offset) : 0;
|
||||||
const t=path.timing;
|
const t=path.timing;
|
||||||
if (!t) return null;
|
if (!t) return null;
|
||||||
const warp=[Math.round(t.rateCoverageMs),t.edgeCount,t.maxRatePpm,offset(t.firstRateMs),t.maxShiftMs,offset(t.firstShiftMs),t.baselinePpm??0];
|
const warp=[Math.round(t.rateCoverageMs),t.edgeCount,t.maxRatePpm,offset(t.firstRateMs),t.maxShiftMs,offset(t.firstShiftMs),t.baselinePpm??0];
|
||||||
if (!warp.every(v=>Number.isSafeInteger(v) && Math.abs(v)<=1800011)) return null;
|
if (!warp.every(v=>Number.isSafeInteger(v) && Math.abs(v)<=3600011)) return null;
|
||||||
return [...timing,end,clock?.uncertainty ?? 0,...warp].join(',');
|
return [...timing,end,clock?.uncertainty ?? 0,...warp].join(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function speechReceipt(speech) {
|
export function speechReceipt(speech) {
|
||||||
if (!speech) return null;
|
if (!speech) return null;
|
||||||
const integer = (v,min,max) => Number.isSafeInteger(v) && v>=min && v<=max;
|
const integer = (v,min,max) => Number.isSafeInteger(v) && v>=min && v<=max;
|
||||||
if (!integer(speech.coverageMs,0,1800000) || !integer(speech.phase,-1,9999) ||
|
if (!integer(speech.coverageMs,0,3600000) || !integer(speech.phase,-1,9999) ||
|
||||||
!integer(speech.phaseAgeMs,-1,1800000) || !integer(speech.total,0,999999) ||
|
!integer(speech.phaseAgeMs,-1,3600000) || !integer(speech.total,0,999999) ||
|
||||||
!integer(speech.maxCadencePpm,-1000000,1000000) || !Array.isArray(speech.events) ||
|
!integer(speech.maxCadencePpm,-1000000,1000000) || !Array.isArray(speech.events) ||
|
||||||
speech.events.length>16) return null;
|
speech.events.length>16) return null;
|
||||||
const rows=[[1,speech.coverageMs,speech.phase,speech.phaseAgeMs,speech.total,speech.maxCadencePpm]];
|
const rows=[[speech.kind===2?2:1,speech.coverageMs,speech.phase,speech.phaseAgeMs,speech.total,speech.maxCadencePpm]];
|
||||||
for (const row of speech.events) {
|
for (const row of speech.events) {
|
||||||
if (!Array.isArray(row) || row.length!==6 || !integer(row[0],1,speech.total) ||
|
if (!Array.isArray(row) || row.length!==6 || !integer(row[0],1,speech.total) ||
|
||||||
!integer(row[1],1,4) || !integer(row[2],0,1800000) ||
|
!integer(row[1],1,4) || !integer(row[2],0,3600000) ||
|
||||||
!integer(row[3],0,1800000-row[2]) || !integer(row[4],-1000000,1000000) || !integer(row[5],-1,9999)) return null;
|
!integer(row[3],0,3600000-row[2]) || !integer(row[4],-1000000,1000000) || !integer(row[5],-1,9999)) return null;
|
||||||
rows.push(row);
|
rows.push(row);
|
||||||
}
|
}
|
||||||
return rows.map(row=>row.join(',')).join(';');
|
return rows.map(row=>row.join(',')).join(';');
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import {SpeechDetector} from './speech-detector.js';
|
|||||||
import {LocalRecording} from './local-recording.js';
|
import {LocalRecording} from './local-recording.js';
|
||||||
|
|
||||||
const el=id=>document.getElementById(id);
|
const el=id=>document.getElementById(id);
|
||||||
|
const digital=new URLSearchParams(location.search).get('test')==='digital';
|
||||||
let replayUrl=null, replayGeneration=0;
|
let replayUrl=null, replayGeneration=0;
|
||||||
function resetReplay() {
|
function resetReplay() {
|
||||||
el('hear-finding').hidden=true; el('hear-finding').onclick=null;
|
el('hear-finding').hidden=true; el('hear-finding').onclick=null;
|
||||||
@ -57,6 +58,8 @@ export async function attachSpeech(run, isCurrent, finish) {
|
|||||||
if(Math.abs(observedAtMono-run.pathStart-path.observedMs)>2000) run.clockGap=true;
|
if(Math.abs(observedAtMono-run.pathStart-path.observedMs)>2000) run.clockGap=true;
|
||||||
path.discontinuities+=run.pathInterruptions+Number(!!run.clockGap);
|
path.discontinuities+=run.pathInterruptions+Number(!!run.clockGap);
|
||||||
run.path={...path,observedAtMono};
|
run.path={...path,observedAtMono};
|
||||||
|
// Receipt kind 2 marks a digitally injected source; 1 is the phone/acoustic source.
|
||||||
|
if (digital) run.path.speech={...path.speech,kind:2};
|
||||||
const s=path.speech;
|
const s=path.speech;
|
||||||
const first=s.events[0]?.[2];
|
const first=s.events[0]?.[2];
|
||||||
if (Number.isFinite(first)) run.firstFindingMs=Math.min(run.firstFindingMs??Infinity,first);
|
if (Number.isFinite(first)) run.firstFindingMs=Math.min(run.firstFindingMs??Infinity,first);
|
||||||
@ -70,6 +73,12 @@ export async function attachSpeech(run, isCurrent, finish) {
|
|||||||
finding='Part of the phrase could not be verified';
|
finding='Part of the phrase could not be verified';
|
||||||
el('path-detail').textContent='Reference matched '+time(s.coverageMs)+' of '+time(path.observedMs)+
|
el('path-detail').textContent='Reference matched '+time(s.coverageMs)+' of '+time(path.observedMs)+
|
||||||
(s.total?' · '+s.total+' recorded observations':'');
|
(s.total?' · '+s.total+' recorded observations':'');
|
||||||
|
if (digital) {
|
||||||
|
el('path-state').textContent=(data.complete?'Digital run complete':path.locked?'Digital run':'Acquiring reference')+
|
||||||
|
' · '+clock+' / '+run.stage.minutes+':00 · '+s.total+' events';
|
||||||
|
if (data.complete) finish('phone test complete');
|
||||||
|
return;
|
||||||
|
}
|
||||||
el('path-state').textContent=(data.complete?(finding?'Stage held':'Stage complete'):
|
el('path-state').textContent=(data.complete?(finding?'Stage held':'Stage complete'):
|
||||||
(finding?'Still measuring':path.locked?'Tracking speech':'Acquiring speech'))+' · '+clock+' / '+run.stage.minutes+':00'+
|
(finding?'Still measuring':path.locked?'Tracking speech':'Acquiring speech'))+' · '+clock+' / '+run.stage.minutes+':00'+
|
||||||
(finding?' · '+finding:'');
|
(finding?' · '+finding:'');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user