use crate::core::relay::Relay;
use crate::schema::structs::TrustLabel;
use std::collections::HashMap;
pub mod eigentrust;
pub mod moon;
pub mod rewards;
#[allow(dead_code)]
struct Trust {
relay: Relay,
labels: HashMap<Vec<u8>, HashMap<Vec<u8>, f64>>,
}
#[allow(dead_code)]
impl Trust {
}
#[allow(dead_code)]
fn datt(
labels: HashMap<&Vec<u8>, &Vec<TrustLabel>>,
self_peer_id: &Vec<u8>,
expansion_threshold: f64,
) {
let self_trust = labels.get(self_peer_id).unwrap();
let mut scores: HashMap<&Vec<u8>, f64> = HashMap::new();
for immediate_peer_label in *self_trust {
scores.insert(&immediate_peer_label.peer_id, immediate_peer_label.trust_data.get(0).unwrap().label());
}
let current_neighbor_expansion = self_trust.clone().clone();
while !current_neighbor_expansion.is_empty() {
let mut next_neighbor_expansion: Vec<TrustLabel> = vec![];
let mut dot_scores: HashMap<&Vec<u8>, Vec<f64>> = HashMap::new();
for l in current_neighbor_expansion.clone() {
if l.trust_data.get(0).unwrap().label() > expansion_threshold {
let outer_labels = labels.get(&l.peer_id).unwrap();
for l2 in *outer_labels {
if !scores.contains_key(&l2.peer_id) {
let transitive_current_score = scores.get(&l.peer_id).unwrap();
let outer_transitive_score = transitive_current_score * l2.trust_data.get(0).unwrap().label();
match dot_scores.get_mut(&l2.peer_id) {
None => {
dot_scores.insert(&l2.peer_id, vec![outer_transitive_score]);
}
Some(v) => {
v.push(outer_transitive_score);
}
}
if !next_neighbor_expansion.contains(l2) {
next_neighbor_expansion.push(l2.clone());
}
}
}
}
}
for (k, v) in dot_scores.iter() {
scores.insert(k, v.iter().sum::<f64>() / (v.len() as f64));
}
}
}
#[test]
fn test_bed() {
println!("wo")
}