WIP
This commit is contained in:
@@ -16,19 +16,28 @@ use std::task::Poll;
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
macro_rules! trace_init { ($($arg:tt)*) => ( if true { trace!($($arg)*); }) }
|
macro_rules! trace_init { ($($arg:tt)*) => ( if true { trace!($($arg)*); }) }
|
||||||
|
|
||||||
|
const DEBUG_CHECKS: bool = true;
|
||||||
|
|
||||||
#[derive(Debug, ThisError)]
|
#[derive(Debug, ThisError)]
|
||||||
#[cstm(name = "BinnedEventsTimeweight")]
|
#[cstm(name = "BinnedEventsTimeweight")]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
BadContainer(#[from] super::super::container_events::EventsContainerError),
|
BadContainer(#[from] super::super::container_events::EventsContainerError),
|
||||||
Unordered,
|
Unordered,
|
||||||
AnotherBeforeRange,
|
|
||||||
NoLstAfterFirst,
|
NoLstAfterFirst,
|
||||||
EmptyContainerInnerHandler,
|
EmptyContainerInnerHandler,
|
||||||
NoLstButMinMax,
|
NoLstButMinMax,
|
||||||
|
WithLstButEventBeforeRange,
|
||||||
|
WithMinMaxButEventBeforeRange,
|
||||||
|
NoMinMaxAfterInit,
|
||||||
|
ExpectEventInInnerVolumeRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
type MinMax<EVT> = (EventSingle<EVT>, EventSingle<EVT>);
|
type MinMax<EVT> = (EventSingle<EVT>, EventSingle<EVT>);
|
||||||
|
|
||||||
|
struct LstRef<'a, EVT>(&'a EventSingle<EVT>);
|
||||||
|
|
||||||
|
struct LstMut<'a, EVT>(&'a mut EventSingle<EVT>);
|
||||||
|
|
||||||
struct InnerB<EVT> {
|
struct InnerB<EVT> {
|
||||||
range: BinnedRange<TsNano>,
|
range: BinnedRange<TsNano>,
|
||||||
cnt: u64,
|
cnt: u64,
|
||||||
@@ -39,11 +48,17 @@ impl<EVT> InnerB<EVT>
|
|||||||
where
|
where
|
||||||
EVT: EventValueType,
|
EVT: EventValueType,
|
||||||
{
|
{
|
||||||
fn ingest_event_with_lst_in_range(
|
fn ingest_event_with_lst_gt_range_beg(
|
||||||
&mut self,
|
&mut self,
|
||||||
ev: EventSingle<EVT>,
|
ev: EventSingle<EVT>,
|
||||||
lst: &mut EventSingle<EVT>,
|
lst: LstMut<EVT>,
|
||||||
|
minmax: &mut MinMax<EVT>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
if DEBUG_CHECKS {
|
||||||
|
if ev.ts <= self.range.nano_beg() {
|
||||||
|
return Err(Error::ExpectEventInInnerVolumeRange);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Aggregator:
|
// Aggregator:
|
||||||
// Must handle min, max, avg, var.
|
// Must handle min, max, avg, var.
|
||||||
// min and max is actually tricky and can not be done in one go with lst:
|
// min and max is actually tricky and can not be done in one go with lst:
|
||||||
@@ -86,6 +101,7 @@ where
|
|||||||
&mut self,
|
&mut self,
|
||||||
mut evs: ContainerEvents<EVT>,
|
mut evs: ContainerEvents<EVT>,
|
||||||
lst: &mut EventSingle<EVT>,
|
lst: &mut EventSingle<EVT>,
|
||||||
|
minmax: &mut MinMax<EVT>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
while let Some(ev) = evs.event_next() {
|
while let Some(ev) = evs.event_next() {
|
||||||
if true {
|
if true {
|
||||||
@@ -110,7 +126,7 @@ where
|
|||||||
// If the event is after the current bin first edge, then min/max is initialized from the lst
|
// If the event is after the current bin first edge, then min/max is initialized from the lst
|
||||||
// and there is a contribution from the lst to the avg.
|
// and there is a contribution from the lst to the avg.
|
||||||
|
|
||||||
self.ingest_event_with_lst_in_range(ev, lst)?;
|
self.ingest_event_with_lst_gt_range_beg(ev, LstMut(lst), minmax)?;
|
||||||
|
|
||||||
// TODO update the lst (needs clone?)
|
// TODO update the lst (needs clone?)
|
||||||
}
|
}
|
||||||
@@ -126,10 +142,14 @@ where
|
|||||||
// TODO how to handle the min max? I don't take event data yet out of the container.
|
// TODO how to handle the min max? I don't take event data yet out of the container.
|
||||||
todo!("minmax handle");
|
todo!("minmax handle");
|
||||||
if let Some(ts0) = evs.ts_first() {
|
if let Some(ts0) = evs.ts_first() {
|
||||||
if ts0 < self.range.nano_beg() {
|
let range = &self.range;
|
||||||
Err(Error::AnotherBeforeRange)
|
let beg = range.nano_beg();
|
||||||
|
let end = range.nano_end();
|
||||||
|
if ts0 < beg {
|
||||||
|
Err(Error::WithMinMaxButEventBeforeRange)
|
||||||
} else {
|
} else {
|
||||||
self.ingest_with_lst_ge_range_beg(evs, lst)
|
todo!();
|
||||||
|
self.ingest_with_lst_ge_range_beg(evs, lst, minmax)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(Error::EmptyContainerInnerHandler)
|
Err(Error::EmptyContainerInnerHandler)
|
||||||
@@ -146,35 +166,58 @@ impl<EVT> InnerA<EVT>
|
|||||||
where
|
where
|
||||||
EVT: EventValueType,
|
EVT: EventValueType,
|
||||||
{
|
{
|
||||||
fn ingest_with_lst_nominmax(
|
fn apply_min_max(ev: &EventSingle<EVT>, minmax: &mut MinMax<EVT>) {
|
||||||
&mut self,
|
if ev.val < minmax.0.val {
|
||||||
evs: ContainerEvents<EVT>,
|
minmax.0 = ev.clone();
|
||||||
lst: &mut EventSingle<EVT>,
|
}
|
||||||
minmax: &mut Option<MinMax<EVT>>,
|
if ev.val > minmax.1.val {
|
||||||
) -> Result<(), Error> {
|
minmax.1 = ev.clone();
|
||||||
// TODO how to handle the min max? I don't take event data yet out of the container.
|
|
||||||
todo!("minmax handle");
|
|
||||||
if let Some(ts0) = evs.ts_first() {
|
|
||||||
if ts0 < self.inner_b.range.nano_beg() {
|
|
||||||
Err(Error::AnotherBeforeRange)
|
|
||||||
} else {
|
|
||||||
self.inner_b.ingest_with_lst_ge_range_beg(evs, lst)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Err(Error::EmptyContainerInnerHandler)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ingest_with_lst(&mut self, evs: ContainerEvents<EVT>, lst: &mut EventSingle<EVT>) -> Result<(), Error> {
|
fn init_minmax(&mut self, ev: &EventSingle<EVT>) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init_minmax_with_lst(&mut self, ev: &EventSingle<EVT>, lst: LstRef<EVT>) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ingest_with_lst(&mut self, mut evs: ContainerEvents<EVT>, lst: &mut EventSingle<EVT>) -> Result<(), Error> {
|
||||||
if let Some(minmax) = self.minmax.as_mut() {
|
if let Some(minmax) = self.minmax.as_mut() {
|
||||||
// TODO
|
self.inner_b.ingest_with_lst_minmax(evs, lst, minmax)
|
||||||
// Maybe?
|
|
||||||
self.inner_b.ingest_with_lst_minmax(evs, lst, minmax)?;
|
|
||||||
todo!()
|
|
||||||
} else {
|
} else {
|
||||||
// self.ingest_with_lst_without_minmax(evs, lst)
|
if let Some(ev) = evs.event_next() {
|
||||||
// TODO we have lst, so expect that this next event gives us minmax.
|
let range = &self.inner_b.range;
|
||||||
todo!()
|
let beg = range.nano_beg();
|
||||||
|
let end = range.nano_end();
|
||||||
|
if ev.ts >= end {
|
||||||
|
// need to cycle, then apply the event again...
|
||||||
|
// TODO write that retry as a loop with iter limit.
|
||||||
|
todo!("cycle and reapply");
|
||||||
|
} else {
|
||||||
|
if DEBUG_CHECKS && ev.ts < beg {
|
||||||
|
return Err(Error::WithLstButEventBeforeRange);
|
||||||
|
} else if ev.ts == beg {
|
||||||
|
self.init_minmax(&ev);
|
||||||
|
todo!("this stops handling of event, but must apply to lst");
|
||||||
|
} else {
|
||||||
|
self.init_minmax_with_lst(&ev, LstRef(lst));
|
||||||
|
if let Some(minmax) = self.minmax.as_mut() {
|
||||||
|
// todo!("apply here also the event aggregation with everything except lst, min, max");
|
||||||
|
self.inner_b
|
||||||
|
.ingest_event_with_lst_gt_range_beg(ev, LstMut(lst), minmax)?;
|
||||||
|
todo!("this stops handling of event, but must apply to lst");
|
||||||
|
todo!("is this correct? we did already init minmax. calling this, it would get applied again?");
|
||||||
|
self.inner_b.ingest_with_lst_minmax(evs, lst, minmax)
|
||||||
|
} else {
|
||||||
|
Err(Error::NoMinMaxAfterInit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,15 +248,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_min_max(ev: &EventSingle<EVT>, minmax: &mut MinMax<EVT>) {
|
|
||||||
if ev.val < minmax.0.val {
|
|
||||||
minmax.0 = ev.clone();
|
|
||||||
}
|
|
||||||
if ev.val > minmax.1.val {
|
|
||||||
minmax.1 = ev.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ingest_event_without_lst(&mut self, ev: EventSingle<EVT>) -> Result<(), Error> {
|
fn ingest_event_without_lst(&mut self, ev: EventSingle<EVT>) -> Result<(), Error> {
|
||||||
let range = &self.inner_a.inner_b.range;
|
let range = &self.inner_a.inner_b.range;
|
||||||
let beg = range.nano_beg();
|
let beg = range.nano_beg();
|
||||||
@@ -230,24 +264,6 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _________ingest_with_lst_without_minmax(
|
|
||||||
&mut self,
|
|
||||||
mut evs: ContainerEvents<EVT>,
|
|
||||||
lst: &mut EventSingle<EVT>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
if let Some(ev) = evs.event_next() {
|
|
||||||
if ev.ts >= self.inner_a.inner_b.range.nano_end() {
|
|
||||||
// need to cycle, then apply the event again...
|
|
||||||
todo!("cycle and reapply");
|
|
||||||
} else {
|
|
||||||
// self.ingest_event_with_lst_without_minmax(ev, lst)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ingest_without_lst(&mut self, mut evs: ContainerEvents<EVT>) -> Result<(), Error> {
|
fn ingest_without_lst(&mut self, mut evs: ContainerEvents<EVT>) -> Result<(), Error> {
|
||||||
if let Some(ev) = evs.event_next() {
|
if let Some(ev) = evs.event_next() {
|
||||||
if ev.ts >= self.inner_a.inner_b.range.nano_end() {
|
if ev.ts >= self.inner_a.inner_b.range.nano_end() {
|
||||||
|
|||||||
Reference in New Issue
Block a user