use crate::distribution::{DistContext, Distribution, PortSummary};
use crate::node::NodeId;
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct StatResult {
pub dist_context: DistContext,
pub node_dists: HashMap<NodeId, DistContext>,
pub branch_dists: HashMap<usize, DistContext>,
pub variant_dists: HashMap<usize, DistContext>,
pub particles: Option<Vec<HashMap<String, f64>>>,
}
impl StatResult {
pub fn new() -> Self {
Self {
dist_context: HashMap::new(),
node_dists: HashMap::new(),
branch_dists: HashMap::new(),
variant_dists: HashMap::new(),
particles: None,
}
}
pub fn get(&self, key: &str) -> Option<&Distribution> {
self.dist_context.get(key)
}
pub fn contains(&self, key: &str) -> bool {
self.dist_context.contains_key(key)
}
pub fn summary(&self, key: &str) -> Option<PortSummary> {
self.dist_context.get(key).map(|d| d.summary())
}
pub fn iter(&self) -> impl Iterator<Item = (&String, &Distribution)> {
self.dist_context.iter()
}
pub fn get_node_dists(&self, node_id: NodeId) -> Option<&DistContext> {
self.node_dists.get(&node_id)
}
pub fn get_from_node(&self, node_id: NodeId, key: &str) -> Option<&Distribution> {
self.node_dists.get(&node_id)?.get(key)
}
pub fn for_branch(&self, branch_id: usize) -> Option<&DistContext> {
self.branch_dists.get(&branch_id)
}
pub fn get_from_branch(&self, branch_id: usize, key: &str) -> Option<&Distribution> {
self.branch_dists.get(&branch_id)?.get(key)
}
pub fn for_variant(&self, variant_idx: usize) -> Option<&DistContext> {
self.variant_dists.get(&variant_idx)
}
pub fn get_from_variant(&self, variant_idx: usize, key: &str) -> Option<&Distribution> {
self.variant_dists.get(&variant_idx)?.get(key)
}
pub fn print_summary(&self) {
let mut keys: Vec<&String> = self
.dist_context
.keys()
.filter(|k| !k.starts_with("__branch_"))
.collect();
keys.sort();
for key in keys {
let dist = &self.dist_context[key];
println!(" {key}: {}", dist.summary());
}
}
}
impl Default for StatResult {
fn default() -> Self {
Self::new()
}
}