@xyo-network/diviner-forecasting-memory 2.75.15 → 2.75.17

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.
package/dist/docs.json CHANGED
@@ -3884,7 +3884,7 @@
3884
3884
  "fileName": "modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts",
3885
3885
  "line": 43,
3886
3886
  "character": 21,
3887
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/329e1cefafe53/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L43"
3887
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/88daee906ba30/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L43"
3888
3888
  }
3889
3889
  ],
3890
3890
  "type": {
@@ -4082,7 +4082,7 @@
4082
4082
  "fileName": "modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts",
4083
4083
  "line": 46,
4084
4084
  "character": 21,
4085
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/329e1cefafe53/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L46"
4085
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/88daee906ba30/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L46"
4086
4086
  }
4087
4087
  ],
4088
4088
  "type": {
@@ -4404,7 +4404,7 @@
4404
4404
  "fileName": "modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts",
4405
4405
  "line": 33,
4406
4406
  "character": 18,
4407
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/329e1cefafe53/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L33"
4407
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/88daee906ba30/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L33"
4408
4408
  }
4409
4409
  ],
4410
4410
  "type": {
@@ -4492,7 +4492,7 @@
4492
4492
  "fileName": "modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts",
4493
4493
  "line": 35,
4494
4494
  "character": 28,
4495
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/329e1cefafe53/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L35"
4495
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/88daee906ba30/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L35"
4496
4496
  }
4497
4497
  ],
4498
4498
  "type": {
@@ -4870,7 +4870,7 @@
4870
4870
  "fileName": "modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts",
4871
4871
  "line": 48,
4872
4872
  "character": 25,
4873
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/329e1cefafe53/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L48"
4873
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/88daee906ba30/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L48"
4874
4874
  }
4875
4875
  ],
4876
4876
  "getSignature": {
@@ -4884,7 +4884,7 @@
4884
4884
  "fileName": "modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts",
4885
4885
  "line": 48,
4886
4886
  "character": 25,
4887
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/329e1cefafe53/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L48"
4887
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/88daee906ba30/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L48"
4888
4888
  }
4889
4889
  ],
4890
4890
  "type": {
@@ -5230,7 +5230,7 @@
5230
5230
  "fileName": "modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts",
5231
5231
  "line": 55,
5232
5232
  "character": 25,
5233
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/329e1cefafe53/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L55"
5233
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/88daee906ba30/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L55"
5234
5234
  }
5235
5235
  ],
5236
5236
  "getSignature": {
@@ -5244,7 +5244,7 @@
5244
5244
  "fileName": "modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts",
5245
5245
  "line": 55,
5246
5246
  "character": 25,
5247
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/329e1cefafe53/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L55"
5247
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/88daee906ba30/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L55"
5248
5248
  }
5249
5249
  ],
5250
5250
  "type": {
@@ -8903,7 +8903,7 @@
8903
8903
  "fileName": "modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts",
8904
8904
  "line": 60,
8905
8905
  "character": 27,
8906
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/329e1cefafe53/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L60"
8906
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/88daee906ba30/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L60"
8907
8907
  }
8908
8908
  ],
8909
8909
  "signatures": [
@@ -8918,7 +8918,7 @@
8918
8918
  "fileName": "modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts",
8919
8919
  "line": 60,
8920
8920
  "character": 27,
8921
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/329e1cefafe53/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L60"
8921
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/88daee906ba30/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L60"
8922
8922
  }
8923
8923
  ],
8924
8924
  "parameters": [
@@ -18058,7 +18058,7 @@
18058
18058
  "fileName": "modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts",
18059
18059
  "line": 30,
18060
18060
  "character": 13,
18061
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/329e1cefafe53/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L30"
18061
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/88daee906ba30/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L30"
18062
18062
  }
18063
18063
  ],
