Imagebuffer reads, time binning
This commit is contained in:
@@ -256,7 +256,7 @@ pub struct BinsDim0CollectedResult<NTY> {
|
||||
#[serde(rename = "avgs")]
|
||||
avgs: VecDeque<f32>,
|
||||
#[serde(rename = "rangeFinal", default, skip_serializing_if = "crate::bool_is_false")]
|
||||
finalised_range: bool,
|
||||
range_final: bool,
|
||||
#[serde(rename = "timedOut", default, skip_serializing_if = "crate::bool_is_false")]
|
||||
timed_out: bool,
|
||||
#[serde(rename = "missingBins", default, skip_serializing_if = "Zero::is_zero")]
|
||||
@@ -309,7 +309,7 @@ impl<NTY> BinsDim0CollectedResult<NTY> {
|
||||
}
|
||||
|
||||
pub fn range_final(&self) -> bool {
|
||||
self.finalised_range
|
||||
self.range_final
|
||||
}
|
||||
|
||||
pub fn missing_bins(&self) -> u32 {
|
||||
@@ -343,7 +343,7 @@ impl<NTY: ScalarOps> ToJsonResult for BinsDim0CollectedResult<NTY> {
|
||||
#[derive(Debug)]
|
||||
pub struct BinsDim0Collector<NTY> {
|
||||
timed_out: bool,
|
||||
range_complete: bool,
|
||||
range_final: bool,
|
||||
vals: BinsDim0<NTY>,
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ impl<NTY> BinsDim0Collector<NTY> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
timed_out: false,
|
||||
range_complete: false,
|
||||
range_final: false,
|
||||
vals: BinsDim0::<NTY>::empty(),
|
||||
}
|
||||
}
|
||||
@@ -379,7 +379,7 @@ impl<NTY: ScalarOps> CollectorType for BinsDim0Collector<NTY> {
|
||||
}
|
||||
|
||||
fn set_range_complete(&mut self) {
|
||||
self.range_complete = true;
|
||||
self.range_final = true;
|
||||
}
|
||||
|
||||
fn set_timed_out(&mut self) {
|
||||
@@ -393,16 +393,23 @@ impl<NTY: ScalarOps> CollectorType for BinsDim0Collector<NTY> {
|
||||
0
|
||||
};
|
||||
let bin_count = self.vals.ts1s.len() as u32;
|
||||
let (missing_bins, continue_at, finished_at) = if bin_count < bin_count_exp {
|
||||
match self.vals.ts2s.back() {
|
||||
Some(&k) => {
|
||||
let missing_bins = bin_count_exp - bin_count;
|
||||
let continue_at = IsoDateTime(Utc.timestamp_nanos(k as i64));
|
||||
let u = k + (k - self.vals.ts1s.back().unwrap()) * missing_bins as u64;
|
||||
let finished_at = IsoDateTime(Utc.timestamp_nanos(u as i64));
|
||||
(missing_bins, Some(continue_at), Some(finished_at))
|
||||
let (missing_bins, continue_at, finished_at) = if self.range_final {
|
||||
if bin_count < bin_count_exp {
|
||||
match self.vals.ts2s.back() {
|
||||
Some(&k) => {
|
||||
let missing_bins = bin_count_exp - bin_count;
|
||||
let continue_at = IsoDateTime(Utc.timestamp_nanos(k as i64));
|
||||
let u = k + (k - self.vals.ts1s.back().unwrap()) * missing_bins as u64;
|
||||
let finished_at = IsoDateTime(Utc.timestamp_nanos(u as i64));
|
||||
(missing_bins, Some(continue_at), Some(finished_at))
|
||||
}
|
||||
None => {
|
||||
warn!("can not determine continue-at parameters");
|
||||
(0, None, None)
|
||||
}
|
||||
}
|
||||
None => Err(Error::with_msg("partial_content but no bin in result"))?,
|
||||
} else {
|
||||
(0, None, None)
|
||||
}
|
||||
} else {
|
||||
(0, None, None)
|
||||
@@ -429,7 +436,7 @@ impl<NTY: ScalarOps> CollectorType for BinsDim0Collector<NTY> {
|
||||
mins,
|
||||
maxs,
|
||||
avgs,
|
||||
finalised_range: self.range_complete,
|
||||
range_final: self.range_final,
|
||||
timed_out: self.timed_out,
|
||||
missing_bins,
|
||||
continue_at,
|
||||
@@ -769,6 +776,11 @@ impl<NTY: ScalarOps> TimeBinner for BinsDim0TimeBinner<NTY> {
|
||||
}
|
||||
|
||||
fn set_range_complete(&mut self) {}
|
||||
|
||||
fn empty(&self) -> Box<dyn items_0::TimeBinned> {
|
||||
let ret = <BinsDim0Aggregator<NTY> as TimeBinnableTypeAggregator>::Output::empty();
|
||||
Box::new(ret)
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY: ScalarOps> TimeBinned for BinsDim0<NTY> {
|
||||
|
||||
@@ -261,7 +261,7 @@ pub struct BinsXbinDim0CollectedResult<NTY> {
|
||||
#[serde(rename = "avgs")]
|
||||
avgs: VecDeque<f32>,
|
||||
#[serde(rename = "rangeFinal", default, skip_serializing_if = "crate::bool_is_false")]
|
||||
finalised_range: bool,
|
||||
range_final: bool,
|
||||
#[serde(rename = "timedOut", default, skip_serializing_if = "crate::bool_is_false")]
|
||||
timed_out: bool,
|
||||
#[serde(rename = "missingBins", default, skip_serializing_if = "Zero::is_zero")]
|
||||
@@ -314,7 +314,7 @@ impl<NTY> BinsXbinDim0CollectedResult<NTY> {
|
||||
}
|
||||
|
||||
pub fn range_final(&self) -> bool {
|
||||
self.finalised_range
|
||||
self.range_final
|
||||
}
|
||||
|
||||
pub fn missing_bins(&self) -> u32 {
|
||||
@@ -344,7 +344,7 @@ impl<NTY: ScalarOps> ToJsonResult for BinsXbinDim0CollectedResult<NTY> {
|
||||
#[derive(Debug)]
|
||||
pub struct BinsXbinDim0Collector<NTY> {
|
||||
timed_out: bool,
|
||||
range_complete: bool,
|
||||
range_final: bool,
|
||||
vals: BinsXbinDim0<NTY>,
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ impl<NTY> BinsXbinDim0Collector<NTY> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
timed_out: false,
|
||||
range_complete: false,
|
||||
range_final: false,
|
||||
vals: BinsXbinDim0::<NTY>::empty(),
|
||||
}
|
||||
}
|
||||
@@ -380,7 +380,7 @@ impl<NTY: ScalarOps> CollectorType for BinsXbinDim0Collector<NTY> {
|
||||
}
|
||||
|
||||
fn set_range_complete(&mut self) {
|
||||
self.range_complete = true;
|
||||
self.range_final = true;
|
||||
}
|
||||
|
||||
fn set_timed_out(&mut self) {
|
||||
@@ -394,16 +394,23 @@ impl<NTY: ScalarOps> CollectorType for BinsXbinDim0Collector<NTY> {
|
||||
0
|
||||
};
|
||||
let bin_count = self.vals.ts1s.len() as u32;
|
||||
let (missing_bins, continue_at, finished_at) = if bin_count < bin_count_exp {
|
||||
match self.vals.ts2s.back() {
|
||||
Some(&k) => {
|
||||
let missing_bins = bin_count_exp - bin_count;
|
||||
let continue_at = IsoDateTime(Utc.timestamp_nanos(k as i64));
|
||||
let u = k + (k - self.vals.ts1s.back().unwrap()) * missing_bins as u64;
|
||||
let finished_at = IsoDateTime(Utc.timestamp_nanos(u as i64));
|
||||
(missing_bins, Some(continue_at), Some(finished_at))
|
||||
let (missing_bins, continue_at, finished_at) = if self.range_final {
|
||||
if bin_count < bin_count_exp {
|
||||
match self.vals.ts2s.back() {
|
||||
Some(&k) => {
|
||||
let missing_bins = bin_count_exp - bin_count;
|
||||
let continue_at = IsoDateTime(Utc.timestamp_nanos(k as i64));
|
||||
let u = k + (k - self.vals.ts1s.back().unwrap()) * missing_bins as u64;
|
||||
let finished_at = IsoDateTime(Utc.timestamp_nanos(u as i64));
|
||||
(missing_bins, Some(continue_at), Some(finished_at))
|
||||
}
|
||||
None => {
|
||||
warn!("can not determine continue-at parameters");
|
||||
(0, None, None)
|
||||
}
|
||||
}
|
||||
None => Err(Error::with_msg("partial_content but no bin in result"))?,
|
||||
} else {
|
||||
(0, None, None)
|
||||
}
|
||||
} else {
|
||||
(0, None, None)
|
||||
@@ -430,7 +437,7 @@ impl<NTY: ScalarOps> CollectorType for BinsXbinDim0Collector<NTY> {
|
||||
mins,
|
||||
maxs,
|
||||
avgs,
|
||||
finalised_range: self.range_complete,
|
||||
range_final: self.range_final,
|
||||
timed_out: self.timed_out,
|
||||
missing_bins,
|
||||
continue_at,
|
||||
@@ -770,6 +777,11 @@ impl<NTY: ScalarOps> TimeBinner for BinsXbinDim0TimeBinner<NTY> {
|
||||
}
|
||||
|
||||
fn set_range_complete(&mut self) {}
|
||||
|
||||
fn empty(&self) -> Box<dyn items_0::TimeBinned> {
|
||||
let ret = <BinsXbinDim0Aggregator<NTY> as TimeBinnableTypeAggregator>::Output::empty();
|
||||
Box::new(ret)
|
||||
}
|
||||
}
|
||||
|
||||
impl<NTY: ScalarOps> TimeBinned for BinsXbinDim0<NTY> {
|
||||
|
||||
@@ -576,6 +576,13 @@ impl crate::timebin::TimeBinner for ChannelEventsTimeBinner {
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn empty(&self) -> Option<Self::Output> {
|
||||
match self.binner.as_ref() {
|
||||
Some(binner) => Some(binner.empty()),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::timebin::TimeBinnable for ChannelEvents {
|
||||
|
||||
@@ -13,6 +13,12 @@ use std::any::Any;
|
||||
use std::collections::VecDeque;
|
||||
use std::{fmt, mem};
|
||||
|
||||
#[allow(unused)]
|
||||
macro_rules! trace2 {
|
||||
(EN$($arg:tt)*) => ();
|
||||
($($arg:tt)*) => (trace!($($arg)*));
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct EventsDim0<NTY> {
|
||||
pub tss: VecDeque<u64>,
|
||||
@@ -286,10 +292,7 @@ impl<NTY: ScalarOps> items_0::collect_s::CollectorType for EventsDim0Collector<N
|
||||
if let Some(range) = &range {
|
||||
Some(IsoDateTime::from_u64(range.beg + netpod::timeunits::SEC))
|
||||
} else {
|
||||
// TODO tricky: should yield again the original range begin? Leads to recursion.
|
||||
// Range begin plus delta?
|
||||
// Anyway, we don't have the range begin here.
|
||||
warn!("timed out without any result, can not yield a continue-at");
|
||||
warn!("can not determine continue-at parameters");
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -820,13 +823,11 @@ impl<NTY: ScalarOps> TimeBinner for EventsDim0TimeBinner<NTY> {
|
||||
|
||||
fn ingest(&mut self, item: &dyn TimeBinnable) {
|
||||
let self_name = std::any::type_name::<Self>();
|
||||
if true {
|
||||
trace!(
|
||||
"TimeBinner for EventsDim0TimeBinner {:?}\n{:?}\n------------------------------------",
|
||||
self.edges.iter().take(2).collect::<Vec<_>>(),
|
||||
item
|
||||
);
|
||||
}
|
||||
trace2!(
|
||||
"TimeBinner for EventsDim0TimeBinner {:?}\n{:?}\n------------------------------------",
|
||||
self.edges.iter().take(2).collect::<Vec<_>>(),
|
||||
item
|
||||
);
|
||||
if item.len() == 0 {
|
||||
// Return already here, RangeOverlapInfo would not give much sense.
|
||||
return;
|
||||
@@ -949,6 +950,11 @@ impl<NTY: ScalarOps> TimeBinner for EventsDim0TimeBinner<NTY> {
|
||||
fn set_range_complete(&mut self) {
|
||||
self.range_complete = true;
|
||||
}
|
||||
|
||||
fn empty(&self) -> Box<dyn items_0::TimeBinned> {
|
||||
let ret = <EventsDim0Aggregator<NTY> as TimeBinnableTypeAggregator>::Output::empty();
|
||||
Box::new(ret)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO remove this struct?
|
||||
|
||||
@@ -451,10 +451,7 @@ where
|
||||
if let Some(range) = &range {
|
||||
Some(IsoDateTime::from_u64(range.beg + netpod::timeunits::SEC))
|
||||
} else {
|
||||
// TODO tricky: should yield again the original range begin? Leads to recursion.
|
||||
// Range begin plus delta?
|
||||
// Anyway, we don't have the range begin here.
|
||||
warn!("timed out without any result, can not yield a continue-at");
|
||||
warn!("can not determine continue-at parameters");
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ impl crate::merger::Mergeable for Box<dyn Events> {
|
||||
}
|
||||
|
||||
// TODO rename to `Typed`
|
||||
pub trait TimeBinnableType: Send + Unpin + RangeOverlapInfo {
|
||||
pub trait TimeBinnableType: Send + Unpin + RangeOverlapInfo + Empty {
|
||||
type Output: TimeBinnableType;
|
||||
type Aggregator: TimeBinnableTypeAggregator<Input = Self, Output = Self::Output> + Send + Unpin;
|
||||
fn aggregator(range: NanoRange, bin_count: usize, do_time_weight: bool) -> Self::Aggregator;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::fmt;
|
||||
|
||||
pub trait TimeBinner: fmt::Debug + Unpin {
|
||||
type Input;
|
||||
type Output;
|
||||
type Input: fmt::Debug;
|
||||
type Output: fmt::Debug;
|
||||
|
||||
fn ingest(&mut self, item: &mut Self::Input);
|
||||
|
||||
@@ -20,6 +20,8 @@ pub trait TimeBinner: fmt::Debug + Unpin {
|
||||
/// to `push_in_progress` did not change the result count, as long as edges are left.
|
||||
/// The next call to `Self::bins_ready_count` must return one higher count than before.
|
||||
fn cycle(&mut self);
|
||||
|
||||
fn empty(&self) -> Option<Self::Output>;
|
||||
}
|
||||
|
||||
pub trait TimeBinnable: fmt::Debug + Sized {
|
||||
|
||||
Reference in New Issue
Block a user