getPossibleInterventionsForAppTripId method

Future<List<PossibleIntervention>> getPossibleInterventionsForAppTripId(
  1. String appTripId
)

Retrieves possible intervention events that occurred during a specific trip.

Analyzes trip data to identify segments where driving interventions could have been beneficial, such as areas with poor driving behavior, potential safety issues, or coaching opportunities. Each intervention includes location data, timing, and associated scoring statistics.

Parameters:

  • appTripId: Unique identifier for the trip to analyze

Returns:

  • List<PossibleIntervention>: List of intervention events with detailed information

Usage:

try {
  final interventions = await communicator.getPossibleInterventionsForAppTripId('trip-123');
  for (final intervention in interventions) {
    print('Intervention type: ${intervention.scoringType}');
    print('Start time: ${intervention.startTime}');
    print('Location: ${intervention.startAddress}');

    // Check scoring statistics
    if (intervention.scoreStats != null) {
      intervention.scoreStats!.forEach((scoreType, stats) {
        if (stats != null) {
          print('$scoreType - Average: ${stats.average}, Max: ${stats.max}');
        }
      });
    }
  }
} catch (e) {
  print('Failed to get interventions: $e');
}

Throws:

  • Future.error("Unable to get possible interventions"): When retrieval fails

Intervention Data Includes:

  • Timing: Start and end timestamps in ISO 8601 format
  • Location: GPS coordinates and resolved addresses for start/end points
  • Scoring: Statistical data for various driving behavior categories
  • Type: Classification of the intervention (e.g., "SPEEDING", "HARD_BRAKING", etc.)

Common Intervention Triggers:

  • Hard braking events
  • Rapid acceleration
  • Sharp cornering
  • Speeding incidents
  • Distracted driving patterns
  • Drowsy driving detection

Use Cases:

  • Driver coaching and feedback
  • Safety analysis and reporting
  • Insurance risk assessment
  • Fleet management insights
  • Training program development

Prerequisites:

  • Trip must be completed and processed
  • Trip data must be synchronized with servers
  • Valid app trip ID is required

Implementation

Future<List<PossibleIntervention>> getPossibleInterventionsForAppTripId(
  String appTripId,
) async {
  try {
    List<PossibleIntervention> possibleInterventions = await kruzr_comm
        .getPossibleInterventionsForAppTripId(appTripId);
    return possibleInterventions;
  } on Exception catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in getPossibleInterventionsForAppTripId");
      print(stackTrace);
      print(e);
    }
    return Future.error(
      "Unable to get possible interventions for app trip ID",
    );
  }
}