diff --git a/disk/src/binned.rs b/disk/src/binned.rs index 25fe6de..917a683 100644 --- a/disk/src/binned.rs +++ b/disk/src/binned.rs @@ -979,7 +979,9 @@ impl MinMaxAvgBinsCollected { #[derive(Serialize)] pub struct MinMaxAvgBinsCollectedResult { - ts_bin_edges: Vec, + ts0: u64, + tsoff: Vec, + //ts_bin_edges: Vec, counts: Vec, mins: Vec>, maxs: Vec>, @@ -989,7 +991,8 @@ pub struct MinMaxAvgBinsCollectedResult { #[serde(skip_serializing_if = "Zero::is_zero", rename = "missingBins")] missing_bins: u32, #[serde(skip_serializing_if = "Option::is_none", rename = "continueAt")] - continue_at: Option, + //continue_at: Option, + continue_at: Option, } pub struct MinMaxAvgBinsCollector { @@ -1041,19 +1044,19 @@ where } fn result(self) -> Result { + let ts0 = self.vals.ts1s.first().map_or(0, |k| *k / SEC); let bin_count = self.vals.ts1s.len() as u32; - let mut tsa: Vec<_> = self - .vals - .ts1s + let mut tsoff: Vec<_> = self.vals.ts1s.iter().map(|k| *k - ts0 * SEC).collect(); + if let Some(&k) = self.vals.ts2s.last() { + tsoff.push(k - ts0 * SEC); + } + let tsoff = tsoff; + let _iso: Vec<_> = tsoff .iter() .map(|&k| IsoDateTime(Utc.timestamp_nanos(k as i64))) .collect(); - if let Some(&z) = self.vals.ts2s.last() { - tsa.push(IsoDateTime(Utc.timestamp_nanos(z as i64))); - } - let tsa = tsa; let continue_at = if self.vals.ts1s.len() < self.bin_count_exp as usize { - match tsa.last() { + match tsoff.last() { Some(k) => Some(k.clone()), None => Err(Error::with_msg("partial_content but no bin in result"))?, } @@ -1061,7 +1064,8 @@ where None }; let ret = MinMaxAvgBinsCollectedResult:: { - ts_bin_edges: tsa, + ts0, + tsoff, counts: self.vals.counts, mins: self.vals.mins, maxs: self.vals.maxs, diff --git a/httpret/static/documentation/api4.html b/httpret/static/documentation/api4.html index 96d4ee9..e0da2fb 100644 --- a/httpret/static/documentation/api4.html +++ b/httpret/static/documentation/api4.html @@ -95,13 +95,14 @@ curl -H 'Accept: application/json' 'https://data-api.psi.ch/api/4/search/channel

CURL example:

-curl -H 'Accept: application/json' 'https://data-api.psi.ch/api/4/events?channelBackend=sf-databuffer&channelName=SLAAR-LSCP4-LAS6891:CH7:1&begDate=2021-06-11T07:00:00.000Z&endDate=2021-06-11T07:00:01.000Z'
+curl -H 'Accept: application/json' 'https://data-api.psi.ch/api/4/events?channelBackend=sf-databuffer
+  &channelName=SLAAR-LSCP4-LAS6891:CH7:1&begDate=2021-06-11T07:00:00.000Z&endDate=2021-06-11T07:00:01.000Z'
 

Timestamp format

Javascript can not represent the full 64-bit integer and the databuffer nanosecond timestamps would lose precision. Therefore, timestamps are represented in the response by ts0 which gives an absolute anchor -in time in units of seconds, and the array tsoff with the offset of each event in microseconds.

+in time in units of seconds, and the array tsoff with the offset of each event in nanoseconds.

Timeout

If the requested range takes too long to retrieve, then the flags timedOut: true will be set.

@@ -128,9 +129,6 @@ in time in units of seconds, and the array tsoff with the offse } -

Complete result

-

If the result does not contain a continueAt key then the result is complete.

-

Finalised range

If the server can determine that no more data will be added to the requested time range then it will add the flag finalisedRange: true to the response.

@@ -169,38 +167,79 @@ as new bins are received.

Example response:

 {
-  "continueAt": "2021-05-25T16:00:00.000Z",
-  "missingBins": 2,
+  "ts0": 1623304800,
+  "missingBins": 1,
+  "continueAt": 86400000000000,
+  "tsoff": [
+    0,
+    7200000000000,
+    14400000000000,
+    21600000000000,
+    28800000000000,
+    36000000000000,
+    43200000000000,
+    50400000000000,
+    57600000000000,
+    64800000000000,
+    72000000000000,
+    79200000000000,
+    86400000000000
+  ],
   "avgs": [
-    340.87640380859375,
-    340.7442321777344,
-    340.58685302734375,
-    341.04608154296875
+    341.3874206542969,
+    341.5171203613281,
+    341.70989990234375,
+    341.2113952636719,
+    341.84088134765625,
+    342.1435546875,
+    341.16558837890625,
+    342.2756652832031,
+    342.9447326660156,
+    343.0351867675781,
+    342.6963195800781,
+    342.054931640625
   ],
   "counts": [
-    143076,
-    143077,
-    143076,
-    143076
+    71539,
+    71537,
+    71538,
+    71539,
+    71538,
+    71537,
+    71538,
+    71539,
+    71539,
+    71539,
+    71538,
+    71299
   ],
   "maxs": [
+    450,
+    450,
+    462,
+    458,
+    454,
+    450,
     452,
-    452,
-    459,
-    458
+    451,
+    450,
+    453,
+    464,
+    448
   ],
   "mins": [
-    231,
-    240,
+    224,
     239,
-    239
-  ],
-  "tsBinEdges": [
-    "2021-05-25T00:00:00.000Z",
-    "2021-05-25T04:00:00.000Z",
-    "2021-05-25T08:00:00.000Z",
-    "2021-05-25T12:00:00.000Z",
-    "2021-05-25T16:00:00.000Z"
+    242,
+    235,
+    243,
+    239,
+    239,
+    241,
+    243,
+    229,
+    244,
+    225
   ]
 }