Skip to content

Commit 6821f96

Browse files
committed
round up instead of truncate in perc. of contribution
1 parent 1bfd60a commit 6821f96

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/onefetch/repo.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ impl<'a> Repo<'a> {
5353
pub fn get_authors(&self, n: usize) -> Vec<(String, usize, usize)> {
5454
let mut authors = std::collections::HashMap::new();
5555
let mut author_name_by_email = std::collections::HashMap::new();
56-
let mut total_commits = 0;
56+
let mut total_nbr_of_commits = 0;
5757
for commit in &self.logs {
5858
let author = commit.author();
5959
let author_name = String::from_utf8_lossy(author.name_bytes()).into_owned();
6060
let author_email = String::from_utf8_lossy(author.email_bytes()).into_owned();
6161

62-
let commit_count = authors.entry(author_email.to_string()).or_insert(0);
62+
let author_nbr_of_commits = authors.entry(author_email.to_string()).or_insert(0);
6363
author_name_by_email.entry(author_email.to_string()).or_insert(author_name);
64-
*commit_count += 1;
65-
total_commits += 1;
64+
*author_nbr_of_commits += 1;
65+
total_nbr_of_commits += 1;
6666
}
6767

6868
let mut authors: Vec<(String, usize)> = authors.into_iter().collect();
@@ -72,11 +72,12 @@ impl<'a> Repo<'a> {
7272

7373
let authors: Vec<(String, usize, usize)> = authors
7474
.into_iter()
75-
.map(|(author, count)| {
75+
.map(|(author_email, author_nbr_of_commits)| {
7676
(
77-
author_name_by_email.get(&author).unwrap().trim_matches('\'').to_string(),
78-
count,
79-
count * 100 / total_commits,
77+
author_name_by_email.get(&author_email).unwrap().trim_matches('\'').to_string(),
78+
author_nbr_of_commits,
79+
(author_nbr_of_commits as f32 * 100. / total_nbr_of_commits as f32).round()
80+
as usize,
8081
)
8182
})
8283
.collect();

0 commit comments

Comments
 (0)