| |
|
|
| |
| #[derive(Debug, Clone)] |
| pub struct Pathway { |
| |
| pub conclusion: String, |
| |
| pub vote: PathwayVote, |
| |
| pub confidence: f64, |
| |
| pub source: &'static str, |
| |
| pub chain: Vec<String>, |
| } |
|
|
| |
| #[derive(Debug, Clone, Copy, PartialEq)] |
| pub enum PathwayVote { |
| Support, |
| Oppose, |
| Neutral, |
| } |
|
|
| |
| #[derive(Debug)] |
| pub struct FusedResult { |
| |
| pub conclusion: String, |
| |
| pub confidence: f64, |
| |
| pub majority_vote: PathwayVote, |
| |
| pub pathways: Vec<Pathway>, |
| } |
|
|
| |
| #[derive(Default, Clone)] |
| pub struct PathwayFusion { |
| pathways: Vec<Pathway>, |
| } |
|
|
| impl PathwayFusion { |
| pub fn new() -> Self { |
| Self::default() |
| } |
|
|
| |
| pub fn add(&mut self, pathway: Pathway) { |
| self.pathways.push(pathway); |
| } |
|
|
| |
| pub fn fuse(&self) -> Option<FusedResult> { |
| if self.pathways.is_empty() { |
| return None; |
| } |
| let votes: Vec<_> = self.pathways.iter().collect(); |
| let total: f64 = votes.iter().map(|p| p.confidence).sum(); |
| let avg_confidence = total / votes.len() as f64; |
| let support_count = votes.iter().filter(|p| p.vote == PathwayVote::Support).count(); |
| let oppose_count = votes.iter().filter(|p| p.vote == PathwayVote::Oppose).count(); |
| let majority = if support_count > oppose_count { |
| PathwayVote::Support |
| } else if oppose_count > support_count { |
| PathwayVote::Oppose |
| } else { |
| PathwayVote::Neutral |
| }; |
| Some(FusedResult { |
| conclusion: votes.first().map(|p| p.conclusion.clone()).unwrap_or_default(), |
| confidence: avg_confidence, |
| majority_vote: majority, |
| pathways: self.pathways.clone(), |
| }) |
| } |
|
|
| |
| pub fn reset(&mut self) { |
| self.pathways.clear(); |
| } |
| } |
|
|