@xyo-network/diviner-forecasting-memory 2.107.5 → 2.108.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 +2 -2
  2. package/dist/browser/MemoryForecastingDiviner.d.cts.map +1 -1
  3. package/dist/browser/MemoryForecastingDiviner.d.mts +2 -2
  4. package/dist/browser/MemoryForecastingDiviner.d.mts.map +1 -1
  5. package/dist/browser/MemoryForecastingDiviner.d.ts +2 -2
  6. package/dist/browser/MemoryForecastingDiviner.d.ts.map +1 -1
  7. package/dist/browser/index.cjs +10 -5
  8. package/dist/browser/index.cjs.map +1 -1
  9. package/dist/browser/index.js +10 -5
  10. package/dist/browser/index.js.map +1 -1
  11. package/dist/neutral/MemoryForecastingDiviner.d.cts +2 -2
  12. package/dist/neutral/MemoryForecastingDiviner.d.cts.map +1 -1
  13. package/dist/neutral/MemoryForecastingDiviner.d.mts +2 -2
  14. package/dist/neutral/MemoryForecastingDiviner.d.mts.map +1 -1
  15. package/dist/neutral/MemoryForecastingDiviner.d.ts +2 -2
  16. package/dist/neutral/MemoryForecastingDiviner.d.ts.map +1 -1
  17. package/dist/neutral/index.cjs +10 -5
  18. package/dist/neutral/index.cjs.map +1 -1
  19. package/dist/neutral/index.js +10 -5
  20. package/dist/neutral/index.js.map +1 -1
  21. package/dist/node/MemoryForecastingDiviner.d.cts +2 -2
  22. package/dist/node/MemoryForecastingDiviner.d.cts.map +1 -1
  23. package/dist/node/MemoryForecastingDiviner.d.mts +2 -2
  24. package/dist/node/MemoryForecastingDiviner.d.mts.map +1 -1
  25. package/dist/node/MemoryForecastingDiviner.d.ts +2 -2
  26. package/dist/node/MemoryForecastingDiviner.d.ts.map +1 -1
  27. package/dist/node/index.cjs +10 -5
  28. package/dist/node/index.cjs.map +1 -1
  29. package/dist/node/index.js +10 -5
  30. package/dist/node/index.js.map +1 -1
  31. package/package.json +14 -14
  32. package/src/MemoryForecastingDiviner.ts +13 -7
@@ -7,8 +7,6 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
7
7
  static readonly configSchemas: Schema[];
8
8
  static readonly defaultConfigSchema: Schema;
9
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
10
- protected readonly batchLimit = 1000;
11
- protected readonly maxTrainingLength = 10000;
12
10
  get boundWitnessDiviner(): import("@xyo-network/module-model").ObjectFilterOptions<import("@xyo-network/module-model").ModuleInstance<import("@xylabs/object").BaseParamsFields & {
13
11
  account?: import("@xyo-network/account-model").AccountInstance | "random";
14
12
  addToResolvers?: boolean;
@@ -58,7 +56,9 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
58
56
  ephemeralQueryAccountEnabled?: boolean;
59
57
  moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
60
58
  }, import("@xyo-network/module-model").ModuleEventData<object>>>;
59
+ protected get batchLimit(): number;
61
60
  protected get forecastingMethod(): ForecastingMethod;
61
+ protected get maxTrainingLength(): number;
62
62
  protected get transformer(): PayloadValueTransformer;
63
63
  protected getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]>;
64
64
  }
@@ -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;AAWxG,qBAA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AAE,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
@@ -7,8 +7,6 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
7
7
  static readonly configSchemas: Schema[];
8
8
  static readonly defaultConfigSchema: Schema;
9
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
10
- protected readonly batchLimit = 1000;
11
- protected readonly maxTrainingLength = 10000;
12
10
  get boundWitnessDiviner(): import("@xyo-network/module-model").ObjectFilterOptions<import("@xyo-network/module-model").ModuleInstance<import("@xylabs/object").BaseParamsFields & {
13
11
  account?: import("@xyo-network/account-model").AccountInstance | "random";
14
12
  addToResolvers?: boolean;
@@ -58,7 +56,9 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
58
56
  ephemeralQueryAccountEnabled?: boolean;
59
57
  moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
60
58
  }, import("@xyo-network/module-model").ModuleEventData<object>>>;
59
+ protected get batchLimit(): number;
61
60
  protected get forecastingMethod(): ForecastingMethod;
61
+ protected get maxTrainingLength(): number;
62
62
  protected get transformer(): PayloadValueTransformer;
63
63
  protected getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]>;
64
64
  }
