Skip to content

Commit

Permalink
First working example for throughput, but…
Browse files Browse the repository at this point in the history
It's way too instable due to timing differences. Ideally it will be able
to produce values much closer to what they really are.

Maybe just an issue with big numbers.
  • Loading branch information
Byron committed Aug 9, 2020
1 parent e2ffb04 commit 0ceebd4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions examples/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,24 @@ fn work_for_a_long_time_blocking(root: Tree) {
)),
);

fn formatter() -> unit::human::Formatter {
fn formatter(decimals: usize) -> unit::human::Formatter {
let mut f = unit::human::Formatter::new();
f.with_decimals(0);
f.with_decimals(decimals);
f
}
let mut human_count = root.add_child("item count unknown");
human_count.init(
None,
Some(unit::dynamic_and_mode(
unit::Human::new(formatter(), "items"),
unit::Human::new(formatter(0), "items"),
unit::display::Mode::with_throughput(),
)),
);
let mut human_count_max = root.add_child("item count");
human_count_max.init(
Some(7_542_241),
Some(unit::dynamic_and_mode(
unit::Human::new(formatter(), "items"),
unit::Human::new(formatter(2), "items"),
unit::display::Mode::with_percentage().and_throughput(),
)),
);
Expand Down
7 changes: 6 additions & 1 deletion src/tree/throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ impl State {
}
}
fn update(&mut self, value: progress::Step, elapsed: Duration) -> Option<unit::display::Throughput> {
self.aggregate_value_for_observed_duration += value.checked_sub(self.last_value).unwrap_or(0);
self.observed += elapsed;
self.last_value = value;
self.throughput()
}

fn throughput(&self) -> Option<unit::display::Throughput> {
Some(unit::display::Throughput {
value_change_in_timespan: self.aggregate_value_for_observed_duration,
value_change_in_timespan: ((self.aggregate_value_for_observed_duration as f64
/ self.observed.as_secs_f64())
* self.desired.as_secs_f64()) as progress::Step,
timespan: self.desired,
})
}
Expand Down

0 comments on commit 0ceebd4

Please sign in to comment.