@xyo-network/diviner-forecasting-memory 3.5.2 → 3.6.0-rc.10

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.
@@ -2,61 +2,14 @@ import type { ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-
2
2
  import { AbstractForecastingDiviner } from '@xyo-network/diviner-forecasting-abstract';
3
3
  import type { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
4
4
  import type { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
5
+ import type { ModuleFilter } from '@xyo-network/module-model';
5
6
  import type { Payload, Schema } from '@xyo-network/payload-model';
6
7
  export type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
7
8
  export declare class MemoryForecastingDiviner<TParams extends ForecastingDivinerParams = ForecastingDivinerParams> extends AbstractForecastingDiviner<TParams> {
8
9
  static readonly configSchemas: Schema[];
9
10
  static readonly defaultConfigSchema: Schema;
10
11
  protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
11
- get boundWitnessDiviner(): import("@xyo-network/module-model").ObjectFilterOptions<import("@xyo-network/module-model").ModuleInstance<import("@xylabs/object").BaseParamsFields & {
12
- account?: import("@xyo-network/account-model").AccountInstance | "random";
13
- addToResolvers?: boolean;
14
- additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
15
- allowNameResolution?: boolean;
16
- config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
17
- schema: "network.xyo.module.config";
18
- }, "schema"> & {
19
- schema: string;
20
- };
21
- ephemeralQueryAccountEnabled?: boolean;
22
- moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
23
- }, import("@xyo-network/module-model").ModuleEventData<object>>> | import("@xyo-network/module-model").AddressObjectFilter<import("@xyo-network/module-model").ModuleInstance<import("@xylabs/object").BaseParamsFields & {
24
- account?: import("@xyo-network/account-model").AccountInstance | "random";
25
- addToResolvers?: boolean;
26
- additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
27
- allowNameResolution?: boolean;
28
- config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
29
- schema: "network.xyo.module.config";
30
- }, "schema"> & {
31
- schema: string;
32
- };
33
- ephemeralQueryAccountEnabled?: boolean;
34
- moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
35
- }, import("@xyo-network/module-model").ModuleEventData<object>>> | import("@xyo-network/module-model").NameObjectFilter<import("@xyo-network/module-model").ModuleInstance<import("@xylabs/object").BaseParamsFields & {
36
- account?: import("@xyo-network/account-model").AccountInstance | "random";
37
- addToResolvers?: boolean;
38
- additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
39
- allowNameResolution?: boolean;
40
- config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
41
- schema: "network.xyo.module.config";
42
- }, "schema"> & {
43
- schema: string;
44
- };
45
- ephemeralQueryAccountEnabled?: boolean;
46
- moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
47
- }, import("@xyo-network/module-model").ModuleEventData<object>>> | import("@xyo-network/module-model").QueryObjectFilter<import("@xyo-network/module-model").ModuleInstance<import("@xylabs/object").BaseParamsFields & {
48
- account?: import("@xyo-network/account-model").AccountInstance | "random";
49
- addToResolvers?: boolean;
50
- additionalSigners?: import("@xyo-network/account-model").AccountInstance[];
51
- allowNameResolution?: boolean;
52
- config: import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & Omit<import("@xyo-network/module-model").ArchivingModuleConfig & import("@xyo-network/module-model").ModuleConfigFields & import("@xyo-network/payload-model").SchemaFields & import("@xyo-network/payload-model").PayloadFields & {
53
- schema: "network.xyo.module.config";
54
- }, "schema"> & {
55
- schema: string;
56
- };
57
- ephemeralQueryAccountEnabled?: boolean;
58
- moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
59
- }, import("@xyo-network/module-model").ModuleEventData<object>>>;
12
+ get boundWitnessDiviner(): ModuleFilter;
60
13
  /**
61
14
  * The max number of records to search during the batch query
62
15
  */
@@ -64,6 +17,6 @@ export declare class MemoryForecastingDiviner<TParams extends ForecastingDiviner
64
17
  protected get forecastingMethod(): ForecastingMethod;
65
18
  protected get maxTrainingLength(): number;
66
19
  protected get transformer(): PayloadValueTransformer;
67
- protected getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]>;
20
+ protected getPayloadsInWindow(_startTimestamp: number, _stopTimestamp: number): Promise<Payload[]>;
68
21
  }
