From c455c01d2488222a4509eb1b42301fa0e523c6c7 Mon Sep 17 00:00:00 2001 From: Dominik Werder Date: Wed, 8 Sep 2021 21:27:34 +0200 Subject: [PATCH] Use unweighted binning as default --- daqbufp2/src/test/timeweightedjson.rs | 23 +++++++++++++++++++++++ disk/src/binned/query.rs | 4 ++-- httpret/src/proxy.rs | 4 ++-- httpret/static/documentation/api4.html | 6 +++--- items/src/eventvalues.rs | 2 -- items/src/minmaxavgbins.rs | 8 +++----- items/src/minmaxavgdim1bins.rs | 9 ++++++--- items/src/minmaxavgwavebins.rs | 9 ++++++--- items/src/waveevents.rs | 5 ++++- items/src/xbinnedwaveevents.rs | 5 ++++- 10 files changed, 53 insertions(+), 22 deletions(-) diff --git a/daqbufp2/src/test/timeweightedjson.rs b/daqbufp2/src/test/timeweightedjson.rs index 1b94009..0be08c4 100644 --- a/daqbufp2/src/test/timeweightedjson.rs +++ b/daqbufp2/src/test/timeweightedjson.rs @@ -78,6 +78,29 @@ fn time_weighted_json_02() { super::run_test(inner()); } +#[test] +fn time_weighted_json_03() { + async fn inner() -> Result<(), Error> { + let rh = require_test_hosts_running()?; + let cluster = &rh.cluster; + let res = get_json_common( + "const-regular-scalar-i32-be", + "1970-01-01T00:20:11.000Z", + "1970-01-01T00:30:20.000Z", + 10, + AggKind::TimeWeightedScalar, + cluster, + 11, + true, + ) + .await?; + let v = res.avgs[0]; + assert!(v > 41.9999 && v < 42.0001); + Ok(()) + } + super::run_test(inner()); +} + #[test] fn time_weighted_json_10() { async fn inner() -> Result<(), Error> { diff --git a/disk/src/binned/query.rs b/disk/src/binned/query.rs index 4dbefd7..462682a 100644 --- a/disk/src/binned/query.rs +++ b/disk/src/binned/query.rs @@ -69,7 +69,7 @@ impl PreBinnedQuery { let ret = Self { patch: PreBinnedPatchCoord::new(bin_t_len, patch_t_len, patch_ix), channel: channel_from_pairs(&pairs)?, - agg_kind: agg_kind_from_binning_scheme(&pairs).unwrap_or(AggKind::TimeWeightedScalar), + agg_kind: agg_kind_from_binning_scheme(&pairs).unwrap_or(AggKind::DimXBins1), cache_usage: CacheUsage::from_pairs(&pairs)?, disk_io_buffer_size: pairs .get("diskIoBufferSize") @@ -312,7 +312,7 @@ impl FromUrl for BinnedQuery { .ok_or(Error::with_msg("missing binCount"))? .parse() .map_err(|e| Error::with_msg(format!("can not parse binCount {:?}", e)))?, - agg_kind: agg_kind_from_binning_scheme(&pairs).unwrap_or(AggKind::TimeWeightedScalar), + agg_kind: agg_kind_from_binning_scheme(&pairs).unwrap_or(AggKind::DimXBins1), cache_usage: CacheUsage::from_pairs(&pairs)?, disk_io_buffer_size: pairs .get("diskIoBufferSize") diff --git a/httpret/src/proxy.rs b/httpret/src/proxy.rs index 64dbfd8..5c03c2b 100644 --- a/httpret/src/proxy.rs +++ b/httpret/src/proxy.rs @@ -1,6 +1,6 @@ use crate::api1::{channel_search_configs_v1, channel_search_list_v1, gather_json_2_v1, proxy_distribute_v1}; use crate::gather::{gather_get_json_generic, SubRes}; -use crate::{api_4_docs, response, Cont}; +use crate::{api_1_docs, api_4_docs, response, Cont}; use disk::binned::query::BinnedQuery; use disk::events::PlainEventsJsonQuery; use err::Error; @@ -86,7 +86,7 @@ async fn proxy_http_service_try(req: Request, proxy_config: &ProxyConfig) proxy_distribute_v1(req).await } else if path.starts_with("/api/1/documentation/") { if req.method() == Method::GET { - Ok(response(StatusCode::NOT_FOUND).body(Body::empty())?) + api_1_docs(path) } else { Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?) } diff --git a/httpret/static/documentation/api4.html b/httpret/static/documentation/api4.html index 64a071e..ba0e271 100644 --- a/httpret/static/documentation/api4.html +++ b/httpret/static/documentation/api4.html @@ -194,12 +194,12 @@ curl -H 'Accept: application/json' 'https://data-api.psi.ch/api/4/events?channel
  • channelName (e.g. "SLAAR-LSCP4-LAS6891:CH7:1")
  • begDate (e.g. "2021-05-26T07:10:00.000Z")
  • endDate (e.g. "2021-05-26T07:16:00.000Z")
  • -
  • binCount (number of requested bins in time-dimension, e.g. "6")
  • +
  • binCount (number of requested bins in time-dimension, e.g. "6". The actual number of returned bins depends on bin-cache-grid-resolution. The server tries to find the best match.)
  • binningScheme (optional)
  • diff --git a/items/src/eventvalues.rs b/items/src/eventvalues.rs index 8c353f7..14eb366 100644 --- a/items/src/eventvalues.rs +++ b/items/src/eventvalues.rs @@ -7,7 +7,6 @@ use crate::{ WithLen, WithTimestamps, }; use err::Error; -use netpod::log::*; use netpod::timeunits::*; use netpod::NanoRange; use serde::{Deserialize, Serialize}; @@ -365,7 +364,6 @@ where self.last_ts = ts; self.last_val = Some(val); } else if ts >= self.range.end { - info!("event after {}", ts / MS); return; } else { self.count += 1; diff --git a/items/src/minmaxavgbins.rs b/items/src/minmaxavgbins.rs index eed9efc..10b47f4 100644 --- a/items/src/minmaxavgbins.rs +++ b/items/src/minmaxavgbins.rs @@ -180,8 +180,8 @@ where type Output = MinMaxAvgBins; type Aggregator = MinMaxAvgBinsAggregator; - fn aggregator(range: NanoRange, _x_bin_count: usize, _do_time_weight: bool) -> Self::Aggregator { - Self::Aggregator::new(range) + fn aggregator(range: NanoRange, _x_bin_count: usize, do_time_weight: bool) -> Self::Aggregator { + Self::Aggregator::new(range, do_time_weight) } } @@ -331,7 +331,7 @@ pub struct MinMaxAvgBinsAggregator { } impl MinMaxAvgBinsAggregator { - pub fn new(range: NanoRange) -> Self { + pub fn new(range: NanoRange, _do_time_weight: bool) -> Self { Self { range, count: 0, @@ -357,9 +357,7 @@ where fn ingest(&mut self, item: &Self::Input) { for i1 in 0..item.ts1s.len() { if item.ts2s[i1] <= self.range.beg { - continue; } else if item.ts1s[i1] >= self.range.end { - continue; } else { self.min = match self.min { None => item.mins[i1], diff --git a/items/src/minmaxavgdim1bins.rs b/items/src/minmaxavgdim1bins.rs index c5c8b72..c07baf6 100644 --- a/items/src/minmaxavgdim1bins.rs +++ b/items/src/minmaxavgdim1bins.rs @@ -181,8 +181,8 @@ where type Output = MinMaxAvgDim1Bins; type Aggregator = MinMaxAvgDim1BinsAggregator; - fn aggregator(range: NanoRange, x_bin_count: usize, _do_time_weight: bool) -> Self::Aggregator { - Self::Aggregator::new(range, x_bin_count) + fn aggregator(range: NanoRange, x_bin_count: usize, do_time_weight: bool) -> Self::Aggregator { + Self::Aggregator::new(range, x_bin_count, do_time_weight) } } @@ -325,7 +325,10 @@ pub struct MinMaxAvgDim1BinsAggregator { } impl MinMaxAvgDim1BinsAggregator { - pub fn new(range: NanoRange, _x_bin_count: usize) -> Self { + pub fn new(range: NanoRange, _x_bin_count: usize, do_time_weight: bool) -> Self { + if do_time_weight { + err::todo(); + } Self { range, count: 0, diff --git a/items/src/minmaxavgwavebins.rs b/items/src/minmaxavgwavebins.rs index 1a1b97d..d7069f4 100644 --- a/items/src/minmaxavgwavebins.rs +++ b/items/src/minmaxavgwavebins.rs @@ -179,8 +179,8 @@ where type Output = MinMaxAvgWaveBins; type Aggregator = MinMaxAvgWaveBinsAggregator; - fn aggregator(range: NanoRange, x_bin_count: usize, _do_time_weight: bool) -> Self::Aggregator { - Self::Aggregator::new(range, x_bin_count) + fn aggregator(range: NanoRange, x_bin_count: usize, do_time_weight: bool) -> Self::Aggregator { + Self::Aggregator::new(range, x_bin_count, do_time_weight) } } @@ -332,7 +332,10 @@ impl MinMaxAvgWaveBinsAggregator where NTY: NumOps, { - pub fn new(range: NanoRange, x_bin_count: usize) -> Self { + pub fn new(range: NanoRange, x_bin_count: usize, do_time_weight: bool) -> Self { + if do_time_weight { + err::todo(); + } Self { range, count: 0, diff --git a/items/src/waveevents.rs b/items/src/waveevents.rs index c758055..7aa9495 100644 --- a/items/src/waveevents.rs +++ b/items/src/waveevents.rs @@ -171,7 +171,10 @@ impl WaveEventsAggregator where NTY: NumOps, { - pub fn new(range: NanoRange, _x_bin_count: usize, _do_time_weight: bool) -> Self { + pub fn new(range: NanoRange, _x_bin_count: usize, do_time_weight: bool) -> Self { + if do_time_weight { + err::todo(); + } Self { range, count: 0, diff --git a/items/src/xbinnedwaveevents.rs b/items/src/xbinnedwaveevents.rs index 224da44..7fb5de1 100644 --- a/items/src/xbinnedwaveevents.rs +++ b/items/src/xbinnedwaveevents.rs @@ -178,7 +178,10 @@ impl XBinnedWaveEventsAggregator where NTY: NumOps, { - pub fn new(range: NanoRange, bin_count: usize, _do_time_weight: bool) -> Self { + pub fn new(range: NanoRange, bin_count: usize, do_time_weight: bool) -> Self { + if do_time_weight { + err::todo(); + } if bin_count == 0 { panic!("bin_count == 0"); }