@xyo-network/location-certainty-plugin 2.96.0 → 2.96.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/Diviner/Diviner.d.cts +0 -1
- package/dist/browser/Diviner/Diviner.d.cts.map +1 -1
- package/dist/browser/Diviner/Diviner.d.mts +0 -1
- package/dist/browser/Diviner/Diviner.d.mts.map +1 -1
- package/dist/browser/Diviner/Diviner.d.ts +0 -1
- package/dist/browser/Diviner/Diviner.d.ts.map +1 -1
- package/dist/browser/Plugin.d.cts +9 -8
- package/dist/browser/Plugin.d.cts.map +1 -1
- package/dist/browser/Plugin.d.mts +9 -8
- package/dist/browser/Plugin.d.mts.map +1 -1
- package/dist/browser/Plugin.d.ts +9 -8
- package/dist/browser/Plugin.d.ts.map +1 -1
- package/dist/browser/index.cjs +1 -119
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +1 -96
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/Diviner/Diviner.d.cts +0 -1
- package/dist/neutral/Diviner/Diviner.d.cts.map +1 -1
- package/dist/neutral/Diviner/Diviner.d.mts +0 -1
- package/dist/neutral/Diviner/Diviner.d.mts.map +1 -1
- package/dist/neutral/Diviner/Diviner.d.ts +0 -1
- package/dist/neutral/Diviner/Diviner.d.ts.map +1 -1
- package/dist/neutral/Plugin.d.cts +9 -8
- package/dist/neutral/Plugin.d.cts.map +1 -1
- package/dist/neutral/Plugin.d.mts +9 -8
- package/dist/neutral/Plugin.d.mts.map +1 -1
- package/dist/neutral/Plugin.d.ts +9 -8
- package/dist/neutral/Plugin.d.ts.map +1 -1
- package/dist/neutral/index.cjs +1 -119
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +1 -96
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/Diviner/Diviner.d.cts +0 -1
- package/dist/node/Diviner/Diviner.d.cts.map +1 -1
- package/dist/node/Diviner/Diviner.d.mts +0 -1
- package/dist/node/Diviner/Diviner.d.mts.map +1 -1
- package/dist/node/Diviner/Diviner.d.ts +0 -1
- package/dist/node/Diviner/Diviner.d.ts.map +1 -1
- package/dist/node/Plugin.d.cts +9 -8
- package/dist/node/Plugin.d.cts.map +1 -1
- package/dist/node/Plugin.d.mts +9 -8
- package/dist/node/Plugin.d.mts.map +1 -1
- package/dist/node/Plugin.d.ts +9 -8
- package/dist/node/Plugin.d.ts.map +1 -1
- package/dist/node/index.cjs +1 -126
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +1 -97
- package/dist/node/index.js.map +1 -1
- package/package.json +18 -18
package/dist/node/index.cjs
CHANGED
|
@@ -1,127 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
LocationCertaintyDiviner: () => LocationCertaintyDiviner,
|
|
24
|
-
LocationCertaintyDivinerConfigSchema: () => LocationCertaintyDivinerConfigSchema,
|
|
25
|
-
LocationCertaintyPlugin: () => LocationCertaintyPlugin,
|
|
26
|
-
default: () => LocationCertaintyPlugin
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(src_exports);
|
|
29
|
-
|
|
30
|
-
// src/Diviner/Config.ts
|
|
31
|
-
var LocationCertaintyDivinerConfigSchema = "network.xyo.location.elevation.diviner.config";
|
|
32
|
-
|
|
33
|
-
// src/Diviner/Diviner.ts
|
|
34
|
-
var import_diviner_abstract = require("@xyo-network/diviner-abstract");
|
|
35
|
-
var import_elevation_plugin = require("@xyo-network/elevation-plugin");
|
|
36
|
-
var import_location_certainty_payload_plugin = require("@xyo-network/location-certainty-payload-plugin");
|
|
37
|
-
var import_location_payload_plugin = require("@xyo-network/location-payload-plugin");
|
|
38
|
-
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
39
|
-
var LocationCertaintyDiviner = class _LocationCertaintyDiviner extends import_diviner_abstract.AbstractDiviner {
|
|
40
|
-
static configSchemas = [...super.configSchemas, LocationCertaintyDivinerConfigSchema];
|
|
41
|
-
static defaultConfigSchema = LocationCertaintyDivinerConfigSchema;
|
|
42
|
-
static targetSchema = import_location_certainty_payload_plugin.LocationCertaintySchema;
|
|
43
|
-
/* Given an array of numbers, find the min/max/mean */
|
|
44
|
-
static calcHeuristic(heuristic) {
|
|
45
|
-
return {
|
|
46
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
47
|
-
max: heuristic.reduce((prev, value) => {
|
|
48
|
-
return value === null ? prev : value > prev ? value : prev;
|
|
49
|
-
}, Number.NEGATIVE_INFINITY),
|
|
50
|
-
mean: (() => {
|
|
51
|
-
const values = heuristic.reduce(
|
|
52
|
-
(prev, value) => {
|
|
53
|
-
return value === null ? prev : [value + prev[0], prev[1] + 1];
|
|
54
|
-
},
|
|
55
|
-
[0, 0]
|
|
56
|
-
);
|
|
57
|
-
return values[0] / values[1];
|
|
58
|
-
})(),
|
|
59
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
60
|
-
min: heuristic.reduce((prev, value) => {
|
|
61
|
-
return value === null ? prev : value < prev ? value : prev;
|
|
62
|
-
}, Number.POSITIVE_INFINITY)
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
/* Given elevation and location payloads, generate heuristic arrays */
|
|
66
|
-
static locationsToHeuristics(elevations, locations) {
|
|
67
|
-
const heuristics = elevations.reduce(
|
|
68
|
-
(prev, elev, index) => {
|
|
69
|
-
const elevation = elev.elevation;
|
|
70
|
-
if (elevation === void 0 || elevation === null) {
|
|
71
|
-
throw new Error("Invalid Elevation");
|
|
72
|
-
}
|
|
73
|
-
const altitude = locations[index].altitude;
|
|
74
|
-
prev.altitude.push(altitude ?? null);
|
|
75
|
-
prev.elevation.push(elevation);
|
|
76
|
-
prev.variance.push(altitude !== void 0 && altitude !== null ? altitude - elevation : null);
|
|
77
|
-
return prev;
|
|
78
|
-
},
|
|
79
|
-
{ altitude: [], elevation: [], variance: [] }
|
|
80
|
-
);
|
|
81
|
-
return heuristics;
|
|
82
|
-
}
|
|
83
|
-
/** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
|
|
84
|
-
async divineHandler(payloads) {
|
|
85
|
-
var _a;
|
|
86
|
-
const locations = payloads == null ? void 0 : payloads.filter((payload) => (payload == null ? void 0 : payload.schema) === import_location_payload_plugin.LocationSchema);
|
|
87
|
-
if (locations && (locations == null ? void 0 : locations.length) > 0) {
|
|
88
|
-
const elevationWitness = await import_elevation_plugin.ElevationWitness.create({
|
|
89
|
-
account: this.account,
|
|
90
|
-
config: {
|
|
91
|
-
locations,
|
|
92
|
-
schema: import_elevation_plugin.ElevationWitnessConfigSchema
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
const elevations = await elevationWitness.observe();
|
|
96
|
-
const heuristics = _LocationCertaintyDiviner.locationsToHeuristics(elevations, locations);
|
|
97
|
-
const result = await new import_payload_builder.PayloadBuilder({ schema: import_location_certainty_payload_plugin.LocationCertaintySchema }).fields({
|
|
98
|
-
altitude: _LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),
|
|
99
|
-
elevation: _LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),
|
|
100
|
-
variance: _LocationCertaintyDiviner.calcHeuristic(heuristics.variance)
|
|
101
|
-
}).build();
|
|
102
|
-
(_a = this.logger) == null ? void 0 : _a.log("LocationCertaintyDiviner.Divine: Processed query");
|
|
103
|
-
return [result];
|
|
104
|
-
}
|
|
105
|
-
return [];
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// src/Plugin.ts
|
|
110
|
-
var import_location_certainty_payload_plugin2 = require("@xyo-network/location-certainty-payload-plugin");
|
|
111
|
-
var import_payload_model = require("@xyo-network/payload-model");
|
|
112
|
-
var import_payloadset_plugin = require("@xyo-network/payloadset-plugin");
|
|
113
|
-
var LocationCertaintyPlugin = () => (0, import_payloadset_plugin.createPayloadSetDivinerPlugin)(
|
|
114
|
-
{ required: { [import_location_certainty_payload_plugin2.LocationCertaintySchema]: 1 }, schema: import_payload_model.PayloadSetSchema },
|
|
115
|
-
{
|
|
116
|
-
diviner: async (params) => {
|
|
117
|
-
return await LocationCertaintyDiviner.create(params);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
);
|
|
121
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
-
0 && (module.exports = {
|
|
123
|
-
LocationCertaintyDiviner,
|
|
124
|
-
LocationCertaintyDivinerConfigSchema,
|
|
125
|
-
LocationCertaintyPlugin
|
|
126
|
-
});
|
|
1
|
+
"use strict";var d=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var x=(o,t)=>{for(var i in t)d(o,i,{get:t[i],enumerable:!0})},b=(o,t,i,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of D(t))!p.call(o,n)&&n!==i&&d(o,n,{get:()=>t[n],enumerable:!(e=S(t,n))||e.enumerable});return o};var E=o=>b(d({},"__esModule",{value:!0}),o);var I={};x(I,{LocationCertaintyDiviner:()=>c,LocationCertaintyDivinerConfigSchema:()=>l,LocationCertaintyPlugin:()=>y,default:()=>y});module.exports=E(I);var l="network.xyo.location.elevation.diviner.config";var v=require("@xyo-network/diviner-abstract"),s=require("@xyo-network/elevation-plugin"),f=require("@xyo-network/location-certainty-payload-plugin"),C=require("@xyo-network/location-payload-plugin"),h=require("@xyo-network/payload-builder");var c=class o extends v.AbstractDiviner{static configSchemas=[...super.configSchemas,l];static defaultConfigSchema=l;static targetSchema=f.LocationCertaintySchema;static calcHeuristic(t){return{max:t.reduce((i,e)=>e===null?i:e>i?e:i,Number.NEGATIVE_INFINITY),mean:(()=>{let i=t.reduce((e,n)=>n===null?e:[n+e[0],e[1]+1],[0,0]);return i[0]/i[1]})(),min:t.reduce((i,e)=>e===null?i:e<i?e:i,Number.POSITIVE_INFINITY)}}static locationsToHeuristics(t,i){return t.reduce((n,u,r)=>{let a=u.elevation;if(a==null)throw new Error("Invalid Elevation");let m=i[r].altitude;return n.altitude.push(m??null),n.elevation.push(a),n.variance.push(m!=null?m-a:null),n},{altitude:[],elevation:[],variance:[]})}async divineHandler(t){var e;let i=t==null?void 0:t.filter(n=>(n==null?void 0:n.schema)===C.LocationSchema);if(i&&(i==null?void 0:i.length)>0){let u=await(await s.ElevationWitness.create({account:this.account,config:{locations:i,schema:s.ElevationWitnessConfigSchema}})).observe(),r=o.locationsToHeuristics(u,i),a=await new h.PayloadBuilder({schema:f.LocationCertaintySchema}).fields({altitude:o.calcHeuristic(r.altitude),elevation:o.calcHeuristic(r.elevation),variance:o.calcHeuristic(r.variance)}).build();return(e=this.logger)==null||e.log("LocationCertaintyDiviner.Divine: Processed query"),[a]}return[]}};var P=require("@xyo-network/location-certainty-payload-plugin"),g=require("@xyo-network/payload-model"),L=require("@xyo-network/payloadset-plugin");var y=()=>(0,L.createPayloadSetDivinerPlugin)({required:{[P.LocationCertaintySchema]:1},schema:g.PayloadSetSchema},{diviner:async o=>await c.create(o)});0&&(module.exports={LocationCertaintyDiviner,LocationCertaintyDivinerConfigSchema,LocationCertaintyPlugin});
|
|
127
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Diviner/Config.ts","../../src/Diviner/Diviner.ts","../../src/Plugin.ts"],"sourcesContent":["export * from './Diviner'\nexport { LocationCertaintyPlugin as default, LocationCertaintyPlugin } from './Plugin'\n","import { DivinerConfig } from '@xyo-network/diviner-model'\nimport { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport type LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'\nexport const LocationCertaintyDivinerConfigSchema: LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'\n\nexport type LocationCertaintyDivinerConfig<TConfig extends Payload = Payload> = DivinerConfig<\n TConfig & {\n schema: LocationCertaintyDivinerConfigSchema\n targetSchema?: LocationCertaintySchema\n }\n>\n","import { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerModule, DivinerParams } from '@xyo-network/diviner-model'\nimport { ElevationPayload } from '@xyo-network/elevation-payload-plugin'\nimport { ElevationWitness, ElevationWitnessConfigSchema } from '@xyo-network/elevation-plugin'\nimport { LocationCertaintyHeuristic, LocationCertaintyPayload, LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { LocationPayload, LocationSchema } from '@xyo-network/location-payload-plugin'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\nimport { LocationCertaintyDivinerConfig, LocationCertaintyDivinerConfigSchema } from './Config'\n\nexport type LocationCertaintyDivinerParams = DivinerParams<AnyConfigSchema<LocationCertaintyDivinerConfig>>\n\nexport class LocationCertaintyDiviner<TParam extends LocationCertaintyDivinerParams = LocationCertaintyDivinerParams>\n extends AbstractDiviner<TParam>\n implements DivinerModule\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, LocationCertaintyDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = LocationCertaintyDivinerConfigSchema\n static override targetSchema = LocationCertaintySchema\n\n /* Given an array of numbers, find the min/max/mean */\n private static calcHeuristic(heuristic: (number | null)[]): LocationCertaintyHeuristic {\n return {\n // eslint-disable-next-line unicorn/no-array-reduce\n max: heuristic.reduce<number>((prev, value) => {\n return (\n value === null ? prev\n : value > prev ? value\n : prev\n )\n }, Number.NEGATIVE_INFINITY),\n mean: (() => {\n // eslint-disable-next-line unicorn/no-array-reduce\n const values = heuristic.reduce<number[]>(\n (prev, value) => {\n return value === null ? prev : [value + prev[0], prev[1] + 1]\n },\n [0, 0],\n )\n return values[0] / values[1]\n })(),\n // eslint-disable-next-line unicorn/no-array-reduce\n min: heuristic.reduce<number>((prev, value) => {\n return (\n value === null ? prev\n : value < prev ? value\n : prev\n )\n }, Number.POSITIVE_INFINITY),\n }\n }\n\n /* Given elevation and location payloads, generate heuristic arrays */\n private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {\n // eslint-disable-next-line unicorn/no-array-reduce\n const heuristics = elevations.reduce<{ altitude: (number | null)[]; elevation: number[]; variance: (number | null)[] }>(\n (prev, elev, index) => {\n const elevation = elev.elevation\n if (elevation === undefined || elevation === null) {\n throw new Error('Invalid Elevation')\n }\n const altitude = locations[index].altitude\n prev.altitude.push(altitude ?? null)\n prev.elevation.push(elevation)\n prev.variance.push(altitude !== undefined && altitude !== null ? altitude - elevation : null)\n return prev\n },\n { altitude: [], elevation: [], variance: [] },\n )\n return heuristics\n }\n\n /** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const locations = payloads?.filter<LocationPayload>((payload): payload is LocationPayload => payload?.schema === LocationSchema)\n // If this is a query we support\n if (locations && locations?.length > 0) {\n const elevationWitness = await ElevationWitness.create({\n account: this.account,\n config: {\n locations,\n schema: ElevationWitnessConfigSchema,\n },\n })\n const elevations = (await elevationWitness.observe()) as ElevationPayload[]\n\n const heuristics = LocationCertaintyDiviner.locationsToHeuristics(elevations, locations)\n\n const result = await new PayloadBuilder<LocationCertaintyPayload>({ schema: LocationCertaintySchema })\n .fields({\n altitude: LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),\n elevation: LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),\n variance: LocationCertaintyDiviner.calcHeuristic(heuristics.variance),\n })\n .build()\n\n this.logger?.log('LocationCertaintyDiviner.Divine: Processed query')\n return [result]\n }\n return []\n }\n}\n","import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { LocationCertaintyDiviner } from './Diviner'\n\nexport const LocationCertaintyPlugin = () =>\n createPayloadSetDivinerPlugin<LocationCertaintyDiviner>(\n { required: { [LocationCertaintySchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n return (await LocationCertaintyDiviner.create(params)) as LocationCertaintyDiviner\n },\n },\n )\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Diviner/Config.ts","../../src/Diviner/Diviner.ts","../../src/Plugin.ts"],"sourcesContent":["export * from './Diviner'\nexport { LocationCertaintyPlugin as default, LocationCertaintyPlugin } from './Plugin'\n","import { DivinerConfig } from '@xyo-network/diviner-model'\nimport { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport type LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'\nexport const LocationCertaintyDivinerConfigSchema: LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'\n\nexport type LocationCertaintyDivinerConfig<TConfig extends Payload = Payload> = DivinerConfig<\n TConfig & {\n schema: LocationCertaintyDivinerConfigSchema\n targetSchema?: LocationCertaintySchema\n }\n>\n","import { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerModule, DivinerParams } from '@xyo-network/diviner-model'\nimport { ElevationPayload } from '@xyo-network/elevation-payload-plugin'\nimport { ElevationWitness, ElevationWitnessConfigSchema } from '@xyo-network/elevation-plugin'\nimport { LocationCertaintyHeuristic, LocationCertaintyPayload, LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { LocationPayload, LocationSchema } from '@xyo-network/location-payload-plugin'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\nimport { LocationCertaintyDivinerConfig, LocationCertaintyDivinerConfigSchema } from './Config'\n\nexport type LocationCertaintyDivinerParams = DivinerParams<AnyConfigSchema<LocationCertaintyDivinerConfig>>\n\nexport class LocationCertaintyDiviner<TParam extends LocationCertaintyDivinerParams = LocationCertaintyDivinerParams>\n extends AbstractDiviner<TParam>\n implements DivinerModule\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, LocationCertaintyDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = LocationCertaintyDivinerConfigSchema\n static override targetSchema = LocationCertaintySchema\n\n /* Given an array of numbers, find the min/max/mean */\n private static calcHeuristic(heuristic: (number | null)[]): LocationCertaintyHeuristic {\n return {\n // eslint-disable-next-line unicorn/no-array-reduce\n max: heuristic.reduce<number>((prev, value) => {\n return (\n value === null ? prev\n : value > prev ? value\n : prev\n )\n }, Number.NEGATIVE_INFINITY),\n mean: (() => {\n // eslint-disable-next-line unicorn/no-array-reduce\n const values = heuristic.reduce<number[]>(\n (prev, value) => {\n return value === null ? prev : [value + prev[0], prev[1] + 1]\n },\n [0, 0],\n )\n return values[0] / values[1]\n })(),\n // eslint-disable-next-line unicorn/no-array-reduce\n min: heuristic.reduce<number>((prev, value) => {\n return (\n value === null ? prev\n : value < prev ? value\n : prev\n )\n }, Number.POSITIVE_INFINITY),\n }\n }\n\n /* Given elevation and location payloads, generate heuristic arrays */\n private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {\n // eslint-disable-next-line unicorn/no-array-reduce\n const heuristics = elevations.reduce<{ altitude: (number | null)[]; elevation: number[]; variance: (number | null)[] }>(\n (prev, elev, index) => {\n const elevation = elev.elevation\n if (elevation === undefined || elevation === null) {\n throw new Error('Invalid Elevation')\n }\n const altitude = locations[index].altitude\n prev.altitude.push(altitude ?? null)\n prev.elevation.push(elevation)\n prev.variance.push(altitude !== undefined && altitude !== null ? altitude - elevation : null)\n return prev\n },\n { altitude: [], elevation: [], variance: [] },\n )\n return heuristics\n }\n\n /** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const locations = payloads?.filter<LocationPayload>((payload): payload is LocationPayload => payload?.schema === LocationSchema)\n // If this is a query we support\n if (locations && locations?.length > 0) {\n const elevationWitness = await ElevationWitness.create({\n account: this.account,\n config: {\n locations,\n schema: ElevationWitnessConfigSchema,\n },\n })\n const elevations = (await elevationWitness.observe()) as ElevationPayload[]\n\n const heuristics = LocationCertaintyDiviner.locationsToHeuristics(elevations, locations)\n\n const result = await new PayloadBuilder<LocationCertaintyPayload>({ schema: LocationCertaintySchema })\n .fields({\n altitude: LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),\n elevation: LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),\n variance: LocationCertaintyDiviner.calcHeuristic(heuristics.variance),\n })\n .build()\n\n this.logger?.log('LocationCertaintyDiviner.Divine: Processed query')\n return [result]\n }\n return []\n }\n}\n","import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { LocationCertaintyDiviner } from './Diviner'\n\nexport const LocationCertaintyPlugin = () =>\n createPayloadSetDivinerPlugin<LocationCertaintyDiviner>(\n { required: { [LocationCertaintySchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n return (await LocationCertaintyDiviner.create(params)) as LocationCertaintyDiviner\n },\n },\n )\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,EAAA,yCAAAC,EAAA,4BAAAC,EAAA,YAAAA,IAAA,eAAAC,EAAAL,GCKO,IAAMM,EAA6E,gDCL1F,IAAAC,EAAgC,yCAGhCC,EAA+D,yCAC/DC,EAA8F,0DAC9FC,EAAgD,gDAEhDC,EAA+B,wCAOxB,IAAMC,EAAN,MAAMC,UACH,iBAEV,CACE,OAAyB,cAA0B,CAAC,GAAG,MAAM,cAAeC,CAAoC,EAChH,OAAyB,oBAA8BA,EACvD,OAAgB,aAAe,0BAG/B,OAAe,cAAcC,EAA0D,CACrF,MAAO,CAEL,IAAKA,EAAU,OAAe,CAACC,EAAMC,IAEjCA,IAAU,KAAOD,EACfC,EAAQD,EAAOC,EACfD,EAEH,OAAO,iBAAiB,EAC3B,MAAO,IAAM,CAEX,IAAME,EAASH,EAAU,OACvB,CAACC,EAAMC,IACEA,IAAU,KAAOD,EAAO,CAACC,EAAQD,EAAK,CAAC,EAAGA,EAAK,CAAC,EAAI,CAAC,EAE9D,CAAC,EAAG,CAAC,CACP,EACA,OAAOE,EAAO,CAAC,EAAIA,EAAO,CAAC,CAC7B,GAAG,EAEH,IAAKH,EAAU,OAAe,CAACC,EAAMC,IAEjCA,IAAU,KAAOD,EACfC,EAAQD,EAAOC,EACfD,EAEH,OAAO,iBAAiB,CAC7B,CACF,CAGA,OAAe,sBAAsBG,EAAgCC,EAA8B,CAgBjG,OAdmBD,EAAW,OAC5B,CAACH,EAAMK,EAAMC,IAAU,CACrB,IAAMC,EAAYF,EAAK,UACvB,GAA+BE,GAAc,KAC3C,MAAM,IAAI,MAAM,mBAAmB,EAErC,IAAMC,EAAWJ,EAAUE,CAAK,EAAE,SAClC,OAAAN,EAAK,SAAS,KAAKQ,GAAY,IAAI,EACnCR,EAAK,UAAU,KAAKO,CAAS,EAC7BP,EAAK,SAAS,KAA+BQ,GAAa,KAAOA,EAAWD,EAAY,IAAI,EACrFP,CACT,EACA,CAAE,SAAU,CAAC,EAAG,UAAW,CAAC,EAAG,SAAU,CAAC,CAAE,CAC9C,CAEF,CAGA,MAAyB,cAAcS,EAA0C,CA3EnF,IAAAC,EA4EI,IAAMN,EAAYK,GAAA,YAAAA,EAAU,OAAyBE,IAAwCA,GAAA,YAAAA,EAAS,UAAW,kBAEjH,GAAIP,IAAaA,GAAA,YAAAA,EAAW,QAAS,EAAG,CAQtC,IAAMD,EAAc,MAPK,MAAM,mBAAiB,OAAO,CACrD,QAAS,KAAK,QACd,OAAQ,CACN,UAAAC,EACA,OAAQ,8BACV,CACF,CAAC,GAC0C,QAAQ,EAE7CQ,EAAaf,EAAyB,sBAAsBM,EAAYC,CAAS,EAEjFS,EAAS,MAAM,IAAI,iBAAyC,CAAE,OAAQ,yBAAwB,CAAC,EAClG,OAAO,CACN,SAAUhB,EAAyB,cAAce,EAAW,QAAQ,EACpE,UAAWf,EAAyB,cAAce,EAAW,SAAS,EACtE,SAAUf,EAAyB,cAAce,EAAW,QAAQ,CACtE,CAAC,EACA,MAAM,EAET,OAAAF,EAAA,KAAK,SAAL,MAAAA,EAAa,IAAI,oDACV,CAACG,CAAM,CAChB,CACA,MAAO,CAAC,CACV,CACF,ECvGA,IAAAC,EAAwC,0DACxCC,EAAiC,sCACjCC,EAA8C,0CAIvC,IAAMC,EAA0B,OACrC,iCACE,CAAE,SAAU,CAAE,CAAC,yBAAuB,EAAG,CAAE,EAAG,OAAQ,kBAAiB,EACvE,CACE,QAAS,MAAOC,GACN,MAAMC,EAAyB,OAAOD,CAAM,CAExD,CACF","names":["src_exports","__export","LocationCertaintyDiviner","LocationCertaintyDivinerConfigSchema","LocationCertaintyPlugin","__toCommonJS","LocationCertaintyDivinerConfigSchema","import_diviner_abstract","import_elevation_plugin","import_location_certainty_payload_plugin","import_location_payload_plugin","import_payload_builder","LocationCertaintyDiviner","_LocationCertaintyDiviner","LocationCertaintyDivinerConfigSchema","heuristic","prev","value","values","elevations","locations","elev","index","elevation","altitude","payloads","_a","payload","heuristics","result","import_location_certainty_payload_plugin","import_payload_model","import_payloadset_plugin","LocationCertaintyPlugin","params","LocationCertaintyDiviner"]}
|
package/dist/node/index.js
CHANGED
|
@@ -1,98 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var LocationCertaintyDivinerConfigSchema = "network.xyo.location.elevation.diviner.config";
|
|
3
|
-
|
|
4
|
-
// src/Diviner/Diviner.ts
|
|
5
|
-
import { AbstractDiviner } from "@xyo-network/diviner-abstract";
|
|
6
|
-
import { ElevationWitness, ElevationWitnessConfigSchema } from "@xyo-network/elevation-plugin";
|
|
7
|
-
import { LocationCertaintySchema } from "@xyo-network/location-certainty-payload-plugin";
|
|
8
|
-
import { LocationSchema } from "@xyo-network/location-payload-plugin";
|
|
9
|
-
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
10
|
-
var LocationCertaintyDiviner = class _LocationCertaintyDiviner extends AbstractDiviner {
|
|
11
|
-
static configSchemas = [...super.configSchemas, LocationCertaintyDivinerConfigSchema];
|
|
12
|
-
static defaultConfigSchema = LocationCertaintyDivinerConfigSchema;
|
|
13
|
-
static targetSchema = LocationCertaintySchema;
|
|
14
|
-
/* Given an array of numbers, find the min/max/mean */
|
|
15
|
-
static calcHeuristic(heuristic) {
|
|
16
|
-
return {
|
|
17
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
18
|
-
max: heuristic.reduce((prev, value) => {
|
|
19
|
-
return value === null ? prev : value > prev ? value : prev;
|
|
20
|
-
}, Number.NEGATIVE_INFINITY),
|
|
21
|
-
mean: (() => {
|
|
22
|
-
const values = heuristic.reduce(
|
|
23
|
-
(prev, value) => {
|
|
24
|
-
return value === null ? prev : [value + prev[0], prev[1] + 1];
|
|
25
|
-
},
|
|
26
|
-
[0, 0]
|
|
27
|
-
);
|
|
28
|
-
return values[0] / values[1];
|
|
29
|
-
})(),
|
|
30
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
31
|
-
min: heuristic.reduce((prev, value) => {
|
|
32
|
-
return value === null ? prev : value < prev ? value : prev;
|
|
33
|
-
}, Number.POSITIVE_INFINITY)
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/* Given elevation and location payloads, generate heuristic arrays */
|
|
37
|
-
static locationsToHeuristics(elevations, locations) {
|
|
38
|
-
const heuristics = elevations.reduce(
|
|
39
|
-
(prev, elev, index) => {
|
|
40
|
-
const elevation = elev.elevation;
|
|
41
|
-
if (elevation === void 0 || elevation === null) {
|
|
42
|
-
throw new Error("Invalid Elevation");
|
|
43
|
-
}
|
|
44
|
-
const altitude = locations[index].altitude;
|
|
45
|
-
prev.altitude.push(altitude ?? null);
|
|
46
|
-
prev.elevation.push(elevation);
|
|
47
|
-
prev.variance.push(altitude !== void 0 && altitude !== null ? altitude - elevation : null);
|
|
48
|
-
return prev;
|
|
49
|
-
},
|
|
50
|
-
{ altitude: [], elevation: [], variance: [] }
|
|
51
|
-
);
|
|
52
|
-
return heuristics;
|
|
53
|
-
}
|
|
54
|
-
/** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
|
|
55
|
-
async divineHandler(payloads) {
|
|
56
|
-
var _a;
|
|
57
|
-
const locations = payloads == null ? void 0 : payloads.filter((payload) => (payload == null ? void 0 : payload.schema) === LocationSchema);
|
|
58
|
-
if (locations && (locations == null ? void 0 : locations.length) > 0) {
|
|
59
|
-
const elevationWitness = await ElevationWitness.create({
|
|
60
|
-
account: this.account,
|
|
61
|
-
config: {
|
|
62
|
-
locations,
|
|
63
|
-
schema: ElevationWitnessConfigSchema
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
const elevations = await elevationWitness.observe();
|
|
67
|
-
const heuristics = _LocationCertaintyDiviner.locationsToHeuristics(elevations, locations);
|
|
68
|
-
const result = await new PayloadBuilder({ schema: LocationCertaintySchema }).fields({
|
|
69
|
-
altitude: _LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),
|
|
70
|
-
elevation: _LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),
|
|
71
|
-
variance: _LocationCertaintyDiviner.calcHeuristic(heuristics.variance)
|
|
72
|
-
}).build();
|
|
73
|
-
(_a = this.logger) == null ? void 0 : _a.log("LocationCertaintyDiviner.Divine: Processed query");
|
|
74
|
-
return [result];
|
|
75
|
-
}
|
|
76
|
-
return [];
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
// src/Plugin.ts
|
|
81
|
-
import { LocationCertaintySchema as LocationCertaintySchema2 } from "@xyo-network/location-certainty-payload-plugin";
|
|
82
|
-
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
83
|
-
import { createPayloadSetDivinerPlugin } from "@xyo-network/payloadset-plugin";
|
|
84
|
-
var LocationCertaintyPlugin = () => createPayloadSetDivinerPlugin(
|
|
85
|
-
{ required: { [LocationCertaintySchema2]: 1 }, schema: PayloadSetSchema },
|
|
86
|
-
{
|
|
87
|
-
diviner: async (params) => {
|
|
88
|
-
return await LocationCertaintyDiviner.create(params);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
);
|
|
92
|
-
export {
|
|
93
|
-
LocationCertaintyDiviner,
|
|
94
|
-
LocationCertaintyDivinerConfigSchema,
|
|
95
|
-
LocationCertaintyPlugin,
|
|
96
|
-
LocationCertaintyPlugin as default
|
|
97
|
-
};
|
|
1
|
+
var s="network.xyo.location.elevation.diviner.config";import{AbstractDiviner as f}from"@xyo-network/diviner-abstract";import{ElevationWitness as y,ElevationWitnessConfigSchema as v}from"@xyo-network/elevation-plugin";import{LocationCertaintySchema as u}from"@xyo-network/location-certainty-payload-plugin";import{LocationSchema as C}from"@xyo-network/location-payload-plugin";import{PayloadBuilder as h}from"@xyo-network/payload-builder";var m=class o extends f{static configSchemas=[...super.configSchemas,s];static defaultConfigSchema=s;static targetSchema=u;static calcHeuristic(n){return{max:n.reduce((i,t)=>t===null?i:t>i?t:i,Number.NEGATIVE_INFINITY),mean:(()=>{let i=n.reduce((t,e)=>e===null?t:[e+t[0],t[1]+1],[0,0]);return i[0]/i[1]})(),min:n.reduce((i,t)=>t===null?i:t<i?t:i,Number.POSITIVE_INFINITY)}}static locationsToHeuristics(n,i){return n.reduce((e,l,r)=>{let a=l.elevation;if(a==null)throw new Error("Invalid Elevation");let c=i[r].altitude;return e.altitude.push(c??null),e.elevation.push(a),e.variance.push(c!=null?c-a:null),e},{altitude:[],elevation:[],variance:[]})}async divineHandler(n){var t;let i=n==null?void 0:n.filter(e=>(e==null?void 0:e.schema)===C);if(i&&(i==null?void 0:i.length)>0){let l=await(await y.create({account:this.account,config:{locations:i,schema:v}})).observe(),r=o.locationsToHeuristics(l,i),a=await new h({schema:u}).fields({altitude:o.calcHeuristic(r.altitude),elevation:o.calcHeuristic(r.elevation),variance:o.calcHeuristic(r.variance)}).build();return(t=this.logger)==null||t.log("LocationCertaintyDiviner.Divine: Processed query"),[a]}return[]}};import{LocationCertaintySchema as P}from"@xyo-network/location-certainty-payload-plugin";import{PayloadSetSchema as g}from"@xyo-network/payload-model";import{createPayloadSetDivinerPlugin as L}from"@xyo-network/payloadset-plugin";var d=()=>L({required:{[P]:1},schema:g},{diviner:async o=>await m.create(o)});export{m as LocationCertaintyDiviner,s as LocationCertaintyDivinerConfigSchema,d as LocationCertaintyPlugin,d as default};
|
|
98
2
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Diviner/Config.ts","../../src/Diviner/Diviner.ts","../../src/Plugin.ts"],"sourcesContent":["import { DivinerConfig } from '@xyo-network/diviner-model'\nimport { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport type LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'\nexport const LocationCertaintyDivinerConfigSchema: LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'\n\nexport type LocationCertaintyDivinerConfig<TConfig extends Payload = Payload> = DivinerConfig<\n TConfig & {\n schema: LocationCertaintyDivinerConfigSchema\n targetSchema?: LocationCertaintySchema\n }\n>\n","import { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerModule, DivinerParams } from '@xyo-network/diviner-model'\nimport { ElevationPayload } from '@xyo-network/elevation-payload-plugin'\nimport { ElevationWitness, ElevationWitnessConfigSchema } from '@xyo-network/elevation-plugin'\nimport { LocationCertaintyHeuristic, LocationCertaintyPayload, LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { LocationPayload, LocationSchema } from '@xyo-network/location-payload-plugin'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\nimport { LocationCertaintyDivinerConfig, LocationCertaintyDivinerConfigSchema } from './Config'\n\nexport type LocationCertaintyDivinerParams = DivinerParams<AnyConfigSchema<LocationCertaintyDivinerConfig>>\n\nexport class LocationCertaintyDiviner<TParam extends LocationCertaintyDivinerParams = LocationCertaintyDivinerParams>\n extends AbstractDiviner<TParam>\n implements DivinerModule\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, LocationCertaintyDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = LocationCertaintyDivinerConfigSchema\n static override targetSchema = LocationCertaintySchema\n\n /* Given an array of numbers, find the min/max/mean */\n private static calcHeuristic(heuristic: (number | null)[]): LocationCertaintyHeuristic {\n return {\n // eslint-disable-next-line unicorn/no-array-reduce\n max: heuristic.reduce<number>((prev, value) => {\n return (\n value === null ? prev\n : value > prev ? value\n : prev\n )\n }, Number.NEGATIVE_INFINITY),\n mean: (() => {\n // eslint-disable-next-line unicorn/no-array-reduce\n const values = heuristic.reduce<number[]>(\n (prev, value) => {\n return value === null ? prev : [value + prev[0], prev[1] + 1]\n },\n [0, 0],\n )\n return values[0] / values[1]\n })(),\n // eslint-disable-next-line unicorn/no-array-reduce\n min: heuristic.reduce<number>((prev, value) => {\n return (\n value === null ? prev\n : value < prev ? value\n : prev\n )\n }, Number.POSITIVE_INFINITY),\n }\n }\n\n /* Given elevation and location payloads, generate heuristic arrays */\n private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {\n // eslint-disable-next-line unicorn/no-array-reduce\n const heuristics = elevations.reduce<{ altitude: (number | null)[]; elevation: number[]; variance: (number | null)[] }>(\n (prev, elev, index) => {\n const elevation = elev.elevation\n if (elevation === undefined || elevation === null) {\n throw new Error('Invalid Elevation')\n }\n const altitude = locations[index].altitude\n prev.altitude.push(altitude ?? null)\n prev.elevation.push(elevation)\n prev.variance.push(altitude !== undefined && altitude !== null ? altitude - elevation : null)\n return prev\n },\n { altitude: [], elevation: [], variance: [] },\n )\n return heuristics\n }\n\n /** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const locations = payloads?.filter<LocationPayload>((payload): payload is LocationPayload => payload?.schema === LocationSchema)\n // If this is a query we support\n if (locations && locations?.length > 0) {\n const elevationWitness = await ElevationWitness.create({\n account: this.account,\n config: {\n locations,\n schema: ElevationWitnessConfigSchema,\n },\n })\n const elevations = (await elevationWitness.observe()) as ElevationPayload[]\n\n const heuristics = LocationCertaintyDiviner.locationsToHeuristics(elevations, locations)\n\n const result = await new PayloadBuilder<LocationCertaintyPayload>({ schema: LocationCertaintySchema })\n .fields({\n altitude: LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),\n elevation: LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),\n variance: LocationCertaintyDiviner.calcHeuristic(heuristics.variance),\n })\n .build()\n\n this.logger?.log('LocationCertaintyDiviner.Divine: Processed query')\n return [result]\n }\n return []\n }\n}\n","import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { LocationCertaintyDiviner } from './Diviner'\n\nexport const LocationCertaintyPlugin = () =>\n createPayloadSetDivinerPlugin<LocationCertaintyDiviner>(\n { required: { [LocationCertaintySchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n return (await LocationCertaintyDiviner.create(params)) as LocationCertaintyDiviner\n },\n },\n )\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner/Config.ts","../../src/Diviner/Diviner.ts","../../src/Plugin.ts"],"sourcesContent":["import { DivinerConfig } from '@xyo-network/diviner-model'\nimport { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { Payload } from '@xyo-network/payload-model'\n\nexport type LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'\nexport const LocationCertaintyDivinerConfigSchema: LocationCertaintyDivinerConfigSchema = 'network.xyo.location.elevation.diviner.config'\n\nexport type LocationCertaintyDivinerConfig<TConfig extends Payload = Payload> = DivinerConfig<\n TConfig & {\n schema: LocationCertaintyDivinerConfigSchema\n targetSchema?: LocationCertaintySchema\n }\n>\n","import { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerModule, DivinerParams } from '@xyo-network/diviner-model'\nimport { ElevationPayload } from '@xyo-network/elevation-payload-plugin'\nimport { ElevationWitness, ElevationWitnessConfigSchema } from '@xyo-network/elevation-plugin'\nimport { LocationCertaintyHeuristic, LocationCertaintyPayload, LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { LocationPayload, LocationSchema } from '@xyo-network/location-payload-plugin'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, Schema } from '@xyo-network/payload-model'\n\nimport { LocationCertaintyDivinerConfig, LocationCertaintyDivinerConfigSchema } from './Config'\n\nexport type LocationCertaintyDivinerParams = DivinerParams<AnyConfigSchema<LocationCertaintyDivinerConfig>>\n\nexport class LocationCertaintyDiviner<TParam extends LocationCertaintyDivinerParams = LocationCertaintyDivinerParams>\n extends AbstractDiviner<TParam>\n implements DivinerModule\n{\n static override readonly configSchemas: Schema[] = [...super.configSchemas, LocationCertaintyDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = LocationCertaintyDivinerConfigSchema\n static override targetSchema = LocationCertaintySchema\n\n /* Given an array of numbers, find the min/max/mean */\n private static calcHeuristic(heuristic: (number | null)[]): LocationCertaintyHeuristic {\n return {\n // eslint-disable-next-line unicorn/no-array-reduce\n max: heuristic.reduce<number>((prev, value) => {\n return (\n value === null ? prev\n : value > prev ? value\n : prev\n )\n }, Number.NEGATIVE_INFINITY),\n mean: (() => {\n // eslint-disable-next-line unicorn/no-array-reduce\n const values = heuristic.reduce<number[]>(\n (prev, value) => {\n return value === null ? prev : [value + prev[0], prev[1] + 1]\n },\n [0, 0],\n )\n return values[0] / values[1]\n })(),\n // eslint-disable-next-line unicorn/no-array-reduce\n min: heuristic.reduce<number>((prev, value) => {\n return (\n value === null ? prev\n : value < prev ? value\n : prev\n )\n }, Number.POSITIVE_INFINITY),\n }\n }\n\n /* Given elevation and location payloads, generate heuristic arrays */\n private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {\n // eslint-disable-next-line unicorn/no-array-reduce\n const heuristics = elevations.reduce<{ altitude: (number | null)[]; elevation: number[]; variance: (number | null)[] }>(\n (prev, elev, index) => {\n const elevation = elev.elevation\n if (elevation === undefined || elevation === null) {\n throw new Error('Invalid Elevation')\n }\n const altitude = locations[index].altitude\n prev.altitude.push(altitude ?? null)\n prev.elevation.push(elevation)\n prev.variance.push(altitude !== undefined && altitude !== null ? altitude - elevation : null)\n return prev\n },\n { altitude: [], elevation: [], variance: [] },\n )\n return heuristics\n }\n\n /** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */\n protected override async divineHandler(payloads?: Payload[]): Promise<Payload[]> {\n const locations = payloads?.filter<LocationPayload>((payload): payload is LocationPayload => payload?.schema === LocationSchema)\n // If this is a query we support\n if (locations && locations?.length > 0) {\n const elevationWitness = await ElevationWitness.create({\n account: this.account,\n config: {\n locations,\n schema: ElevationWitnessConfigSchema,\n },\n })\n const elevations = (await elevationWitness.observe()) as ElevationPayload[]\n\n const heuristics = LocationCertaintyDiviner.locationsToHeuristics(elevations, locations)\n\n const result = await new PayloadBuilder<LocationCertaintyPayload>({ schema: LocationCertaintySchema })\n .fields({\n altitude: LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),\n elevation: LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),\n variance: LocationCertaintyDiviner.calcHeuristic(heuristics.variance),\n })\n .build()\n\n this.logger?.log('LocationCertaintyDiviner.Divine: Processed query')\n return [result]\n }\n return []\n }\n}\n","import { LocationCertaintySchema } from '@xyo-network/location-certainty-payload-plugin'\nimport { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { LocationCertaintyDiviner } from './Diviner'\n\nexport const LocationCertaintyPlugin = () =>\n createPayloadSetDivinerPlugin<LocationCertaintyDiviner>(\n { required: { [LocationCertaintySchema]: 1 }, schema: PayloadSetSchema },\n {\n diviner: async (params) => {\n return (await LocationCertaintyDiviner.create(params)) as LocationCertaintyDiviner\n },\n },\n )\n"],"mappings":"AAKO,IAAMA,EAA6E,gDCL1F,OAAS,mBAAAC,MAAuB,gCAGhC,OAAS,oBAAAC,EAAkB,gCAAAC,MAAoC,gCAC/D,OAA+D,2BAAAC,MAA+B,iDAC9F,OAA0B,kBAAAC,MAAsB,uCAEhD,OAAS,kBAAAC,MAAsB,+BAOxB,IAAMC,EAAN,MAAMC,UACHC,CAEV,CACE,OAAyB,cAA0B,CAAC,GAAG,MAAM,cAAeC,CAAoC,EAChH,OAAyB,oBAA8BA,EACvD,OAAgB,aAAeC,EAG/B,OAAe,cAAcC,EAA0D,CACrF,MAAO,CAEL,IAAKA,EAAU,OAAe,CAACC,EAAMC,IAEjCA,IAAU,KAAOD,EACfC,EAAQD,EAAOC,EACfD,EAEH,OAAO,iBAAiB,EAC3B,MAAO,IAAM,CAEX,IAAME,EAASH,EAAU,OACvB,CAACC,EAAMC,IACEA,IAAU,KAAOD,EAAO,CAACC,EAAQD,EAAK,CAAC,EAAGA,EAAK,CAAC,EAAI,CAAC,EAE9D,CAAC,EAAG,CAAC,CACP,EACA,OAAOE,EAAO,CAAC,EAAIA,EAAO,CAAC,CAC7B,GAAG,EAEH,IAAKH,EAAU,OAAe,CAACC,EAAMC,IAEjCA,IAAU,KAAOD,EACfC,EAAQD,EAAOC,EACfD,EAEH,OAAO,iBAAiB,CAC7B,CACF,CAGA,OAAe,sBAAsBG,EAAgCC,EAA8B,CAgBjG,OAdmBD,EAAW,OAC5B,CAACH,EAAMK,EAAMC,IAAU,CACrB,IAAMC,EAAYF,EAAK,UACvB,GAA+BE,GAAc,KAC3C,MAAM,IAAI,MAAM,mBAAmB,EAErC,IAAMC,EAAWJ,EAAUE,CAAK,EAAE,SAClC,OAAAN,EAAK,SAAS,KAAKQ,GAAY,IAAI,EACnCR,EAAK,UAAU,KAAKO,CAAS,EAC7BP,EAAK,SAAS,KAA+BQ,GAAa,KAAOA,EAAWD,EAAY,IAAI,EACrFP,CACT,EACA,CAAE,SAAU,CAAC,EAAG,UAAW,CAAC,EAAG,SAAU,CAAC,CAAE,CAC9C,CAEF,CAGA,MAAyB,cAAcS,EAA0C,CA3EnF,IAAAC,EA4EI,IAAMN,EAAYK,GAAA,YAAAA,EAAU,OAAyBE,IAAwCA,GAAA,YAAAA,EAAS,UAAWC,GAEjH,GAAIR,IAAaA,GAAA,YAAAA,EAAW,QAAS,EAAG,CAQtC,IAAMD,EAAc,MAPK,MAAMU,EAAiB,OAAO,CACrD,QAAS,KAAK,QACd,OAAQ,CACN,UAAAT,EACA,OAAQU,CACV,CACF,CAAC,GAC0C,QAAQ,EAE7CC,EAAapB,EAAyB,sBAAsBQ,EAAYC,CAAS,EAEjFY,EAAS,MAAM,IAAIC,EAAyC,CAAE,OAAQnB,CAAwB,CAAC,EAClG,OAAO,CACN,SAAUH,EAAyB,cAAcoB,EAAW,QAAQ,EACpE,UAAWpB,EAAyB,cAAcoB,EAAW,SAAS,EACtE,SAAUpB,EAAyB,cAAcoB,EAAW,QAAQ,CACtE,CAAC,EACA,MAAM,EAET,OAAAL,EAAA,KAAK,SAAL,MAAAA,EAAa,IAAI,oDACV,CAACM,CAAM,CAChB,CACA,MAAO,CAAC,CACV,CACF,ECvGA,OAAS,2BAAAE,MAA+B,iDACxC,OAAS,oBAAAC,MAAwB,6BACjC,OAAS,iCAAAC,MAAqC,iCAIvC,IAAMC,EAA0B,IACrCC,EACE,CAAE,SAAU,CAAE,CAACC,CAAuB,EAAG,CAAE,EAAG,OAAQC,CAAiB,EACvE,CACE,QAAS,MAAOC,GACN,MAAMC,EAAyB,OAAOD,CAAM,CAExD,CACF","names":["LocationCertaintyDivinerConfigSchema","AbstractDiviner","ElevationWitness","ElevationWitnessConfigSchema","LocationCertaintySchema","LocationSchema","PayloadBuilder","LocationCertaintyDiviner","_LocationCertaintyDiviner","AbstractDiviner","LocationCertaintyDivinerConfigSchema","LocationCertaintySchema","heuristic","prev","value","values","elevations","locations","elev","index","elevation","altitude","payloads","_a","payload","LocationSchema","ElevationWitness","ElevationWitnessConfigSchema","heuristics","result","PayloadBuilder","LocationCertaintySchema","PayloadSetSchema","createPayloadSetDivinerPlugin","LocationCertaintyPlugin","createPayloadSetDivinerPlugin","LocationCertaintySchema","PayloadSetSchema","params","LocationCertaintyDiviner"]}
|
package/package.json
CHANGED
|
@@ -10,25 +10,25 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/plugins/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xyo-network/diviner-abstract": "^2.
|
|
14
|
-
"@xyo-network/diviner-model": "^2.
|
|
15
|
-
"@xyo-network/elevation-payload-plugin": "~2.96.
|
|
16
|
-
"@xyo-network/elevation-plugin": "~2.96.
|
|
17
|
-
"@xyo-network/location-certainty-payload-plugin": "~2.96.
|
|
18
|
-
"@xyo-network/location-payload-plugin": "~2.96.
|
|
19
|
-
"@xyo-network/module-model": "^2.
|
|
20
|
-
"@xyo-network/payload-builder": "^2.
|
|
21
|
-
"@xyo-network/payload-model": "^2.
|
|
22
|
-
"@xyo-network/payloadset-plugin": "^2.
|
|
13
|
+
"@xyo-network/diviner-abstract": "^2.106.0",
|
|
14
|
+
"@xyo-network/diviner-model": "^2.106.0",
|
|
15
|
+
"@xyo-network/elevation-payload-plugin": "~2.96.2",
|
|
16
|
+
"@xyo-network/elevation-plugin": "~2.96.2",
|
|
17
|
+
"@xyo-network/location-certainty-payload-plugin": "~2.96.2",
|
|
18
|
+
"@xyo-network/location-payload-plugin": "~2.96.2",
|
|
19
|
+
"@xyo-network/module-model": "^2.106.0",
|
|
20
|
+
"@xyo-network/payload-builder": "^2.106.0",
|
|
21
|
+
"@xyo-network/payload-model": "^2.106.0",
|
|
22
|
+
"@xyo-network/payloadset-plugin": "^2.106.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@xylabs/ts-scripts-yarn3": "^3.
|
|
26
|
-
"@xylabs/tsconfig": "^3.
|
|
27
|
-
"@xylabs/tsconfig-jest": "^3.
|
|
28
|
-
"@xyo-network/archivist-abstract": "^2.
|
|
29
|
-
"@xyo-network/archivist-memory": "^2.
|
|
30
|
-
"@xyo-network/module-resolver": "^2.
|
|
31
|
-
"typescript": "^5.
|
|
25
|
+
"@xylabs/ts-scripts-yarn3": "^3.11.7",
|
|
26
|
+
"@xylabs/tsconfig": "^3.11.7",
|
|
27
|
+
"@xylabs/tsconfig-jest": "^3.11.7",
|
|
28
|
+
"@xyo-network/archivist-abstract": "^2.106.0",
|
|
29
|
+
"@xyo-network/archivist-memory": "^2.106.0",
|
|
30
|
+
"@xyo-network/module-resolver": "^2.106.0",
|
|
31
|
+
"typescript": "^5.5.2"
|
|
32
32
|
},
|
|
33
33
|
"description": "Typescript/Javascript Plugins for XYO Platform",
|
|
34
34
|
"exports": {
|
|
@@ -69,6 +69,6 @@
|
|
|
69
69
|
"url": "https://github.com/XYOracleNetwork/plugins.git"
|
|
70
70
|
},
|
|
71
71
|
"sideEffects": false,
|
|
72
|
-
"version": "2.96.
|
|
72
|
+
"version": "2.96.2",
|
|
73
73
|
"type": "module"
|
|
74
74
|
}
|