Files
pyMC_Repeater/repeater/web/html/assets/CADCalibration-BfevMbv2.js
T

1 line
11 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{r as e}from"./chunk-DECur_0Z.js";import{C as t,T as n,U as r,_t as i,f as a,gt as o,h as s,l as c,m as l,o as u,p as d,r as f,s as p,u as m,w as ee}from"./runtime-core.esm-bundler-CINEgm0a.js";import{l as te,t as h}from"./api-BKl2GiAy.js";import{t as ne}from"./system-SIN02-p2.js";import{f as g,r as re}from"./index-BJuW9-S6.js";import{t as _}from"./plotly.min-BmxIBpZZ.js";var v=e(_(),1),ie={class:`p-6 space-y-6`},y={class:`glass-card rounded-[15px] p-6`},ae={class:`flex justify-center`},oe={class:`flex gap-4`},se=[`disabled`],ce=[`disabled`],le={class:`glass-card rounded-[15px] p-6 space-y-4`},ue={class:`text-content-primary dark:text-content-primary`},de={class:`flex items-center justify-between gap-4 px-4 bg-primary/10 border border-primary/30 rounded-lg h-[52px] overflow-hidden`},fe={key:0,class:`text-content-primary dark:text-primary text-sm`},pe={key:1,class:`text-content-muted dark:text-content-muted text-sm italic`},me={key:2,class:`text-content-primary dark:text-content-primary text-sm`},he={key:3,class:`text-content-secondary dark:text-content-muted text-sm`},ge={class:`space-y-2`},b={class:`w-full bg-white/10 rounded-full h-2`},x={class:`text-content-secondary dark:text-content-muted text-sm`},S={class:`grid grid-cols-2 md:grid-cols-4 gap-4`},C={class:`glass-card rounded-[15px] p-4 text-center`},w={class:`text-2xl font-bold text-primary`},T={class:`glass-card rounded-[15px] p-4 text-center`},E={class:`text-2xl font-bold text-primary`},D={class:`glass-card rounded-[15px] p-4 text-center`},O={class:`text-2xl font-bold text-primary`},k={class:`glass-card rounded-[15px] p-4 text-center`},A={class:`text-2xl font-bold text-primary`},j=g(s({name:`CADCalibrationView`,__name:`CADCalibration`,setup(e){let s=ne(),g=u(()=>document.documentElement.classList.contains(`dark`)),_=()=>{let e=g.value;return{title:e?`#F9FAFB`:`#111827`,subtitle:e?`#9CA3AF`:`#6B7280`,axis:e?`#D1D5DB`:`#374151`,tick:e?`#9CA3AF`:`#6B7280`,grid:e?`rgba(148, 163, 184, 0.1)`:`rgba(107, 114, 128, 0.15)`,zeroline:e?`rgba(148, 163, 184, 0.2)`:`rgba(107, 114, 128, 0.25)`,line:e?`rgba(148, 163, 184, 0.3)`:`rgba(107, 114, 128, 0.35)`,colorbarBorder:e?`rgba(255,255,255,0.2)`:`rgba(0,0,0,0.15)`,markerLine:e?`rgba(255,255,255,0.2)`:`rgba(0,0,0,0.15)`}},j=r(!1),M=r(null),N=r(null),P=r({}),F=r(null),I=r([]),L=r({}),R=r(`Ready to start calibration`),z=r(0),B=r(0),V=r(0),H=r(0),U=r(0),W=r(0),G=r(null),K=r(!1),q=r(!1),J=r(!1),Y=r(!1),X=null,_e={responsive:!0,displayModeBar:!0,modeBarButtonsToRemove:[`pan2d`,`select2d`,`lasso2d`,`autoScale2d`],displaylogo:!1,toImageButtonOptions:{format:`png`,filename:`cad-calibration-heatmap`,height:600,width:800,scale:2}};function ve(){let e=_(),t=[{x:[],y:[],z:[],mode:`markers`,type:`scatter`,marker:{size:12,color:[],colorscale:[[0,`rgba(75, 85, 99, 0.4)`],[.1,`rgba(6, 182, 212, 0.3)`],[.5,`rgba(6, 182, 212, 0.6)`],[1,`rgba(16, 185, 129, 0.9)`]],showscale:!0,colorbar:{title:{text:`Detection Rate (%)`,font:{color:e.axis,size:14}},tickfont:{color:e.tick},bgcolor:`rgba(0,0,0,0)`,bordercolor:e.colorbarBorder,borderwidth:1,thickness:15},line:{color:e.markerLine,width:1}},hovertemplate:`<b>Peak:</b> %{x}<br><b>Min:</b> %{y}<br><b>Detection Rate:</b> %{marker.color:.1f}%<br><extra></extra>`,name:`Test Results`}],n={title:{text:`CAD Detection Rate<br><sub style="color: ${e.subtitle};">Channel Activity Detection Calibration</sub>`,font:{color:e.title,size:18},x:.5},xaxis:{title:{text:`CAD Peak Threshold`,font:{color:e.axis,size:14}},tickfont:{color:e.tick},gridcolor:e.grid,zerolinecolor:e.zeroline,linecolor:e.line},yaxis:{title:{text:`CAD Min Threshold`,font:{color:e.axis,size:14}},tickfont:{color:e.tick},gridcolor:e.grid,zerolinecolor:e.zeroline,linecolor:e.line},plot_bgcolor:`rgba(0, 0, 0, 0)`,paper_bgcolor:`rgba(0, 0, 0, 0)`,font:{color:e.title,family:`Inter, system-ui, sans-serif`},margin:{l:80,r:80,t:100,b:80},showlegend:!1};v.default.newPlot(`plotly-chart`,t,n,_e)}function ye(){if(Object.keys(P.value).length===0)return;let e=Object.values(P.value),t=[],n=[],r=[];for(let i of e)t.push(i.det_peak),n.push(i.det_min),r.push(i.detection_rate);let i={x:[t],y:[n],"marker.color":[r],hovertemplate:`<b>Peak:</b> %{x}<br><b>Min:</b> %{y}<br><b>Detection Rate:</b> %{marker.color:.1f}%<br><b>Status:</b> Tested<br><extra></extra>`};v.default.restyle(`plotly-chart`,i,[0])}async function Z(){try{let e=await h.post(`/cad-calibration-start`,{samples:10,delay_ms:50});if(e.success)j.value=!0,M.value=Date.now(),s.setCadCalibrationRunning(!0),P.value={},I.value=[],L.value={},F.value=null,K.value=!1,q.value=!1,J.value=!1,Y.value=!1,V.value=0,H.value=0,U.value=0,W.value=0,z.value=0,B.value=0,X=setInterval(()=>{M.value&&(W.value=Math.floor((Date.now()-M.value)/1e3))},1e3),be();else throw Error(e.error||`Failed to start calibration`)}catch(e){R.value=`Error: ${e instanceof Error?e.message:`Unknown error`}`}}async function Q(){try{(await h.post(`/cad-calibration-stop`)).success&&(j.value=!1,s.setCadCalibrationRunning(!1),N.value&&=(N.value.close(),null),X&&=(clearInterval(X),null))}catch(e){console.error(`Failed to stop calibration:`,e)}}function be(){N.value&&N.value.close();let e=te(),t=e?`?token=${encodeURIComponent(e)}`:``;N.value=new EventSource(`/api/cad-calibration-stream${t}`),N.value.onmessage=function(e){try{xe(JSON.parse(e.data))}catch(e){console.error(`Failed to parse SSE data:`,e)}},N.value.onerror=function(e){console.error(`SSE connection error:`,e),j.value||(N.value&&=(N.value.close(),null))}}function xe(e){switch(e.type){case`status`:R.value=e.message||`Status update`,e.test_ranges&&(G.value=e.test_ranges,K.value=!0);break;case`progress`:z.value=e.current||0,B.value=e.total||0,V.value=e.current||0;break;case`result`:if(e.det_peak!==void 0&&e.det_min!==void 0&&e.detection_rate!==void 0&&e.detections!==void 0&&e.samples!==void 0){let t=`${e.det_peak}_${e.det_min}`;P.value[t]={det_peak:e.det_peak,det_min:e.det_min,detection_rate:e.detection_rate,detections:e.detections,samples:e.samples},ye(),Se()}break;case`complete`:case`completed`:j.value=!1,R.value=e.message||`Calibration completed`,s.setCadCalibrationRunning(!1),Ce(),N.value&&=(N.value.close(),null),X&&=(clearInterval(X),null);break;case`error`:R.value=`Error: ${e.message}`,s.setCadCalibrationRunning(!1),Q();break}}function Se(){let e=Object.values(P.value).map(e=>e.detection_rate);e.length!==0&&(H.value=Math.max(...e),U.value=e.reduce((e,t)=>e+t,0)/e.length)}function Ce(){q.value=!0;let e=null,t=0;for(let n of Object.values(P.value))n.detection_rate>t&&(t=n.detection_rate,e=n);F.value=e,e&&t>0?(J.value=!0,Y.value=!1):(J.value=!1,Y.value=!0)}let $=r(!1);async function we(){if(!F.value){R.value=`Error: No calibration results to save`;return}try{let e=await h.post(`/save_cad_settings`,{peak:F.value.det_peak,min_val:F.value.det_min,detection_rate:F.value.detection_rate});if(e.success)$.value=!0;else throw Error(e.error||`Failed to save settings`)}catch(e){R.value=`Error: Failed to save settings: ${e instanceof Error?e.message:`Unknown error`}`}}return t(()=>{ve()}),ee(()=>{N.value&&N.value.close(),X&&clearInterval(X),s.setCadCalibrationRunning(!1),document.getElementById(`plotly-chart`)&&v.default.purge(`plotly-chart`)}),(e,t)=>(n(),m(f,null,[p(`div`,ie,[t[13]||=p(`div`,null,[p(`h1`,{class:`text-2xl font-bold text-content-primary dark:text-content-primary`},` CAD Calibration Tool `),p(`p`,{class:`text-content-secondary dark:text-content-muted mt-2`},` Channel Activity Detection calibration `)],-1),p(`div`,y,[p(`div`,ae,[p(`div`,oe,[p(`button`,{onClick:Z,disabled:j.value,class:`flex items-center gap-3 px-6 py-3 bg-accent-green/10 hover:bg-accent-green/20 disabled:bg-gray-500/10 text-accent-green disabled:text-gray-400 rounded-lg border border-accent-green/30 disabled:border-gray-500/20 transition-colors disabled:cursor-not-allowed`},[...t[1]||=[a(`<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" data-v-950ea1f9><polygon points="5 3 19 12 5 21 5 3" data-v-950ea1f9></polygon></svg><div class="text-left" data-v-950ea1f9><div class="font-medium" data-v-950ea1f9>Start Calibration</div><div class="text-xs opacity-80" data-v-950ea1f9>Begin testing</div></div>`,2)]],8,se),p(`button`,{onClick:Q,disabled:!j.value,class:`flex items-center gap-3 px-6 py-3 bg-accent-red/10 hover:bg-accent-red/20 disabled:bg-gray-500/10 text-accent-red disabled:text-gray-400 rounded-lg border border-accent-red/30 disabled:border-gray-500/20 transition-colors disabled:cursor-not-allowed`},[...t[2]||=[a(`<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" data-v-950ea1f9><rect x="6" y="6" width="12" height="12" data-v-950ea1f9></rect></svg><div class="text-left" data-v-950ea1f9><div class="font-medium" data-v-950ea1f9>Stop</div><div class="text-xs opacity-80" data-v-950ea1f9>Halt calibration</div></div>`,2)]],8,ce)])])]),p(`div`,le,[p(`div`,ue,i(R.value),1),p(`div`,de,[!q.value&&K.value&&G.value?(n(),m(`div`,fe,[t[3]||=p(`strong`,null,`Configuration:`,-1),d(` SF`+i(G.value.spreading_factor)+` | Peak: `+i(G.value.peak_min)+``+i(G.value.peak_max)+` | Min: `+i(G.value.min_min)+``+i(G.value.min_max)+` | `+i((G.value.peak_max-G.value.peak_min+1)*(G.value.min_max-G.value.min_min+1))+` tests `,1)])):q.value?J.value&&F.value?(n(),m(`div`,me,[t[4]||=p(`span`,{class:`text-accent-green font-medium`},`Optimal settings found — `,-1),t[5]||=d(` Peak: `,-1),p(`strong`,null,i(F.value.det_peak),1),t[6]||=d(`, Min: `,-1),p(`strong`,null,i(F.value.det_min),1),t[7]||=d(`, Rate: `,-1),p(`strong`,null,i(F.value.detection_rate.toFixed(1))+`%`,1)])):Y.value?(n(),m(`div`,he,` No optimal settings found. Consider running calibration again. `)):c(``,!0):(n(),m(`div`,pe,` Awaiting calibration… `)),J.value&&F.value?(n(),m(`button`,{key:4,onClick:we,class:`btn-primary flex-shrink-0 flex items-center gap-2`},[...t[8]||=[p(`svg`,{class:`w-4 h-4`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[p(`path`,{d:`M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`})],-1),d(` Save Settings `,-1)]])):c(``,!0)]),p(`div`,ge,[p(`div`,b,[p(`div`,{class:`bg-gradient-to-r from-primary to-accent-green h-2 rounded-full transition-all duration-300`,style:o({width:B.value>0?`${z.value/B.value*100}%`:`0%`})},null,4)]),p(`div`,x,i(z.value)+` / `+i(B.value)+` tests completed `,1)])]),p(`div`,S,[p(`div`,C,[p(`div`,w,i(V.value),1),t[9]||=p(`div`,{class:`text-content-secondary dark:text-content-muted text-sm`},`Tests Completed`,-1)]),p(`div`,T,[p(`div`,E,i(H.value.toFixed(1))+`%`,1),t[10]||=p(`div`,{class:`text-content-secondary dark:text-content-muted text-sm`},` Best Detection Rate `,-1)]),p(`div`,D,[p(`div`,O,i(U.value.toFixed(1))+`%`,1),t[11]||=p(`div`,{class:`text-content-secondary dark:text-content-muted text-sm`},`Average Rate`,-1)]),p(`div`,k,[p(`div`,A,i(W.value)+`s`,1),t[12]||=p(`div`,{class:`text-content-secondary dark:text-content-muted text-sm`},`Elapsed Time`,-1)])]),t[14]||=p(`div`,{class:`glass-card rounded-[15px] p-6`},[p(`div`,{id:`plotly-chart`,class:`w-full h-96`})],-1)]),l(re,{modelValue:$.value,"onUpdate:modelValue":t[0]||=e=>$.value=e,title:`CAD Calibration Saved: Restart Required`,message:`In order for the CAD Calibration settings to take effect and the noise floor to return to normal, the service needs to be restarted.`},null,8,[`modelValue`])],64))}}),[[`__scopeId`,`data-v-950ea1f9`]]);export{j as default};