@uwrl/qc-utils 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +627 -565
- package/dist/index.umd.cjs +13 -13
- package/dist/types/index.d.ts +95 -37
- package/dist/utils/plotting/script.d.ts +8 -7
- package/package.json +1 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
(function(b,I){typeof exports=="object"&&typeof module<"u"?I(exports):typeof define=="function"&&define.amd?define(["exports"],I):(b=typeof globalThis<"u"?globalThis:b||self,I(b["@uwrl/qc-utils"]={}))})(this,(function(b){"use strict";var I=(r=>(r.SECOND="s",r.MINUTE="m",r.HOUR="h",r.DAY="D",r.WEEK="W",r.MONTH="M",r.YEAR="Y",r))(I||{}),v=(r=>(r.ADD_POINTS="ADD_POINTS",r.CHANGE_VALUES="CHANGE_VALUES",r.ASSIGN_VALUES_BULK="ASSIGN_VALUES_BULK",r.DELETE_POINTS="DELETE_POINTS",r.DRIFT_CORRECTION="DRIFT_CORRECTION",r.INTERPOLATE="INTERPOLATE",r.SHIFT_DATETIMES="SHIFT_DATETIMES",r.ASSIGN_DATETIMES_BULK="ASSIGN_DATETIMES_BULK",r.FILL_GAPS="FILL_GAPS",r))(v||{}),
|
|
1
|
+
(function(b,I){typeof exports=="object"&&typeof module<"u"?I(exports):typeof define=="function"&&define.amd?define(["exports"],I):(b=typeof globalThis<"u"?globalThis:b||self,I(b["@uwrl/qc-utils"]={}))})(this,(function(b){"use strict";var I=(r=>(r.SECOND="s",r.MINUTE="m",r.HOUR="h",r.DAY="D",r.WEEK="W",r.MONTH="M",r.YEAR="Y",r))(I||{}),v=(r=>(r.ADD_POINTS="ADD_POINTS",r.CHANGE_VALUES="CHANGE_VALUES",r.ASSIGN_VALUES_BULK="ASSIGN_VALUES_BULK",r.DELETE_POINTS="DELETE_POINTS",r.DRIFT_CORRECTION="DRIFT_CORRECTION",r.INTERPOLATE="INTERPOLATE",r.SHIFT_DATETIMES="SHIFT_DATETIMES",r.ASSIGN_DATETIMES_BULK="ASSIGN_DATETIMES_BULK",r.FILL_GAPS="FILL_GAPS",r))(v||{}),L=(r=>(r.FIND_GAPS="FIND_GAPS",r.PERSISTENCE="PERSISTENCE",r.CHANGE="CHANGE",r.RATE_OF_CHANGE="RATE_OF_CHANGE",r.VALUE_THRESHOLD="VALUE_THRESHOLD",r.DATETIME_RANGE="DATETIME_RANGE",r.SELECTION="SELECTION",r))(L||{}),j=(r=>(r.LT="Less than",r.LTE="Less than or equal to",r.GT="Greater than",r.GTE="Greater than or equal to",r.E="Equal",r))(j||{}),Ae=(r=>(r.ADD="ADD",r.SUB="SUB",r.MULT="MULT",r.DIV="DIV",r.ASSIGN="ASSIGN",r))(Ae||{}),Le=(r=>(r.LT="Less than",r.LTE="Less than or equal to",r.GT="Greater than",r.GTE="Greater than or equal to",r.E="Equal",r))(Le||{});class Te{id;thingId;link;frequency;path;datastreamIds;publicResource;constructor(){this.id="",this.thingId="",this.link="",this.frequency=null,this.path="HydroShare",this.datastreamIds=[],this.publicResource=!1}}class At extends Te{resourceTitle;resourceAbstract;resourceKeywords;constructor(){super(),this.resourceTitle=void 0,this.resourceAbstract=void 0,this.resourceKeywords=void 0}}class _e{latitude;longitude;elevation_m;elevationDatum;state;county;country;constructor(){this.elevationDatum="WGS84",this.state="",this.county="",this.country=""}}class Lt{id;workspaceId;name;location=new _e;tags;hydroShareArchive;siteType;samplingFeatureCode;isPrivate;description;samplingFeatureType;dataDisclaimer;constructor(){this.id="",this.workspaceId="",this.name="",this.tags=[],this.siteType="",this.samplingFeatureCode="",this.isPrivate=!1,this.description="",this.samplingFeatureType="Site",this.dataDisclaimer=""}}class Tt{id;workspaceId;name;description;thingId;observationType;resultType;status;sampledMedium;noDataValue;aggregationStatistic;unitId;observedPropertyId;sensorId;processingLevelId;isPrivate;isVisible;phenomenonBeginTime;phenomenonEndTime;intendedTimeSpacing;intendedTimeSpacingUnit;timeAggregationInterval;timeAggregationIntervalUnit;dataSourceId;valueCount;constructor(e){this.id="",this.workspaceId="",this.name="",this.description="",this.thingId=e||"",this.observationType="OM_Measurement",this.resultType="Time Series Coverage",this.sampledMedium="",this.noDataValue=-9999,this.aggregationStatistic="",this.unitId="",this.observedPropertyId="",this.sensorId="",this.processingLevelId="",this.timeAggregationInterval=null,this.timeAggregationIntervalUnit="seconds",this.isPrivate=!0,this.isVisible=!0,this.valueCount=0}}class _t{id;workspaceId;name;symbol;definition;type;constructor(){this.id="",this.workspaceId="",this.name="",this.symbol="",this.definition="",this.type=""}}class Rt{id;workspaceId;name;description;manufacturer;model;methodType;methodCode;methodLink;encodingType;modelLink;constructor(){this.id="",this.workspaceId="",this.name="",this.description="",this.manufacturer="",this.model="",this.methodType="Instrument Deployment",this.methodCode="",this.methodLink="",this.encodingType="application/json",this.modelLink=""}}class It{id;workspaceId;name;definition;description;type;code;constructor(){this.id="",this.workspaceId="",this.name="",this.definition="",this.description="",this.type="Hydrology",this.code=""}}class Mt{id;workspaceId;code;definition;explanation;constructor(){this.id="",this.workspaceId="",this.code="",this.definition="",this.explanation=""}}class Ot{id;workspaceId;code;description;constructor(){this.id="",this.workspaceId="",this.code="",this.description=""}}class Ut{name;code;type;description;link;constructor(){}}class Ct{id;email;password;firstName;middleName;lastName;phone;address;organization;type;link;accountType;hydroShareConnected;constructor(){this.id="",this.email="",this.password="",this.firstName="",this.middleName="",this.lastName="",this.phone="",this.address="",this.type="",this.link="",this.accountType="standard",this.hydroShareConnected=!1}}class Dt{id;name;iconLink;signupEnabled;connectEnabled;constructor(){this.id="",this.name="",this.iconLink="",this.signupEnabled=!0,this.connectEnabled=!0}}var Re=(r=>(r.Global="*",r.View="view",r.Create="create",r.Edit="edit",r.Delete="delete",r))(Re||{}),Ie=(r=>(r.Global="*",r.Workspace="Workspace",r.Collaborator="Collaborator",r.Thing="Thing",r.Datastream="Datastream",r.Sensor="Sensor",r.Unit="Unit",r.ObservedProperty="ObservedProperty",r.ProcessingLevel="ProcessingLevel",r.Observation="Observation",r))(Ie||{});class Nt{id="";key="";name="";description="";isActive=!0;expiresAt="";createdAt="";lastUsed="";workspaceId="";role=null;constructor(e){Object.assign(this,e)}}class Ft{id;name;isPrivate;owner;collaboratorRole;pendingTransferTo;constructor(){this.id="",this.name="",this.isPrivate=!1,this.owner=null,this.collaboratorRole=null,this.pendingTransferTo=null}}class Pt{user;role;constructor(){this.user={phone:"",address:"",link:"",type:"",name:"",email:"",organizationName:""},this.role={name:"",description:"",id:"",isApikeyRole:!1,isUserRole:!1,workspaceId:"",permissions:[]}}}const Me={HTTP:{type:"HTTP",sourceUri:"",placeholderVariables:[]},local:{type:"local",sourceUri:"",placeholderVariables:[]}},Oe={JSON:{type:"JSON",timestamp:{key:"",format:"ISO8601",timezoneMode:"embeddedOffset"},JMESPath:""},CSV:{type:"CSV",timestamp:{key:"",format:"ISO8601",timezoneMode:"embeddedOffset"},headerRow:1,dataStartRow:2,delimiter:",",identifierType:"name"}},Ue={HydroServer:{type:"HydroServer"}};class Bt{name="";settings={type:"SDL",extractor:JSON.parse(JSON.stringify(Me.local)),transformer:JSON.parse(JSON.stringify(Oe.CSV)),loader:JSON.parse(JSON.stringify(Ue.HydroServer)),payloads:[]};id="";workspaceId="";orchestrationSystem={id:"",name:"",workspaceId:"",type:""};schedule={interval:15,intervalUnits:"minutes"};status={paused:!0};datastreams=[];constructor(e){Object.assign(this,e)}switchExtractor(e){this.settings.extractor=JSON.parse(JSON.stringify(Me[e]))}switchTransformer(e){this.settings.transformer=JSON.parse(JSON.stringify(Oe[e]))}switchLoader(e){this.settings.loader=JSON.parse(JSON.stringify(Ue[e]))}}class jt{name="";mappings=[];extractorVariables={};constructor(e){Object.assign(this,e)}}const Ce=1,H=Ce*60,te=H*60,re=te*24,xt=re*7,Wt=te*30,Yt=re*365,W={[I.SECOND]:Ce,[I.MINUTE]:H,[I.HOUR]:te,[I.DAY]:re,[I.WEEK]:xt,[I.MONTH]:Wt,[I.YEAR]:Yt},Gt=r=>r.toLocaleString(void 0,{year:"numeric",month:"short",day:"2-digit",hour:"2-digit",hour12:!1,minute:"2-digit",second:"2-digit"}),zt=r=>{let e,t;r>=H*1e3?(e=r/(H*1e3),t="m"):r>=1e3?(e=r/1e3,t="s"):(e=r,t="ms");let n;return t==="ms"?n=Math.round(e).toString():n=e.toFixed(2),`${n} ${t}`},X=async(r,e)=>{e&&console.info(e);const t=performance.now(),n=await r(),i=+(performance.now()-t);return{response:n,duration:i}};var ne=function(r,e){return ne=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])},ne(r,e)};function $(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");ne(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}function se(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function oe(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(a){s={error:a}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(s)throw s.error}}return i}function ie(r,e,t){if(t||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return r.concat(i||Array.prototype.slice.call(e))}typeof SuppressedError=="function"&&SuppressedError;function B(r){return typeof r=="function"}function De(r){var e=function(n){Error.call(n),n.stack=new Error().stack},t=r(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var ae=De(function(r){return function(t){r(this),this.message=t?t.length+` errors occurred during unsubscription:
|
|
2
2
|
`+t.map(function(n,o){return o+1+") "+n.toString()}).join(`
|
|
3
|
-
`):"",this.name="UnsubscriptionError",this.errors=t}});function ce(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var V=(function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,n,o,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=se(s),c=a.next();!c.done;c=a.next()){var
|
|
4
|
-
`,$e=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",
|
|
5
|
-
`,qe=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Ve],{type:"text/javascript;charset=utf-8"});function
|
|
6
|
-
`,Je=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Ke],{type:"text/javascript;charset=utf-8"});function
|
|
7
|
-
`,Ze=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Qe],{type:"text/javascript;charset=utf-8"});function
|
|
8
|
-
`,tt=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",et],{type:"text/javascript;charset=utf-8"});function
|
|
9
|
-
`,nt=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",rt],{type:"text/javascript;charset=utf-8"});function
|
|
10
|
-
`,ot=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",st],{type:"text/javascript;charset=utf-8"});function
|
|
11
|
-
`,at=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",it],{type:"text/javascript;charset=utf-8"});function
|
|
12
|
-
`,lt=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",ct],{type:"text/javascript;charset=utf-8"});function
|
|
13
|
-
`,ft=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",ut],{type:"text/javascript;charset=utf-8"});function
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=t}});function ce(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1)}}var V=(function(){function r(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var e,t,n,o,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=se(s),c=a.next();!c.done;c=a.next()){var d=c.value;d.remove(this)}}catch(l){e={error:l}}finally{try{c&&!c.done&&(t=a.return)&&t.call(a)}finally{if(e)throw e.error}}else s.remove(this);var f=this.initialTeardown;if(B(f))try{f()}catch(l){i=l instanceof ae?l.errors:[l]}var w=this._finalizers;if(w){this._finalizers=null;try{for(var m=se(w),p=m.next();!p.done;p=m.next()){var y=p.value;try{Pe(y)}catch(l){i=i??[],l instanceof ae?i=ie(ie([],oe(i)),oe(l.errors)):i.push(l)}}}catch(l){n={error:l}}finally{try{p&&!p.done&&(o=m.return)&&o.call(m)}finally{if(n)throw n.error}}}if(i)throw new ae(i)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)Pe(e);else{if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e)}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&ce(t,e)},r.prototype.remove=function(e){var t=this._finalizers;t&&ce(t,e),e instanceof r&&e._removeParent(this)},r.EMPTY=(function(){var e=new r;return e.closed=!0,e})(),r})(),Ne=V.EMPTY;function Fe(r){return r instanceof V||r&&"closed"in r&&B(r.remove)&&B(r.add)&&B(r.unsubscribe)}function Pe(r){B(r)?r():r.unsubscribe()}var Ht={Promise:void 0},Xt={setTimeout:function(r,e){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];return setTimeout.apply(void 0,ie([r,e],oe(t)))},clearTimeout:function(r){return clearTimeout(r)},delegate:void 0};function $t(r){Xt.setTimeout(function(){throw r})}function Be(){}function q(r){r()}var je=(function(r){$(e,r);function e(t){var n=r.call(this)||this;return n.isStopped=!1,t?(n.destination=t,Fe(t)&&t.add(n)):n.destination=Kt,n}return e.create=function(t,n,o){return new le(t,n,o)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e})(V),Vt=(function(){function r(e){this.partialObserver=e}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(n){K(n)}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(n){K(n)}else K(e)},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(t){K(t)}},r})(),le=(function(r){$(e,r);function e(t,n,o){var i=r.call(this)||this,s;return B(t)||!t?s={next:t??void 0,error:n??void 0,complete:o??void 0}:s=t,i.destination=new Vt(s),i}return e})(je);function K(r){$t(r)}function qt(r){throw r}var Kt={closed:!0,next:Be,error:qt,complete:Be},Jt=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Qt(r){return r}function Zt(r){return r.length===0?Qt:r.length===1?r[0]:function(t){return r.reduce(function(n,o){return o(n)},t)}}var xe=(function(){function r(e){e&&(this._subscribe=e)}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,n){var o=this,i=tr(e)?e:new le(e,t,n);return q(function(){var s=o,a=s.operator,c=s.source;i.add(a?a.call(i,c):c?o._subscribe(i):o._trySubscribe(i))}),i},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},r.prototype.forEach=function(e,t){var n=this;return t=We(t),new t(function(o,i){var s=new le({next:function(a){try{e(a)}catch(c){i(c),s.unsubscribe()}},error:i,complete:o});n.subscribe(s)})},r.prototype._subscribe=function(e){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[Jt]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Zt(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=We(e),new e(function(n,o){var i;t.subscribe(function(s){return i=s},function(s){return o(s)},function(){return n(i)})})},r.create=function(e){return new r(e)},r})();function We(r){var e;return(e=r??Ht.Promise)!==null&&e!==void 0?e:Promise}function er(r){return r&&B(r.next)&&B(r.error)&&B(r.complete)}function tr(r){return r&&r instanceof je||er(r)&&Fe(r)}var rr=De(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),Ye=(function(r){$(e,r);function e(){var t=r.call(this)||this;return t.closed=!1,t.currentObservers=null,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return e.prototype.lift=function(t){var n=new Ge(this,this);return n.operator=t,n},e.prototype._throwIfClosed=function(){if(this.closed)throw new rr},e.prototype.next=function(t){var n=this;q(function(){var o,i;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var s=se(n.currentObservers),a=s.next();!a.done;a=s.next()){var c=a.value;c.next(t)}}catch(d){o={error:d}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(o)throw o.error}}}})},e.prototype.error=function(t){var n=this;q(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=t;for(var o=n.observers;o.length;)o.shift().error(t)}})},e.prototype.complete=function(){var t=this;q(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var n=t.observers;n.length;)n.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return((t=this.observers)===null||t===void 0?void 0:t.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(t){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,t)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var n=this,o=this,i=o.hasError,s=o.isStopped,a=o.observers;return i||s?Ne:(this.currentObservers=null,a.push(t),new V(function(){n.currentObservers=null,ce(a,t)}))},e.prototype._checkFinalizedStatuses=function(t){var n=this,o=n.hasError,i=n.thrownError,s=n.isStopped;o?t.error(i):s&&t.complete()},e.prototype.asObservable=function(){var t=new xe;return t.source=this,t},e.create=function(t,n){return new Ge(t,n)},e})(xe),Ge=(function(r){$(e,r);function e(t,n){var o=r.call(this)||this;return o.destination=t,o.source=n,o}return e.prototype.next=function(t){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.next)===null||o===void 0||o.call(n,t)},e.prototype.error=function(t){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.error)===null||o===void 0||o.call(n,t)},e.prototype.complete=function(){var t,n;(n=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||n===void 0||n.call(t)},e.prototype._subscribe=function(t){var n,o;return(o=(n=this.source)===null||n===void 0?void 0:n.subscribe(t))!==null&&o!==void 0?o:Ne},e})(Ye);const ue=3e3;var fe=(r=>(r.Warning="warning",r.Success="success",r.Error="error",r.Info="info",r))(fe||{}),he=(r=>(r.Success="mdi-checkbox-marked-circle",r.Warning="mdi-alert",r.Error="mdi-alert-circle",r.Info="mdi-information",r.None="none",r))(he||{}),de=(r=>(r.Warning="Warning",r.Success="Success",r.Error="Error",r.Info="Info",r))(de||{}),ze=(r=>(r.Center="center",r.Left="left",r.Right="right",r.Bottom="bottom",r.Top="top",r))(ze||{});class He{constructor(e="",t="info",n="none",o="Info",i=ue,s="center",a=!1){this.message=e,this.color=t,this.icon=n,this.title=o,this.timeout=i,this.position=s,this.visible=a}}class nr{static subject=new Ye;static get snack$(){return this.subject.asObservable()}static createSnackbar(e,t){this.subject.next(new He(e,fe[t],he[t],de[t],ue,"bottom",!0))}static success(e){this.createSnackbar(e,"Success")}static warn(e){this.createSnackbar(e,"Warning")}static error(e){this.createSnackbar(e,"Error")}static info(e){this.createSnackbar(e,"Info")}}function sr(r,e){const t=new Date(r);return t.setHours(t.getHours()-e),t.toISOString()}const D=(r,e)=>{let t=0,n=r.length;for(;t<n;){const o=t+n>>1;r[o]<e?t=o+1:n=o}return t},N=(r,e)=>{let t=0,n=r.length;for(;t<n;){const o=t+n>>1;r[o]>e?n=o:t=o+1}return t-1},Xe=`(function(){"use strict";function c(n,s,a,u,f,l,y,o){let r=0,e=o;for(let t=l;t<=y;t++)r<a.length&&t===a[r]?r++:(u[e]=n[t],f[e]=s[t],e++);return e-o}self.onmessage=n=>{const{bufferX:s,bufferY:a,outputBufferX:u,outputBufferY:f,start:l,end:y,deleteSegment:o,startTarget:r}=n.data,e=new Float64Array(s),t=new Float32Array(a),A=new Float64Array(u),g=new Float32Array(f);c(e,t,o,A,g,l,y,r),self.postMessage("Done")}})();
|
|
4
|
+
`,$e=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Xe],{type:"text/javascript;charset=utf-8"});function or(r){let e;try{if(e=$e&&(self.URL||self.webkitURL).createObjectURL($e),!e)throw"";const t=new Worker(e,{name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Xe),{name:r?.name})}}const Ve=`(function(){"use strict";function F(n,l,a,o,s,y,g,f,i,w,A){let e=0,t=f;for(let r=y;r<=g;r++)if(o[t]=n[r],s[t]=l[r],t++,e<a.length&&r===a[e][0]){const u=a[e][0],c=a[e][1],d=n[u],h=n[c],m=l[u],D=l[c],x=h-d,P=D-m;let p=d+i;for(;p<h;)o[t]=p,s[t]=w?m+(p-d)*P/x:A,t++,p+=i;e++}return t-f}self.onmessage=n=>{const{bufferX:l,bufferY:a,outputBufferX:o,outputBufferY:s,start:y,end:g,gapsSegment:f,startTarget:i,fillDelta:w,interpolate:A,fillValue:e}=n.data,t=new Float64Array(l),r=new Float32Array(a),u=new Float64Array(o),c=new Float32Array(s);F(t,r,f,u,c,y,g,i,w,A,e),self.postMessage("Done")}})();
|
|
5
|
+
`,qe=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Ve],{type:"text/javascript;charset=utf-8"});function ir(r){let e;try{if(e=qe&&(self.URL||self.webkitURL).createObjectURL(qe),!e)throw"";const t=new Worker(e,{name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Ve),{name:r?.name})}}const Ke=`(function(){"use strict";function g(o,n,c){for(let s=0;s<c.length;s++){const{indexes:t,lowerIdx:l,upperIdx:r}=c[s],i=o[l],f=n[l],a=o[r],d=n[r],p=a-i,w=d-f;if(p===0){for(let e=0;e<t.length;e++)n[t[e]]=f;continue}for(let e=0;e<t.length;e++){const u=t[e];n[u]=f+(o[u]-i)*w/p}}}self.onmessage=o=>{const{bufferX:n,bufferY:c,groups:s}=o.data,t=new Float64Array(n),l=new Float32Array(c);g(t,l,s),self.postMessage("Done")}})();
|
|
6
|
+
`,Je=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Ke],{type:"text/javascript;charset=utf-8"});function ar(r){let e;try{if(e=Je&&(self.URL||self.webkitURL).createObjectURL(Je),!e)throw"";const t=new Worker(e,{name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Ke),{name:r?.name})}}const Qe=`(function(){"use strict";self.onmessage=r=>{const{bufferX:s,bufferY:o,jobs:a}=r.data,f=new Float64Array(s),n=new Float32Array(o);for(let e=0;e<a.length;e++){const{chunkStart:c,chunkEnd:l,startDatetime:u,value:i,extent:y}=a[e];for(let t=c;t<l;t++)n[t]=n[t]+i*((f[t]-u)/y)}self.postMessage("Done")}})();
|
|
7
|
+
`,Ze=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Qe],{type:"text/javascript;charset=utf-8"});function cr(r){let e;try{if(e=Ze&&(self.URL||self.webkitURL).createObjectURL(Ze),!e)throw"";const t=new Worker(e,{name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Qe),{name:r?.name})}}const et=`(function(){"use strict";function u(f,o,a,n,l,c,s,i){let r=c,e=0,t=i;const w=a.length;for(;r<s&&e<w;){const y=a[e][0];f[r]<=y?(n[t]=f[r],l[t]=o[r],r++):(n[t]=y,l[t]=a[e][1],e++),t++}for(;r<s;)n[t]=f[r],l[t]=o[r],r++,t++;for(;e<w;)n[t]=a[e][0],l[t]=a[e][1],e++,t++;return t-i}self.onmessage=f=>{const{bufferX:o,bufferY:a,outputBufferX:n,outputBufferY:l,origStart:c,origEnd:s,insertions:i,outStart:r}=f.data,e=new Float64Array(o),t=new Float32Array(a),w=new Float64Array(n),y=new Float32Array(l);u(e,t,i,w,y,c,s,r),self.postMessage("Done")}})();
|
|
8
|
+
`,tt=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",et],{type:"text/javascript;charset=utf-8"});function lr(r){let e;try{if(e=tt&&(self.URL||self.webkitURL).createObjectURL(tt),!e)throw"";const t=new Worker(e,{name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(et),{name:r?.name})}}const rt=`(function(){"use strict";self.onmessage=i=>{const{bufferX:c,bufferY:g,outputBufferX:d,outputBufferY:y,indexes:n,outStart:r,amount:f,isMonth:Y,isYear:h,deltaMs:w}=i.data,s=new Float64Array(c),a=new Float32Array(g),l=new Float64Array(d),u=new Float32Array(y);if(Y)for(let t=0;t<n.length;t++){const e=n[t],o=new Date(s[e]);o.setMonth(o.getMonth()+f),l[r+t]=o.getTime(),u[r+t]=a[e]}else if(h)for(let t=0;t<n.length;t++){const e=n[t],o=new Date(s[e]);o.setFullYear(o.getFullYear()+f),l[r+t]=o.getTime(),u[r+t]=a[e]}else for(let t=0;t<n.length;t++){const e=n[t];l[r+t]=s[e]+w,u[r+t]=a[e]}self.postMessage("Done")}})();
|
|
9
|
+
`,nt=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",rt],{type:"text/javascript;charset=utf-8"});function ur(r){let e;try{if(e=nt&&(self.URL||self.webkitURL).createObjectURL(nt),!e)throw"";const t=new Worker(e,{name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(rt),{name:r?.name})}}const st=`(function(){"use strict";function a(e,t,o,c){const n=[];let r=e[t];for(let s=t+1;s<=o;s++){const f=e[s];f-r>c&&n.push(s-1,s),r=f}return n}self.onmessage=e=>{const{bufferX:t,start:o,endInclusive:c,threshold:n}=e.data,r=new Float64Array(t);self.postMessage(a(r,o,c,n))}})();
|
|
10
|
+
`,ot=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",st],{type:"text/javascript;charset=utf-8"});function fr(r){let e;try{if(e=ot&&(self.URL||self.webkitURL).createObjectURL(ot),!e)throw"";const t=new Worker(e,{name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(st),{name:r?.name})}}const it=`(function(){"use strict";function c(u,s,t){const n=[];if(s>=t)return n;let e=s,o=u[s];for(let r=s+1;r<t;r++){const f=u[r];f!==o&&(n.push(e,r-e,o),e=r,o=f)}return n.push(e,t-e,o),n}self.onmessage=u=>{const{bufferY:s,start:t,end:n}=u.data,e=new Float32Array(s);self.postMessage(c(e,t,n))}})();
|
|
11
|
+
`,at=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",it],{type:"text/javascript;charset=utf-8"});function hr(r){let e;try{if(e=at&&(self.URL||self.webkitURL).createObjectURL(at),!e)throw"";const t=new Worker(e,{name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(it),{name:r?.name})}}const ct=`(function(){"use strict";function o(s,i,t,n,l){const f=[];if(n==="Less than")for(let e=i;e<t;e++)s[e]-s[e-1]<l&&f.push(e);else if(n==="Less than or equal to")for(let e=i;e<t;e++)s[e]-s[e-1]<=l&&f.push(e);else if(n==="Greater than")for(let e=i;e<t;e++)s[e]-s[e-1]>l&&f.push(e);else if(n==="Greater than or equal to")for(let e=i;e<t;e++)s[e]-s[e-1]>=l&&f.push(e);else if(n==="Equal")for(let e=i;e<t;e++)s[e]-s[e-1]==l&&f.push(e);return f}self.onmessage=s=>{const{bufferY:i,start:t,end:n,comparator:l,value:f}=s.data,e=new Float32Array(i);self.postMessage(o(e,t,n,l,f))}})();
|
|
12
|
+
`,lt=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",ct],{type:"text/javascript;charset=utf-8"});function dr(r){let e;try{if(e=lt&&(self.URL||self.webkitURL).createObjectURL(lt),!e)throw"";const t=new Worker(e,{name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(ct),{name:r?.name})}}const ut=`(function(){"use strict";function l(t,i,n,o,h){const f=[];if(o==="Less than")for(let e=i;e<n;e++){const s=t[e-1];(t[e]-s)/Math.abs(s)<h&&f.push(e)}else if(o==="Less than or equal to")for(let e=i;e<n;e++){const s=t[e-1];(t[e]-s)/Math.abs(s)<=h&&f.push(e)}else if(o==="Greater than")for(let e=i;e<n;e++){const s=t[e-1];(t[e]-s)/Math.abs(s)>h&&f.push(e)}else if(o==="Greater than or equal to")for(let e=i;e<n;e++){const s=t[e-1];(t[e]-s)/Math.abs(s)>=h&&f.push(e)}else if(o==="Equal")for(let e=i;e<n;e++){const s=t[e-1];(t[e]-s)/Math.abs(s)==h&&f.push(e)}return f}self.onmessage=t=>{const{bufferY:i,start:n,end:o,comparator:h,value:f}=t.data,e=new Float32Array(i);self.postMessage(l(e,n,o,h,f))}})();
|
|
13
|
+
`,ft=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",ut],{type:"text/javascript;charset=utf-8"});function pr(r){let e;try{if(e=ft&&(self.URL||self.webkitURL).createObjectURL(ft),!e)throw"";const t=new Worker(e,{name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(ut),{name:r?.name})}}const ht=`(function(){"use strict";function k(i,l,u,r,c){const f=[],b=r.length;for(let a=l;a<u;a++){const t=i[a];let e=!1;for(let n=0;n<b;n++){const o=r[n],s=c[n];if(o===0){if(t<s){e=!0;break}}else if(o===1){if(t<=s){e=!0;break}}else if(o===2){if(t>s){e=!0;break}}else if(o===3){if(t>=s){e=!0;break}}else if(t==s){e=!0;break}}e&&f.push(a)}return f}self.onmessage=i=>{const{bufferY:l,start:u,end:r,ops:c,values:f}=i.data,b=new Float32Array(l);self.postMessage(k(b,u,r,c,f))}})();
|
|
14
14
|
`,dt=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",ht],{type:"text/javascript;charset=utf-8"});function pe(r){let e;try{if(e=dt&&(self.URL||self.webkitURL).createObjectURL(dt),!e)throw"";const t=new Worker(e,{name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(ht),{name:r?.name})}}const pt=`(function(){"use strict";function e(l,t,o,s){const c=t.length;if(o==="ADD")for(let f=0;f<c;f++)l[t[f]]=l[t[f]]+s;else if(o==="SUB")for(let f=0;f<c;f++)l[t[f]]=l[t[f]]-s;else if(o==="MULT")for(let f=0;f<c;f++)l[t[f]]=l[t[f]]*s;else if(o==="DIV")for(let f=0;f<c;f++)l[t[f]]=l[t[f]]/s;else if(o==="ASSIGN")for(let f=0;f<c;f++)l[t[f]]=s}self.onmessage=l=>{const{bufferY:t,indexes:o,operator:s,value:c}=l.data,f=new Float32Array(t);e(f,o,s,c),self.postMessage("Done")}})();
|
|
15
|
-
`,mt=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",pt],{type:"text/javascript;charset=utf-8"});function pr(r){let e;try{if(e=mt&&(self.URL||self.webkitURL).createObjectURL(mt),!e)throw"";const t=new Worker(e,{name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(pt),{name:r?.name})}}function wt(r,e,t,n,o){const i=[],s=n.length;for(let a=e;a<t;a++){const c=r[a];let p=!1;for(let f=0;f<s;f++){const w=n[f],m=o[f];if(w===0){if(c<m){p=!0;break}}else if(w===1){if(c<=m){p=!0;break}}else if(w===2){if(c>m){p=!0;break}}else if(w===3){if(c>=m){p=!0;break}}else if(c==m){p=!0;break}}p&&i.push(a)}return i}function mr(r,e,t,n,o){const i=[];if(n==="Less than")for(let s=e;s<t;s++)r[s]-r[s-1]<o&&i.push(s);else if(n==="Less than or equal to")for(let s=e;s<t;s++)r[s]-r[s-1]<=o&&i.push(s);else if(n==="Greater than")for(let s=e;s<t;s++)r[s]-r[s-1]>o&&i.push(s);else if(n==="Greater than or equal to")for(let s=e;s<t;s++)r[s]-r[s-1]>=o&&i.push(s);else if(n==="Equal")for(let s=e;s<t;s++)r[s]-r[s-1]==o&&i.push(s);return i}function wr(r,e,t,n,o){const i=[];if(n==="Less than")for(let s=e;s<t;s++){const a=r[s-1];(r[s]-a)/Math.abs(a)<o&&i.push(s)}else if(n==="Less than or equal to")for(let s=e;s<t;s++){const a=r[s-1];(r[s]-a)/Math.abs(a)<=o&&i.push(s)}else if(n==="Greater than")for(let s=e;s<t;s++){const a=r[s-1];(r[s]-a)/Math.abs(a)>o&&i.push(s)}else if(n==="Greater than or equal to")for(let s=e;s<t;s++){const a=r[s-1];(r[s]-a)/Math.abs(a)>=o&&i.push(s)}else if(n==="Equal")for(let s=e;s<t;s++){const a=r[s-1];(r[s]-a)/Math.abs(a)==o&&i.push(s)}return i}function gr(r,e,t,n){const o=[];let i=r[e];for(let s=e+1;s<=t;s++){const a=r[s];a-i>n&&o.push(s-1,s),i=a}return o}function yr(r,e,t){const n=[];if(e>=t)return n;let o=e,i=r[e];for(let s=e+1;s<t;s++){const a=r[s];a!==i&&(n.push(o,s-o,i),o=s,i=a)}return n.push(o,t-o,i),n}function br(r,e,t,n,o,i,s,a,c,p,f){let w=0,m=a;for(let d=i;d<=s;d++)if(n[m]=r[d],o[m]=e[d],m++,w<t.length&&d===t[w][0]){const y=t[w][0],l=t[w][1],u=r[y],g=r[l],h=e[y],E=e[l],S=g-u,L=E-h;let _=u+c;for(;_<g;)n[m]=_,o[m]=p?h+(_-u)*L/S:f,m++,_+=c;w++}return m-a}function Er(r,e,t,n,o,i,s,a){let c=i,p=0,f=a;const w=t.length;for(;c<s&&p<w;){const m=t[p][0];r[c]<=m?(n[f]=r[c],o[f]=e[c],c++):(n[f]=m,o[f]=t[p][1],p++),f++}for(;c<s;)n[f]=r[c],o[f]=e[c],c++,f++;for(;p<w;)n[f]=t[p][0],o[f]=t[p][1],p++,f++;return f-a}function Sr(r,e,t,n,o,i,s,a){let c=0,p=a;for(let f=i;f<=s;f++)c<t.length&&f===t[c]?c++:(n[p]=r[f],o[p]=e[f],p++);return p-a}function vr(r,e,t,n){const o=t.length,i=new Array(o);if(n.isMonth)for(let s=0;s<o;s++){const a=t[s],c=new Date(r[a]);c.setMonth(c.getMonth()+n.amount),i[s]=[c.getTime(),e[a]]}else if(n.isYear)for(let s=0;s<o;s++){const a=t[s],c=new Date(r[a]);c.setFullYear(c.getFullYear()+n.amount),i[s]=[c.getTime(),e[a]]}else for(let s=0;s<o;s++){const a=t[s];i[s]=[r[a]+n.deltaMs,e[a]]}return i}function kr(r,e,t){for(let n=0;n<t.length;n++){const{indexes:o,lowerIdx:i,upperIdx:s}=t[n],a=r[i],c=e[i],p=r[s],f=e[s],w=p-a,m=f-c;if(w===0){for(let d=0;d<o.length;d++)e[o[d]]=c;continue}for(let d=0;d<o.length;d++){const y=o[d];e[y]=c+(r[y]-a)*m/w}}}function Lr(r,e,t){for(let n=0;n<t.length;n++){const o=t[n][0],i=t[n][1],s=t[n][2];if(i<=o)continue;const a=r[o],c=r[i]-a;if(c!==0)for(let p=o;p<i;p++)e[p]=e[p]+s*((r[p]-a)/c)}}function gt(r,e,t,n){const o=e.length;if(t==="ADD")for(let i=0;i<o;i++)r[e[i]]=r[e[i]]+n;else if(t==="SUB")for(let i=0;i<o;i++)r[e[i]]=r[e[i]]-n;else if(t==="MULT")for(let i=0;i<o;i++)r[e[i]]=r[e[i]]*n;else if(t==="DIV")for(let i=0;i<o;i++)r[e[i]]=r[e[i]]/n;else if(t==="ASSIGN")for(let i=0;i<o;i++)r[e[i]]=n}const me="qc-utils:calibration:v1",Ar=720*60*60*1e3,J=5e4,Q=2e5,Z={spawnOverheadMs:50,inlineThroughput:5e4,workerThroughput:8e4,hwConcurrency:4,measuredAt:0,userAgent:"default"};let M=Cr()??Z,we=null,Y=null;const ge=new Set,ye={[A.VALUE_THRESHOLD]:{mode:"calibrated",weight:1,rationale:"O(n) single-pass scan; baseline reference"},[A.CHANGE]:{mode:"calibrated",weight:1.1,rationale:"O(n) with one subtraction per step"},[A.RATE_OF_CHANGE]:{mode:"calibrated",weight:1.4,rationale:"O(n) with division + abs per step"},[A.FIND_GAPS]:{mode:"calibrated",weight:.9,rationale:"O(n) on X only, mostly empty output"},[A.PERSISTENCE]:{mode:"calibrated",weight:1.3,rationale:"O(n) + chunk-boundary stitch"},[A.DATETIME_RANGE]:{mode:"always-inline",weight:0,rationale:"O(log n) binary search; never worth the worker hop"},[A.SELECTION]:{mode:"always-inline",weight:0,rationale:"Pure history bookkeeping"},[v.CHANGE_VALUES]:{mode:"calibrated",weight:.7,rationale:"O(k) in-place arithmetic on selection"},[v.ASSIGN_VALUES_BULK]:{mode:"always-inline",weight:0,rationale:"Single tight loop, already inline"},[v.ASSIGN_DATETIMES_BULK]:{mode:"always-inline",weight:0,rationale:"Composes delete+add which handle their own dispatch"},[v.INTERPOLATE]:{mode:"calibrated",weight:1.5,rationale:"Linear interp per consecutive group; in-place writes"},[v.DRIFT_CORRECTION]:{mode:"calibrated",weight:1.2,rationale:"O(range total) in-place math; one pass per range"},[v.SHIFT_DATETIMES]:{mode:"calibrated",weight:1.1,rationale:"O(k) per-point shift math; inline skips SAB allocation"},[v.ADD_POINTS]:{mode:"calibrated",weight:1.8,rationale:"Single merge pass over Y/X + insertions; fresh SAB per call"},[v.DELETE_POINTS]:{mode:"calibrated",weight:1.4,rationale:"Single skip-on-delete pass over Y/X; fresh SAB per call"},[v.FILL_GAPS]:{mode:"calibrated",weight:1.3,rationale:"Single copy-with-fills pass; fresh SAB sized to newLength"}};function U(r,e){const t=ye[r];if(!t)return{useWorker:!0,predictedInlineMs:1/0,predictedWorkerMs:0,reason:"unknown op; keeping default worker path"};if(t.mode==="always-inline")return{useWorker:!1,predictedInlineMs:0,predictedWorkerMs:0,reason:t.rationale};if(typeof SharedArrayBuffer>"u")return{useWorker:!1,predictedInlineMs:0,predictedWorkerMs:1/0,reason:"SharedArrayBuffer unavailable; forced inline"};if(t.mode==="always-worker")return{useWorker:!0,predictedInlineMs:1/0,predictedWorkerMs:0,reason:t.rationale};const n=_r(r,e);if(n<=0)return{useWorker:!1,predictedInlineMs:0,predictedWorkerMs:M.spawnOverheadMs,reason:"zero work units"};const o=Math.max(1,Math.min(e.parallelism??M.hwConcurrency,M.hwConcurrency)),i=t.weight*n/M.inlineThroughput,s=M.spawnOverheadMs+t.weight*n/(M.workerThroughput*o),a=i>s;return{useWorker:a,predictedInlineMs:i,predictedWorkerMs:s,reason:a?`worker faster (${s.toFixed(1)} vs ${i.toFixed(1)} ms)`:`inline faster (${i.toFixed(1)} vs ${s.toFixed(1)} ms)`}}function _r(r,e){switch(r){case v.CHANGE_VALUES:case v.INTERPOLATE:case v.SHIFT_DATETIMES:case v.DRIFT_CORRECTION:return e.selectionSize??0;case v.DELETE_POINTS:return(e.selectionSize??0)+e.datasetSize*.25;case v.ADD_POINTS:{const t=Math.max(1,Math.log2(Math.max(e.datasetSize,2)));return e.datasetSize+(e.selectionSize??0)*t}default:return e.datasetSize}}function Tr(r){return ge.add(r),()=>ge.delete(r)}function Rr(){return M}function Ir(){return we}function Mr(){return Object.keys(ye).map(r=>({op:r,...ye[r]}))}function Or(){M=Z,we=null;try{localStorage.removeItem(me)}catch{}}async function Ur(r={}){if(typeof window>"u"||!(r.force||M.measuredAt===0||Date.now()-M.measuredAt>Ar))return M;if(Y)await Y;else{Y=yt().finally(()=>{Y=null});const t=await Y;M=t,Dr(t),we=t;for(const n of ge)n(M)}return M}async function yt(){if(!(typeof SharedArrayBuffer<"u"))return{...Z,measuredAt:Date.now(),userAgent:navigator.userAgent,hwConcurrency:navigator.hardwareConcurrency||Z.hwConcurrency,sharedArrayBufferAvailable:!1,samples:{spawnRoundtripMs:[],inlineScanMs:[],workerScanMs:[]}};const e=navigator.hardwareConcurrency||4,t=new Float32Array(J);for(let l=0;l<J;l++)t[l]=Math.sin(l);const n=await be(3,()=>{const l=performance.now();return wt(t,0,J,[2],[.5]),performance.now()-l}),o=Ee(n),i=J/Math.max(o,.001),s=new SharedArrayBuffer(256*Float32Array.BYTES_PER_ELEMENT),a=await be(3,async()=>{const l=performance.now();return await new Promise(u=>{const g=new pe;g.onmessage=()=>{g.terminate(),u()},g.postMessage({bufferY:s,start:0,end:256,ops:[2],values:[.5]})}),performance.now()-l}),c=Ee(a),p=new SharedArrayBuffer(Q*Float32Array.BYTES_PER_ELEMENT),f=new Float32Array(p);for(let l=0;l<Q;l++)f[l]=Math.sin(l);const w=await be(3,async()=>{const l=performance.now();return await new Promise(u=>{const g=new pe;g.onmessage=()=>{g.terminate(),u()},g.postMessage({bufferY:p,start:0,end:Q,ops:[2],values:[.5]})}),performance.now()-l}),m=Math.max(Ee(w)-c,.1),d=Q/m;return{spawnOverheadMs:c,inlineThroughput:i,workerThroughput:d,hwConcurrency:e,measuredAt:Date.now(),userAgent:navigator.userAgent,sharedArrayBufferAvailable:!0,samples:{spawnRoundtripMs:a,inlineScanMs:n,workerScanMs:w}}}async function be(r,e){const t=[];for(let n=0;n<r;n++)await new Promise(o=>setTimeout(o,0)),t.push(await e());return t}function Ee(r){if(!r.length)return 0;const e=[...r].sort((n,o)=>n-o),t=Math.floor(e.length/2);return e.length%2?e[t]:(e[t-1]+e[t])/2}function Cr(){if(typeof localStorage>"u")return null;try{const r=localStorage.getItem(me);if(!r)return null;const e=JSON.parse(r);return!e||typeof e.spawnOverheadMs!="number"?null:e}catch{return null}}function Dr(r){if(!(typeof localStorage>"u"))try{const e={spawnOverheadMs:r.spawnOverheadMs,inlineThroughput:r.inlineThroughput,workerThroughput:r.workerThroughput,hwConcurrency:r.hwConcurrency,measuredAt:r.measuredAt,userAgent:r.userAgent};localStorage.setItem(me,JSON.stringify(e))}catch{}}const x=20*1e3,Nr=typeof SharedArrayBuffer<"u";function O(r,e){return Nr?e!==void 0?new SharedArrayBuffer(r,{maxByteLength:e}):new SharedArrayBuffer(r):e!==void 0?new ArrayBuffer(r,{maxByteLength:e}):new ArrayBuffer(r)}function bt(r,e){const t=r;typeof t.grow=="function"?t.grow(e):typeof t.resize=="function"&&t.resize(e)}function Fr(r,e){if(r.length!==e.length)return!1;for(let t=0;t<r.length;t++)if(r[t]!==e[t])return!1;return!0}function Pr(r,e){switch(r){case v.ADD_POINTS:case v.FILL_GAPS:return!1;default:return!0}}class Br{dataset={source:{x:new Float64Array(O(x*Float64Array.BYTES_PER_ELEMENT,x*Float64Array.BYTES_PER_ELEMENT)),y:new Float32Array(O(x*Float32Array.BYTES_PER_ELEMENT,x*Float32Array.BYTES_PER_ELEMENT))}};history=[];redoStack=[];_isReplaying=!1;_pendingExecutionMode="inline";loadingTime=null;isLoading=!0;rawData;constructor(e){this.history=[],this.rawData=e,this.loadData(this.rawData)}async loadData(e){if(!e)return;this.isLoading=!0;const t=await z(()=>{this._growBuffer(e.datetimes.length),this._resizeTo(e.datetimes.length),this.dataX.set(e.datetimes),this.dataY.set(e.dataValues)});this.loadingTime=t.duration,this.history.length=0,this.isLoading=!1}get dataX(){return this.dataset.source.x}get dataY(){return this.dataset.source.y}_resizeTo(e){this.dataset.source.x=new Float64Array(this.dataset.source.x.buffer).subarray(0,e),this.dataset.source.y=new Float32Array(this.dataset.source.y.buffer).subarray(0,e)}_growBuffer(e){const t=e*Float64Array.BYTES_PER_ELEMENT;let n=this.dataX.buffer.byteLength;for(;t>n;)n+=x*Float64Array.BYTES_PER_ELEMENT;if(n*Float64Array.BYTES_PER_ELEMENT>this.dataX.buffer.maxByteLength){const o=O(this.dataX.buffer.byteLength,n*Float64Array.BYTES_PER_ELEMENT),i=O(this.dataY.buffer.byteLength,n*Float32Array.BYTES_PER_ELEMENT),s=new Float64Array(o),a=new Float32Array(i);s.set(this.dataX),a.set(this.dataY),this.dataset.source.x=s,this.dataset.source.y=a}this.dataX.buffer.byteLength<e*Float64Array.BYTES_PER_ELEMENT&&(bt(this.dataX.buffer,e*Float64Array.BYTES_PER_ELEMENT),bt(this.dataY.buffer,e*Float32Array.BYTES_PER_ELEMENT))}async reload(){this.loadingTime=null,this.isLoading=!0,this.history.length=0,await this.loadData(this.rawData)}async reloadHistory(e){const t=this.history.slice(0,e+1);return this.redoStack.length=0,await this.reload(),await this.dispatch(t.map(n=>[n.method,...n.args||[]]))}async removeHistoryItem(e){const t=[...this.history];return t.splice(e,1),this.redoStack.length=0,await this.reload(),await this.dispatch(t.map(n=>[n.method,...n.args||[]]))}async undo(){if(!this.history.length)return[];const e=this.history[this.history.length-1],t=this.history.slice(0,-1);await this.reload(),this.redoStack.push(e),this._isReplaying=!0;try{return await this.dispatch(t.map(n=>[n.method,...n.args||[]]))}finally{this._isReplaying=!1}}async redo(){if(!this.redoStack.length)return[];const e=this.redoStack.pop();this._isReplaying=!0;try{return await this.dispatch([[e.method,...e.args||[]]])}finally{this._isReplaying=!1}}get beginTime(){return this.dataset.source.x.length?new Date(this.dataset.source.x[0]):null}get endTime(){return this.dataset.source.x.length?new Date(this.dataset.source.x[this.dataset.source.x.length-1]):null}async dispatchAction(e,...t){const n={[v.ADD_POINTS]:this._addDataPoints,[v.CHANGE_VALUES]:this._changeValues,[v.ASSIGN_VALUES_BULK]:this._assignValuesBulk,[v.DELETE_POINTS]:this._deleteDataPointsFromSelection,[v.DRIFT_CORRECTION]:this._driftCorrectionFromSelection,[v.INTERPOLATE]:this._interpolateFromSelection,[v.SHIFT_DATETIMES]:this._shiftFromSelection,[v.ASSIGN_DATETIMES_BULK]:this._assignDatetimesBulk,[v.FILL_GAPS]:this._fillGaps};let o=[],i=null;try{this._isReplaying||(this.redoStack.length=0),i={method:e,args:t,isLoading:!0,timestamp:Date.now()},this.history.push(i),Pr(e,t)||this.history[this.history.length-2]?.method===A.SELECTION&&this.history.splice(this.history.length-2,1),this._pendingExecutionMode="inline";const s=await z(async()=>await n[e].apply(this,t));o=s.response;const a=this.history.indexOf(i),c=a>=0?this.history[a]:void 0;c&&(c.duration=s.duration,c.executionMode=this._pendingExecutionMode,c.status="success",c.isLoading=!1)}catch{if(i){const a=this.history.indexOf(i),c=a>=0?this.history[a]:void 0;c&&(c.status="failed",c.isLoading=!1)}}return o}async dispatch(e,...t){const n=async(o,i)=>A[o]?await this.dispatchFilter(o,...i):await this.dispatchAction(o,...i);if(Array.isArray(e)){let o=[];for(let i=0;i<e.length;i++){const s=e[i][0],a=e[i].slice(1,e[i].length);o=await n(s,a)}return o}else return await n(e,t)}async dispatchFilter(e,...t){const n={[A.FIND_GAPS]:this._findGaps,[A.VALUE_THRESHOLD]:this._valueThreshold,[A.DATETIME_RANGE]:this._datetimeRange,[A.PERSISTENCE]:this._persistence,[A.CHANGE]:this._change,[A.RATE_OF_CHANGE]:this._rateOfChange,[A.SELECTION]:this._selection};let o=[],i=null;try{const s=e===A.SELECTION,a=s&&(!t[0]||Array.isArray(t[0])&&t[0].length===0);!this._isReplaying&&!a&&(this.redoStack.length=0),i={method:e,args:t,isLoading:!0,timestamp:Date.now()};const c=this.history[this.history.length-1],p=!!A[c?.method],f=c?.method===e||p&&!s;let w;f?(w=this.history.length-1,this.history[w]=i):(this.history.push(i),w=this.history.length-1),this._pendingExecutionMode="inline";const m=await z(async()=>await n[e].apply(this,t));o=m.response;const d=this.history.indexOf(i),y=d>=0?this.history[d]:void 0;y&&(y.duration=m.duration,y.executionMode=this._pendingExecutionMode,y.selected=m.response,y.status="success",y.isLoading=!1)}catch(s){if(console.log(`Failed to execute filter operation: ${e} with arguments: `,t),console.log(s),i){const a=this.history.indexOf(i),c=a>=0?this.history[a]:void 0;c&&(c.status="failed",c.isLoading=!1)}}return o}async _changeValues(e,t){const n=this.history[this.history.length-2]?.selected;if(!n||n.length===0)return[];const o=n.length;if(!U(v.CHANGE_VALUES,{datasetSize:this.dataset.source.y.length,selectionSize:o}).useWorker)return gt(this.dataY,n,e,t),[];this._pendingExecutionMode="worker";const s=Math.min(navigator.hardwareConcurrency||1,o),a=Math.ceil(o/s),c=[],p=[];for(let f=0;f<s;f++){const w=f*a,m=Math.min((f+1)*a,o);if(w>=m)break;const d=n.slice(w,m);p.push(new Promise(y=>{const l=new pr;c.push(l),l.postMessage({bufferY:this.dataY.buffer,indexes:d,operator:e,value:t}),l.onmessage=u=>{y(u.data)}}))}return await Promise.all(p),c.forEach(f=>f.terminate()),[]}_applyOperatorInPlace(e,t,n){gt(this.dataY,e,t,n)}async _assignValuesBulk(e){const t=this.history[this.history.length-2]?.selected;if(!t||!t.length||!e?.length)return[];const n=Math.min(t.length,e.length),o=this.dataY;for(let i=0;i<n;i++)o[t[i]]=e[i];return[]}async _assignDatetimesBulk(e){const t=this.history[this.history.length-2]?.selected;if(!t||!t.length||!e?.length)return[];const n=Math.min(t.length,e.length),o=new Array(n),i=new Array(n);for(let s=0;s<n;s++)o[s]=[e[s],this.dataY[t[s]]],i[s]=t[s];return i.sort((s,a)=>s-a),await this._deleteDataPoints(i),await this._addDataPoints(o),[]}async _interpolateFromSelection(){const e=this.history[this.history.length-2]?.selected;if(!(!e||e.length===0))return this._interpolate(e)}async _interpolate(e){const t=this._getConsecutiveGroups(e);if(t.length===0||t[0].length===0)return;const n=this.dataset.source.y.length,o=t.map(f=>({indexes:f,lowerIdx:Math.max(0,f[0]-1),upperIdx:Math.min(n-1,f[f.length-1]+1)}));if(!U(v.INTERPOLATE,{datasetSize:n,selectionSize:e.length}).useWorker){kr(this.dataX,this.dataY,o);return}this._pendingExecutionMode="worker";const s=Math.min(navigator.hardwareConcurrency||1,o.length),a=Math.ceil(o.length/s),c=[],p=[];for(let f=0;f<s;f++){const w=o.slice(f*a,(f+1)*a);if(w.length===0)break;p.push(new Promise(m=>{const d=new ir;c.push(d),d.postMessage({bufferX:this.dataX.buffer,bufferY:this.dataY.buffer,groups:w}),d.onmessage=y=>{m(y.data)}}))}await Promise.all(p),c.forEach(f=>f.terminate())}async _shiftFromSelection(e,t){const n=this.history[this.history.length-2]?.selected;return!n||n.length===0?[]:await this._shift(n,e,t)??[]}async _shift(e,t,n){if(e.length===0)return[];const o=n===I.MONTH,i=n===I.YEAR,s=!o&&!i?t*W[n]*1e3:0,a=e.length;if(!U(v.SHIFT_DATETIMES,{datasetSize:this.dataset.source.x.length,selectionSize:a}).useWorker){const h=vr(this.dataX,this.dataY,e,{amount:t,isMonth:o,isYear:i,deltaMs:s});return await this._deleteDataPoints(e),await this._addDataPoints(h)??[]}this._pendingExecutionMode="worker";const p=O(a*Float64Array.BYTES_PER_ELEMENT),f=O(a*Float32Array.BYTES_PER_ELEMENT),w=Math.min(navigator.hardwareConcurrency||1,a),m=Math.ceil(a/w),d=[],y=[];for(let h=0;h<w;h++){const E=h*m,S=Math.min((h+1)*m,a);if(E>=S)break;const L=e.slice(E,S);y.push(new Promise(_=>{const T=new lr;d.push(T),T.postMessage({bufferX:this.dataX.buffer,bufferY:this.dataY.buffer,outputBufferX:p,outputBufferY:f,indexes:L,outStart:E,amount:t,isMonth:o,isYear:i,deltaMs:s}),T.onmessage=R=>{_(R.data)}}))}await Promise.all(y),d.forEach(h=>h.terminate());const l=new Float64Array(p),u=new Float32Array(f),g=new Array(a);for(let h=0;h<a;h++)g[h]=[l[h],u[h]];return await this._deleteDataPoints(e),await this._addDataPoints(g)??[]}async _fillGaps(e,t,n,o,i){const s=this.dataX.length;if(s===0)return[];const a=e[0]*W[e[1]]*1e3,c=t[0]*W[t[1]]*1e3,p=this.dataX,f=i?.[0]!=null&&Number.isFinite(i[0])?D(p,i[0]):0,w=i?.[1]!=null&&Number.isFinite(i[1])?N(p,i[1]):s-1,m=[],d=[];let y=0;for(let k=f+1;k<=w;k++)if(p[k]-p[k-1]>a){let C=0,F=p[k-1]+c;for(;F<p[k];)C++,F+=c;C>0&&(m.push([k-1,k]),d.push(C),y+=C)}if(y===0)return[];const l=new Array(y);let u=0,g=0;for(let k=0;k<m.length;k++){const P=m[k][0],C=d[k];for(let F=1;F<=C;F++)l[g++]=P+u+F;u+=C}const h=s+y,E=h*Float64Array.BYTES_PER_ELEMENT,S=h*Float32Array.BYTES_PER_ELEMENT,L=O(E,Math.max(this.dataX.buffer.maxByteLength,E)),_=O(S,Math.max(this.dataY.buffer.maxByteLength,S));if(!U(v.FILL_GAPS,{datasetSize:s,selectionSize:y}).useWorker){const k=new Float64Array(L),P=new Float32Array(_);return br(this.dataX,this.dataY,m,k,P,0,s-1,0,c,n,o),this.dataset.source.x=k,this.dataset.source.y=P,this._resizeTo(h),l}this._pendingExecutionMode="worker";const R=navigator.hardwareConcurrency||1,Et=Math.ceil(s/R),Se=[];let H=0;for(let k=0;k<R;k++){const P=k*Et,C=Math.min((k+1)*Et-1,s-1),F=[];let ee=0;for(;H<m.length&&m[H][0]<=C;)F.push(m[H]),ee+=d[H],H++;Se.push({start:P,end:C,gapsSegment:F,fillsInSegment:ee})}const ve=new Array(R).fill(0);for(let k=1;k<R;k++)ve[k]=ve[k-1]+Se[k-1].fillsInSegment;const St=[],vt=[];for(let k=0;k<R;k++){const{start:P,end:C,gapsSegment:F}=Se[k],ee=P+ve[k];vt.push(new Promise(Gr=>{const ke=new or;St.push(ke),ke.postMessage({bufferX:this.dataX.buffer,bufferY:this.dataY.buffer,outputBufferX:L,outputBufferY:_,start:P,end:C,gapsSegment:F,startTarget:ee,fillDelta:c,interpolate:n,fillValue:o}),ke.onmessage=Hr=>{Gr(Hr.data)}}))}return await Promise.all(vt),St.forEach(k=>k.terminate()),this.dataset.source.x=new Float64Array(L),this.dataset.source.y=new Float32Array(_),this._resizeTo(h),l}async _deleteDataPointsFromSelection(){const e=this.history[this.history.length-2]?.selected;if(!(!e||e.length===0))return this._deleteDataPoints(e)}async _deleteDataPoints(e){const t=this.dataX.length,n=t-e.length;if(!U(v.DELETE_POINTS,{datasetSize:t,selectionSize:e.length}).useWorker){const d=O(this.dataX.buffer.byteLength,this.dataX.buffer.maxByteLength),y=O(this.dataY.buffer.byteLength,this.dataY.buffer.maxByteLength),l=new Float64Array(d),u=new Float32Array(y);Sr(this.dataX,this.dataY,e,l,u,0,t-1,0),this.dataset.source.x=l,this.dataset.source.y=u,this._resizeTo(n);return}this._pendingExecutionMode="worker";const i=navigator.hardwareConcurrency||1,s=Math.ceil(this.dataX.length/i),a=[],c=[];for(let d=0;d<i;d++){const y=d*s,l=Math.min((d+1)*s-1,this.dataX.length-1),u=D(e,y),g=N(e,l),h=e.slice(u,g+1);c.push({start:y,end:l,deleteSegment:h})}const p=new Array(i).fill(0);for(let d=1;d<i;d++)p[d]=p[d-1]+c[d-1].deleteSegment.length;const f=[],w=O(this.dataX.buffer.byteLength,this.dataX.buffer.maxByteLength),m=O(this.dataY.buffer.byteLength,this.dataY.buffer.maxByteLength);for(let d=0;d<i;d++){const{start:y,end:l,deleteSegment:u}=c[d],g=y-p[d];f.push(new Promise(h=>{const E=new sr;a.push(E),E.postMessage({bufferX:this.dataX.buffer,bufferY:this.dataY.buffer,outputBufferX:w,outputBufferY:m,start:y,end:l,deleteSegment:u,startTarget:g}),E.onmessage=S=>{h(S.data)}}))}await Promise.all(f),a.forEach(d=>d.terminate()),this.dataset.source.x=new Float64Array(w),this.dataset.source.y=new Float32Array(m),this._resizeTo(n)}async _driftCorrectionFromSelection(e){const t=this.history[this.history.length-2]?.selected;if(!t||t.length===0)return;const n=this._getConsecutiveGroups(t),o=[];for(const i of n)i.length!==0&&o.push([i[0],i[i.length-1],e]);if(o.length!==0)return this._driftCorrection(o)}async _driftCorrection(e){if(!e||e.length===0)return;const t=this.dataset.source.x,n=navigator.hardwareConcurrency||1;let o=0;for(const[w,m]of e)m>w&&(o+=m-w);if(!U(v.DRIFT_CORRECTION,{datasetSize:t.length,selectionSize:o}).useWorker){Lr(t,this.dataY,e);return}this._pendingExecutionMode="worker";const s=[];for(const[w,m,d]of e){if(m<=w)continue;const y=t[w],l=t[m]-y;if(l===0)continue;const u=m-w,g=Math.max(1,Math.ceil(u/n));for(let h=w;h<m;h+=g)s.push({chunkStart:h,chunkEnd:Math.min(h+g,m),startDatetime:y,value:d,extent:l})}if(s.length===0)return;const a=Math.min(n,s.length),c=Array.from({length:a},()=>[]);s.forEach((w,m)=>c[m%a].push(w));const p=[],f=[];for(const w of c)w.length!==0&&f.push(new Promise(m=>{const d=new ar;p.push(d),d.postMessage({bufferX:this.dataX.buffer,bufferY:this.dataY.buffer,jobs:w}),d.onmessage=y=>{m(y.data)}}));await Promise.all(f),p.forEach(w=>w.terminate())}_getConsecutiveGroups(e){const t=[[]];return e.reduce((n,o)=>{const i=n[n.length-1];return!i.length||o==i[i.length-1]+1?i.push(o):n.push([o]),n},t),t}async _addDataPoints(e){if(e.length===0)return[];const t=this.dataX.length,n=t+e.length;e.sort((l,u)=>l[0]-u[0]);const o=new Array(e.length);for(let l=0;l<e.length;l++){const u=e[l][0],g=N(this.dataX,u)+1;o[l]=g+l}const i=n*Float64Array.BYTES_PER_ELEMENT,s=n*Float32Array.BYTES_PER_ELEMENT,a=O(i,Math.max(this.dataX.buffer.maxByteLength,i)),c=O(s,Math.max(this.dataY.buffer.maxByteLength,s));if(!U(v.ADD_POINTS,{datasetSize:t,selectionSize:e.length}).useWorker){const l=new Float64Array(a),u=new Float32Array(c);return Er(this.dataX,this.dataY,e,l,u,0,t,0),this.dataset.source.x=l,this.dataset.source.y=u,this._resizeTo(n),o}this._pendingExecutionMode="worker";const f=e.map(l=>N(this.dataX,l[0])+1),w=Math.max(1,Math.min(navigator.hardwareConcurrency||1,Math.max(t,1))),m=Math.ceil(Math.max(t,1)/w),d=[],y=[];for(let l=0;l<w;l++){const u=l*m,g=Math.min((l+1)*m,t),h=D(f,u),E=l===w-1?e.length:D(f,g),S=e.slice(h,E),L=u+h;u>=g&&S.length===0||y.push(new Promise(_=>{const T=new cr;d.push(T),T.postMessage({bufferX:this.dataX.buffer,bufferY:this.dataY.buffer,outputBufferX:a,outputBufferY:c,origStart:u,origEnd:g,insertions:S,outStart:L}),T.onmessage=R=>{_(R.data)}}))}return await Promise.all(y),d.forEach(l=>l.terminate()),this.dataset.source.x=new Float64Array(a),this.dataset.source.y=new Float32Array(c),this._resizeTo(n),o}async _valueThreshold(e,t){const n=Object.keys(e);if(n.length===0)return[];const o={[j.LT]:0,[j.LTE]:1,[j.GT]:2,[j.GTE]:3,[j.E]:4},i=n.map(E=>o[E]??4),s=n.map(E=>e[E]),a=this.dataset.source.y,c=this.dataset.source.x;let p=0,f=a.length;if(f===0)return[];if(t!=null){const[E,S]=t;E!=null&&Number.isFinite(E)&&(p=D(c,E)),S!=null&&Number.isFinite(S)&&(f=N(c,S)+1)}if(f<=p)return[];const w=f-p;if(!U(A.VALUE_THRESHOLD,{datasetSize:w}).useWorker)return wt(a,p,f,i,s);this._pendingExecutionMode="worker";const d=Math.min(navigator.hardwareConcurrency||1,w),y=Math.ceil(w/d),l=[],u=[];for(let E=0;E<d;E++){const S=p+E*y,L=Math.min(p+(E+1)*y,f);if(S>=L)break;u.push(new Promise(_=>{const T=new pe;l.push(T),T.postMessage({bufferY:this.dataY.buffer,start:S,end:L,ops:i,values:s}),T.onmessage=R=>{_(R.data)}}))}const g=await Promise.all(u);l.forEach(E=>E.terminate());const h=[];for(let E=0;E<g.length;E++){const S=g[E];for(let L=0;L<S.length;L++)h.push(S[L])}return h}async _rateOfChange(e,t,n){const o=this.dataset.source.y,i=this.dataset.source.x;if(o.length<2)return[];let s=1,a=o.length;if(n!=null){const[u,g]=n;u!=null&&Number.isFinite(u)&&(s=Math.max(1,D(i,u))),g!=null&&Number.isFinite(g)&&(a=N(i,g)+1)}if(a<=s)return[];const c=a-s;if(!U(A.RATE_OF_CHANGE,{datasetSize:o.length}).useWorker)return wr(o,s,a,e,t);this._pendingExecutionMode="worker";const f=Math.min(navigator.hardwareConcurrency||1,c),w=Math.ceil(c/f),m=[],d=[];for(let u=0;u<f;u++){const g=s+u*w,h=Math.min(s+(u+1)*w,a);if(g>=h)break;d.push(new Promise(E=>{const S=new dr;m.push(S),S.postMessage({bufferY:this.dataY.buffer,start:g,end:h,comparator:e,value:t}),S.onmessage=L=>{E(L.data)}}))}const y=await Promise.all(d);m.forEach(u=>u.terminate());const l=[];for(let u=0;u<y.length;u++){const g=y[u];for(let h=0;h<g.length;h++)l.push(g[h])}return l}async _datetimeRange(e,t){const n=this.dataset.source.x,o=n.length;if(o===0)return[];const i=e==null?0:D(n,e),s=t==null?o-1:N(n,t);if(i>s)return[];const a=new Array(s-i+1);for(let c=i;c<=s;c++)a[c-i]=c;return a}async _selection(e){const t=this.history[this.history.length-2],n=!!t&&t.method!==A.SELECTION&&!!A[t.method],o=n&&Array.isArray(t.selected)?t.selected:void 0;return!e||!e.length?(this.history.pop(),o&&o.length>0&&this.history.pop(),e):(o&&Fr(o,e)?this.history.pop():n&&this.history.splice(this.history.length-2,1),e)}async _change(e,t,n){const o=this.dataset.source.y,i=this.dataset.source.x;if(o.length<2)return[];let s=1,a=o.length;if(n!=null){const[u,g]=n;u!=null&&Number.isFinite(u)&&(s=Math.max(1,D(i,u))),g!=null&&Number.isFinite(g)&&(a=N(i,g)+1)}if(a<=s)return[];const c=a-s;if(!U(A.CHANGE,{datasetSize:o.length}).useWorker)return mr(o,s,a,e,t);this._pendingExecutionMode="worker";const f=Math.min(navigator.hardwareConcurrency||1,c),w=Math.ceil(c/f),m=[],d=[];for(let u=0;u<f;u++){const g=s+u*w,h=Math.min(s+(u+1)*w,a);if(g>=h)break;d.push(new Promise(E=>{const S=new hr;m.push(S),S.postMessage({bufferY:this.dataY.buffer,start:g,end:h,comparator:e,value:t}),S.onmessage=L=>{E(L.data)}}))}const y=await Promise.all(d);m.forEach(u=>u.terminate());const l=[];for(let u=0;u<y.length;u++){const g=y[u];for(let h=0;h<g.length;h++)l.push(g[h])}return l}async _findGaps(e,t,n){const o=this.dataset.source.x;let i=0,s=o.length;if(n!=null){const[u,g]=n;u!=null&&Number.isFinite(u)&&(i=D(o,u)),g!=null&&Number.isFinite(g)&&(s=N(o,g)+1)}if(s<=i)return[];const a=e*W[t]*1e3;if(!U(A.FIND_GAPS,{datasetSize:s-i}).useWorker){const u=gr(o,i,s-1,a),g=new Set;for(let h=0;h<u.length;h++)g.add(u[h]);return[...g]}this._pendingExecutionMode="worker";const p=s-i,f=Math.min(navigator.hardwareConcurrency||1,p),w=Math.ceil(p/f),m=[],d=[];for(let u=0;u<f;u++){const g=i+u*w,h=Math.min(i+(u+1)*w,s);if(g>=h)break;d.push(new Promise(E=>{const S=new ur;m.push(S),S.postMessage({bufferX:this.dataX.buffer,start:g,endInclusive:h,threshold:a}),S.onmessage=L=>{E(L.data)}}))}const y=await Promise.all(d);m.forEach(u=>u.terminate());const l=new Set;for(let u=0;u<y.length;u++){const g=y[u];for(let h=0;h<g.length;h++)l.add(g[h])}return[...l]}async _persistence(e,t){const n=this.dataset.source.x,o=this.dataset.source.y;let i=0,s=o.length;if(t!=null){const[h,E]=t;h!=null&&Number.isFinite(h)&&(i=D(n,h)),E!=null&&Number.isFinite(E)&&(s=N(n,E)+1)}if(s<=i)return[];const a=s-i;if(!U(A.PERSISTENCE,{datasetSize:a}).useWorker){const h=yr(o,i,s),E=[];for(let S=0;S<h.length;S+=3){const L=h[S],_=h[S+1];if(_>=e)for(let T=0;T<_;T++)E.push(L+T)}return E}this._pendingExecutionMode="worker";const p=Math.min(navigator.hardwareConcurrency||1,a),f=Math.ceil(a/p),w=[],m=[];for(let h=0;h<p;h++){const E=i+h*f,S=Math.min(i+(h+1)*f,s);if(E>=S)break;m.push(new Promise(L=>{const _=new fr;w.push(_),_.postMessage({bufferY:this.dataY.buffer,start:E,end:S}),_.onmessage=T=>{L(T.data)}}))}const d=await Promise.all(m);w.forEach(h=>h.terminate());const y=[],l=[],u=[];for(let h=0;h<d.length;h++){const E=d[h];for(let S=0;S<E.length;S+=3){const L=E[S],_=E[S+1],T=E[S+2],R=y.length-1;R>=0&&u[R]===T&&y[R]+l[R]===L?l[R]+=_:(y.push(L),l.push(_),u.push(T))}}const g=[];for(let h=0;h<y.length;h++){const E=l[h];if(E>=e){const S=y[h];for(let L=0;L<E;L++)g.push(S+L)}}return g}}const G="1",jr=new Set([...Object.values(v),...Object.values(A)]);function xr(r,e){const t=r.history.map(n=>{const o={method:n.method,args:n.args?[...n.args]:[]};return n.status==="failed"&&(o.status="failed"),typeof n.timestamp=="number"&&Number.isFinite(n.timestamp)&&(o.timestamp=n.timestamp),o});return{version:G,createdAt:new Date().toISOString(),window:{startDate:e.startDate,endDate:e.endDate},operations:t}}function Wr(r){if(!r||typeof r!="object")throw new Error("QC script must be a JSON object.");const e=r;if(e.version!==G)throw new Error(`Unsupported QC script version: ${String(e.version)}. This loader understands version "${G}".`);if(typeof e.createdAt!="string")throw new Error("QC script is missing `createdAt` (ISO-8601 string).");const t=e.window;if(!t||typeof t!="object")throw new Error("QC script is missing `window`.");if(typeof t.startDate!="string"||typeof t.endDate!="string")throw new Error("`window.startDate` and `window.endDate` must be ISO-8601 strings.");if(!Array.isArray(e.operations))throw new Error("QC script `operations` must be an array.");const n=e.operations.map((o,i)=>{if(!o||typeof o!="object")throw new Error(`Operation ${i} must be an object.`);const s=o;if(typeof s.method!="string")throw new Error(`Operation ${i} missing string \`method\`.`);if(!jr.has(s.method))throw new Error(`Operation ${i} has unknown method: "${s.method}".`);if(!Array.isArray(s.args))throw new Error(`Operation ${i} \`args\` must be an array.`);const a={method:s.method,args:[...s.args]};if(s.status==="failed"&&(a.status="failed"),s.timestamp!==void 0){if(typeof s.timestamp!="number"||!Number.isFinite(s.timestamp))throw new Error(`Operation ${i} \`timestamp\` must be a finite epoch-ms number when present.`);a.timestamp=s.timestamp}return a});return{version:G,createdAt:e.createdAt,window:{startDate:t.startDate,endDate:t.endDate},operations:n}}async function Yr(r,e){r.history.length=0,r.redoStack.length=0,await r.reload();const t={applied:0,failed:[]};for(let n=0;n<e.operations.length;n++){const o=e.operations[n];try{await r.dispatch(o.method,...o.args),r.history[r.history.length-1]?.status==="failed"?t.failed.push({index:n,method:o.method,error:"Operation handler reported failure (see console)."}):t.applied++}catch(i){t.failed.push({index:n,method:o.method,error:i instanceof Error?i.message:String(i)})}}return t}b.ApiKey=Dt,b.Collaborator=Ft,b.DEFAULT_SNACK_DURATION=ue,b.DataSource=Pt,b.Datastream=At,b.EnumEditOperations=v,b.EnumFilterOperations=A,b.FilterOperation=j,b.HydroShareArchive=_e,b.INCREASE_AMOUNT=x,b.Location=Te,b.LogicalOperation=Ae,b.OAuthProvider=Ct,b.ObservationRecord=Br,b.ObservedProperty=Rt,b.Operator=Le,b.Organization=Ot,b.Payload=Bt,b.PermissionAction=Re,b.PermissionResource=Ie,b.Position=He,b.PostHydroShareArchive=kt,b.ProcessingLevel=It,b.QC_SCRIPT_VERSION=G,b.ResultQualifier=Mt,b.Sensor=Tt,b.Snack=Xe,b.SnackColor=fe,b.SnackIcon=he,b.SnackTitle=de,b.Snackbar=rr,b.Thing=Lt,b.TimeUnit=I,b.Unit=_t,b.User=Ut,b.Workspace=Nt,b.applyScript=Yr,b.clearCalibration=Or,b.ensureCalibration=Ur,b.findFirstGreaterOrEqual=D,b.findLastLessOrEqual=N,b.formatDate=Yt,b.formatDuration=Gt,b.getCalibration=Rr,b.getLastBenchmarkDetail=Ir,b.getOperationTable=Mr,b.measureEllapsedTime=z,b.onCalibrationChange=Tr,b.parseScript=Wr,b.runBenchmarks=yt,b.serializeHistory=xr,b.shouldUseWorker=U,b.subtractHours=nr,b.timeUnitMultipliers=W,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|
|
15
|
+
`,mt=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",pt],{type:"text/javascript;charset=utf-8"});function mr(r){let e;try{if(e=mt&&(self.URL||self.webkitURL).createObjectURL(mt),!e)throw"";const t=new Worker(e,{name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(pt),{name:r?.name})}}function wt(r,e,t,n,o){const i=[],s=n.length;for(let a=e;a<t;a++){const c=r[a];let d=!1;for(let f=0;f<s;f++){const w=n[f],m=o[f];if(w===0){if(c<m){d=!0;break}}else if(w===1){if(c<=m){d=!0;break}}else if(w===2){if(c>m){d=!0;break}}else if(w===3){if(c>=m){d=!0;break}}else if(c==m){d=!0;break}}d&&i.push(a)}return i}function wr(r,e,t,n,o){const i=[];if(n==="Less than")for(let s=e;s<t;s++)r[s]-r[s-1]<o&&i.push(s);else if(n==="Less than or equal to")for(let s=e;s<t;s++)r[s]-r[s-1]<=o&&i.push(s);else if(n==="Greater than")for(let s=e;s<t;s++)r[s]-r[s-1]>o&&i.push(s);else if(n==="Greater than or equal to")for(let s=e;s<t;s++)r[s]-r[s-1]>=o&&i.push(s);else if(n==="Equal")for(let s=e;s<t;s++)r[s]-r[s-1]==o&&i.push(s);return i}function gr(r,e,t,n,o){const i=[];if(n==="Less than")for(let s=e;s<t;s++){const a=r[s-1];(r[s]-a)/Math.abs(a)<o&&i.push(s)}else if(n==="Less than or equal to")for(let s=e;s<t;s++){const a=r[s-1];(r[s]-a)/Math.abs(a)<=o&&i.push(s)}else if(n==="Greater than")for(let s=e;s<t;s++){const a=r[s-1];(r[s]-a)/Math.abs(a)>o&&i.push(s)}else if(n==="Greater than or equal to")for(let s=e;s<t;s++){const a=r[s-1];(r[s]-a)/Math.abs(a)>=o&&i.push(s)}else if(n==="Equal")for(let s=e;s<t;s++){const a=r[s-1];(r[s]-a)/Math.abs(a)==o&&i.push(s)}return i}function yr(r,e,t,n){const o=[];let i=r[e];for(let s=e+1;s<=t;s++){const a=r[s];a-i>n&&o.push(s-1,s),i=a}return o}function br(r,e,t){const n=[];if(e>=t)return n;let o=e,i=r[e];for(let s=e+1;s<t;s++){const a=r[s];a!==i&&(n.push(o,s-o,i),o=s,i=a)}return n.push(o,t-o,i),n}function Sr(r,e,t,n,o,i,s,a,c,d,f){let w=0,m=a;for(let p=i;p<=s;p++)if(n[m]=r[p],o[m]=e[p],m++,w<t.length&&p===t[w][0]){const y=t[w][0],l=t[w][1],u=r[y],g=r[l],h=e[y],S=e[l],E=g-u,A=S-h;let T=u+c;for(;T<g;)n[m]=T,o[m]=d?h+(T-u)*A/E:f,m++,T+=c;w++}return m-a}function Er(r,e,t,n,o,i,s,a){let c=i,d=0,f=a;const w=t.length;for(;c<s&&d<w;){const m=t[d][0];r[c]<=m?(n[f]=r[c],o[f]=e[c],c++):(n[f]=m,o[f]=t[d][1],d++),f++}for(;c<s;)n[f]=r[c],o[f]=e[c],c++,f++;for(;d<w;)n[f]=t[d][0],o[f]=t[d][1],d++,f++;return f-a}function vr(r,e,t,n,o,i,s,a){let c=0,d=a;for(let f=i;f<=s;f++)c<t.length&&f===t[c]?c++:(n[d]=r[f],o[d]=e[f],d++);return d-a}function kr(r,e,t,n){const o=t.length,i=new Array(o);if(n.isMonth)for(let s=0;s<o;s++){const a=t[s],c=new Date(r[a]);c.setMonth(c.getMonth()+n.amount),i[s]=[c.getTime(),e[a]]}else if(n.isYear)for(let s=0;s<o;s++){const a=t[s],c=new Date(r[a]);c.setFullYear(c.getFullYear()+n.amount),i[s]=[c.getTime(),e[a]]}else for(let s=0;s<o;s++){const a=t[s];i[s]=[r[a]+n.deltaMs,e[a]]}return i}function Ar(r,e,t){for(let n=0;n<t.length;n++){const{indexes:o,lowerIdx:i,upperIdx:s}=t[n],a=r[i],c=e[i],d=r[s],f=e[s],w=d-a,m=f-c;if(w===0){for(let p=0;p<o.length;p++)e[o[p]]=c;continue}for(let p=0;p<o.length;p++){const y=o[p];e[y]=c+(r[y]-a)*m/w}}}function Lr(r,e,t){for(let n=0;n<t.length;n++){const o=t[n][0],i=t[n][1],s=t[n][2];if(i<=o)continue;const a=r[o],c=r[i]-a;if(c!==0)for(let d=o;d<i;d++)e[d]=e[d]+s*((r[d]-a)/c)}}function gt(r,e,t,n){const o=e.length;if(t==="ADD")for(let i=0;i<o;i++)r[e[i]]=r[e[i]]+n;else if(t==="SUB")for(let i=0;i<o;i++)r[e[i]]=r[e[i]]-n;else if(t==="MULT")for(let i=0;i<o;i++)r[e[i]]=r[e[i]]*n;else if(t==="DIV")for(let i=0;i<o;i++)r[e[i]]=r[e[i]]/n;else if(t==="ASSIGN")for(let i=0;i<o;i++)r[e[i]]=n}const me="qc-utils:calibration:v1",Tr=720*60*60*1e3,J=5e4,Q=2e5,Z={spawnOverheadMs:50,inlineThroughput:5e4,workerThroughput:8e4,hwConcurrency:4,measuredAt:0,userAgent:"default"};let M=Dr()??Z,we=null,Y=null;const ge=new Set,ye={[L.VALUE_THRESHOLD]:{mode:"calibrated",weight:1,rationale:"O(n) single-pass scan; baseline reference"},[L.CHANGE]:{mode:"calibrated",weight:1.1,rationale:"O(n) with one subtraction per step"},[L.RATE_OF_CHANGE]:{mode:"calibrated",weight:1.4,rationale:"O(n) with division + abs per step"},[L.FIND_GAPS]:{mode:"calibrated",weight:.9,rationale:"O(n) on X only, mostly empty output"},[L.PERSISTENCE]:{mode:"calibrated",weight:1.3,rationale:"O(n) + chunk-boundary stitch"},[L.DATETIME_RANGE]:{mode:"always-inline",weight:0,rationale:"O(log n) binary search; never worth the worker hop"},[L.SELECTION]:{mode:"always-inline",weight:0,rationale:"Pure history bookkeeping"},[v.CHANGE_VALUES]:{mode:"calibrated",weight:.7,rationale:"O(k) in-place arithmetic on selection"},[v.ASSIGN_VALUES_BULK]:{mode:"always-inline",weight:0,rationale:"Single tight loop, already inline"},[v.ASSIGN_DATETIMES_BULK]:{mode:"always-inline",weight:0,rationale:"Composes delete+add which handle their own dispatch"},[v.INTERPOLATE]:{mode:"calibrated",weight:1.5,rationale:"Linear interp per consecutive group; in-place writes"},[v.DRIFT_CORRECTION]:{mode:"calibrated",weight:1.2,rationale:"O(range total) in-place math; one pass per range"},[v.SHIFT_DATETIMES]:{mode:"calibrated",weight:1.1,rationale:"O(k) per-point shift math; inline skips SAB allocation"},[v.ADD_POINTS]:{mode:"calibrated",weight:1.8,rationale:"Single merge pass over Y/X + insertions; fresh SAB per call"},[v.DELETE_POINTS]:{mode:"calibrated",weight:1.4,rationale:"Single skip-on-delete pass over Y/X; fresh SAB per call"},[v.FILL_GAPS]:{mode:"calibrated",weight:1.3,rationale:"Single copy-with-fills pass; fresh SAB sized to newLength"}};function U(r,e){const t=ye[r];if(!t)return{useWorker:!0,predictedInlineMs:1/0,predictedWorkerMs:0,reason:"unknown op; keeping default worker path"};if(t.mode==="always-inline")return{useWorker:!1,predictedInlineMs:0,predictedWorkerMs:0,reason:t.rationale};if(typeof SharedArrayBuffer>"u")return{useWorker:!1,predictedInlineMs:0,predictedWorkerMs:1/0,reason:"SharedArrayBuffer unavailable; forced inline"};if(t.mode==="always-worker")return{useWorker:!0,predictedInlineMs:1/0,predictedWorkerMs:0,reason:t.rationale};const n=_r(r,e);if(n<=0)return{useWorker:!1,predictedInlineMs:0,predictedWorkerMs:M.spawnOverheadMs,reason:"zero work units"};const o=Math.max(1,Math.min(e.parallelism??M.hwConcurrency,M.hwConcurrency)),i=t.weight*n/M.inlineThroughput,s=M.spawnOverheadMs+t.weight*n/(M.workerThroughput*o),a=i>s;return{useWorker:a,predictedInlineMs:i,predictedWorkerMs:s,reason:a?`worker faster (${s.toFixed(1)} vs ${i.toFixed(1)} ms)`:`inline faster (${i.toFixed(1)} vs ${s.toFixed(1)} ms)`}}function _r(r,e){switch(r){case v.CHANGE_VALUES:case v.INTERPOLATE:case v.SHIFT_DATETIMES:case v.DRIFT_CORRECTION:return e.selectionSize??0;case v.DELETE_POINTS:return(e.selectionSize??0)+e.datasetSize*.25;case v.ADD_POINTS:{const t=Math.max(1,Math.log2(Math.max(e.datasetSize,2)));return e.datasetSize+(e.selectionSize??0)*t}default:return e.datasetSize}}function Rr(r){return ge.add(r),()=>ge.delete(r)}function Ir(){return M}function Mr(){return we}function Or(){return Object.keys(ye).map(r=>({op:r,...ye[r]}))}function Ur(){M=Z,we=null;try{localStorage.removeItem(me)}catch{}}async function Cr(r={}){if(typeof window>"u"||!(r.force||M.measuredAt===0||Date.now()-M.measuredAt>Tr))return M;if(Y)await Y;else{Y=yt().finally(()=>{Y=null});const t=await Y;M=t,Nr(t),we=t;for(const n of ge)n(M)}return M}async function yt(){if(!(typeof SharedArrayBuffer<"u"))return{...Z,measuredAt:Date.now(),userAgent:navigator.userAgent,hwConcurrency:navigator.hardwareConcurrency||Z.hwConcurrency,sharedArrayBufferAvailable:!1,samples:{spawnRoundtripMs:[],inlineScanMs:[],workerScanMs:[]}};const e=navigator.hardwareConcurrency||4,t=new Float32Array(J);for(let l=0;l<J;l++)t[l]=Math.sin(l);const n=await be(3,()=>{const l=performance.now();return wt(t,0,J,[2],[.5]),performance.now()-l}),o=Se(n),i=J/Math.max(o,.001),s=new SharedArrayBuffer(256*Float32Array.BYTES_PER_ELEMENT),a=await be(3,async()=>{const l=performance.now();return await new Promise(u=>{const g=new pe;g.onmessage=()=>{g.terminate(),u()},g.postMessage({bufferY:s,start:0,end:256,ops:[2],values:[.5]})}),performance.now()-l}),c=Se(a),d=new SharedArrayBuffer(Q*Float32Array.BYTES_PER_ELEMENT),f=new Float32Array(d);for(let l=0;l<Q;l++)f[l]=Math.sin(l);const w=await be(3,async()=>{const l=performance.now();return await new Promise(u=>{const g=new pe;g.onmessage=()=>{g.terminate(),u()},g.postMessage({bufferY:d,start:0,end:Q,ops:[2],values:[.5]})}),performance.now()-l}),m=Math.max(Se(w)-c,.1),p=Q/m;return{spawnOverheadMs:c,inlineThroughput:i,workerThroughput:p,hwConcurrency:e,measuredAt:Date.now(),userAgent:navigator.userAgent,sharedArrayBufferAvailable:!0,samples:{spawnRoundtripMs:a,inlineScanMs:n,workerScanMs:w}}}async function be(r,e){const t=[];for(let n=0;n<r;n++)await new Promise(o=>setTimeout(o,0)),t.push(await e());return t}function Se(r){if(!r.length)return 0;const e=[...r].sort((n,o)=>n-o),t=Math.floor(e.length/2);return e.length%2?e[t]:(e[t-1]+e[t])/2}function Dr(){if(typeof localStorage>"u")return null;try{const r=localStorage.getItem(me);if(!r)return null;const e=JSON.parse(r);return!e||typeof e.spawnOverheadMs!="number"?null:e}catch{return null}}function Nr(r){if(!(typeof localStorage>"u"))try{const e={spawnOverheadMs:r.spawnOverheadMs,inlineThroughput:r.inlineThroughput,workerThroughput:r.workerThroughput,hwConcurrency:r.hwConcurrency,measuredAt:r.measuredAt,userAgent:r.userAgent};localStorage.setItem(me,JSON.stringify(e))}catch{}}const x=20*1e3,Fr=typeof SharedArrayBuffer<"u";function O(r,e){return Fr?e!==void 0?new SharedArrayBuffer(r,{maxByteLength:e}):new SharedArrayBuffer(r):e!==void 0?new ArrayBuffer(r,{maxByteLength:e}):new ArrayBuffer(r)}function bt(r,e){const t=r;typeof t.grow=="function"?t.grow(e):typeof t.resize=="function"&&t.resize(e)}function Pr(r,e){if(r.length!==e.length)return!1;for(let t=0;t<r.length;t++)if(r[t]!==e[t])return!1;return!0}function St(r,e){switch(r){case v.ADD_POINTS:case v.FILL_GAPS:return!1;default:return!0}}class Br{dataset={source:{x:new Float64Array(O(x*Float64Array.BYTES_PER_ELEMENT,x*Float64Array.BYTES_PER_ELEMENT)),y:new Float32Array(O(x*Float32Array.BYTES_PER_ELEMENT,x*Float32Array.BYTES_PER_ELEMENT))}};history=[];redoStack=[];_isReplaying=!1;_pendingExecutionMode="inline";loadingTime=null;isLoading=!0;rawData;constructor(e){this.history=[],this.rawData=e,this.loadData(this.rawData)}async loadData(e){if(!e)return;this.isLoading=!0;const t=await X(()=>{this._growBuffer(e.datetimes.length),this._resizeTo(e.datetimes.length),this.dataX.set(e.datetimes),this.dataY.set(e.dataValues)});this.loadingTime=t.duration,this.history.length=0,this.isLoading=!1}get dataX(){return this.dataset.source.x}get dataY(){return this.dataset.source.y}_resizeTo(e){this.dataset.source.x=new Float64Array(this.dataset.source.x.buffer).subarray(0,e),this.dataset.source.y=new Float32Array(this.dataset.source.y.buffer).subarray(0,e)}_growBuffer(e){const t=e*Float64Array.BYTES_PER_ELEMENT;let n=this.dataX.buffer.byteLength;for(;t>n;)n+=x*Float64Array.BYTES_PER_ELEMENT;if(n*Float64Array.BYTES_PER_ELEMENT>this.dataX.buffer.maxByteLength){const o=O(this.dataX.buffer.byteLength,n*Float64Array.BYTES_PER_ELEMENT),i=O(this.dataY.buffer.byteLength,n*Float32Array.BYTES_PER_ELEMENT),s=new Float64Array(o),a=new Float32Array(i);s.set(this.dataX),a.set(this.dataY),this.dataset.source.x=s,this.dataset.source.y=a}this.dataX.buffer.byteLength<e*Float64Array.BYTES_PER_ELEMENT&&(bt(this.dataX.buffer,e*Float64Array.BYTES_PER_ELEMENT),bt(this.dataY.buffer,e*Float32Array.BYTES_PER_ELEMENT))}async reload(){this.loadingTime=null,this.isLoading=!0,this.history.length=0,await this.loadData(this.rawData)}async reloadHistory(e){const t=this.history.slice(0,e+1);return this.redoStack.length=0,await this.reload(),await this.dispatch(t.map(n=>[n.method,...n.args||[]]))}async removeHistoryItem(e){const t=[...this.history];return t.splice(e,1),this.redoStack.length=0,await this.reload(),await this.dispatch(t.map(n=>[n.method,...n.args||[]]))}async undo(){if(!this.history.length)return[];const e=this.history[this.history.length-1],t=this.history.slice(0,-1);await this.reload(),this.redoStack.push(e),this._isReplaying=!0;try{return await this.dispatch(t.map(n=>[n.method,...n.args||[]]))}finally{this._isReplaying=!1}}async redo(){if(!this.redoStack.length)return[];const e=this.redoStack.pop();this._isReplaying=!0;try{return await this.dispatch([[e.method,...e.args||[]]])}finally{this._isReplaying=!1}}get beginTime(){return this.dataset.source.x.length?new Date(this.dataset.source.x[0]):null}get endTime(){return this.dataset.source.x.length?new Date(this.dataset.source.x[this.dataset.source.x.length-1]):null}async dispatchAction(e,...t){const n={[v.ADD_POINTS]:this._addDataPoints,[v.CHANGE_VALUES]:this._changeValues,[v.ASSIGN_VALUES_BULK]:this._assignValuesBulk,[v.DELETE_POINTS]:this._deleteDataPointsFromSelection,[v.DRIFT_CORRECTION]:this._driftCorrectionFromSelection,[v.INTERPOLATE]:this._interpolateFromSelection,[v.SHIFT_DATETIMES]:this._shiftFromSelection,[v.ASSIGN_DATETIMES_BULK]:this._assignDatetimesBulk,[v.FILL_GAPS]:this._fillGaps};let o=[],i=null;try{this._isReplaying||(this.redoStack.length=0);const s=St(e,t)&&this.history[this.history.length-1]?.method===L.SELECTION?this.history[this.history.length-1].selected?.length:void 0;i={method:e,args:t,execution:{startedAt:Date.now(),inFlight:!0,datasetSize:this.dataset.source.x?.length??0,selectionSize:s}},this.history.push(i),St(e,t)||this.history[this.history.length-2]?.method===L.SELECTION&&this.history.splice(this.history.length-2,1),this._pendingExecutionMode="inline";const a=await X(async()=>await n[e].apply(this,t));o=a.response;const c=this.history.indexOf(i),d=c>=0?this.history[c]:void 0;d&&(d.execution={...d.execution,status:"success",durationMs:a.duration,mode:this._pendingExecutionMode,inFlight:!1})}catch{if(i){const a=this.history.indexOf(i),c=a>=0?this.history[a]:void 0;c&&(c.execution={...c.execution,status:"failed",inFlight:!1})}}return o}async dispatch(e,...t){const n=async(o,i)=>L[o]?await this.dispatchFilter(o,...i):await this.dispatchAction(o,...i);if(Array.isArray(e)){let o=[];for(let i=0;i<e.length;i++){const s=e[i][0],a=e[i].slice(1,e[i].length);o=await n(s,a)}return o}else return await n(e,t)}async dispatchFilter(e,...t){const n={[L.FIND_GAPS]:this._findGaps,[L.VALUE_THRESHOLD]:this._valueThreshold,[L.DATETIME_RANGE]:this._datetimeRange,[L.PERSISTENCE]:this._persistence,[L.CHANGE]:this._change,[L.RATE_OF_CHANGE]:this._rateOfChange,[L.SELECTION]:this._selection};let o=[],i=null;try{const s=e===L.SELECTION,a=s&&(!t[0]||Array.isArray(t[0])&&t[0].length===0);!this._isReplaying&&!a&&(this.redoStack.length=0),i={method:e,args:t,execution:{startedAt:Date.now(),inFlight:!0,datasetSize:this.dataset.source.x?.length??0}};const c=this.history[this.history.length-1],d=!!L[c?.method],f=c?.method===e||d&&!s;let w;f?(w=this.history.length-1,this.history[w]=i):(this.history.push(i),w=this.history.length-1),this._pendingExecutionMode="inline";const m=await X(async()=>await n[e].apply(this,t));o=m.response;const p=this.history.indexOf(i),y=p>=0?this.history[p]:void 0;y&&(y.selected=m.response,y.execution={...y.execution,status:"success",durationMs:m.duration,mode:this._pendingExecutionMode,selectionSize:m.response?.length,inFlight:!1})}catch(s){if(console.log(`Failed to execute filter operation: ${e} with arguments: `,t),console.log(s),i){const a=this.history.indexOf(i),c=a>=0?this.history[a]:void 0;c&&(c.execution={...c.execution,status:"failed",inFlight:!1})}}return o}async _changeValues(e,t){const n=this.history[this.history.length-2]?.selected;if(!n||n.length===0)return[];const o=n.length;if(!U(v.CHANGE_VALUES,{datasetSize:this.dataset.source.y.length,selectionSize:o}).useWorker)return gt(this.dataY,n,e,t),[];this._pendingExecutionMode="worker";const s=Math.min(navigator.hardwareConcurrency||1,o),a=Math.ceil(o/s),c=[],d=[];for(let f=0;f<s;f++){const w=f*a,m=Math.min((f+1)*a,o);if(w>=m)break;const p=n.slice(w,m);d.push(new Promise(y=>{const l=new mr;c.push(l),l.postMessage({bufferY:this.dataY.buffer,indexes:p,operator:e,value:t}),l.onmessage=u=>{y(u.data)}}))}return await Promise.all(d),c.forEach(f=>f.terminate()),[]}_applyOperatorInPlace(e,t,n){gt(this.dataY,e,t,n)}async _assignValuesBulk(e){const t=this.history[this.history.length-2]?.selected;if(!t||!t.length||!e?.length)return[];const n=Math.min(t.length,e.length),o=this.dataY;for(let i=0;i<n;i++)o[t[i]]=e[i];return[]}async _assignDatetimesBulk(e){const t=this.history[this.history.length-2]?.selected;if(!t||!t.length||!e?.length)return[];const n=Math.min(t.length,e.length),o=new Array(n),i=new Array(n);for(let s=0;s<n;s++)o[s]=[e[s],this.dataY[t[s]]],i[s]=t[s];return i.sort((s,a)=>s-a),await this._deleteDataPoints(i),await this._addDataPoints(o),[]}async _interpolateFromSelection(){const e=this.history[this.history.length-2]?.selected;if(!(!e||e.length===0))return this._interpolate(e)}async _interpolate(e){const t=this._getConsecutiveGroups(e);if(t.length===0||t[0].length===0)return;const n=this.dataset.source.y.length,o=t.map(f=>({indexes:f,lowerIdx:Math.max(0,f[0]-1),upperIdx:Math.min(n-1,f[f.length-1]+1)}));if(!U(v.INTERPOLATE,{datasetSize:n,selectionSize:e.length}).useWorker){Ar(this.dataX,this.dataY,o);return}this._pendingExecutionMode="worker";const s=Math.min(navigator.hardwareConcurrency||1,o.length),a=Math.ceil(o.length/s),c=[],d=[];for(let f=0;f<s;f++){const w=o.slice(f*a,(f+1)*a);if(w.length===0)break;d.push(new Promise(m=>{const p=new ar;c.push(p),p.postMessage({bufferX:this.dataX.buffer,bufferY:this.dataY.buffer,groups:w}),p.onmessage=y=>{m(y.data)}}))}await Promise.all(d),c.forEach(f=>f.terminate())}async _shiftFromSelection(e,t){const n=this.history[this.history.length-2]?.selected;return!n||n.length===0?[]:await this._shift(n,e,t)??[]}async _shift(e,t,n){if(e.length===0)return[];const o=n===I.MONTH,i=n===I.YEAR,s=!o&&!i?t*W[n]*1e3:0,a=e.length;if(!U(v.SHIFT_DATETIMES,{datasetSize:this.dataset.source.x.length,selectionSize:a}).useWorker){const h=kr(this.dataX,this.dataY,e,{amount:t,isMonth:o,isYear:i,deltaMs:s});return await this._deleteDataPoints(e),await this._addDataPoints(h)??[]}this._pendingExecutionMode="worker";const d=O(a*Float64Array.BYTES_PER_ELEMENT),f=O(a*Float32Array.BYTES_PER_ELEMENT),w=Math.min(navigator.hardwareConcurrency||1,a),m=Math.ceil(a/w),p=[],y=[];for(let h=0;h<w;h++){const S=h*m,E=Math.min((h+1)*m,a);if(S>=E)break;const A=e.slice(S,E);y.push(new Promise(T=>{const _=new ur;p.push(_),_.postMessage({bufferX:this.dataX.buffer,bufferY:this.dataY.buffer,outputBufferX:d,outputBufferY:f,indexes:A,outStart:S,amount:t,isMonth:o,isYear:i,deltaMs:s}),_.onmessage=R=>{T(R.data)}}))}await Promise.all(y),p.forEach(h=>h.terminate());const l=new Float64Array(d),u=new Float32Array(f),g=new Array(a);for(let h=0;h<a;h++)g[h]=[l[h],u[h]];return await this._deleteDataPoints(e),await this._addDataPoints(g)??[]}async _fillGaps(e,t,n,o,i){const s=this.dataX.length;if(s===0)return[];const a=e[0]*W[e[1]]*1e3,c=t[0]*W[t[1]]*1e3,d=this.dataX,f=i?.[0]!=null&&Number.isFinite(i[0])?D(d,i[0]):0,w=i?.[1]!=null&&Number.isFinite(i[1])?N(d,i[1]):s-1,m=[],p=[];let y=0;for(let k=f+1;k<=w;k++)if(d[k]-d[k-1]>a){let C=0,F=d[k-1]+c;for(;F<d[k];)C++,F+=c;C>0&&(m.push([k-1,k]),p.push(C),y+=C)}if(y===0)return[];const l=new Array(y);let u=0,g=0;for(let k=0;k<m.length;k++){const P=m[k][0],C=p[k];for(let F=1;F<=C;F++)l[g++]=P+u+F;u+=C}const h=s+y,S=h*Float64Array.BYTES_PER_ELEMENT,E=h*Float32Array.BYTES_PER_ELEMENT,A=O(S,Math.max(this.dataX.buffer.maxByteLength,S)),T=O(E,Math.max(this.dataY.buffer.maxByteLength,E));if(!U(v.FILL_GAPS,{datasetSize:s,selectionSize:y}).useWorker){const k=new Float64Array(A),P=new Float32Array(T);return Sr(this.dataX,this.dataY,m,k,P,0,s-1,0,c,n,o),this.dataset.source.x=k,this.dataset.source.y=P,this._resizeTo(h),l}this._pendingExecutionMode="worker";const R=navigator.hardwareConcurrency||1,Et=Math.ceil(s/R),Ee=[];let z=0;for(let k=0;k<R;k++){const P=k*Et,C=Math.min((k+1)*Et-1,s-1),F=[];let ee=0;for(;z<m.length&&m[z][0]<=C;)F.push(m[z]),ee+=p[z],z++;Ee.push({start:P,end:C,gapsSegment:F,fillsInSegment:ee})}const ve=new Array(R).fill(0);for(let k=1;k<R;k++)ve[k]=ve[k-1]+Ee[k-1].fillsInSegment;const vt=[],kt=[];for(let k=0;k<R;k++){const{start:P,end:C,gapsSegment:F}=Ee[k],ee=P+ve[k];kt.push(new Promise(Hr=>{const ke=new ir;vt.push(ke),ke.postMessage({bufferX:this.dataX.buffer,bufferY:this.dataY.buffer,outputBufferX:A,outputBufferY:T,start:P,end:C,gapsSegment:F,startTarget:ee,fillDelta:c,interpolate:n,fillValue:o}),ke.onmessage=Xr=>{Hr(Xr.data)}}))}return await Promise.all(kt),vt.forEach(k=>k.terminate()),this.dataset.source.x=new Float64Array(A),this.dataset.source.y=new Float32Array(T),this._resizeTo(h),l}async _deleteDataPointsFromSelection(){const e=this.history[this.history.length-2]?.selected;if(!(!e||e.length===0))return this._deleteDataPoints(e)}async _deleteDataPoints(e){const t=this.dataX.length,n=t-e.length;if(!U(v.DELETE_POINTS,{datasetSize:t,selectionSize:e.length}).useWorker){const p=O(this.dataX.buffer.byteLength,this.dataX.buffer.maxByteLength),y=O(this.dataY.buffer.byteLength,this.dataY.buffer.maxByteLength),l=new Float64Array(p),u=new Float32Array(y);vr(this.dataX,this.dataY,e,l,u,0,t-1,0),this.dataset.source.x=l,this.dataset.source.y=u,this._resizeTo(n);return}this._pendingExecutionMode="worker";const i=navigator.hardwareConcurrency||1,s=Math.ceil(this.dataX.length/i),a=[],c=[];for(let p=0;p<i;p++){const y=p*s,l=Math.min((p+1)*s-1,this.dataX.length-1),u=D(e,y),g=N(e,l),h=e.slice(u,g+1);c.push({start:y,end:l,deleteSegment:h})}const d=new Array(i).fill(0);for(let p=1;p<i;p++)d[p]=d[p-1]+c[p-1].deleteSegment.length;const f=[],w=O(this.dataX.buffer.byteLength,this.dataX.buffer.maxByteLength),m=O(this.dataY.buffer.byteLength,this.dataY.buffer.maxByteLength);for(let p=0;p<i;p++){const{start:y,end:l,deleteSegment:u}=c[p],g=y-d[p];f.push(new Promise(h=>{const S=new or;a.push(S),S.postMessage({bufferX:this.dataX.buffer,bufferY:this.dataY.buffer,outputBufferX:w,outputBufferY:m,start:y,end:l,deleteSegment:u,startTarget:g}),S.onmessage=E=>{h(E.data)}}))}await Promise.all(f),a.forEach(p=>p.terminate()),this.dataset.source.x=new Float64Array(w),this.dataset.source.y=new Float32Array(m),this._resizeTo(n)}async _driftCorrectionFromSelection(e){const t=this.history[this.history.length-2]?.selected;if(!t||t.length===0)return;const n=this._getConsecutiveGroups(t),o=[];for(const i of n)i.length!==0&&o.push([i[0],i[i.length-1],e]);if(o.length!==0)return this._driftCorrection(o)}async _driftCorrection(e){if(!e||e.length===0)return;const t=this.dataset.source.x,n=navigator.hardwareConcurrency||1;let o=0;for(const[w,m]of e)m>w&&(o+=m-w);if(!U(v.DRIFT_CORRECTION,{datasetSize:t.length,selectionSize:o}).useWorker){Lr(t,this.dataY,e);return}this._pendingExecutionMode="worker";const s=[];for(const[w,m,p]of e){if(m<=w)continue;const y=t[w],l=t[m]-y;if(l===0)continue;const u=m-w,g=Math.max(1,Math.ceil(u/n));for(let h=w;h<m;h+=g)s.push({chunkStart:h,chunkEnd:Math.min(h+g,m),startDatetime:y,value:p,extent:l})}if(s.length===0)return;const a=Math.min(n,s.length),c=Array.from({length:a},()=>[]);s.forEach((w,m)=>c[m%a].push(w));const d=[],f=[];for(const w of c)w.length!==0&&f.push(new Promise(m=>{const p=new cr;d.push(p),p.postMessage({bufferX:this.dataX.buffer,bufferY:this.dataY.buffer,jobs:w}),p.onmessage=y=>{m(y.data)}}));await Promise.all(f),d.forEach(w=>w.terminate())}_getConsecutiveGroups(e){const t=[[]];return e.reduce((n,o)=>{const i=n[n.length-1];return!i.length||o==i[i.length-1]+1?i.push(o):n.push([o]),n},t),t}async _addDataPoints(e){if(e.length===0)return[];const t=this.dataX.length,n=t+e.length;e.sort((l,u)=>l[0]-u[0]);const o=new Array(e.length);for(let l=0;l<e.length;l++){const u=e[l][0],g=N(this.dataX,u)+1;o[l]=g+l}const i=n*Float64Array.BYTES_PER_ELEMENT,s=n*Float32Array.BYTES_PER_ELEMENT,a=O(i,Math.max(this.dataX.buffer.maxByteLength,i)),c=O(s,Math.max(this.dataY.buffer.maxByteLength,s));if(!U(v.ADD_POINTS,{datasetSize:t,selectionSize:e.length}).useWorker){const l=new Float64Array(a),u=new Float32Array(c);return Er(this.dataX,this.dataY,e,l,u,0,t,0),this.dataset.source.x=l,this.dataset.source.y=u,this._resizeTo(n),o}this._pendingExecutionMode="worker";const f=e.map(l=>N(this.dataX,l[0])+1),w=Math.max(1,Math.min(navigator.hardwareConcurrency||1,Math.max(t,1))),m=Math.ceil(Math.max(t,1)/w),p=[],y=[];for(let l=0;l<w;l++){const u=l*m,g=Math.min((l+1)*m,t),h=D(f,u),S=l===w-1?e.length:D(f,g),E=e.slice(h,S),A=u+h;u>=g&&E.length===0||y.push(new Promise(T=>{const _=new lr;p.push(_),_.postMessage({bufferX:this.dataX.buffer,bufferY:this.dataY.buffer,outputBufferX:a,outputBufferY:c,origStart:u,origEnd:g,insertions:E,outStart:A}),_.onmessage=R=>{T(R.data)}}))}return await Promise.all(y),p.forEach(l=>l.terminate()),this.dataset.source.x=new Float64Array(a),this.dataset.source.y=new Float32Array(c),this._resizeTo(n),o}async _valueThreshold(e,t){const n=Object.keys(e);if(n.length===0)return[];const o={[j.LT]:0,[j.LTE]:1,[j.GT]:2,[j.GTE]:3,[j.E]:4},i=n.map(S=>o[S]??4),s=n.map(S=>e[S]),a=this.dataset.source.y,c=this.dataset.source.x;let d=0,f=a.length;if(f===0)return[];if(t!=null){const[S,E]=t;S!=null&&Number.isFinite(S)&&(d=D(c,S)),E!=null&&Number.isFinite(E)&&(f=N(c,E)+1)}if(f<=d)return[];const w=f-d;if(!U(L.VALUE_THRESHOLD,{datasetSize:w}).useWorker)return wt(a,d,f,i,s);this._pendingExecutionMode="worker";const p=Math.min(navigator.hardwareConcurrency||1,w),y=Math.ceil(w/p),l=[],u=[];for(let S=0;S<p;S++){const E=d+S*y,A=Math.min(d+(S+1)*y,f);if(E>=A)break;u.push(new Promise(T=>{const _=new pe;l.push(_),_.postMessage({bufferY:this.dataY.buffer,start:E,end:A,ops:i,values:s}),_.onmessage=R=>{T(R.data)}}))}const g=await Promise.all(u);l.forEach(S=>S.terminate());const h=[];for(let S=0;S<g.length;S++){const E=g[S];for(let A=0;A<E.length;A++)h.push(E[A])}return h}async _rateOfChange(e,t,n){const o=this.dataset.source.y,i=this.dataset.source.x;if(o.length<2)return[];let s=1,a=o.length;if(n!=null){const[u,g]=n;u!=null&&Number.isFinite(u)&&(s=Math.max(1,D(i,u))),g!=null&&Number.isFinite(g)&&(a=N(i,g)+1)}if(a<=s)return[];const c=a-s;if(!U(L.RATE_OF_CHANGE,{datasetSize:o.length}).useWorker)return gr(o,s,a,e,t);this._pendingExecutionMode="worker";const f=Math.min(navigator.hardwareConcurrency||1,c),w=Math.ceil(c/f),m=[],p=[];for(let u=0;u<f;u++){const g=s+u*w,h=Math.min(s+(u+1)*w,a);if(g>=h)break;p.push(new Promise(S=>{const E=new pr;m.push(E),E.postMessage({bufferY:this.dataY.buffer,start:g,end:h,comparator:e,value:t}),E.onmessage=A=>{S(A.data)}}))}const y=await Promise.all(p);m.forEach(u=>u.terminate());const l=[];for(let u=0;u<y.length;u++){const g=y[u];for(let h=0;h<g.length;h++)l.push(g[h])}return l}async _datetimeRange(e,t){const n=this.dataset.source.x,o=n.length;if(o===0)return[];const i=e==null?0:D(n,e),s=t==null?o-1:N(n,t);if(i>s)return[];const a=new Array(s-i+1);for(let c=i;c<=s;c++)a[c-i]=c;return a}async _selection(e){const t=this.history[this.history.length-2],n=!!t&&t.method!==L.SELECTION&&!!L[t.method],o=n&&Array.isArray(t.selected)?t.selected:void 0;return!e||!e.length?(this.history.pop(),o&&o.length>0&&this.history.pop(),e):(o&&Pr(o,e)?this.history.pop():n&&this.history.splice(this.history.length-2,1),e)}async _change(e,t,n){const o=this.dataset.source.y,i=this.dataset.source.x;if(o.length<2)return[];let s=1,a=o.length;if(n!=null){const[u,g]=n;u!=null&&Number.isFinite(u)&&(s=Math.max(1,D(i,u))),g!=null&&Number.isFinite(g)&&(a=N(i,g)+1)}if(a<=s)return[];const c=a-s;if(!U(L.CHANGE,{datasetSize:o.length}).useWorker)return wr(o,s,a,e,t);this._pendingExecutionMode="worker";const f=Math.min(navigator.hardwareConcurrency||1,c),w=Math.ceil(c/f),m=[],p=[];for(let u=0;u<f;u++){const g=s+u*w,h=Math.min(s+(u+1)*w,a);if(g>=h)break;p.push(new Promise(S=>{const E=new dr;m.push(E),E.postMessage({bufferY:this.dataY.buffer,start:g,end:h,comparator:e,value:t}),E.onmessage=A=>{S(A.data)}}))}const y=await Promise.all(p);m.forEach(u=>u.terminate());const l=[];for(let u=0;u<y.length;u++){const g=y[u];for(let h=0;h<g.length;h++)l.push(g[h])}return l}async _findGaps(e,t,n){const o=this.dataset.source.x;let i=0,s=o.length;if(n!=null){const[u,g]=n;u!=null&&Number.isFinite(u)&&(i=D(o,u)),g!=null&&Number.isFinite(g)&&(s=N(o,g)+1)}if(s<=i)return[];const a=e*W[t]*1e3;if(!U(L.FIND_GAPS,{datasetSize:s-i}).useWorker){const u=yr(o,i,s-1,a),g=new Set;for(let h=0;h<u.length;h++)g.add(u[h]);return[...g]}this._pendingExecutionMode="worker";const d=s-i,f=Math.min(navigator.hardwareConcurrency||1,d),w=Math.ceil(d/f),m=[],p=[];for(let u=0;u<f;u++){const g=i+u*w,h=Math.min(i+(u+1)*w,s);if(g>=h)break;p.push(new Promise(S=>{const E=new fr;m.push(E),E.postMessage({bufferX:this.dataX.buffer,start:g,endInclusive:h,threshold:a}),E.onmessage=A=>{S(A.data)}}))}const y=await Promise.all(p);m.forEach(u=>u.terminate());const l=new Set;for(let u=0;u<y.length;u++){const g=y[u];for(let h=0;h<g.length;h++)l.add(g[h])}return[...l]}async _persistence(e,t){const n=this.dataset.source.x,o=this.dataset.source.y;let i=0,s=o.length;if(t!=null){const[h,S]=t;h!=null&&Number.isFinite(h)&&(i=D(n,h)),S!=null&&Number.isFinite(S)&&(s=N(n,S)+1)}if(s<=i)return[];const a=s-i;if(!U(L.PERSISTENCE,{datasetSize:a}).useWorker){const h=br(o,i,s),S=[];for(let E=0;E<h.length;E+=3){const A=h[E],T=h[E+1];if(T>=e)for(let _=0;_<T;_++)S.push(A+_)}return S}this._pendingExecutionMode="worker";const d=Math.min(navigator.hardwareConcurrency||1,a),f=Math.ceil(a/d),w=[],m=[];for(let h=0;h<d;h++){const S=i+h*f,E=Math.min(i+(h+1)*f,s);if(S>=E)break;m.push(new Promise(A=>{const T=new hr;w.push(T),T.postMessage({bufferY:this.dataY.buffer,start:S,end:E}),T.onmessage=_=>{A(_.data)}}))}const p=await Promise.all(m);w.forEach(h=>h.terminate());const y=[],l=[],u=[];for(let h=0;h<p.length;h++){const S=p[h];for(let E=0;E<S.length;E+=3){const A=S[E],T=S[E+1],_=S[E+2],R=y.length-1;R>=0&&u[R]===_&&y[R]+l[R]===A?l[R]+=T:(y.push(A),l.push(T),u.push(_))}}const g=[];for(let h=0;h<y.length;h++){const S=l[h];if(S>=e){const E=y[h];for(let A=0;A<S;A++)g.push(E+A)}}return g}}const G="1",jr=new Set([...Object.values(v),...Object.values(L)]);function xr(r){if(!r)return;const e={},t=a=>typeof a=="number"&&Number.isFinite(a)?a:void 0,n=t(r.startedAt);n!==void 0&&(e.startedAt=n),(r.status==="success"||r.status==="failed")&&(e.status=r.status);const o=t(r.durationMs);o!==void 0&&(e.durationMs=o),(r.mode==="worker"||r.mode==="inline")&&(e.mode=r.mode);const i=t(r.datasetSize);i!==void 0&&(e.datasetSize=i);const s=t(r.selectionSize);return s!==void 0&&(e.selectionSize=s),Object.keys(e).length===0?void 0:e}function Wr(r,e){if(r===void 0)return;if(!r||typeof r!="object")throw new Error(`Operation ${e} \`execution\` must be an object when present.`);const t=r,n={},o=(i,s)=>{if(typeof s!="number"||!Number.isFinite(s))throw new Error(`Operation ${e} \`execution.${i}\` must be a finite number when present.`)};if(t.startedAt!==void 0&&(o("startedAt",t.startedAt),n.startedAt=t.startedAt),t.status!==void 0){if(t.status!=="success"&&t.status!=="failed")throw new Error(`Operation ${e} \`execution.status\` must be "success" or "failed" when present.`);n.status=t.status}if(t.durationMs!==void 0&&(o("durationMs",t.durationMs),n.durationMs=t.durationMs),t.mode!==void 0){if(t.mode!=="worker"&&t.mode!=="inline")throw new Error(`Operation ${e} \`execution.mode\` must be "worker" or "inline" when present.`);n.mode=t.mode}return t.datasetSize!==void 0&&(o("datasetSize",t.datasetSize),n.datasetSize=t.datasetSize),t.selectionSize!==void 0&&(o("selectionSize",t.selectionSize),n.selectionSize=t.selectionSize),n}function Yr(r,e){const t=r.history.map(n=>{const o={method:n.method,args:n.args?[...n.args]:[]},i=xr(n.execution);return i&&(o.execution=i),o});return{version:G,createdAt:new Date().toISOString(),window:{startDate:e.startDate,endDate:e.endDate},operations:t}}function Gr(r){if(!r||typeof r!="object")throw new Error("QC script must be a JSON object.");const e=r;if(e.version!==G)throw new Error(`Unsupported QC script version: ${String(e.version)}. This loader understands version "${G}".`);if(typeof e.createdAt!="string")throw new Error("QC script is missing `createdAt` (ISO-8601 string).");const t=e.window;if(!t||typeof t!="object")throw new Error("QC script is missing `window`.");if(typeof t.startDate!="string"||typeof t.endDate!="string")throw new Error("`window.startDate` and `window.endDate` must be ISO-8601 strings.");if(!Array.isArray(e.operations))throw new Error("QC script `operations` must be an array.");const n=e.operations.map((o,i)=>{if(!o||typeof o!="object")throw new Error(`Operation ${i} must be an object.`);const s=o;if(typeof s.method!="string")throw new Error(`Operation ${i} missing string \`method\`.`);if(!jr.has(s.method))throw new Error(`Operation ${i} has unknown method: "${s.method}".`);if(!Array.isArray(s.args))throw new Error(`Operation ${i} \`args\` must be an array.`);const a={method:s.method,args:[...s.args]},c=Wr(s.execution,i);return c&&(a.execution=c),a});return{version:G,createdAt:e.createdAt,window:{startDate:t.startDate,endDate:t.endDate},operations:n}}async function zr(r,e){r.history.length=0,r.redoStack.length=0,await r.reload();const t={applied:0,failed:[]};for(let n=0;n<e.operations.length;n++){const o=e.operations[n];try{await r.dispatch(o.method,...o.args),r.history[r.history.length-1]?.execution.status==="failed"?t.failed.push({index:n,method:o.method,error:"Operation handler reported failure (see console)."}):t.applied++}catch(i){t.failed.push({index:n,method:o.method,error:i instanceof Error?i.message:String(i)})}}return t}b.ApiKey=Nt,b.Collaborator=Pt,b.DEFAULT_SNACK_DURATION=ue,b.DataSource=Bt,b.Datastream=Tt,b.EnumEditOperations=v,b.EnumFilterOperations=L,b.FilterOperation=j,b.HydroShareArchive=Te,b.INCREASE_AMOUNT=x,b.Location=_e,b.LogicalOperation=Le,b.OAuthProvider=Dt,b.ObservationRecord=Br,b.ObservedProperty=It,b.Operator=Ae,b.Organization=Ut,b.Payload=jt,b.PermissionAction=Re,b.PermissionResource=Ie,b.Position=ze,b.PostHydroShareArchive=At,b.ProcessingLevel=Mt,b.QC_SCRIPT_VERSION=G,b.ResultQualifier=Ot,b.Sensor=Rt,b.Snack=He,b.SnackColor=fe,b.SnackIcon=he,b.SnackTitle=de,b.Snackbar=nr,b.Thing=Lt,b.TimeUnit=I,b.Unit=_t,b.User=Ct,b.Workspace=Ft,b.applyScript=zr,b.clearCalibration=Ur,b.ensureCalibration=Cr,b.findFirstGreaterOrEqual=D,b.findLastLessOrEqual=N,b.formatDate=Gt,b.formatDuration=zt,b.getCalibration=Ir,b.getLastBenchmarkDetail=Mr,b.getOperationTable=Or,b.measureEllapsedTime=X,b.onCalibrationChange=Rr,b.parseScript=Gr,b.runBenchmarks=yt,b.serializeHistory=Yr,b.shouldUseWorker=U,b.subtractHours=sr,b.timeUnitMultipliers=W,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/types/index.d.ts
CHANGED
|
@@ -64,33 +64,82 @@ export declare enum LogicalOperation {
|
|
|
64
64
|
GTE = "Greater than or equal to",
|
|
65
65
|
E = "Equal"
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Per-dispatch runtime information attached to every `HistoryItem`.
|
|
69
|
+
*
|
|
70
|
+
* Populated in two phases by `ObservationRecord.dispatchAction` /
|
|
71
|
+
* `dispatchFilter`:
|
|
72
|
+
*
|
|
73
|
+
* - **Push time**: `startedAt`, `inFlight: true`, `datasetSize`,
|
|
74
|
+
* and (for selection-consuming edits) `selectionSize` are set
|
|
75
|
+
* before the handler runs.
|
|
76
|
+
* - **Resolve time**: `status`, `durationMs`, `mode`, and (for
|
|
77
|
+
* filters) `selectionSize` are set when the handler returns or
|
|
78
|
+
* throws.
|
|
79
|
+
*
|
|
80
|
+
* The qc-app reads this object to drive the EditHistory UI
|
|
81
|
+
* (per-row spinner via `inFlight`, failure badge via `status`,
|
|
82
|
+
* duration text via `durationMs`, dev-only worker/inline chip via
|
|
83
|
+
* `mode`). Replays from `undo()` / `redo()` / `applyScript` build
|
|
84
|
+
* a fresh execution record for the new run rather than re-stamping
|
|
85
|
+
* the saved one.
|
|
86
|
+
*/
|
|
87
|
+
export interface HistoryExecution {
|
|
88
|
+
/**
|
|
89
|
+
* Wall-clock epoch-milliseconds (UTC) when the dispatch site pushed
|
|
90
|
+
* this entry. Re-stamped on every replay so the in-memory value
|
|
91
|
+
* always reflects the current session's execution. `serializeHistory`
|
|
92
|
+
* persists it for audit; the script loader does not restore it.
|
|
93
|
+
*/
|
|
94
|
+
startedAt: number;
|
|
95
|
+
/**
|
|
96
|
+
* True from the moment the dispatch pushed the entry until the
|
|
97
|
+
* handler resolves (success or failure). Drives per-row spinners
|
|
98
|
+
* in the qc-app.
|
|
99
|
+
*/
|
|
100
|
+
inFlight: boolean;
|
|
101
|
+
/** Final outcome — `undefined` while `inFlight` is `true`. */
|
|
102
|
+
status?: "success" | "failed";
|
|
103
|
+
/**
|
|
104
|
+
* Wall-clock duration in milliseconds. Set after the handler
|
|
105
|
+
* resolves. `undefined` while `inFlight`.
|
|
106
|
+
*/
|
|
107
|
+
durationMs?: number;
|
|
108
|
+
/**
|
|
109
|
+
* Whether the op actually ran on a web worker or inline on the
|
|
110
|
+
* main thread. Populated based on the calibration decision and
|
|
111
|
+
* any always-inline / always-worker handler behaviour. Mainly
|
|
112
|
+
* useful in dev for verifying that the calibration layer is
|
|
113
|
+
* routing as expected.
|
|
114
|
+
*/
|
|
115
|
+
mode?: "worker" | "inline";
|
|
116
|
+
/**
|
|
117
|
+
* Number of observations in the record at the time the op ran,
|
|
118
|
+
* captured at push time. Reflects the pre-edit shape — i.e.
|
|
119
|
+
* exactly what the handler saw on entry. Useful for retrospective
|
|
120
|
+
* perf inspection: "this op took 300ms because the record had
|
|
121
|
+
* 500k points."
|
|
122
|
+
*/
|
|
123
|
+
datasetSize?: number;
|
|
124
|
+
/**
|
|
125
|
+
* Number of indices the op acted on. For filters this is the
|
|
126
|
+
* size of the resulting selection (populated at resolve time);
|
|
127
|
+
* for selection-consuming edits it's the size of the preceding
|
|
128
|
+
* SELECTION (populated at push time). `undefined` when not
|
|
129
|
+
* applicable (e.g. ADD_POINTS, which is datetime-addressed).
|
|
130
|
+
*/
|
|
131
|
+
selectionSize?: number;
|
|
132
|
+
}
|
|
67
133
|
export type HistoryItem = {
|
|
68
134
|
method: EnumEditOperations | EnumFilterOperations;
|
|
69
|
-
isLoading: boolean;
|
|
70
135
|
args?: any[];
|
|
71
|
-
duration?: number;
|
|
72
136
|
selected?: number[];
|
|
73
|
-
status?: "success" | "failed";
|
|
74
|
-
/**
|
|
75
|
-
* Whether the operation actually ran on a web worker or inline on
|
|
76
|
-
* the main thread. Populated by the `ObservationRecord` dispatch
|
|
77
|
-
* site based on the calibration decision and any always-inline /
|
|
78
|
-
* always-worker handler behaviour. Mainly useful in dev for
|
|
79
|
-
* verifying that the calibration layer is routing as expected —
|
|
80
|
-
* the qc-app surfaces a small badge per history entry when
|
|
81
|
-
* `import.meta.env.DEV` is truthy.
|
|
82
|
-
*/
|
|
83
|
-
executionMode?: "worker" | "inline";
|
|
84
137
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* `dispatchFilter`, so re-dispatches from `undo()` / `redo()` /
|
|
89
|
-
* `applyScript` overwrite an older value with the replay time.
|
|
90
|
-
* Optional because the field is runtime-only: it is stripped on
|
|
91
|
-
* `serializeHistory` and re-stamped when the loader replays.
|
|
138
|
+
* Per-dispatch runtime information. Always present; some fields
|
|
139
|
+
* populate at push time, others fill in after the handler resolves.
|
|
140
|
+
* See `HistoryExecution` for the two-phase population rules.
|
|
92
141
|
*/
|
|
93
|
-
|
|
142
|
+
execution: HistoryExecution;
|
|
94
143
|
};
|
|
95
144
|
/** The wall-clock window the script was authored against. The
|
|
96
145
|
* loader is responsible for fetching this exact range of
|
|
@@ -101,27 +150,36 @@ export type QcScriptWindow = {
|
|
|
101
150
|
startDate: string;
|
|
102
151
|
endDate: string;
|
|
103
152
|
};
|
|
153
|
+
/**
|
|
154
|
+
* The execution record persisted alongside a saved script operation.
|
|
155
|
+
* Mirrors `HistoryExecution` minus the runtime-only `inFlight` flag,
|
|
156
|
+
* since a serialized op is always "resolved" by definition. Every
|
|
157
|
+
* field is optional so pre-v1.1 scripts (and any consumer that
|
|
158
|
+
* hand-writes the JSON) still load.
|
|
159
|
+
*
|
|
160
|
+
* Replays do **not** restore these values onto the new
|
|
161
|
+
* `HistoryItem.execution`; the dispatch site stamps fresh runtime
|
|
162
|
+
* data for the current session. Persistence is for audit only:
|
|
163
|
+
* "this op originally ran inline on a 50k record in 240ms."
|
|
164
|
+
*/
|
|
165
|
+
export type QcScriptExecution = {
|
|
166
|
+
startedAt?: number;
|
|
167
|
+
status?: "success" | "failed";
|
|
168
|
+
durationMs?: number;
|
|
169
|
+
mode?: "worker" | "inline";
|
|
170
|
+
datasetSize?: number;
|
|
171
|
+
selectionSize?: number;
|
|
172
|
+
};
|
|
104
173
|
/** A single replayable operation entry. Mirrors the
|
|
105
174
|
* `[method, ...args]` tuple shape that
|
|
106
|
-
* `ObservationRecord.dispatch` accepts. `
|
|
107
|
-
*
|
|
108
|
-
*
|
|
175
|
+
* `ObservationRecord.dispatch` accepts. `execution` carries
|
|
176
|
+
* per-dispatch audit data (timing, mode, dataset shape) round-
|
|
177
|
+
* tripped verbatim so the saved script preserves the authoring
|
|
178
|
+
* context for review. */
|
|
109
179
|
export type QcScriptOperation = {
|
|
110
180
|
method: EnumEditOperations | EnumFilterOperations;
|
|
111
181
|
args: any[];
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Wall-clock epoch-milliseconds (UTC) at which the operation was
|
|
115
|
-
* originally dispatched — round-tripped verbatim so the saved
|
|
116
|
-
* script preserves the authoring timeline for audit / display.
|
|
117
|
-
* Optional because pre-v1.1 scripts (and any consumer that hand-
|
|
118
|
-
* writes the JSON without timestamps) must still load. The replay
|
|
119
|
-
* path does NOT use this value to re-stamp `HistoryItem.timestamp`:
|
|
120
|
-
* `dispatchAction` / `dispatchFilter` stamp fresh `Date.now()` at
|
|
121
|
-
* replay time so the in-memory history reflects when the operation
|
|
122
|
-
* actually ran in this session.
|
|
123
|
-
*/
|
|
124
|
-
timestamp?: number;
|
|
182
|
+
execution?: QcScriptExecution;
|
|
125
183
|
};
|
|
126
184
|
/** A serialized QC history. Schema `version: "1"`. */
|
|
127
185
|
export type QcScript = {
|
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
* See `docs/HISTORY_SCRIPT.md` for the full design rationale. The
|
|
5
5
|
* short version:
|
|
6
6
|
*
|
|
7
|
-
* - **Save:** walk `record.history`,
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* `
|
|
13
|
-
*
|
|
7
|
+
* - **Save:** walk `record.history`, keep `method` and `args`,
|
|
8
|
+
* project the live `HistoryExecution` into a `QcScriptExecution`
|
|
9
|
+
* (drop `inFlight` since a serialized entry is always
|
|
10
|
+
* resolved; keep the rest — `startedAt`, `status`, `durationMs`,
|
|
11
|
+
* `mode`, `datasetSize`, `selectionSize`). The runtime-only
|
|
12
|
+
* `selected` array is recomputed on replay and not persisted.
|
|
13
|
+
* Wrap with a `version`, `createdAt`, and the wall-clock
|
|
14
|
+
* `window` the consumer was working in.
|
|
14
15
|
*
|
|
15
16
|
* - **Load:** reset `history` + `redoStack`, `record.reload()`,
|
|
16
17
|
* then `record.dispatch(operations.map(o => [o.method, ...o.args]))`.
|