@xyo-network/diviner-forecasting-memory 2.107.3 → 2.107.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,124 @@
1
- "use strict";var I=Object.create;var a=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var h=(i,t)=>a(i,"name",{value:t,configurable:!0});var j=(i,t)=>{for(var s in t)a(i,s,{get:t[s],enumerable:!0})},M=(i,t,s,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of P(t))!T.call(i,o)&&o!==s&&a(i,o,{get:()=>t[o],enumerable:!(n=N(t,o))||n.enumerable});return i};var U=(i,t,s)=>(s=i!=null?I(L(i)):{},M(t||!i||!i.__esModule?a(s,"default",{value:i,enumerable:!0}):s,i)),k=i=>M(a({},"__esModule",{value:!0}),i);var G={};j(G,{MemoryForecastingDiviner:()=>l});module.exports=k(G);var r=require("@xylabs/assert"),m=require("@xylabs/exists"),w=require("@xyo-network/archivist-model"),E=require("@xyo-network/diviner-boundwitness-model"),S=require("@xyo-network/diviner-forecasting-abstract"),f=require("@xyo-network/diviner-forecasting-method-arima"),p=require("@xyo-network/diviner-forecasting-model"),x=require("@xyo-network/diviner-model"),D=U(require("jsonpath"),1);var C=h(i=>h(s=>{let n=D.default.value(s,i);if(typeof n=="number")return n;throw new Error("Parsed invalid payload value")},"transformer"),"getJsonPathTransformer"),l=class i extends S.AbstractForecastingDiviner{static{h(this,"MemoryForecastingDiviner")}static configSchemas=[...super.configSchemas,p.ForecastingDivinerConfigSchema];static defaultConfigSchema=p.ForecastingDivinerConfigSchema;static forecastingMethodDict={arimaForecasting:f.arimaForecastingMethod,seasonalArimaForecasting:f.seasonalArimaForecastingMethod};batchLimit=1e3;maxTrainingLength=1e4;get boundWitnessDiviner(){return(0,r.assertEx)(this.config.boundWitnessDiviner,()=>"No boundWitnessDiviner configured")}get forecastingMethod(){let t=(0,r.assertEx)(this.config.forecastingMethod,()=>"Missing forecastingMethod in config"),s=i.forecastingMethodDict[t];if(s)return s;throw new Error(`Unsupported forecasting method: ${t}`)}get transformer(){let t=(0,r.assertEx)(this.config.jsonPathExpression,()=>"Missing jsonPathExpression in config");return C(t)}async getPayloadsInWindow(t,s){let n=this.config.witnessAddresses,o=[(0,r.assertEx)(this.config.witnessSchema,()=>"Missing witnessSchema in config")],g=[],y=(0,w.asArchivistInstance)(await this.archivistInstance(),()=>"Unable to resolve archivist"),A=(0,x.asDivinerInstance)((await this.resolve(this.boundWitnessDiviner)).pop(),"Unable to resolve boundWitnessDiviner"),u=this.batchLimit,W=(0,r.assertEx)(this.config.witnessSchema,()=>"Missing witnessSchema in config"),d=s,v=!0;for(;v||g.length<this.maxTrainingLength;){let F={addresses:n,limit:u,payload_schemas:o,schema:E.BoundWitnessDivinerQuerySchema,timestamp:d},c=(await A.divine([F])).filter(e=>e.timestamp&&e.timestamp>=t&&e.timestamp<=s);if(c.length===0||(d=c.map(e=>e.timestamp).filter(m.exists).reduce((e,_)=>Math.min(e,_),Number.MAX_SAFE_INTEGER),d===Number.MAX_SAFE_INTEGER))break;v=c.length===u;let b=c.map(e=>e.payload_hashes[e.payload_schemas.indexOf(W)]).filter(m.exists);if(b.length>0){let e=(await y.get(b)).filter(m.exists);g.push(...e)}}return g}};
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ MemoryForecastingDiviner: () => MemoryForecastingDiviner
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+
38
+ // src/MemoryForecastingDiviner.ts
39
+ var import_assert = require("@xylabs/assert");
40
+ var import_exists = require("@xylabs/exists");
41
+ var import_archivist_model = require("@xyo-network/archivist-model");
42
+ var import_diviner_boundwitness_model = require("@xyo-network/diviner-boundwitness-model");
43
+ var import_diviner_forecasting_abstract = require("@xyo-network/diviner-forecasting-abstract");
44
+ var import_diviner_forecasting_method_arima = require("@xyo-network/diviner-forecasting-method-arima");
45
+ var import_diviner_forecasting_model = require("@xyo-network/diviner-forecasting-model");
46
+ var import_diviner_model = require("@xyo-network/diviner-model");
47
+ var import_jsonpath = __toESM(require("jsonpath"), 1);
48
+ var getJsonPathTransformer = /* @__PURE__ */ __name((pathExpression) => {
49
+ const transformer = /* @__PURE__ */ __name((x) => {
50
+ const ret = import_jsonpath.default.value(x, pathExpression);
51
+ if (typeof ret === "number") return ret;
52
+ throw new Error("Parsed invalid payload value");
53
+ }, "transformer");
54
+ return transformer;
55
+ }, "getJsonPathTransformer");
56
+ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_diviner_forecasting_abstract.AbstractForecastingDiviner {
57
+ static {
58
+ __name(this, "MemoryForecastingDiviner");
59
+ }
60
+ static configSchemas = [
61
+ ...super.configSchemas,
62
+ import_diviner_forecasting_model.ForecastingDivinerConfigSchema
63
+ ];
64
+ static defaultConfigSchema = import_diviner_forecasting_model.ForecastingDivinerConfigSchema;
65
+ static forecastingMethodDict = {
66
+ arimaForecasting: import_diviner_forecasting_method_arima.arimaForecastingMethod,
67
+ seasonalArimaForecasting: import_diviner_forecasting_method_arima.seasonalArimaForecastingMethod
68
+ };
69
+ /**
70
+ * The max number of records to search during the batch query
71
+ */
72
+ batchLimit = 1e3;
73
+ // TODO: Inject via config
74
+ maxTrainingLength = 1e4;
75
+ get boundWitnessDiviner() {
76
+ return (0, import_assert.assertEx)(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
77
+ }
78
+ get forecastingMethod() {
79
+ const forecastingMethodName = (0, import_assert.assertEx)(this.config.forecastingMethod, () => "Missing forecastingMethod in config");
80
+ const forecastingMethod = _MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName];
81
+ if (forecastingMethod) return forecastingMethod;
82
+ throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
83
+ }
84
+ get transformer() {
85
+ const pathExpression = (0, import_assert.assertEx)(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
86
+ return getJsonPathTransformer(pathExpression);
87
+ }
88
+ async getPayloadsInWindow(startTimestamp, stopTimestamp) {
89
+ const addresses = this.config.witnessAddresses;
90
+ const payload_schemas = [
91
+ (0, import_assert.assertEx)(this.config.witnessSchema, () => "Missing witnessSchema in config")
92
+ ];
93
+ const payloads = [];
94
+ const archivist = (0, import_archivist_model.asArchivistInstance)(await this.archivistInstance(), () => "Unable to resolve archivist");
95
+ const bwDiviner = (0, import_diviner_model.asDivinerInstance)((await this.resolve(this.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
96
+ const limit = this.batchLimit;
97
+ const witnessSchema = (0, import_assert.assertEx)(this.config.witnessSchema, () => "Missing witnessSchema in config");
98
+ let timestamp = stopTimestamp;
99
+ let more = true;
100
+ while (more || payloads.length < this.maxTrainingLength) {
101
+ const query = {
102
+ addresses,
103
+ limit,
104
+ payload_schemas,
105
+ schema: import_diviner_boundwitness_model.BoundWitnessDivinerQuerySchema,
106
+ timestamp
107
+ };
108
+ const boundWitnesses = (await bwDiviner.divine([
109
+ query
110
+ ])).filter((bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp);
111
+ if (boundWitnesses.length === 0) break;
112
+ timestamp = boundWitnesses.map((bw) => bw.timestamp).filter(import_exists.exists).reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER);
113
+ if (timestamp === Number.MAX_SAFE_INTEGER) break;
114
+ more = boundWitnesses.length === limit;
115
+ const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(import_exists.exists);
116
+ if (hashes.length > 0) {
117
+ const batchPayloads = (await archivist.get(hashes)).filter(import_exists.exists);
118
+ payloads.push(...batchPayloads);
119
+ }
120
+ }
121
+ return payloads;
122
+ }
123
+ };
2
124
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n const transformer = (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n return transformer\n}\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override 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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":"6mBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC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,EACtEC,KAAYC,sBACf,MAAM,KAAKC,QAAQ,KAAKpB,mBAAmB,GAAGqB,IAAG,EAClD,uCAAA,EAEIC,EAAQ,KAAKxB,WACbe,KAAgBZ,YAAS,KAAKC,OAAOW,cAAe,IAAM,iCAAA,EAC5DU,EAAYd,EACZe,EAAO,GAIX,KAAOA,GAAQV,EAASW,OAAS,KAAK1B,mBAAmB,CACvD,IAAM2B,EAAyC,CAAEhB,UAAAA,EAAWY,MAAAA,EAAOV,gBAAAA,EAAiBe,OAAQC,iCAAgCL,UAAAA,CAAU,EAChIM,GAAkB,MAAMX,EAAUY,OAAO,CAACJ,EAAM,GAAGK,OACtDC,GAAOA,EAAGT,WAAaS,EAAGT,WAAaf,GAAkBwB,EAAGT,WAAad,CAAAA,EAU5E,GARIoB,EAAeJ,SAAW,IAG9BF,EAAYM,EACTI,IAAKD,GAAOA,EAAGT,SAAS,EACxBQ,OAAOG,QAAAA,EAEPC,OAAO,CAACC,EAAGC,IAAMC,KAAKC,IAAIH,EAAGC,CAAAA,EAAIG,OAAOC,gBAAgB,EACvDlB,IAAciB,OAAOC,kBAAkB,MAG3CjB,EAAOK,EAAeJ,SAAWH,EAGjC,IAAMoB,EAASb,EAAeI,IAAKD,GAAOA,EAAGW,eAAeX,EAAGpB,gBAAgBgC,QAAQ/B,CAAAA,CAAAA,CAAe,EAAEkB,OAAOG,QAAAA,EAG/G,GAAIQ,EAAOjB,OAAS,EAAG,CACrB,IAAMoB,GAAiB,MAAM9B,EAAU+B,IAAIJ,CAAAA,GAASX,OAAOG,QAAAA,EAC3DpB,EAASiC,KAAI,GAAIF,CAAAA,CACnB,CACF,CACA,OAAO/B,CACT,CACF","names":["src_exports","__export","MemoryForecastingDiviner","__toCommonJS","import_assert","import_exists","import_archivist_model","import_diviner_boundwitness_model","import_diviner_forecasting_abstract","import_diviner_forecasting_method_arima","import_diviner_forecasting_model","import_diviner_model","import_jsonpath","getJsonPathTransformer","__name","pathExpression","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","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/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n const transformer = (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n return transformer\n}\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override 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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AACzB,oBAAuB;AACvB,6BAAoC;AAEpC,wCAA2G;AAC3G,0CAAqE;AACrE,8CAKO;AACP,uCAA2F;AAC3F,2BAAmD;AAEnD,sBAAqB;AAIrB,IAAMA,yBAAyB,wBAACC,mBAAAA;AAC9B,QAAMC,cAAc,wBAACC,MAAAA;AACnB,UAAMC,MAAMC,gBAAAA,QAASC,MAAMH,GAAGF,cAAAA;AAC9B,QAAI,OAAOG,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB,GAJoB;A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AM0B,QAAyC;QAAEhB;QAAWY;QAAOV;QAAiBe,QAAQC;QAAgCL;MAAU;AACtI,YAAMM,kBAAkB,MAAMX,UAAUY,OAAO;QAACJ;OAAM,GAAGK,OACvD,CAACC,OAAOA,GAAGT,aAAaS,GAAGT,aAAaf,kBAAkBwB,GAAGT,aAAad,aAAAA;AAE5E,UAAIoB,eAAeJ,WAAW,EAAG;AAGjCF,kBAAYM,eACTI,IAAI,CAACD,OAAOA,GAAGT,SAAS,EACxBQ,OAAOG,oBAAAA,EAEPC,OAAO,CAACC,GAAGC,MAAMC,KAAKC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC,iBAAkB;AAG3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAI,CAACD,OAAOA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,oBAAAA;AAG/G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,oBAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;","names":["getJsonPathTransformer","pathExpression","transformer","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push"]}
@@ -1,2 +1,93 @@
1
- var S=Object.defineProperty;var a=(e,i)=>S(e,"name",{value:i,configurable:!0});import{assertEx as n}from"@xylabs/assert";import{exists as m}from"@xylabs/exists";import{asArchivistInstance as x}from"@xyo-network/archivist-model";import{BoundWitnessDivinerQuerySchema as D}from"@xyo-network/diviner-boundwitness-model";import{AbstractForecastingDiviner as y}from"@xyo-network/diviner-forecasting-abstract";import{arimaForecastingMethod as A,seasonalArimaForecastingMethod as W}from"@xyo-network/diviner-forecasting-method-arima";import{ForecastingDivinerConfigSchema as p}from"@xyo-network/diviner-forecasting-model";import{asDivinerInstance as F}from"@xyo-network/diviner-model";import _ from"jsonpath";var I=a(e=>a(s=>{let o=_.value(s,e);if(typeof o=="number")return o;throw new Error("Parsed invalid payload value")},"transformer"),"getJsonPathTransformer"),l=class e extends y{static{a(this,"MemoryForecastingDiviner")}static configSchemas=[...super.configSchemas,p];static defaultConfigSchema=p;static forecastingMethodDict={arimaForecasting:A,seasonalArimaForecasting:W};batchLimit=1e3;maxTrainingLength=1e4;get boundWitnessDiviner(){return n(this.config.boundWitnessDiviner,()=>"No boundWitnessDiviner configured")}get forecastingMethod(){let i=n(this.config.forecastingMethod,()=>"Missing forecastingMethod in config"),s=e.forecastingMethodDict[i];if(s)return s;throw new Error(`Unsupported forecasting method: ${i}`)}get transformer(){let i=n(this.config.jsonPathExpression,()=>"Missing jsonPathExpression in config");return I(i)}async getPayloadsInWindow(i,s){let o=this.config.witnessAddresses,u=[n(this.config.witnessSchema,()=>"Missing witnessSchema in config")],c=[],v=x(await this.archivistInstance(),()=>"Unable to resolve archivist"),b=F((await this.resolve(this.boundWitnessDiviner)).pop(),"Unable to resolve boundWitnessDiviner"),f=this.batchLimit,M=n(this.config.witnessSchema,()=>"Missing witnessSchema in config"),h=s,g=!0;for(;g||c.length<this.maxTrainingLength;){let w={addresses:o,limit:f,payload_schemas:u,schema:D,timestamp:h},r=(await b.divine([w])).filter(t=>t.timestamp&&t.timestamp>=i&&t.timestamp<=s);if(r.length===0||(h=r.map(t=>t.timestamp).filter(m).reduce((t,E)=>Math.min(t,E),Number.MAX_SAFE_INTEGER),h===Number.MAX_SAFE_INTEGER))break;g=r.length===f;let d=r.map(t=>t.payload_hashes[t.payload_schemas.indexOf(M)]).filter(m);if(d.length>0){let t=(await v.get(d)).filter(m);c.push(...t)}}return c}};export{l as MemoryForecastingDiviner};
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/MemoryForecastingDiviner.ts
5
+ import { assertEx } from "@xylabs/assert";
6
+ import { exists } from "@xylabs/exists";
7
+ import { asArchivistInstance } from "@xyo-network/archivist-model";
8
+ import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
9
+ import { AbstractForecastingDiviner } from "@xyo-network/diviner-forecasting-abstract";
10
+ import { arimaForecastingMethod, seasonalArimaForecastingMethod } 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 = /* @__PURE__ */ __name((pathExpression) => {
15
+ const transformer = /* @__PURE__ */ __name((x) => {
16
+ const ret = jsonpath.value(x, pathExpression);
17
+ if (typeof ret === "number") return ret;
18
+ throw new Error("Parsed invalid payload value");
19
+ }, "transformer");
20
+ return transformer;
21
+ }, "getJsonPathTransformer");
22
+ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractForecastingDiviner {
23
+ static {
24
+ __name(this, "MemoryForecastingDiviner");
25
+ }
26
+ static configSchemas = [
27
+ ...super.configSchemas,
28
+ ForecastingDivinerConfigSchema
29
+ ];
30
+ static defaultConfigSchema = ForecastingDivinerConfigSchema;
31
+ static forecastingMethodDict = {
32
+ arimaForecasting: arimaForecastingMethod,
33
+ seasonalArimaForecasting: seasonalArimaForecastingMethod
34
+ };
35
+ /**
36
+ * The max number of records to search during the batch query
37
+ */
38
+ batchLimit = 1e3;
39
+ // TODO: Inject via config
40
+ maxTrainingLength = 1e4;
41
+ get boundWitnessDiviner() {
42
+ return assertEx(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
43
+ }
44
+ get forecastingMethod() {
45
+ const forecastingMethodName = assertEx(this.config.forecastingMethod, () => "Missing forecastingMethod in config");
46
+ const forecastingMethod = _MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName];
47
+ if (forecastingMethod) return forecastingMethod;
48
+ throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
49
+ }
50
+ get transformer() {
51
+ const pathExpression = assertEx(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
52
+ return getJsonPathTransformer(pathExpression);
53
+ }
54
+ async getPayloadsInWindow(startTimestamp, stopTimestamp) {
55
+ const addresses = this.config.witnessAddresses;
56
+ const payload_schemas = [
57
+ assertEx(this.config.witnessSchema, () => "Missing witnessSchema in config")
58
+ ];
59
+ const payloads = [];
60
+ const archivist = asArchivistInstance(await this.archivistInstance(), () => "Unable to resolve archivist");
61
+ const bwDiviner = asDivinerInstance((await this.resolve(this.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
62
+ const limit = this.batchLimit;
63
+ const witnessSchema = assertEx(this.config.witnessSchema, () => "Missing witnessSchema in config");
64
+ let timestamp = stopTimestamp;
65
+ let more = true;
66
+ while (more || payloads.length < this.maxTrainingLength) {
67
+ const query = {
68
+ addresses,
69
+ limit,
70
+ payload_schemas,
71
+ schema: BoundWitnessDivinerQuerySchema,
72
+ timestamp
73
+ };
74
+ const boundWitnesses = (await bwDiviner.divine([
75
+ query
76
+ ])).filter((bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp);
77
+ if (boundWitnesses.length === 0) break;
78
+ timestamp = boundWitnesses.map((bw) => bw.timestamp).filter(exists).reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER);
79
+ if (timestamp === Number.MAX_SAFE_INTEGER) break;
80
+ more = boundWitnesses.length === limit;
81
+ const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists);
82
+ if (hashes.length > 0) {
83
+ const batchPayloads = (await archivist.get(hashes)).filter(exists);
84
+ payloads.push(...batchPayloads);
85
+ }
86
+ }
87
+ return payloads;
88
+ }
89
+ };
90
+ export {
91
+ MemoryForecastingDiviner
92
+ };
2
93
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n const transformer = (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n return transformer\n}\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override 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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":"+EAAA,OAASA,YAAAA,MAAgB,iBACzB,OAASC,UAAAA,MAAc,iBACvB,OAASC,uBAAAA,MAA2B,+BAEpC,OAAqEC,kCAAAA,MAAsC,0CAC3G,OAASC,8BAAAA,MAA4D,4CACrE,OACEC,0BAAAA,EAEAC,kCAAAA,MAEK,gDACP,OAASC,kCAAAA,MAAkF,yCAC3F,OAASC,qBAAAA,MAA0C,6BAEnD,OAAOC,MAAc,WAIrB,IAAMC,EAAyBC,EAACC,GACVD,EAACE,GAAAA,CACnB,IAAMC,EAAMC,EAASC,MAAMH,EAAGD,CAAAA,EAC9B,GAAI,OAAOE,GAAQ,SAAU,OAAOA,EACpC,MAAM,IAAIG,MAAM,8BAAA,CAClB,EAJoB,eADS,0BASlBC,EAAN,MAAMA,UAEHC,CA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M,GAAGK,OACtDC,GAAOA,EAAGT,WAAaS,EAAGT,WAAaf,GAAkBwB,EAAGT,WAAad,CAAAA,EAU5E,GARIoB,EAAeJ,SAAW,IAG9BF,EAAYM,EACTI,IAAKD,GAAOA,EAAGT,SAAS,EACxBQ,OAAOG,CAAAA,EAEPC,OAAO,CAACC,EAAGC,IAAMC,KAAKC,IAAIH,EAAGC,CAAAA,EAAIG,OAAOC,gBAAgB,EACvDlB,IAAciB,OAAOC,kBAAkB,MAG3CjB,EAAOK,EAAeJ,SAAWH,EAGjC,IAAMoB,EAASb,EAAeI,IAAKD,GAAOA,EAAGW,eAAeX,EAAGpB,gBAAgBgC,QAAQ/B,CAAAA,CAAAA,CAAe,EAAEkB,OAAOG,CAAAA,EAG/G,GAAIQ,EAAOjB,OAAS,EAAG,CACrB,IAAMoB,GAAiB,MAAM9B,EAAU+B,IAAIJ,CAAAA,GAASX,OAAOG,CAAAA,EAC3DpB,EAASiC,KAAI,GAAIF,CAAAA,CACnB,CACF,CACA,OAAO/B,CACT,CACF","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","__name","pathExpression","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","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 { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n const transformer = (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n return transformer\n}\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override 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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,2BAA2B;AAEpC,SAAqEC,sCAAsC;AAC3G,SAASC,kCAA4D;AACrE,SACEC,wBAEAC,sCAEK;AACP,SAASC,sCAAkF;AAC3F,SAASC,yBAA0C;AAEnD,OAAOC,cAAc;AAIrB,IAAMC,yBAAyB,wBAACC,mBAAAA;AAC9B,QAAMC,cAAc,wBAACC,MAAAA;AACnB,UAAMC,MAAMC,SAASC,MAAMH,GAAGF,cAAAA;AAC9B,QAAI,OAAOG,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB,GAJoB;AAKpB,SAAOL;AACT,GAP+B;AASxB,IAAMM,2BAAN,MAAMA,kCAEHC,2BAAAA;EA9BV,OA8BUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,OAA0BE,wBAA6E;IACrGC,kBAAkBC;IAClBC,0BAA0BC;EAC5B;;;;EAKmBC,aAAa;;EAGbC,oBAAoB;EAEvC,IAAIC,sBAAsB;AACxB,WAAOC,SAAS,KAAKC,OAAOF,qBAAqB,MAAM,mCAAA;EACzD;EAEA,IAAuBG,oBAAuC;AAC5D,UAAMC,wBAAwBH,SAAS,KAAKC,OAAOC,mBAAmB,MAAM,qCAAA;AAC5E,UAA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G3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAI,CAACD,OAAOA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,MAAAA;AAG/G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,MAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","pathExpression","transformer","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push"]}
@@ -1,2 +1,124 @@
1
- "use strict";var I=Object.create;var a=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,T=Object.prototype.hasOwnProperty;var h=(i,t)=>a(i,"name",{value:t,configurable:!0});var j=(i,t)=>{for(var s in t)a(i,s,{get:t[s],enumerable:!0})},M=(i,t,s,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of P(t))!T.call(i,o)&&o!==s&&a(i,o,{get:()=>t[o],enumerable:!(n=N(t,o))||n.enumerable});return i};var U=(i,t,s)=>(s=i!=null?I(L(i)):{},M(t||!i||!i.__esModule?a(s,"default",{value:i,enumerable:!0}):s,i)),k=i=>M(a({},"__esModule",{value:!0}),i);var G={};j(G,{MemoryForecastingDiviner:()=>l});module.exports=k(G);var r=require("@xylabs/assert"),m=require("@xylabs/exists"),w=require("@xyo-network/archivist-model"),E=require("@xyo-network/diviner-boundwitness-model"),S=require("@xyo-network/diviner-forecasting-abstract"),f=require("@xyo-network/diviner-forecasting-method-arima"),p=require("@xyo-network/diviner-forecasting-model"),x=require("@xyo-network/diviner-model"),D=U(require("jsonpath"),1);var C=h(i=>h(s=>{let n=D.default.value(s,i);if(typeof n=="number")return n;throw new Error("Parsed invalid payload value")},"transformer"),"getJsonPathTransformer"),l=class i extends S.AbstractForecastingDiviner{static{h(this,"MemoryForecastingDiviner")}static configSchemas=[...super.configSchemas,p.ForecastingDivinerConfigSchema];static defaultConfigSchema=p.ForecastingDivinerConfigSchema;static forecastingMethodDict={arimaForecasting:f.arimaForecastingMethod,seasonalArimaForecasting:f.seasonalArimaForecastingMethod};batchLimit=1e3;maxTrainingLength=1e4;get boundWitnessDiviner(){return(0,r.assertEx)(this.config.boundWitnessDiviner,()=>"No boundWitnessDiviner configured")}get forecastingMethod(){let t=(0,r.assertEx)(this.config.forecastingMethod,()=>"Missing forecastingMethod in config"),s=i.forecastingMethodDict[t];if(s)return s;throw new Error(`Unsupported forecasting method: ${t}`)}get transformer(){let t=(0,r.assertEx)(this.config.jsonPathExpression,()=>"Missing jsonPathExpression in config");return C(t)}async getPayloadsInWindow(t,s){let n=this.config.witnessAddresses,o=[(0,r.assertEx)(this.config.witnessSchema,()=>"Missing witnessSchema in config")],g=[],y=(0,w.asArchivistInstance)(await this.archivistInstance(),()=>"Unable to resolve archivist"),A=(0,x.asDivinerInstance)((await this.resolve(this.boundWitnessDiviner)).pop(),"Unable to resolve boundWitnessDiviner"),u=this.batchLimit,W=(0,r.assertEx)(this.config.witnessSchema,()=>"Missing witnessSchema in config"),d=s,v=!0;for(;v||g.length<this.maxTrainingLength;){let F={addresses:n,limit:u,payload_schemas:o,schema:E.BoundWitnessDivinerQuerySchema,timestamp:d},c=(await A.divine([F])).filter(e=>e.timestamp&&e.timestamp>=t&&e.timestamp<=s);if(c.length===0||(d=c.map(e=>e.timestamp).filter(m.exists).reduce((e,_)=>Math.min(e,_),Number.MAX_SAFE_INTEGER),d===Number.MAX_SAFE_INTEGER))break;v=c.length===u;let b=c.map(e=>e.payload_hashes[e.payload_schemas.indexOf(W)]).filter(m.exists);if(b.length>0){let e=(await y.get(b)).filter(m.exists);g.push(...e)}}return g}};
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ MemoryForecastingDiviner: () => MemoryForecastingDiviner
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+
38
+ // src/MemoryForecastingDiviner.ts
39
+ var import_assert = require("@xylabs/assert");
40
+ var import_exists = require("@xylabs/exists");
41
+ var import_archivist_model = require("@xyo-network/archivist-model");
42
+ var import_diviner_boundwitness_model = require("@xyo-network/diviner-boundwitness-model");
43
+ var import_diviner_forecasting_abstract = require("@xyo-network/diviner-forecasting-abstract");
44
+ var import_diviner_forecasting_method_arima = require("@xyo-network/diviner-forecasting-method-arima");
45
+ var import_diviner_forecasting_model = require("@xyo-network/diviner-forecasting-model");
46
+ var import_diviner_model = require("@xyo-network/diviner-model");
47
+ var import_jsonpath = __toESM(require("jsonpath"), 1);
48
+ var getJsonPathTransformer = /* @__PURE__ */ __name((pathExpression) => {
49
+ const transformer = /* @__PURE__ */ __name((x) => {
50
+ const ret = import_jsonpath.default.value(x, pathExpression);
51
+ if (typeof ret === "number") return ret;
52
+ throw new Error("Parsed invalid payload value");
53
+ }, "transformer");
54
+ return transformer;
55
+ }, "getJsonPathTransformer");
56
+ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_diviner_forecasting_abstract.AbstractForecastingDiviner {
57
+ static {
58
+ __name(this, "MemoryForecastingDiviner");
59
+ }
60
+ static configSchemas = [
61
+ ...super.configSchemas,
62
+ import_diviner_forecasting_model.ForecastingDivinerConfigSchema
63
+ ];
64
+ static defaultConfigSchema = import_diviner_forecasting_model.ForecastingDivinerConfigSchema;
65
+ static forecastingMethodDict = {
66
+ arimaForecasting: import_diviner_forecasting_method_arima.arimaForecastingMethod,
67
+ seasonalArimaForecasting: import_diviner_forecasting_method_arima.seasonalArimaForecastingMethod
68
+ };
69
+ /**
70
+ * The max number of records to search during the batch query
71
+ */
72
+ batchLimit = 1e3;
73
+ // TODO: Inject via config
74
+ maxTrainingLength = 1e4;
75
+ get boundWitnessDiviner() {
76
+ return (0, import_assert.assertEx)(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
77
+ }
78
+ get forecastingMethod() {
79
+ const forecastingMethodName = (0, import_assert.assertEx)(this.config.forecastingMethod, () => "Missing forecastingMethod in config");
80
+ const forecastingMethod = _MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName];
81
+ if (forecastingMethod) return forecastingMethod;
82
+ throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
83
+ }
84
+ get transformer() {
85
+ const pathExpression = (0, import_assert.assertEx)(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
86
+ return getJsonPathTransformer(pathExpression);
87
+ }
88
+ async getPayloadsInWindow(startTimestamp, stopTimestamp) {
89
+ const addresses = this.config.witnessAddresses;
90
+ const payload_schemas = [
91
+ (0, import_assert.assertEx)(this.config.witnessSchema, () => "Missing witnessSchema in config")
92
+ ];
93
+ const payloads = [];
94
+ const archivist = (0, import_archivist_model.asArchivistInstance)(await this.archivistInstance(), () => "Unable to resolve archivist");
95
+ const bwDiviner = (0, import_diviner_model.asDivinerInstance)((await this.resolve(this.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
96
+ const limit = this.batchLimit;
97
+ const witnessSchema = (0, import_assert.assertEx)(this.config.witnessSchema, () => "Missing witnessSchema in config");
98
+ let timestamp = stopTimestamp;
99
+ let more = true;
100
+ while (more || payloads.length < this.maxTrainingLength) {
101
+ const query = {
102
+ addresses,
103
+ limit,
104
+ payload_schemas,
105
+ schema: import_diviner_boundwitness_model.BoundWitnessDivinerQuerySchema,
106
+ timestamp
107
+ };
108
+ const boundWitnesses = (await bwDiviner.divine([
109
+ query
110
+ ])).filter((bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp);
111
+ if (boundWitnesses.length === 0) break;
112
+ timestamp = boundWitnesses.map((bw) => bw.timestamp).filter(import_exists.exists).reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER);
113
+ if (timestamp === Number.MAX_SAFE_INTEGER) break;
114
+ more = boundWitnesses.length === limit;
115
+ const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(import_exists.exists);
116
+ if (hashes.length > 0) {
117
+ const batchPayloads = (await archivist.get(hashes)).filter(import_exists.exists);
118
+ payloads.push(...batchPayloads);
119
+ }
120
+ }
121
+ return payloads;
122
+ }
123
+ };
2
124
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n const transformer = (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n return transformer\n}\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override 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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":"6mBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAyB,0BACzBC,EAAuB,0BACvBC,EAAoC,wCAEpCC,EAA2G,mDAC3GC,EAAqE,qDACrEC,EAKO,yDACPC,EAA2F,kDAC3FC,EAAmD,sCAEnDC,EAAqB,yBAIrB,IAAMC,EAAyBC,EAACC,GACVD,EAACE,GAAAA,CACnB,IAAMC,EAAMC,EAAAA,QAASC,MAAMH,EAAGD,CAAAA,EAC9B,GAAI,OAAOE,GAAQ,SAAU,OAAOA,EACpC,MAAM,IAAIG,MAAM,8BAAA,CAClB,EAJoB,eADS,0BASlBC,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,MAAMX,EAAUY,OAAO,CAACJ,EAAM,GAAGK,OACtDC,GAAOA,EAAGT,WAAaS,EAAGT,WAAaf,GAAkBwB,EAAGT,WAAad,CAAAA,EAU5E,GARIoB,EAAeJ,SAAW,IAG9BF,EAAYM,EACTI,IAAKD,GAAOA,EAAGT,SAAS,EACxBQ,OAAOG,QAAAA,EAEPC,OAAO,CAACC,EAAGC,IAAMC,KAAKC,IAAIH,EAAGC,CAAAA,EAAIG,OAAOC,gBAAgB,EACvDlB,IAAciB,OAAOC,kBAAkB,MAG3CjB,EAAOK,EAAeJ,SAAWH,EAGjC,IAAMoB,EAASb,EAAeI,IAAKD,GAAOA,EAAGW,eAAeX,EAAGpB,gBAAgBgC,QAAQ/B,CAAAA,CAAAA,CAAe,EAAEkB,OAAOG,QAAAA,EAG/G,GAAIQ,EAAOjB,OAAS,EAAG,CACrB,IAAMoB,GAAiB,MAAM9B,EAAU+B,IAAIJ,CAAAA,GAASX,OAAOG,QAAAA,EAC3DpB,EAASiC,KAAI,GAAIF,CAAAA,CACnB,CACF,CACA,OAAO/B,CACT,CACF","names":["src_exports","__export","MemoryForecastingDiviner","__toCommonJS","import_assert","import_exists","import_archivist_model","import_diviner_boundwitness_model","import_diviner_forecasting_abstract","import_diviner_forecasting_method_arima","import_diviner_forecasting_model","import_diviner_model","import_jsonpath","getJsonPathTransformer","__name","pathExpression","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","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/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n const transformer = (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n return transformer\n}\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override 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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AACzB,oBAAuB;AACvB,6BAAoC;AAEpC,wCAA2G;AAC3G,0CAAqE;AACrE,8CAKO;AACP,uCAA2F;AAC3F,2BAAmD;AAEnD,sBAAqB;AAIrB,IAAMA,yBAAyB,wBAACC,mBAAAA;AAC9B,QAAMC,cAAc,wBAACC,MAAAA;AACnB,UAAMC,MAAMC,gBAAAA,QAASC,MAAMH,GAAGF,cAAAA;AAC9B,QAAI,OAAOG,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8BAAA;EAClB,GAJoB;AAKpB,SAAOL;AACT,GAP+B;AASxB,IAAMM,2BAAN,MAAMA,kCAEHC,+DAAAA;EA9BV,OA8BUA;;;EACR,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeC;;EAC5E,OAAyBC,sBAA8BD;EAEvD,OAA0BE,wBAA6E;IACrGC,kBAAkBC;IAClBC,0BAA0BC;EAC5B;;;;EAKmBC,aAAa;;EAGbC,oBAAoB;EAEvC,IAAIC,sBAAsB;AACxB,eAAOC,wBAAS,KAAKC,OAAOF,qBAAqB,MAAM,mCAAA;EACzD;EAEA,IAAuBG,oBAA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KC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC,iBAAkB;AAG3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAI,CAACD,OAAOA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,oBAAAA;AAG/G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,oBAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;","names":["getJsonPathTransformer","pathExpression","transformer","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push"]}
@@ -1,2 +1,93 @@
1
- var S=Object.defineProperty;var a=(e,i)=>S(e,"name",{value:i,configurable:!0});import{assertEx as n}from"@xylabs/assert";import{exists as m}from"@xylabs/exists";import{asArchivistInstance as x}from"@xyo-network/archivist-model";import{BoundWitnessDivinerQuerySchema as D}from"@xyo-network/diviner-boundwitness-model";import{AbstractForecastingDiviner as y}from"@xyo-network/diviner-forecasting-abstract";import{arimaForecastingMethod as A,seasonalArimaForecastingMethod as W}from"@xyo-network/diviner-forecasting-method-arima";import{ForecastingDivinerConfigSchema as p}from"@xyo-network/diviner-forecasting-model";import{asDivinerInstance as F}from"@xyo-network/diviner-model";import _ from"jsonpath";var I=a(e=>a(s=>{let o=_.value(s,e);if(typeof o=="number")return o;throw new Error("Parsed invalid payload value")},"transformer"),"getJsonPathTransformer"),l=class e extends y{static{a(this,"MemoryForecastingDiviner")}static configSchemas=[...super.configSchemas,p];static defaultConfigSchema=p;static forecastingMethodDict={arimaForecasting:A,seasonalArimaForecasting:W};batchLimit=1e3;maxTrainingLength=1e4;get boundWitnessDiviner(){return n(this.config.boundWitnessDiviner,()=>"No boundWitnessDiviner configured")}get forecastingMethod(){let i=n(this.config.forecastingMethod,()=>"Missing forecastingMethod in config"),s=e.forecastingMethodDict[i];if(s)return s;throw new Error(`Unsupported forecasting method: ${i}`)}get transformer(){let i=n(this.config.jsonPathExpression,()=>"Missing jsonPathExpression in config");return I(i)}async getPayloadsInWindow(i,s){let o=this.config.witnessAddresses,u=[n(this.config.witnessSchema,()=>"Missing witnessSchema in config")],c=[],v=x(await this.archivistInstance(),()=>"Unable to resolve archivist"),b=F((await this.resolve(this.boundWitnessDiviner)).pop(),"Unable to resolve boundWitnessDiviner"),f=this.batchLimit,M=n(this.config.witnessSchema,()=>"Missing witnessSchema in config"),h=s,g=!0;for(;g||c.length<this.maxTrainingLength;){let w={addresses:o,limit:f,payload_schemas:u,schema:D,timestamp:h},r=(await b.divine([w])).filter(t=>t.timestamp&&t.timestamp>=i&&t.timestamp<=s);if(r.length===0||(h=r.map(t=>t.timestamp).filter(m).reduce((t,E)=>Math.min(t,E),Number.MAX_SAFE_INTEGER),h===Number.MAX_SAFE_INTEGER))break;g=r.length===f;let d=r.map(t=>t.payload_hashes[t.payload_schemas.indexOf(M)]).filter(m);if(d.length>0){let t=(await v.get(d)).filter(m);c.push(...t)}}return c}};export{l as MemoryForecastingDiviner};
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/MemoryForecastingDiviner.ts
5
+ import { assertEx } from "@xylabs/assert";
6
+ import { exists } from "@xylabs/exists";
7
+ import { asArchivistInstance } from "@xyo-network/archivist-model";
8
+ import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
9
+ import { AbstractForecastingDiviner } from "@xyo-network/diviner-forecasting-abstract";
10
+ import { arimaForecastingMethod, seasonalArimaForecastingMethod } 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 = /* @__PURE__ */ __name((pathExpression) => {
15
+ const transformer = /* @__PURE__ */ __name((x) => {
16
+ const ret = jsonpath.value(x, pathExpression);
17
+ if (typeof ret === "number") return ret;
18
+ throw new Error("Parsed invalid payload value");
19
+ }, "transformer");
20
+ return transformer;
21
+ }, "getJsonPathTransformer");
22
+ var MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractForecastingDiviner {
23
+ static {
24
+ __name(this, "MemoryForecastingDiviner");
25
+ }
26
+ static configSchemas = [
27
+ ...super.configSchemas,
28
+ ForecastingDivinerConfigSchema
29
+ ];
30
+ static defaultConfigSchema = ForecastingDivinerConfigSchema;
31
+ static forecastingMethodDict = {
32
+ arimaForecasting: arimaForecastingMethod,
33
+ seasonalArimaForecasting: seasonalArimaForecastingMethod
34
+ };
35
+ /**
36
+ * The max number of records to search during the batch query
37
+ */
38
+ batchLimit = 1e3;
39
+ // TODO: Inject via config
40
+ maxTrainingLength = 1e4;
41
+ get boundWitnessDiviner() {
42
+ return assertEx(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
43
+ }
44
+ get forecastingMethod() {
45
+ const forecastingMethodName = assertEx(this.config.forecastingMethod, () => "Missing forecastingMethod in config");
46
+ const forecastingMethod = _MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName];
47
+ if (forecastingMethod) return forecastingMethod;
48
+ throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
49
+ }
50
+ get transformer() {
51
+ const pathExpression = assertEx(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
52
+ return getJsonPathTransformer(pathExpression);
53
+ }
54
+ async getPayloadsInWindow(startTimestamp, stopTimestamp) {
55
+ const addresses = this.config.witnessAddresses;
56
+ const payload_schemas = [
57
+ assertEx(this.config.witnessSchema, () => "Missing witnessSchema in config")
58
+ ];
59
+ const payloads = [];
60
+ const archivist = asArchivistInstance(await this.archivistInstance(), () => "Unable to resolve archivist");
61
+ const bwDiviner = asDivinerInstance((await this.resolve(this.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
62
+ const limit = this.batchLimit;
63
+ const witnessSchema = assertEx(this.config.witnessSchema, () => "Missing witnessSchema in config");
64
+ let timestamp = stopTimestamp;
65
+ let more = true;
66
+ while (more || payloads.length < this.maxTrainingLength) {
67
+ const query = {
68
+ addresses,
69
+ limit,
70
+ payload_schemas,
71
+ schema: BoundWitnessDivinerQuerySchema,
72
+ timestamp
73
+ };
74
+ const boundWitnesses = (await bwDiviner.divine([
75
+ query
76
+ ])).filter((bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp);
77
+ if (boundWitnesses.length === 0) break;
78
+ timestamp = boundWitnesses.map((bw) => bw.timestamp).filter(exists).reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER);
79
+ if (timestamp === Number.MAX_SAFE_INTEGER) break;
80
+ more = boundWitnesses.length === limit;
81
+ const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists);
82
+ if (hashes.length > 0) {
83
+ const batchPayloads = (await archivist.get(hashes)).filter(exists);
84
+ payloads.push(...batchPayloads);
85
+ }
86
+ }
87
+ return payloads;
88
+ }
89
+ };
90
+ export {
91
+ MemoryForecastingDiviner
92
+ };
2
93
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n const transformer = (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n return transformer\n}\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override 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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":"+EAAA,OAASA,YAAAA,MAAgB,iBACzB,OAASC,UAAAA,MAAc,iBACvB,OAASC,uBAAAA,MAA2B,+BAEpC,OAAqEC,kCAAAA,MAAsC,0CAC3G,OAASC,8BAAAA,MAA4D,4CACrE,OACEC,0BAAAA,EAEAC,kCAAAA,MAEK,gDACP,OAASC,kCAAAA,MAAkF,yCAC3F,OAASC,qBAAAA,MAA0C,6BAEnD,OAAOC,MAAc,WAIrB,IAAMC,EAAyBC,EAACC,GACVD,EAACE,GAAAA,CACnB,IAAMC,EAAMC,EAASC,MAAMH,EAAGD,CAAAA,EAC9B,GAAI,OAAOE,GAAQ,SAAU,OAAOA,EACpC,MAAM,IAAIG,MAAM,8BAAA,CAClB,EAJoB,eADS,0BASlBC,EAAN,MAAMA,UAEHC,CAAAA,CA9BV,MA8BUA,CAAAA,EAAAA,iCACR,OAAyBC,cAA0B,IAAI,MAAMA,cAAeC,GAC5E,OAAyBC,oBAA8BD,EAEvD,OAA0BE,sBAA6E,CACrGC,iBAAkBC,EAClBC,yBAA0BC,CAC5B,EAKmBC,WAAa,IAGbC,kBAAoB,IAEvC,IAAIC,qBAAsB,CACxB,OAAOC,EAAS,KAAKC,OAAOF,oBAAqB,IAAM,mCAAA,CACzD,CAEA,IAAuBG,mBAAuC,CAC5D,IAAMC,EAAwBH,EAAS,KAAKC,OAAOC,kBAAmB,IAAM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,IAAKD,GAAOA,EAAGW,eAAeX,EAAGpB,gBAAgBgC,QAAQ/B,CAAAA,CAAAA,CAAe,EAAEkB,OAAOG,CAAAA,EAG/G,GAAIQ,EAAOjB,OAAS,EAAG,CACrB,IAAMoB,GAAiB,MAAM9B,EAAU+B,IAAIJ,CAAAA,GAASX,OAAOG,CAAAA,EAC3DpB,EAASiC,KAAI,GAAIF,CAAAA,CACnB,CACF,CACA,OAAO/B,CACT,CACF","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","__name","pathExpression","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","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 { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n const transformer = (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n return transformer\n}\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override 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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n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ists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","pathExpression","transformer","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","forecastingMethodDict","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push"]}
@@ -1,2 +1,131 @@
1
- "use strict";var U=Object.create;var r=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty;var R=Reflect.get;var X=(s,t,i)=>t in s?r(s,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[t]=i;var m=(s,t)=>r(s,"name",{value:t,configurable:!0});var q=(s,t)=>{for(var i in t)r(s,i,{get:t[i],enumerable:!0})},x=(s,t,i,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of C(t))!G.call(s,a)&&a!==i&&r(s,a,{get:()=>t[a],enumerable:!(o=k(t,a))||o.enumerable});return s};var B=(s,t,i)=>(i=s!=null?U(S(s)):{},x(t||!s||!s.__esModule?r(i,"default",{value:s,enumerable:!0}):i,s)),F=s=>x(r({},"__esModule",{value:!0}),s);var f=(s,t,i)=>X(s,typeof t!="symbol"?t+"":t,i);var A=(s,t,i)=>R(S(s),i,t);var O={};q(O,{MemoryForecastingDiviner:()=>b});module.exports=F(O);var c=require("@xylabs/assert"),g=require("@xylabs/exists"),M=require("@xyo-network/archivist-model"),W=require("@xyo-network/diviner-boundwitness-model"),I=require("@xyo-network/diviner-forecasting-abstract"),d=require("@xyo-network/diviner-forecasting-method-arima"),u=require("@xyo-network/diviner-forecasting-model"),N=require("@xyo-network/diviner-model"),P=B(require("jsonpath"),1);var J=m(s=>m(i=>{let o=P.default.value(i,s);if(typeof o=="number")return o;throw new Error("Parsed invalid payload value")},"transformer"),"getJsonPathTransformer"),n=class n extends I.AbstractForecastingDiviner{batchLimit=1e3;maxTrainingLength=1e4;get boundWitnessDiviner(){return(0,c.assertEx)(this.config.boundWitnessDiviner,()=>"No boundWitnessDiviner configured")}get forecastingMethod(){let t=(0,c.assertEx)(this.config.forecastingMethod,()=>"Missing forecastingMethod in config"),i=n.forecastingMethodDict[t];if(i)return i;throw new Error(`Unsupported forecasting method: ${t}`)}get transformer(){let t=(0,c.assertEx)(this.config.jsonPathExpression,()=>"Missing jsonPathExpression in config");return J(t)}async getPayloadsInWindow(t,i){let o=this.config.witnessAddresses,a=[(0,c.assertEx)(this.config.witnessSchema,()=>"Missing witnessSchema in config")],p=[],D=(0,M.asArchivistInstance)(await this.archivistInstance(),()=>"Unable to resolve archivist"),y=(0,N.asDivinerInstance)((await this.resolve(this.boundWitnessDiviner)).pop(),"Unable to resolve boundWitnessDiviner"),v=this.batchLimit,L=(0,c.assertEx)(this.config.witnessSchema,()=>"Missing witnessSchema in config"),l=i,w=!0;for(;w||p.length<this.maxTrainingLength;){let T={addresses:o,limit:v,payload_schemas:a,schema:W.BoundWitnessDivinerQuerySchema,timestamp:l},h=(await y.divine([T])).filter(e=>e.timestamp&&e.timestamp>=t&&e.timestamp<=i);if(h.length===0||(l=h.map(e=>e.timestamp).filter(g.exists).reduce((e,j)=>Math.min(e,j),Number.MAX_SAFE_INTEGER),l===Number.MAX_SAFE_INTEGER))break;w=h.length===v;let E=h.map(e=>e.payload_hashes[e.payload_schemas.indexOf(L)]).filter(g.exists);if(E.length>0){let e=(await D.get(E)).filter(g.exists);p.push(...e)}}return p}};m(n,"MemoryForecastingDiviner"),f(n,"configSchemas",[...A(n,n,"configSchemas"),u.ForecastingDivinerConfigSchema]),f(n,"defaultConfigSchema",u.ForecastingDivinerConfigSchema),f(n,"forecastingMethodDict",{arimaForecasting:d.arimaForecastingMethod,seasonalArimaForecasting:d.seasonalArimaForecastingMethod});var b=n;0&&(module.exports={MemoryForecastingDiviner});
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 __reflectGet = Reflect.get;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
33
+ var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
34
+
35
+ // src/index.ts
36
+ var src_exports = {};
37
+ __export(src_exports, {
38
+ MemoryForecastingDiviner: () => MemoryForecastingDiviner
39
+ });
40
+ module.exports = __toCommonJS(src_exports);
41
+
42
+ // src/MemoryForecastingDiviner.ts
43
+ var import_assert = require("@xylabs/assert");
44
+ var import_exists = require("@xylabs/exists");
45
+ var import_archivist_model = require("@xyo-network/archivist-model");
46
+ var import_diviner_boundwitness_model = require("@xyo-network/diviner-boundwitness-model");
47
+ var import_diviner_forecasting_abstract = require("@xyo-network/diviner-forecasting-abstract");
48
+ var import_diviner_forecasting_method_arima = require("@xyo-network/diviner-forecasting-method-arima");
49
+ var import_diviner_forecasting_model = require("@xyo-network/diviner-forecasting-model");
50
+ var import_diviner_model = require("@xyo-network/diviner-model");
51
+ var import_jsonpath = __toESM(require("jsonpath"), 1);
52
+ var getJsonPathTransformer = /* @__PURE__ */ __name((pathExpression) => {
53
+ const transformer = /* @__PURE__ */ __name((x) => {
54
+ const ret = import_jsonpath.default.value(x, pathExpression);
55
+ if (typeof ret === "number") return ret;
56
+ throw new Error("Parsed invalid payload value");
57
+ }, "transformer");
58
+ return transformer;
59
+ }, "getJsonPathTransformer");
60
+ var _MemoryForecastingDiviner = class _MemoryForecastingDiviner extends import_diviner_forecasting_abstract.AbstractForecastingDiviner {
61
+ /**
62
+ * The max number of records to search during the batch query
63
+ */
64
+ batchLimit = 1e3;
65
+ // TODO: Inject via config
66
+ maxTrainingLength = 1e4;
67
+ get boundWitnessDiviner() {
68
+ return (0, import_assert.assertEx)(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
69
+ }
70
+ get forecastingMethod() {
71
+ const forecastingMethodName = (0, import_assert.assertEx)(this.config.forecastingMethod, () => "Missing forecastingMethod in config");
72
+ const forecastingMethod = _MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName];
73
+ if (forecastingMethod) return forecastingMethod;
74
+ throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
75
+ }
76
+ get transformer() {
77
+ const pathExpression = (0, import_assert.assertEx)(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
78
+ return getJsonPathTransformer(pathExpression);
79
+ }
80
+ async getPayloadsInWindow(startTimestamp, stopTimestamp) {
81
+ const addresses = this.config.witnessAddresses;
82
+ const payload_schemas = [
83
+ (0, import_assert.assertEx)(this.config.witnessSchema, () => "Missing witnessSchema in config")
84
+ ];
85
+ const payloads = [];
86
+ const archivist = (0, import_archivist_model.asArchivistInstance)(await this.archivistInstance(), () => "Unable to resolve archivist");
87
+ const bwDiviner = (0, import_diviner_model.asDivinerInstance)((await this.resolve(this.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
88
+ const limit = this.batchLimit;
89
+ const witnessSchema = (0, import_assert.assertEx)(this.config.witnessSchema, () => "Missing witnessSchema in config");
90
+ let timestamp = stopTimestamp;
91
+ let more = true;
92
+ while (more || payloads.length < this.maxTrainingLength) {
93
+ const query = {
94
+ addresses,
95
+ limit,
96
+ payload_schemas,
97
+ schema: import_diviner_boundwitness_model.BoundWitnessDivinerQuerySchema,
98
+ timestamp
99
+ };
100
+ const boundWitnesses = (await bwDiviner.divine([
101
+ query
102
+ ])).filter((bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp);
103
+ if (boundWitnesses.length === 0) break;
104
+ timestamp = boundWitnesses.map((bw) => bw.timestamp).filter(import_exists.exists).reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER);
105
+ if (timestamp === Number.MAX_SAFE_INTEGER) break;
106
+ more = boundWitnesses.length === limit;
107
+ const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(import_exists.exists);
108
+ if (hashes.length > 0) {
109
+ const batchPayloads = (await archivist.get(hashes)).filter(import_exists.exists);
110
+ payloads.push(...batchPayloads);
111
+ }
112
+ }
113
+ return payloads;
114
+ }
115
+ };
116
+ __name(_MemoryForecastingDiviner, "MemoryForecastingDiviner");
117
+ __publicField(_MemoryForecastingDiviner, "configSchemas", [
118
+ ...__superGet(_MemoryForecastingDiviner, _MemoryForecastingDiviner, "configSchemas"),
119
+ import_diviner_forecasting_model.ForecastingDivinerConfigSchema
120
+ ]);
121
+ __publicField(_MemoryForecastingDiviner, "defaultConfigSchema", import_diviner_forecasting_model.ForecastingDivinerConfigSchema);
122
+ __publicField(_MemoryForecastingDiviner, "forecastingMethodDict", {
123
+ arimaForecasting: import_diviner_forecasting_method_arima.arimaForecastingMethod,
124
+ seasonalArimaForecasting: import_diviner_forecasting_method_arima.seasonalArimaForecastingMethod
125
+ });
126
+ var MemoryForecastingDiviner = _MemoryForecastingDiviner;
127
+ // Annotate the CommonJS export names for ESM import in node:
128
+ 0 && (module.exports = {
129
+ MemoryForecastingDiviner
130
+ });
2
131
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n const transformer = (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n return transformer\n}\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override 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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":"kyBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAyB,0BACzBC,EAAuB,0BACvBC,EAAoC,wCAEpC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AmB,CACvD,IAAM4B,EAAyC,CAAEhB,UAAAA,EAAWY,MAAAA,EAAOV,gBAAAA,EAAiBe,OAAQC,iCAAgCL,UAAAA,CAAU,EAChIM,GAAkB,MAAMX,EAAUY,OAAO,CAACJ,EAAM,GAAGK,OACtDC,GAAOA,EAAGT,WAAaS,EAAGT,WAAaf,GAAkBwB,EAAGT,WAAad,CAAAA,EAU5E,GARIoB,EAAeJ,SAAW,IAG9BF,EAAYM,EACTI,IAAKD,GAAOA,EAAGT,SAAS,EACxBQ,OAAOG,QAAAA,EAEPC,OAAO,CAACC,EAAGC,IAAMC,KAAKC,IAAIH,EAAGC,CAAAA,EAAIG,OAAOC,gBAAgB,EACvDlB,IAAciB,OAAOC,kBAAkB,MAG3CjB,EAAOK,EAAeJ,SAAWH,EAGjC,IAAMoB,EAASb,EAAeI,IAAKD,GAAOA,EAAGW,eAAeX,EAAGpB,gBAAgBgC,QAAQ/B,CAAAA,CAAAA,CAAe,EAAEkB,OAAOG,QAAAA,EAG/G,GAAIQ,EAAOjB,OAAS,EAAG,CACrB,IAAMoB,GAAiB,MAAM9B,EAAU+B,IAAIJ,CAAAA,GAASX,OAAOG,QAAAA,EAC3DpB,EAASiC,KAAI,GAAIF,CAAAA,CACnB,CACF,CACA,OAAO/B,CACT,CACF,EA9EUlB,EAAAA,EAAAA,4BACRoD,EAHWrD,EAGcsD,gBAA0B,IAAIC,EAAAC,IAAMF,iBAAeG,mCAC5EJ,EAJWrD,EAIc0D,sBAA8BD,kCAEvDJ,EANWrD,EAMeS,wBAA6E,CACrGkD,iBAAkBC,yBAClBC,yBAA0BC,gCAC5B,GATK,IAAM9D,EAANwD","names":["src_exports","__export","MemoryForecastingDiviner","__toCommonJS","import_assert","import_exists","import_archivist_model","import_diviner_boundwitness_model","import_diviner_forecasting_abstract","import_diviner_forecasting_method_arima","import_diviner_forecasting_model","import_diviner_model","import_jsonpath","getJsonPathTransformer","__name","pathExpression","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","forecastingMethodDict","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","__publicField","configSchemas","__superGet","_MemoryForecastingDiviner","ForecastingDivinerConfigSchema","defaultConfigSchema","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["export * from './MemoryForecastingDiviner'\n","import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n const transformer = (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n return transformer\n}\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override 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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,oBAAyB;AACzB,oBAAuB;AACvB,6BAAoC;AAEpC,wCAA2G;AAC3G,0CAAqE;AACrE,8CAKO;AACP,uCAA2F;AAC3F,2BAAmD;AAEnD,sBAAqB;AAIrB,IAAMA,yBAAyB,wBAACC,mBAAAA;AAC9B,QAAMC,cAAc,wBAACC,MAAAA;AACnB,UAAMC,MAAMC,gBAAAA,QAASC,MAAMH,GAAGF,cAAAA;AAC9B,QAAI,OAAOG,QAAQ,SAAU,QAAOA;AACpC,UAAM,IAAIG,MAAM,8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AACC,OAAOA,GAAGT,aAAaS,GAAGT,aAAaf,kBAAkBwB,GAAGT,aAAad,aAAAA;AAE5E,UAAIoB,eAAeJ,WAAW,EAAG;AAGjCF,kBAAYM,eACTI,IAAI,CAACD,OAAOA,GAAGT,SAAS,EACxBQ,OAAOG,oBAAAA,EAEPC,OAAO,CAACC,GAAGC,MAAMC,KAAKC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC,iBAAkB;AAG3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAI,CAACD,OAAOA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,oBAAAA;AAG/G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,oBAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;AA9EUjB;AACR,cAHWD,2BAGcoD,iBAA0B;KAAI,iEAAMA;EAAeC;;AAC5E,cAJWrD,2BAIcsD,uBAA8BD;AAEvD,cANWrD,2BAMeS,yBAA6E;EACrG8C,kBAAkBC;EAClBC,0BAA0BC;AAC5B;AATK,IAAM1D,2BAAN;","names":["getJsonPathTransformer","pathExpression","transformer","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","forecastingMethodDict","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod"]}
@@ -1,2 +1,97 @@
1
- var u=Object.defineProperty;var I=Object.getPrototypeOf;var N=Reflect.get;var P=(e,t,s)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var c=(e,t)=>u(e,"name",{value:t,configurable:!0});var h=(e,t,s)=>P(e,typeof t!="symbol"?t+"":t,s);var b=(e,t,s)=>N(I(e),s,t);import{assertEx as o}from"@xylabs/assert";import{exists as g}from"@xylabs/exists";import{asArchivistInstance as D}from"@xyo-network/archivist-model";import{BoundWitnessDivinerQuerySchema as y}from"@xyo-network/diviner-boundwitness-model";import{AbstractForecastingDiviner as L}from"@xyo-network/diviner-forecasting-abstract";import{arimaForecastingMethod as T,seasonalArimaForecastingMethod as j}from"@xyo-network/diviner-forecasting-method-arima";import{ForecastingDivinerConfigSchema as v}from"@xyo-network/diviner-forecasting-model";import{asDivinerInstance as U}from"@xyo-network/diviner-model";import k from"jsonpath";var C=c(e=>c(s=>{let a=k.value(s,e);if(typeof a=="number")return a;throw new Error("Parsed invalid payload value")},"transformer"),"getJsonPathTransformer"),n=class n extends L{batchLimit=1e3;maxTrainingLength=1e4;get boundWitnessDiviner(){return o(this.config.boundWitnessDiviner,()=>"No boundWitnessDiviner configured")}get forecastingMethod(){let t=o(this.config.forecastingMethod,()=>"Missing forecastingMethod in config"),s=n.forecastingMethodDict[t];if(s)return s;throw new Error(`Unsupported forecasting method: ${t}`)}get transformer(){let t=o(this.config.jsonPathExpression,()=>"Missing jsonPathExpression in config");return C(t)}async getPayloadsInWindow(t,s){let a=this.config.witnessAddresses,E=[o(this.config.witnessSchema,()=>"Missing witnessSchema in config")],m=[],S=D(await this.archivistInstance(),()=>"Unable to resolve archivist"),x=U((await this.resolve(this.boundWitnessDiviner)).pop(),"Unable to resolve boundWitnessDiviner"),d=this.batchLimit,A=o(this.config.witnessSchema,()=>"Missing witnessSchema in config"),f=s,p=!0;for(;p||m.length<this.maxTrainingLength;){let M={addresses:a,limit:d,payload_schemas:E,schema:y,timestamp:f},r=(await x.divine([M])).filter(i=>i.timestamp&&i.timestamp>=t&&i.timestamp<=s);if(r.length===0||(f=r.map(i=>i.timestamp).filter(g).reduce((i,W)=>Math.min(i,W),Number.MAX_SAFE_INTEGER),f===Number.MAX_SAFE_INTEGER))break;p=r.length===d;let l=r.map(i=>i.payload_hashes[i.payload_schemas.indexOf(A)]).filter(g);if(l.length>0){let i=(await S.get(l)).filter(g);m.push(...i)}}return m}};c(n,"MemoryForecastingDiviner"),h(n,"configSchemas",[...b(n,n,"configSchemas"),v]),h(n,"defaultConfigSchema",v),h(n,"forecastingMethodDict",{arimaForecasting:T,seasonalArimaForecasting:j});var w=n;export{w as MemoryForecastingDiviner};
1
+ var __defProp = Object.defineProperty;
2
+ var __getProtoOf = Object.getPrototypeOf;
3
+ var __reflectGet = Reflect.get;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
8
+
9
+ // src/MemoryForecastingDiviner.ts
10
+ import { assertEx } from "@xylabs/assert";
11
+ import { exists } from "@xylabs/exists";
12
+ import { asArchivistInstance } from "@xyo-network/archivist-model";
13
+ import { BoundWitnessDivinerQuerySchema } from "@xyo-network/diviner-boundwitness-model";
14
+ import { AbstractForecastingDiviner } from "@xyo-network/diviner-forecasting-abstract";
15
+ import { arimaForecastingMethod, seasonalArimaForecastingMethod } from "@xyo-network/diviner-forecasting-method-arima";
16
+ import { ForecastingDivinerConfigSchema } from "@xyo-network/diviner-forecasting-model";
17
+ import { asDivinerInstance } from "@xyo-network/diviner-model";
18
+ import jsonpath from "jsonpath";
19
+ var getJsonPathTransformer = /* @__PURE__ */ __name((pathExpression) => {
20
+ const transformer = /* @__PURE__ */ __name((x) => {
21
+ const ret = jsonpath.value(x, pathExpression);
22
+ if (typeof ret === "number") return ret;
23
+ throw new Error("Parsed invalid payload value");
24
+ }, "transformer");
25
+ return transformer;
26
+ }, "getJsonPathTransformer");
27
+ var _MemoryForecastingDiviner = class _MemoryForecastingDiviner extends AbstractForecastingDiviner {
28
+ /**
29
+ * The max number of records to search during the batch query
30
+ */
31
+ batchLimit = 1e3;
32
+ // TODO: Inject via config
33
+ maxTrainingLength = 1e4;
34
+ get boundWitnessDiviner() {
35
+ return assertEx(this.config.boundWitnessDiviner, () => "No boundWitnessDiviner configured");
36
+ }
37
+ get forecastingMethod() {
38
+ const forecastingMethodName = assertEx(this.config.forecastingMethod, () => "Missing forecastingMethod in config");
39
+ const forecastingMethod = _MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName];
40
+ if (forecastingMethod) return forecastingMethod;
41
+ throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`);
42
+ }
43
+ get transformer() {
44
+ const pathExpression = assertEx(this.config.jsonPathExpression, () => "Missing jsonPathExpression in config");
45
+ return getJsonPathTransformer(pathExpression);
46
+ }
47
+ async getPayloadsInWindow(startTimestamp, stopTimestamp) {
48
+ const addresses = this.config.witnessAddresses;
49
+ const payload_schemas = [
50
+ assertEx(this.config.witnessSchema, () => "Missing witnessSchema in config")
51
+ ];
52
+ const payloads = [];
53
+ const archivist = asArchivistInstance(await this.archivistInstance(), () => "Unable to resolve archivist");
54
+ const bwDiviner = asDivinerInstance((await this.resolve(this.boundWitnessDiviner)).pop(), "Unable to resolve boundWitnessDiviner");
55
+ const limit = this.batchLimit;
56
+ const witnessSchema = assertEx(this.config.witnessSchema, () => "Missing witnessSchema in config");
57
+ let timestamp = stopTimestamp;
58
+ let more = true;
59
+ while (more || payloads.length < this.maxTrainingLength) {
60
+ const query = {
61
+ addresses,
62
+ limit,
63
+ payload_schemas,
64
+ schema: BoundWitnessDivinerQuerySchema,
65
+ timestamp
66
+ };
67
+ const boundWitnesses = (await bwDiviner.divine([
68
+ query
69
+ ])).filter((bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp);
70
+ if (boundWitnesses.length === 0) break;
71
+ timestamp = boundWitnesses.map((bw) => bw.timestamp).filter(exists).reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER);
72
+ if (timestamp === Number.MAX_SAFE_INTEGER) break;
73
+ more = boundWitnesses.length === limit;
74
+ const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists);
75
+ if (hashes.length > 0) {
76
+ const batchPayloads = (await archivist.get(hashes)).filter(exists);
77
+ payloads.push(...batchPayloads);
78
+ }
79
+ }
80
+ return payloads;
81
+ }
82
+ };
83
+ __name(_MemoryForecastingDiviner, "MemoryForecastingDiviner");
84
+ __publicField(_MemoryForecastingDiviner, "configSchemas", [
85
+ ...__superGet(_MemoryForecastingDiviner, _MemoryForecastingDiviner, "configSchemas"),
86
+ ForecastingDivinerConfigSchema
87
+ ]);
88
+ __publicField(_MemoryForecastingDiviner, "defaultConfigSchema", ForecastingDivinerConfigSchema);
89
+ __publicField(_MemoryForecastingDiviner, "forecastingMethodDict", {
90
+ arimaForecasting: arimaForecastingMethod,
91
+ seasonalArimaForecasting: seasonalArimaForecastingMethod
92
+ });
93
+ var MemoryForecastingDiviner = _MemoryForecastingDiviner;
94
+ export {
95
+ MemoryForecastingDiviner
96
+ };
2
97
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n const transformer = (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n return transformer\n}\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override 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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":"gSAAA,OAASA,YAAAA,MAAgB,iBACzB,OAASC,UAAAA,MAAc,iBACvB,OAASC,uBAAAA,MAA2B,+BAEpC,OAAqEC,kCAAAA,MAAsC,0CAC3G,OAASC,8BAAAA,MAA4D,4CACrE,OACEC,0BAAAA,EAEAC,kCAAAA,MAEK,gDACP,OAASC,kCAAAA,MAAkF,yCAC3F,OAASC,qBAAAA,MAA0C,6BAEnD,OAAOC,MAAc,WAIrB,IAAMC,EAAyBC,EAACC,GACVD,EAACE,GAAAA,CACnB,IAAMC,EAAMC,EAASC,MAAMH,EAAGD,CAAAA,EAC9B,GAAI,OAAOE,GAAQ,SAAU,OAAOA,EACpC,MAAM,IAAIG,MAAM,8BAAA,CAClB,EAJoB,eADS,0BASlBC,EAAN,MAAMA,UAEHC,CAAAA,CAYWC,WAAa,IAGbC,kBAAoB,IAEvC,IAAIC,qBAAsB,CACxB,OAAOC,EAAS,KAAKC,OAAOF,oBAAqB,IAAM,mCAAA,CACzD,CAEA,IAAuBG,mBAAuC,CAC5D,IAAMC,EAAwBH,EAAS,KAAKC,OAAOC,kBAAmB,IAAM,qCAAA,EACtEA,EAAoBP,EAAyBS,sBAAsBD,CAAAA,EACzE,GAAID,EAAmB,OAAOA,EAC9B,MAAM,IAAIR,MAAM,mCAAmCS,CAAAA,EAAuB,CAC5E,CAEA,IAAuBE,aAAuC,CAC5D,IAAMhB,EAAiBW,EAAS,KAAKC,OAAOK,mBAAoB,IAAM,sCAAA,EACtE,OAAOnB,EAAuBE,CAAAA,CAChC,CAEA,MAAyBkB,oBAAoBC,EAAwBC,EAA2C,CAC9G,IAAMC,EAAY,KAAKT,OAAOU,iBACxBC,EAAkB,CAACZ,EAAS,KAAKC,OAAOY,cAAe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AJWrD,EAIc0D,sBAA8BD,GAEvDJ,EANWrD,EAMeS,wBAA6E,CACrGkD,iBAAkBC,EAClBC,yBAA0BC,CAC5B,GATK,IAAM9D,EAANwD","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","__name","pathExpression","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","forecastingMethodDict","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","__publicField","configSchemas","__superGet","_MemoryForecastingDiviner","ForecastingDivinerConfigSchema","defaultConfigSchema","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod"]}
1
+ {"version":3,"sources":["../../src/MemoryForecastingDiviner.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { exists } from '@xylabs/exists'\nimport { asArchivistInstance } from '@xyo-network/archivist-model'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitnessDivinerQuerySchema } from '@xyo-network/diviner-boundwitness-model'\nimport { AbstractForecastingDiviner, ForecastingDivinerParams } from '@xyo-network/diviner-forecasting-abstract'\nimport {\n arimaForecastingMethod,\n arimaForecastingName,\n seasonalArimaForecastingMethod,\n seasonalArimaForecastingName,\n} from '@xyo-network/diviner-forecasting-method-arima'\nimport { ForecastingDivinerConfigSchema, ForecastingMethod, PayloadValueTransformer } from '@xyo-network/diviner-forecasting-model'\nimport { asDivinerInstance, DivinerInstance } from '@xyo-network/diviner-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\n\nexport type SupportedForecastingType = typeof arimaForecastingName | typeof seasonalArimaForecastingName\n\nconst getJsonPathTransformer = (pathExpression: string): PayloadValueTransformer => {\n const transformer = (x: Payload): number => {\n const ret = jsonpath.value(x, pathExpression)\n if (typeof ret === 'number') return ret\n throw new Error('Parsed invalid payload value')\n }\n return transformer\n}\n\nexport class MemoryForecastingDiviner<\n TParams extends ForecastingDivinerParams = ForecastingDivinerParams,\n> extends AbstractForecastingDiviner<TParams> {\n static override 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 /**\n * The max number of records to search during the batch query\n */\n protected readonly batchLimit = 1000\n\n // TODO: Inject via config\n protected readonly maxTrainingLength = 10_000\n\n get boundWitnessDiviner() {\n return assertEx(this.config.boundWitnessDiviner, () => 'No boundWitnessDiviner configured')\n }\n\n protected override get forecastingMethod(): ForecastingMethod {\n const forecastingMethodName = assertEx(this.config.forecastingMethod, () => 'Missing forecastingMethod in config') as SupportedForecastingType\n const forecastingMethod = MemoryForecastingDiviner.forecastingMethodDict[forecastingMethodName]\n if (forecastingMethod) return forecastingMethod\n throw new Error(`Unsupported forecasting method: ${forecastingMethodName}`)\n }\n\n protected override get transformer(): PayloadValueTransformer {\n const pathExpression = assertEx(this.config.jsonPathExpression, () => 'Missing jsonPathExpression in config')\n return getJsonPathTransformer(pathExpression)\n }\n\n protected override async getPayloadsInWindow(startTimestamp: number, stopTimestamp: number): Promise<Payload[]> {\n const addresses = this.config.witnessAddresses\n const payload_schemas = [assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')]\n const payloads: Payload[] = []\n const archivist = asArchivistInstance(await this.archivistInstance(), () => 'Unable to resolve archivist')\n const bwDiviner = asDivinerInstance(\n (await this.resolve(this.boundWitnessDiviner)).pop(),\n 'Unable to resolve boundWitnessDiviner',\n ) as DivinerInstance<BoundWitnessDivinerParams, BoundWitnessDivinerQueryPayload, BoundWitness>\n const limit = this.batchLimit\n const witnessSchema = assertEx(this.config.witnessSchema, () => 'Missing witnessSchema in config')\n let timestamp = stopTimestamp\n let more = true\n\n // TODO: Window size vs sample size\n // Loop until there are no more BWs to process or we've got enough payloads to satisfy the training window\n while (more || payloads.length < this.maxTrainingLength) {\n const query: BoundWitnessDivinerQueryPayload = { addresses, limit, payload_schemas, schema: BoundWitnessDivinerQuerySchema, timestamp }\n const boundWitnesses = (await bwDiviner.divine([query])).filter(\n (bw) => bw.timestamp && bw.timestamp >= startTimestamp && bw.timestamp <= stopTimestamp,\n )\n if (boundWitnesses.length === 0) break\n\n // Update the timestamp value for the next batch\n timestamp = boundWitnesses\n .map((bw) => bw.timestamp)\n .filter(exists)\n // eslint-disable-next-line unicorn/no-array-reduce\n .reduce((a, b) => Math.min(a, b), Number.MAX_SAFE_INTEGER)\n if (timestamp === Number.MAX_SAFE_INTEGER) break\n\n // Set the more flag to false if there are fewer documents returned than the batch size\n more = boundWitnesses.length === limit\n\n // Get the corresponding payload hashes from the BWs\n const hashes = boundWitnesses.map((bw) => bw.payload_hashes[bw.payload_schemas.indexOf(witnessSchema)]).filter(exists)\n\n // Get the payloads corresponding to the BW hashes from the archivist\n if (hashes.length > 0) {\n const batchPayloads = (await archivist.get(hashes)).filter(exists)\n payloads.push(...batchPayloads)\n }\n }\n return payloads\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,cAAc;AACvB,SAASC,2BAA2B;AAEpC,SAAqEC,sCAAsC;AAC3G,SAASC,kCAA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SAAS,KAAKC,OAAOW,eAAe,MAAM,iCAAA;AAChE,QAAIU,YAAYd;AAChB,QAAIe,OAAO;AAIX,WAAOA,QAAQV,SAASW,SAAS,KAAK1B,mBAAmB;AACvD,YAAM2B,QAAyC;QAAEhB;QAAWY;QAAOV;QAAiBe,QAAQC;QAAgCL;MAAU;AACtI,YAAMM,kBAAkB,MAAMX,UAAUY,OAAO;QAACJ;OAAM,GAAGK,OACvD,CAACC,OAAOA,GAAGT,aAAaS,GAAGT,aAAaf,kBAAkBwB,GAAGT,aAAad,aAAAA;AAE5E,UAAIoB,eAAeJ,WAAW,EAAG;AAGjCF,kBAAYM,eACTI,IAAI,CAACD,OAAOA,GAAGT,SAAS,EACxBQ,OAAOG,MAAAA,EAEPC,OAAO,CAACC,GAAGC,MAAMC,KAAKC,IAAIH,GAAGC,CAAAA,GAAIG,OAAOC,gBAAgB;AAC3D,UAAIlB,cAAciB,OAAOC,iBAAkB;AAG3CjB,aAAOK,eAAeJ,WAAWH;AAGjC,YAAMoB,SAASb,eAAeI,IAAI,CAACD,OAAOA,GAAGW,eAAeX,GAAGpB,gBAAgBgC,QAAQ/B,aAAAA,CAAAA,CAAe,EAAEkB,OAAOG,MAAAA;AAG/G,UAAIQ,OAAOjB,SAAS,GAAG;AACrB,cAAMoB,iBAAiB,MAAM9B,UAAU+B,IAAIJ,MAAAA,GAASX,OAAOG,MAAAA;AAC3DpB,iBAASiC,KAAI,GAAIF,aAAAA;MACnB;IACF;AACA,WAAO/B;EACT;AACF;AA9EUjB;AACR,cAHWD,2BAGcoD,iBAA0B;KAAI,iEAAMA;EAAeC;;AAC5E,cAJWrD,2BAIcsD,uBAA8BD;AAEvD,cANWrD,2BAMeS,yBAA6E;EACrG8C,kBAAkBC;EAClBC,0BAA0BC;AAC5B;AATK,IAAM1D,2BAAN;","names":["assertEx","exists","asArchivistInstance","BoundWitnessDivinerQuerySchema","AbstractForecastingDiviner","arimaForecastingMethod","seasonalArimaForecastingMethod","ForecastingDivinerConfigSchema","asDivinerInstance","jsonpath","getJsonPathTransformer","pathExpression","transformer","x","ret","jsonpath","value","Error","MemoryForecastingDiviner","AbstractForecastingDiviner","batchLimit","maxTrainingLength","boundWitnessDiviner","assertEx","config","forecastingMethod","forecastingMethodName","forecastingMethodDict","jsonPathExpression","getPayloadsInWindow","startTimestamp","stopTimestamp","addresses","witnessAddresses","payload_schemas","witnessSchema","payloads","archivist","asArchivistInstance","archivistInstance","bwDiviner","asDivinerInstance","resolve","pop","limit","timestamp","more","length","query","schema","BoundWitnessDivinerQuerySchema","boundWitnesses","divine","filter","bw","map","exists","reduce","a","b","Math","min","Number","MAX_SAFE_INTEGER","hashes","payload_hashes","indexOf","batchPayloads","get","push","configSchemas","ForecastingDivinerConfigSchema","defaultConfigSchema","arimaForecasting","arimaForecastingMethod","seasonalArimaForecasting","seasonalArimaForecastingMethod"]}
package/package.json CHANGED
@@ -12,20 +12,20 @@
12
12
  "dependencies": {
13
13
  "@xylabs/assert": "^3.5.1",
14
14
  "@xylabs/exists": "^3.5.1",
15
- "@xyo-network/archivist-model": "~2.107.3",
16
- "@xyo-network/boundwitness-model": "~2.107.3",
17
- "@xyo-network/diviner-boundwitness-model": "~2.107.3",
18
- "@xyo-network/diviner-forecasting-abstract": "~2.107.3",
19
- "@xyo-network/diviner-forecasting-method-arima": "~2.107.3",
20
- "@xyo-network/diviner-forecasting-model": "~2.107.3",
21
- "@xyo-network/diviner-model": "~2.107.3",
22
- "@xyo-network/payload-model": "~2.107.3",
15
+ "@xyo-network/archivist-model": "~2.107.5",
16
+ "@xyo-network/boundwitness-model": "~2.107.5",
17
+ "@xyo-network/diviner-boundwitness-model": "~2.107.5",
18
+ "@xyo-network/diviner-forecasting-abstract": "~2.107.5",
19
+ "@xyo-network/diviner-forecasting-method-arima": "~2.107.5",
20
+ "@xyo-network/diviner-forecasting-model": "~2.107.5",
21
+ "@xyo-network/diviner-model": "~2.107.5",
22
+ "@xyo-network/payload-model": "~2.107.5",
23
23
  "jsonpath": "^1.1.1"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/jsonpath": "^0.2.4",
27
- "@xylabs/ts-scripts-yarn3": "^3.11.9",
28
- "@xylabs/tsconfig": "^3.11.9",
27
+ "@xylabs/ts-scripts-yarn3": "^3.11.10",
28
+ "@xylabs/tsconfig": "^3.11.10",
29
29
  "typescript": "^5.5.2"
30
30
  },
31
31
  "description": "Primary SDK for using XYO Protocol 2.0",
@@ -67,6 +67,6 @@
67
67
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
68
68
  },
69
69
  "sideEffects": false,
70
- "version": "2.107.3",
70
+ "version": "2.107.5",
71
71
  "type": "module"
72
72
  }