use serde::{Deserialize, Serialize};
use crate::events::LearningEvent;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StrategyAdviceRecord {
pub timestamp_ms: u64,
pub tick: u64,
pub advisor: String,
pub current_strategy: String,
pub recommended: String,
pub should_change: bool,
pub confidence: f64,
pub reason: String,
pub frontier_count: usize,
pub total_visits: u32,
pub failure_rate: f64,
pub latency_ms: u64,
pub success: bool,
pub error: Option<String>,
}
impl From<&LearningEvent> for StrategyAdviceRecord {
fn from(event: &LearningEvent) -> Self {
match event {
LearningEvent::StrategyAdvice {
timestamp_ms,
tick,
advisor,
current_strategy,
recommended,
should_change,
confidence,
reason,
frontier_count,
total_visits,
failure_rate,
latency_ms,
success,
error,
} => Self {
timestamp_ms: *timestamp_ms,
tick: *tick,
advisor: advisor.clone(),
current_strategy: current_strategy.clone(),
recommended: recommended.clone(),
should_change: *should_change,
confidence: *confidence,
reason: reason.clone(),
frontier_count: *frontier_count,
total_visits: *total_visits,
failure_rate: *failure_rate,
latency_ms: *latency_ms,
success: *success,
error: error.clone(),
},
_ => panic!("StrategyAdviceRecord::from() requires StrategyAdvice event"),
}
}
}
impl StrategyAdviceRecord {
pub fn is_success(&self) -> bool {
self.success
}
pub fn recommends_change(&self) -> bool {
self.should_change
}
}