use rskit_errors::AppResult;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchSample<L = String> {
pub id: String,
#[serde(skip)]
pub input: Vec<u8>,
pub label: L,
#[serde(default)]
pub source: String,
#[serde(default)]
pub metadata: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Prediction<L = String> {
#[serde(default)]
pub sample_id: String,
pub label: L,
pub score: f64,
#[serde(default)]
pub scores: HashMap<String, f64>,
#[serde(default)]
pub metadata: HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone)]
pub struct ScoredSample<L = String> {
pub sample: BenchSample<L>,
pub prediction: Prediction<L>,
}
pub type LabelMapper<L> = Box<dyn Fn(&str) -> AppResult<L> + Send + Sync>;
pub fn string_label_mapper() -> LabelMapper<String> {
Box::new(|s| Ok(s.to_string()))
}
impl<L: Default> Default for Prediction<L> {
fn default() -> Self {
Self {
sample_id: String::default(),
label: L::default(),
score: 0.0,
scores: HashMap::new(),
metadata: HashMap::new(),
}
}
}