feat: tracker location based on multiple location providers #5
@@ -15,8 +15,8 @@ domainEventEmitter.on(
|
|||||||
|
|
||||||
var wifi_based_latitude: number;
|
var wifi_based_latitude: number;
|
||||||
var wifi_based_longitude: number;
|
var wifi_based_longitude: number;
|
||||||
var gnss_based_latitude: number;
|
var gnss_based_latitude: number | undefined = undefined;
|
||||||
var gnss_based_longitude: number;
|
var gnss_based_longitude: number | undefined = undefined;
|
||||||
var ttn_gw_based_latitude: number | undefined = undefined;
|
var ttn_gw_based_latitude: number | undefined = undefined;
|
||||||
var ttn_gw_based_longitude: number | undefined = undefined;
|
var ttn_gw_based_longitude: number | undefined = undefined;
|
||||||
|
localhorst marked this conversation as resolved
Outdated
|
|||||||
|
|
||||||
@@ -50,14 +50,21 @@ domainEventEmitter.on(
|
|||||||
// TODO: parse Wifi location here
|
// TODO: parse Wifi location here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((event.gnssLocation.latitude) && (event.gnssLocation.longitude)) {
|
||||||
|
gnss_based_latitude = event.gnssLocation.latitude;
|
||||||
|
gnss_based_longitude = event.gnssLocation.longitude;
|
||||||
|
} else {
|
||||||
|
console.log("No GNSS location received!")
|
||||||
|
}
|
||||||
|
|
||||||
const newLocation = await locationService.createLocation({
|
const newLocation = await locationService.createLocation({
|
||||||
lp_ttn_end_device_uplinks_id: event.lp_ttn_end_device_uplinks_id,
|
lp_ttn_end_device_uplinks_id: event.lp_ttn_end_device_uplinks_id,
|
||||||
|
localhorst marked this conversation as resolved
Outdated
Pheanox
commented
Der Wifi eintrag wird nur die die Datenbank geschrieben, wenn es eine Location gibt, sollte dieser nicht auch ohne reingeschrieben werden mit latitude und longitude undefined? Ansonsten würde ich es in drei steps unterteilen: Api Call, Datenbank entry erstellen, totalWeight + weightedLatitude + weightedLongitude ausrechnen. Ich glaube das macht es übersichtlicher ist aber vermutlich Geschmackssache. Mein Vorschlag: ` const wifiScans = await Promise.all(
Der Wifi eintrag wird nur die die Datenbank geschrieben, wenn es eine Location gibt, sollte dieser nicht auch ohne reingeschrieben werden mit latitude und longitude undefined? Ansonsten würde ich es in drei steps unterteilen: Api Call, Datenbank entry erstellen, totalWeight + weightedLatitude + weightedLongitude ausrechnen. Ich glaube das macht es übersichtlicher ist aber vermutlich Geschmackssache. Mein Vorschlag:
` const wifiScans = await Promise.all(
event.wifis.map(async (wifi) => {
const apiResponse = await getLocationForWifiMemoized(wifi.mac);
return {
lp_ttn_end_device_uplinks_id: event.lp_ttn_end_device_uplinks_id,
mac: wifi.mac,
rssi: wifi.rssi,
latitude: apiResponse?.results[0]?.trilat,
longitude: apiResponse?.results[0]?.trilong,
};
})
);
await wifiScanService.createWifiScans(wifiScans);
const { totalWeight, weightedLatitude, weightedLongitude } =
wifiScans.reduce(
(acc, { latitude, longitude, rssi }) => {
if (latitude && longitude && rssi !== 0) {
const weight = 1 / Math.abs(rssi);
acc.totalWeight += weight;
acc.weightedLatitude += latitude * weight;
acc.weightedLongitude += longitude * weight;
}
return acc;
},
{
totalWeight: 0,
weightedLatitude: 0,
weightedLongitude: 0,
}
);
const virtualLocation = {
latitude: weightedLatitude / totalWeight,
longitude: weightedLongitude / totalWeight,
};`
|
|||||||
ttn_gw_latitude: ttn_gw_based_latitude,
|
ttn_gw_latitude: ttn_gw_based_latitude,
|
||||||
ttn_gw_longitude: ttn_gw_based_longitude,
|
ttn_gw_longitude: ttn_gw_based_longitude,
|
||||||
//TODO: Add gnss location
|
gnss_latitude: gnss_based_latitude,
|
||||||
|
gnss_longitude: gnss_based_longitude,
|
||||||
});
|
});
|
||||||
|
localhorst marked this conversation as resolved
Outdated
Pheanox
commented
await wifiScanService.createWifiScan await wifiScanService.createWifiScan
|
|||||||
|
|
||||||
|
|
||||||
console.log(newLocation)
|
console.log(newLocation)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Das ! kann weg.
Bzw. kann alles weg, wird nicht verwendet