getDrivingBehaviourScore method

Future<DrivingBehaviourScore?> getDrivingBehaviourScore(
  1. DateTime startTime,
  2. DateTime endTime,
  3. KruzrPerioicType kruzrPerioicType
)

Retrieves detailed driving behavior scores broken down by category.

Provides granular analysis of driving behavior including scores for specific categories like acceleration, braking, cornering, speeding, etc.

Parameters:

  • startTime: Beginning of the time range
  • endTime: End of the time range
  • kruzrPerioicType: Aggregation period (daily, weekly, monthly)

Returns:

  • DrivingBehaviourScore?: Detailed behavior scores by category, or null if not available

Usage:

try {
  final behaviorScore = await communicator.getDrivingBehaviourScore(
    DateTime.now().subtract(Duration(days: 7)),
    DateTime.now(),
    KruzrPerioicType.daily,
  );
  if (behaviorScore != null) {
    print('Acceleration score: ${behaviorScore.accelerationScore}');
    print('Braking score: ${behaviorScore.brakingScore}');
    print('Cornering score: ${behaviorScore.corneringScore}');
  }
} catch (e) {
  print('Failed to get behavior score: $e');
}

Throws:

  • Future.error("Unable to get aggregated driving behaviour score"): When retrieval fails

Implementation

Future<DrivingBehaviourScore?> getDrivingBehaviourScore(
    DateTime startTime,
    DateTime endTime,
    KruzrPerioicType kruzrPerioicType,
    ) async {
  try {
    return await kruzr_comm.getDrivingBehaviourScore(
      startTime,
      endTime,
      kruzrPerioicType,
    );
  } on PlatformException catch (e) {
    if (kDebugMode) {
      print(e);
      print("PlatformException in getDrivingBehaviourScore");
    }
    return Future.error({"code": e.code, "message": e.message, "details": e.details});
  } on Exception catch (e) {
    if (kDebugMode) {
      print(e);
      print("Exception in getDrivingBehaviourScore");
    }
    return Future.error(PlatformException(code: "PLUGIN_ERROR", message: e.toString()));
  }
}