pub mod json;
pub use json::JsonReporter;
use std::path::Path;
use serde::{Deserialize, Serialize};
use crate::aggregator::AggregatedResults;
use crate::error::Result;
use crate::run::EvalRun;
pub trait Reporter {
fn generate(&self, report: &EvalReport) -> Result<String>;
fn write_to_file(&self, report: &EvalReport, path: impl AsRef<Path>) -> Result<()> {
let content = self.generate(report)?;
std::fs::write(path, content)?;
Ok(())
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ConfigSummary {
pub scenario_name: String,
pub scenario_id: String,
pub worker_count: usize,
pub max_ticks: u64,
pub run_count: usize,
}
#[derive(Debug, Clone, Default)]
pub struct SeedInfo {
pub base_seed: u64,
pub run_seeds: Vec<u64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AssertionResult {
pub name: String,
pub passed: bool,
pub expected: String,
pub actual: String,
pub message: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EvalReport {
pub config_summary: ConfigSummary,
#[serde(skip)]
pub seed_info: SeedInfo,
pub runs: Vec<EvalRun>,
pub aggregated: AggregatedResults,
pub assertion_results: Vec<AssertionResult>,
}
impl EvalReport {
pub fn all_assertions_passed(&self) -> bool {
self.assertion_results.iter().all(|r| r.passed)
}
pub fn to_json_file(&self, path: impl AsRef<Path>) -> Result<()> {
JsonReporter::new().write_to_file(self, path)
}
}