From 25f0e358a3892873df3250ae8f2620aed0abb527 Mon Sep 17 00:00:00 2001 From: stopflock Date: Sun, 28 Sep 2025 17:02:58 -0500 Subject: [PATCH] clean up debug logging --- .../map_data_submodules/nodes_from_local.dart | 77 ++++--------------- 1 file changed, 16 insertions(+), 61 deletions(-) diff --git a/lib/services/map_data_submodules/nodes_from_local.dart b/lib/services/map_data_submodules/nodes_from_local.dart index 0273c94..46ec4b4 100644 --- a/lib/services/map_data_submodules/nodes_from_local.dart +++ b/lib/services/map_data_submodules/nodes_from_local.dart @@ -17,68 +17,29 @@ Future> fetchLocalNodes({ final areas = OfflineAreaService().offlineAreas; final Map 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> _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> _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) {