-
Notifications
You must be signed in to change notification settings - Fork 15
/
veterans.rs
85 lines (74 loc) · 2.28 KB
/
veterans.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use super::Error;
use catalyst_toolbox::community_advisors::models::VeteranRankingRow;
use catalyst_toolbox::rewards::veterans::{self, VcaRewards, VeteranAdvisorIncentive};
use catalyst_toolbox::rewards::Rewards;
use catalyst_toolbox::utils::csv;
use serde::Serialize;
use std::path::PathBuf;
use structopt::StructOpt;
#[derive(StructOpt)]
#[structopt(rename_all = "kebab-case")]
pub struct VeteransRewards {
/// Reviews csv file path
from: PathBuf,
/// Results file output path
to: PathBuf,
/// Reward to be distributed
#[structopt(long = "total-rewards")]
total_rewards: Rewards,
/// Minimum number of rankings for each vca to be considered for reputatin and rewards
/// distribution
#[structopt(long)]
min_rankings: usize,
/// Cutoff for monetary rewards: ranking more reviews than this limit will not result in more rewards
#[structopt(long)]
max_rankings_rewards: usize,
/// Cutoff for reputation: ranking more reviews than this limit will not result in more reputation awarded
#[structopt(long)]
max_rankings_reputation: usize,
}
impl VeteransRewards {
pub fn exec(self) -> Result<(), Error> {
let Self {
from,
to,
total_rewards,
min_rankings,
max_rankings_reputation,
max_rankings_rewards,
} = self;
let reviews: Vec<VeteranRankingRow> = csv::load_data_from_csv::<_, b','>(&from)?;
let results = veterans::calculate_veteran_advisors_incentives(
&reviews,
total_rewards,
min_rankings..=max_rankings_rewards,
min_rankings..=max_rankings_reputation,
);
csv::dump_data_to_csv(&rewards_to_csv_data(results), &to).unwrap();
Ok(())
}
}
fn rewards_to_csv_data(rewards: VcaRewards) -> Vec<impl Serialize> {
#[derive(Serialize)]
struct Entry {
id: String,
rewards: Rewards,
reputation: u64,
}
rewards
.into_iter()
.map(
|(
id,
VeteranAdvisorIncentive {
rewards,
reputation,
},
)| Entry {
id,
rewards,
reputation,
},
)
.collect()
}