Skip to content

Commit

Permalink
possibly working impl of getting the throughput + reconcile
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 9, 2020
1 parent a1af8fc commit 74315bf
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/tree/throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ struct State {
}

impl State {
fn new(value: progress::Step) -> Self {
fn new(value: progress::Step, elapsed: Duration) -> Self {
State {
desired: Duration::from_secs(1),
observed: Default::default(),
aggregate_value_for_observed_duration: 0,
observed: elapsed,
aggregate_value_for_observed_duration: value,
last_value: value,
}
}
fn update(&mut self, value: progress::Step, elapsed: Duration) -> Option<unit::display::Throughput> {
self.throughput()
}

fn throughput(&self) -> Option<unit::display::Throughput> {
None
}
}

#[derive(Default)]
Expand All @@ -32,7 +39,18 @@ impl Throughput {
value: &progress::Value,
elapsed: Duration,
) -> Option<unit::display::Throughput> {
unimplemented!("update and get")
value
.progress
.as_ref()
.and_then(|progress| match self.sorted_by_key.binary_search_by_key(key, |t| t.0) {
Ok(index) => self.sorted_by_key[index].1.update(progress.step, elapsed),
Err(index) => {
let state = State::new(progress.step, elapsed);
let tp = state.throughput();
self.sorted_by_key.insert(index, (*key, state));
tp
}
})
}
pub fn reconcile(&mut self, values: &[(tree::Key, progress::Value)]) {
unimplemented!("reconcile")
Expand Down

0 comments on commit 74315bf

Please sign in to comment.