Deliver also bin edges as ts offsets, update docs

This commit is contained in:
Dominik Werder
2021-06-11 15:40:09 +02:00
parent 321b31d6a6
commit bb6d853b78
2 changed files with 82 additions and 39 deletions

View File

@@ -979,7 +979,9 @@ impl<NTY> MinMaxAvgBinsCollected<NTY> {
#[derive(Serialize)]
pub struct MinMaxAvgBinsCollectedResult<NTY> {
ts_bin_edges: Vec<IsoDateTime>,
ts0: u64,
tsoff: Vec<u64>,
//ts_bin_edges: Vec<IsoDateTime>,
counts: Vec<u64>,
mins: Vec<Option<NTY>>,
maxs: Vec<Option<NTY>>,
@@ -989,7 +991,8 @@ pub struct MinMaxAvgBinsCollectedResult<NTY> {
#[serde(skip_serializing_if = "Zero::is_zero", rename = "missingBins")]
missing_bins: u32,
#[serde(skip_serializing_if = "Option::is_none", rename = "continueAt")]
continue_at: Option<IsoDateTime>,
//continue_at: Option<IsoDateTime>,
continue_at: Option<u64>,
}
pub struct MinMaxAvgBinsCollector<NTY> {
@@ -1041,19 +1044,19 @@ where
}
fn result(self) -> Result<Self::Output, Error> {
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::<NTY> {
ts_bin_edges: tsa,
ts0,
tsoff,
counts: self.vals.counts,
mins: self.vals.mins,
maxs: self.vals.maxs,

View File

@@ -95,13 +95,14 @@ curl -H 'Accept: application/json' 'https://data-api.psi.ch/api/4/search/channel
<h4>CURL example:</h4>
<pre>
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'
</pre>
<h4>Timestamp format</h4>
<p>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 <strong>ts0</strong> which gives an absolute anchor
in time in units of seconds, and the array <strong>tsoff</strong> with the offset of each event in microseconds.</p>
in time in units of seconds, and the array <strong>tsoff</strong> with the offset of each event in nanoseconds.</p>
<h4>Timeout</h4>
<p>If the requested range takes too long to retrieve, then the flags <strong>timedOut: true</strong> will be set.</p>
@@ -128,9 +129,6 @@ in time in units of seconds, and the array <strong>tsoff</strong> with the offse
}
</pre>
<h4>Complete result</h4>
<p>If the result does not contain a <strong>continueAt</strong> key then the result is complete.</p>
<h4>Finalised range</h4>
<p>If the server can determine that no more data will be added to the requested time range
then it will add the flag <strong>finalisedRange: true</strong> to the response.</p>
@@ -169,38 +167,79 @@ as new bins are received.</p>
<p>Example response:</p>
<pre>
{
"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
]
}
</pre>