|
|
@@ -527,62 +527,97 @@
|
|
|
$("spectrogram").getContext("2d").fillRect(0, 0, 704, 300);
|
|
|
$("decisionExplanation").textContent = "Выберите один из контрольных примеров или загрузите аудио/видео со звуком. Порог изменяет только правило принятия решения.";
|
|
|
window.GOLOS_DEBUG = { extractFeatures, predict, makeAudioSpectrogram };
|
|
|
- // Built-in synchronized illustrative scenario (embedded video + staged dataset spectrograms).
|
|
|
- const demoVideo = document.getElementById('demoVideo');
|
|
|
- const demoStart = document.getElementById('demoStart');
|
|
|
- const demoReset = document.getElementById('demoReset');
|
|
|
- const demoAlert = document.getElementById('demoAlert');
|
|
|
- let demoRunning = false, demoTick = null, demoLastSlot = -1;
|
|
|
- const demoCandidates = SAMPLES.map(sample => {
|
|
|
- const bytes = decodeBase64(sample.base64);
|
|
|
- const result = predict(Float64Array.from(bytes, v => v * 0.3 - 45));
|
|
|
- return {sample, bytes, result};
|
|
|
- });
|
|
|
- const demoBg = demoCandidates.filter(x => !x.sample.label).sort((a,b)=>a.result.probability-b.result.probability);
|
|
|
- const demoUav = demoCandidates.filter(x => x.sample.label).sort((a,b)=>b.result.probability-a.result.probability);
|
|
|
- function pickDemoSample(uav, index){
|
|
|
- const list = uav ? demoUav : demoBg;
|
|
|
- return list[index % Math.max(1,list.length)] || demoCandidates[0];
|
|
|
+ // Embedded 40-second training scenario: audio + weather visuals + spectral display + manual scoring.
|
|
|
+ const demoStart = $('demoStart'), demoReset = $('demoReset'), demoAlert = $('demoAlert');
|
|
|
+ const demoAudio = $('demoAudio'), manualToggle = $('manualToggle');
|
|
|
+ let demoRunning=false, demoTimer=null, demoSecond=-1, demoScoring=[];
|
|
|
+ const scenarioDuration=40;
|
|
|
+ const drone=$('droneSilhouette'), snow=$('snowLayer'), visual=$('demoVisual');
|
|
|
+ // seconds 18..34: sound is present; the silhouette becomes visible only after 24 seconds.
|
|
|
+ // a weak drone-like sound at 7..9 is a deliberately ambiguous background cue (false-alarm trap).
|
|
|
+ function truthAt(t){return t>=18 && t<34;}
|
|
|
+ function autoAt(t){return (t>=18 && t<34) || (t>=7 && t<9);}
|
|
|
+ function autoConfidence(t){
|
|
|
+ if(t>=18&&t<34){return t<20?.58:t<24?.76:t<30?.93:t<32?.78:.61;}
|
|
|
+ if(t>=7&&t<9)return .69; // deliberately false positive
|
|
|
+ return .12+((Math.sin(t*2.1)+1)*.025);
|
|
|
+ }
|
|
|
+ function renderDemoSpec(t){
|
|
|
+ const bytes=new Uint8Array(64*44); const fade=(t>=18&&t<34)?Math.max(0,Math.min(1,(t-18)/4,(34-t)/4)):0;
|
|
|
+ const falseCue=(t>=7&&t<9)?0.24:0;
|
|
|
+ for(let f=0;f<64;f++)for(let x=0;x<44;x++){
|
|
|
+ const noise=18+((Math.sin(f*3.2+x*1.7+t*5)+Math.cos(f*.8-x*2.1+t*3))*8)+((f*11+x*7)%17);
|
|
|
+ const band=(f>=5&&f<=13)?12*Math.max(0,Math.sin(x*.8+t*2)):0;
|
|
|
+ const harmonic=fade*(f===9||f===18||f===27||f===36?100:((f%9===0)?45:0)) + falseCue*((f%9===0)?38:0);
|
|
|
+ const gust=(t<18||t>34)?22*Math.max(0,Math.sin(t*1.4+f*.5)):8;
|
|
|
+ bytes[f*44+x]=Math.max(0,Math.min(255,Math.round(noise+band+harmonic+gust)));
|
|
|
+ }
|
|
|
+ return bytes;
|
|
|
+ }
|
|
|
+ function drawRollingSpec(t){
|
|
|
+ const canvas=$('spectrogram'),ctx=canvas.getContext('2d');const W=canvas.width,H=canvas.height;
|
|
|
+ ctx.fillStyle='#101d24';ctx.fillRect(0,0,W,H);
|
|
|
+ const strip=renderDemoSpec(t),cw=W/44,ch=H/64;
|
|
|
+ for(let f=0;f<64;f++)for(let x=0;x<44;x++){
|
|
|
+ const v=strip[f*44+x],c=colorMap(v/255);
|
|
|
+ ctx.fillStyle=`rgb(${c[0]},${c[1]},${c[2]})`;ctx.fillRect(x*cw,H-(f+1)*ch,Math.ceil(cw),Math.ceil(ch));
|
|
|
+ }
|
|
|
+ ctx.strokeStyle='rgba(230,215,185,.25)';ctx.lineWidth=1;
|
|
|
+ for(let i=1;i<4;i++){ctx.beginPath();ctx.moveTo(0,H*i/4);ctx.lineTo(W,H*i/4);ctx.stroke();}
|
|
|
+ }
|
|
|
+ function statsFor(which){
|
|
|
+ let tp=0,fp=0,fn=0,tn=0;
|
|
|
+ for(const row of demoScoring){const pred=which==='manual'?row.manual:row.auto; if(row.truth&&pred)tp++;else if(!row.truth&&pred)fp++;else if(row.truth&&!pred)fn++;else tn++;}
|
|
|
+ return {tp,fp,fn,tn,score:Math.max(0,tp*10-fp*4-fn*6)};
|
|
|
+ }
|
|
|
+ function updateScoreboard(){
|
|
|
+ const m=statsFor('manual'),a=statsFor('auto');
|
|
|
+ $('manualScore').textContent=m.score; $('autoScore').textContent=a.score;
|
|
|
+ $('manualStats').textContent=`TP ${m.tp} · FP ${m.fp} · FN ${m.fn}`;
|
|
|
+ $('autoStats').textContent=`TP ${a.tp} · FP ${a.fp} · FN ${a.fn}`;
|
|
|
}
|
|
|
- function demoSlot(time){ return Math.floor(time); }
|
|
|
- function applyDemoSlot(slot){
|
|
|
- if(slot===demoLastSlot)return; demoLastSlot=slot;
|
|
|
- const event = slot>=6 && slot<13;
|
|
|
- const item = pickDemoSample(event, event?slot-6:slot<6?slot:slot-13);
|
|
|
- state.currentName = `СЦЕНАРИЙ · ${event?'БПЛА':'ФОН'} · ${slot+1}`;
|
|
|
- state.spec = item.bytes; state.probability = item.result.probability; state.components = item.result.components;
|
|
|
- state.truth = item.sample.label; state.windows = []; state.selectedWindow = 0;
|
|
|
- drawSpectrogram(item.bytes); drawComponents(item.result.components); renderDecision();
|
|
|
- $('specSource').textContent = `СЦЕНАРИЙ · ${slot+1}/18`;
|
|
|
- $('featuresSource').textContent = 'ДЕМОНСТРАЦИОННЫЙ ПРОГОН';
|
|
|
- $('analysisStatus').textContent = event ? 'СИГНАЛ В СЦЕНАРИИ' : 'ФОНОВОЕ НАБЛЮДЕНИЕ';
|
|
|
- $('analysisStatus').className = `status-pill ${event?'alert':'ready'}`;
|
|
|
- $('fileName').textContent = 'Встроенный сценарий синхронизирован с видеорядом';
|
|
|
- $('decisionLabel').textContent = event ? 'СИГНАЛ БПЛА' : 'ФОН';
|
|
|
- $('decisionLabel').className = `decision-label ${event?'detected':'background'}`;
|
|
|
- demoAlert.classList.toggle('detected',event);
|
|
|
- $('demoAlertText').textContent = event ? 'ТРЕВОГА · БПЛА' : 'НАБЛЮДЕНИЕ';
|
|
|
- $('demoAlertSub').textContent = event ? 'В сценарии присутствует характерный сигнал' : 'Звуковой фон в пределах сценария';
|
|
|
- $('demoCaption').textContent = event ? 'ОБНАРУЖЕН СИГНАЛ · РЕЖИМ ТРЕВОГИ' : slot>=13 ? 'СИГНАЛ УДАЛЯЕТСЯ · НАБЛЮДЕНИЕ' : 'ФОНОВАЯ ОБСТАНОВКА · НАБЛЮДЕНИЕ';
|
|
|
+ function evaluateSecond(t){
|
|
|
+ if(t<0||t>=scenarioDuration)return;
|
|
|
+ const manual=!!manualToggle.checked,truth=truthAt(t),auto=autoAt(t);
|
|
|
+ demoScoring[t]={manual,truth,auto};updateScoreboard();
|
|
|
}
|
|
|
- function demoFrame(){
|
|
|
- if(!demoVideo || !demoRunning)return;
|
|
|
- const t=Math.min(17.99,demoVideo.currentTime||0);
|
|
|
- $('demoClock').textContent=`00:${String(Math.floor(t)).padStart(2,'0')}`;
|
|
|
- applyDemoSlot(demoSlot(t));
|
|
|
- if(t>=17.95){stopDemo();demoVideo.pause();demoVideo.currentTime=0;demoLastSlot=-1;applyDemoSlot(0);$('demoClock').textContent='00:00';}
|
|
|
+ function updateDemo(t){
|
|
|
+ const sec=Math.floor(t); if(sec===demoSecond)return;demoSecond=sec;
|
|
|
+ const audible=truthAt(t),auto=autoAt(t),p=autoConfidence(t);
|
|
|
+ drawRollingSpec(t);$('specSource').textContent=`СЦЕНАРИЙ · ${sec+1}/40`;
|
|
|
+ $('demoClock').textContent=`00:${String(sec).padStart(2,'0')}`;
|
|
|
+ $('demoCaption').textContent= t<14?'ФОНОВАЯ ОБСТАНОВКА · ВЕТЕР И ЛЁД':t<18?'СЛАБЫЙ АКУСТИЧЕСКИЙ СИГНАЛ · ОБЪЕКТ НЕ ВИДЕН':t<24?'СИГНАЛ ВИНТОВ · ОЖИДАНИЕ ВИЗУАЛЬНОГО ПОДТВЕРЖДЕНИЯ':t<30?'БПЛА В СЕКТОРЕ · СИГНАЛ ОТЧЁТЛИВ':t<34?'БПЛА УДАЛЯЕТСЯ · СИГНАЛ ЗАТУХАЕТ':'ФОН · СИГНАЛ ИСЧЕЗ';
|
|
|
+ // Reveal the aircraft silhouette gradually after the alarm window begins.
|
|
|
+ const vis=sec<24?0:sec<26?(sec-24)/2:sec<30?1:sec<32?(32-sec)/2:0;
|
|
|
+ drone.style.opacity=Math.max(0,vis);drone.style.transform=`translate(${Math.max(0,sec-24)*4}px,${Math.max(0,sec-24)*1.8}px) scale(${.75+vis*.25})`;
|
|
|
+ snow.style.opacity=(sec<14||sec>=34)?1:sec<18?.75:.35;
|
|
|
+ const alarm=manualToggle.checked;
|
|
|
+ demoAlert.classList.toggle('detected',alarm);$('demoAlertText').textContent=alarm?'РУЧНАЯ ТРЕВОГА':'НАБЛЮДЕНИЕ';
|
|
|
+ $('demoAlertSub').textContent=alarm?'Оператор включил сигнал тревоги':'Фоновый шум / акустический контроль';
|
|
|
+ $('manualState').textContent=alarm?'ТРЕВОГА ВКЛЮЧЕНА':'ТРЕВОГА ОТКЛЮЧЕНА';
|
|
|
+ $('analysisStatus').textContent=auto?'АВТОМАТ: ОБНАРУЖЕНИЕ':'АВТОМАТ: ФОН';$('analysisStatus').className='status-pill '+(auto?'busy':'ready');
|
|
|
+ $('scenarioStatus').textContent=`${sec.toString().padStart(2,'0')} / 40 С · ${audible?'ЗВУК БПЛА ПРИСУТСТВУЕТ':'ФОНОВАЯ ОБСТАНОВКА'} · АВТО ${Math.round(p*100)}%`;
|
|
|
+ $('scenarioStatus').classList.toggle('scenario-alert',auto);
|
|
|
+ // For scenario only, keep a clear and honest rule-based simulated automatic indicator, not an ML inference.
|
|
|
+ $('decisionLabel').textContent=auto?'БПЛА / СИГНАЛ':'ФОН';$('decisionLabel').className='decision-label '+(auto?'drone':'');
|
|
|
+ $('probText').textContent=`${Math.round(p*100)}%`;$('bgText').textContent=`${Math.round((1-p)*100)}%`;$('probBar').style.width=(p*100)+'%';$('bgBar').style.width=((1-p)*100)+'%';
|
|
|
+ $('featuresSource').textContent='ВСТРОЕННЫЙ СЦЕНАРИЙ';$('specSource').textContent=`СЦЕНАРИЙ · ${sec+1}/40`;
|
|
|
+ $('decisionExplanation').textContent='Автоматическая отметка в сценарии заранее размечена для учебного подсчёта; она не является выходом обученной ML-модели.';
|
|
|
+ evaluateSecond(sec);
|
|
|
}
|
|
|
- function stopDemo(){demoRunning=false;clearInterval(demoTick);demoTick=null;demoStart.textContent='▶ ЗАПУСТИТЬ СЦЕНАРИЙ';}
|
|
|
+ function stopDemo(){demoRunning=false;clearInterval(demoTimer);demoTimer=null;demoStart.textContent='▶ ЗАПУСК';demoAudio.pause();}
|
|
|
+ function resetDemo(){stopDemo();demoAudio.currentTime=0;manualToggle.checked=false;demoScoring=[];demoSecond=-1;drone.style.opacity=0;updateScoreboard();drawRollingSpec(0);updateDemo(0);$('demoClock').textContent='00:00';$('scenarioStatus').textContent='СЦЕНАРИЙ ГОТОВ · ОЖИДАНИЕ';}
|
|
|
demoStart?.addEventListener('click',async()=>{
|
|
|
- if(demoRunning){stopDemo();demoVideo.pause();return;}
|
|
|
- // stop the regular uploaded-file session to avoid confusing display state
|
|
|
- demoRunning=true;demoStart.textContent='Ⅱ ПАУЗА';demoVideo.currentTime=0;demoLastSlot=-1;
|
|
|
- try{await demoVideo.play();}catch(e){stopDemo();$('demoCaption').textContent='Не удалось запустить встроенный видеоряд';return;}
|
|
|
- demoTick=setInterval(demoFrame,250);demoFrame();
|
|
|
+ if(demoRunning){stopDemo();$('scenarioStatus').textContent='СЦЕНАРИЙ ПРИОСТАНОВЛЕН';return;}
|
|
|
+ demoRunning=true;demoStart.textContent='Ⅱ ПАУЗА';demoSecond=-1;demoScoring=[];manualToggle.checked=false;demoAudio.currentTime=0;
|
|
|
+ updateScoreboard();
|
|
|
+ try{await demoAudio.play();}catch(e){stopDemo();$('scenarioStatus').textContent='Не удалось воспроизвести звук';return;}
|
|
|
+ updateDemo(0);demoTimer=setInterval(()=>{const t=demoAudio.currentTime;updateDemo(t);if(t>=39.95){stopDemo();$('scenarioStatus').textContent='ИСПЫТАНИЕ ЗАВЕРШЕНО · СБРОС ДЛЯ ПОВТОРА';}},250);
|
|
|
});
|
|
|
- demoReset?.addEventListener('click',()=>{stopDemo();demoVideo.pause();demoVideo.currentTime=0;demoLastSlot=-1;applyDemoSlot(0);$('demoClock').textContent='00:00';});
|
|
|
- demoVideo?.addEventListener('ended',()=>{stopDemo();demoLastSlot=-1;applyDemoSlot(0);});
|
|
|
- applyDemoSlot(0);
|
|
|
+ demoReset?.addEventListener('click',resetDemo);
|
|
|
+ manualToggle?.addEventListener('change',()=>{if(demoRunning){evaluateSecond(Math.floor(demoAudio.currentTime));updateDemo(demoAudio.currentTime);}});
|
|
|
+ demoAudio?.addEventListener('ended',()=>{stopDemo();$('scenarioStatus').textContent='ИСПЫТАНИЕ ЗАВЕРШЕНО · СБРОС ДЛЯ ПОВТОРА';});
|
|
|
+ resetDemo();
|
|
|
|
|
|
})();
|
|
|
|