-
Notifications
You must be signed in to change notification settings - Fork 15
/
de.rs
97 lines (90 loc) · 3.18 KB
/
de.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
86
87
88
89
90
91
92
93
94
95
96
97
use crate::utils::serde::deserialize_truthy_falsy;
use serde::Deserialize;
#[derive(Deserialize)]
pub struct AdvisorReviewRow {
pub proposal_id: String,
#[serde(alias = "Idea URL")]
pub idea_url: String,
#[serde(alias = "Assessor")]
pub assessor: String,
#[serde(alias = "Impact / Alignment Note")]
pub impact_alignment_note: String,
#[serde(alias = "Impact / Alignment Rating")]
pub impact_alignment_rating: u8,
#[serde(alias = "Feasibility Note")]
pub feasibility_note: String,
#[serde(alias = "Feasibility Rating")]
pub feasibility_rating: u8,
#[serde(alias = "Auditability Note")]
pub auditability_note: String,
#[serde(alias = "Auditability Rating")]
pub auditability_rating: u8,
#[serde(alias = "Excellent", deserialize_with = "deserialize_truthy_falsy")]
excellent: bool,
#[serde(alias = "Good", deserialize_with = "deserialize_truthy_falsy")]
good: bool,
}
pub enum ReviewScore {
Excellent,
Good,
FilteredOut,
NA, // not reviewed by vCAs
}
impl AdvisorReviewRow {
pub fn score(&self) -> ReviewScore {
match (self.excellent, self.good) {
(true, false) => ReviewScore::Excellent,
(false, true) => ReviewScore::Good,
(false, false) => ReviewScore::NA,
_ => {
// This should never happen, from the source of information a review could be either
// Excellent or Good or not assessed. It cannot be both and it is considered
// a malformed information input.
panic!(
"Invalid combination of scores from assessor {} for proposal {}",
self.assessor, self.proposal_id
)
}
}
}
}
#[cfg(test)]
mod tests {
use super::ReviewScore;
use crate::community_advisors::models::AdvisorReviewRow;
use crate::utils::csv as csv_utils;
use rand::{distributions::Alphanumeric, Rng};
use std::path::PathBuf;
#[test]
fn test_deserialize() {
let file_path = PathBuf::from("./resources/testing/valid_assessments.csv");
let data: Vec<AdvisorReviewRow> =
csv_utils::load_data_from_csv::<_, b','>(&file_path).unwrap();
assert_eq!(data.len(), 1);
}
impl AdvisorReviewRow {
pub fn dummy(score: ReviewScore) -> Self {
let (excellent, good) = match score {
ReviewScore::Good => (false, true),
ReviewScore::Excellent => (true, false),
ReviewScore::NA => (false, false),
_ => unimplemented!(),
};
AdvisorReviewRow {
proposal_id: String::new(),
idea_url: String::new(),
assessor: (0..10)
.map(|_| rand::thread_rng().sample(Alphanumeric) as char)
.collect(),
impact_alignment_note: String::new(),
impact_alignment_rating: 0,
feasibility_note: String::new(),
feasibility_rating: 0,
auditability_note: String::new(),
auditability_rating: 0,
excellent,
good,
}
}
}
}