@xyo-network/location-certainty-plugin 2.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +80 -0
  3. package/dist/cjs/Diviner/Config.d.ts +10 -0
  4. package/dist/cjs/Diviner/Config.d.ts.map +1 -0
  5. package/dist/cjs/Diviner/Config.js +5 -0
  6. package/dist/cjs/Diviner/Config.js.map +1 -0
  7. package/dist/cjs/Diviner/Diviner.d.ts +18 -0
  8. package/dist/cjs/Diviner/Diviner.d.ts.map +1 -0
  9. package/dist/cjs/Diviner/Diviner.js +104 -0
  10. package/dist/cjs/Diviner/Diviner.js.map +1 -0
  11. package/dist/cjs/Diviner/index.d.ts +3 -0
  12. package/dist/cjs/Diviner/index.d.ts.map +1 -0
  13. package/dist/cjs/Diviner/index.js +6 -0
  14. package/dist/cjs/Diviner/index.js.map +1 -0
  15. package/dist/cjs/Plugin.d.ts +16 -0
  16. package/dist/cjs/Plugin.d.ts.map +1 -0
  17. package/dist/cjs/Plugin.js +15 -0
  18. package/dist/cjs/Plugin.js.map +1 -0
  19. package/dist/cjs/index.d.ts +5 -0
  20. package/dist/cjs/index.d.ts.map +1 -0
  21. package/dist/cjs/index.js +10 -0
  22. package/dist/cjs/index.js.map +1 -0
  23. package/dist/docs.json +5434 -0
  24. package/dist/esm/Diviner/Config.d.ts +10 -0
  25. package/dist/esm/Diviner/Config.d.ts.map +1 -0
  26. package/dist/esm/Diviner/Config.js +2 -0
  27. package/dist/esm/Diviner/Config.js.map +1 -0
  28. package/dist/esm/Diviner/Diviner.d.ts +18 -0
  29. package/dist/esm/Diviner/Diviner.d.ts.map +1 -0
  30. package/dist/esm/Diviner/Diviner.js +87 -0
  31. package/dist/esm/Diviner/Diviner.js.map +1 -0
  32. package/dist/esm/Diviner/index.d.ts +3 -0
  33. package/dist/esm/Diviner/index.d.ts.map +1 -0
  34. package/dist/esm/Diviner/index.js +3 -0
  35. package/dist/esm/Diviner/index.js.map +1 -0
  36. package/dist/esm/Plugin.d.ts +16 -0
  37. package/dist/esm/Plugin.d.ts.map +1 -0
  38. package/dist/esm/Plugin.js +10 -0
  39. package/dist/esm/Plugin.js.map +1 -0
  40. package/dist/esm/index.d.ts +5 -0
  41. package/dist/esm/index.d.ts.map +1 -0
  42. package/dist/esm/index.js +6 -0
  43. package/dist/esm/index.js.map +1 -0
  44. package/package.json +66 -0
  45. package/src/Diviner/Config.ts +14 -0
  46. package/src/Diviner/Diviner.spec.ts +128 -0
  47. package/src/Diviner/Diviner.ts +106 -0
  48. package/src/Diviner/index.ts +2 -0
  49. package/src/Plugin.spec.ts +20 -0
  50. package/src/Plugin.ts +16 -0
  51. package/src/index.ts +8 -0
