getStatistics method

Map<String, dynamic> getStatistics()

Get statistics

Implementation

Map<String, dynamic> getStatistics() {
  final completed = _entries.where((e) => e.isCompleted).toList();
  final successful = completed.where((e) => e.isSuccess).length;
  final failed = completed
      .where((e) => e.hasError || e.isClientError || e.isServerError)
      .length;
  final avgDuration = completed.isEmpty
      ? 0
      : completed
                .where((e) => e.duration != null)
                .map((e) => e.duration!.inMilliseconds)
                .fold<int>(0, (a, b) => a + b) ~/
            completed.where((e) => e.duration != null).length;

  return {
    'total': _entries.length,
    'completed': completed.length,
    'successful': successful,
    'failed': failed,
    'pending': _entries.length - completed.length,
    'avgDuration': avgDuration,
  };
}