Skip to main content

briefcase_core/models/
scorecard.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
5pub struct Scorecard {
6    pub metrics: HashMap<String, f64>,
7    pub weights: HashMap<String, f64>,
8    pub metadata: HashMap<String, serde_json::Value>,
9}
10
11impl Scorecard {
12    pub fn new() -> Self {
13        Self::default()
14    }
15
16    pub fn add_score(&mut self, name: String, value: f64, weight: f64) {
17        self.metrics.insert(name.clone(), value);
18        self.weights.insert(name, weight);
19    }
20
21    pub fn composite_score(&self) -> f64 {
22        if self.metrics.is_empty() {
23            return 0.0;
24        }
25        let mut total_weight = 0.0;
26        let mut weighted_sum = 0.0;
27        for (name, val) in &self.metrics {
28            let weight = self.weights.get(name).unwrap_or(&1.0);
29            weighted_sum += val * weight;
30            total_weight += weight;
31        }
32        if total_weight == 0.0 {
33            0.0
34        } else {
35            weighted_sum / total_weight
36        }
37    }
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
41pub struct ExperimentMetadata {
42    pub experiment_id: String,
43    pub run_index: u32,
44    pub total_runs: u32,
45    #[serde(default)]
46    pub tags: HashMap<String, String>,
47}