fetchTripInsights method

Future<TripInsights?> fetchTripInsights(
  1. String appTripId
)

Retrieves comprehensive insights for a specific trip.

Provides a detailed analysis of the trip across multiple dimensions including safety, performance, efficiency, contextual factors, and comparative trends. These insights are generated using advanced analytics on trip data to help users understand driving behavior and identify areas of improvement.

Parameters:

  • appTripId: Unique identifier for the trip

Returns:

  • List<TripInsights>: A list containing structured insights for the trip. Each item includes:
    • Safety Insights: Risk score, interventions, critical events, safety tips
    • Performance Insights: Driving score, smoothness, speed compliance
    • Efficiency Insights: Route efficiency, time comparison, fuel tips
    • Contextual Insights: Weather, traffic, time of day, route familiarity
    • Comparative Insights: Trends, improvements, strengths, streak analysis
    • Summary: High-level human-readable insights

Usage:

try {
  final insights = await communicator.fetchTripInsights('trip-123');

  for (final insight in insights) {
    print('Driving Score: ${insight.performance?.drivingScore}');
    print('Risk Score: ${insight.safety?.riskScore}');
    print('Summary: ${insight.summary}');
  }
} catch (e) {
  print('Failed to fetch trip insights: $e');
}

Throws:

  • Future.error("Unable to fetch trip insights"): When retrieval fails

Use Cases:

  • Post-trip feedback and summaries
  • Driver coaching and improvement tracking
  • Gamification (streaks, achievements, progress)
  • Risk and safety analysis
  • Personalized driving recommendations

Prerequisites:

  • User must be logged in
  • Trip must be completed and processed
  • Trip data should be synchronized with backend

Implementation

Future<TripInsights?> fetchTripInsights(String appTripId) async {
  try {
    return await kruzr_comm.fetchTripInsights(appTripId);
  } on Exception catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in fetchTripInsights");
      print(stackTrace);
      print(e);
    }
    return Future.error("Unable to fetch trip insights");
  }
}