target method
Implementation
Duration target(String client, String type) {
Duration? median(Iterable<Map<String, dynamic>> entries) {
final seconds = entries
.take(5)
.map((e) => e['durationSeconds'])
.whereType<int>()
.where((s) => s > 0)
.toList()
..sort();
if (seconds.isEmpty) return null;
return Duration(seconds: seconds[seconds.length ~/ 2]);
}
return median(_history
.where((e) => e['client'] == client && e['type'] == type)) ??
median(_history.where((e) => e['type'] == type)) ??
defaults[type] ??
const Duration(minutes: 5);
}