hoffmation-base 2.17.0 → 2.17.1
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/lib/server/devices/espresense/espresenseDevice.d.ts +1 -1
- package/lib/server/devices/espresense/espresenseDevice.js +4 -4
- package/lib/server/devices/espresense/trilateration.js +8 -8
- package/lib/server/devices/espresense/trilaterationBasePoint.d.ts +1 -1
- package/lib/server/devices/espresense/trilaterationBasePoint.js +4 -4
- package/lib/server/services/utils/utils.js +4 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ export declare class EspresenseDevice implements iRoomDevice, iBluetoothDetector
|
|
|
14
14
|
deviceType: DeviceType;
|
|
15
15
|
readonly name: string;
|
|
16
16
|
private deviceMap;
|
|
17
|
-
private
|
|
17
|
+
private proximityCallbackMap;
|
|
18
18
|
constructor(name: string, roomName: string, x: number, y: number, z: number);
|
|
19
19
|
get customName(): string;
|
|
20
20
|
protected _info: DeviceInfo;
|
|
@@ -17,7 +17,7 @@ class EspresenseDevice {
|
|
|
17
17
|
this.deviceCapabilities = [DeviceCapability_1.DeviceCapability.bluetoothDetector];
|
|
18
18
|
this.deviceType = deviceType_1.DeviceType.Espresense;
|
|
19
19
|
this.deviceMap = new Map();
|
|
20
|
-
this.
|
|
20
|
+
this.proximityCallbackMap = new Map();
|
|
21
21
|
this.position = new trilaterationBasePoint_1.TrilaterationBasePoint(x, y, z, roomName);
|
|
22
22
|
this.name = name;
|
|
23
23
|
this._info = new DeviceInfo_1.DeviceInfo();
|
|
@@ -77,7 +77,7 @@ class EspresenseDevice {
|
|
|
77
77
|
}
|
|
78
78
|
dev.updateDistance(this, data.distance);
|
|
79
79
|
dev.guessRoom();
|
|
80
|
-
const cbs = this.
|
|
80
|
+
const cbs = this.proximityCallbackMap.get(dev.name);
|
|
81
81
|
if (cbs === undefined) {
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
@@ -125,12 +125,12 @@ class EspresenseDevice {
|
|
|
125
125
|
// Nothing
|
|
126
126
|
}
|
|
127
127
|
addProximityCallback(cb) {
|
|
128
|
-
let currentValue = this.
|
|
128
|
+
let currentValue = this.proximityCallbackMap.get(cb.deviceName);
|
|
129
129
|
if (currentValue == undefined) {
|
|
130
130
|
currentValue = [];
|
|
131
131
|
}
|
|
132
132
|
currentValue.push(cb);
|
|
133
|
-
this.
|
|
133
|
+
this.proximityCallbackMap.set(cb.deviceName, currentValue);
|
|
134
134
|
}
|
|
135
135
|
addDeviceTracking(devName) {
|
|
136
136
|
const dev = detectedBluetoothDevice_1.DetectedBluetoothDevice.getOrCreate(devName);
|
|
@@ -35,7 +35,7 @@ class Trilateration {
|
|
|
35
35
|
return bestMatches;
|
|
36
36
|
}
|
|
37
37
|
static getBestRatedCoordinates(distances) {
|
|
38
|
-
const
|
|
38
|
+
const allRatedCoordinatesMap = new Map();
|
|
39
39
|
for (const dist of distances) {
|
|
40
40
|
const point = this.basePoints.find((basePoint) => basePoint.ownPoint.coordinateName === dist.pointName);
|
|
41
41
|
if (point === undefined) {
|
|
@@ -49,16 +49,16 @@ class Trilateration {
|
|
|
49
49
|
const ratedCoordinates = point.getRatedCoordinates(dist.distance);
|
|
50
50
|
services_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Found ${ratedCoordinates.length} rated coordinates for ${dist.pointName} within distance of ${dist.distance}m`, { debugType: services_1.LogDebugType.Trilateration });
|
|
51
51
|
for (const ratedCoordinate of ratedCoordinates) {
|
|
52
|
-
const existingCoordinate =
|
|
52
|
+
const existingCoordinate = allRatedCoordinatesMap.get(ratedCoordinate.coordinateName);
|
|
53
53
|
if (existingCoordinate === undefined) {
|
|
54
|
-
|
|
54
|
+
allRatedCoordinatesMap.set(ratedCoordinate.coordinateName, ratedCoordinate);
|
|
55
55
|
continue;
|
|
56
56
|
}
|
|
57
57
|
existingCoordinate.rating += ratedCoordinate.rating;
|
|
58
58
|
existingCoordinate.matchCount++;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
return this.getBestRatedCoordinatesFromMap(
|
|
61
|
+
return this.getBestRatedCoordinatesFromMap(allRatedCoordinatesMap);
|
|
62
62
|
}
|
|
63
63
|
static checkRoom(distances) {
|
|
64
64
|
var _a;
|
|
@@ -71,13 +71,13 @@ class Trilateration {
|
|
|
71
71
|
return bestMatches[0].roomName;
|
|
72
72
|
}
|
|
73
73
|
// As we have multiple possible winners, we need to check how often which room occurs
|
|
74
|
-
const
|
|
74
|
+
const roomCountMap = new Map();
|
|
75
75
|
for (const point of bestMatches) {
|
|
76
76
|
const room = point.roomName;
|
|
77
|
-
const existingCount = (_a =
|
|
78
|
-
|
|
77
|
+
const existingCount = (_a = roomCountMap.get(room)) !== null && _a !== void 0 ? _a : 0;
|
|
78
|
+
roomCountMap.set(room, existingCount + 1);
|
|
79
79
|
}
|
|
80
|
-
return Array.from(
|
|
80
|
+
return Array.from(roomCountMap.entries()).sort((a, b) => b[1] - a[1])[0][0];
|
|
81
81
|
}
|
|
82
82
|
static getBestRatedCoordinatesFromMap(allRatedCoordinates) {
|
|
83
83
|
const sortedCoordinates = Array.from(allRatedCoordinates.values()).sort((a, b) => {
|
|
@@ -7,7 +7,7 @@ export declare class TrilaterationBasePoint {
|
|
|
7
7
|
readonly roomName: string;
|
|
8
8
|
private readonly _maximumDistance;
|
|
9
9
|
readonly ownPoint: TrilaterationPoint;
|
|
10
|
-
readonly
|
|
10
|
+
readonly precalculatedDistancesMap: Map<number, string[]>;
|
|
11
11
|
constructor(x: number, y: number, z: number, roomName: string, _maximumDistance?: number);
|
|
12
12
|
getRatedCoordinates(distance: number): TrilaterationRatedCoordinate[];
|
|
13
13
|
private rateCoordinates;
|
|
@@ -12,7 +12,7 @@ class TrilaterationBasePoint {
|
|
|
12
12
|
this.z = z;
|
|
13
13
|
this.roomName = roomName;
|
|
14
14
|
this._maximumDistance = _maximumDistance;
|
|
15
|
-
this.
|
|
15
|
+
this.precalculatedDistancesMap = new Map();
|
|
16
16
|
this.ownPoint = new trilaterationPoint_1.TrilaterationPoint(x, y, z, roomName);
|
|
17
17
|
}
|
|
18
18
|
getRatedCoordinates(distance) {
|
|
@@ -28,7 +28,7 @@ class TrilaterationBasePoint {
|
|
|
28
28
|
return result;
|
|
29
29
|
}
|
|
30
30
|
rateCoordinates(distance, result, rating) {
|
|
31
|
-
const possiblePoints = this.
|
|
31
|
+
const possiblePoints = this.precalculatedDistancesMap.get(distance);
|
|
32
32
|
if (possiblePoints !== undefined) {
|
|
33
33
|
for (const point of possiblePoints) {
|
|
34
34
|
result.push(new trilaterationRatedCoordinate_1.TrilaterationRatedCoordinate(point, rating));
|
|
@@ -44,9 +44,9 @@ class TrilaterationBasePoint {
|
|
|
44
44
|
continue;
|
|
45
45
|
}
|
|
46
46
|
count++;
|
|
47
|
-
const distancePoints = (_a = this.
|
|
47
|
+
const distancePoints = (_a = this.precalculatedDistancesMap.get(distance)) !== null && _a !== void 0 ? _a : [];
|
|
48
48
|
distancePoints.push(point.coordinateName);
|
|
49
|
-
this.
|
|
49
|
+
this.precalculatedDistancesMap.set(distance, distancePoints);
|
|
50
50
|
}
|
|
51
51
|
services_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Filled ${count} distances for Trilateration in room: ${this.roomName}`);
|
|
52
52
|
}
|
|
@@ -185,6 +185,10 @@ class Utils {
|
|
|
185
185
|
const newKey = lowerKey.replace('map', 'dict');
|
|
186
186
|
const dict = {};
|
|
187
187
|
const map = value;
|
|
188
|
+
if (typeof map.keys !== 'function') {
|
|
189
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Error, `Map ${currentKey}.${lowerKey} is not a map`);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
188
192
|
for (const mapName of map.keys()) {
|
|
189
193
|
dict[mapName] = lodash_1.default.isObject(map.get(mapName))
|
|
190
194
|
? this.deepOmit(map.get(mapName), keysToOmit, level + 1, `${currentKey}.${lowerKey}.${mapName}`)
|