Skip to content

Commit

Permalink
Fix total bug (#105)
Browse files Browse the repository at this point in the history
* extra + total

* mb
  • Loading branch information
sergey-shandar authored Oct 18, 2023
1 parent 42e434f commit 389cf2e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ fn add<'a, T: Io, S: 'a + Storage>(
Ok(())
}

fn calculate_total(io: &impl Io, d: &str, mut total: u64) -> io::Result<u64> {
fn calculate_total(io: &impl Io, d: &str, extra: u64) -> io::Result<u64> {
let stdout = &mut io.stdout();
let a = io.read_dir(&("cdt0/".to_owned() + d))?;
let an = a.len() as u64;
let mut total = 0;
let state = &mut State::new(stdout);
for (ai, ia) in a.iter().enumerate() {
let b = io.read_dir(&ia.path())?;
Expand All @@ -97,16 +98,16 @@ fn calculate_total(io: &impl Io, d: &str, mut total: u64) -> io::Result<u64> {
total += d;
}
let p = (bn * ai as u64 + bi as u64) as f64 / (an * bn) as f64;
let e = (total as f64) / p;
let e = (extra + total) as f64 / p;
let s = "size: ~".to_string()
+ &mb(e as u64)
+ &mb(extra + e as u64)
+ ". "
+ &((p * 100.0) as u64).to_string()
+ "%.";
state.set(&s)?;
}
}
Ok(total)
Ok(extra + total)
}

pub fn run(io: &impl Io) -> Result<(), String> {
Expand Down

0 comments on commit 389cf2e

Please sign in to comment.