cognite/dto/data_modeling/instances/extensions/
timeseries.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use crate::models::instances::{InstanceId, NodeOrEdgeCreate};
5
6use super::{
7    common::{CogniteDescribable, CogniteSourceable},
8    CogniteExtendable, WithInstance, WithView,
9};
10
11/// Represents a series of data points in time order..
12pub type CogniteTimeseries = CogniteExtendable<Timeseries>;
13
14#[derive(Serialize, Deserialize, Clone, Debug, Default)]
15#[serde(rename_all = "lowercase")]
16/// Specifies the data type of the data points.
17pub enum TimeSeriesType {
18    /// Indicates that timeseries type is a string.
19    String,
20    #[default]
21    /// Indicates that timeseries type is a number.
22    Numeric,
23}
24
25#[skip_serializing_none]
26#[derive(Serialize, Deserialize, Clone, Debug, Default)]
27#[serde(rename_all = "camelCase")]
28/// The properties of the time series.
29pub struct Timeseries {
30    #[serde(flatten)]
31    /// Descriptions of the instance.
32    pub description: CogniteDescribable,
33    #[serde(flatten)]
34    /// Source system.
35    pub source: CogniteSourceable,
36    /// Defines whether the time series is a step series or not.
37    pub is_step: bool,
38    /// Unit as specified in the source system.
39    pub source_unit: String,
40    /// Direct relation to the unit of the time series.
41    pub unit: Option<InstanceId>,
42    /// List of assets to which this file relates.
43    pub assets: Option<Vec<InstanceId>>,
44    /// List of activities associated with this time series.
45    pub activities: Option<Vec<InstanceId>>,
46    /// Type of datapoints the time series contains.
47    pub r#type: TimeSeriesType,
48}
49
50impl Timeseries {
51    /// Create a new timeseries instance.
52    pub fn new(is_step: bool) -> Self {
53        Self {
54            is_step,
55            ..Default::default()
56        }
57    }
58}
59
60impl WithView for Timeseries {
61    const SPACE: &'static str = "cdf_cdm";
62    const EXTERNAL_ID: &'static str = "CogniteTimeSeries";
63    const VERSION: &'static str = "v1";
64}
65
66impl From<CogniteTimeseries> for NodeOrEdgeCreate<Timeseries> {
67    fn from(value: CogniteTimeseries) -> NodeOrEdgeCreate<Timeseries> {
68        value.instance()
69    }
70}