bstein: serve direct-duration digital RCT reference runs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jenkins 2026-12-03 14:08:00 -06:00
parent 0e05c0cd38
commit d2f4e920ff
4 changed files with 36 additions and 21 deletions

View File

@ -1,33 +1,39 @@
import {attachSpeech} from './speech-watch.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';
const status = document.getElementById('path-state');
const detail = document.getElementById('path-detail');
const duration = document.getElementById('stage-duration');
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() {
for (const [index, option] of Array.from(duration.options).entries()) {
option.disabled = index > unlockedIndex;
option.disabled = !digitalTest && index > unlockedIndex;
}
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) {
if (device === input) return;
device = input; stageIndex = 0; unlockedIndex = 0; attempt++;
device = input; if (!digitalTest) stageIndex = 0; unlockedIndex = 0; attempt++;
renderStage();
}
export function beginStage(input) {
selectStageInput(input);
unlockedIndex = stageIndex;
renderStage();
return {minutes:STAGE_MINUTES[stageIndex], attempt:++attempt};
return {minutes:MINUTES[stageIndex], attempt:++attempt};
}
export async function reviewStage(run, reason, delivered) {
if (reason !== 'phone test complete') return;
if (reason !== 'phone test complete' || digitalTest) return;
const ok = await delivered;
if (attempt !== run.stage.attempt) return;
if (!ok) { status.textContent = 'Stage held · Atlas receipt unavailable'; return; }
@ -41,15 +47,15 @@ const clock = ms => {
export function setupPhoneMode() {
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;
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;
renderStage();
document.getElementById('local-review').hidden = !speechMode;
if (speechMode) status.title='Compare received speech to the phone phrase';
duration.onchange = () => {
if (!duration.disabled && duration.selectedIndex>=0 && duration.selectedIndex<=unlockedIndex) {
if (!duration.disabled && duration.selectedIndex>=0 && (digitalTest || duration.selectedIndex<=unlockedIndex)) {
stageIndex = duration.selectedIndex;
}
renderStage();

View File

@ -14,7 +14,7 @@ http {
}
map $http_x_av_stage $av_annotation {
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 {
default "";
@ -22,11 +22,11 @@ http {
}
map $http_x_av_speech $av_speech {
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 {
default "";
'~^1[|]1,' 1;
'~^1[|][12],' 1;
}
map $http_x_av_watch $av_watch {
default "";

View File

@ -43,32 +43,32 @@ export function stopState(reason) {
// Only fixed, bounded integers supplement an authenticated acoustic receipt.
// First-event offsets use offset+1, reserving zero for no event.
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 timing = [path.stageMinutes,Math.round(path.observedMs),offset(path.firstLevelDropMs),
Math.round(path.longestLevelDropMs),offset(path.firstUnclearMs),Math.round(path.gapMaxMs),
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 t=path.timing;
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];
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(',');
}
export function speechReceipt(speech) {
if (!speech) return null;
const integer = (v,min,max) => Number.isSafeInteger(v) && v>=min && v<=max;
if (!integer(speech.coverageMs,0,1800000) || !integer(speech.phase,-1,9999) ||
!integer(speech.phaseAgeMs,-1,1800000) || !integer(speech.total,0,999999) ||
if (!integer(speech.coverageMs,0,3600000) || !integer(speech.phase,-1,9999) ||
!integer(speech.phaseAgeMs,-1,3600000) || !integer(speech.total,0,999999) ||
!integer(speech.maxCadencePpm,-1000000,1000000) || !Array.isArray(speech.events) ||
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) {
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[3],0,1800000-row[2]) || !integer(row[4],-1000000,1000000) || !integer(row[5],-1,9999)) return null;
!integer(row[1],1,4) || !integer(row[2],0,3600000) ||
!integer(row[3],0,3600000-row[2]) || !integer(row[4],-1000000,1000000) || !integer(row[5],-1,9999)) return null;
rows.push(row);
}
return rows.map(row=>row.join(',')).join(';');

View File

@ -3,6 +3,7 @@ import {SpeechDetector} from './speech-detector.js';
import {LocalRecording} from './local-recording.js';
const el=id=>document.getElementById(id);
const digital=new URLSearchParams(location.search).get('test')==='digital';
let replayUrl=null, replayGeneration=0;
function resetReplay() {
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;
path.discontinuities+=run.pathInterruptions+Number(!!run.clockGap);
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 first=s.events[0]?.[2];
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';
el('path-detail').textContent='Reference matched '+time(s.coverageMs)+' of '+time(path.observedMs)+
(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'):
(finding?'Still measuring':path.locked?'Tracking speech':'Acquiring speech'))+' · '+clock+' / '+run.stage.minutes+':00'+
(finding?' · '+finding:'');