@xyo-network/diviner-forecasting-memory 2.110.18 → 2.111.0

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.
Files changed (32) hide show
  1. package/dist/browser/MemoryForecastingDiviner.d.cts +1 -1
  2. package/dist/browser/MemoryForecastingDiviner.d.cts.map +1 -1
  3. package/dist/browser/MemoryForecastingDiviner.d.mts +1 -1
  4. package/dist/browser/MemoryForecastingDiviner.d.mts.map +1 -1
  5. package/dist/browser/MemoryForecastingDiviner.d.ts +1 -1
  6. package/dist/browser/MemoryForecastingDiviner.d.ts.map +1 -1
  7. package/dist/browser/index.cjs.map +1 -1
  8. package/dist/browser/{index.js → index.mjs} +1 -1
  9. package/dist/browser/index.mjs.map +1 -0
  10. package/dist/neutral/MemoryForecastingDiviner.d.cts +1 -1
  11. package/dist/neutral/MemoryForecastingDiviner.d.cts.map +1 -1
  12. package/dist/neutral/MemoryForecastingDiviner.d.mts +1 -1
  13. package/dist/neutral/MemoryForecastingDiviner.d.mts.map +1 -1
  14. package/dist/neutral/MemoryForecastingDiviner.d.ts +1 -1
  15. package/dist/neutral/MemoryForecastingDiviner.d.ts.map +1 -1
  16. package/dist/neutral/index.cjs.map +1 -1
  17. package/dist/neutral/{index.js → index.mjs} +1 -1
  18. package/dist/neutral/index.mjs.map +1 -0
  19. package/dist/node/MemoryForecastingDiviner.d.cts +1 -1
  20. package/dist/node/MemoryForecastingDiviner.d.cts.map +1 -1
  21. package/dist/node/MemoryForecastingDiviner.d.mts +1 -1
  22. package/dist/node/MemoryForecastingDiviner.d.mts.map +1 -1
  23. package/dist/node/MemoryForecastingDiviner.d.ts +1 -1
  24. package/dist/node/MemoryForecastingDiviner.d.ts.map +1 -1
  25. package/dist/node/index.cjs.map +1 -1
  26. package/dist/node/{index.js → index.mjs} +1 -1
  27. package/dist/node/index.mjs.map +1 -0
  28. package/package.json +16 -16
  29. package/src/MemoryForecastingDiviner.ts +7 -5
  30. package/dist/browser/index.js.map +0 -1
  31. package/dist/neutral/index.js.map +0 -1
  32. package/dist/node/index.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
