Skip to content

Commit

Permalink
Load submission details as separate step
Browse files Browse the repository at this point in the history
  • Loading branch information
cptartur committed Aug 29, 2024
1 parent 35bf475 commit 7b9f8fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
8 changes: 6 additions & 2 deletions neurons/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ fn main() {
let users: Vec<String> = serde_json::from_str(users_raw.as_str()).unwrap();

let votes_raw = fs::read_to_string("data/votes.json").unwrap();
let votes: HashMap<Submission, HashMap<String, Vote>> =
let votes: HashMap<String, HashMap<String, Vote>> =
serde_json::from_str(votes_raw.as_str()).unwrap();

let submissions_raw = fs::read_to_string("data/submissions.json").unwrap();
let submissions: Vec<Submission> = serde_json::from_str(submissions_raw.as_str()).unwrap();

let delegatees_for_user_raw = fs::read_to_string("data/delegatees_for_user.json").unwrap();
let delegatees_for_user: HashMap<String, DelegateesForUser> =
serde_json::from_str(delegatees_for_user_raw.as_str()).unwrap();
let normalized_votes = normalize_votes(votes, &delegatees_for_user).unwrap();
let normalized_votes = normalize_votes(votes, &submissions, &delegatees_for_user).unwrap();
write_result(
"result/normalized_votes.json",
&to_sorted_map(normalized_votes),
Expand Down
22 changes: 12 additions & 10 deletions neurons/src/quorum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ impl DelegateesForUser {
}
}

#[allow(clippy::implicit_hasher)]
#[allow(clippy::implicit_hasher, clippy::missing_panics_doc)]
pub fn normalize_votes(
votes: HashMap<Submission, HashMap<String, Vote>>,
votes: HashMap<String, HashMap<String, Vote>>,
submissions: &[Submission],
delegatees_for_user: &HashMap<String, DelegateesForUser>,
) -> Result<HashMap<Submission, HashMap<String, Vote>>> {
) -> Result<HashMap<String, HashMap<String, Vote>>> {
votes
.into_iter()
.map(|(submission, submission_votes)| {
let submission_votes = normalize_votes_for_submission(
&submission,
&submission_votes,
delegatees_for_user,
)?;
Ok((submission, submission_votes))
.map(|(submission_name, submission_votes)| {
let submission = submissions
.iter()
.find(|sub| sub.name == submission_name)
.expect("Missing details for submission");
let submission_votes =
normalize_votes_for_submission(submission, &submission_votes, delegatees_for_user)?;
Ok((submission_name, submission_votes))
})
.collect::<Result<_>>()
}
Expand Down

0 comments on commit 7b9f8fc

Please sign in to comment.