@xyo-network/diviner-forecasting-memory 2.84.16 → 2.84.18

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.
@@ -80,7 +80,7 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_di
80
80
  const addresses = this.config.witnessAddresses;
81
81
  const payload_schemas = [(0, import_assert.assertEx)(this.config.witnessSchema, "Missing witnessSchema in config")];
82
82
  const payloads = [];
83
- const archivist = (0, import_archivist_model.asArchivistInstance)(await this.readArchivist(), "Unable to resolve archivist");
83
+ const archivist = (0, import_archivist_model.asArchivistInstance)(await this.getArchivist(), "Unable to resolve archivist");
84
84
  const bwDiviner = (0, import_diviner_model.asDivinerInstance)((await this.resolve(this.config.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
85
85
  const limit = this.batchLimit;
86
86
  const witnessSchema = (0, import_assert.assertEx)(this.config.witnessSchema, "Missing witnessSchema in config");
@@ -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 { 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 } 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 // eslint-disable-next-line import/no-named-as-default-member\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 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.readArchivist(), 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance((await this.resolve(this.config.boundWitnessDiviner)).pop(), 'Unable to resolve boundWitnessDiviner')\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])) as BoundWitness[]).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;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,oBAAuB;AACvB,6BAAoC;AAEpC,wCAAgF;AAChF,0CAAqE;AACrE,8CAKO;AACP,uCAA2F;AAC3F,2BAAkC;AAElC,sBAAqB;AAIrB,IAAM,yBAAyB,CAAC,mBAAoD;AAClF,QAAM,cAAc,CAAC,MAAuB;AAE1C,UAAM,MAAM,gBAAAA,QAAS,MAAM,GAAG,cAAc;AAC5C,QAAI,OAAO,QAAQ;AAAU,aAAO;AACpC,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AACA,SAAO;AACT;AAEO,IAAM,2BAAN,MAAM,kCAEH,+DAAoC;AAAA,EAC5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AAI,eAAe,WAAW;AAAG;AAGjC,kBAAY,eACT,IAAI,CAAC,OAAO,GAAG,SAAS,EACxB,OAAO,oBAAM,EAEb,OAAO,CAAC,GAAG,MAAM,KAAK,IAAI,GAAG,CAAC,GAAG,OAAO,gBAAgB;AAC3D,UAAI,cAAc,OAAO;AAAkB;AAG3C,aAAO,eAAe,WAAW;AAGjC,YAAM,SAAS,eAAe,IAAI,CAAC,OAAO,GAAG,eAAe,GAAG,gBAAgB,QAAQ,aAAa,CAAC,CAAC,EAAE,OAAO,oBAAM;AAGrH,UAAI,OAAO,SAAS,GAAG;AACrB,cAAM,iBAAiB,MAAM,UAAU,IAAI,MAAM,GAAG,OAAO,oBAAM;AACjE,iBAAS,KAAK,GAAG,aAAa;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":["jsonpath"]}
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 { 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 } 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 // eslint-disable-next-line import/no-named-as-default-member\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 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.getArchivist(), 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance((await this.resolve(this.config.boundWitnessDiviner)).pop(), 'Unable to resolve boundWitnessDiviner')\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])) as BoundWitness[]).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;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,oBAAuB;AACvB,6BAAoC;AAEpC,wCAAgF;AAChF,0CAAqE;AACrE,8CAKO;AACP,uCAA2F;AAC3F,2BAAkC;AAElC,sBAAqB;AAIrB,IAAM,yBAAyB,CAAC,mBAAoD;AAClF,QAAM,cAAc,CAAC,MAAuB;AAE1C,UAAM,MAAM,gBAAAA,QAAS,MAAM,GAAG,cAAc;AAC5C,QAAI,OAAO,QAAQ;AAAU,aAAO;AACpC,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AACA,SAAO;AACT;AAEO,IAAM,2BAAN,MAAM,kCAEH,+DAAoC;AAAA,EAC5C,OAAgB,gBAAgB,CAAC,+DAA8B;AAAA,EAE/D,OAA0B,wBAA6E;AAAA,IACrG,kBAAkB;A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,oBAAM,EAEb,OAAO,CAAC,GAAG,MAAM,KAAK,IAAI,GAAG,CAAC,GAAG,OAAO,gBAAgB;AAC3D,UAAI,cAAc,OAAO;AAAkB;AAG3C,aAAO,eAAe,WAAW;AAGjC,YAAM,SAAS,eAAe,IAAI,CAAC,OAAO,GAAG,eAAe,GAAG,gBAAgB,QAAQ,aAAa,CAAC,CAAC,EAAE,OAAO,oBAAM;AAGrH,UAAI,OAAO,SAAS,GAAG;AACrB,cAAM,iBAAiB,MAAM,UAAU,IAAI,MAAM,GAAG,OAAO,oBAAM;AACjE,iBAAS,KAAK,GAAG,aAAa;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":["jsonpath"]}
@@ -47,7 +47,7 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractF
47
47
  const addresses = this.config.witnessAddresses;
48
48
  const payload_schemas = [assertEx(this.config.witnessSchema, "Missing witnessSchema in config")];
49
49
  const payloads = [];
50
- const archivist = asArchivistInstance(await this.readArchivist(), "Unable to resolve archivist");
50
+ const archivist = asArchivistInstance(await this.getArchivist(), "Unable to resolve archivist");
51
51
  const bwDiviner = asDivinerInstance((await this.resolve(this.config.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
52
52
  const limit = this.batchLimit;
53
53
  const witnessSchema = assertEx(this.config.witnessSchema, "Missing witnessSchema in config");
@@ -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 { 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 } 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 // eslint-disable-next-line import/no-named-as-default-member\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 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.readArchivist(), 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance((await this.resolve(this.config.boundWitnessDiviner)).pop(), 'Unable to resolve boundWitnessDiviner')\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])) as BoundWitness[]).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,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,2BAA2B;AAEpC,SAA0C,sCAAsC;AAChF,SAAS,kCAA4D;AACrE;AAAA,EACE;AAAA,EAEA;AAAA,OAEK;AACP,SAAS,sCAAkF;AAC3F,SAAS,yBAAyB;AAElC,OAAO,cAAc;AAIrB,IAAM,yBAAyB,CAAC,mBAAoD;AA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,YAAM,QAAyC,EAAE,WAAW,OAAO,iBAAiB,QAAQ,gCAAgC,UAAU;AACtI,YAAM,kBAAmB,MAAM,UAAU,OAAO,CAAC,KAAK,CAAC,GAAsB;AAAA,QAC3E,CAAC,OAAO,GAAG,aAAa,GAAG,aAAa,kBAAkB,GAAG,aAAa;AAAA,MAC5E;AACA,UAAI,eAAe,WAAW;AAAG;AAGjC,kBAAY,eACT,IAAI,CAAC,OAAO,GAAG,SAAS,EACxB,OAAO,MAAM,EAEb,OAAO,CAAC,GAAG,MAAM,KAAK,IAAI,GAAG,CAAC,GAAG,OAAO,gBAAgB;AAC3D,UAAI,cAAc,OAAO;AAAkB;AAG3C,aAAO,eAAe,WAAW;AAGjC,YAAM,SAAS,eAAe,IAAI,CAAC,OAAO,GAAG,eAAe,GAAG,gBAAgB,QAAQ,aAAa,CAAC,CAAC,EAAE,OAAO,MAAM;AAGrH,UAAI,OAAO,SAAS,GAAG;AACrB,cAAM,iBAAiB,MAAM,UAAU,IAAI,MAAM,GAAG,OAAO,MAAM;AACjE,iBAAS,KAAK,GAAG,aAAa;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
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 { 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 } 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 // eslint-disable-next-line import/no-named-as-default-member\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 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.getArchivist(), 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance((await this.resolve(this.config.boundWitnessDiviner)).pop(), 'Unable to resolve boundWitnessDiviner')\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])) as BoundWitness[]).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,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,2BAA2B;AAEpC,SAA0C,sCAAsC;AAChF,SAAS,kCAA4D;AACrE;AAAA,EACE;AAAA,EAEA;AAAA,OAEK;AACP,SAAS,sCAAkF;AAC3F,SAAS,yBAAyB;AAElC,OAAO,cAAc;AAIrB,IAAM,yBAAyB,CAAC,mBAAoD;AAClF,QAAM,cAAc,CAAC,MAAuB;AAE1C,UAAM,MAAM,SAAS,MAAM,GAAG,cAAc;AAC5C,QAAI,OAAO,QAAQ;AAAU,aAAO;AACpC,UAAM,IAAI,MAAM,8BAA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CAAC,OAAO,GAAG,aAAa,GAAG,aAAa,kBAAkB,GAAG,aAAa;AAAA,MAC5E;AACA,UAAI,eAAe,WAAW;AAAG;AAGjC,kBAAY,eACT,IAAI,CAAC,OAAO,GAAG,SAAS,EACxB,OAAO,MAAM,EAEb,OAAO,CAAC,GAAG,MAAM,KAAK,IAAI,GAAG,CAAC,GAAG,OAAO,gBAAgB;AAC3D,UAAI,cAAc,OAAO;AAAkB;AAG3C,aAAO,eAAe,WAAW;AAGjC,YAAM,SAAS,eAAe,IAAI,CAAC,OAAO,GAAG,eAAe,GAAG,gBAAgB,QAAQ,aAAa,CAAC,CAAC,EAAE,OAAO,MAAM;AAGrH,UAAI,OAAO,SAAS,GAAG;AACrB,cAAM,iBAAiB,MAAM,UAAU,IAAI,MAAM,GAAG,OAAO,MAAM;AACjE,iBAAS,KAAK,GAAG,aAAa;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -80,7 +80,7 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_di
80
80
  const addresses = this.config.witnessAddresses;
81
81
  const payload_schemas = [(0, import_assert.assertEx)(this.config.witnessSchema, "Missing witnessSchema in config")];
82
82
  const payloads = [];
83
- const archivist = (0, import_archivist_model.asArchivistInstance)(await this.readArchivist(), "Unable to resolve archivist");
83
+ const archivist = (0, import_archivist_model.asArchivistInstance)(await this.getArchivist(), "Unable to resolve archivist");
84
84
  const bwDiviner = (0, import_diviner_model.asDivinerInstance)((await this.resolve(this.config.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
85
85
  const limit = this.batchLimit;
86
86
  const witnessSchema = (0, import_assert.assertEx)(this.config.witnessSchema, "Missing witnessSchema in config");
@@ -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 { 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 } 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 // eslint-disable-next-line import/no-named-as-default-member\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 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.readArchivist(), 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance((await this.resolve(this.config.boundWitnessDiviner)).pop(), 'Unable to resolve boundWitnessDiviner')\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])) as BoundWitness[]).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"],"m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,UAAM,gBAAY,yCAAmB,MAAM,KAAK,QAAQ,KAAK,OAAO,mBAAmB,GAAG,IAAI,GAAG,uCAAuC;AACxI,UAAM,QAAQ,KAAK;AACnB,UAAM,oBAAgB,wBAAS,KAAK,OAAO,eAAe,iCAAiC;AAC3F,QAAI,YAAY;AAChB,QAAI,OAAO;AAIX,WAAO,QAAQ,SAAS,SAAS,KAAK,mBAAmB;AACvD,YAAM,QAAyC,EAAE,WAAW,OAAO,iBAAiB,QAAQ,kEAAgC,UAAU;AACtI,YAAM,kBAAmB,MAAM,UAAU,OAAO,CAAC,KAAK,CAAC,GAAsB;AAAA,QAC3E,CAAC,OAAO,GAAG,aAAa,GAAG,aAAa,kBAAkB,GAAG,aAAa;AAAA,MAC5E;AACA,UAAI,eAAe,WAAW;AAAG;AAGjC,kBAAY,eACT,IAAI,CAAC,OAAO,GAAG,SAAS,EACxB,OAAO,oBAAM,EAEb,OAAO,CAAC,GAAG,MAAM,KAAK,IAAI,GAAG,CAAC,GAAG,OAAO,gBAAgB;AAC3D,UAAI,cAAc,OAAO;AAAkB;AAG3C,aAAO,eAAe,WAAW;AAGjC,YAAM,SAAS,eAAe,IAAI,CAAC,OAAO,GAAG,eAAe,GAAG,gBAAgB,QAAQ,aAAa,CAAC,CAAC,EAAE,OAAO,oBAAM;AAGrH,UAAI,OAAO,SAAS,GAAG;AACrB,cAAM,iBAAiB,MAAM,UAAU,IAAI,MAAM,GAAG,OAAO,oBAAM;AACjE,iBAAS,KAAK,GAAG,aAAa;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":["jsonpath"]}
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 { 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 } 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 // eslint-disable-next-line import/no-named-as-default-member\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 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.getArchivist(), 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance((await this.resolve(this.config.boundWitnessDiviner)).pop(), 'Unable to resolve boundWitnessDiviner')\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])) as BoundWitness[]).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;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAA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AAuC;AACxI,UAAM,QAAQ,KAAK;AACnB,UAAM,oBAAgB,wBAAS,KAAK,OAAO,eAAe,iCAAiC;AAC3F,QAAI,YAAY;AAChB,QAAI,OAAO;AAIX,WAAO,QAAQ,SAAS,SAAS,KAAK,mBAAmB;AACvD,YAAM,QAAyC,EAAE,WAAW,OAAO,iBAAiB,QAAQ,kEAAgC,UAAU;AACtI,YAAM,kBAAmB,MAAM,UAAU,OAAO,CAAC,KAAK,CAAC,GAAsB;AAAA,QAC3E,CAAC,OAAO,GAAG,aAAa,GAAG,aAAa,kBAAkB,GAAG,aAAa;AAAA,MAC5E;AACA,UAAI,eAAe,WAAW;AAAG;AAGjC,kBAAY,eACT,IAAI,CAAC,OAAO,GAAG,SAAS,EACxB,OAAO,oBAAM,EAEb,OAAO,CAAC,GAAG,MAAM,KAAK,IAAI,GAAG,CAAC,GAAG,OAAO,gBAAgB;AAC3D,UAAI,cAAc,OAAO;AAAkB;AAG3C,aAAO,eAAe,WAAW;AAGjC,YAAM,SAAS,eAAe,IAAI,CAAC,OAAO,GAAG,eAAe,GAAG,gBAAgB,QAAQ,aAAa,CAAC,CAAC,EAAE,OAAO,oBAAM;AAGrH,UAAI,OAAO,SAAS,GAAG;AACrB,cAAM,iBAAiB,MAAM,UAAU,IAAI,MAAM,GAAG,OAAO,oBAAM;AACjE,iBAAS,KAAK,GAAG,aAAa;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":["jsonpath"]}
@@ -47,7 +47,7 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractF
47
47
  const addresses = this.config.witnessAddresses;
48
48
  const payload_schemas = [assertEx(this.config.witnessSchema, "Missing witnessSchema in config")];
49
49
  const payloads = [];
50
- const archivist = asArchivistInstance(await this.readArchivist(), "Unable to resolve archivist");
50
+ const archivist = asArchivistInstance(await this.getArchivist(), "Unable to resolve archivist");
51
51
  const bwDiviner = asDivinerInstance((await this.resolve(this.config.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
52
52
  const limit = this.batchLimit;
53
53
  const witnessSchema = assertEx(this.config.witnessSchema, "Missing witnessSchema in config");
@@ -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 { 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 } 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 // eslint-disable-next-line import/no-named-as-default-member\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 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.readArchivist(), 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance((await this.resolve(this.config.boundWitnessDiviner)).pop(), 'Unable to resolve boundWitnessDiviner')\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])) as BoundWitness[]).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,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,SAAS,2BAA2B;AAEpC,SAA0C,sCAAsC;AAChF,SAAS,kCAA4D;AACrE;AAAA,EACE;AAAA,EAEA;AAAA,OAEK;AACP,SAAS,sCAAkF;AAC3F,SAAS,yBAAyB;AAElC,OAAO,cAAc;AAIrB,IAAM,yBAAyB,CAAC,mBAAoD;AAClF,QAAM,cAAc,CAAC,MAAuB;AAE1C,UAAM,MAAM,SAAS,MAAM,GAAG,cAAc;AAC5C,QAAI,OAAO,QAAQ;AAAU,aAAO;AACpC,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AACA,SAAO;AACT;AAEO,IAAM,2BAAN,MAAM,kCAEH,2BAAoC;AAAA,EAC5C,OAAgB,gBAAgB,CAAC,8BAA8B;AAAA,EAE/D,OAA0B,wBAA6E;AAAA,IACrG,kBAAkB;AAAA,IAClB,0BAA0B;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAKmB,aAAa;AAAA;AAAA,EAGb,oBAAoB;AAAA,EAEvC,IAAuB,oBAAuC;AAC5D,UAAM,wBAAwB,SAAS,KAAK,OAAO,mBAAmB,qCAAqC;AAC3G,UAAM,oBAAoB,0BAAyB,sBAAsB,qBAAqB;AAC9F,QAAI;AAAmB,aAAO;AAC9B,UAAM,IAAI,MAAM,mCAAmC,qBAAqB,EAAE;AAAA,EAC5E;AAAA,EAEA,IAAuB,cAAuC;AAC5D,UAAM,iBAAiB,SAAS,KAAK,OAAO,oBAAoB,sCAAsC;AACtG,WAAO,uBAAuB,cAAc;AAAA,EAC9C;AAAA,EAEA,MAA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ryForecastingDiviner.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 { 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 } 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 // eslint-disable-next-line import/no-named-as-default-member\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 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.getArchivist(), 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance((await this.resolve(this.config.boundWitnessDiviner)).pop(), 'Unable to resolve boundWitnessDiviner')\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])) as BoundWitness[]).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 > 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AAsB,CAAC;AAC7B,UAAM,YAAY,oBAAoB,MAAM,KAAK,aAAa,GAAG,6BAA6B;AAC9F,UAAM,YAAY,mBAAmB,MAAM,KAAK,QAAQ,KAAK,OAAO,mBAAmB,GAAG,IAAI,GAAG,uCAAuC;AACxI,UAAM,QAAQ,KAAK;AACnB,UAAM,gBAAgB,SAAS,KAAK,OAAO,eAAe,iCAAiC;AAC3F,QAAI,YAAY;AAChB,QAAI,OAAO;AAIX,WAAO,QAAQ,SAAS,SAAS,KAAK,mBAAmB;AACvD,YAAM,QAAyC,EAAE,WAAW,OAAO,iBAAiB,QAAQ,gCAAgC,UAAU;AACtI,YAAM,kBAAmB,MAAM,UAAU,OAAO,CAAC,KAAK,CAAC,GAAsB;AAAA,QAC3E,CAAC,OAAO,GAAG,aAAa,GAAG,aAAa,kBAAkB,GAAG,aAAa;AAAA,MAC5E;AACA,UAAI,eAAe,WAAW;AAAG;AAGjC,kBAAY,eACT,IAAI,CAAC,OAAO,GAAG,SAAS,EACxB,OAAO,MAAM,EAEb,OAAO,CAAC,GAAG,MAAM,KAAK,IAAI,GAAG,CAAC,GAAG,OAAO,gBAAgB;AAC3D,UAAI,cAAc,OAAO;AAAkB;AAG3C,aAAO,eAAe,WAAW;AAGjC,YAAM,SAAS,eAAe,IAAI,CAAC,OAAO,GAAG,eAAe,GAAG,gBAAgB,QAAQ,aAAa,CAAC,CAAC,EAAE,OAAO,MAAM;AAGrH,UAAI,OAAO,SAAS,GAAG;AACrB,cAAM,iBAAiB,MAAM,UAAU,IAAI,MAAM,GAAG,OAAO,MAAM;AACjE,iBAAS,KAAK,GAAG,aAAa;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
package/package.json CHANGED
@@ -12,14 +12,14 @@
12
12
  "dependencies": {
13
13
  "@xylabs/assert": "^2.13.20",
14
14
  "@xylabs/exists": "^2.13.20",
15
- "@xyo-network/archivist-model": "~2.84.16",
16
- "@xyo-network/boundwitness-model": "~2.84.16",
17
- "@xyo-network/diviner-boundwitness-model": "~2.84.16",
18
- "@xyo-network/diviner-forecasting-abstract": "~2.84.16",
19
- "@xyo-network/diviner-forecasting-method-arima": "~2.84.16",
20
- "@xyo-network/diviner-forecasting-model": "~2.84.16",
21
- "@xyo-network/diviner-model": "~2.84.16",
22
- "@xyo-network/payload-model": "~2.84.16",
15
+ "@xyo-network/archivist-model": "~2.84.18",
16
+ "@xyo-network/boundwitness-model": "~2.84.18",
17
+ "@xyo-network/diviner-boundwitness-model": "~2.84.18",
18
+ "@xyo-network/diviner-forecasting-abstract": "~2.84.18",
19
+ "@xyo-network/diviner-forecasting-method-arima": "~2.84.18",
20
+ "@xyo-network/diviner-forecasting-model": "~2.84.18",
21
+ "@xyo-network/diviner-model": "~2.84.18",
22
+ "@xyo-network/payload-model": "~2.84.18",
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.84.16",
70
+ "version": "2.84.18",
71
71
  "type": "module"
72
72
  }
@@ -61,7 +61,7 @@ export class MemoryForecastingDiviner<
61
61
  const addresses = this.config.witnessAddresses
62
62
  const payload_schemas = [assertEx(this.config.witnessSchema, 'Missing witnessSchema in config')]
63
63
  const payloads: Payload[] = []
64
- const archivist = asArchivistInstance(await this.readArchivist(), 'Unable to resolve archivist')
64
+ const archivist = asArchivistInstance(await this.getArchivist(), 'Unable to resolve archivist')
65
65
  const bwDiviner = asDivinerInstance((await this.resolve(this.config.boundWitnessDiviner)).pop(), 'Unable to resolve boundWitnessDiviner')
66
66
  const limit = this.batchLimit
67
67
  const witnessSchema = assertEx(this.config.witnessSchema, 'Missing witnessSchema in config')