@@ -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;AAWxG,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;IAKD,SAAS,CAAC,QAAQ,CAAC,UAAU,QAAO;IAGpC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,SAAS;IAE7C,IAAI,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qEAEtB;IAED,cAAuB,iBAAiB,IAAI,iBAAiB,CAK5D;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA6ChH"}
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;AAcxG,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
@@ -7,8 +7,6 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
7
7
  static readonly configSchemas: Schema[];
8
8
  static readonly defaultConfigSchema: Schema;
9
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
10
- protected readonly batchLimit = 1000;
11
- protected readonly maxTrainingLength = 10000;
12
10
  get boundWitnessDiviner(): import("@xyo-network/module-model").ObjectFilterOptions<import("@xyo-network/module-model").ModuleInstance<import("@xylabs/object").BaseParamsFields & {
13
11
  account?: import("@xyo-network/account-model").AccountInstance | "random";
14
12
  addToResolvers?: boolean;
@@ -58,7 +56,9 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
58
56
  ephemeralQueryAccountEnabled?: boolean;
59
57
  moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
60
58
  }, import("@xyo-network/module-model").ModuleEventData<object>>>;
59
+ protected get batchLimit(): number;
61
60
  protected get forecastingMethod(): ForecastingMethod;
61
+ protected get maxTrainingLength(): number;
62
62
  protected get transformer(): PayloadValueTransformer;
63
63
  protected getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]>;
64
64
  }
@@ -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;AAWxG,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;I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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"}
@@ -53,6 +53,8 @@ var getJsonPathTransformer = /* @__PURE__ */ __name((pathExpression) => {
53
53
  }, "transformer");
54
54
  return transformer;
55
55
  }, "getJsonPathTransformer");
