mirror of
https://github.com/pyMC-dev/pyMC_Repeater.git
synced 2026-07-07 02:11:29 +02:00
1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
import{r as e}from"./chunk-DECur_0Z.js";import{E as t,H as n,T as r,f as i,g as a,gt as o,ht as ee,l as s,m as c,o as l,p as u,r as d,s as f,u as p,w as te}from"./runtime-core.esm-bundler-BiwffnQU.js";import{l as ne,t as m}from"./api-DRn_D8oU.js";import{t as re}from"./system-DN2LtoaR.js";import{t as h}from"./_plugin-vue_export-helper-TcpyXLsZ.js";import{t as g}from"./plotly.min-B1MU54E1.js";import{t as ie}from"./RestartModal-haLtPnBZ.js";var _=e(g(),1),ae={class:`p-6 space-y-6`},v={class:`glass-card rounded-[15px] p-6`},y={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=h(a({name:`CADCalibrationView`,__name:`CADCalibration`,setup(e){let a=re(),h=l(()=>document.documentElement.classList.contains(`dark`)),g=()=>{let e=h.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=n(!1),M=n(null),N=n(null),P=n({}),F=n(null),I=n([]),L=n({}),R=n(`Ready to start calibration`),z=n(0),B=n(0),V=n(0),H=n(0),U=n(0),W=n(0),G=n(null),K=n(!1),q=n(!1),J=n(!1),Y=n(!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=g(),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};_.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>`};_.default.restyle(`plotly-chart`,i,[0])}async function Z(){try{let e=await m.post(`/cad-calibration-start`,{samples:10,delay_ms:50});if(e.success)j.value=!0,M.value=Date.now(),a.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 m.post(`/cad-calibration-stop`)).success&&(j.value=!1,a.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=ne(),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`,a.setCadCalibrationRunning(!1),Ce(),N.value&&=(N.value.close(),null),X&&=(clearInterval(X),null);break;case`error`:R.value=`Error: ${e.message}`,a.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 $=n(!1);async function we(){if(!F.value){R.value=`Error: No calibration results to save`;return}try{let e=await m.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 te(()=>{ve()}),r(()=>{N.value&&N.value.close(),X&&clearInterval(X),a.setCadCalibrationRunning(!1),document.getElementById(`plotly-chart`)&&_.default.purge(`plotly-chart`)}),(e,n)=>(t(),p(d,null,[f(`div`,ae,[n[13]||=f(`div`,null,[f(`h1`,{class:`text-2xl font-bold text-content-primary dark:text-content-primary`},` CAD Calibration Tool `),f(`p`,{class:`text-content-secondary dark:text-content-muted mt-2`},` Channel Activity Detection calibration `)],-1),f(`div`,v,[f(`div`,y,[f(`div`,oe,[f(`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`},[...n[1]||=[i(`<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" data-v-188efae5><polygon points="5 3 19 12 5 21 5 3" data-v-188efae5></polygon></svg><div class="text-left" data-v-188efae5><div class="font-medium" data-v-188efae5>Start Calibration</div><div class="text-xs opacity-80" data-v-188efae5>Begin testing</div></div>`,2)]],8,se),f(`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`},[...n[2]||=[i(`<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" data-v-188efae5><rect x="6" y="6" width="12" height="12" data-v-188efae5></rect></svg><div class="text-left" data-v-188efae5><div class="font-medium" data-v-188efae5>Stop</div><div class="text-xs opacity-80" data-v-188efae5>Halt calibration</div></div>`,2)]],8,ce)])])]),f(`div`,le,[f(`div`,ue,o(R.value),1),f(`div`,de,[!q.value&&K.value&&G.value?(t(),p(`div`,fe,[n[3]||=f(`strong`,null,`Configuration:`,-1),u(` SF`+o(G.value.spreading_factor)+` | Peak: `+o(G.value.peak_min)+`–`+o(G.value.peak_max)+` | Min: `+o(G.value.min_min)+`–`+o(G.value.min_max)+` | `+o((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?(t(),p(`div`,me,[n[4]||=f(`span`,{class:`text-accent-green font-medium`},`Optimal settings found — `,-1),n[5]||=u(` Peak: `,-1),f(`strong`,null,o(F.value.det_peak),1),n[6]||=u(`, Min: `,-1),f(`strong`,null,o(F.value.det_min),1),n[7]||=u(`, Rate: `,-1),f(`strong`,null,o(F.value.detection_rate.toFixed(1))+`%`,1)])):Y.value?(t(),p(`div`,he,` No optimal settings found. Consider running calibration again. `)):s(``,!0):(t(),p(`div`,pe,` Awaiting calibration… `)),J.value&&F.value?(t(),p(`button`,{key:4,onClick:we,class:`flex-shrink-0 flex items-center gap-2 px-4 py-2 bg-primary/20 hover:bg-primary/30 text-primary rounded-lg border border-primary/50 transition-colors text-sm font-medium`},[...n[8]||=[f(`svg`,{class:`w-4 h-4`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`},[f(`path`,{d:`M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`})],-1),u(` Save Settings `,-1)]])):s(``,!0)]),f(`div`,ge,[f(`div`,b,[f(`div`,{class:`bg-gradient-to-r from-primary to-accent-green h-2 rounded-full transition-all duration-300`,style:ee({width:B.value>0?`${z.value/B.value*100}%`:`0%`})},null,4)]),f(`div`,x,o(z.value)+` / `+o(B.value)+` tests completed `,1)])]),f(`div`,S,[f(`div`,C,[f(`div`,w,o(V.value),1),n[9]||=f(`div`,{class:`text-content-secondary dark:text-content-muted text-sm`},`Tests Completed`,-1)]),f(`div`,T,[f(`div`,E,o(H.value.toFixed(1))+`%`,1),n[10]||=f(`div`,{class:`text-content-secondary dark:text-content-muted text-sm`},` Best Detection Rate `,-1)]),f(`div`,D,[f(`div`,O,o(U.value.toFixed(1))+`%`,1),n[11]||=f(`div`,{class:`text-content-secondary dark:text-content-muted text-sm`},`Average Rate`,-1)]),f(`div`,k,[f(`div`,A,o(W.value)+`s`,1),n[12]||=f(`div`,{class:`text-content-secondary dark:text-content-muted text-sm`},`Elapsed Time`,-1)])]),n[14]||=f(`div`,{class:`glass-card rounded-[15px] p-6`},[f(`div`,{id:`plotly-chart`,class:`w-full h-96`})],-1)]),c(ie,{modelValue:$.value,"onUpdate:modelValue":n[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-188efae5`]]);export{j as default}; |