- import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
2
+ import type { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
4
  import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryForecastingDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryForecastingDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AAChH,OAAO,EAEL,oBAAoB,EAEpB,4BAA4B,EAC7B,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAkC,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAEnI,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAG5D,MAAM,MAAM,wBAAwB,GAAG,OAAO,oBAAoB,GAAG,OAAO,4BAA4B,CAAA;AAaxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC,OAAO,CAAC;IAC3C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA2D;IAC3G,gBAAyB,mBAAmB,EAAE,MAAM,CAAiC;IAErF,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAGnG;IAED,IAAI,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA6ChH"}
@@ -1,5 +1,5 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
- import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
2
+ import type { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
4
  import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryForecastingDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryForecastingDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AAChH,OAAO,EAEL,oBAAoB,EAEpB,4BAA4B,EAC7B,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAkC,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAEnI,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAG5D,MAAM,MAAM,wBAAwB,GAAG,OAAO,oBAAoB,GAAG,OAAO,4BAA4B,CAAA;AAaxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC,OAAO,CAAC;IAC3C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA2D;IAC3G,gBAAyB,mBAAmB,EAAE,MAAM,CAAiC;IAErF,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC,wBAAwB,EAAE,iBAAiB,CA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I,iBAAiB,CAK5D;IAED,SAAS,KAAK,iBAAiB,WAE9B;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA6ChH"}
@@ -1,5 +1,5 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
- import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
2
+ import type { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
4
  import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryForecastingDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryForecastingDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AAChH,OAAO,EAEL,oBAAoB,EAEpB,4BAA4B,EAC7B,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAkC,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAEnI,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAG5D,MAAM,MAAM,wBAAwB,GAAG,OAAO,oBAAoB,GAAG,OAAO,4BAA4B,CAAA;AAaxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC,OAAO,CAAC;IAC3C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA2D;IAC3G,gBAAyB,mBAAmB,EAAE,MAAM,CAAiC;IAErF,SAAS,CAAC,MAAM,CAA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;;;qEAEtB;IAKD,SAAS,KAAK,UAAU,WAEvB;IAED,cAAuB,iBAAiB,IAAI,iBAAiB,CAK5D;IAED,SAAS,KAAK,iBAAiB,WAE9B;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA6ChH"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AACzB,oBAAuB;AACvB,6BAAoC;AAEpC,wCAA2G;AAC3G,0CAAqE;AACrE,8CAKO;AACP,uCAA2F;AAC3F,2BAAmD;AAEnD,sBAAqB;AAIrB,IAAMA,yBAAyB,wBAACC,mBAAAA;AAC9B,SAAO,CAACC,MAAAA;AACN,UAAMC,MAAMC,gBAAAA,QAASC,MAAMH,GAAGD,cAAAA;AAC9B,QAAI,OAAOE,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB;AACF,GAN+B;AAQ/B,IAAMC,oBAAoB;AAC1B,IAAMC,2BAA2B;AAE1B,IAAMC,2BAAN,MAAMA,kCAEHC,+DAAAA;EAhCV,OAgCUA;;;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;AACvD,YAAMsB,QAAyC;QAAEhB;QAAWY;QAAOV;QAAiBe,QAAQC;QAAgCL;MAAU;AACtI,YAAMM,kBAAkB,MAAMX,UAAUY,OAAO;QAACJ;OAAM,GAAGK,OACvD,CAACC,OAAOA,GAAGT,aAAaS,GAAGT,aAAaf,kBAAkBwB,GAAGT,aAAad,aAAAA;AAE5E,UAAIoB,eAAeJ,WAAW,EAAG;AAGjCF,kBAAYM,eACTI,IAAI,CAACD,OAAOA,GAAGT,SAAS,EACxBQ,OAAOG,oBAAAA,EAEPC,OAAO,CAACC,GAAGC,MAAMC,KAAKC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC,iBAAkB;AAG3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAI,CAACD,OAAOA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,oBAAAA;AAG/G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,oBAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;","names":["getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport type {\n arimaForecastingName,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport {\n arimaForecastingMethod,\n seasonalArimaForecastingMethod,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n bw => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map(bw => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map(bw => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AACzB,oBAAuB;AACvB,6BAAoC;AAEpC,wCAA2G;AAC3G,0CAAqE;AAKrE,8CAGO;AACP,uCAA2F;AAC3F,2BAAmD;AAEnD,sBAAqB;AAIrB,IAAMA,yBAAyB,wBAACC,mBAAAA;AAC9B,SAAO,CAACC,MAAAA;AACN,UAAMC,MAAMC,gBAAAA,QAASC,MAAMH,GAAGD,cAAAA;AAC9B,QAAI,OAAOE,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB;AACF,GAN+B;AAQ/B,IAAMC,oBAAoB;AAC1B,IAAMC,2BAA2B;AAE1B,IAAMC,2BAAN,MAAMA,kCAEHC,+DAAAA;EAlCV,OAkCUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,OAA0BE,wBAA6E;IACrGC,kBAAkBC;IAClBC,0BAA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J;OAAM,GAAGK,OACvDC,CAAAA,OAAMA,GAAGT,aAAaS,GAAGT,aAAaf,kBAAkBwB,GAAGT,aAAad,aAAAA;AAE1E,UAAIoB,eAAeJ,WAAW,EAAG;AAGjCF,kBAAYM,eACTI,IAAID,CAAAA,OAAMA,GAAGT,SAAS,EACtBQ,OAAOG,oBAAAA,EAEPC,OAAO,CAACC,GAAGC,MAAMC,KAAKC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC,iBAAkB;AAG3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAID,CAAAA,OAAMA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,oBAAAA;AAG7G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,oBAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;","names":["getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push"]}
@@ -94,4 +94,4 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractF
94
94
  export {
95
95
  MemoryForecastingDiviner
96
96
  };
97
- //# sourceMappingURL=index.js.map
97
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport type {\n arimaForecastingName,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport {\n arimaForecastingMethod,\n seasonalArimaForecastingMethod,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n bw => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map(bw => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map(bw => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,2BAA2B;AAEpC,SAAqEC,sCAAsC;AAC3G,SAASC,kCAA4D;AAKrE,SACEC,wBACAC,sCACK;AACP,SAASC,sCAAkF;AAC3F,SAASC,yBAA0C;AAEnD,OAAOC,cAAc;AAIrB,IAAMC,yBAAyB,wBAACC,mBAAAA;AAC9B,SAAO,CAACC,MAAAA;AACN,UAAMC,MAAMC,SAASC,MAAMH,GAAGD,cAAAA;AAC9B,QAAI,OAAOE,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB;AACF,GAN+B;AAQ/B,IAAMC,oBAAoB;AAC1B,IAAMC,2BAA2B;AAE1B,IAAMC,2BAAN,MAAMA,kCAEHC,2BAAAA;EAlCV,OAkCUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,OAA0BE,wBAA6E;IACrGC,k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Y,OAAO;QAACJ;OAAM,GAAGK,OACvDC,CAAAA,OAAMA,GAAGT,aAAaS,GAAGT,aAAaf,kBAAkBwB,GAAGT,aAAad,aAAAA;AAE1E,UAAIoB,eAAeJ,WAAW,EAAG;AAGjCF,kBAAYM,eACTI,IAAID,CAAAA,OAAMA,GAAGT,SAAS,EACtBQ,OAAOG,MAAAA,EAEPC,OAAO,CAACC,GAAGC,MAAMC,KAAKC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC,iBAAkB;AAG3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAID,CAAAA,OAAMA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,MAAAA;AAG7G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,MAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push"]}
@@ -1,5 +1,5 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
- import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
2
+ import type { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
4
  import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryForecastingDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryForecastingDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AAChH,OAAO,EAEL,oBAAoB,EAEpB,4BAA4B,EAC7B,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAkC,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAEnI,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAG5D,MAAM,MAAM,wBAAwB,GAAG,OAAO,oBAAoB,GAAG,OAAO,4BAA4B,CAAA;AAaxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC,OAAO,CAAC;IAC3C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA2D;IAC3G,gBAAyB,mBAAmB,EAAE,MAAM,CAAiC;IAErF,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC,wBAAwB,EAAE,i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AAiB,IAAI,iBAAiB,CAK5D;IAED,SAAS,KAAK,iBAAiB,WAE9B;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA6ChH"}
@@ -1,5 +1,5 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
- import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
2
+ import type { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
4
  import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryForecastingDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryForecastingDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AAChH,OAAO,EAEL,oBAAoB,EAEpB,4BAA4B,EAC7B,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAkC,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAEnI,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAG5D,MAAM,MAAM,wBAAwB,GAAG,OAAO,oBAAoB,GAAG,OAAO,4BAA4B,CAAA;AAaxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC,OAAO,CAAC;IAC3C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA2D;IAC3G,gBAAyB,mBAAmB,EAAE,MAAM,CAAiC;IAErF,SAAS,CAAC,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;;;;;;;;;;;qEAEtB;IAKD,SAAS,KAAK,UAAU,WAEvB;IAED,cAAuB,iBAAiB,IAAI,iBAAiB,CAK5D;IAED,SAAS,KAAK,iBAAiB,WAE9B;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA6ChH"}
@@ -1,5 +1,5 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
- import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
2
+ import type { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
4
  import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryForecastingDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryForecastingDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AAChH,OAAO,EAEL,oBAAoB,EAEpB,4BAA4B,EAC7B,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAkC,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAEnI,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAG5D,MAAM,MAAM,wBAAwB,GAAG,OAAO,oBAAoB,GAAG,OAAO,4BAA4B,CAAA;AAaxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC,OAAO,CAAC;IAC3C,gBAAyB,aAAa,EAAE,MAAM,EAAE,C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GnG;IAED,IAAI,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qEAEtB;IAKD,SAAS,KAAK,UAAU,WAEvB;IAED,cAAuB,iBAAiB,IAAI,iBAAiB,CAK5D;IAED,SAAS,KAAK,iBAAiB,WAE9B;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA6ChH"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AACzB,oBAAuB;AACvB,6BAAoC;AAEpC,wCAA2G;AAC3G,0CAAqE;AACrE,8CAKO;AACP,uCAA2F;AAC3F,2BAAmD;AAEnD,sBAAqB;AAIrB,IAAMA,yBAAyB,wBAACC,mBAAAA;AAC9B,SAAO,CAACC,MAAAA;AACN,UAAMC,MAAMC,gBAAAA,QAASC,MAAMH,GAAGD,cAAAA;AAC9B,QAAI,OAAOE,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB;AACF,GAN+B;AAQ/B,IAAMC,oBAAoB;AAC1B,IA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U,YAAYd;AAChB,QAAIe,OAAO;AAIX,WAAOA,QAAQV,SAASW,SAAS,KAAKrB,mBAAmB;AACvD,YAAMsB,QAAyC;QAAEhB;QAAWY;QAAOV;QAAiBe,QAAQC;QAAgCL;MAAU;AACtI,YAAMM,kBAAkB,MAAMX,UAAUY,OAAO;QAACJ;OAAM,GAAGK,OACvD,CAACC,OAAOA,GAAGT,aAAaS,GAAGT,aAAaf,kBAAkBwB,GAAGT,aAAad,aAAAA;AAE5E,UAAIoB,eAAeJ,WAAW,EAAG;AAGjCF,kBAAYM,eACTI,IAAI,CAACD,OAAOA,GAAGT,SAAS,EACxBQ,OAAOG,oBAAAA,EAEPC,OAAO,CAACC,GAAGC,MAAMC,KAAKC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC,iBAAkB;AAG3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAI,CAACD,OAAOA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,oBAAAA;AAG/G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,oBAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;","names":["getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport type {\n arimaForecastingName,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport {\n arimaForecastingMethod,\n seasonalArimaForecastingMethod,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n bw => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map(bw => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map(bw => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AACzB,oBAAuB;AACvB,6BAAoC;AAEpC,wCAA2G;AAC3G,0CAAqE;AAKrE,8CAGO;AACP,uCAA2F;AAC3F,2BAAmD;AAEnD,sBAAqB;AAIrB,IAAMA,yBAAyB,wBAACC,mBAAAA;AAC9B,SAAO,CAACC,MAAAA;AACN,UAAMC,MAAMC,gBAAAA,QAASC,MAAMH,GAAGD,cAAAA;AAC9B,QAAI,OAAOE,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB;AACF,GAN+B;AAQ/B,IAAMC,oBAAoB;AAC1B,IAAMC,2BAA2B;AAE1B,IAAMC,2BAAN,MAAMA,kCAEHC,+DAAAA;EAlCV,OAkCUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;E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;QAAiBe,QAAQC;QAAgCL;MAAU;AACtI,YAAMM,kBAAkB,MAAMX,UAAUY,OAAO;QAACJ;OAAM,GAAGK,OACvDC,CAAAA,OAAMA,GAAGT,aAAaS,GAAGT,aAAaf,kBAAkBwB,GAAGT,aAAad,aAAAA;AAE1E,UAAIoB,eAAeJ,WAAW,EAAG;AAGjCF,kBAAYM,eACTI,IAAID,CAAAA,OAAMA,GAAGT,SAAS,EACtBQ,OAAOG,oBAAAA,EAEPC,OAAO,CAACC,GAAGC,MAAMC,KAAKC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC,iBAAkB;AAG3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAID,CAAAA,OAAMA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,oBAAAA;AAG7G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,oBAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;","names":["getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push"]}
@@ -94,4 +94,4 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractF
94
94
  export {
95
95
  MemoryForecastingDiviner
96
96
  };
97
- //# sourceMappingURL=index.js.map
97
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport type {\n arimaForecastingName,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport {\n arimaForecastingMethod,\n seasonalArimaForecastingMethod,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n bw => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map(bw => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map(bw => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,2BAA2B;AAEpC,SAAqEC,sCAAsC;AAC3G,SAASC,kCAA4D;AAKrE,SACEC,wBACAC,sCACK;AACP,SAASC,sCAAkF;AAC3F,SAASC,yBAA0C;AAEnD,OAAOC,cAAc;AAIrB,IAAMC,yBAAyB,wBAACC,mBAAAA;AAC9B,SAAO,CAACC,MAAAA;AACN,UAAMC,MAAMC,SAASC,MAAMH,GAAGD,cAAAA;AAC9B,QAAI,OAAOE,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB;AACF,GAN+B;AAQ/B,IAAMC,oBAAoB;AAC1B,IAAMC,2BAA2B;AAE1B,IAAMC,2BAAN,MAAMA,kCAEHC,2BAAAA;EAlCV,OAkCUA;;;EACR,OAAyBC,gBAA0B;OA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AAWY;QAAOV;QAAiBe,QAAQC;QAAgCL;MAAU;AACtI,YAAMM,kBAAkB,MAAMX,UAAUY,OAAO;QAACJ;OAAM,GAAGK,OACvDC,CAAAA,OAAMA,GAAGT,aAAaS,GAAGT,aAAaf,kBAAkBwB,GAAGT,aAAad,aAAAA;AAE1E,UAAIoB,eAAeJ,WAAW,EAAG;AAGjCF,kBAAYM,eACTI,IAAID,CAAAA,OAAMA,GAAGT,SAAS,EACtBQ,OAAOG,MAAAA,EAEPC,OAAO,CAACC,GAAGC,MAAMC,KAAKC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC,iBAAkB;AAG3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAID,CAAAA,OAAMA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,MAAAA;AAG7G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,MAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push"]}
@@ -1,5 +1,5 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
- import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
2
+ import type { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
4
  import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryForecastingDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryForecastingDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AAChH,OAAO,EAEL,oBAAoB,EAEpB,4BAA4B,EAC7B,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAkC,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAEnI,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAG5D,MAAM,MAAM,wBAAwB,GAAG,OAAO,oBAAoB,GAAG,OAAO,4BAA4B,CAAA;AAaxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC,OAAO,CAAC;IAC3C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA2D;IAC3G,gBAAyB,mBAAmB,EAAE,MAAM,CAAiC;IAErF,SA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;;;;;;;;;;;;;;;;;;;qEAEtB;IAKD,SAAS,KAAK,UAAU,WAEvB;IAED,cAAuB,iBAAiB,IAAI,iBAAiB,CAK5D;IAED,SAAS,KAAK,iBAAiB,WAE9B;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA6ChH"}
@@ -1,5 +1,5 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
- import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
2
+ import type { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
4
  import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryForecastingDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryForecastingDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AAChH,OAAO,EAEL,oBAAoB,EAEpB,4BAA4B,EAC7B,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAkC,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAEnI,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAG5D,MAAM,MAAM,wBAAwB,GAAG,OAAO,oBAAoB,GAAG,OAAO,4BAA4B,CAAA;AAaxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC,OAAO,CAAC;IAC3C,gBAAyB,aAAa,EAAE,MAA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,CAAC,CAGnG;IAED,IAAI,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qEAEtB;IAKD,SAAS,KAAK,UAAU,WAEvB;IAED,cAAuB,iBAAiB,IAAI,iBAAiB,CAK5D;IAED,SAAS,KAAK,iBAAiB,WAE9B;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA6ChH"}
@@ -1,5 +1,5 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
- import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
2
+ import type { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
4
  import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryForecastingDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryForecastingDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AAChH,OAAO,EAEL,oBAAoB,EAEpB,4BAA4B,EAC7B,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAkC,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAEnI,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAG5D,MAAM,MAAM,wBAAwB,GAAG,OAAO,oBAAoB,GAAG,OAAO,4BAA4B,CAAA;AAaxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACn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CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAGnG;IAED,IAAI,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qEAEtB;IAKD,SAAS,KAAK,UAAU,WAEvB;IAED,cAAuB,iBAAiB,IAAI,iBAAiB,CAK5D;IAED,SAAS,KAAK,iBAAiB,WAE9B;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA6ChH"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AACzB,oBAAuB;AACvB,6BAAoC;AAEpC,wCAA2G;AAC3G,0CAAqE;AACrE,8CAKO;AACP,uCAA2F;AAC3F,2BAAmD;AAEnD,sBAAqB;AAIrB,IAAMA,yBAAyB,wBAACC,mBAAAA;AAC9B,SAAO,CAACC,MAAAA;AACN,UAAMC,MAAMC,gBAAAA,QAASC,MAAMH,GAAGD,cAAAA;AAC9B,QAAI,OAAOE,QAAQ,SAAU,QAAOA;AAC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;AACvD,YAAMsB,QAAyC;QAAEhB;QAAWY;QAAOV;QAAiBe,QAAQC;QAAgCL;MAAU;AACtI,YAAMM,kBAAkB,MAAMX,UAAUY,OAAO;QAACJ;OAAM,GAAGK,OACvD,CAACC,OAAOA,GAAGT,aAAaS,GAAGT,aAAaf,kBAAkBwB,GAAGT,aAAad,aAAAA;AAE5E,UAAIoB,eAAeJ,WAAW,EAAG;AAGjCF,kBAAYM,eACTI,IAAI,CAACD,OAAOA,GAAGT,SAAS,EACxBQ,OAAOG,oBAAAA,EAEPC,OAAO,CAACC,GAAGC,MAAMC,KAAKC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC,iBAAkB;AAG3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAI,CAACD,OAAOA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,oBAAAA;AAG/G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,oBAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;AAjFUlB;AACR,cAHWD,2BAGcqD,iBAA0B;KAAI,iEAAMA;EAAeC;;AAC5E,cAJWtD,2BAIcuD,uBAA8BD;AAEvD,cANWtD,2BAMeQ,yBAA6E;EACrGgD,kBAAkBC;EAClBC,0BAA0BC;AAC5B;AATK,IAAM3D,2BAAN;","names":["getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","forecastingMethodDict","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport type {\n arimaForecastingName,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport {\n arimaForecastingMethod,\n seasonalArimaForecastingMethod,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n bw => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map(bw => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map(bw => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AACzB,oBAAuB;AACvB,6BAAoC;AAEpC,wCAA2G;AAC3G,0CAAqE;AAKrE,8CAGO;AACP,uCAA2F;AAC3F,2BAAmD;AAEnD,sBAAqB;AAIrB,IAAMA,yBAAyB,wBAACC,mBAAAA;AAC9B,SAAO,CAACC,MAAAA;AACN,UAAMC,MAAMC,gBAAAA,QAASC,MAAMH,GAAGD,cAAAA;AAC9B,QAAI,OAAOE,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB;AACF,GAN+B;AAQ/B,IAAMC,oBAAoB;AAC1B,IAA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AAMM,kBAAkB,MAAMX,UAAUY,OAAO;QAACJ;OAAM,GAAGK,OACvDC,CAAAA,OAAMA,GAAGT,aAAaS,GAAGT,aAAaf,kBAAkBwB,GAAGT,aAAad,aAAAA;AAE1E,UAAIoB,eAAeJ,WAAW,EAAG;AAGjCF,kBAAYM,eACTI,IAAID,CAAAA,OAAMA,GAAGT,SAAS,EACtBQ,OAAOG,oBAAAA,EAEPC,OAAO,CAACC,GAAGC,MAAMC,KAAKC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC,iBAAkB;AAG3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAID,CAAAA,OAAMA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,oBAAAA;AAG7G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,oBAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;AAjFUlB;AACR,cAHWD,2BAGcqD,iBAA0B;KAAI,iEAAMA;EAAeC;;AAC5E,cAJWtD,2BAIcuD,uBAA8BD;AAEvD,cANWtD,2BAMeQ,yBAA6E;EACrGgD,kBAAkBC;EAClBC,0BAA0BC;AAC5B;AATK,IAAM3D,2BAAN;","names":["getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","forecastingMethodDict","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod"]}
@@ -98,4 +98,4 @@ var MemoryForecastingDiviner = _MemoryForecastingDiviner;
98
98
  export {
99
99
  MemoryForecastingDiviner
100
100
  };
101
- //# sourceMappingURL=index.js.map
101
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport type {\n arimaForecastingName,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport {\n arimaForecastingMethod,\n seasonalArimaForecastingMethod,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n bw => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map(bw => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map(bw => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,2BAA2B;AAEpC,SAAqEC,sCAAsC;AAC3G,SAASC,kCAA4D;AAKrE,SACEC,wBACAC,sCACK;AACP,SAASC,sCAAkF;AAC3F,SAASC,yBAA0C;AAEnD,OAAOC,cAAc;AAIrB,IAAMC,yBAAyB,wBAACC,mBAAAA;AAC9B,SAAO,CAACC,MAAAA;AACN,UAAMC,MAAMC,SAASC,MAAMH,GAAGD,cAAAA;AAC9B,QAAI,OAAOE,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;E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AAOV;QAAiBe,QAAQC;QAAgCL;MAAU;AACtI,YAAMM,kBAAkB,MAAMX,UAAUY,OAAO;QAACJ;OAAM,GAAGK,OACvDC,CAAAA,OAAMA,GAAGT,aAAaS,GAAGT,aAAaf,kBAAkBwB,GAAGT,aAAad,aAAAA;AAE1E,UAAIoB,eAAeJ,WAAW,EAAG;AAGjCF,kBAAYM,eACTI,IAAID,CAAAA,OAAMA,GAAGT,SAAS,EACtBQ,OAAOG,MAAAA,EAEPC,OAAO,CAACC,GAAGC,MAAMC,KAAKC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC,iBAAkB;AAG3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAID,CAAAA,OAAMA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,MAAAA;AAG7G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,MAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;AAjFUlB;AACR,cAHWD,2BAGcqD,iBAA0B;KAAI,iEAAMA;EAAeC;;AAC5E,cAJWtD,2BAIcuD,uBAA8BD;AAEvD,cANWtD,2BAMeQ,yBAA6E;EACrGgD,kBAAkBC;EAClBC,0BAA0BC;AAC5B;AATK,IAAM3D,2BAAN;","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","forecastingMethodDict","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod"]}
package/package.json CHANGED
@@ -10,22 +10,22 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xylabs/assert": "^3.6.6",
14
- "@xylabs/exists": "^3.6.6",
15
- "@xyo-network/archivist-model": "^2.110.18",
16
- "@xyo-network/boundwitness-model": "^2.110.18",
17
- "@xyo-network/diviner-boundwitness-model": "^2.110.18",
18
- "@xyo-network/diviner-forecasting-abstract": "^2.110.18",
19
- "@xyo-network/diviner-forecasting-method-arima": "^2.110.18",
20
- "@xyo-network/diviner-forecasting-model": "^2.110.18",
21
- "@xyo-network/diviner-model": "^2.110.18",
22
- "@xyo-network/payload-model": "^2.110.18",
13
+ "@xylabs/assert": "^3.6.8",
14
+ "@xylabs/exists": "^3.6.8",
15
+ "@xyo-network/archivist-model": "^2.111.0",
16
+ "@xyo-network/boundwitness-model": "^2.111.0",
17
+ "@xyo-network/diviner-boundwitness-model": "^2.111.0",
18
+ "@xyo-network/diviner-forecasting-abstract": "^2.111.0",
19
+ "@xyo-network/diviner-forecasting-method-arima": "^2.111.0",
20
+ "@xyo-network/diviner-forecasting-model": "^2.111.0",
21
+ "@xyo-network/diviner-model": "^2.111.0",
22
+ "@xyo-network/payload-model": "^2.111.0",
23
23
  "jsonpath": "^1.1.1"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/jsonpath": "^0.2.4",
27
- "@xylabs/ts-scripts-yarn3": "^3.14.1",
28
- "@xylabs/tsconfig": "^3.14.1",
27
+ "@xylabs/ts-scripts-yarn3": "^3.15.5",
28
+ "@xylabs/tsconfig": "^3.15.5",
29
29
  "typescript": "^5.5.4"
30
30
  },
31
31
  "description": "Primary SDK for using XYO Protocol 2.0",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "import": {
41
41
  "types": "./dist/browser/index.d.mts",
42
- "default": "./dist/browser/index.js"
42
+ "default": "./dist/browser/index.mjs"
43
43
  }
44
44
  },
45
45
  "node": {
@@ -49,14 +49,14 @@
49
49
  },
50
50
  "import": {
51
51
  "types": "./dist/node/index.d.mts",
52
- "default": "./dist/node/index.js"
52
+ "default": "./dist/node/index.mjs"
53
53
  }
54
54
  }
55
55
  },
56
56
  "./package.json": "./package.json"
57
57
  },
58
58
  "main": "dist/node/index.cjs",
59
- "module": "dist/node/index.js",
59
+ "module": "dist/node/index.mjs",
60
60
  "homepage": "https://xyo.network",
61
61
  "license": "LGPL-3.0-only",
62
62
  "publishConfig": {
@@ -67,6 +67,6 @@
67
67
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
68
68
  },
69
69
  "sideEffects": false,
70
- "version": "2.110.18",
70
+ "version": "2.111.0",
71
71
  "type": "module"
72
72
  }
@@ -4,11 +4,13 @@ import { asArchivistInstance } from '@xyo-network/archivist-model'
4
4
  import { BoundWitness } from '@xyo-network/boundwitness-model'
5
5
  import { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'
6
6
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'
7
+ import type {
8
+ arimaForecastingName,
9
+ seasonalArimaForecastingName,
10
+ } from '@xyo-network/diviner-forecasting-method-arima'
7
11
  import {
8
12
  arimaForecastingMethod,
9
- arimaForecastingName,
10
13
  seasonalArimaForecastingMethod,
11
- seasonalArimaForecastingName,
12
14
  } from '@xyo-network/diviner-forecasting-method-arima'
13
15
  import { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'
14
16
  import { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'
@@ -85,13 +87,13 @@ export class MemoryForecastingDiviner<
85
87
  while (more || payloads.length < this.maxTrainingLength) {
86
88
  const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }
87
89
  const boundWitnesses = (await bwDiviner.divine([query])).filter(
88
- (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,
90
+ bw => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,
89
91
  )
90
92
  if (boundWitnesses.length === 0) break
91
93
 
92
94
  // Update the timestamp value for the next batch
93
95
  timestamp = boundWitnesses
94
- .map((bw) => bw.timestamp)
96
+ .map(bw => bw.timestamp)
95
97
  .filter(exists)
96
98
  // eslint-disable-next-line unicorn/no-array-reduce
97
99
  .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)
@@ -101,7 +103,7 @@ export class MemoryForecastingDiviner<
101
103
  more = boundWitnesses.length === limit
102
104
 
103
105
  // Get the corresponding payload hashes from the BWs
104
- const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)
106
+ const hashes = boundWitnesses.map(bw => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)
105
107
 
106
108
  // Get the payloads corresponding to the BW hashes from the archivist
107
109
  if (hashes.length > 0) {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,2BAA2B;AAEpC,SAAqEC,sCAAsC;AAC3G,SAASC,kCAA4D;AACrE,SACEC,wBAEAC,sCAEK;AACP,SAASC,sCAAkF;AAC3F,SAASC,yBAA0C;AAEnD,OAAOC,cAAc;AAIrB,IAAMC,yBAAyB,wBAACC,mBAAAA;AAC9B,SAAO,CAACC,MAAAA;AACN,UAAMC,MAAMC,SAASC,MAAMH,GAAGD,cAAAA;AAC9B,QAAI,OAAOE,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB;AACF,GAN+B;AAQ/B,IAAMC,oBAAoB;AAC1B,IAAMC,2BAA2B;AAE1B,IAAMC,2BAAN,MAAMA,kCAEHC,2BAAAA;EAhCV,OAgCUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,OAA0BE,wBAA6E;IACrGC,kBAAkBC;IAClBC,0BAA0BC;EAC5B;EAEA,IAAIC,sBAAsB;AACxB,WAAOC,SAAS,KAAKC,OAAOF,qBAAqB,MAAM,mCAAA;EACzD;;;;EAKA,IAAcG,aAAa;AACzB,WAAO,KAAKD,OAAOC,cAAcf;EACnC;EAEA,IAAuBgB,oBAAuC;AAC5D,UAAMC,wBAAwBJ,SAAS,KAAKC,OAAOE,mBAAmB,MAAM,qCAAA;AAC5E,UAAMA,oBAAoBd,0BAAyBK,sBAAsBU,qBAAAA;AACzE,QAAID,kBAAmB,QAAOA;AAC9B,UAA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OK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAI,CAACD,OAAOA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,MAAAA;AAG/G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,MAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,2BAA2B;AAEpC,SAAqEC,sCAAsC;AAC3G,SAASC,kCAA4D;AACrE,SACEC,wBAEAC,sCAEK;AACP,SAASC,sCAAkF;AAC3F,SAASC,yBAA0C;AAEnD,OAAOC,cAAc;AAIrB,IAAMC,yBAAyB,wBAACC,mBAAAA;AAC9B,SAAO,CAACC,MAAAA;AACN,UAAMC,MAAMC,SAASC,MAAMH,GAAGD,cAAAA;AAC9B,QAAI,OAAOE,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB;AACF,GAN+B;AAQ/B,IAAMC,oBAAoB;AAC1B,IAAMC,2BAA2B;AAE1B,IAAMC,2BAAN,MAAMA,kCAEHC,2BAAAA;EAhCV,OAgCUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,OAA0BE,wBAA6E;IACrGC,kBAAkBC;IAClBC,0BAA0BC;EAC5B;EAEA,IAAIC,sBAAsB;AACxB,WAAOC,SAAS,KAAKC,OAAOF,qBAAqB,MAAM,mCAAA;EACzD;;;;EAKA,IAAcG,aAAa;AACzB,WAAO,KAAKD,OAAOC,cAAcf;EACnC;EAEA,IAAuBgB,oBAAuC;AAC5D,UAAMC,wBAAwBJ,SAAS,KAAKC,OAAOE,mBAAmB,MAAM,qCAAA;AAC5E,UAAMA,oBAAoBd,0BAAyBK,sBAAsBU,qBAAAA;AACzE,QAAID,kBAAmB,QAAOA;AAC9B,UAAM,IAAIjB,MAAM,mCAAmCkB,qBAAAA,EAAuB;EAC5E;EAEA,I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D,OAAOA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,MAAAA;AAG/G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,MAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,2BAA2B;AAEpC,SAAqEC,sCAAsC;AAC3G,SAASC,kCAA4D;AACrE,SACEC,wBAEAC,sCAEK;AACP,SAASC,sCAAkF;AAC3F,SAASC,yBAA0C;AAEnD,OAAOC,cAAc;AAIrB,IAAMC,yBAAyB,wBAACC,mBAAAA;AAC9B,SAAO,CAACC,MAAAA;AACN,UAAMC,MAAMC,SAASC,MAAMH,GAAGD,cAAAA;AAC9B,QAAI,OAAOE,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB;AACF,GAN+B;AAQ/B,IAAMC,oBAAoB;AAC1B,IAAMC,2BAA2B;AAE1B,IAAMC,4BAAN,MAAMA,kCAEHC,2BAAAA;EASR,IAAIC,sBAAsB;AACxB,WAAOC,SAAS,KAAKC,OAAOF,qBAAqB,MAAM,mCAAA;EACzD;;;;EAKA,IAAcG,aAAa;AACzB,WAAO,KAAKD,OAAOC,cAAcP;EACnC;EAEA,IAAuBQ,oBAAuC;AAC5D,UAAMC,wBAAwBJ,SAAS,KAAKC,OAAOE,mBAAmB,MAAM,qCAAA;AAC5E,UAAMA,oBAAoBN,0BAAyBQ,sBAAsBD,qBAAAA;AACzE,QAAID,kBAAmB,QAAOA;AAC9B,UAAM,IAAIT,MAAM,mCAAmCU,qBAAAA,EAAuB;EAC5E;EAEA,IAAcE,oBAAoB;AAChC,WAAO,KAAKL,OAAOK,qBAAqBV;EAC1C;EAEA,IAAuBW,cAAuC;AAC5D,UAAMlB,iBAAiBW,SAAS,KAAKC,OAAOO,oBAAoB,MAAM,sCAAA;AACtE,WAAOpB,uBAAuBC,cAAAA;EAChC;EAEA,MAAyBoB,oBAAo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C3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;AAjFUlB;AACR,cAHWD,2BAGcqD,iBAA0B;KAAI,iEAAMA;EAAeC;;AAC5E,cAJWtD,2BAIcuD,uBAA8BD;AAEvD,cANWtD,2BAMeQ,yBAA6E;EACrGgD,kBAAkBC;EAClBC,0BAA0BC;AAC5B;AATK,IAAM3D,2BAAN;","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","forecastingMethodDict","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod"]}