reductionml_core/metrics/
example_number.rs1use crate::{metrics::Metric, Features};
2
3use super::MetricValue;
4
5pub struct ExampleNumberMetric {
6 pub count: u64,
7}
8
9impl ExampleNumberMetric {
10 pub fn new() -> ExampleNumberMetric {
11 ExampleNumberMetric { count: 0 }
12 }
13}
14
15impl Default for ExampleNumberMetric {
16 fn default() -> Self {
17 Self::new()
18 }
19}
20
21impl Metric for ExampleNumberMetric {
22 fn add_point(
23 &mut self,
24 _features: &Features,
25 _label: &crate::types::Label,
26 _prediction: &crate::types::Prediction,
27 ) {
28 self.count += 1;
29 }
30
31 fn get_value(&self) -> MetricValue {
32 if self.count == 0 {
33 panic!("Cannot get value of ExampleNumberMetric with no points");
34 }
35 MetricValue::Int(self.count as i32 - 1)
36 }
37
38 fn get_name(&self) -> String {
39 "Example #".to_owned()
40 }
41}