@xyo-network/location-certainty-plugin 2.75.15 → 2.75.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docs.json +34 -34
- package/package.json +15 -15
- package/dist/browser/Diviner/Config.cjs +0 -27
- package/dist/browser/Diviner/Config.cjs.map +0 -1
- package/dist/browser/Diviner/Config.js +0 -6
- package/dist/browser/Diviner/Config.js.map +0 -1
- package/dist/browser/Diviner/Diviner.cjs +0 -101
- package/dist/browser/Diviner/Diviner.cjs.map +0 -1
- package/dist/browser/Diviner/Diviner.js +0 -80
- package/dist/browser/Diviner/Diviner.js.map +0 -1
- package/dist/browser/Diviner/index.cjs +0 -102
- package/dist/browser/Diviner/index.cjs.map +0 -1
- package/dist/browser/Diviner/index.js +0 -79
- package/dist/browser/Diviner/index.js.map +0 -1
- package/dist/browser/Plugin.cjs +0 -114
- package/dist/browser/Plugin.cjs.map +0 -1
- package/dist/browser/Plugin.js +0 -93
- package/dist/browser/Plugin.js.map +0 -1
- package/dist/node/Diviner/Config.js +0 -31
- package/dist/node/Diviner/Config.js.map +0 -1
- package/dist/node/Diviner/Config.mjs +0 -6
- package/dist/node/Diviner/Config.mjs.map +0 -1
- package/dist/node/Diviner/Diviner.js +0 -106
- package/dist/node/Diviner/Diviner.js.map +0 -1
- package/dist/node/Diviner/Diviner.mjs +0 -81
- package/dist/node/Diviner/Diviner.mjs.map +0 -1
- package/dist/node/Diviner/index.js +0 -108
- package/dist/node/Diviner/index.js.map +0 -1
- package/dist/node/Diviner/index.mjs +0 -80
- package/dist/node/Diviner/index.mjs.map +0 -1
- package/dist/node/Plugin.js +0 -119
- package/dist/node/Plugin.js.map +0 -1
- package/dist/node/Plugin.mjs +0 -94
- package/dist/node/Plugin.mjs.map +0 -1
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// src/Diviner/Diviner.ts
|
|
2
|
-
import { AbstractDiviner } from "@xyo-network/abstract-diviner";
|
|
3
|
-
import { ElevationWitness, ElevationWitnessConfigSchema } from "@xyo-network/elevation-plugin";
|
|
4
|
-
import { LocationCertaintySchema } from "@xyo-network/location-certainty-payload-plugin";
|
|
5
|
-
import { LocationSchema } from "@xyo-network/location-payload-plugin";
|
|
6
|
-
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
7
|
-
|
|
8
|
-
// src/Diviner/Config.ts
|
|
9
|
-
var LocationCertaintyDivinerConfigSchema = "network.xyo.location.elevation.diviner.config";
|
|
10
|
-
|
|
11
|
-
// src/Diviner/Diviner.ts
|
|
12
|
-
var LocationCertaintyDiviner = class _LocationCertaintyDiviner extends AbstractDiviner {
|
|
13
|
-
static configSchemas = [LocationCertaintyDivinerConfigSchema];
|
|
14
|
-
static targetSchema = LocationCertaintySchema;
|
|
15
|
-
/* Given an array of numbers, find the min/max/mean */
|
|
16
|
-
static calcHeuristic(heuristic) {
|
|
17
|
-
return {
|
|
18
|
-
max: heuristic.reduce((prev, value) => {
|
|
19
|
-
return value !== null ? value > prev ? value : prev : prev;
|
|
20
|
-
}, -Infinity),
|
|
21
|
-
mean: (() => {
|
|
22
|
-
const values = heuristic.reduce(
|
|
23
|
-
(prev, value) => {
|
|
24
|
-
return value !== null ? [value + prev[0], prev[1] + 1] : prev;
|
|
25
|
-
},
|
|
26
|
-
[0, 0]
|
|
27
|
-
);
|
|
28
|
-
return values[0] / values[1];
|
|
29
|
-
})(),
|
|
30
|
-
min: heuristic.reduce((prev, value) => {
|
|
31
|
-
return value !== null ? value < prev ? value : prev : prev;
|
|
32
|
-
}, Infinity)
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
/* Given elevation and location payloads, generate heuristic arrays */
|
|
36
|
-
static locationsToHeuristics(elevations, locations) {
|
|
37
|
-
const heuristics = elevations.reduce(
|
|
38
|
-
(prev, elev, index) => {
|
|
39
|
-
const elevation = elev.elevation;
|
|
40
|
-
if (elevation === void 0 || elevation === null) {
|
|
41
|
-
throw Error("Invalid Elevation");
|
|
42
|
-
}
|
|
43
|
-
const altitude = locations[index].altitude;
|
|
44
|
-
prev.altitude.push(altitude ?? null);
|
|
45
|
-
prev.elevation.push(elevation);
|
|
46
|
-
prev.variance.push(altitude !== void 0 && altitude !== null ? altitude - elevation : null);
|
|
47
|
-
return prev;
|
|
48
|
-
},
|
|
49
|
-
{ altitude: [], elevation: [], variance: [] }
|
|
50
|
-
);
|
|
51
|
-
return heuristics;
|
|
52
|
-
}
|
|
53
|
-
/** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
|
|
54
|
-
async divineHandler(payloads) {
|
|
55
|
-
var _a;
|
|
56
|
-
const locations = payloads == null ? void 0 : payloads.filter((payload) => (payload == null ? void 0 : payload.schema) === LocationSchema);
|
|
57
|
-
if (locations && (locations == null ? void 0 : locations.length) > 0) {
|
|
58
|
-
const elevationWitness = await ElevationWitness.create({
|
|
59
|
-
account: this.account,
|
|
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 PayloadBuilder({ schema: LocationCertaintySchema }).fields({
|
|
68
|
-
altitude: _LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),
|
|
69
|
-
elevation: _LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),
|
|
70
|
-
variance: _LocationCertaintyDiviner.calcHeuristic(heuristics.variance)
|
|
71
|
-
}).build();
|
|
72
|
-
(_a = this.logger) == null ? void 0 : _a.log("LocationCertaintyDiviner.Divine: Processed query");
|
|
73
|
-
return [result];
|
|
74
|
-
}
|
|
75
|
-
return [];
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
export {
|
|
79
|
-
LocationCertaintyDiviner
|
|
80
|
-
};
|
|
81
|
-
//# sourceMappingURL=Diviner.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Diviner/Diviner.ts","../../../src/Diviner/Config.ts"],"sourcesContent":["import { AbstractDiviner } from '@xyo-network/abstract-diviner'\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 } 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 configSchemas = [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 max: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value > prev ? value : prev) : prev\n }, -Infinity),\n mean: (() => {\n const values = heuristic.reduce<number[]>(\n (prev, value) => {\n return value !== null ? [value + prev[0], prev[1] + 1] : prev\n },\n [0, 0],\n )\n return values[0] / values[1]\n })(),\n min: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value < prev ? value : prev) : prev\n }, Infinity),\n }\n }\n\n /* Given elevation and location payloads, generate heuristic arrays */\n private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {\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 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 = 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 { 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"],"mappings":";AAAA,SAAS,uBAAuB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;AAAA,MACA,EAAE,UAAU,CAAC,GAAG,WAAW,CAAC,GAAG,UAAU,CAAC,EAAE;AAAA,IAC9C;AACA,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,MAAyB,cAAc,UAA0C;AA9DnF;AA+DI,UAAM,YAAY,qCAAU,OAAwB,CAAC,aAAwC,mCAAS,YAAW;AAEjH,QAAI,cAAa,uCAAW,UAAS,GAAG;AACtC,YAAM,mBAAmB,MAAM,iBAAiB,OAAO;AAAA,QACrD,SAAS,KAAK;AAAA,QACd,QAAQ;AAAA,UACN;AAAA,UACA,QAAQ;AAAA,QACV;AAAA,MACF,CAAC;AACD,YAAM,aAAc,MAAM,iBAAiB,QAAQ;AAEnD,YAAM,aAAa,0BAAyB,sBAAsB,YAAY,SAAS;AAEvF,YAAM,SAAS,IAAI,eAAyC,EAAE,QAAQ,wBAAwB,CAAC,EAC5F,OAAO;AAAA,QACN,UAAU,0BAAyB,cAAc,WAAW,QAAQ;AAAA,QACpE,WAAW,0BAAyB,cAAc,WAAW,SAAS;AAAA,QACtE,UAAU,0BAAyB,cAAc,WAAW,QAAQ;AAAA,MACtE,CAAC,EACA,MAAM;AAET,iBAAK,WAAL,mBAAa,IAAI;AACjB,aAAO,CAAC,MAAM;AAAA,IAChB;AACA,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
|
@@ -1,108 +0,0 @@
|
|
|
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/Diviner/index.ts
|
|
21
|
-
var Diviner_exports = {};
|
|
22
|
-
__export(Diviner_exports, {
|
|
23
|
-
LocationCertaintyDiviner: () => LocationCertaintyDiviner,
|
|
24
|
-
LocationCertaintyDivinerConfigSchema: () => LocationCertaintyDivinerConfigSchema
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(Diviner_exports);
|
|
27
|
-
|
|
28
|
-
// src/Diviner/Config.ts
|
|
29
|
-
var LocationCertaintyDivinerConfigSchema = "network.xyo.location.elevation.diviner.config";
|
|
30
|
-
|
|
31
|
-
// src/Diviner/Diviner.ts
|
|
32
|
-
var import_abstract_diviner = require("@xyo-network/abstract-diviner");
|
|
33
|
-
var import_elevation_plugin = require("@xyo-network/elevation-plugin");
|
|
34
|
-
var import_location_certainty_payload_plugin = require("@xyo-network/location-certainty-payload-plugin");
|
|
35
|
-
var import_location_payload_plugin = require("@xyo-network/location-payload-plugin");
|
|
36
|
-
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
37
|
-
var LocationCertaintyDiviner = class _LocationCertaintyDiviner extends import_abstract_diviner.AbstractDiviner {
|
|
38
|
-
static configSchemas = [LocationCertaintyDivinerConfigSchema];
|
|
39
|
-
static targetSchema = import_location_certainty_payload_plugin.LocationCertaintySchema;
|
|
40
|
-
/* Given an array of numbers, find the min/max/mean */
|
|
41
|
-
static calcHeuristic(heuristic) {
|
|
42
|
-
return {
|
|
43
|
-
max: heuristic.reduce((prev, value) => {
|
|
44
|
-
return value !== null ? value > prev ? value : prev : prev;
|
|
45
|
-
}, -Infinity),
|
|
46
|
-
mean: (() => {
|
|
47
|
-
const values = heuristic.reduce(
|
|
48
|
-
(prev, value) => {
|
|
49
|
-
return value !== null ? [value + prev[0], prev[1] + 1] : prev;
|
|
50
|
-
},
|
|
51
|
-
[0, 0]
|
|
52
|
-
);
|
|
53
|
-
return values[0] / values[1];
|
|
54
|
-
})(),
|
|
55
|
-
min: heuristic.reduce((prev, value) => {
|
|
56
|
-
return value !== null ? value < prev ? value : prev : prev;
|
|
57
|
-
}, Infinity)
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/* Given elevation and location payloads, generate heuristic arrays */
|
|
61
|
-
static locationsToHeuristics(elevations, locations) {
|
|
62
|
-
const heuristics = elevations.reduce(
|
|
63
|
-
(prev, elev, index) => {
|
|
64
|
-
const elevation = elev.elevation;
|
|
65
|
-
if (elevation === void 0 || elevation === null) {
|
|
66
|
-
throw Error("Invalid Elevation");
|
|
67
|
-
}
|
|
68
|
-
const altitude = locations[index].altitude;
|
|
69
|
-
prev.altitude.push(altitude ?? null);
|
|
70
|
-
prev.elevation.push(elevation);
|
|
71
|
-
prev.variance.push(altitude !== void 0 && altitude !== null ? altitude - elevation : null);
|
|
72
|
-
return prev;
|
|
73
|
-
},
|
|
74
|
-
{ altitude: [], elevation: [], variance: [] }
|
|
75
|
-
);
|
|
76
|
-
return heuristics;
|
|
77
|
-
}
|
|
78
|
-
/** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
|
|
79
|
-
async divineHandler(payloads) {
|
|
80
|
-
var _a;
|
|
81
|
-
const locations = payloads == null ? void 0 : payloads.filter((payload) => (payload == null ? void 0 : payload.schema) === import_location_payload_plugin.LocationSchema);
|
|
82
|
-
if (locations && (locations == null ? void 0 : locations.length) > 0) {
|
|
83
|
-
const elevationWitness = await import_elevation_plugin.ElevationWitness.create({
|
|
84
|
-
account: this.account,
|
|
85
|
-
config: {
|
|
86
|
-
locations,
|
|
87
|
-
schema: import_elevation_plugin.ElevationWitnessConfigSchema
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
const elevations = await elevationWitness.observe();
|
|
91
|
-
const heuristics = _LocationCertaintyDiviner.locationsToHeuristics(elevations, locations);
|
|
92
|
-
const result = new import_payload_builder.PayloadBuilder({ schema: import_location_certainty_payload_plugin.LocationCertaintySchema }).fields({
|
|
93
|
-
altitude: _LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),
|
|
94
|
-
elevation: _LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),
|
|
95
|
-
variance: _LocationCertaintyDiviner.calcHeuristic(heuristics.variance)
|
|
96
|
-
}).build();
|
|
97
|
-
(_a = this.logger) == null ? void 0 : _a.log("LocationCertaintyDiviner.Divine: Processed query");
|
|
98
|
-
return [result];
|
|
99
|
-
}
|
|
100
|
-
return [];
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
-
0 && (module.exports = {
|
|
105
|
-
LocationCertaintyDiviner,
|
|
106
|
-
LocationCertaintyDivinerConfigSchema
|
|
107
|
-
});
|
|
108
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Diviner/index.ts","../../../src/Diviner/Config.ts","../../../src/Diviner/Diviner.ts"],"sourcesContent":["export * from './Config'\nexport * from './Diviner'\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/abstract-diviner'\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 } 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 configSchemas = [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 max: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value > prev ? value : prev) : prev\n }, -Infinity),\n mean: (() => {\n const values = heuristic.reduce<number[]>(\n (prev, value) => {\n return value !== null ? [value + prev[0], prev[1] + 1] : prev\n },\n [0, 0],\n )\n return values[0] / values[1]\n })(),\n min: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value < prev ? value : prev) : prev\n }, Infinity),\n }\n }\n\n /* Given elevation and location payloads, generate heuristic arrays */\n private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {\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 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 = 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,IAAM,uCAA6E;;;ACL1F,8BAAgC;AAGhC,8BAA+D;AAC/D,+CAA8F;AAC9F,qCAAgD;AAEhD,6BAA+B;AAOxB,IAAM,2BAAN,MAAM,kCACH,wCAEV;AAAA,EACE,OAAgB,gBAAgB,CAAC,oCAAoC;AAAA,EACrE,OAAgB,eAAe;AAAA;AAAA,EAG/B,OAAe,cAAc,WAA0D;AACrF,WAAO;AAAA,MACL,KAAK,UAAU,OAAe,CAAC,MAAM,UAAU;AAC7C,eAAO,UAAU,OAAQ,QAAQ,OAAO,QAAQ,OAAQ;AAAA,MAC1D,GAAG,SAAS;AAAA,MACZ,OAAO,MAAM;AACX,cAAM,SAAS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a,0BAAyB,sBAAsB,YAAY,SAAS;AAEvF,YAAM,SAAS,IAAI,sCAAyC,EAAE,QAAQ,iEAAwB,CAAC,EAC5F,OAAO;AAAA,QACN,UAAU,0BAAyB,cAAc,WAAW,QAAQ;AAAA,QACpE,WAAW,0BAAyB,cAAc,WAAW,SAAS;AAAA,QACtE,UAAU,0BAAyB,cAAc,WAAW,QAAQ;AAAA,MACtE,CAAC,EACA,MAAM;AAET,iBAAK,WAAL,mBAAa,IAAI;AACjB,aAAO,CAAC,MAAM;AAAA,IAChB;AACA,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// src/Diviner/Config.ts
|
|
2
|
-
var LocationCertaintyDivinerConfigSchema = "network.xyo.location.elevation.diviner.config";
|
|
3
|
-
|
|
4
|
-
// src/Diviner/Diviner.ts
|
|
5
|
-
import { AbstractDiviner } from "@xyo-network/abstract-diviner";
|
|
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 = [LocationCertaintyDivinerConfigSchema];
|
|
12
|
-
static targetSchema = LocationCertaintySchema;
|
|
13
|
-
/* Given an array of numbers, find the min/max/mean */
|
|
14
|
-
static calcHeuristic(heuristic) {
|
|
15
|
-
return {
|
|
16
|
-
max: heuristic.reduce((prev, value) => {
|
|
17
|
-
return value !== null ? value > prev ? value : prev : prev;
|
|
18
|
-
}, -Infinity),
|
|
19
|
-
mean: (() => {
|
|
20
|
-
const values = heuristic.reduce(
|
|
21
|
-
(prev, value) => {
|
|
22
|
-
return value !== null ? [value + prev[0], prev[1] + 1] : prev;
|
|
23
|
-
},
|
|
24
|
-
[0, 0]
|
|
25
|
-
);
|
|
26
|
-
return values[0] / values[1];
|
|
27
|
-
})(),
|
|
28
|
-
min: heuristic.reduce((prev, value) => {
|
|
29
|
-
return value !== null ? value < prev ? value : prev : prev;
|
|
30
|
-
}, Infinity)
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/* Given elevation and location payloads, generate heuristic arrays */
|
|
34
|
-
static locationsToHeuristics(elevations, locations) {
|
|
35
|
-
const heuristics = elevations.reduce(
|
|
36
|
-
(prev, elev, index) => {
|
|
37
|
-
const elevation = elev.elevation;
|
|
38
|
-
if (elevation === void 0 || elevation === null) {
|
|
39
|
-
throw Error("Invalid Elevation");
|
|
40
|
-
}
|
|
41
|
-
const altitude = locations[index].altitude;
|
|
42
|
-
prev.altitude.push(altitude ?? null);
|
|
43
|
-
prev.elevation.push(elevation);
|
|
44
|
-
prev.variance.push(altitude !== void 0 && altitude !== null ? altitude - elevation : null);
|
|
45
|
-
return prev;
|
|
46
|
-
},
|
|
47
|
-
{ altitude: [], elevation: [], variance: [] }
|
|
48
|
-
);
|
|
49
|
-
return heuristics;
|
|
50
|
-
}
|
|
51
|
-
/** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
|
|
52
|
-
async divineHandler(payloads) {
|
|
53
|
-
var _a;
|
|
54
|
-
const locations = payloads == null ? void 0 : payloads.filter((payload) => (payload == null ? void 0 : payload.schema) === LocationSchema);
|
|
55
|
-
if (locations && (locations == null ? void 0 : locations.length) > 0) {
|
|
56
|
-
const elevationWitness = await ElevationWitness.create({
|
|
57
|
-
account: this.account,
|
|
58
|
-
config: {
|
|
59
|
-
locations,
|
|
60
|
-
schema: ElevationWitnessConfigSchema
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
const elevations = await elevationWitness.observe();
|
|
64
|
-
const heuristics = _LocationCertaintyDiviner.locationsToHeuristics(elevations, locations);
|
|
65
|
-
const result = new PayloadBuilder({ schema: LocationCertaintySchema }).fields({
|
|
66
|
-
altitude: _LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),
|
|
67
|
-
elevation: _LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),
|
|
68
|
-
variance: _LocationCertaintyDiviner.calcHeuristic(heuristics.variance)
|
|
69
|
-
}).build();
|
|
70
|
-
(_a = this.logger) == null ? void 0 : _a.log("LocationCertaintyDiviner.Divine: Processed query");
|
|
71
|
-
return [result];
|
|
72
|
-
}
|
|
73
|
-
return [];
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
export {
|
|
77
|
-
LocationCertaintyDiviner,
|
|
78
|
-
LocationCertaintyDivinerConfigSchema
|
|
79
|
-
};
|
|
80
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Diviner/Config.ts","../../../src/Diviner/Diviner.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/abstract-diviner'\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 } 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 configSchemas = [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 max: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value > prev ? value : prev) : prev\n }, -Infinity),\n mean: (() => {\n const values = heuristic.reduce<number[]>(\n (prev, value) => {\n return value !== null ? [value + prev[0], prev[1] + 1] : prev\n },\n [0, 0],\n )\n return values[0] / values[1]\n })(),\n min: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value < prev ? value : prev) : prev\n }, Infinity),\n }\n }\n\n /* Given elevation and location payloads, generate heuristic arrays */\n private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {\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 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 = 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"],"mappings":";AAKO,IAAM,uCAA6E;;;ACL1F,SAAS,uBAAuB;AAGhC,SAAS,kBAAkB,oCAAoC;AAC/D,SAA+D,+BAA+B;AAC9F,SAA0B,sBAAsB;AAEhD,SAAS,sBAAsB;AAOxB,IAAM,2BAAN,MAAM,kCACH,gBAEV;AAAA,EACE,OAAgB,gBAAgB,CAAC,oCAAoC;AAAA,EACrE,OAAgB,eAAe;AAAA;AAAA,EAG/B,OAAe,cAAc,WAA0D;AACrF,WAAO;AAAA,MACL,KAAK,UAAU,OAAe,CAAC,MAAM,UAAU;AAC7C,eAAO,UAAU,OAAQ,QAAQ,OAAO,QAAQ,OAAQ;AAAA,MAC1D,GAAG,SAAS;AAAA,MACZ,OAAO,MAAM;AACX,cAAM,SAAS,UAAU;AAAA,UACvB,CAAC,MAAM,UAAU;AACf,mBAAO,UAAU,OAAO,CAAC,QAAQ,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI;AAAA,UAC3D;AAAA,UACA,CAAC,GAAG,CAAC;AAAA,QACP;AACA,eAAO,OAAO,CAAC,IAAI,OAAO,CAAC;AAAA,MAC7B,GAAG;AAAA,MACH,KAAK,UAAU,OAAe,CAAC,MAAM,UAAU;AAC7C,eAAO,UAAU,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jB,aAAO,CAAC,MAAM;AAAA,IAChB;AACA,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
package/dist/node/Plugin.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
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/Plugin.ts
|
|
21
|
-
var Plugin_exports = {};
|
|
22
|
-
__export(Plugin_exports, {
|
|
23
|
-
LocationCertaintyPlugin: () => LocationCertaintyPlugin
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(Plugin_exports);
|
|
26
|
-
var import_location_certainty_payload_plugin2 = require("@xyo-network/location-certainty-payload-plugin");
|
|
27
|
-
var import_payload_model = require("@xyo-network/payload-model");
|
|
28
|
-
var import_payloadset_plugin = require("@xyo-network/payloadset-plugin");
|
|
29
|
-
|
|
30
|
-
// src/Diviner/Config.ts
|
|
31
|
-
var LocationCertaintyDivinerConfigSchema = "network.xyo.location.elevation.diviner.config";
|
|
32
|
-
|
|
33
|
-
// src/Diviner/Diviner.ts
|
|
34
|
-
var import_abstract_diviner = require("@xyo-network/abstract-diviner");
|
|
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_abstract_diviner.AbstractDiviner {
|
|
40
|
-
static configSchemas = [LocationCertaintyDivinerConfigSchema];
|
|
41
|
-
static targetSchema = import_location_certainty_payload_plugin.LocationCertaintySchema;
|
|
42
|
-
/* Given an array of numbers, find the min/max/mean */
|
|
43
|
-
static calcHeuristic(heuristic) {
|
|
44
|
-
return {
|
|
45
|
-
max: heuristic.reduce((prev, value) => {
|
|
46
|
-
return value !== null ? value > prev ? value : prev : prev;
|
|
47
|
-
}, -Infinity),
|
|
48
|
-
mean: (() => {
|
|
49
|
-
const values = heuristic.reduce(
|
|
50
|
-
(prev, value) => {
|
|
51
|
-
return value !== null ? [value + prev[0], prev[1] + 1] : prev;
|
|
52
|
-
},
|
|
53
|
-
[0, 0]
|
|
54
|
-
);
|
|
55
|
-
return values[0] / values[1];
|
|
56
|
-
})(),
|
|
57
|
-
min: heuristic.reduce((prev, value) => {
|
|
58
|
-
return value !== null ? value < prev ? value : prev : prev;
|
|
59
|
-
}, Infinity)
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
/* Given elevation and location payloads, generate heuristic arrays */
|
|
63
|
-
static locationsToHeuristics(elevations, locations) {
|
|
64
|
-
const heuristics = elevations.reduce(
|
|
65
|
-
(prev, elev, index) => {
|
|
66
|
-
const elevation = elev.elevation;
|
|
67
|
-
if (elevation === void 0 || elevation === null) {
|
|
68
|
-
throw Error("Invalid Elevation");
|
|
69
|
-
}
|
|
70
|
-
const altitude = locations[index].altitude;
|
|
71
|
-
prev.altitude.push(altitude ?? null);
|
|
72
|
-
prev.elevation.push(elevation);
|
|
73
|
-
prev.variance.push(altitude !== void 0 && altitude !== null ? altitude - elevation : null);
|
|
74
|
-
return prev;
|
|
75
|
-
},
|
|
76
|
-
{ altitude: [], elevation: [], variance: [] }
|
|
77
|
-
);
|
|
78
|
-
return heuristics;
|
|
79
|
-
}
|
|
80
|
-
/** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
|
|
81
|
-
async divineHandler(payloads) {
|
|
82
|
-
var _a;
|
|
83
|
-
const locations = payloads == null ? void 0 : payloads.filter((payload) => (payload == null ? void 0 : payload.schema) === import_location_payload_plugin.LocationSchema);
|
|
84
|
-
if (locations && (locations == null ? void 0 : locations.length) > 0) {
|
|
85
|
-
const elevationWitness = await import_elevation_plugin.ElevationWitness.create({
|
|
86
|
-
account: this.account,
|
|
87
|
-
config: {
|
|
88
|
-
locations,
|
|
89
|
-
schema: import_elevation_plugin.ElevationWitnessConfigSchema
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
const elevations = await elevationWitness.observe();
|
|
93
|
-
const heuristics = _LocationCertaintyDiviner.locationsToHeuristics(elevations, locations);
|
|
94
|
-
const result = new import_payload_builder.PayloadBuilder({ schema: import_location_certainty_payload_plugin.LocationCertaintySchema }).fields({
|
|
95
|
-
altitude: _LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),
|
|
96
|
-
elevation: _LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),
|
|
97
|
-
variance: _LocationCertaintyDiviner.calcHeuristic(heuristics.variance)
|
|
98
|
-
}).build();
|
|
99
|
-
(_a = this.logger) == null ? void 0 : _a.log("LocationCertaintyDiviner.Divine: Processed query");
|
|
100
|
-
return [result];
|
|
101
|
-
}
|
|
102
|
-
return [];
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
// src/Plugin.ts
|
|
107
|
-
var LocationCertaintyPlugin = () => (0, import_payloadset_plugin.createPayloadSetDivinerPlugin)(
|
|
108
|
-
{ required: { [import_location_certainty_payload_plugin2.LocationCertaintySchema]: 1 }, schema: import_payload_model.PayloadSetSchema },
|
|
109
|
-
{
|
|
110
|
-
diviner: async (params) => {
|
|
111
|
-
return await LocationCertaintyDiviner.create(params);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
-
0 && (module.exports = {
|
|
117
|
-
LocationCertaintyPlugin
|
|
118
|
-
});
|
|
119
|
-
//# sourceMappingURL=Plugin.js.map
|
package/dist/node/Plugin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Plugin.ts","../../src/Diviner/Config.ts","../../src/Diviner/Diviner.ts"],"sourcesContent":["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","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/abstract-diviner'\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 } 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 configSchemas = [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 max: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value > prev ? value : prev) : prev\n }, -Infinity),\n mean: (() => {\n const values = heuristic.reduce<number[]>(\n (prev, value) => {\n return value !== null ? [value + prev[0], prev[1] + 1] : prev\n },\n [0, 0],\n )\n return values[0] / values[1]\n })(),\n min: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value < prev ? value : prev) : prev\n }, Infinity),\n }\n }\n\n /* Given elevation and location payloads, generate heuristic arrays */\n private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {\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 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 = 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,4CAAwC;AACxC,2BAAiC;AACjC,+BAA8C;;;ACGvC,IAAM,uCAA6E;;;ACL1F,8BAAgC;AAGhC,8BAA+D;AAC/D,+CAA8F;AAC9F,qCAAgD;AAEhD,6BAA+B;AAOxB,IAAM,2BAAN,MAAM,kCACH,wCAEV;AAAA,EACE,OAAgB,gBAAgB,CAAC,oCAAoC;AAAA,EACrE,OAAgB,eAAe;AAAA;AAAA,EAG/B,OAAe,cAAc,WAA0D;AACrF,WAAO;AAAA,MACL,KAAK,UAAU,OAAe,CAAC,MAAM,UAAU;AAC7C,eAAO,UAAU,OAAQ,QAAQ,OAAO,QAAQ,OAAQ;AAAA,MAC1D,GAAG,SAAS;AAAA,MACZ,OAAO,MA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;AAEnD,YAAM,aAAa,0BAAyB,sBAAsB,YAAY,SAAS;AAEvF,YAAM,SAAS,IAAI,sCAAyC,EAAE,QAAQ,iEAAwB,CAAC,EAC5F,OAAO;AAAA,QACN,UAAU,0BAAyB,cAAc,WAAW,QAAQ;AAAA,QACpE,WAAW,0BAAyB,cAAc,WAAW,SAAS;AAAA,QACtE,UAAU,0BAAyB,cAAc,WAAW,QAAQ;AAAA,MACtE,CAAC,EACA,MAAM;AAET,iBAAK,WAAL,mBAAa,IAAI;AACjB,aAAO,CAAC,MAAM;AAAA,IAChB;AACA,WAAO,CAAC;AAAA,EACV;AACF;;;AFpFO,IAAM,0BAA0B,UACrC;AAAA,EACE,EAAE,UAAU,EAAE,CAAC,iEAAuB,GAAG,EAAE,GAAG,QAAQ,sCAAiB;AAAA,EACvE;AAAA,IACE,SAAS,OAAO,WAAW;AACzB,aAAQ,MAAM,yBAAyB,OAAO,MAAM;AAAA,IACtD;AAAA,EACF;AACF;","names":["import_location_certainty_payload_plugin"]}
|
package/dist/node/Plugin.mjs
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// src/Plugin.ts
|
|
2
|
-
import { LocationCertaintySchema as LocationCertaintySchema2 } from "@xyo-network/location-certainty-payload-plugin";
|
|
3
|
-
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
4
|
-
import { createPayloadSetDivinerPlugin } from "@xyo-network/payloadset-plugin";
|
|
5
|
-
|
|
6
|
-
// src/Diviner/Config.ts
|
|
7
|
-
var LocationCertaintyDivinerConfigSchema = "network.xyo.location.elevation.diviner.config";
|
|
8
|
-
|
|
9
|
-
// src/Diviner/Diviner.ts
|
|
10
|
-
import { AbstractDiviner } from "@xyo-network/abstract-diviner";
|
|
11
|
-
import { ElevationWitness, ElevationWitnessConfigSchema } from "@xyo-network/elevation-plugin";
|
|
12
|
-
import { LocationCertaintySchema } from "@xyo-network/location-certainty-payload-plugin";
|
|
13
|
-
import { LocationSchema } from "@xyo-network/location-payload-plugin";
|
|
14
|
-
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
15
|
-
var LocationCertaintyDiviner = class _LocationCertaintyDiviner extends AbstractDiviner {
|
|
16
|
-
static configSchemas = [LocationCertaintyDivinerConfigSchema];
|
|
17
|
-
static targetSchema = LocationCertaintySchema;
|
|
18
|
-
/* Given an array of numbers, find the min/max/mean */
|
|
19
|
-
static calcHeuristic(heuristic) {
|
|
20
|
-
return {
|
|
21
|
-
max: heuristic.reduce((prev, value) => {
|
|
22
|
-
return value !== null ? value > prev ? value : prev : prev;
|
|
23
|
-
}, -Infinity),
|
|
24
|
-
mean: (() => {
|
|
25
|
-
const values = heuristic.reduce(
|
|
26
|
-
(prev, value) => {
|
|
27
|
-
return value !== null ? [value + prev[0], prev[1] + 1] : prev;
|
|
28
|
-
},
|
|
29
|
-
[0, 0]
|
|
30
|
-
);
|
|
31
|
-
return values[0] / values[1];
|
|
32
|
-
})(),
|
|
33
|
-
min: heuristic.reduce((prev, value) => {
|
|
34
|
-
return value !== null ? value < prev ? value : prev : prev;
|
|
35
|
-
}, Infinity)
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/* Given elevation and location payloads, generate heuristic arrays */
|
|
39
|
-
static locationsToHeuristics(elevations, locations) {
|
|
40
|
-
const heuristics = elevations.reduce(
|
|
41
|
-
(prev, elev, index) => {
|
|
42
|
-
const elevation = elev.elevation;
|
|
43
|
-
if (elevation === void 0 || 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 !== void 0 && altitude !== null ? altitude - elevation : null);
|
|
50
|
-
return prev;
|
|
51
|
-
},
|
|
52
|
-
{ altitude: [], elevation: [], variance: [] }
|
|
53
|
-
);
|
|
54
|
-
return heuristics;
|
|
55
|
-
}
|
|
56
|
-
/** @description Given a set of locations, get the expected elevations (witness if needed), and return score/variance */
|
|
57
|
-
async divineHandler(payloads) {
|
|
58
|
-
var _a;
|
|
59
|
-
const locations = payloads == null ? void 0 : payloads.filter((payload) => (payload == null ? void 0 : payload.schema) === LocationSchema);
|
|
60
|
-
if (locations && (locations == null ? void 0 : locations.length) > 0) {
|
|
61
|
-
const elevationWitness = await ElevationWitness.create({
|
|
62
|
-
account: this.account,
|
|
63
|
-
config: {
|
|
64
|
-
locations,
|
|
65
|
-
schema: ElevationWitnessConfigSchema
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
const elevations = await elevationWitness.observe();
|
|
69
|
-
const heuristics = _LocationCertaintyDiviner.locationsToHeuristics(elevations, locations);
|
|
70
|
-
const result = new PayloadBuilder({ schema: LocationCertaintySchema }).fields({
|
|
71
|
-
altitude: _LocationCertaintyDiviner.calcHeuristic(heuristics.altitude),
|
|
72
|
-
elevation: _LocationCertaintyDiviner.calcHeuristic(heuristics.elevation),
|
|
73
|
-
variance: _LocationCertaintyDiviner.calcHeuristic(heuristics.variance)
|
|
74
|
-
}).build();
|
|
75
|
-
(_a = this.logger) == null ? void 0 : _a.log("LocationCertaintyDiviner.Divine: Processed query");
|
|
76
|
-
return [result];
|
|
77
|
-
}
|
|
78
|
-
return [];
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// src/Plugin.ts
|
|
83
|
-
var LocationCertaintyPlugin = () => createPayloadSetDivinerPlugin(
|
|
84
|
-
{ required: { [LocationCertaintySchema2]: 1 }, schema: PayloadSetSchema },
|
|
85
|
-
{
|
|
86
|
-
diviner: async (params) => {
|
|
87
|
-
return await LocationCertaintyDiviner.create(params);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
export {
|
|
92
|
-
LocationCertaintyPlugin
|
|
93
|
-
};
|
|
94
|
-
//# sourceMappingURL=Plugin.mjs.map
|
package/dist/node/Plugin.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Plugin.ts","../../src/Diviner/Config.ts","../../src/Diviner/Diviner.ts"],"sourcesContent":["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","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/abstract-diviner'\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 } 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 configSchemas = [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 max: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value > prev ? value : prev) : prev\n }, -Infinity),\n mean: (() => {\n const values = heuristic.reduce<number[]>(\n (prev, value) => {\n return value !== null ? [value + prev[0], prev[1] + 1] : prev\n },\n [0, 0],\n )\n return values[0] / values[1]\n })(),\n min: heuristic.reduce<number>((prev, value) => {\n return value !== null ? (value < prev ? value : prev) : prev\n }, Infinity),\n }\n }\n\n /* Given elevation and location payloads, generate heuristic arrays */\n private static locationsToHeuristics(elevations: ElevationPayload[], locations: LocationPayload[]) {\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 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 = 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"],"mappings":";AAAA,SAAS,2BAAAA,gCAA+B;AACxC,SAAS,wBAAwB;AACjC,SAAS,qCAAqC;;;ACGvC,IAAM,uCAA6E;;;ACL1F,SAAS,uBAAuB;AAGhC,SAAS,kBAAkB,oCAAoC;AAC/D,SAA+D,+BAA+B;AAC9F,SAA0B,sBAAsB;AAEhD,SAAS,sBAAsB;AAOxB,IAAM,2BAAN,MAAM,kCACH,gBAEV;AAAA,EACE,OAAgB,gBAAgB,CAAC,oCAAoC;AAAA,EACrE,OAAgB,eAAe;AAAA;AAAA,EAG/B,OAAe,cAAc,WAA0D;AACrF,WAAO;AAAA,MACL,KAAK,UAAU,OAAe,CAAC,MAAM,UAAU;AAC7C,eAAO,UAAU,OAAQ,QAAQ,OAAO,QAAQ,OAAQ;AAAA,MAC1D,GAAG,SAAS;AAAA,MACZ,OAAO,MAAM;AACX,cAAM,SAAS,UAAU;AAAA,UACvB,CAAC,MAAM,UAAU;AACf,mBAAO,UAAU,OAAO,CAAC,QAAQ,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI;AAAA,UAC3D;AAAA,UACA,CAAC,GAAG,CAAC;AAAA,QACP;AACA,eAAO,OAAO,CAAC,IAAI,OAAO,CAAC;AAAA,MAC7B,GAAG;AAAA,MACH,KAAK,UAAU,OAAe,CAAC,MAAM,UAAU;AAC7C,eAAO,UAAU,OAAQ,QAAQ,OAAO,QAAQ,OAAQ;AAAA,MAC1D,GAAG,Q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