Skip to content

Commit

Permalink
Fix total curse values being wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
sondr3 committed May 12, 2020
1 parent 7db0b52 commit ac6e891
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ impl Repo {
/// Create a sorted `Vec` from a HashMap of curses, sorted by counts
fn sort(curses: &HashMap<String, usize>) -> Vec<(String, usize)> {
let mut curses: Vec<(&String, &usize)> = curses.iter().collect();
curses.sort_by(|a, b| a.1.cmp(b.1));
curses.reverse();
curses.sort_by(|(a, _), (b, _)| a.cmp(b));
let curses: Vec<_> = curses
.iter()
.map(|(c, i)| ((*c).to_string(), **i))
Expand Down Expand Up @@ -179,7 +178,7 @@ impl Repo {
out.push_str("0\t");
}
}
out.push_str(&curses.iter().map(|(_, c)| *c).sum::<usize>().to_string());
out.push_str(&author.curses.values().sum::<usize>().to_string());

writeln!(tw, "{}", out)?;
}
Expand All @@ -194,15 +193,14 @@ impl Repo {
curses: &[(String, usize)],
) -> Result<(), Box<dyn Error>> {
let mut out = String::new();
let total: usize = curses.iter().map(|(_, c)| c).sum();

out.push_str(&["Overall", "\t"].concat());

curses
.iter()
.for_each(|(_, count)| out.push_str(&[&count.to_string(), "\t"].concat()));

out.push_str(&total.to_string());
out.push_str(&self.total_curses.to_string());

writeln!(tw, "{}", out)?;

Expand Down

0 comments on commit ac6e891

Please sign in to comment.