Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update catalyst-toolbox proposal-score command | NPG-7776 #491

Merged
merged 4 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

4 changes: 2 additions & 2 deletions src/catalyst-toolbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ OPTIONS:

#### Proposals score calculation

Given a proposal's reviews .csv file (example in `catalyst-toolbox/src/proposal_score/test_data/reviews-example.csv`) calculates proposal's scores values and puts it into the given db sqlite file (example in `catalyst-toolbox/src/proposal_score/test_data/fund9.sqlite3`), particularly into `proposals` table, `proposal_files_url` column.
Given a proposal's reviews .csv file (example in `catalyst-toolbox/src/proposal_score/test_data/reviews-example.csv`) calculates proposal's scores values and updates the provided file (example in `catalyst-toolbox/src/proposal_score/test_data/proposals.json`) (which should already contain some information about proposals), particularly into `files_url` field, extended json encoded object with the new fields.
```shell
USAGE:
catalyst-toolbox proposal-score --allocated-weight <ALLOCATED_WEIGHT> --not-allocated-weight <NOT_ALLOCATED_WEIGHT> --reviews-path <REVIEWS_PATH> --db-path <DB_PATH>
catalyst-toolbox proposal-score --allocated-weight <ALLOCATED_WEIGHT> --not-allocated-weight <NOT_ALLOCATED_WEIGHT> --reviews-path <REVIEWS_PATH> --proposals-path <PROPOSALS_PATH>
```

## Python scripts
Expand Down
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
Loading