Skip to content

Commit

Permalink
update proposal score command
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy committed Jul 27, 2023
1 parent 1eabee9 commit 00f555c
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 1,302 deletions.
84 changes: 23 additions & 61 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion src/catalyst-toolbox/catalyst-toolbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ snapshot-lib = { path = "../snapshot-lib" }
fraction = "0.12"
tracing.workspace = true
tracing-subscriber.workspace = true
rusqlite = { version = "0.29.0", features = ["bundled"] }
vit-servicing-station-lib = { path = "../../vit-servicing-station/vit-servicing-station-lib", optional = true }

[dev-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ pub struct ProposalScore {
#[clap(long)]
reviews_path: PathBuf,

/// Path to the output sqlite3 database file
/// Path to the input json file with the proposals file, in which resulted output will rewrite its content
#[clap(long)]
db_path: PathBuf,
proposals_path: PathBuf,
}

impl ProposalScore {
pub fn exec(self) -> Result<(), Report> {
let reviews =
catalyst_toolbox::proposal_score::load::load_reviews_from_csv(&self.reviews_path)?;
let mut proposals =
catalyst_toolbox::proposal_score::load::load_proposals_from_json(&self.proposals_path)?;

for (proposal_id, (aligment_reviews, feasibility_reviews, auditability_reviews)) in reviews
{
Expand All @@ -40,19 +42,24 @@ impl ProposalScore {
&aligment_reviews,
&feasibility_reviews,
&auditability_reviews,
)
.unwrap();
)?;

catalyst_toolbox::proposal_score::store::store_scores_in_sqllite_db(
&self.db_path,
proposal_id,
let proposal = proposals.get_mut(&proposal_id).ok_or_else(|| {
color_eyre::eyre::eyre!("Proposal with id {} not found", proposal_id.0)
})?;
catalyst_toolbox::proposal_score::store::store_score_into_proposal(
proposal,
aligment_score,
feasibility_score,
auditability_score,
)
.unwrap();
)?;
}

catalyst_toolbox::proposal_score::store::store_proposals_into_file(
&self.proposals_path,
proposals.into_values().collect(),
)?;

Ok(())
}
}
Expand All @@ -67,7 +74,7 @@ mod tests {
allocated_weight: 0.8,
not_allocated_weight: 0.2,
reviews_path: PathBuf::from("src/proposal_score/test_data/reviews-example.csv"),
db_path: PathBuf::from("src/proposal_score/test_data/fund9.sqlite3"),
proposals_path: PathBuf::from("src/proposal_score/test_data/proposals.json"),
};

proposal_score.exec().unwrap();
Expand Down
Loading

0 comments on commit 00f555c

Please sign in to comment.