From dcdff6abbd7ef81517371e998b60bee43d5e782e Mon Sep 17 00:00:00 2001 From: stopflock Date: Tue, 5 Aug 2025 17:30:55 -0500 Subject: [PATCH] profile filtering and submissions fixes --- lib/models/pending_upload.dart | 6 ++++-- lib/services/overpass_service.dart | 19 ++++++++----------- lib/services/uploader.dart | 11 +++++++---- lib/widgets/add_camera_sheet.dart | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/models/pending_upload.dart b/lib/models/pending_upload.dart index b0d8fcf..498a5ce 100644 --- a/lib/models/pending_upload.dart +++ b/lib/models/pending_upload.dart @@ -18,14 +18,16 @@ class PendingUpload { 'lat': coord.latitude, 'lon': coord.longitude, 'dir': direction, - 'profile': profile.name, + 'profile': profile.toJson(), 'attempts': attempts, }; factory PendingUpload.fromJson(Map j) => PendingUpload( coord: LatLng(j['lat'], j['lon']), direction: j['dir'], - profile: CameraProfile.alpr(), // only built‑in for now + profile: j['profile'] is Map + ? CameraProfile.fromJson(j['profile']) + : CameraProfile.alpr(), // fallback for legacy, more logic can be added attempts: j['attempts'] ?? 0, ); } diff --git a/lib/services/overpass_service.dart b/lib/services/overpass_service.dart index fa5dd86..4028ab2 100644 --- a/lib/services/overpass_service.dart +++ b/lib/services/overpass_service.dart @@ -15,21 +15,18 @@ class OverpassService { ) async { if (profiles.isEmpty) return []; - // Build regex of surveillance:type values from enabled profiles - final types = profiles - .map((p) => p.tags['surveillance:type']) - .whereType() - .toSet(); - final regex = types.join('|'); + // Build one node query per enabled profile (each with all its tags required) + final nodeClauses = profiles.map((profile) { + final tagFilters = profile.tags.entries + .map((e) => '["${e.key}"="${e.value}"]') + .join('\n '); + return '''node\n $tagFilters\n (${bbox.southWest.latitude},${bbox.southWest.longitude},\n ${bbox.northEast.latitude},${bbox.northEast.longitude});'''; + }).join('\n '); final query = ''' [out:json][timeout:25]; ( - node - ["man_made"="surveillance"] - ["surveillance:type"~"^(${regex})\$"] - (${bbox.southWest.latitude},${bbox.southWest.longitude}, - ${bbox.northEast.latitude},${bbox.northEast.longitude}); + $nodeClauses ); out body 250; '''; diff --git a/lib/services/uploader.dart b/lib/services/uploader.dart index e0d2182..9bc88a9 100644 --- a/lib/services/uploader.dart +++ b/lib/services/uploader.dart @@ -32,13 +32,16 @@ class Uploader { print('Uploader: Created changeset ID: $csId'); // 2. create node + // Merge tags: direction in PendingUpload should always be present, + // and override any in the profile for upload purposes + final mergedTags = Map.from(p.profile.tags) + ..['direction'] = p.direction.round().toString(); + final tagsXml = mergedTags.entries.map((e) => + '').join('\n '); final nodeXml = ''' - - - - + $tagsXml '''; print('Uploader: Creating node...'); diff --git a/lib/widgets/add_camera_sheet.dart b/lib/widgets/add_camera_sheet.dart index 845df6d..3d910bb 100644 --- a/lib/widgets/add_camera_sheet.dart +++ b/lib/widgets/add_camera_sheet.dart @@ -46,7 +46,7 @@ class AddCameraSheet extends StatelessWidget { title: const Text('Profile'), trailing: DropdownButton( value: session.profile, - items: appState.profiles + items: appState.enabledProfiles .map((p) => DropdownMenuItem(value: p, child: Text(p.name))) .toList(), onChanged: (p) =>