Skip to content

Commit

Permalink
Fix total_rating calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
grunch committed Dec 23, 2024
1 parent 87b307d commit d1176b8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ uuid = { version = "1.8.0", features = [
"serde",
] }
reqwest = { version = "0.12.1", features = ["json"] }
# mostro-core = { version = "0.6.18", features = ["sqlx"] }
mostro-core = { git = "https://github.com/MostroP2P/mostro-core.git", branch = "user-table-pubkey", features = ["sqlx"] }
mostro-core = { version = "0.6.19", features = ["sqlx"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
config = "0.14.0"
clap = { version = "4.5.19", features = ["derive"] }
lnurl-rs = "0.9.0"
openssl = { version = "0.10.66", features = ["vendored"] }
once_cell = "1.20.2"
bitcoin = "0.32.5"
bitcoin = "0.32.5"
9 changes: 4 additions & 5 deletions src/app/rate_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,12 @@ pub async fn update_user_reputation_action(
// Going on with calculation
// increment first
user_to_vote.total_reviews += 1;
let old_rating = user_to_vote.total_rating as f64;
// recompute new rating
user_to_vote.total_rating = old_rating
+ ((user_to_vote.last_rating as f64) - old_rating) / (user_to_vote.total_reviews as f64);
// Store last rating
user_to_vote.last_rating = rating.into();
// recompute rating
user_to_vote.total_rating =
((user_to_vote.total_rating * (user_to_vote.total_reviews - 1) as f64) + rating as f64)
/ user_to_vote.total_reviews as f64;

// Create new rating event
let reputation_event = Rating::new(
user_to_vote.total_reviews as u64,
Expand Down

0 comments on commit d1176b8

Please sign in to comment.