85 lines
3.3 KiB
Dart
85 lines
3.3 KiB
Dart
import 'road_alert_models.dart';
|
|
|
|
/// Regional regulatory compliance status for speed cameras and enforcement traps.
|
|
enum AlertComplianceJurisdiction {
|
|
/// Exact distance countdown, camera type, and mobile speed trap locations (e.g. United States, UK).
|
|
standard,
|
|
|
|
/// French "Zone de Danger" regulatory compliance (Art. R413-15 Code de la route).
|
|
/// Exact camera pinpoints are prohibited and transformed into general Danger Zone corridor advisories.
|
|
frenchDangerZone,
|
|
|
|
/// Jurisdictions where speed camera warning devices and software are strictly prohibited
|
|
/// while driving (e.g. Germany § 23 Abs. 1c StVO, Switzerland Art. 57b SVG).
|
|
/// Camera and radar trap alerts must be suppressed.
|
|
prohibited,
|
|
}
|
|
|
|
/// Evaluates and enforces regional compliance rules on road alerts.
|
|
class RoadAlertCompliance {
|
|
/// Evaluates regional regulatory compliance based on rider GPS coordinates.
|
|
static AlertComplianceJurisdiction evaluateJurisdiction(double lat, double lng) {
|
|
// Switzerland: Lat [45.81, 47.81], Lng [5.95, 10.49]
|
|
if (lat >= 45.81 && lat <= 47.81 && lng >= 5.95 && lng <= 10.49) {
|
|
return AlertComplianceJurisdiction.prohibited;
|
|
}
|
|
|
|
// Germany: Lat [47.27, 55.06], Lng [5.86, 15.04]
|
|
if (lat >= 47.27 && lat <= 55.06 && lng >= 5.86 && lng <= 15.04) {
|
|
return AlertComplianceJurisdiction.prohibited;
|
|
}
|
|
|
|
// France: Lat [41.33, 51.09], Lng [-5.14, 9.56]
|
|
// Exclude Switzerland/Germany overlap
|
|
if (lat >= 41.33 && lat <= 51.09 && lng >= -5.14 && lng <= 9.56) {
|
|
return AlertComplianceJurisdiction.frenchDangerZone;
|
|
}
|
|
|
|
// Default: United States (all 50 states + DC) and other standard jurisdictions
|
|
return AlertComplianceJurisdiction.standard;
|
|
}
|
|
|
|
/// Filters or transforms alerts to satisfy jurisdictional requirements.
|
|
static List<RoadAlert> applyCompliance(
|
|
List<RoadAlert> alerts, {
|
|
required double userLat,
|
|
required double userLng,
|
|
bool complianceEnabled = true,
|
|
}) {
|
|
if (!complianceEnabled) return alerts;
|
|
|
|
final jurisdiction = evaluateJurisdiction(userLat, userLng);
|
|
switch (jurisdiction) {
|
|
case AlertComplianceJurisdiction.prohibited:
|
|
// Suppress stationary speed cameras and mobile speed enforcement in Germany & Switzerland
|
|
return alerts.where((alert) {
|
|
if (alert.category == RoadAlertCategory.speedCamera) return false;
|
|
if (alert.category == RoadAlertCategory.police) {
|
|
final desc = alert.description.toLowerCase();
|
|
if (desc.contains('speed') || desc.contains('radar') || desc.contains('trap')) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}).toList();
|
|
|
|
case AlertComplianceJurisdiction.frenchDangerZone:
|
|
// Transform exact speed cameras into "Zone de Danger" corridor advisories
|
|
return alerts.map((alert) {
|
|
if (alert.category == RoadAlertCategory.speedCamera) {
|
|
return alert.copyWith(
|
|
category: RoadAlertCategory.hazard,
|
|
description: 'Zone de Danger — Section Sécurité Routière',
|
|
severity: RoadAlertSeverity.medium,
|
|
);
|
|
}
|
|
return alert;
|
|
}).toList();
|
|
|
|
case AlertComplianceJurisdiction.standard:
|
|
// United States standard: 100% full fidelity exact camera & mobile police alerts
|
|
return alerts;
|
|
}
|
|
}
|
|
}
|