18064
18064
  "typeParameters": [
@@ -18119,7 +18119,7 @@
18119
18119
  "fileName": "modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts",
18120
18120
  "line": 18,
18121
18121
  "character": 12,
18122
- "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/329e1cefafe53/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L18"
18122
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/blob/88daee906ba30/packages/modules/packages/diviner/packages/forecasting/packages/memory/src/MemoryForecastingDiviner.ts#L18"
18123
18123
  }
18124
18124
  ],
18125
18125
  "type": {
package/package.json CHANGED
@@ -10,22 +10,22 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xylabs/assert": "^2.12.22",
14
- "@xylabs/exists": "^2.12.22",
15
- "@xyo-network/archivist-model": "~2.75.15",
16
- "@xyo-network/boundwitness-model": "~2.75.15",
17
- "@xyo-network/diviner-boundwitness-model": "~2.75.15",
18
- "@xyo-network/diviner-forecasting-abstract": "~2.75.15",
19
- "@xyo-network/diviner-forecasting-method-arima": "~2.75.15",
20
- "@xyo-network/diviner-forecasting-model": "~2.75.15",
21
- "@xyo-network/diviner-model": "~2.75.15",
22
- "@xyo-network/payload-model": "~2.75.15",
13
+ "@xylabs/assert": "^2.12.24",
14
+ "@xylabs/exists": "^2.12.24",
15
+ "@xyo-network/archivist-model": "~2.75.17",
16
+ "@xyo-network/boundwitness-model": "~2.75.17",
17
+ "@xyo-network/diviner-boundwitness-model": "~2.75.17",
18
+ "@xyo-network/diviner-forecasting-abstract": "~2.75.17",
19
+ "@xyo-network/diviner-forecasting-method-arima": "~2.75.17",
20
+ "@xyo-network/diviner-forecasting-model": "~2.75.17",
21
+ "@xyo-network/diviner-model": "~2.75.17",
22
+ "@xyo-network/payload-model": "~2.75.17",
23
23
  "jsonpath": "^1.1.1"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/jsonpath": "^0.2.1",
27
- "@xylabs/ts-scripts-yarn3": "^3.0.88",
28
- "@xylabs/tsconfig": "^3.0.88",
27
+ "@xylabs/ts-scripts-yarn3": "^3.1.9",
28
+ "@xylabs/tsconfig": "^3.1.9",
29
29
  "typescript": "^5.2.2"
30
30
  },
31
31
  "description": "Primary SDK for using XYO Protocol 2.0",
@@ -71,5 +71,5 @@
71
71
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
72
72
  },
73
73
  "sideEffects": false,
74
- "version": "2.75.15"
74
+ "version": "2.75.17"
75
75
  }
