Improved binning by default

This commit is contained in:
Dominik Werder
2024-10-25 14:36:48 +02:00
parent b02b2a7add
commit d773c42808
13 changed files with 211 additions and 172 deletions
+12 -9
View File
@@ -9,6 +9,9 @@ use serde::Serialize;
#[allow(unused)]
macro_rules! trace_event { ($($arg:tt)*) => ( if false { trace!($($arg)*); }) }
#[allow(unused)]
macro_rules! trace_result { ($($arg:tt)*) => ( if false { trace!($($arg)*); }) }
pub trait AggTimeWeightOutputAvg: fmt::Debug + Clone + Send + Serialize + for<'a> Deserialize<'a> {}
impl AggTimeWeightOutputAvg for u8 {}
@@ -93,7 +96,7 @@ impl AggregatorTimeWeight<f32> for AggregatorNumeric {
fn result_and_reset_for_new_bin(&mut self, filled_width_fraction: f32) -> f32 {
let sum = self.sum.clone() as f32;
trace!("result_and_reset_for_new_bin sum {} {}", sum, filled_width_fraction);
trace_result!("result_and_reset_for_new_bin sum {} {}", sum, filled_width_fraction);
self.sum = 0.;
sum / filled_width_fraction
}
@@ -108,7 +111,7 @@ macro_rules! impl_agg_tw_for_agg_num {
fn ingest(&mut self, dt: DtNano, bl: DtNano, val: $evt) {
let f = dt.ns() as f64 / bl.ns() as f64;
trace!("INGEST {} {}", f, val);
trace_event!("INGEST {} {}", f, val);
self.sum += f * val as f64;
}
@@ -118,7 +121,7 @@ macro_rules! impl_agg_tw_for_agg_num {
fn result_and_reset_for_new_bin(&mut self, filled_width_fraction: f32) -> f64 {
let sum = self.sum.clone();
trace!(
trace_result!(
"result_and_reset_for_new_bin sum {} {}",
sum,
filled_width_fraction
@@ -145,7 +148,7 @@ impl AggregatorTimeWeight<u64> for AggregatorNumeric {
fn ingest(&mut self, dt: DtNano, bl: DtNano, val: u64) {
let f = dt.ns() as f64 / bl.ns() as f64;
trace!("INGEST {} {}", f, val);
trace_event!("INGEST {} {}", f, val);
self.sum += f * val as f64;
}
@@ -155,7 +158,7 @@ impl AggregatorTimeWeight<u64> for AggregatorNumeric {
fn result_and_reset_for_new_bin(&mut self, filled_width_fraction: f32) -> f64 {
let sum = self.sum.clone();
trace!("result_and_reset_for_new_bin sum {} {}", sum, filled_width_fraction);
trace_result!("result_and_reset_for_new_bin sum {} {}", sum, filled_width_fraction);
self.sum = 0.;
sum / filled_width_fraction as f64
}
@@ -168,7 +171,7 @@ impl AggregatorTimeWeight<bool> for AggregatorNumeric {
fn ingest(&mut self, dt: DtNano, bl: DtNano, val: bool) {
let f = dt.ns() as f64 / bl.ns() as f64;
trace!("INGEST {} {}", f, val);
trace_event!("INGEST {} {}", f, val);
self.sum += f * val as u8 as f64;
}
@@ -178,7 +181,7 @@ impl AggregatorTimeWeight<bool> for AggregatorNumeric {
fn result_and_reset_for_new_bin(&mut self, filled_width_fraction: f32) -> f64 {
let sum = self.sum.clone();
trace!("result_and_reset_for_new_bin sum {} {}", sum, filled_width_fraction);
trace_result!("result_and_reset_for_new_bin sum {} {}", sum, filled_width_fraction);
self.sum = 0.;
sum / filled_width_fraction as f64
}
@@ -191,7 +194,7 @@ impl AggregatorTimeWeight<String> for AggregatorNumeric {
fn ingest(&mut self, dt: DtNano, bl: DtNano, val: String) {
let f = dt.ns() as f64 / bl.ns() as f64;
trace!("INGEST {} {}", f, val);
trace_event!("INGEST {} {}", f, val);
self.sum += f * val.len() as f64;
}
@@ -201,7 +204,7 @@ impl AggregatorTimeWeight<String> for AggregatorNumeric {
fn result_and_reset_for_new_bin(&mut self, filled_width_fraction: f32) -> f64 {
let sum = self.sum.clone();
trace!("result_and_reset_for_new_bin sum {} {}", sum, filled_width_fraction);
trace_result!("result_and_reset_for_new_bin sum {} {}", sum, filled_width_fraction);
self.sum = 0.;
sum / filled_width_fraction as f64
}
@@ -42,7 +42,13 @@ macro_rules! trace_ingest_firsts { ($($arg:tt)*) => ( if true { trace_!($($arg)*
macro_rules! trace_ingest_finish_bin { ($($arg:tt)*) => ( if true { trace_!($($arg)*); }) }
#[allow(unused)]
macro_rules! trace_ingest_container { ($($arg:tt)*) => ( if true { trace_!($($arg)*); }) }
macro_rules! trace_ingest_container { ($($arg:tt)*) => ( if false { trace_!($($arg)*); }) }
#[allow(unused)]
macro_rules! trace_ingest_container_2 { ($($arg:tt)*) => ( if false { trace_!($($arg)*); }) }
#[allow(unused)]
macro_rules! trace_fill_until { ($($arg:tt)*) => ( if false { trace_!($($arg)*); }) }
#[cold]
#[inline]
@@ -197,7 +203,7 @@ where
} else {
self.ingest_event_with_lst_gt_range_beg(ev.clone(), LstMut(lst.0), minmax)?;
self.cnt += 1;
trace_ingest_firsts!("{selfname} now calling ingest_with_lst_gt_range_beg");
trace_ingest_event!("{selfname} now calling ingest_with_lst_gt_range_beg");
return self.ingest_with_lst_gt_range_beg(evs, LstMut(lst.0), minmax);
}
}
@@ -232,7 +238,7 @@ where
assert!(b.filled_until < ts);
assert!(ts <= b.active_end);
let dt = ts.delta(b.filled_until);
trace_cycle!("fill_until ts {:?} dt {:?} lst {:?}", ts, dt, lst.0);
trace_fill_until!("fill_until ts {:?} dt {:?} lst {:?}", ts, dt, lst.0);
assert!(b.filled_until < ts);
assert!(ts <= b.active_end);
b.agg.ingest(dt, b.active_len, lst.0.val.clone());
@@ -280,7 +286,7 @@ where
fn ingest_with_lst(&mut self, mut evs: ContainerEventsTakeUpTo<EVT>, lst: LstMut<EVT>) -> Result<(), Error> {
let selfname = "ingest_with_lst";
trace_ingest_container!("{selfname}");
trace_ingest_container!("{selfname} evs len {}", evs.len());
let b = &mut self.inner_b;
if let Some(minmax) = self.minmax.as_mut() {
b.ingest_with_lst_minmax(evs, lst, minmax)
@@ -587,7 +593,6 @@ where
return Err(Error::EventAfterRange);
}
if ts >= b.active_end {
trace_cycle!("bin edge boundary {:?}", b.active_end);
assert!(b.filled_until < b.active_end, "{} < {}", b.filled_until, b.active_end);
self.cycle_01(ts);
}
@@ -603,7 +608,7 @@ where
} else {
self.ingest_ordered(evs)?
};
trace_ingest_container!("ingest after still left len evs {}", evs_all.len());
trace_ingest_container_2!("ingest after still left len evs {}", evs_all.len());
let n2 = evs_all.len();
if n2 != 0 {
if n2 == n1 {