@@ -0,0 +1,10 @@
1
+ import { DivinerConfig } from '@xyo-network/diviner';
2
+ import { LocationCertaintyPayload, LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin';
3
+ import { XyoPayload } from '@xyo-network/payload';
4
+ export type LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config';
5
+ export declare const LocationCertaintyDivinerConfigSchema: LocationCertaintyDivinerConfigSchema;
6
+ export type LocationCertaintyDivinerConfig<TConfig extends XyoPayload = XyoPayload> = DivinerConfig<LocationCertaintyPayload, TConfig & {
7
+ schema: LocationCertaintyDivinerConfigSchema;
8
+ targetSchema: LocationCertaintySchema;
9
+ }>;
10
+ //# sourceMappingURL=Config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../../src/Diviner/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAA;AAClH,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjD,MAAM,MAAM,oCAAoC,GAAG,+CAA+C,CAAA;AAClG,eAAO,MAAM,oCAAoC,EAAE,oCAAsF,CAAA;AAEzI,MAAM,MAAM,8BAA8B,CAAC,OAAO,SAAS,UAAU,GAAG,UAAU,IAAI,aAAa,CACjG,wBAAwB,EACxB,OAAO,GAAG;IACR,MAAM,EAAE,oCAAoC,CAAA;IAC5C,YAAY,EAAE,uBAAuB,CAAA;CACtC,CACF,CAAA"}
@@ -0,0 +1,2 @@
1
+ export const LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config';
2
+ //# sourceMappingURL=Config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Config.js","sourceRoot":"","sources":["../../../src/Diviner/Config.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,oCAAoC,GAAyC,+CAA+C,CAAA"}
@@ -0,0 +1,18 @@
1
+ import { AbstractDiviner } from '@xyo-network/diviner';
2
+ import { XyoModuleParams } from '@xyo-network/module';
3
+ import { XyoPayloads } from '@xyo-network/payload';
4
+ import { Job, JobProvider } from '@xyo-network/shared';
5
+ import { LocationCertaintyDivinerConfig } from './Config';
6
+ export declare class LocationCertaintyDiviner extends AbstractDiviner<LocationCertaintyDivinerConfig> implements LocationCertaintyDiviner, JobProvider {
7
+ static configSchema: "network.xyo.location.elevation.diviner.config";
8
+ static targetSchema: "network.xyo.location.certainty";
9
+ get jobs(): Job[];
10
+ static create(params?: XyoModuleParams<LocationCertaintyDivinerConfig>): Promise<LocationCertaintyDiviner>;
11
+ private static calcHeuristic;
12
+ private static locationsToHeuristics;
13
+ /** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
14
+ divine(payloads?: XyoPayloads): Promise<XyoPayloads>;
15
+ /** @description Is the goal here to prime/index the diviner? */
16
+ private divineElevationBatch;
17
+ }
18
+ //# sourceMappingURL=Diviner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../../src/Diviner/Diviner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAKtD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAqB,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACrE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEtD,OAAO,EAAE,8BAA8B,EAAwC,MAAM,UAAU,CAAA;AAE/F,qBAAa,wBAAyB,SAAQ,eAAe,CAAC,8BAA8B,CAAE,YAAW,wBAAwB,EAAE,WAAW;IAC5I,OAAgB,YAAY,kDAAuC;IACnE,OAAgB,YAAY,mCAA0B;IAEtD,IAAI,IAAI,IAAI,GAAG,EAAE,CAQhB;WAEqB,MAAM,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,8BAA8B,CAAC;IAKrF,OAAO,CAAC,MAAM,CAAC,aAAa;IAqB5B,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAkBpC,wHAAwH;IAC3G,MAAM,CAAC,QAAQ,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IA4BjE,gEAAgE;IAChE,OAAO,CAAC,oBAAoB,CAK3B;CACF"}
@@ -0,0 +1,87 @@
1
+ import { AbstractDiviner } from '@xyo-network/diviner';
2
+ import { ElevationWitness, ElevationWitnessConfigSchema } from '@xyo-network/elevation-plugin';
3
+ import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin';
4
+ import { LocationSchema } from '@xyo-network/location-payload-plugin';
5
+ import { XyoPayloadBuilder } from '@xyo-network/payload';
6
+ import { LocationCertaintyDivinerConfigSchema } from './Config';
7
+ export class LocationCertaintyDiviner extends AbstractDiviner {
8
+ static configSchema = LocationCertaintyDivinerConfigSchema;
9
+ static targetSchema = LocationCertaintySchema;
10
+ get jobs() {
11
+ return [
12
+ {
13
+ name: 'LocationCertaintyDiviner.DivineElevationBatch',
14
+ schedule: '10 minute',
15
+ task: async () => await this.divineElevationBatch(),
16
+ },
17
+ ];
18
+ }
19
+ static async create(params) {
20
+ return (await super.create(params));
21
+ }
22
+ /* Given an array of numbers, find the min/max/mean */
23
+ static calcHeuristic(heuristic) {
24
+ return {
25
+ max: heuristic.reduce((prev, value) => {
26
+ return value !== null ? (value > prev ? value : prev) : prev;
27
+ }, -Infinity),
28
+ mean: (() => {
29
+ const values = heuristic.reduce((prev, value) => {
30
+ return value !== null ? [value + prev[0], prev[1] + 1] : prev;
31
+ }, [0, 0]);
32
+ return values[0] / values[1];
33
+ })(),
34
+ min: heuristic.reduce((prev, value) => {
35
+ return value !== null ? (value < prev ? value : prev) : prev;
36
+ }, Infinity),
37
+ };
38
+ }
39
+ /* Given elevation and location payloads, generate heuristic arrays */
40
+ static locationsToHeuristics(elevations, locations) {
41
+ const heuristics = elevations.reduce((prev, elev, index) => {
42
+ const elevation = elev.elevation;
43
+ if (elevation === undefined || elevation === null) {
44
+ throw Error('Invalid Elevation');
45
+ }
46
+ const altitude = locations[index].altitude;
47
+ prev.altitude.push(altitude ?? null);
48
+ prev.elevation.push(elevation);
49
+ prev.variance.push(altitude !== undefined && altitude !== null ? altitude - elevation : null);
50
+ return prev;
51
+ }, { altitude: [], elevation: [], variance: [] });
52
+ return heuristics;
53
+ }
54
+ /** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
55
+ async divine(payloads) {
56
+ const locations = payloads?.filter((payload) => payload?.schema === LocationSchema);
57
+ // If this is a query we support
58
+ if (locations && locations?.length > 0) {
59
+ const elevationWitness = await ElevationWitness.create({
60
+ config: {
61
+ locations,
62
+ schema: ElevationWitnessConfigSchema,
63
+ },
64
+ });
65
+ const elevations = (await elevationWitness.observe());
66
+ const heuristics = LocationCertaintyDiviner.locationsToHeuristics(elevations, locations);
67
+ const result = new XyoPayloadBuilder({ schema: LocationCertaintySchema })
68
+ .fields({
69
+ altitude: LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),
70
+ elevation: LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),
71
+ variance: LocationCertaintyDiviner.calcHeuristic(heuristics.variance),
72
+ })
73
+ .build();
74
+ this.logger?.log('LocationCertaintyDiviner.Divine: Processed query');
75
+ return [result];
76
+ }
77
+ return [];
78
+ }
79
+ /** @description Is the goal here to prime/index the diviner? */
80
+ divineElevationBatch = async () => {
81
+ this.logger?.log('LocationCertaintyDiviner.DivineElevationBatch: Divining elevations for batch');
82
+ // TODO: Any background/batch processing here
83
+ await Promise.resolve();
84
+ this.logger?.log('LocationCertaintyDiviner.DivineElevationBatch: Divined elevations for batch');
85
+ };
86
+ }
87
+ //# sourceMappingURL=Diviner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Diviner.js","sourceRoot":"","sources":["../../../src/Diviner/Diviner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAEtD,OAAO,EAAE,gBAAgB,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAA;AAC9F,OAAO,EAAwD,uBAAuB,EAAE,MAAM,gDAAgD,CAAA;AAC9I,OAAO,EAAmB,cAAc,EAAE,MAAM,sCAAsC,CAAA;AAEtF,OAAO,EAAE,iBAAiB,EAAe,MAAM,sBAAsB,CAAA;AAGrE,OAAO,EAAkC,oCAAoC,EAAE,MAAM,UAAU,CAAA;AAE/F,MAAM,OAAO,wBAAyB,SAAQ,eAA+C;IAC3F,MAAM,CAAU,YAAY,GAAG,oCAAoC,CAAA;IACnE,MAAM,CAAU,YAAY,GAAG,uBAAuB,CAAA;IAEtD,IAAI,IAAI;QACN,OAAO;YACL;gBACE,IAAI,EAAE,+CAA+C;gBACrD,QAAQ,EAAE,WAAW;gBACrB,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,oBAAoB,EAAE;aACpD;SACF,CAAA;IACH,CAAC;IAED,MAAM,CAAU,KAAK,CAAC,MAAM,CAAC,MAAwD;QACnF,OAAO,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAA6B,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B,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;YAExF,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAA2B,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC;iBAChG,MAAM,CAAC;gBACN,QAAQ,EAAE,wBAAwB,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC;gBACrE,SAAS,EAAE,wBAAwB,CAAC,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC;gBACvE,QAAQ,EAAE,wBAAwB,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC;aACtE,CAAC;iBACD,KAAK,EAAE,CAAA;YAEV,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,kDAAkD,CAAC,CAAA;YACpE,OAAO,CAAC,MAAM,CAAC,CAAA;SAChB;QACD,OAAO,EAAE,CAAA;IACX,CAAC;IAED,gEAAgE;IACxD,oBAAoB,GAAG,KAAK,IAAI,EAAE;QACxC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,8EAA8E,CAAC,CAAA;QAChG,6CAA6C;QAC7C,MAAM,OAAO,CAAC,OAAO,EAAE,CAAA;QACvB,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,6EAA6E,CAAC,CAAA;IACjG,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './Config';
2
+ export * from './Diviner';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Diviner/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './Config';
2
+ export * from './Diviner';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Diviner/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { XyoModuleParams } from '@xyo-network/module';
2
+ import { PayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin';
3
+ export declare const LocationCertaintyPlugin: () => PayloadSetDivinerPlugin<XyoModuleParams<import("@xyo-network/payload").SchemaFields & import("@xyo-network/payload").PayloadFields & {
4
+ security?: {
5
+ allowed?: Record<string, string[][]> | undefined;
6
+ disallowed?: Record<string, string[]> | undefined;
7
+ } | undefined;
8
+ } & {
9
+ targetSchema?: "network.xyo.location.certainty" | undefined;
10
+ } & {
11
+ schema: string;
12
+ } & {
13
+ schema: "network.xyo.location.elevation.diviner.config";
14
+ targetSchema: "network.xyo.location.certainty";
15
+ }>>;
16
+ //# sourceMappingURL=Plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD,OAAO,EAA0B,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;AAIhG,eAAO,MAAM,uBAAuB;;;;;;;;;;;;GAQjC,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin';
2
+ import { PayloadSetSchema } from '@xyo-network/payload';
3
+ import { createPayloadSetPlugin } from '@xyo-network/payloadset-plugin';
4
+ import { LocationCertaintyDiviner } from './Diviner';
5
+ export const LocationCertaintyPlugin = () => createPayloadSetPlugin({ required: { [LocationCertaintySchema]: 1 }, schema: PayloadSetSchema }, {
6
+ diviner: async (params) => {
7
+ return await LocationCertaintyDiviner.create(params);
8
+ },
9
+ });
10
+ //# sourceMappingURL=Plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Plugin.js","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAA;AAExF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,sBAAsB,EAA2B,MAAM,gCAAgC,CAAA;AAEhG,OAAO,EAAE,wBAAwB,EAAkC,MAAM,WAAW,CAAA;AAEpF,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,EAAE,CAC1C,sBAAsB,CACpB,EAAE,QAAQ,EAAE,EAAE,CAAC,uBAAuB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,EACxE;IACE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QACxB,OAAO,MAAM,wBAAwB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACtD,CAAC;CACF,CACF,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { LocationCertaintyPlugin } from './Plugin';
2
+ export * from './Diviner';
3
+ export { LocationCertaintyPlugin };
4
+ export default LocationCertaintyPlugin;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAElD,cAAc,WAAW,CAAA;AAEzB,OAAO,EAAE,uBAAuB,EAAE,CAAA;AAGlC,eAAe,uBAAuB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import { LocationCertaintyPlugin } from './Plugin';
2
+ export * from './Diviner';
3
+ export { LocationCertaintyPlugin };
4
+ // eslint-disable-next-line import/no-default-export
5
+ export default LocationCertaintyPlugin;
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAElD,cAAc,WAAW,CAAA;AAEzB,OAAO,EAAE,uBAAuB,EAAE,CAAA;AAElC,oDAAoD;AACpD,eAAe,uBAAuB,CAAA"}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@xyo-network/location-certainty-plugin",
3
+ "author": {
4
+ "email": "support@xyo.network",
5
+ "name": "XYO Development Team",
6
+ "url": "https://xyo.network"
7
+ },
8
+ "bugs": {
9
+ "email": "support@xyo.network",
10
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
+ },
12
+ "dependencies": {
13
+ "@xyo-network/diviner": "^2.42.0",
14
+ "@xyo-network/elevation-payload-plugin": "^2.42.0",
15
+ "@xyo-network/elevation-plugin": "^2.42.0",
16
+ "@xyo-network/location-certainty-payload-plugin": "^2.42.0",
17
+ "@xyo-network/location-payload-plugin": "^2.42.0",
18
+ "@xyo-network/module": "^2.42.0",
19
+ "@xyo-network/payload": "^2.42.0",
20
+ "@xyo-network/payloadset-plugin": "^2.42.0",
21
+ "@xyo-network/shared": "^2.42.0",
22
+ "tslib": "^2.4.1"
23
+ },
24
+ "devDependencies": {
25
+ "axios": "~1.2.1",
26
+ "pako": "^2.1.0"
27
+ },
28
+ "peerDependencies": {
29
+ "axios": "~1.2.1",
30
+ "pako": "^2.1.0"
31
+ },
32
+ "description": "Primary SDK for using XYO Protocol 2.0",
33
+ "browser": "dist/esm/index.js",
34
+ "docs": "dist/docs.json",
35
+ "exports": {
36
+ ".": {
37
+ "node": {
38
+ "import": "./dist/esm/index.js",
39
+ "require": "./dist/cjs/index.js"
40
+ },
41
+ "browser": {
42
+ "import": "./dist/esm/index.js",
43
+ "require": "./dist/cjs/index.js"
44
+ },
45
+ "default": "./dist/esm/index.js"
46
+ },
47
+ "./dist/docs.json": {
48
+ "default": "./dist/docs.json"
49
+ },
50
+ "./package.json": "./package.json"
51
+ },
52
+ "main": "dist/cjs/index.js",
53
+ "module": "dist/esm/index.js",
54
+ "homepage": "https://xyo.network",
55
+ "license": "LGPL-3.0-only",
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
62
+ },
63
+ "sideEffects": false,
64
+ "types": "dist/esm/index.d.ts",
65
+ "version": "2.42.0"
66
+ }
@@ -0,0 +1,14 @@
1
+ import { DivinerConfig } from '@xyo-network/diviner'
2
+ import { LocationCertaintyPayload, LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'
3
+ import { XyoPayload } from '@xyo-network/payload'
4
+
5
+ export type LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'
6
+ export const LocationCertaintyDivinerConfigSchema: LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'
7
+
8
+ export type LocationCertaintyDivinerConfig<TConfig extends XyoPayload = XyoPayload> = DivinerConfig<
9
+ LocationCertaintyPayload,
10
+ TConfig & {
11
+ schema: LocationCertaintyDivinerConfigSchema
12
+ targetSchema: LocationCertaintySchema
13
+ }
14
+ >
@@ -0,0 +1,128 @@
1
+ import { AbstractArchivist, MemoryArchivist } from '@xyo-network/archivist'
2
+ import { LocationCertaintyPayload, LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'
3
+ import { LocationPayload, LocationSchema } from '@xyo-network/location-payload-plugin'
4
+ import { XyoModuleResolver } from '@xyo-network/module'
5
+
6
+ import { LocationCertaintyDivinerConfigSchema } from './Config'
7
+ import { LocationCertaintyDiviner } from './Diviner'
8
+
9
+ const sample1: LocationPayload[] = [
10
+ {
11
+ altitude: -5,
12
+ latitude: 32.71664,
13
+ longitude: -117.12033,
14
+ schema: LocationSchema,
15
+ },
16
+ {
17
+ altitude: -9,
18
+ latitude: 32.7174,
19
+ longitude: -117.11674,
20
+ schema: LocationSchema,
21
+ },
22
+ {
23
+ altitude: -11,
24
+ latitude: 32.71788,
25
+ longitude: -117.11377,
26
+ schema: LocationSchema,
27
+ },
28
+ ]
29
+
30
+ const sample2: LocationPayload[] = [
31
+ {
32
+ altitude: 50,
33
+ latitude: 32.71664,
34
+ longitude: -117.12033,
35
+ schema: LocationSchema,
36
+ },
37
+ {
38
+ altitude: 53,
39
+ latitude: 32.7174,
40
+ longitude: -117.11674,
41
+ schema: LocationSchema,
42
+ },
43
+ {
44
+ altitude: 55,
45
+ latitude: 32.71788,
46
+ longitude: -117.11377,
47
+ schema: LocationSchema,
48
+ },
49
+ ]
50
+
51
+ const sample3: LocationPayload[] = [
52
+ {
53
+ altitude: 151,
54
+ latitude: 32.71664,
55
+ longitude: -117.12033,
56
+ schema: LocationSchema,
57
+ },
58
+ {
59
+ altitude: 163,
60
+ latitude: 32.7174,
61
+ longitude: -117.11674,
62
+ schema: LocationSchema,
63
+ },
64
+ {
65
+ altitude: 168,
66
+ latitude: 32.71788,
67
+ longitude: -117.11377,
68
+ schema: LocationSchema,
69
+ },
70
+ ]
71
+
72
+ describe('MongoDBLocationCertaintyDiviner', () => {
73
+ let payloadsArchivist: AbstractArchivist
74
+ let sut: LocationCertaintyDiviner
75
+ beforeEach(async () => {
76
+ payloadsArchivist = await MemoryArchivist.create()
77
+ const params = {
78
+ config: {
79
+ schema: LocationCertaintyDivinerConfigSchema,
80
+ targetSchema: LocationCertaintySchema,
81
+ },
82
+ resolver: new XyoModuleResolver().add(payloadsArchivist),
83
+ }
84
+ sut = await LocationCertaintyDiviner.create(params)
85
+ })
86
+ describe('divine', () => {
87
+ describe('with valid query', () => {
88
+ it('divines', async () => {
89
+ const noLocations: LocationPayload[] = []
90
+ const noLocationsResult = await sut.divine(noLocations)
91
+ expect(noLocationsResult).toBeArrayOfSize(0)
92
+ const locations: LocationPayload[] = [
93
+ { altitude: 5, quadkey: '0203', schema: LocationSchema },
94
+ { altitude: 300, quadkey: '0102', schema: LocationSchema },
95
+ ]
96
+ const locationsResult = await sut.divine(locations)
97
+ expect(locationsResult).toBeArrayOfSize(1)
98
+ const actual = locationsResult[0] as LocationCertaintyPayload
99
+ expect(actual).toBeObject()
100
+ expect(actual.schema).toBe(LocationCertaintySchema)
101
+
102
+ const locationsResult1 = (await sut.divine(sample1)) as LocationCertaintyPayload[]
103
+ const locationsResult2 = (await sut.divine(sample2)) as LocationCertaintyPayload[]
104
+ const locationsResult3 = (await sut.divine(sample3)) as LocationCertaintyPayload[]
105
+ ;[locationsResult1, locationsResult2, locationsResult3].map(validateLocationResult)
106
+ })
107
+ })
108
+ })
109
+ })
110
+
111
+ const validateLocationResult = (results: LocationCertaintyPayload[]) => {
112
+ expect(results).toBeArrayOfSize(1)
113
+ const [result] = results
114
+ expect(result).toBeObject()
115
+ expect(result.schema).toBe(LocationCertaintySchema)
116
+ expect(result.altitude).toBeObject()
117
+ expect(result.altitude.max).toBeNumber()
118
+ expect(result.altitude.mean).toBeNumber()
119
+ expect(result.altitude.min).toBeNumber()
120
+ expect(result.elevation).toBeObject()
121
+ expect(result.elevation.max).toBeNumber()
122
+ expect(result.elevation.mean).toBeNumber()
123
+ expect(result.elevation.min).toBeNumber()
124
+ expect(result.variance).toBeObject()
125
+ expect(result.variance.max).toBeNumber()
126
+ expect(result.variance.mean).toBeNumber()
127
+ expect(result.variance.min).toBeNumber()
128
+ }
@@ -0,0 +1,106 @@
1
+ import { AbstractDiviner } from '@xyo-network/diviner'
2
+ import { ElevationPayload } from '@xyo-network/elevation-payload-plugin'
3
+ import { ElevationWitness, ElevationWitnessConfigSchema } from '@xyo-network/elevation-plugin'
4
+ import { LocationCertaintyHeuristic, LocationCertaintyPayload, LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'
5
+ import { LocationPayload, LocationSchema } from '@xyo-network/location-payload-plugin'
6
+ import { XyoModuleParams } from '@xyo-network/module'
7
+ import { XyoPayloadBuilder, XyoPayloads } from '@xyo-network/payload'
8
+ import { Job, JobProvider } from '@xyo-network/shared'
9
+
10
+ import { LocationCertaintyDivinerConfig, LocationCertaintyDivinerConfigSchema } from './Config'
11
+
12
+ export class LocationCertaintyDiviner extends AbstractDiviner<LocationCertaintyDivinerConfig> implements LocationCertaintyDiviner, JobProvider {
13
+ static override configSchema = LocationCertaintyDivinerConfigSchema
14
+ static override targetSchema = LocationCertaintySchema
15
+
16
+ get jobs(): Job[] {
17
+ return [
18
+ {
19
+ name: 'LocationCertaintyDiviner.DivineElevationBatch',
20
+ schedule: '10 minute',
21
+ task: async () => await this.divineElevationBatch(),
22
+ },
23
+ ]
24
+ }
25
+
26
+ static override async create(params?: XyoModuleParams<LocationCertaintyDivinerConfig>) {
27
+ return (await super.create(params)) as LocationCertaintyDiviner
28
+ }
29
+
30
+ /* Given an array of numbers, find the min/max/mean */
31
+ private static calcHeuristic(heuristic: (number | null)[]): LocationCertaintyHeuristic {
32
+ return {
33
+ max: heuristic.reduce<number>((prev, value) => {
34
+ return value !== null ? (value > prev ? value : prev) : prev
35
+ }, -Infinity),
36
+ mean: (() => {
37
+ const values = heuristic.reduce<number[]>(
38
+ (prev, value) => {
39
+ return value !== null ? [value + prev[0], prev[1] + 1] : prev
40
+ },
41
+ [0, 0],
42
+ )
43
+ return values[0] / values[1]
44
+ })(),
45
+ min: heuristic.reduce<number>((prev, value) => {
46
+ return value !== null ? (value < prev ? value : prev) : prev
47
+ }, Infinity),
48
+ }
49
+ }
50
+
51
+ /* Given elevation and location payloads, generate heuristic arrays */
52
+ private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {
53
+ const heuristics = elevations.reduce<{ altitude: (number | null)[]; elevation: number[]; variance: (number | null)[] }>(
54
+ (prev, elev, index) => {
55
+ const elevation = elev.elevation
56
+ if (elevation === undefined || elevation === null) {
57
+ throw Error('Invalid Elevation')
58
+ }
59
+ const altitude = locations[index].altitude
60
+ prev.altitude.push(altitude ?? null)
61
+ prev.elevation.push(elevation)
62
+ prev.variance.push(altitude !== undefined && altitude !== null ? altitude - elevation : null)
63
+ return prev
64
+ },
65
+ { altitude: [], elevation: [], variance: [] },
66
+ )
67
+ return heuristics
68
+ }
69
+
70
+ /** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
71
+ public async divine(payloads?: XyoPayloads): Promise<XyoPayloads> {
72
+ const locations = payloads?.filter<LocationPayload>((payload): payload is LocationPayload => payload?.schema === LocationSchema)
73
+ // If this is a query we support
74
+ if (locations && locations?.length > 0) {
75
+ const elevationWitness = await ElevationWitness.create({
76
+ config: {
77
+ locations,
78
+ schema: ElevationWitnessConfigSchema,
79
+ },
80
+ })
81
+ const elevations = (await elevationWitness.observe()) as ElevationPayload[]
82
+
83
+ const heuristics = LocationCertaintyDiviner.locationsToHeuristics(elevations, locations)
84
+
85
+ const result = new XyoPayloadBuilder<LocationCertaintyPayload>({ schema: LocationCertaintySchema })
86
+ .fields({
87
+ altitude: LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),
88
+ elevation: LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),
89
+ variance: LocationCertaintyDiviner.calcHeuristic(heuristics.variance),
90
+ })
91
+ .build()
92
+
93
+ this.logger?.log('LocationCertaintyDiviner.Divine: Processed query')
94
+ return [result]
95
+ }
96
+ return []
97
+ }
98
+
99
+ /** @description Is the goal here to prime/index the diviner? */
100
+ private divineElevationBatch = async () => {
101
+ this.logger?.log('LocationCertaintyDiviner.DivineElevationBatch: Divining elevations for batch')
102
+ // TODO: Any background/batch processing here
103
+ await Promise.resolve()
104
+ this.logger?.log('LocationCertaintyDiviner.DivineElevationBatch: Divined elevations for batch')
105
+ }
106
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Config'
2
+ export * from './Diviner'
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+
5
+ import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'
6
+ import { PayloadSetPluginResolver } from '@xyo-network/payloadset-plugin'
7
+
8
+ import { LocationCertaintyDivinerConfigSchema } from './Diviner'
9
+ import { LocationCertaintyPlugin } from './Plugin'
10
+
11
+ describe('LocationCertaintyPlugin', () => {
12
+ test('Add to Resolver', () => {
13
+ const plugin = LocationCertaintyPlugin()
14
+ const resolver = new PayloadSetPluginResolver().register(plugin, {
15
+ diviner: { config: { schema: LocationCertaintyDivinerConfigSchema, targetSchema: LocationCertaintySchema } },
16
+ })
17
+ expect(resolver.resolve(plugin.set)).toBeObject()
18
+ expect(resolver.diviner(LocationCertaintySchema)).toBeObject()
19
+ })
20
+ })
package/src/Plugin.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'
2
+ import { XyoModuleParams } from '@xyo-network/module'
3
+ import { PayloadSetSchema } from '@xyo-network/payload'
4
+ import { createPayloadSetPlugin, PayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'
5
+
6
+ import { LocationCertaintyDiviner, LocationCertaintyDivinerConfig } from './Diviner'
7
+
8
+ export const LocationCertaintyPlugin = () =>
9
+ createPayloadSetPlugin<PayloadSetDivinerPlugin<XyoModuleParams<LocationCertaintyDivinerConfig>>>(
10
+ { required: { [LocationCertaintySchema]: 1 }, schema: PayloadSetSchema },
11
+ {
12
+ diviner: async (params) => {
13
+ return await LocationCertaintyDiviner.create(params)
14
+ },
15
+ },
16
+ )
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { LocationCertaintyPlugin } from './Plugin'
2
+
3
+ export * from './Diviner'
4
+
5
+ export { LocationCertaintyPlugin }
6
+
7
+ // eslint-disable-next-line import/no-default-export
8
+ export default LocationCertaintyPlugin