69
22
  //# sourceMappingURL=MemoryForecastingDiviner.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryForecastingDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryForecastingDiviner.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AACzF,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAA;AACtF,OAAO,KAAK,EACV,oBAAoB,EACpB,4BAA4B,EAC7B,MAAM,+CAA+C,CAAA;AAKtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAIxG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CA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AwB,GAAG,OAAO,oBAAoB,GAAG,OAAO,4BAA4B,CAAA;AAaxG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC,OAAO,CAAC;IAC3C,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA2D;IAC3G,gBAAyB,mBAAmB,EAAE,MAAM,CAAiC;IAErF,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAGnG;IAED,IAAI,mBAAmB,IAAI,YAAY,CAEtC;IAED;;OAEG;IACH,SAAS,KAAK,UAAU,WAEvB;IAED,cAAuB,iBAAiB,IAAI,iBAAiB,CAK5D;IAED,SAAS,KAAK,iBAAiB,WAE9B;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAkDlH"}
@@ -55,7 +55,7 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractF
55
55
  const pathExpression = assertEx(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
56
56
  return getJsonPathTransformer(pathExpression);
57
57
  }
58
- async getPayloadsInWindow(startTimestamp, stopTimestamp) {
58
+ async getPayloadsInWindow(_startTimestamp, _stopTimestamp) {
59
59
  const addresses = this.config.witnessAddresses;
60
60
  const payload_schemas = [
61
61
  assertEx(this.config.witnessSchema, () => "Missing witnessSchema in config")
@@ -65,22 +65,22 @@ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractF
65
65
  const bwDiviner = asDivinerInstance((await this.resolve(this.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
66
66
  const limit = this.batchLimit;
67
67
  const witnessSchema = assertEx(this.config.witnessSchema, () => "Missing witnessSchema in config");
68
- let timestamp = stopTimestamp;
69
68
  let more = true;
70
69
  while (more || payloads.length < this.maxTrainingLength) {
71
70
  const query = {
72
71
  addresses,
73
72
  limit,
74
73
  payload_schemas,
75
- schema: BoundWitnessDivinerQuerySchema,
76
- timestamp
74
+ schema: BoundWitnessDivinerQuerySchema
77
75
  };
78
76
  const boundWitnesses = (await bwDiviner.divine([
79
77
  query
80
- ])).filter((bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp);
78
+ ])).filter(
79
+ // TODO; Replace with sequence
80
+ // bw => bw.$timestamp && bw.$timestamp >= startTimestamp && bw.$timestamp <= stopTimestamp,
81
+ (_) => true
82
+ );
81
83
  if (boundWitnesses.length === 0) break;
82
- timestamp = boundWitnesses.map((bw) => bw.timestamp).filter(exists).reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER);
83
- if (timestamp === Number.MAX_SAFE_INTEGER) break;
84
84
  more = boundWitnesses.length === limit;
85
85
  const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists);
86
86
  if (hashes.length > 0) {
@@ -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 type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport type { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport type { ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport { AbstractForecastingDiviner } from '@xyo-network/diviner-forecasting-abstract'\nimport type {\n arimaForecastingName,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport {\n arimaForecastingMethod,\n seasonalArimaForecastingMethod,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport type { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { ForecastingDivinerConfigSchema } from '@xyo-network/diviner-forecasting-model'\nimport type { DivinerInstance } from '@xyo-network/diviner-model'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport type { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = {\n addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp,\n }\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 }\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AIJ,MAAAA,GAASX,OAAOG,MAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push"]}
1
+ {"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 type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport type { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload } from '@xyo-network/diviner-boundwitness-model'\nimport { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport type { ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport { AbstractForecastingDiviner } from '@xyo-network/diviner-forecasting-abstract'\nimport type {\n arimaForecastingName,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport {\n arimaForecastingMethod,\n seasonalArimaForecastingMethod,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport type { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { ForecastingDivinerConfigSchema } from '@xyo-network/diviner-forecasting-model'\nimport type { DivinerInstance } from '@xyo-network/diviner-model'\nimport { asDivinerInstance } from '@xyo-network/diviner-model'\nimport type { ModuleFilter } from '@xyo-network/module-model'\nimport type { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n return (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n}\n\nconst defaultBatchLimit = 1000\nconst defaultMaxTrainingLength = 10_000\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, ForecastingDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = ForecastingDivinerConfigSchema\n\n protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {\n arimaForecasting: arimaForecastingMethod,\n seasonalArimaForecasting: seasonalArimaForecastingMethod,\n }\n\n get boundWitnessDiviner(): ModuleFilter {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured') as ModuleFilter\n }\n\n /**\n * The max number of records to search during the batch query\n */\n protected get batchLimit() {\n return this.config.batchLimit ?? defaultBatchLimit\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected get maxTrainingLength() {\n return this.config.maxTrainingLength ?? defaultMaxTrainingLength\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(_startTimestamp: number, _stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n // let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = {\n addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema,\n }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n // TODO; Replace with sequence\n // bw => bw.$timestamp && bw.$timestamp >= startTimestamp && bw.$timestamp <= stopTimestamp,\n _ => true,\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\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;AAGpC,SAASC,sCAAsC;AAE/C,SAASC,kCAAkC;AAK3C,SACEC,wBACAC,sCACK;AAEP,SAASC,sCAAsC;AAE/C,SAASC,yBAAyB;AAGlC,OAAOC,cAAc;AAIrB,IAAMC,yBAAyB,wBAACC,mBAAAA;AAC9B,SAAO,CAACC,MAAAA;AACN,UAAMC,MAAMC,SAASC,MAAMH,GAAGD,cAAAA;AAC9B,QAAI,OAAOE,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB;AACF,GAN+B;AAQ/B,IAAMC,oBAAoB;AAC1B,IAAMC,2BAA2B;AAE1B,IAAMC,2BAAN,MAAMA,kCAEHC,2BAAAA;EAvCV,OAuCUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,OAA0BE,wBAA6E;IACrGC,kBAAkBC;IAClBC,0BAA0BC;EAC5B;EAEA,IAAIC,sBAAoC;AACtC,WAAOC,SAAS,KAAKC,OAAOF,qBAAqB,MAAM,mCAAA;EACzD;;;;EAKA,IAAcG,aAAa;AACzB,WAAO,KAAKD,OAAOC,cAAcf;EACnC;EAEA,IAAuBgB,oBAAuC;AAC5D,UAAMC,wBAAwBJ,SAAS,KAAKC,OAAOE,mBAAmB,MAAM,qCAAA;AAC5E,UAAMA,oBAAoBd,0BAAyBK,sBAAsBU,qBAAAA;AACzE,QAAID,kBAAmB,QAAOA;AAC9B,UAAM,IAAIjB,MAAM,mCAAmCkB,qBAAAA,EAAuB;EAC5E;EAEA,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":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","pathExpression","x","ret","jsonpath","value","Error","defaultBatchLimit","defaultMaxTrainingLength","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","boundWitnessDiviner","assertEx","config","batchLimit","forecastingMethod","forecastingMethodName","maxTrainingLength","transformer","jsonPathExpression","getPayloadsInWindow","_startTimestamp","_stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","_","hashes","map","bw","payload_hashes","indexOf","exists","batchPayloads","get","push"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/diviner-forecasting-memory",
3
- "version": "3.5.2",
3
+ "version": "3.6.0-rc.10",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -29,25 +29,27 @@
29
29
  "module": "dist/neutral/index.mjs",
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "dependencies": {
32
- "@xylabs/assert": "^4.4.9",
33
- "@xylabs/exists": "^4.4.9",
34
- "@xyo-network/archivist-model": "^3.5.2",
35
- "@xyo-network/boundwitness-model": "^3.5.2",
36
- "@xyo-network/diviner-boundwitness-model": "^3.5.2",
37
- "@xyo-network/diviner-forecasting-abstract": "^3.5.2",
38
- "@xyo-network/diviner-forecasting-method-arima": "^3.5.2",
39
- "@xyo-network/diviner-forecasting-model": "^3.5.2",
40
- "@xyo-network/diviner-model": "^3.5.2",
41
- "@xyo-network/payload-model": "^3.5.2",
32
+ "@xylabs/assert": "^4.4.21",
33
+ "@xylabs/exists": "^4.4.21",
34
+ "@xyo-network/archivist-model": "^3.6.0-rc.10",
35
+ "@xyo-network/boundwitness-model": "^3.6.0-rc.10",
36
+ "@xyo-network/diviner-boundwitness-model": "^3.6.0-rc.10",
37
+ "@xyo-network/diviner-forecasting-abstract": "^3.6.0-rc.10",
38
+ "@xyo-network/diviner-forecasting-method-arima": "^3.6.0-rc.10",
39
+ "@xyo-network/diviner-forecasting-model": "^3.6.0-rc.10",
40
+ "@xyo-network/diviner-model": "^3.6.0-rc.10",
41
+ "@xyo-network/module-model": "^3.6.0-rc.10",
42
+ "@xyo-network/payload-model": "^3.6.0-rc.10",
42
43
  "jsonpath": "^1.1.1"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@types/jsonpath": "^0.2.4",
46
- "@xylabs/ts-scripts-yarn3": "^4.2.4",
47
- "@xylabs/tsconfig": "^4.2.4",
47
+ "@xylabs/ts-scripts-yarn3": "^4.2.6",
48
+ "@xylabs/tsconfig": "^4.2.6",
48
49
  "typescript": "^5.7.2"
49
50
  },
50
51
  "publishConfig": {
51
52
  "access": "public"
52
- }
53
+ },
54
+ "stableVersion": "3.5.2"
53
55
  }
@@ -18,6 +18,7 @@ import type { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/di
18
18
  import { ForecastingDivinerConfigSchema } from '@xyo-network/diviner-forecasting-model'
19
19
  import type { DivinerInstance } from '@xyo-network/diviner-model'
20
20
  import { asDivinerInstance } from '@xyo-network/diviner-model'
21
+ import type { ModuleFilter } from '@xyo-network/module-model'
21
22
  import type { Payload, Schema } from '@xyo-network/payload-model'
22
23
  import jsonpath from 'jsonpath'
23
24
 
@@ -45,8 +46,8 @@ export class MemoryForecastingDiviner<
45
46
  seasonalArimaForecasting: seasonalArimaForecastingMethod,
46
47
  }
47
48
 
48
- get boundWitnessDiviner() {
49
- return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')
49
+ get boundWitnessDiviner(): ModuleFilter {
50
+ return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured') as ModuleFilter
50
51
  }
51
52
 
52
53
  /**
@@ -72,7 +73,7 @@ export class MemoryForecastingDiviner<
72
73
  return getJsonPathTransformer(pathExpression)
73
74
  }
74
75
 
75
- protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {
76
+ protected override async getPayloadsInWindow(_startTimestamp: number, _stopTimestamp: number): Promise<Payload[]> {
76
77
  const addresses = this.config.witnessAddresses
77
78
  const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]
78
79
  const payloads: Payload[] = []
@@ -83,27 +84,30 @@ export class MemoryForecastingDiviner<
83
84
  ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>
84
85
  const limit = this.batchLimit
85
86
  const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')
86
- let timestamp = stopTimestamp
87
+ // let timestamp = stopTimestamp
87
88
  let more = true
88
89
 
89
90
  // TODO: Window size vs sample size
90
91
  // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window
91
92
  while (more || payloads.length < this.maxTrainingLength) {
92
93
  const query: BoundWitnessDivinerQueryPayload = {
93
- addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp,
94
+ addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema,
94
95
  }
95
96
  const boundWitnesses = (await bwDiviner.divine([query])).filter(
96
- bw => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,
97
+ // TODO; Replace with sequence
98
+ // bw => bw.$timestamp && bw.$timestamp >= startTimestamp && bw.$timestamp <= stopTimestamp,
99
+ _ => true,
97
100
  )
98
101
  if (boundWitnesses.length === 0) break
99
102
 
100
103
  // Update the timestamp value for the next batch
101
- timestamp = boundWitnesses
102
- .map(bw => bw.timestamp)
104
+ /* timestamp = boundWitnesses
105
+ .map(bw => bw.$timestamp)
103
106
  .filter(exists)
104
107
  // eslint-disable-next-line unicorn/no-array-reduce
105
108
  .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)
106
109
  if (timestamp === Number.MAX_SAFE_INTEGER) break
110
+ */
107
111
 
108
112
  // Set the more flag to false if there are fewer documents returned than the batch size
109
113
  more = boundWitnesses.length === limit