import{u as l,v as w,H as P,I as S,A as k,E as m,G as E}from"./index-Bm2SqMk3.js";async function G(t,a){const{rpcManager:e}=l.getSession(t),n=w.getConf(t,"numStdDev")||3,{adapterConfig:g,autoscaleType:s}=t,r=P.getRpcSessionId(t),{currStatsBpPerPx:c}=a,p={sessionId:r,adapterConfig:g,statusCallback:o=>{S(t)&&t.setMessage(o)},...a};if(s==="global"||s==="globalsd"){const o=await e.call(r,"WiggleGetGlobalQuantitativeStats",p),{scoreMin:d,scoreMean:i,scoreStdDev:u}=o;return s==="globalsd"?{...o,scoreMin:d>=0?0:i-n*u,scoreMax:i+n*u,currStatsBpPerPx:c}:{...o,currStatsBpPerPx:c}}if(s==="local"||s==="localsd"){const{dynamicBlocks:o,bpPerPx:d}=l.getContainingView(t),i=await e.call(r,"WiggleGetMultiRegionQuantitativeStats",{...p,regions:o.contentBlocks.map(x=>{const{start:y,end:b}=x;return{...JSON.parse(JSON.stringify(x)),start:Math.floor(y),end:Math.ceil(b)}}),bpPerPx:d}),{scoreMin:u,scoreMean:v,scoreStdDev:M}=i;return s==="localsd"?{...i,scoreMin:u>=0?0:v-n*M,scoreMax:v+n*M,currStatsBpPerPx:c}:{...i,currStatsBpPerPx:c}}if(s==="zscale")return e.call(r,"WiggleGetGlobalQuantitativeStats",p);throw new Error(`invalid autoscaleType '${s}'`)}function B(t){k(t,m(async()=>{try{if(t.quantitativeStatsReady){const a=l.getContainingView(t),e=E.createStopToken();t.setStatsLoading(e);const n=JSON.stringify(a.dynamicBlocks),g=await G(t,{stopToken:e,filters:[],currStatsBpPerPx:a.bpPerPx,...t.adapterProps()});S(t)&&t.updateQuantitativeStats(g,n)}}catch(a){S(t)&&!l.isAbortException(a)&&(console.error(a),t.setError(a))}},{delay:1e3}))}export{B as getQuantitativeStatsAutorun};
