clean up debug logging

This commit is contained in:
stopflock
2025-09-28 17:02:58 -05:00
parent 0cbcec7017
commit 25f0e358a3

View File

@@ -17,68 +17,29 @@ Future<List<OsmCameraNode>> fetchLocalNodes({
final areas = OfflineAreaService().offlineAreas;
final Map<int, OsmCameraNode> deduped = {};
debugPrint('[fetchLocalNodes] Checking ${areas.length} offline areas for nodes');
debugPrint('[fetchLocalNodes] Requested bounds: ${bounds.southWest.latitude},${bounds.southWest.longitude} to ${bounds.northEast.latitude},${bounds.northEast.longitude}');
debugPrint('[fetchLocalNodes] Using ${profiles.length} profiles: ${profiles.map((p) => p.name).join(', ')}');
for (final area in areas) {
debugPrint('[fetchLocalNodes] Area ${area.name} (${area.id}): status=${area.status}');
if (area.status != OfflineAreaStatus.complete) {
debugPrint('[fetchLocalNodes] Skipping area ${area.name} - status is ${area.status}');
continue;
}
debugPrint('[fetchLocalNodes] Area ${area.name} bounds: ${area.bounds.southWest.latitude},${area.bounds.southWest.longitude} to ${area.bounds.northEast.latitude},${area.bounds.northEast.longitude}');
if (!area.bounds.isOverlapping(bounds)) {
debugPrint('[fetchLocalNodes] Skipping area ${area.name} - bounds do not overlap');
continue;
}
if (area.status != OfflineAreaStatus.complete) continue;
if (!area.bounds.isOverlapping(bounds)) continue;
final nodes = await _loadAreaNodes(area);
debugPrint('[fetchLocalNodes] Area ${area.name} loaded ${nodes.length} nodes from storage');
int nodesBefore = deduped.length;
int dedupFiltered = 0;
int boundsFiltered = 0;
int profileFiltered = 0;
for (final node in nodes) {
// Deduplicate by node ID, preferring the first occurrence
if (deduped.containsKey(node.id)) {
dedupFiltered++;
continue;
}
if (deduped.containsKey(node.id)) continue;
// Within view bounds?
if (!_pointInBounds(node.coord, bounds)) {
boundsFiltered++;
if (boundsFiltered <= 3) { // Log first few for debugging
debugPrint('[fetchLocalNodes] Node ${node.id} at ${node.coord.latitude},${node.coord.longitude} outside bounds ${bounds.southWest.latitude},${bounds.southWest.longitude} to ${bounds.northEast.latitude},${bounds.northEast.longitude}');
}
continue;
}
if (!_pointInBounds(node.coord, bounds)) continue;
// Profile filter if used
if (profiles.isNotEmpty && !_matchesAnyProfile(node, profiles)) {
profileFiltered++;
if (profileFiltered <= 3) { // Log first few for debugging
debugPrint('[fetchLocalNodes] Node ${node.id} tags ${node.tags} don\'t match any of ${profiles.length} profiles');
}
continue;
}
if (profiles.isNotEmpty && !_matchesAnyProfile(node, profiles)) continue;
deduped[node.id] = node;
}
int nodesAdded = deduped.length - nodesBefore;
debugPrint('[fetchLocalNodes] Area ${area.name}: dedup filtered: $dedupFiltered, bounds filtered: $boundsFiltered, profile filtered: $profileFiltered');
debugPrint('[fetchLocalNodes] Area ${area.name} contributed ${nodesAdded} nodes after filtering');
}
final out = deduped.values.take(maxNodes ?? deduped.length).toList();
debugPrint('[fetchLocalNodes] Returning ${out.length} nodes total');
return out;
}
// Try in-memory first, else load from disk
Future<List<OsmCameraNode>> _loadAreaNodes(OfflineArea area) async {
if (area.nodes.isNotEmpty) {
debugPrint('[_loadAreaNodes] Area ${area.name} has ${area.nodes.length} nodes in memory');
return area.nodes;
}
@@ -86,30 +47,24 @@ Future<List<OsmCameraNode>> _loadAreaNodes(OfflineArea area) async {
final nodeFile = File('${area.directory}/nodes.json');
final legacyCameraFile = File('${area.directory}/cameras.json');
File fileToLoad;
File? fileToLoad;
if (await nodeFile.exists()) {
fileToLoad = nodeFile;
debugPrint('[_loadAreaNodes] Found new node file: ${fileToLoad.path}');
} else if (await legacyCameraFile.exists()) {
fileToLoad = legacyCameraFile;
debugPrint('[_loadAreaNodes] Found legacy camera file: ${fileToLoad.path}');
} else {
debugPrint('[_loadAreaNodes] No node file exists for area ${area.name}');
debugPrint('[_loadAreaNodes] Checked: ${nodeFile.path}');
debugPrint('[_loadAreaNodes] Checked: ${legacyCameraFile.path}');
return [];
}
try {
final str = await fileToLoad.readAsString();
final jsonList = jsonDecode(str) as List;
final nodes = jsonList.map((e) => OsmCameraNode.fromJson(e)).toList();
debugPrint('[_loadAreaNodes] Loaded ${nodes.length} nodes from ${fileToLoad.path}');
return nodes;
} catch (e) {
debugPrint('[_loadAreaNodes] Error loading nodes from ${fileToLoad.path}: $e');
return [];
if (fileToLoad != null) {
try {
final str = await fileToLoad.readAsString();
final jsonList = jsonDecode(str) as List;
return jsonList.map((e) => OsmCameraNode.fromJson(e)).toList();
} catch (e) {
debugPrint('[_loadAreaNodes] Error loading nodes from ${fileToLoad.path}: $e');
}
}
return [];
}
bool _pointInBounds(LatLng pt, LatLngBounds bounds) {