WIP
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
use crate::{ts_offs_from_abs, ts_offs_from_abs_with_anchor};
|
||||
use crate::{IsoDateTime, RangeOverlapInfo, ScalarOps};
|
||||
use crate::{IsoDateTime, RangeOverlapInfo};
|
||||
use crate::{TimeBinnable, TimeBinnableType, TimeBinnableTypeAggregator, TimeBinner};
|
||||
use chrono::{TimeZone, Utc};
|
||||
use err::Error;
|
||||
use items_0::collect_s::{Collectable, CollectableType, CollectorType, ToJsonResult};
|
||||
use items_0::scalar_ops::ScalarOps;
|
||||
use items_0::AppendEmptyBin;
|
||||
use items_0::Empty;
|
||||
use items_0::TimeBinned;
|
||||
@@ -74,8 +75,8 @@ impl<NTY: ScalarOps> BinsDim0<NTY> {
|
||||
self.ts1s.push_back(beg);
|
||||
self.ts2s.push_back(end);
|
||||
self.counts.push_back(0);
|
||||
self.mins.push_back(NTY::zero());
|
||||
self.maxs.push_back(NTY::zero());
|
||||
self.mins.push_back(NTY::zero_b());
|
||||
self.maxs.push_back(NTY::zero_b());
|
||||
self.avgs.push_back(0.);
|
||||
}
|
||||
|
||||
@@ -168,8 +169,8 @@ impl<NTY: ScalarOps> AppendEmptyBin for BinsDim0<NTY> {
|
||||
self.ts1s.push_back(ts1);
|
||||
self.ts2s.push_back(ts2);
|
||||
self.counts.push_back(0);
|
||||
self.mins.push_back(NTY::zero());
|
||||
self.maxs.push_back(NTY::zero());
|
||||
self.mins.push_back(NTY::zero_b());
|
||||
self.maxs.push_back(NTY::zero_b());
|
||||
self.avgs.push_back(0.);
|
||||
}
|
||||
}
|
||||
@@ -393,8 +394,8 @@ impl<NTY: ScalarOps> BinsDim0Aggregator<NTY> {
|
||||
Self {
|
||||
range,
|
||||
count: 0,
|
||||
min: NTY::zero(),
|
||||
max: NTY::zero(),
|
||||
min: NTY::zero_b(),
|
||||
max: NTY::zero_b(),
|
||||
avg: 0.,
|
||||
sumc: 0,
|
||||
sum: 0f32,
|
||||
@@ -656,12 +657,12 @@ impl<NTY: ScalarOps> TimeBinned for BinsDim0<NTY> {
|
||||
|
||||
// TODO is Vec needed?
|
||||
fn mins(&self) -> Vec<f32> {
|
||||
self.mins.iter().map(|x| x.clone().as_prim_f32()).collect()
|
||||
self.mins.iter().map(|x| x.clone().as_prim_f32_b()).collect()
|
||||
}
|
||||
|
||||
// TODO is Vec needed?
|
||||
fn maxs(&self) -> Vec<f32> {
|
||||
self.maxs.iter().map(|x| x.clone().as_prim_f32()).collect()
|
||||
self.maxs.iter().map(|x| x.clone().as_prim_f32_b()).collect()
|
||||
}
|
||||
|
||||
// TODO is Vec needed?
|
||||
@@ -676,7 +677,7 @@ impl<NTY: ScalarOps> TimeBinned for BinsDim0<NTY> {
|
||||
write!(&mut msg, "ts1s ≠ ts2s\n").unwrap();
|
||||
}
|
||||
for (i, ((count, min), max)) in self.counts.iter().zip(&self.mins).zip(&self.maxs).enumerate() {
|
||||
if min.as_prim_f32() < 1. && *count != 0 {
|
||||
if min.as_prim_f32_b() < 1. && *count != 0 {
|
||||
write!(&mut msg, "i {} count {} min {:?} max {:?}\n", i, count, min, max).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ mod serde_channel_events {
|
||||
where
|
||||
A: de::SeqAccess<'de>,
|
||||
{
|
||||
use items::SubFrId;
|
||||
use items_0::subfr::SubFrId;
|
||||
let e0: &str = seq.next_element()?.ok_or(de::Error::missing_field("ty .0"))?;
|
||||
let e1: u32 = seq.next_element()?.ok_or(de::Error::missing_field("nty .1"))?;
|
||||
if e0 == EventsDim0::<u8>::serde_id() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::binsdim0::BinsDim0;
|
||||
use crate::ScalarOps;
|
||||
use crate::{pulse_offs_from_abs, ts_offs_from_abs, RangeOverlapInfo};
|
||||
use crate::{TimeBinnable, TimeBinnableType, TimeBinnableTypeAggregator, TimeBinner};
|
||||
use err::Error;
|
||||
use items_0::scalar_ops::ScalarOps;
|
||||
use items_0::{Empty, Events, WithLen};
|
||||
use netpod::log::*;
|
||||
use netpod::timeunits::SEC;
|
||||
@@ -292,8 +292,8 @@ impl<NTY: ScalarOps> EventsDim0Aggregator<NTY> {
|
||||
Self {
|
||||
range,
|
||||
count: 0,
|
||||
min: NTY::zero(),
|
||||
max: NTY::zero(),
|
||||
min: NTY::zero_b(),
|
||||
max: NTY::zero_b(),
|
||||
sum: 0.,
|
||||
sumc: 0,
|
||||
int_ts,
|
||||
@@ -334,7 +334,7 @@ impl<NTY: ScalarOps> EventsDim0Aggregator<NTY> {
|
||||
fn apply_event_unweight(&mut self, val: NTY) {
|
||||
trace!("TODO check again result_reset_unweight");
|
||||
err::todo();
|
||||
let vf = val.as_prim_f32();
|
||||
let vf = val.as_prim_f32_b();
|
||||
self.apply_min_max(val);
|
||||
if vf.is_nan() {
|
||||
} else {
|
||||
@@ -345,7 +345,7 @@ impl<NTY: ScalarOps> EventsDim0Aggregator<NTY> {
|
||||
|
||||
fn apply_event_time_weight(&mut self, ts: u64) {
|
||||
if let Some(v) = &self.last_seen_val {
|
||||
let vf = v.as_prim_f32();
|
||||
let vf = v.as_prim_f32_b();
|
||||
let v2 = v.clone();
|
||||
if ts > self.range.beg {
|
||||
self.apply_min_max(v2);
|
||||
@@ -435,9 +435,9 @@ impl<NTY: ScalarOps> EventsDim0Aggregator<NTY> {
|
||||
} else {
|
||||
let g = match &self.last_seen_val {
|
||||
Some(x) => x.clone(),
|
||||
None => NTY::zero(),
|
||||
None => NTY::zero_b(),
|
||||
};
|
||||
(g.clone(), g.clone(), g.as_prim_f32())
|
||||
(g.clone(), g.clone(), g.as_prim_f32_b())
|
||||
};
|
||||
let ret = BinsDim0 {
|
||||
ts1s: [self.range.beg].into(),
|
||||
@@ -470,9 +470,9 @@ impl<NTY: ScalarOps> EventsDim0Aggregator<NTY> {
|
||||
} else {
|
||||
let g = match &self.last_seen_val {
|
||||
Some(x) => x.clone(),
|
||||
None => NTY::zero(),
|
||||
None => NTY::zero_b(),
|
||||
};
|
||||
(g.clone(), g.clone(), g.as_prim_f32())
|
||||
(g.clone(), g.clone(), g.as_prim_f32_b())
|
||||
};
|
||||
let ret = BinsDim0 {
|
||||
ts1s: [self.range.beg].into(),
|
||||
@@ -488,8 +488,8 @@ impl<NTY: ScalarOps> EventsDim0Aggregator<NTY> {
|
||||
self.sum = 0.;
|
||||
self.sumc = 0;
|
||||
self.did_min_max = false;
|
||||
self.min = NTY::zero();
|
||||
self.max = NTY::zero();
|
||||
self.min = NTY::zero_b();
|
||||
self.max = NTY::zero_b();
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ use futures_util::StreamExt;
|
||||
use items::RangeCompletableItem;
|
||||
use items::Sitemty;
|
||||
use items::StreamItem;
|
||||
use items::SubFrId;
|
||||
use items_0::collect_s::Collector;
|
||||
use items_0::collect_s::ToJsonResult;
|
||||
use items_0::Empty;
|
||||
@@ -70,90 +69,6 @@ pub fn pulse_offs_from_abs(pulse: &[u64]) -> (u64, VecDeque<u64>) {
|
||||
(pulse_anchor, pulse_off)
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
const fn is_nan_int<T>(_x: &T) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn is_nan_f32(x: f32) -> bool {
|
||||
x.is_nan()
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn is_nan_f64(x: f64) -> bool {
|
||||
x.is_nan()
|
||||
}
|
||||
|
||||
pub trait AsPrimF32 {
|
||||
fn as_prim_f32(&self) -> f32;
|
||||
}
|
||||
|
||||
macro_rules! impl_as_prim_f32 {
|
||||
($ty:ident) => {
|
||||
impl AsPrimF32 for $ty {
|
||||
fn as_prim_f32(&self) -> f32 {
|
||||
*self as f32
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_as_prim_f32!(u8);
|
||||
impl_as_prim_f32!(u16);
|
||||
impl_as_prim_f32!(u32);
|
||||
impl_as_prim_f32!(u64);
|
||||
impl_as_prim_f32!(i8);
|
||||
impl_as_prim_f32!(i16);
|
||||
impl_as_prim_f32!(i32);
|
||||
impl_as_prim_f32!(i64);
|
||||
impl_as_prim_f32!(f32);
|
||||
impl_as_prim_f32!(f64);
|
||||
|
||||
pub trait ScalarOps:
|
||||
fmt::Debug + Clone + PartialOrd + SubFrId + AsPrimF32 + Serialize + Unpin + Send + 'static
|
||||
{
|
||||
fn zero() -> Self;
|
||||
fn equal_slack(&self, rhs: &Self) -> bool;
|
||||
}
|
||||
|
||||
macro_rules! impl_num_ops {
|
||||
($ty:ident, $zero:expr, $equal_slack:ident) => {
|
||||
impl ScalarOps for $ty {
|
||||
fn zero() -> Self {
|
||||
$zero
|
||||
}
|
||||
|
||||
fn equal_slack(&self, rhs: &Self) -> bool {
|
||||
$equal_slack(*self, *rhs)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn equal_int<T: PartialEq>(a: T, b: T) -> bool {
|
||||
a == b
|
||||
}
|
||||
|
||||
fn equal_f32(a: f32, b: f32) -> bool {
|
||||
(a - b).abs() < 1e-4 || (a / b > 0.999 && a / b < 1.001)
|
||||
}
|
||||
|
||||
fn equal_f64(a: f64, b: f64) -> bool {
|
||||
(a - b).abs() < 1e-6 || (a / b > 0.99999 && a / b < 1.00001)
|
||||
}
|
||||
|
||||
impl_num_ops!(u8, 0, equal_int);
|
||||
impl_num_ops!(u16, 0, equal_int);
|
||||
impl_num_ops!(u32, 0, equal_int);
|
||||
impl_num_ops!(u64, 0, equal_int);
|
||||
impl_num_ops!(i8, 0, equal_int);
|
||||
impl_num_ops!(i16, 0, equal_int);
|
||||
impl_num_ops!(i32, 0, equal_int);
|
||||
impl_num_ops!(i64, 0, equal_int);
|
||||
impl_num_ops!(f32, 0., equal_f32);
|
||||
impl_num_ops!(f64, 0., equal_f64);
|
||||
|
||||
#[allow(unused)]
|
||||
struct Ts(u64);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user