(function(){"use strict";function k(f,g,o,L,i,B,N,z,E,U,m,s){const d=m*60/s,J=Math.floor(Date.now()/1e3),x=Math.floor(J/d)*d,_=x-m*60,p=new Array(s),w=new Array(s),A=new Array(s),u=new Array(s),I=new Array(s),W=new Float64Array(s),q=new Float64Array(s),R=new Uint32Array(s),D=new Array(s),F=new Array(s),G=new Array(s),M=new Array(s),O={},h={},v={};let X=0,b=0,S=0;for(let e=0;e<s;e++){const r=_+e*d,t=r+d,a={bucket:e,start:r,end:t,count:0,airtime_ms:0,avg_snr:0,avg_rssi:0};p[e]={...a},w[e]={...a},A[e]={...a},u[e]={...a},I[e]={...a},D[e]=new Set,F[e]={start:r,end:t,bytesByType:{},totalBytes:0},G[e]={start:r,end:t,bytesByType:{},totalBytes:0},M[e]={start:r,end:t,bytesByType:{},totalBytes:0}}const K=f.length;for(let e=0;e<K;e++){const r=f[e];if(r<_||r>x)continue;const t=Math.floor((r-_)/d);if(t<0||t>=s)continue;const a=g[e],T=i[e],V=B[e],j=N[e],n=L[e],y=o[e];if(T===1?(A[t].count++,A[t].airtime_ms+=a):T===2||V&&T!==1?(u[t].count++,u[t].airtime_ms+=a):j&&(I[t].count++,I[t].airtime_ms+=a),T!==1){p[t].count++,p[t].airtime_ms+=a,W[t]+=z[e],q[t]+=E[e],R[t]++;const c=U[e];D[t].has(c)||(D[t].add(c),w[t].count++,w[t].airtime_ms+=a);const P=F[t];P.bytesByType[n]=(P.bytesByType[n]??0)+y,P.totalBytes+=y,O[n]=(O[n]??0)+y,S+=y}if(T===2||V&&T!==1){const c=G[t];c.bytesByType[n]=(c.bytesByType[n]??0)+y,c.totalBytes+=y,h[n]=(h[n]??0)+y,X++}if(j){const c=M[t];c.bytesByType[n]=(c.bytesByType[n]??0)+y,c.totalBytes+=y,v[n]=(v[n]??0)+y,b++}}for(let e=0;e<s;e++)R[e]>0&&(p[e].avg_snr=W[e]/R[e],p[e].avg_rssi=q[e]/R[e]);const H=e=>Object.keys(e).map(r=>parseInt(r,10)).filter(r=>e[r]>0).sort((r,t)=>e[t]-e[r]),l=m/60;return{time_range_minutes:m,bucket_count:s,bucket_duration_seconds:d,start_time:_,end_time:x,received:p,unique_received:w,transmitted:A,forwarded:u,dropped:I,receivedBytesBuckets:F,receivedActiveTypes:H(O),receivedTotalByType:O,forwardedBytesBuckets:G,forwardedActiveTypes:H(h),forwardedTotalByType:h,forwardedRatePerHour:l>0?Math.round(X/l):0,totalForwardedCount:X,droppedBytesBuckets:M,droppedActiveTypes:H(v),droppedTotalByType:v,droppedRatePerHour:l>0?Math.round(b/l):0,totalDroppedCount:b,totalReceivedBytes:S,kbPerHour:l>0?Math.round(S/1024/l):0}}self.onmessage=f=>{const{type:g,payload:o}=f.data;if(g!=="compute")return;const L=performance.now();try{const i=k(o.timestamps,o.airtimeMs,o.byteSizes,o.payloadTypes,o.origins,o.transmitted,o.dropped,o.snrValues,o.rssiValues,o.hashIndices,o.rangeMinutes,o.bucketCount),B=performance.now()-L,N={type:"result",payload:i,computeTimeMs:B};self.postMessage(N)}catch(i){const B={type:"error",error:i instanceof Error?i.message:String(i)};self.postMessage(B)}}})();
