cognite/dto/core/time_series/
synthetic.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use crate::time_series::TimestampOrRelative;
5
6#[skip_serializing_none]
7#[derive(Serialize, Deserialize, Debug, Default, Clone)]
8#[serde(rename_all = "camelCase")]
9/// Query for synthetic time series data points.
10pub struct SyntheticTimeSeriesQuery {
11    /// query definition. For limits, see the
12    /// [guide to synthetic time series](https://developer.cognite.com/dev/concepts/resource_types/synthetic_timeseries.html#limits).
13    pub expression: String,
14    /// Get datapoints starting from, and including, this time.
15    pub start: Option<TimestampOrRelative>,
16    /// Get datapoints up to, but excluding, this time.
17    pub end: Option<TimestampOrRelative>,
18    /// Return up to this number of datapoints.
19    pub limit: Option<i32>,
20}
21
22#[skip_serializing_none]
23#[derive(Serialize, Deserialize, Debug, Clone)]
24#[serde(rename_all = "camelCase")]
25/// Synthetic data point.
26pub struct SyntheticDataValue {
27    /// Timestamp in milliseconds since epoch.
28    pub timestamp: i64,
29    /// Data point value.
30    pub value: f64,
31}
32
33#[skip_serializing_none]
34#[derive(Serialize, Deserialize, Debug, Clone)]
35#[serde(rename_all = "camelCase")]
36/// Synthetic data error.
37pub struct SyntheticDataError {
38    /// Timestamp in milliseconds since epoch.
39    pub timestamp: i64,
40    /// Error that occured when computing synthetic data point.
41    pub error: String,
42}
43
44#[skip_serializing_none]
45#[derive(Serialize, Deserialize, Debug, Clone)]
46#[serde(untagged)]
47/// Synthetic data point or error.
48pub enum SyntheticDataPoint {
49    /// A synthetic value.
50    Value(SyntheticDataValue),
51    /// A computation error.
52    Error(SyntheticDataError),
53}
54
55#[skip_serializing_none]
56#[derive(Serialize, Deserialize, Debug, Clone)]
57#[serde(rename_all = "camelCase")]
58/// Response when querying synthetic data points.
59pub struct SyntheticQueryResponse {
60    /// Whether the results are strings. Currently, this is always false.
61    pub is_string: Option<bool>,
62    /// List of computed data points.
63    pub datapoints: Vec<SyntheticDataPoint>,
64}