Skip to content

Commit

Permalink
Improvements on filtering ot accurate reports
Browse files Browse the repository at this point in the history
  • Loading branch information
danny committed Sep 9, 2024
1 parent c19628d commit bab8460
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions macless_haystack/lib/accessory/accessory_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,30 +217,29 @@ class AccessoryRegistry extends ChangeNotifier {
//Sort by date
decryptedReports.sort((a, b) {
var aDate = a.timestamp ?? DateTime(1970);
var bDate = b.timestamp ?? DateTime(1970);
var bDate = b.timestamp ?? DateTime(1970);
return aDate.compareTo(bDate);
});

//Update the latest timestamp
if (decryptedReports.isNotEmpty) {
var lastReport = decryptedReports[decryptedReports.length - 1];
var oldTs = DateTime(1970);
var oldTs = DateTime(1970);
var latestReportTS = lastReport.timestamp ?? DateTime(1971);
if (oldTs.isBefore(latestReportTS)) {
//only an actualization if oldTS is not set or is older than the latest of the new ones
accessory.lastLocation =
LatLng(lastReport.latitude!, lastReport.longitude!);
accessory.datePublished = latestReportTS;//
accessory.datePublished = latestReportTS; //
notifyListeners(); //redraw the UI, if the timestamp has changed
}
}

//add to history in correct order
for (var i = 0; i < decryptedReports.length; i++) {
FindMyLocationReport report = decryptedReports[i];
if (report.longitude!.abs() <= 180 &&
report.latitude!.abs() <= 90 &&
report.accuracy! < 100) {
if (report.accuracy! < 100 ||
report.longitude!.abs() <= 180 && report.latitude!.abs() <= 90) {
accessory.addLocationHistoryEntry(report);
} else {
logger.d(
Expand Down

0 comments on commit bab8460

Please sign in to comment.