@@ -1,107 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/MemoryForecastingDiviner.ts
31
- var MemoryForecastingDiviner_exports = {};
32
- __export(MemoryForecastingDiviner_exports, {
33
- MemoryForecastingDiviner: () => MemoryForecastingDiviner
34
- });
35
- module.exports = __toCommonJS(MemoryForecastingDiviner_exports);
36
- var import_assert = require("@xylabs/assert");
37
- var import_exists = require("@xylabs/exists");
38
- var import_archivist_model = require("@xyo-network/archivist-model");
39
- var import_diviner_boundwitness_model = require("@xyo-network/diviner-boundwitness-model");
40
- var import_diviner_forecasting_abstract = require("@xyo-network/diviner-forecasting-abstract");
41
- var import_diviner_forecasting_method_arima = require("@xyo-network/diviner-forecasting-method-arima");
42
- var import_diviner_forecasting_model = require("@xyo-network/diviner-forecasting-model");
43
- var import_diviner_model = require("@xyo-network/diviner-model");
44
- var import_jsonpath = __toESM(require("jsonpath"));
45
- var getJsonPathTransformer = (pathExpression) => {
46
- const transformer = (x) => {
47
- const ret = import_jsonpath.default.value(x, pathExpression);
48
- if (typeof ret === "number")
49
- return ret;
50
- throw new Error("Parsed invalid payload value");
51
- };
52
- return transformer;
53
- };
54
- var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_diviner_forecasting_abstract.AbstractForecastingDiviner {
55
- static configSchemas = [import_diviner_forecasting_model.ForecastingDivinerConfigSchema];
56
- static forecastingMethodDict = {
57
- arimaForecasting: import_diviner_forecasting_method_arima.arimaForecastingMethod,
58
- seasonalArimaForecasting: import_diviner_forecasting_method_arima.seasonalArimaForecastingMethod
59
- };
60
- /**
61
- * The max number of records to search during the batch query
62
- */
63
- batchLimit = 1e3;
64
- // TODO: Inject via config
65
- maxTrainingLength = 1e4;
66
- get forecastingMethod() {
67
- const forecastingMethodName = (0, import_assert.assertEx)(this.config.forecastingMethod, "Missing forecastingMethod in config");
68
- const forecastingMethod = _MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName];
69
- if (forecastingMethod)
70
- return forecastingMethod;
71
- throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
72
- }
73
- get transformer() {
74
- const pathExpression = (0, import_assert.assertEx)(this.config.jsonPathExpression, "Missing jsonPathExpression in config");
75
- return getJsonPathTransformer(pathExpression);
76
- }
77
- async getPayloadsInWindow(startTimestamp, stopTimestamp) {
78
- const addresses = this.config.witnessAddresses;
79
- const payload_schemas = [(0, import_assert.assertEx)(this.config.witnessSchema, "Missing witnessSchema in config")];
80
- const payloads = [];
81
- const archivist = (0, import_archivist_model.asArchivistInstance)(await this.readArchivist(), "Unable to resolve archivist");
82
- const bwDiviner = (0, import_diviner_model.asDivinerInstance)((await this.resolve(this.config.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
83
- const limit = this.batchLimit;
84
- const witnessSchema = (0, import_assert.assertEx)(this.config.witnessSchema, "Missing witnessSchema in config");
85
- let timestamp = stopTimestamp;
86
- let more = true;
87
- while (more || payloads.length < this.maxTrainingLength) {
88
- const query = { addresses, limit, payload_schemas, schema: import_diviner_boundwitness_model.BoundWitnessDivinerQuerySchema, timestamp };
89
- const boundWitnesses = (await bwDiviner.divine([query])).filter(
90
- (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp
91
- );
92
- if (boundWitnesses.length === 0)
93
- break;
94
- timestamp = boundWitnesses.map((bw) => bw.timestamp).filter(import_exists.exists).reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER);
95
- if (timestamp === Number.MAX_SAFE_INTEGER)
96
- break;
97
- more = boundWitnesses.length === limit;
98
- const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.findIndex((s) => s === witnessSchema)]).filter(import_exists.exists);
99
- if (hashes.length !== 0) {
100
- const batchPayloads = (await archivist.get(hashes)).filter(import_exists.exists);
101
- payloads.push(...batchPayloads);
102
- }
103
- }
104
- return payloads;
105
- }
106
- };
107
- //# sourceMappingURL=MemoryForecastingDiviner.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { 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 = 1_000\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 .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.findIndex((s) => s === 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;AAAA,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,kCA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Aa;AAAA,MAC5E;AACA,UAAI,eAAe,WAAW;AAAG;AAGjC,kBAAY,eACT,IAAI,CAAC,OAAO,GAAG,SAAS,EACxB,OAAO,oBAAM,EACb,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,UAAU,CAAC,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,OAAO,oBAAM;AAGpI,UAAI,OAAO,WAAW,GAAG;AACvB,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,79 +0,0 @@
1
- // src/MemoryForecastingDiviner.ts
2
- import { assertEx } from "@xylabs/assert";
3
- import { exists } from "@xylabs/exists";
4
- import { asArchivistInstance } from "@xyo-network/archivist-model";
5
- import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
6
- import { AbstractForecastingDiviner } from "@xyo-network/diviner-forecasting-abstract";
7
- import {
8
- arimaForecastingMethod,
9
- seasonalArimaForecastingMethod
10
- } from "@xyo-network/diviner-forecasting-method-arima";
11
- import { ForecastingDivinerConfigSchema } from "@xyo-network/diviner-forecasting-model";
12
- import { asDivinerInstance } from "@xyo-network/diviner-model";
13
- import jsonpath from "jsonpath";
14
- var getJsonPathTransformer = (pathExpression) => {
15
- const transformer = (x) => {
16
- const ret = jsonpath.value(x, pathExpression);
17
- if (typeof ret === "number")
18
- return ret;
19
- throw new Error("Parsed invalid payload value");
20
- };
21
- return transformer;
22
- };
23
- var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractForecastingDiviner {
24
- static configSchemas = [ForecastingDivinerConfigSchema];
25
- static forecastingMethodDict = {
26
- arimaForecasting: arimaForecastingMethod,
27
- seasonalArimaForecasting: seasonalArimaForecastingMethod
28
- };
29
- /**
30
- * The max number of records to search during the batch query
31
- */
32
- batchLimit = 1e3;
33
- // TODO: Inject via config
34
- maxTrainingLength = 1e4;
35
- get forecastingMethod() {
36
- const forecastingMethodName = assertEx(this.config.forecastingMethod, "Missing forecastingMethod in config");
37
- const forecastingMethod = _MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName];
38
- if (forecastingMethod)
39
- return forecastingMethod;
40
- throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
41
- }
42
- get transformer() {
43
- const pathExpression = assertEx(this.config.jsonPathExpression, "Missing jsonPathExpression in config");
44
- return getJsonPathTransformer(pathExpression);
45
- }
46
- async getPayloadsInWindow(startTimestamp, stopTimestamp) {
47
- const addresses = this.config.witnessAddresses;
48
- const payload_schemas = [assertEx(this.config.witnessSchema, "Missing witnessSchema in config")];
49
- const payloads = [];
50
- const archivist = asArchivistInstance(await this.readArchivist(), "Unable to resolve archivist");
51
- const bwDiviner = asDivinerInstance((await this.resolve(this.config.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
52
- const limit = this.batchLimit;
53
- const witnessSchema = assertEx(this.config.witnessSchema, "Missing witnessSchema in config");
54
- let timestamp = stopTimestamp;
55
- let more = true;
56
- while (more || payloads.length < this.maxTrainingLength) {
57
- const query = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp };
58
- const boundWitnesses = (await bwDiviner.divine([query])).filter(
59
- (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp
60
- );
61
- if (boundWitnesses.length === 0)
62
- break;
63
- timestamp = boundWitnesses.map((bw) => bw.timestamp).filter(exists).reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER);
64
- if (timestamp === Number.MAX_SAFE_INTEGER)
65
- break;
66
- more = boundWitnesses.length === limit;
67
- const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.findIndex((s) => s === witnessSchema)]).filter(exists);
68
- if (hashes.length !== 0) {
69
- const batchPayloads = (await archivist.get(hashes)).filter(exists);
70
- payloads.push(...batchPayloads);
71
- }
72
- }
73
- return payloads;
74
- }
75
- };
76
- export {
77
- MemoryForecastingDiviner
78
- };
79
- //# sourceMappingURL=MemoryForecastingDiviner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { 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 = 1_000\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 .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.findIndex((s) => s === 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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AU,IAAI,MAAM,GAAG,OAAO,MAAM;AACjE,iBAAS,KAAK,GAAG,aAAa;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1,111 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/MemoryForecastingDiviner.ts
31
- var MemoryForecastingDiviner_exports = {};
32
- __export(MemoryForecastingDiviner_exports, {
33
- MemoryForecastingDiviner: () => MemoryForecastingDiviner
34
- });
35
- module.exports = __toCommonJS(MemoryForecastingDiviner_exports);
36
- var import_assert = require("@xylabs/assert");
37
- var import_exists = require("@xylabs/exists");
38
- var import_archivist_model = require("@xyo-network/archivist-model");
39
- var import_diviner_boundwitness_model = require("@xyo-network/diviner-boundwitness-model");
40
- var import_diviner_forecasting_abstract = require("@xyo-network/diviner-forecasting-abstract");
41
- var import_diviner_forecasting_method_arima = require("@xyo-network/diviner-forecasting-method-arima");
42
- var import_diviner_forecasting_model = require("@xyo-network/diviner-forecasting-model");
43
- var import_diviner_model = require("@xyo-network/diviner-model");
44
- var import_jsonpath = __toESM(require("jsonpath"));
45
- var getJsonPathTransformer = (pathExpression) => {
46
- const transformer = (x) => {
47
- const ret = import_jsonpath.default.value(x, pathExpression);
48
- if (typeof ret === "number")
49
- return ret;
50
- throw new Error("Parsed invalid payload value");
51
- };
52
- return transformer;
53
- };
54
- var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_diviner_forecasting_abstract.AbstractForecastingDiviner {
55
- static configSchemas = [import_diviner_forecasting_model.ForecastingDivinerConfigSchema];
56
- static forecastingMethodDict = {
57
- arimaForecasting: import_diviner_forecasting_method_arima.arimaForecastingMethod,
58
- seasonalArimaForecasting: import_diviner_forecasting_method_arima.seasonalArimaForecastingMethod
59
- };
60
- /**
61
- * The max number of records to search during the batch query
62
- */
63
- batchLimit = 1e3;
64
- // TODO: Inject via config
65
- maxTrainingLength = 1e4;
66
- get forecastingMethod() {
67
- const forecastingMethodName = (0, import_assert.assertEx)(this.config.forecastingMethod, "Missing forecastingMethod in config");
68
- const forecastingMethod = _MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName];
69
- if (forecastingMethod)
70
- return forecastingMethod;
71
- throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
72
- }
73
- get transformer() {
74
- const pathExpression = (0, import_assert.assertEx)(this.config.jsonPathExpression, "Missing jsonPathExpression in config");
75
- return getJsonPathTransformer(pathExpression);
76
- }
77
- async getPayloadsInWindow(startTimestamp, stopTimestamp) {
78
- const addresses = this.config.witnessAddresses;
79
- const payload_schemas = [(0, import_assert.assertEx)(this.config.witnessSchema, "Missing witnessSchema in config")];
80
- const payloads = [];
81
- const archivist = (0, import_archivist_model.asArchivistInstance)(await this.readArchivist(), "Unable to resolve archivist");
82
- const bwDiviner = (0, import_diviner_model.asDivinerInstance)((await this.resolve(this.config.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
83
- const limit = this.batchLimit;
84
- const witnessSchema = (0, import_assert.assertEx)(this.config.witnessSchema, "Missing witnessSchema in config");
85
- let timestamp = stopTimestamp;
86
- let more = true;
87
- while (more || payloads.length < this.maxTrainingLength) {
88
- const query = { addresses, limit, payload_schemas, schema: import_diviner_boundwitness_model.BoundWitnessDivinerQuerySchema, timestamp };
89
- const boundWitnesses = (await bwDiviner.divine([query])).filter(
90
- (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp
91
- );
92
- if (boundWitnesses.length === 0)
93
- break;
94
- timestamp = boundWitnesses.map((bw) => bw.timestamp).filter(import_exists.exists).reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER);
95
- if (timestamp === Number.MAX_SAFE_INTEGER)
96
- break;
97
- more = boundWitnesses.length === limit;
98
- const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.findIndex((s) => s === witnessSchema)]).filter(import_exists.exists);
99
- if (hashes.length !== 0) {
100
- const batchPayloads = (await archivist.get(hashes)).filter(import_exists.exists);
101
- payloads.push(...batchPayloads);
102
- }
103
- }
104
- return payloads;
105
- }
106
- };
107
- // Annotate the CommonJS export names for ESM import in node:
108
- 0 && (module.exports = {
109
- MemoryForecastingDiviner
110
- });
111
- //# sourceMappingURL=MemoryForecastingDiviner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { 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 = 1_000\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 .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.findIndex((s) => s === 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;AAAA,oBAAyB;AACzB,oBAAuB;AACvB,6BAAoC;AAEpC,wCAAgF;AAChF,0CAAqE;AACrE,8CAKO;AACP,uCAA2F;AAC3F,2BAA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AY;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,EACb,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,UAAU,CAAC,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,OAAO,oBAAM;AAGpI,UAAI,OAAO,WAAW,GAAG;AACvB,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,79 +0,0 @@
1
- // src/MemoryForecastingDiviner.ts
2
- import { assertEx } from "@xylabs/assert";
3
- import { exists } from "@xylabs/exists";
4
- import { asArchivistInstance } from "@xyo-network/archivist-model";
5
- import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
6
- import { AbstractForecastingDiviner } from "@xyo-network/diviner-forecasting-abstract";
7
- import {
8
- arimaForecastingMethod,
9
- seasonalArimaForecastingMethod
10
- } from "@xyo-network/diviner-forecasting-method-arima";
11
- import { ForecastingDivinerConfigSchema } from "@xyo-network/diviner-forecasting-model";
12
- import { asDivinerInstance } from "@xyo-network/diviner-model";
13
- import jsonpath from "jsonpath";
14
- var getJsonPathTransformer = (pathExpression) => {
15
- const transformer = (x) => {
16
- const ret = jsonpath.value(x, pathExpression);
17
- if (typeof ret === "number")
18
- return ret;
19
- throw new Error("Parsed invalid payload value");
20
- };
21
- return transformer;
22
- };
23
- var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractForecastingDiviner {
24
- static configSchemas = [ForecastingDivinerConfigSchema];
25
- static forecastingMethodDict = {
26
- arimaForecasting: arimaForecastingMethod,
27
- seasonalArimaForecasting: seasonalArimaForecastingMethod
28
- };
29
- /**
30
- * The max number of records to search during the batch query
31
- */
32
- batchLimit = 1e3;
33
- // TODO: Inject via config
34
- maxTrainingLength = 1e4;
35
- get forecastingMethod() {
36
- const forecastingMethodName = assertEx(this.config.forecastingMethod, "Missing forecastingMethod in config");
37
- const forecastingMethod = _MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName];
38
- if (forecastingMethod)
39
- return forecastingMethod;
40
- throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
41
- }
42
- get transformer() {
43
- const pathExpression = assertEx(this.config.jsonPathExpression, "Missing jsonPathExpression in config");
44
- return getJsonPathTransformer(pathExpression);
45
- }
46
- async getPayloadsInWindow(startTimestamp, stopTimestamp) {
47
- const addresses = this.config.witnessAddresses;
48
- const payload_schemas = [assertEx(this.config.witnessSchema, "Missing witnessSchema in config")];
49
- const payloads = [];
50
- const archivist = asArchivistInstance(await this.readArchivist(), "Unable to resolve archivist");
51
- const bwDiviner = asDivinerInstance((await this.resolve(this.config.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
52
- const limit = this.batchLimit;
53
- const witnessSchema = assertEx(this.config.witnessSchema, "Missing witnessSchema in config");
54
- let timestamp = stopTimestamp;
55
- let more = true;
56
- while (more || payloads.length < this.maxTrainingLength) {
57
- const query = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp };
58
- const boundWitnesses = (await bwDiviner.divine([query])).filter(
59
- (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp
60
- );
61
- if (boundWitnesses.length === 0)
62
- break;
63
- timestamp = boundWitnesses.map((bw) => bw.timestamp).filter(exists).reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER);
64
- if (timestamp === Number.MAX_SAFE_INTEGER)
65
- break;
66
- more = boundWitnesses.length === limit;
67
- const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.findIndex((s) => s === witnessSchema)]).filter(exists);
68
- if (hashes.length !== 0) {
69
- const batchPayloads = (await archivist.get(hashes)).filter(exists);
70
- payloads.push(...batchPayloads);
71
- }
72
- }
73
- return payloads;
74
- }
75
- };
76
- export {
77
- MemoryForecastingDiviner
78
- };
79
- //# sourceMappingURL=MemoryForecastingDiviner.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { 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 = 1_000\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 .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.findIndex((s) => s === 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;AAA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