|
| 1 | +use catalyst_toolbox::stats::distribution::Stats; |
| 2 | +use catalyst_toolbox::stats::voters::calculate_active_wallet_distribution; |
| 3 | +use std::ops::Range; |
| 4 | +use std::path::PathBuf; |
| 5 | +use structopt::StructOpt; |
| 6 | + |
| 7 | +#[derive(StructOpt, Debug)] |
| 8 | +pub struct ActiveVotersCommand { |
| 9 | + #[structopt(long = "support-lovelace")] |
| 10 | + pub support_lovelace: bool, |
| 11 | + #[structopt(long = "block0")] |
| 12 | + pub block0: String, |
| 13 | + #[structopt(long = "threshold")] |
| 14 | + pub threshold: u64, |
| 15 | + #[structopt(long = "votes-count-file")] |
| 16 | + pub votes_count_path: PathBuf, |
| 17 | + #[structopt(subcommand)] |
| 18 | + pub command: Command, |
| 19 | +} |
| 20 | + |
| 21 | +#[derive(StructOpt, Debug)] |
| 22 | +pub enum Command { |
| 23 | + Count, |
| 24 | + Ada, |
| 25 | + Votes, |
| 26 | +} |
| 27 | + |
| 28 | +impl ActiveVotersCommand { |
| 29 | + pub fn exec(&self) -> Result<(), catalyst_toolbox::stats::Error> { |
| 30 | + match self.command { |
| 31 | + Command::Count => calculate_active_wallet_distribution( |
| 32 | + Stats::new(self.threshold), |
| 33 | + &self.block0, |
| 34 | + &self.votes_count_path, |
| 35 | + self.support_lovelace, |
| 36 | + |stats, value, _| stats.add(value), |
| 37 | + )? |
| 38 | + .print_count_per_level(), |
| 39 | + Command::Ada => calculate_active_wallet_distribution( |
| 40 | + Stats::new(self.threshold), |
| 41 | + &self.block0, |
| 42 | + &self.votes_count_path, |
| 43 | + self.support_lovelace, |
| 44 | + |stats, value, _| stats.add(value), |
| 45 | + )? |
| 46 | + .print_ada_per_level(), |
| 47 | + Command::Votes => calculate_active_wallet_distribution( |
| 48 | + Stats::new_with_levels(casted_votes_levels()), |
| 49 | + &self.block0, |
| 50 | + &self.votes_count_path, |
| 51 | + self.support_lovelace, |
| 52 | + |stats, _, weight| stats.add_with_weight(1, weight as u32), |
| 53 | + )? |
| 54 | + .print_count_per_level(), |
| 55 | + }; |
| 56 | + |
| 57 | + Ok(()) |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +fn casted_votes_levels() -> Vec<Range<u64>> { |
| 62 | + vec![ |
| 63 | + (1..5), |
| 64 | + (5..10), |
| 65 | + (10..20), |
| 66 | + (20..50), |
| 67 | + (50..100), |
| 68 | + (100..200), |
| 69 | + (200..400), |
| 70 | + (400..800), |
| 71 | + (800..5_000), |
| 72 | + ] |
| 73 | +} |
0 commit comments