56
+ var defaultBatchLimit = 1e3;
57
+ var defaultMaxTrainingLength = 1e4;
56
58
  var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_diviner_forecasting_abstract.AbstractForecastingDiviner {
57
59
  static {
58
60
  __name(this, "MemoryForecastingDiviner");
@@ -66,14 +68,14 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_di
66
68
  arimaForecasting: import_diviner_forecasting_method_arima.arimaForecastingMethod,
67
69
  seasonalArimaForecasting: import_diviner_forecasting_method_arima.seasonalArimaForecastingMethod
68
70
  };
71
+ get boundWitnessDiviner() {
72
+ return (0, import_assert.assertEx)(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
73
+ }
69
74
  /**
70
75
  * The max number of records to search during the batch query
71
76
  */
72
- batchLimit = 1e3;
73
- // TODO: Inject via config
74
- maxTrainingLength = 1e4;
75
- get boundWitnessDiviner() {
76
- return (0, import_assert.assertEx)(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
77
+ get batchLimit() {
78
+ return this.config.batchLimit ?? defaultBatchLimit;
77
79
  }
78
80
  get forecastingMethod() {
79
81
  const forecastingMethodName = (0, import_assert.assertEx)(this.config.forecastingMethod, () => "Missing forecastingMethod in config");
@@ -81,6 +83,9 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_di
81
83
  if (forecastingMethod) return forecastingMethod;
82
84
  throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
83
85
  }
86
+ get maxTrainingLength() {
87
+ return this.config.maxTrainingLength ?? defaultMaxTrainingLength;
88
+ }
84
89
  get transformer() {
85
90
  const pathExpression = (0, import_assert.assertEx)(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
86
91
  return getJsonPathTransformer(pathExpression);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner'\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 const transformer = (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 return transformer\n}\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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\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 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,QAAMC,cAAc,wBAACC,MAAAA;AACnB,UAAMC,MAAMC,gBAAAA,QAASC,MAAMH,GAAGF,cAAAA;AAC9B,QAAI,OAAOG,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB,GAJoB;AAKpB,SAAOL;AACT,GAP+B;AASxB,IAAMM,2BAAN,MAAMA,kCAEHC,+DAAAA;EA9BV,OA8BUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,OAA0BE,wBAA6E;IACrGC,kBAAkBC;IAClBC,0BAA0BC;EAC5B;;;;EAKmBC,aAAa;;EAGbC,oBAAoB;EAEvC,IAAIC,sBAAsB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,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","transformer","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","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'\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 const transformer = (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 return transformer\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,QAAMC,cAAc,wBAACC,MAAAA;AACnB,UAAMC,MAAMC,gBAAAA,QAASC,MAAMH,GAAGF,cAAAA;AAC9B,QAAI,OAAOG,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB,GAJoB;AAKpB,SAAOL;AACT,GAP+B;AAS/B,IAAMM,oBAAoB;AAC1B,IAAMC,2BAA2B;AAE1B,IAAMC,2BAAN,MAAMA,kCAEHC,+DAAAA;EAjCV,OAiCUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,OAA0BE,wBAA6E;IACrGC,kBAAkBC;IAClBC,0BAA0BC;EAC5B;EAEA,IAAIC,sBAAsB;AACxB,eAAOC,wBAAS,KAAKC,OAAOF,qBAAqB,MAAM,mCAAA;EACzD;;;;EAKA,IAAcG,aAAa;AACzB,WAAO,KAAKD,OAAOC,cAAcf;EACnC;EAEA,IAAuBgB,oBAAuC;AAC5D,UAAMC,4BAAwBJ,wBAAS,KAAKC,OAAOE,mBAAmB,MAAM,qCAAA;AAC5E,UAAMA,oBAAoBd,0BAAyBK,sBAAsBU,qBAAAA;AACzE,QA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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","transformer","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","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"]}
@@ -19,6 +19,8 @@ var getJsonPathTransformer = /* @__PURE__ */ __name((pathExpression) => {
19
19
  }, "transformer");
20
20
  return transformer;
21
21
  }, "getJsonPathTransformer");
22
+ var defaultBatchLimit = 1e3;
23
+ var defaultMaxTrainingLength = 1e4;
22
24
  var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractForecastingDiviner {
23
25
  static {
24
26
  __name(this, "MemoryForecastingDiviner");
@@ -32,14 +34,14 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractF
32
34
  arimaForecasting: arimaForecastingMethod,
33
35
  seasonalArimaForecasting: seasonalArimaForecastingMethod
34
36
  };
37
+ get boundWitnessDiviner() {
38
+ return assertEx(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
39
+ }
35
40
  /**
36
41
  * The max number of records to search during the batch query
37
42
  */
38
- batchLimit = 1e3;
39
- // TODO: Inject via config
40
- maxTrainingLength = 1e4;
41
- get boundWitnessDiviner() {
42
- return assertEx(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
43
+ get batchLimit() {
44
+ return this.config.batchLimit ?? defaultBatchLimit;
43
45
  }
44
46
  get forecastingMethod() {
45
47
  const forecastingMethodName = assertEx(this.config.forecastingMethod, () => "Missing forecastingMethod in config");
@@ -47,6 +49,9 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractF
47
49
  if (forecastingMethod) return forecastingMethod;
48
50
  throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
49
51
  }
52
+ get maxTrainingLength() {
53
+ return this.config.maxTrainingLength ?? defaultMaxTrainingLength;
54
+ }
50
55
  get transformer() {
51
56
  const pathExpression = assertEx(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
52
57
  return getJsonPathTransformer(pathExpression);
@@ -1 +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 {\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 const transformer = (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 return transformer\n}\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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\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 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,SAAS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GAAI,MAAM,6BAAA;AAC5E,UAAMC,YAAYC,mBACf,MAAM,KAAKC,QAAQ,KAAKnB,mBAAmB,GAAGoB,IAAG,GAClD,uCAAA;AAEF,UAAMC,QAAQ,KAAKvB;AACnB,UAAMc,gBAAgBX,SAAS,KAAKC,OAAOU,eAAe,MAAM,iCAAA;AAChE,QAAIU,YAAYd;AAChB,QAAIe,OAAO;AAIX,WAAOA,QAAQV,SAASW,SAAS,KAAKzB,mBAAmB;AACvD,YAAM0B,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,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,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","transformer","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","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/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 const transformer = (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 return transformer\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,QAAMC,cAAc,wBAACC,MAAAA;AACnB,UAAMC,MAAMC,SAASC,MAA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QAAQ,KAAKrB,mBAAmB,GAAGsB,IAAG,GAClD,uCAAA;AAEF,UAAMC,QAAQ,KAAKpB;AACnB,UAAMW,gBAAgBb,SAAS,KAAKC,OAAOY,eAAe,MAAM,iCAAA;AAChE,QAAIU,YAAYd;AAChB,QAAIe,OAAO;AAIX,WAAOA,QAAQV,SAASW,SAAS,KAAKpB,mBAAmB;AACvD,YAAMqB,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,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,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","transformer","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","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"]}
@@ -7,8 +7,6 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
7
7
  static readonly configSchemas: Schema[];
8
8
  static readonly defaultConfigSchema: Schema;
9
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
10
- protected readonly batchLimit = 1000;
11
- protected readonly maxTrainingLength = 10000;
12
10
  get boundWitnessDiviner(): import("@xyo-network/module-model").ObjectFilterOptions<import("@xyo-network/module-model").ModuleInstance<import("@xylabs/object").BaseParamsFields & {
13
11
  account?: import("@xyo-network/account-model").AccountInstance | "random";
14
12
  addToResolvers?: boolean;
@@ -58,7 +56,9 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
58
56
  ephemeralQueryAccountEnabled?: boolean;
59
57
  moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
60
58
  }, import("@xyo-network/module-model").ModuleEventData<object>>>;
59
+ protected get batchLimit(): number;
61
60
  protected get forecastingMethod(): ForecastingMethod;
61
+ protected get maxTrainingLength(): number;
62
62
  protected get transformer(): PayloadValueTransformer;
63
63
  protected getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]>;
64
64
  }
@@ -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;AAWxG,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;IAKD,SAAS,CAAC,QAAQ,CAAC,UAAU,QAAO;IAGpC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,SAAS;IAE7C,IAAI,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qEAEtB;IAED,cAAuB,iBAAiB,IAAI,iBAAiB,CAK5D;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA6ChH"}
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;AAcxG,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
@@ -7,8 +7,6 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
7
7
  static readonly configSchemas: Schema[];
8
8
  static readonly defaultConfigSchema: Schema;
9
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
10
- protected readonly batchLimit = 1000;
11
- protected readonly maxTrainingLength = 10000;
12
10
  get boundWitnessDiviner(): import("@xyo-network/module-model").ObjectFilterOptions<import("@xyo-network/module-model").ModuleInstance<import("@xylabs/object").BaseParamsFields & {
13
11
  account?: import("@xyo-network/account-model").AccountInstance | "random";
14
12
  addToResolvers?: boolean;
@@ -58,7 +56,9 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
58
56
  ephemeralQueryAccountEnabled?: boolean;
59
57
  moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
60
58
  }, import("@xyo-network/module-model").ModuleEventData<object>>>;
59
+ protected get batchLimit(): number;
61
60
  protected get forecastingMethod(): ForecastingMethod;
61
+ protected get maxTrainingLength(): number;
62
62
  protected get transformer(): PayloadValueTransformer;
63
63
  protected getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]>;
64
64
  }
@@ -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;AAWxG,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;IAKD,SAAS,CAAC,QAAQ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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"}
@@ -7,8 +7,6 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
7
7
  static readonly configSchemas: Schema[];
8
8
  static readonly defaultConfigSchema: Schema;
9
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
10
- protected readonly batchLimit = 1000;
11
- protected readonly maxTrainingLength = 10000;
12
10
  get boundWitnessDiviner(): import("@xyo-network/module-model").ObjectFilterOptions<import("@xyo-network/module-model").ModuleInstance<import("@xylabs/object").BaseParamsFields & {
13
11
  account?: import("@xyo-network/account-model").AccountInstance | "random";
14
12
  addToResolvers?: boolean;
@@ -58,7 +56,9 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
58
56
  ephemeralQueryAccountEnabled?: boolean;
59
57
  moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
60
58
  }, import("@xyo-network/module-model").ModuleEventData<object>>>;
59
+ protected get batchLimit(): number;
61
60
  protected get forecastingMethod(): ForecastingMethod;
61
+ protected get maxTrainingLength(): number;
62
62
  protected get transformer(): PayloadValueTransformer;
63
63
  protected getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]>;
64
64
  }
@@ -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,wCAA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,OAAO,4BAA4B,CAAA;AAcxG,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
@@ -53,6 +53,8 @@ var getJsonPathTransformer = /* @__PURE__ */ __name((pathExpression) => {
53
53
  }, "transformer");
54
54
  return transformer;
55
55
  }, "getJsonPathTransformer");
56
+ var defaultBatchLimit = 1e3;
57
+ var defaultMaxTrainingLength = 1e4;
56
58
  var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_diviner_forecasting_abstract.AbstractForecastingDiviner {
57
59
  static {
58
60
  __name(this, "MemoryForecastingDiviner");
@@ -66,14 +68,14 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_di
66
68
  arimaForecasting: import_diviner_forecasting_method_arima.arimaForecastingMethod,
67
69
  seasonalArimaForecasting: import_diviner_forecasting_method_arima.seasonalArimaForecastingMethod
68
70
  };
71
+ get boundWitnessDiviner() {
72
+ return (0, import_assert.assertEx)(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
73
+ }
69
74
  /**
70
75
  * The max number of records to search during the batch query
71
76
  */
72
- batchLimit = 1e3;
73
- // TODO: Inject via config
74
- maxTrainingLength = 1e4;
75
- get boundWitnessDiviner() {
76
- return (0, import_assert.assertEx)(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
77
+ get batchLimit() {
78
+ return this.config.batchLimit ?? defaultBatchLimit;
77
79
  }
78
80
  get forecastingMethod() {
79
81
  const forecastingMethodName = (0, import_assert.assertEx)(this.config.forecastingMethod, () => "Missing forecastingMethod in config");
@@ -81,6 +83,9 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_di
81
83
  if (forecastingMethod) return forecastingMethod;
82
84
  throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
83
85
  }
86
+ get maxTrainingLength() {
87
+ return this.config.maxTrainingLength ?? defaultMaxTrainingLength;
88
+ }
84
89
  get transformer() {
85
90
  const pathExpression = (0, import_assert.assertEx)(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
86
91
  return getJsonPathTransformer(pathExpression);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner'\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 const transformer = (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 return transformer\n}\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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\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 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,Q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,KAAKvB;AACnB,UAAMc,oBAAgBX,wBAAS,KAAKC,OAAOU,eAAe,MAAM,iCAAA;AAChE,QAAIU,YAAYd;AAChB,QAAIe,OAAO;AAIX,WAAOA,QAAQV,SAASW,SAAS,KAAKzB,mBAAmB;AACvD,YAAM0B,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","transformer","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","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'\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 const transformer = (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 return transformer\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,QAAMC,cAAc,wBAACC,MAAAA;AACnB,UAAMC,MAAMC,gBAAAA,QAASC,MAAMH,GAAGF,cAAAA;AAC9B,QAAI,OAAOG,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB,GAJoB;AAKpB,SAAOL;AACT,GAP+B;AAS/B,IAAMM,oBAAoB;AAC1B,IAAMC,2BAA2B;AAE1B,IAAMC,2BAAN,MAAMA,kCAEHC,+DAAAA;EA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AAKpB,mBAAmB;AACvD,YAAMqB,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","transformer","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","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"]}
@@ -19,6 +19,8 @@ var getJsonPathTransformer = /* @__PURE__ */ __name((pathExpression) => {
19
19
  }, "transformer");
20
20
  return transformer;
21
21
  }, "getJsonPathTransformer");
22
+ var defaultBatchLimit = 1e3;
23
+ var defaultMaxTrainingLength = 1e4;
22
24
  var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractForecastingDiviner {
23
25
  static {
24
26
  __name(this, "MemoryForecastingDiviner");
@@ -32,14 +34,14 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractF
32
34
  arimaForecasting: arimaForecastingMethod,
33
35
  seasonalArimaForecasting: seasonalArimaForecastingMethod
34
36
  };
37
+ get boundWitnessDiviner() {
38
+ return assertEx(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
39
+ }
35
40
  /**
36
41
  * The max number of records to search during the batch query
37
42
  */
38
- batchLimit = 1e3;
39
- // TODO: Inject via config
40
- maxTrainingLength = 1e4;
41
- get boundWitnessDiviner() {
42
- return assertEx(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
43
+ get batchLimit() {
44
+ return this.config.batchLimit ?? defaultBatchLimit;
43
45
  }
44
46
  get forecastingMethod() {
45
47
  const forecastingMethodName = assertEx(this.config.forecastingMethod, () => "Missing forecastingMethod in config");
@@ -47,6 +49,9 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractF
47
49
  if (forecastingMethod) return forecastingMethod;
48
50
  throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
49
51
  }
52
+ get maxTrainingLength() {
53
+ return this.config.maxTrainingLength ?? defaultMaxTrainingLength;
54
+ }
50
55
  get transformer() {
51
56
  const pathExpression = assertEx(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
52
57
  return getJsonPathTransformer(pathExpression);
@@ -1 +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 {\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 const transformer = (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 return transformer\n}\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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\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 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,QAAMC,cAAc,wBAACC,MAAAA;AACnB,UAAMC,MAAMC,SAASC,MAAMH,GAAGF,cAAAA;AAC9B,QAAI,OAAOG,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB,GAJoB;AAKpB,SAAOL;AACT,GAP+B;AASxB,IAAMM,2BAAN,MAAMA,kCAEHC,2BAAAA;EA9BV,OA8BUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,OAA0BE,wBAA6E;IACrGC,kBAAkBC;IAClBC,0BAA0BC;EAC5B;;;;EAKmBC,aAAa;;EAGbC,oBAAoB;EAEvC,IAAIC,sBAAsB;AACxB,WAAOC,SAAS,KAAKC,OAAOF,qBAAqB,MAAM,mCAAA;EACzD;EAEA,IAAuBG,oBAAuC;AAC5D,UAAMC,wBAAwBH,SAAS,KAAKC,OAAOC,mBAAmB,MAAM,qCAAA;AAC5E,UAAMA,oBAAoBf,0BAAyBK,sBAAsBW,q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jC,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","transformer","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","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/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 const transformer = (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 return transformer\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,QAAMC,cAAc,wBAACC,MAAAA;AACnB,UAAMC,MAAMC,SAASC,MAAMH,GAAGF,cAAAA;AAC9B,QAAI,OAAOG,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB,GAJoB;AAKpB,SAAOL;AACT,GAP+B;AAS/B,IAAMM,oBAAoB;AAC1B,IAAMC,2BAA2B;AAE1B,IAAMC,2BAAN,MAAMA,kCAEHC,2BAAAA;EAjCV,OAiCUA;;;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,IAAcC,oBAAoB;AAChC,WAA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AAGpB,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","transformer","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","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"]}
@@ -7,8 +7,6 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
7
7
  static readonly configSchemas: Schema[];
8
8
  static readonly defaultConfigSchema: Schema;
9
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
10
- protected readonly batchLimit = 1000;
11
- protected readonly maxTrainingLength = 10000;
12
10
  get boundWitnessDiviner(): import("@xyo-network/module-model").ObjectFilterOptions<import("@xyo-network/module-model").ModuleInstance<import("@xylabs/object").BaseParamsFields & {
13
11
  account?: import("@xyo-network/account-model").AccountInstance | "random";
14
12
  addToResolvers?: boolean;
@@ -58,7 +56,9 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
58
56
  ephemeralQueryAccountEnabled?: boolean;
59
57
  moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
60
58
  }, import("@xyo-network/module-model").ModuleEventData<object>>>;
59
+ protected get batchLimit(): number;
61
60
  protected get forecastingMethod(): ForecastingMethod;
61
+ protected get maxTrainingLength(): number;
62
62
  protected get transformer(): PayloadValueTransformer;
63
63
  protected getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]>;
64
64
  }
@@ -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;AAWxG,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;IAKD,SAAS,CAAC,QAAQ,CAAC,UAAU,QAAO;IAG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,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"}
@@ -7,8 +7,6 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
7
7
  static readonly configSchemas: Schema[];
8
8
  static readonly defaultConfigSchema: Schema;
9
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
10
- protected readonly batchLimit = 1000;
11
- protected readonly maxTrainingLength = 10000;
12
10
  get boundWitnessDiviner(): import("@xyo-network/module-model").ObjectFilterOptions<import("@xyo-network/module-model").ModuleInstance<import("@xylabs/object").BaseParamsFields & {
13
11
  account?: import("@xyo-network/account-model").AccountInstance | "random";
14
12
  addToResolvers?: boolean;
@@ -58,7 +56,9 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
58
56
  ephemeralQueryAccountEnabled?: boolean;
59
57
  moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
60
58
  }, import("@xyo-network/module-model").ModuleEventData<object>>>;
59
+ protected get batchLimit(): number;
61
60
  protected get forecastingMethod(): ForecastingMethod;
61
+ protected get maxTrainingLength(): number;
62
62
  protected get transformer(): PayloadValueTransformer;
63
63
  protected getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]>;
64
64
  }
@@ -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,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AcxG,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
@@ -7,8 +7,6 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
7
7
  static readonly configSchemas: Schema[];
8
8
  static readonly defaultConfigSchema: Schema;
9
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
10
- protected readonly batchLimit = 1000;
11
- protected readonly maxTrainingLength = 10000;
12
10
  get boundWitnessDiviner(): import("@xyo-network/module-model").ObjectFilterOptions<import("@xyo-network/module-model").ModuleInstance<import("@xylabs/object").BaseParamsFields & {
13
11
  account?: import("@xyo-network/account-model").AccountInstance | "random";
14
12
  addToResolvers?: boolean;
@@ -58,7 +56,9 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
58
56
  ephemeralQueryAccountEnabled?: boolean;
59
57
  moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
60
58
  }, import("@xyo-network/module-model").ModuleEventData<object>>>;
59
+ protected get batchLimit(): number;
61
60
  protected get forecastingMethod(): ForecastingMethod;
61
+ protected get maxTrainingLength(): number;
62
62
  protected get transformer(): PayloadValueTransformer;
63
63
  protected getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]>;
64
64
  }
@@ -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;AAWxG,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;IAKD,SAAS,CAAC,QAAQ,CAAC,UAAU,QAAO;IAGpC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,SAAS;IAE7C,IAAI,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qEAEtB;IAED,cAAuB,iBAAiB,IAAI,iBAAiB,CAK5D;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA6ChH"}
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;AAcxG,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
@@ -57,15 +57,17 @@ var getJsonPathTransformer = /* @__PURE__ */ __name((pathExpression) => {
57
57
  }, "transformer");
58
58
  return transformer;
59
59
  }, "getJsonPathTransformer");
60
+ var defaultBatchLimit = 1e3;
61
+ var defaultMaxTrainingLength = 1e4;
60
62
  var _MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_diviner_forecasting_abstract.AbstractForecastingDiviner {
63
+ get boundWitnessDiviner() {
64
+ return (0, import_assert.assertEx)(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
65
+ }
61
66
  /**
62
67
  * The max number of records to search during the batch query
63
68
  */
64
- batchLimit = 1e3;
65
- // TODO: Inject via config
66
- maxTrainingLength = 1e4;
67
- get boundWitnessDiviner() {
68
- return (0, import_assert.assertEx)(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
69
+ get batchLimit() {
70
+ return this.config.batchLimit ?? defaultBatchLimit;
69
71
  }
70
72
  get forecastingMethod() {
71
73
  const forecastingMethodName = (0, import_assert.assertEx)(this.config.forecastingMethod, () => "Missing forecastingMethod in config");
@@ -73,6 +75,9 @@ var _MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_d
73
75
  if (forecastingMethod) return forecastingMethod;
74
76
  throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
75
77
  }
78
+ get maxTrainingLength() {
79
+ return this.config.maxTrainingLength ?? defaultMaxTrainingLength;
80
+ }
76
81
  get transformer() {
77
82
  const pathExpression = (0, import_assert.assertEx)(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
78
83
  return getJsonPathTransformer(pathExpression);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner'\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 const transformer = (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 return transformer\n}\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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\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 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"],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IAAM1D,2BAAN;","names":["getJsonPathTransformer","pathExpression","transformer","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","forecastingMethodDict","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'\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 const transformer = (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 return transformer\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,QAAMC,cAA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AAgBd,wBAAS,KAAKC,OAAOa,eAAe,MAAM,iCAAA;AAChE,QAAIU,YAAYd;AAChB,QAAIe,OAAO;AAIX,WAAOA,QAAQV,SAASW,SAAS,KAAKpB,mBAAmB;AACvD,YAAMqB,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;AAjFUjB;AACR,cAHWD,2BAGcoD,iBAA0B;KAAI,iEAAMA;EAAeC;;AAC5E,cAJWrD,2BAIcsD,uBAA8BD;AAEvD,cANWrD,2BAMeQ,yBAA6E;EACrG+C,kBAAkBC;EAClBC,0BAA0BC;AAC5B;AATK,IAAM1D,2BAAN;","names":["getJsonPathTransformer","pathExpression","transformer","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","forecastingMethodDict","maxTrainingLength","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"]}
@@ -24,15 +24,17 @@ var getJsonPathTransformer = /* @__PURE__ */ __name((pathExpression) => {
24
24
  }, "transformer");
25
25
  return transformer;
26
26
  }, "getJsonPathTransformer");
27
+ var defaultBatchLimit = 1e3;
28
+ var defaultMaxTrainingLength = 1e4;
27
29
  var _MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractForecastingDiviner {
30
+ get boundWitnessDiviner() {
31
+ return assertEx(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
32
+ }
28
33
  /**
29
34
  * The max number of records to search during the batch query
30
35
  */
31
- batchLimit = 1e3;
32
- // TODO: Inject via config
33
- maxTrainingLength = 1e4;
34
- get boundWitnessDiviner() {
35
- return assertEx(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
36
+ get batchLimit() {
37
+ return this.config.batchLimit ?? defaultBatchLimit;
36
38
  }
37
39
  get forecastingMethod() {
38
40
  const forecastingMethodName = assertEx(this.config.forecastingMethod, () => "Missing forecastingMethod in config");
@@ -40,6 +42,9 @@ var _MemoryForecastingDiviner = class _MemoryForecastingDiviner extends Abstract
40
42
  if (forecastingMethod) return forecastingMethod;
41
43
  throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
42
44
  }
45
+ get maxTrainingLength() {
46
+ return this.config.maxTrainingLength ?? defaultMaxTrainingLength;
47
+ }
43
48
  get transformer() {
44
49
  const pathExpression = assertEx(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
45
50
  return getJsonPathTransformer(pathExpression);
@@ -1 +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 {\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 const transformer = (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 return transformer\n}\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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\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 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,QAAMC,cAAc,wBAACC,MAAAA;AACnB,UAAMC,MAAMC,SAASC,MAAMH,GAAGF,cAAAA;AAC9B,QAAI,OAAOG,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB,GAJoB;AAKpB,SAAOL;AACT,GAP+B;AASxB,IAAMM,4BAAN,MAAMA,kCAEHC,2BAAAA;;;;EAYWC,aAAa;;EAGbC,oBAAoB;EAEvC,IAAIC,sBAAsB;AACxB,WAAOC,SAAS,KAAKC,OAAOF,qBAAqB,MAAM,mCAAA;EACzD;EAEA,IAAuBG,oBAAuC;AAC5D,UAAMC,wBAAwBH,SAAS,KAAKC,OAAOC,mBAAmB,MAAM,qCAAA;AAC5E,UAAMA,oBAAoBP,0BAAyBS,sBAAsBD,qBAAAA;AACz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ASb,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;AA9EUjB;AACR,cAHWD,2BAGcoD,iBAA0B;KAAI,iEAAMA;EAAeC;;AAC5E,cAJWrD,2BAIcsD,uBAA8BD;AAEvD,cANWrD,2BAMeS,yBAA6E;EACrG8C,kBAAkBC;EAClBC,0BAA0BC;AAC5B;AATK,IAAM1D,2BAAN;","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","pathExpression","transformer","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","forecastingMethodDict","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/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 const transformer = (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 return transformer\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,QAAMC,cAAc,wBAACC,MAAAA;AACnB,UAAMC,MAAMC,SAASC,MAAMH,GAAGF,cAAAA;AAC9B,QAAI,OAAOG,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB,GAJoB;AAKpB,SAAOL;AACT,GAP+B;AAS/B,IAAMM,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;EA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,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;AAjFUjB;AACR,cAHWD,2BAGcoD,iBAA0B;KAAI,iEAAMA;EAAeC;;AAC5E,cAJWrD,2BAIcsD,uBAA8BD;AAEvD,cANWrD,2BAMeQ,yBAA6E;EACrG+C,kBAAkBC;EAClBC,0BAA0BC;AAC5B;AATK,IAAM1D,2BAAN;","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","pathExpression","transformer","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","forecastingMethodDict","maxTrainingLength","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,23 +10,23 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xylabs/assert": "^3.5.1",
14
- "@xylabs/exists": "^3.5.1",
15
- "@xyo-network/archivist-model": "~2.107.5",
16
- "@xyo-network/boundwitness-model": "~2.107.5",
17
- "@xyo-network/diviner-boundwitness-model": "~2.107.5",
18
- "@xyo-network/diviner-forecasting-abstract": "~2.107.5",
19
- "@xyo-network/diviner-forecasting-method-arima": "~2.107.5",
20
- "@xyo-network/diviner-forecasting-model": "~2.107.5",
21
- "@xyo-network/diviner-model": "~2.107.5",
22
- "@xyo-network/payload-model": "~2.107.5",
13
+ "@xylabs/assert": "^3.5.2",
14
+ "@xylabs/exists": "^3.5.2",
15
+ "@xyo-network/archivist-model": "^2.108.0",
16
+ "@xyo-network/boundwitness-model": "^2.108.0",
17
+ "@xyo-network/diviner-boundwitness-model": "^2.108.0",
18
+ "@xyo-network/diviner-forecasting-abstract": "^2.108.0",
19
+ "@xyo-network/diviner-forecasting-method-arima": "^2.108.0",
20
+ "@xyo-network/diviner-forecasting-model": "^2.108.0",
21
+ "@xyo-network/diviner-model": "^2.108.0",
22
+ "@xyo-network/payload-model": "^2.108.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.11.10",
28
- "@xylabs/tsconfig": "^3.11.10",
29
- "typescript": "^5.5.2"
27
+ "@xylabs/ts-scripts-yarn3": "^3.11.12",
28
+ "@xylabs/tsconfig": "^3.11.12",
29
+ "typescript": "^5.5.3"
30
30
  },
31
31
  "description": "Primary SDK for using XYO Protocol 2.0",
32
32
  "types": "dist/node/index.d.ts",
@@ -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.107.5",
70
+ "version": "2.108.0",
71
71
  "type": "module"
72
72
  }
@@ -26,6 +26,9 @@ const getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer
26
26
  return transformer
27
27
  }
28
28
 
29
+ const defaultBatchLimit = 1000
30
+ const defaultMaxTrainingLength = 10_000
31
+
29
32
  export class MemoryForecastingDiviner<
30
33
  TParams extends ForecastingDivinerParams = ForecastingDivinerParams,
31
34
  > extends AbstractForecastingDiviner<TParams> {
@@ -37,16 +40,15 @@ export class MemoryForecastingDiviner<
37
40
  seasonalArimaForecasting: seasonalArimaForecastingMethod,
38
41
  }
39
42
 
43
+ get boundWitnessDiviner() {
44
+ return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')
45
+ }
46
+
40
47
  /**
41
48
  * The max number of records to search during the batch query
42
49
  */
43
- protected readonly batchLimit = 1000
44
-
45
- // TODO: Inject via config
46
- protected readonly maxTrainingLength = 10_000
47
-
48
- get boundWitnessDiviner() {
49
- return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')
50
+ protected get batchLimit() {
51
+ return this.config.batchLimit ?? defaultBatchLimit
50
52
  }
51
53
 
52
54
  protected override get forecastingMethod(): ForecastingMethod {
@@ -56,6 +58,10 @@ export class MemoryForecastingDiviner<
56
58
  throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)
57
59
  }
58
60
 
61
+ protected get maxTrainingLength() {
62
+ return this.config.maxTrainingLength ?? defaultMaxTrainingLength
63
+ }
64
+
59
65
  protected override get transformer(): PayloadValueTransformer {
60
66
  const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')
61
67
  return getJsonPathTransformer(pathExpression)