@xyo-network/diviner-forecasting-memory 2.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ import { assertEx } from '@xylabs/assert';
2
+ import { exists } from '@xylabs/exists';
3
+ import { ArchivistWrapper } from '@xyo-network/archivist-wrapper';
4
+ import { BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model';
5
+ import { AbstractForecastingDiviner } from '@xyo-network/diviner-forecasting-abstract';
6
+ import { arimaForecastingMethod, seasonalArimaForecastingMethod, } from '@xyo-network/diviner-forecasting-method-arima';
7
+ import { ForecastingDivinerConfigSchema } from '@xyo-network/diviner-forecasting-model';
8
+ import { DivinerWrapper } from '@xyo-network/diviner-wrapper';
9
+ import { value } from 'jsonpath';
10
+ const getJsonPathTransformer = (pathExpression) => {
11
+ const transformer = (x) => {
12
+ const ret = value(x, pathExpression);
13
+ if (typeof ret === 'number')
14
+ return ret;
15
+ throw new Error('Parsed invalid payload value');
16
+ };
17
+ return transformer;
18
+ };
19
+ export class MemoryForecastingDiviner extends AbstractForecastingDiviner {
20
+ static configSchema = ForecastingDivinerConfigSchema;
21
+ static forecastingMethodDict = {
22
+ arimaForecasting: arimaForecastingMethod,
23
+ seasonalArimaForecasting: seasonalArimaForecastingMethod,
24
+ };
25
+ /**
26
+ * The max number of records to search during the batch query
27
+ */
28
+ batchLimit = 1_000;
29
+ // TODO: Inject via config
30
+ maxTrainingLength = 10_000;
31
+ get forecastingMethod() {
32
+ const forecastingMethodName = assertEx(this.config.forecastingMethod, 'Missing forecastingMethod in config');
33
+ const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName];
34
+ if (forecastingMethod)
35
+ return forecastingMethod;
36
+ throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
37
+ }
38
+ get transformer() {
39
+ const pathExpression = assertEx(this.config.jsonPathExpression, 'Missing jsonPathExpression in config');
40
+ return getJsonPathTransformer(pathExpression);
41
+ }
42
+ async getPayloadsInWindow(startTimestamp, stopTimestamp) {
43
+ const addresses = this.config.witnessAddresses;
44
+ const payload_schemas = [assertEx(this.config.witnessSchema, 'Missing witnessSchema in config')];
45
+ const payloads = [];
46
+ const archivistMod = assertEx((await this.upResolver.resolve(this.config.archivist)).pop(), 'Unable to resolve archivist');
47
+ const archivist = ArchivistWrapper.wrap(archivistMod);
48
+ const bwDivinerMod = assertEx((await this.upResolver.resolve(this.config.boundWitnessDiviner)).pop(), 'Unable to resolve boundWitnessDiviner');
49
+ const bwDiviner = DivinerWrapper.wrap(bwDivinerMod);
50
+ const limit = this.batchLimit;
51
+ const witnessSchema = assertEx(this.config.witnessSchema, 'Missing witnessSchema in config');
52
+ let timestamp = stopTimestamp;
53
+ let more = true;
54
+ // TODO: Window size vs sample size
55
+ // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window
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((bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp);
59
+ if (boundWitnesses.length === 0)
60
+ break;
61
+ // Update the timestamp value for the next batch
62
+ timestamp = boundWitnesses
63
+ .map((bw) => bw.timestamp)
64
+ .filter(exists)
65
+ .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER);
66
+ if (timestamp === Number.MAX_SAFE_INTEGER)
67
+ break;
68
+ // Set the more flag to false if there are fewer documents returned than the batch size
69
+ more = boundWitnesses.length === limit;
70
+ // Get the corresponding payload hashes from the BWs
71
+ const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.findIndex((s) => s === witnessSchema)]).filter(exists);
72
+ // Get the payloads corresponding to the BW hashes from the archivist
73
+ if (hashes.length !== 0) {
74
+ const batchPayloads = await archivist.get(hashes);
75
+ payloads.push(...batchPayloads);
76
+ }
77
+ }
78
+ return payloads;
79
+ }
80
+ }
81
+ //# sourceMappingURL=MemoryForecastingDiviner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryForecastingDiviner.js","sourceRoot":"","sources":["../../src/MemoryForecastingDiviner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAEjE,OAAO,EAAmC,8BAA8B,EAAE,MAAM,yCAAyC,CAAA;AACzH,OAAO,EAAE,0BAA0B,EAA4B,MAAM,2CAA2C,CAAA;AAChH,OAAO,EACL,sBAAsB,EAEtB,8BAA8B,GAE/B,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,8BAA8B,EAA8C,MAAM,wCAAwC,CAAA;AACnI,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAE7D,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAIhC,MAAM,sBAAsB,GAAG,CAAC,cAAsB,EAA2B,EAAE;IACjF,MAAM,WAAW,GAAG,CAAC,CAAU,EAAU,EAAE;QACzC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAA;QACpC,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,GAAG,CAAA;QACvC,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC,CAAA;IACD,OAAO,WAAW,CAAA;AACpB,CAAC,CAAA;AAED,MAAM,OAAO,wBAEX,SAAQ,0BAAmC;IAC3C,MAAM,CAAU,YAAY,GAAG,8BAA8B,CAAA;IAEnD,MAAM,CAAU,qBAAqB,GAAwD;QACrG,gBAAgB,EAAE,sBAAsB;QACxC,wBAAwB,EAAE,8BAA8B;KACzD,CAAA;IAED;;OAEG;IACgB,UAAU,GAAG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AAoD;YACpD,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAErI,qEAAqE;YACrE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;gBACvB,MAAM,aAAa,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;gBACjD,QAAQ,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAA;aAChC;SACF;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './MemoryForecastingDiviner';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA"}
@@ -0,0 +1,19 @@
1
+ import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract';
2
+ import { arimaForecastingName, seasonalArimaForecastingName } from '@xyo-network/diviner-forecasting-method-arima';
3
+ import { ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model';
4
+ import { Payload } from '@xyo-network/payload-model';
5
+ type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName;
6
+ export declare class MemoryForecastingDiviner<TParams extends ForecastingDivinerParams = ForecastingDivinerParams> extends AbstractForecastingDiviner<TParams> {
7
+ static configSchema: "network.xyo.diviner.forecasting.config";
8
+ protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod>;
9
+ /**
10
+ * The max number of records to search during the batch query
11
+ */
12
+ protected readonly batchLimit = 1000;
13
+ protected readonly maxTrainingLength = 10000;
14
+ protected get forecastingMethod(): ForecastingMethod;
15
+ protected get transformer(): PayloadValueTransformer;
16
+ protected getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]>;
17
+ }
18
+ export {};
19
+ //# sourceMappingURL=MemoryForecastingDiviner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryForecastingDiviner.d.ts","sourceRoot":"","sources":["../../src/MemoryForecastingDiviner.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAA;AAChH,OAAO,EAEL,oBAAoB,EAEpB,4BAA4B,EAC7B,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAkC,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAEnI,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAGpD,KAAK,wBAAwB,GAAG,OAAO,oBAAoB,GAAG,OAAO,4BAA4B,CAAA;AAWjG,qBAAa,wBAAwB,CACnC,OAAO,SAAS,wBAAwB,GAAG,wBAAwB,CACnE,SAAQ,0BAA0B,CAAC,OAAO,CAAC;IAC3C,OAAgB,YAAY,2CAAiC;IAE7D,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAGnG;IAED;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,UAAU,QAAQ;IAGrC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,SAAS;IAE7C,cAAuB,iBAAiB,IAAI,iBAAiB,CAK5D;IAED,cAAuB,WAAW,IAAI,uBAAuB,CAG5D;cAEwB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA2ChH"}
@@ -0,0 +1,2 @@
1
+ export * from './MemoryForecastingDiviner';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@xyo-network/diviner-forecasting-memory",
3
+ "author": {
4
+ "email": "support@xyo.network",
5
+ "name": "XYO Development Team",
6
+ "url": "https://xyo.network"
7
+ },
8
+ "bugs": {
9
+ "email": "support@xyo.network",
10
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
+ },
12
+ "dependencies": {
13
+ "@types/jsonpath": "^0.2.0",
14
+ "@xylabs/assert": "^2.7.6",
15
+ "@xylabs/exists": "^2.7.6",
16
+ "@xyo-network/archivist-wrapper": "^2.56.0",
17
+ "@xyo-network/boundwitness-model": "^2.56.0",
18
+ "@xyo-network/diviner-boundwitness-model": "^2.56.0",
19
+ "@xyo-network/diviner-forecasting-abstract": "^2.56.0",
20
+ "@xyo-network/diviner-forecasting-method-arima": "^2.56.0",
21
+ "@xyo-network/diviner-forecasting-model": "^2.56.0",
22
+ "@xyo-network/diviner-wrapper": "^2.56.0",
23
+ "@xyo-network/payload-model": "^2.56.0",
24
+ "jsonpath": "^1.1.1"
25
+ },
26
+ "devDependencies": {
27
+ "@xylabs/ts-scripts-yarn3": "^2.16.5",
28
+ "@xylabs/tsconfig": "^2.16.5",
29
+ "typescript": "^4.9.5"
30
+ },
31
+ "description": "Primary SDK for using XYO Protocol 2.0",
32
+ "browser": "dist/esm/index.js",
33
+ "docs": "dist/docs.json",
34
+ "exports": {
35
+ ".": {
36
+ "node": {
37
+ "import": "./dist/esm/index.js",
38
+ "require": "./dist/cjs/index.js"
39
+ },
40
+ "browser": {
41
+ "import": "./dist/esm/index.js",
42
+ "require": "./dist/cjs/index.js"
43
+ },
44
+ "default": "./dist/esm/index.js"
45
+ },
46
+ "./dist/docs.json": {
47
+ "default": "./dist/docs.json"
48
+ },
49
+ "./package.json": "./package.json"
50
+ },
51
+ "main": "dist/cjs/index.js",
52
+ "module": "dist/esm/index.js",
53
+ "homepage": "https://xyo.network",
54
+ "license": "LGPL-3.0",
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
61
+ },
62
+ "sideEffects": false,
63
+ "types": "dist/types/index.d.ts",
64
+ "version": "2.56.0"
65
+ }
@@ -0,0 +1,102 @@
1
+ import { assertEx } from '@xylabs/assert'
2
+ import { exists } from '@xylabs/exists'
3
+ import { ArchivistWrapper } from '@xyo-network/archivist-wrapper'
4
+ import { BoundWitness } from '@xyo-network/boundwitness-model'
5
+ import { BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'
6
+ import { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'
7
+ import {
8
+ arimaForecastingMethod,
9
+ arimaForecastingName,
10
+ seasonalArimaForecastingMethod,
11
+ seasonalArimaForecastingName,
12
+ } from '@xyo-network/diviner-forecasting-method-arima'
13
+ import { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'
14
+ import { DivinerWrapper } from '@xyo-network/diviner-wrapper'
15
+ import { Payload } from '@xyo-network/payload-model'
16
+ import { value } from 'jsonpath'
17
+
18
+ type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName
19
+
20
+ const getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {
21
+ const transformer = (x: Payload): number => {
22
+ const ret = value(x, pathExpression)
23
+ if (typeof ret === 'number') return ret
24
+ throw new Error('Parsed invalid payload value')
25
+ }
26
+ return transformer
27
+ }
28
+
29
+ export class MemoryForecastingDiviner<
30
+ TParams extends ForecastingDivinerParams = ForecastingDivinerParams,
31
+ > extends AbstractForecastingDiviner<TParams> {
32
+ static override configSchema = ForecastingDivinerConfigSchema
33
+
34
+ protected static readonly forecastingMethodDict: Record<SupportedForecastingType, ForecastingMethod> = {
35
+ arimaForecasting: arimaForecastingMethod,
36
+ seasonalArimaForecasting: seasonalArimaForecastingMethod,
37
+ }
38
+
39
+ /**
40
+ * The max number of records to search during the batch query
41
+ */
42
+ protected readonly batchLimit = 1_000
43
+
44
+ // TODO: Inject via config
45
+ protected readonly maxTrainingLength = 10_000
46
+
47
+ protected override get forecastingMethod(): ForecastingMethod {
48
+ const forecastingMethodName = assertEx(this.config.forecastingMethod, 'Missing forecastingMethod in config') as SupportedForecastingType
49
+ const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]
50
+ if (forecastingMethod) return forecastingMethod
51
+ throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)
52
+ }
53
+
54
+ protected override get transformer(): PayloadValueTransformer {
55
+ const pathExpression = assertEx(this.config.jsonPathExpression, 'Missing jsonPathExpression in config')
56
+ return getJsonPathTransformer(pathExpression)
57
+ }
58
+
59
+ protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {
60
+ const addresses = this.config.witnessAddresses
61
+ const payload_schemas = [assertEx(this.config.witnessSchema, 'Missing witnessSchema in config')]
62
+ const payloads: Payload[] = []
63
+ const archivistMod = assertEx((await this.upResolver.resolve(this.config.archivist)).pop(), 'Unable to resolve archivist')
64
+ const archivist = ArchivistWrapper.wrap(archivistMod)
65
+ const bwDivinerMod = assertEx((await this.upResolver.resolve(this.config.boundWitnessDiviner)).pop(), 'Unable to resolve boundWitnessDiviner')
66
+ const bwDiviner = DivinerWrapper.wrap(bwDivinerMod)
67
+ const limit = this.batchLimit
68
+ const witnessSchema = assertEx(this.config.witnessSchema, 'Missing witnessSchema in config')
69
+ let timestamp = stopTimestamp
70
+ let more = true
71
+
72
+ // TODO: Window size vs sample size
73
+ // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window
74
+ while (more || payloads.length < this.maxTrainingLength) {
75
+ const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }
76
+ const boundWitnesses = ((await bwDiviner.divine([query])) as BoundWitness[]).filter(
77
+ (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,
78
+ )
79
+ if (boundWitnesses.length === 0) break
80
+
81
+ // Update the timestamp value for the next batch
82
+ timestamp = boundWitnesses
83
+ .map((bw) => bw.timestamp)
84
+ .filter(exists)
85
+ .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)
86
+ if (timestamp === Number.MAX_SAFE_INTEGER) break
87
+
88
+ // Set the more flag to false if there are fewer documents returned than the batch size
89
+ more = boundWitnesses.length === limit
90
+
91
+ // Get the corresponding payload hashes from the BWs
92
+ const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.findIndex((s) => s === witnessSchema)]).filter(exists)
93
+
94
+ // Get the payloads corresponding to the BW hashes from the archivist
95
+ if (hashes.length !== 0) {
96
+ const batchPayloads = await archivist.get(hashes)
97
+ payloads.push(...batchPayloads)
98
+ }
99
+ }
100
+ return payloads
101
+ }
102
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './MemoryForecastingDiviner'