This commit is contained in:
Dominik Werder
2021-05-14 10:30:54 +02:00
parent 70426e8e48
commit 8dc80f5dba
12 changed files with 159 additions and 47 deletions

View File

@@ -96,6 +96,8 @@ where
fn cur(&mut self, cx: &mut Context) -> Poll<Option<Result<I, Error>>> {
if let Some(cur) = self.left.take() {
cur
} else if self.inp_completed {
Poll::Ready(None)
} else {
let inp_poll_span = span!(Level::TRACE, "into_t_inp_poll");
inp_poll_span.in_scope(|| self.inp.poll_next_unpin(cx))
@@ -182,7 +184,6 @@ where
Some(Ready(Some(Err(e))))
}
Ready(None) => {
// No more input, no more in leftover.
self.inp_completed = true;
if self.all_bins_emitted {
None
@@ -239,9 +240,6 @@ where
continue 'outer;
}
} else {
// TODO make sure that we don't poll our input here after it has completed.
err::todo();
let cur = self.cur(cx);
match self.handle(cur) {
Some(item) => item,

View File

@@ -178,6 +178,7 @@ pub struct MinMaxAvgScalarEventBatchAggregator {
min: f32,
max: f32,
sum: f32,
sumc: u64,
}
impl MinMaxAvgScalarEventBatchAggregator {
@@ -185,10 +186,11 @@ impl MinMaxAvgScalarEventBatchAggregator {
Self {
ts1,
ts2,
count: 0,
min: f32::MAX,
max: f32::MIN,
sum: 0f32,
count: 0,
sum: f32::NAN,
sumc: 0,
}
}
}
@@ -226,10 +228,19 @@ impl AggregatorTdim for MinMaxAvgScalarEventBatchAggregator {
} else if ts >= self.ts2 {
continue;
} else {
self.count += 1;
self.min = self.min.min(v.mins[i1]);
self.max = self.max.max(v.maxs[i1]);
self.sum += v.avgs[i1];
self.count += 1;
let x = v.avgs[i1];
if x.is_nan() {
} else {
if self.sum.is_nan() {
self.sum = x;
} else {
self.sum += x;
}
self.sumc += 1;
}
}
}
}
@@ -237,10 +248,10 @@ impl AggregatorTdim for MinMaxAvgScalarEventBatchAggregator {
fn result(self) -> Vec<Self::OutputValue> {
let min = if self.min == f32::MAX { f32::NAN } else { self.min };
let max = if self.max == f32::MIN { f32::NAN } else { self.max };
let avg = if self.count == 0 {
let avg = if self.sumc == 0 {
f32::NAN
} else {
self.sum / self.count as f32
self.sum / self.sumc as f32
};
let v = MinMaxAvgScalarBinBatch {
ts1s: vec![self.ts1],

View File

@@ -116,11 +116,13 @@ impl std::fmt::Debug for MinMaxAvgScalarBinBatch {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
fmt,
"MinMaxAvgScalarBinBatch count {} ts1s {:?} ts2s {:?} counts {:?} avgs {:?}",
"MinMaxAvgScalarBinBatch count {} ts1s {:?} ts2s {:?} counts {:?} mins {:?} maxs {:?} avgs {:?}",
self.ts1s.len(),
self.ts1s.iter().map(|k| k / SEC).collect::<Vec<_>>(),
self.ts2s.iter().map(|k| k / SEC).collect::<Vec<_>>(),
self.counts,
self.mins,
self.maxs,
self.avgs,
)
}
@@ -289,8 +291,16 @@ impl AggregatorTdim for MinMaxAvgScalarBinBatchAggregator {
self.count += v.counts[i1];
self.min = self.min.min(v.mins[i1]);
self.max = self.max.max(v.maxs[i1]);
self.sum += v.avgs[i1];
self.sumc += 1;
let x = v.avgs[i1];
if x.is_nan() {
} else {
if self.sum.is_nan() {
self.sum = x;
} else {
self.sum += x;
}
self.sumc += 1;
}
}
}
}