@xyo-network/diviner-forecasting-memory 2.96.2 → 2.97.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,11 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
2
  import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
- import { Payload } from '@xyo-network/payload-model';
4
+ import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
6
6
  export declare class MemoryForecastingDiviner<TParams extends ForecastingDivinerParams = ForecastingDivinerParams> extends AbstractForecastingDiviner<TParams> {
7
- static configSchemas: "network.xyo.diviner.forecasting.config"[];
7
+ static configSchemas: Schema[];
8
+ static defaultConfigSchema: Schema;
8
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
9
10
  /**
10
11
  * The max number of records to search during the batch query
@@ -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,4BAA4B,CAAA;AAGpD,MAAM,MAAM,wBAAwB,GAAG,OAAO,oBAAoB,GAAG,OAAO,4BAA4B,CAAA;AAWxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC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AAE,iBAAiB,CAAC,CAGnG;IAED;;OAEG;IACH,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,10 +1,11 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
2
  import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
- import { Payload } from '@xyo-network/payload-model';
4
+ import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
6
6
  export declare class MemoryForecastingDiviner<TParams extends ForecastingDivinerParams = ForecastingDivinerParams> extends AbstractForecastingDiviner<TParams> {
7
- static configSchemas: "network.xyo.diviner.forecasting.config"[];
7
+ static configSchemas: Schema[];
8
+ static defaultConfigSchema: Schema;
8
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
9
10
  /**
10
11
  * The max number of records to search during the batch query
@@ -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,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B,CAAA;AAWxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC,OAAO,CAAC;IAC3C,OAAgB,aAAa,EAAE,MAAM,EAAE,CAA2D;IAClG,OAAgB,mBAAmB,EAAE,MAAM,CAAiC;IAE5E,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAGnG;IAED;;OAEG;IACH,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,10 +1,11 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
2
  import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
- import { Payload } from '@xyo-network/payload-model';
4
+ import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
6
6
  export declare class MemoryForecastingDiviner<TParams extends ForecastingDivinerParams = ForecastingDivinerParams> extends AbstractForecastingDiviner<TParams> {
7
- static configSchemas: "network.xyo.diviner.forecasting.config"[];
7
+ static configSchemas: Schema[];
8
+ static defaultConfigSchema: Schema;
8
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
9
10
  /**
10
11
  * The max number of records to search during the batch query
@@ -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,4BAA4B,CAAA;AAGpD,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,OAAgB,aAAa,6CAAmC;IAEhE,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAGnG;IAED;;OAEG;IACH,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;AAWxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC,OAAO,CAAC;IAC3C,OAAgB,aAAa,EAAE,MAAM,EAAE,CAA2D;IAClG,OAAgB,mBAAmB,EAAE,MAAM,CAAiC;IAE5E,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAGnG;IAED;;OAEG;IACH,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"}
@@ -59,8 +59,10 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_di
59
59
  __name(this, "MemoryForecastingDiviner");
60
60
  }
61
61
  static configSchemas = [
62
+ ...super.configSchemas,
62
63
  import_diviner_forecasting_model.ForecastingDivinerConfigSchema
63
64
  ];
65
+ static defaultConfigSchema = import_diviner_forecasting_model.ForecastingDivinerConfigSchema;
64
66
  static forecastingMethodDict = {
65
67
  arimaForecasting: import_diviner_forecasting_method_arima.arimaForecastingMethod,
66
68
  seasonalArimaForecasting: import_diviner_forecasting_method_arima.seasonalArimaForecastingMethod
@@ -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 } 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 configSchemas = [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;AAAU,aAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB,GAJoB;AAKpB,SAAOL;AACT,GAP+B;AASxB,IAAMM,2BAAN,MAAMA,kCAEHC,+DAAAA;EA9BV,OA8BUA;;;EACR,OAAgBC,gBAAgB;IAACC;;EAEjC,OAA0BC,wBAA6E;IACrGC,kBAAkBC;IAClBC,0BAA0BC;EAC5B;;;;EAKmBC,aAAa;;EAGbC,oBAAoB;EAEvC,IAAIC,sBAAsB;AACxB,eAAOC,wBAAS,KAAKC,OAAOF,qBAAqB,MAAM,mCAAA;EACzD;EAEA,IAAuBG,oBAAuC;AAC5D,UAAMC,4BAAwBH,wBAAS,KAAKC,OAAOC,mBAAmB,MAAM,qCAAA;AAC5E,UAAMA,oBAAoBd,0BAAyBI,sBAAsBW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WH;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","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\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override 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;;;;;;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UAAMC,gBAAYC,4CAAoB,MAAM,KAAKC,kBAAiB,GAAI,MAAM,6BAAA;AAC5E,UAAMC,gBAAYC,yCACf,MAAM,KAAKC,QAAQ,KAAKnB,mBAAmB,GAAGoB,IAAG,GAClD,uCAAA;AAEF,UAAMC,QAAQ,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;AAAG;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;AAAkB;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"]}
@@ -25,8 +25,10 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractF
25
25
  __name(this, "MemoryForecastingDiviner");
26
26
  }
27
27
  static configSchemas = [
28
+ ...super.configSchemas,
28
29
  ForecastingDivinerConfigSchema
29
30
  ];
31
+ static defaultConfigSchema = ForecastingDivinerConfigSchema;
30
32
  static forecastingMethodDict = {
31
33
  arimaForecasting: arimaForecastingMethod,
32
34
  seasonalArimaForecasting: seasonalArimaForecastingMethod
@@ -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 } 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 configSchemas = [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,m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AKC,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;AAAG;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;AAAkB;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","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\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override 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;AAAU,aAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB,GAJoB;AAKpB,SAAOL;AACT,GAP+B;AASxB,IAAMM,2BAAN,MAAMA,kCAEHC,2BAAAA;EA9BV,OA8BUA;;;EACR,OAAgBC,gBAA0B;OAAI,MAAMA;IAAeC;;EACnE,OAAgBC,sBAA8BD;EAE9C,OAA0BE,wBAA6E;IAC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T,aAAad,aAAAA;AAE5E,UAAIoB,eAAeJ,WAAW;AAAG;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;AAAkB;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,10 +1,11 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
2
  import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
- import { Payload } from '@xyo-network/payload-model';
4
+ import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
6
6
  export declare class MemoryForecastingDiviner<TParams extends ForecastingDivinerParams = ForecastingDivinerParams> extends AbstractForecastingDiviner<TParams> {
7
- static configSchemas: "network.xyo.diviner.forecasting.config"[];
7
+ static configSchemas: Schema[];
8
+ static defaultConfigSchema: Schema;
8
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
9
10
  /**
10
11
  * The max number of records to search during the batch query
@@ -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,4BAA4B,CAAA;AAGpD,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,OAAgB,aAAa,6CAAmC;IAEhE,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM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,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,10 +1,11 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
2
  import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
- import { Payload } from '@xyo-network/payload-model';
4
+ import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
6
6
  export declare class MemoryForecastingDiviner<TParams extends ForecastingDivinerParams = ForecastingDivinerParams> extends AbstractForecastingDiviner<TParams> {
7
- static configSchemas: "network.xyo.diviner.forecasting.config"[];
7
+ static configSchemas: Schema[];
8
+ static defaultConfigSchema: Schema;
8
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
9
10
  /**
10
11
  * The max number of records to search during the batch query
@@ -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,4BAA4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CAAC;IAC3C,OAAgB,aAAa,EAAE,MAAM,EAAE,CAA2D;IAClG,OAAgB,mBAAmB,EAAE,MAAM,CAAiC;IAE5E,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAGnG;IAED;;OAEG;IACH,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,10 +1,11 @@
1
1
  import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
2
  import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
3
  import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
- import { Payload } from '@xyo-network/payload-model';
4
+ import { Payload, Schema } from '@xyo-network/payload-model';
5
5
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
6
6
  export declare class MemoryForecastingDiviner<TParams extends ForecastingDivinerParams = ForecastingDivinerParams> extends AbstractForecastingDiviner<TParams> {
7
- static configSchemas: "network.xyo.diviner.forecasting.config"[];
7
+ static configSchemas: Schema[];
8
+ static defaultConfigSchema: Schema;
8
9
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
9
10
  /**
10
11
  * The max number of records to search during the batch query
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryForecastingDiviner.d.ts","sourceRoot":"","sources":["../../src/Memo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B,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,OAAgB,aAAa,EAAE,MAAM,EAAE,CAA2D;IAClG,OAAgB,mBAAmB,EAAE,MAAM,CAAiC;IAE5E,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAGnG;IAED;;OAEG;IACH,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"}
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __reflectGet = Reflect.get;
8
9
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
10
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
11
  var __export = (target, all) => {
@@ -32,6 +33,7 @@ var __publicField = (obj, key, value) => {
32
33
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
33
34
  return value;
34
35
  };
36
+ var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
35
37
 
36
38
  // src/index.ts
37
39
  var src_exports = {};
@@ -120,8 +122,10 @@ var _MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_d
120
122
  };
121
123
  __name(_MemoryForecastingDiviner, "MemoryForecastingDiviner");
122
124
  __publicField(_MemoryForecastingDiviner, "configSchemas", [
125
+ ...__superGet(_MemoryForecastingDiviner, _MemoryForecastingDiviner, "configSchemas"),
123
126
  import_diviner_forecasting_model.ForecastingDivinerConfigSchema
124
127
  ]);
128
+ __publicField(_MemoryForecastingDiviner, "defaultConfigSchema", import_diviner_forecasting_model.ForecastingDivinerConfigSchema);
125
129
  __publicField(_MemoryForecastingDiviner, "forecastingMethodDict", {
126
130
  arimaForecasting: import_diviner_forecasting_method_arima.arimaForecastingMethod,
127
131
  seasonalArimaForecasting: import_diviner_forecasting_method_arima.seasonalArimaForecastingMethod
@@ -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 } 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 configSchemas = [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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OV;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;AAAG;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;AAAkB;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;AA7EUjB;AACR,cAHWD,2BAGKoD,iBAAgB;EAACC;;AAEjC,cALWrD,2BAKeS,yBAA6E;EACrG6C,kBAAkBC;EAClBC,0BAA0BC;AAC5B;AARK,IAAMzD,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","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\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override 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;AAAU,aAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB,GAJoB;AAKpB,SAAOL;AACT,GAP+B;AASxB,IAAMM,4BAAN,MAAMA,kCAEHC,+DAAAA;;;;EAYWC,aAAa;;EAGbC,oBAAoB;EAEvC,IAAIC,sBAAsB;AACxB,eAAOC,wBAAS,KAAKC,OAAOF,qBAAqB,MAAM,mCAAA;EACzD;EAEA,IAAuBG,oBAAuC;AAC5D,UAAMC,4BAAwBH,wBAAS,KAAKC,OAAOC,mBAAmB,MAAM,qCAAA;AAC5E,UA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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;AA9EUjB;AACR,cAHWD,2BAGKoD,iBAA0B;KAAI,iEAAMA;EAAeC;;AACnE,cAJWrD,2BAIKsD,uBAA8BD;AAE9C,cANWrD,2BAMeS,yBAA6E;EACrG8C,kBAAkBC;EAClBC,0BAA0BC;AAC5B;AATK,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,10 +1,13 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __getProtoOf = Object.getPrototypeOf;
3
+ var __reflectGet = Reflect.get;
2
4
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
6
  var __publicField = (obj, key, value) => {
5
7
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
8
  return value;
7
9
  };
10
+ var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
8
11
 
9
12
  // src/MemoryForecastingDiviner.ts
10
13
  import { assertEx } from "@xylabs/assert";
@@ -86,8 +89,10 @@ var _MemoryForecastingDiviner = class _MemoryForecastingDiviner extends Abstract
86
89
  };
87
90
  __name(_MemoryForecastingDiviner, "MemoryForecastingDiviner");
88
91
  __publicField(_MemoryForecastingDiviner, "configSchemas", [
92
+ ...__superGet(_MemoryForecastingDiviner, _MemoryForecastingDiviner, "configSchemas"),
89
93
  ForecastingDivinerConfigSchema
90
94
  ]);
95
+ __publicField(_MemoryForecastingDiviner, "defaultConfigSchema", ForecastingDivinerConfigSchema);
91
96
  __publicField(_MemoryForecastingDiviner, "forecastingMethodDict", {
92
97
  arimaForecasting: arimaForecastingMethod,
93
98
  seasonalArimaForecasting: seasonalArimaForecastingMethod
@@ -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 } 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 configSchemas = [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,MA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WY;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;AAAG;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;AAAkB;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;AA7EUjB;AACR,cAHWD,2BAGKoD,iBAAgB;EAACC;;AAEjC,cALWrD,2BAKeS,yBAA6E;EACrG6C,kBAAkBC;EAClBC,0BAA0BC;AAC5B;AARK,IAAMzD,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","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\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override 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;AAAU,aAAOA;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;EACz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AMC,KAAKC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC;AAAkB;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;AA9EUjB;AACR,cAHWD,2BAGKoD,iBAA0B;KAAI,iEAAMA;EAAeC;;AACnE,cAJWrD,2BAIKsD,uBAA8BD;AAE9C,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"]}
package/package.json CHANGED
@@ -12,14 +12,14 @@
12
12
  "dependencies": {
13
13
  "@xylabs/assert": "^3.1.8",
14
14
  "@xylabs/exists": "^3.1.8",
15
- "@xyo-network/archivist-model": "~2.96.2",
16
- "@xyo-network/boundwitness-model": "~2.96.2",
17
- "@xyo-network/diviner-boundwitness-model": "~2.96.2",
18
- "@xyo-network/diviner-forecasting-abstract": "~2.96.2",
19
- "@xyo-network/diviner-forecasting-method-arima": "~2.96.2",
20
- "@xyo-network/diviner-forecasting-model": "~2.96.2",
21
- "@xyo-network/diviner-model": "~2.96.2",
22
- "@xyo-network/payload-model": "~2.96.2",
15
+ "@xyo-network/archivist-model": "~2.97.1",
16
+ "@xyo-network/boundwitness-model": "~2.97.1",
17
+ "@xyo-network/diviner-boundwitness-model": "~2.97.1",
18
+ "@xyo-network/diviner-forecasting-abstract": "~2.97.1",
19
+ "@xyo-network/diviner-forecasting-method-arima": "~2.97.1",
20
+ "@xyo-network/diviner-forecasting-model": "~2.97.1",
21
+ "@xyo-network/diviner-model": "~2.97.1",
22
+ "@xyo-network/payload-model": "~2.97.1",
23
23
  "jsonpath": "^1.1.1"
24
24
  },
25
25
  "devDependencies": {
@@ -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.96.2",
70
+ "version": "2.97.1",
71
71
  "type": "module"
72
72
  }
@@ -12,7 +12,7 @@ import {
12
12
  } from '@xyo-network/diviner-forecasting-method-arima'
13
13
  import { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'
14
14
  import { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'
15
- import { Payload } from '@xyo-network/payload-model'
15
+ import { Payload, Schema } from '@xyo-network/payload-model'
16
16
  import jsonpath from 'jsonpath'
17
17
 
18
18
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName
@@ -29,7 +29,8 @@ const getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer
29
29
  export class MemoryForecastingDiviner<
30
30
  TParams extends ForecastingDivinerParams = ForecastingDivinerParams,
31
31
  > extends AbstractForecastingDiviner<TParams> {
32
- static override configSchemas = [ForecastingDivinerConfigSchema]
32
+ static override configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]
33
+ static override defaultConfigSchema: Schema = ForecastingDivinerConfigSchema
33
34
 
34
35
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {
35
36
  arimaForecasting: arimaForecastingMethod,