diff --git a/core/Cargo.toml b/core/Cargo.toml index be3f3fe..4551946 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "meritrank_core" -version = "0.8.2" +version = "0.8.3" edition = "2021" description = "MeritRank algorithm library" license = "MIT" diff --git a/core/src/rank.rs b/core/src/rank.rs index efffb5f..1c99fc5 100644 --- a/core/src/rank.rs +++ b/core/src/rank.rs @@ -53,18 +53,19 @@ impl MeritRank { } pub fn get_node_score(&self, ego: NodeId, target: NodeId) -> Result { - let counter = self.pos_hits.get(&ego) + let ego_positive_hits = self.pos_hits.get(&ego) .ok_or(MeritRankError::NodeIsNotCalculated)?; - let hits = counter.get_count(&target); + let target_hits = ego_positive_hits.get_count(&target); //if ASSERT && hits > 0.0 && !self.graph.is_connecting(ego, target) { return Err(MeritRankError::NoPathExists); } let default_counter = Counter::default(); let ego_neg_hits = self.neg_hits.get(&ego).unwrap_or(&default_counter); - let hits_penalized: Weight = hits as Weight - ego_neg_hits.get_count(&target) as Weight; - Ok(hits_penalized / counter.total_count() as Weight) + let total_hits = ego_positive_hits.total_count() + ego_neg_hits.total_count(); + let hits_penalized: Weight = target_hits as Weight - ego_neg_hits.get_count(&target) as Weight; + Ok(hits_penalized / total_hits as Weight) } pub fn get_ranks(&self, ego: NodeId, limit: Option) -> Result, MeritRankError> { diff --git a/service/Cargo.toml b/service/Cargo.toml index f888fac..312312b 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "meritrank_service" -version = "0.2.24" +version = "0.2.25" edition = "2021" [features] diff --git a/service/src/operations.rs b/service/src/operations.rs index d12a5fe..de43893 100644 --- a/service/src/operations.rs +++ b/service/src/operations.rs @@ -1287,7 +1287,7 @@ impl AugMultiGraph { self.node_info_from_id(src_id).name.clone(), self.node_info_from_id(dst_id).name.clone(), weight, - self.fetch_user_score_reversed(context, src_id, dst_id) + self.fetch_user_score_reversed(context, ego_id, dst_id) )}) .collect() } diff --git a/service/src/tests.rs b/service/src/tests.rs index 1b8a679..4962feb 100644 --- a/service/src/tests.rs +++ b/service/src/tests.rs @@ -1611,8 +1611,8 @@ fn scores_reversed() { "U3" => { assert!(x.2 > -0.1); assert!(x.2 < 0.3); - assert!(x.3 >= -1.0); - assert!(x.3 < -0.6); + assert!(x.3 > -0.3); + assert!(x.3 < 0.0); }, _ => assert!(false), @@ -2049,8 +2049,7 @@ fn graph_reversed() { if x.1 == "U1" { assert!(x.2 > 0.5); assert!(x.2 < 0.6); - assert!(x.3 > 0.15); - assert!(x.3 < 0.35); + assert!(x.3 > 0.4); } if x.1 == "U3" {