mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-10-01 05:29:35 +02:00
Suspected location exclusion zone, drawn under real nodes, and update progress bar
This commit is contained in:
1 parent
4a44ab96d6
commit
f9351ba272
8 files changed
+206
-21
No files matched your search
@@ -52,7 +52,7 @@ class SuspectedLocationCache extends ChangeNotifier {
|
||||
|
||||
final boundsKey = '${bounds.north.toStringAsFixed(4)},${bounds.south.toStringAsFixed(4)},${bounds.east.toStringAsFixed(4)},${bounds.west.toStringAsFixed(4)}';
|
||||
|
||||
debugPrint('[SuspectedLocationCache] Getting locations for bounds: $boundsKey, processed entries count: ${_processedEntries.length}');
|
||||
// debugPrint('[SuspectedLocationCache] Getting locations for bounds: $boundsKey, processed entries count: ${_processedEntries.length}');
|
||||
|
||||
// Check cache first
|
||||
if (_boundsCache.containsKey(boundsKey)) {
|
||||
@@ -83,7 +83,7 @@ class SuspectedLocationCache extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
debugPrint('[SuspectedLocationCache] Checked ${_processedEntries.length} entries, $inBoundsCount in bounds, result: ${locations.length} locations');
|
||||
// debugPrint('[SuspectedLocationCache] Checked ${_processedEntries.length} entries, $inBoundsCount in bounds, result: ${locations.length} locations');
|
||||
|
||||
// Cache the result
|
||||
_boundsCache[boundsKey] = locations;
|
||||
@@ -125,7 +125,11 @@ class SuspectedLocationCache extends ChangeNotifier {
|
||||
}
|
||||
|
||||
/// Process raw CSV data and save to storage (calculates centroids once)
|
||||
Future<void> processAndSave(List<Map<String, dynamic>> rawData, DateTime fetchTime) async {
|
||||
Future<void> processAndSave(
|
||||
List<Map<String, dynamic>> rawData,
|
||||
DateTime fetchTime, {
|
||||
void Function(String message, double? progress)? onProgress,
|
||||
}) async {
|
||||
try {
|
||||
debugPrint('[SuspectedLocationCache] Processing ${rawData.length} raw entries...');
|
||||
|
||||
@@ -136,6 +140,13 @@ class SuspectedLocationCache extends ChangeNotifier {
|
||||
|
||||
for (int i = 0; i < rawData.length; i++) {
|
||||
final rowData = rawData[i];
|
||||
|
||||
// Report progress every 1000 entries
|
||||
if (i % 1000 == 0) {
|
||||
final progress = i / rawData.length;
|
||||
onProgress?.call('Calculating coordinates: ${i + 1}/${rawData.length}', progress);
|
||||
}
|
||||
|
||||
try {
|
||||
// Create a temporary SuspectedLocation to extract the centroid
|
||||
final tempLocation = SuspectedLocation.fromCsvRow(rowData);
|
||||
|
||||
@@ -64,8 +64,10 @@ class SuspectedLocationService {
|
||||
}
|
||||
|
||||
/// Manually refresh the data
|
||||
Future<bool> refreshData() async {
|
||||
return await _fetchData();
|
||||
Future<bool> refreshData({
|
||||
void Function(String message, double? progress)? onProgress,
|
||||
}) async {
|
||||
return await _fetchData(onProgress: onProgress);
|
||||
}
|
||||
|
||||
/// Check if data should be refreshed
|
||||
@@ -90,11 +92,14 @@ class SuspectedLocationService {
|
||||
}
|
||||
|
||||
/// Fetch data from the CSV URL
|
||||
Future<bool> _fetchData() async {
|
||||
Future<bool> _fetchData({
|
||||
void Function(String message, double? progress)? onProgress,
|
||||
}) async {
|
||||
if (_isLoading) return false;
|
||||
|
||||
_isLoading = true;
|
||||
try {
|
||||
onProgress?.call('Downloading CSV data...', null);
|
||||
debugPrint('[SuspectedLocationService] Fetching CSV data from $_csvUrl');
|
||||
|
||||
final response = await http.get(
|
||||
@@ -109,6 +114,8 @@ class SuspectedLocationService {
|
||||
return false;
|
||||
}
|
||||
|
||||
onProgress?.call('Parsing CSV data...', 0.2);
|
||||
|
||||
// Parse CSV with proper field separator and quote handling
|
||||
final csvData = const CsvToListConverter(
|
||||
fieldDelimiter: ',',
|
||||
@@ -180,9 +187,11 @@ class SuspectedLocationService {
|
||||
validRows++;
|
||||
}
|
||||
|
||||
// Log progress every 1000 rows
|
||||
// Log progress every 1000 rows and report to UI
|
||||
if (rowIndex % 1000 == 0) {
|
||||
debugPrint('[SuspectedLocationService] Processing row $rowIndex...');
|
||||
final progress = 0.4 + (rowIndex / dataRows.length) * 0.4; // 40% to 80% of total
|
||||
onProgress?.call('Processing row $rowIndex...', progress);
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
// Skip rows that can't be parsed
|
||||
@@ -191,10 +200,18 @@ class SuspectedLocationService {
|
||||
}
|
||||
}
|
||||
|
||||
onProgress?.call('Calculating coordinates...', 0.8);
|
||||
|
||||
final fetchTime = DateTime.now();
|
||||
|
||||
// Process raw data and save (calculates centroids once)
|
||||
await _cache.processAndSave(rawDataList, fetchTime);
|
||||
await _cache.processAndSave(rawDataList, fetchTime, onProgress: (message, progress) {
|
||||
// Map cache progress to final 20% (0.8 to 1.0)
|
||||
final finalProgress = 0.8 + (progress ?? 0) * 0.2;
|
||||
onProgress?.call(message, finalProgress);
|
||||
});
|
||||
|
||||
onProgress?.call('Complete!', 1.0);
|
||||
|
||||
debugPrint('[SuspectedLocationService] Successfully fetched and stored $validRows valid raw entries (${rawDataList.length} total)');
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user