Spaces:
Build error
Build error
File size: 2,627 Bytes
3382f47 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
// TODO: Remove the ability to have null values when benchmark implementation is complete
/// `Metrics` holds key performance metrics related to a benchmark test run.
///
/// The class encapsulates various data points like difficulty, success rate,
/// whether the task was attempted, the percentage of success, and other performance metrics.
class Metrics {
/// The perceived difficulty level of the test, usually represented as a string.
final String difficulty;
/// A boolean indicating whether the test was successful.
final bool success;
/// A boolean indicating whether the test was attempted.
final bool attempted;
/// The percentage of success in the test, represented as a double.
final double successPercentage;
/// The cost metric, can be any type depending on what is being measured (time, resources, etc.).
/// It is dynamic to allow for various types.
final dynamic cost;
/// The total runtime of the test, represented as a string.
final String runTime;
/// Constructs a new `Metrics` instance.
///
/// [difficulty]: The perceived difficulty level of the test.
/// [success]: A boolean indicating the success status of the test.
/// [attempted]: A boolean indicating if the test was attempted.
/// [successPercentage]: The success rate as a percentage.
/// [cost]: The cost metric for the test.
/// [runTime]: The total runtime of the test.
Metrics({
required this.difficulty,
required this.success,
required this.attempted,
required this.successPercentage,
required this.cost,
required this.runTime,
});
/// Creates a `Metrics` instance from a map.
///
/// [json]: A map containing key-value pairs corresponding to `Metrics` fields.
///
/// Returns a new `Metrics` populated with values from the map.
factory Metrics.fromJson(Map<String, dynamic> json) => Metrics(
difficulty: json['difficulty'] ?? 'placeholder',
success: json['success'],
attempted: json['attempted'] ?? false,
successPercentage: (json['success_percentage'] != null)
? json['success_percentage'].toDouble()
: 0.0,
cost: json['cost'] ?? 'placeholder',
runTime: json['run_time'] ?? 'placeholder',
);
/// Converts the `Metrics` instance to a map.
///
/// Returns a map containing key-value pairs corresponding to `Metrics` fields.
Map<String, dynamic> toJson() => {
'difficulty': difficulty,
'success': success,
'attempted': attempted,
'success_percentage': successPercentage,
'cost': cost,
'run_time': runTime,
};
}
|