ih_muse_proto/
metric.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// crates/ih-muse-proto/src/metric.rs

use serde::{Deserialize, Serialize};

use crate::types::*;
use crate::utils::deterministic_u32_from_str;

pub fn metric_id_from_code(code: &str) -> u32 {
    deterministic_u32_from_str(code)
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct MetricDefinition {
    pub id: MetricId,
    pub code: String,
    pub name: String,
    pub description: String,
}

impl MetricDefinition {
    pub fn new(code: &str, name: &str, description: &str) -> Self {
        Self {
            id: metric_id_from_code(code),
            code: code.to_string(),
            name: name.to_string(),
            description: description.to_string(),
        }
    }
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MetricPayload {
    pub time: Timestamp,
    pub element_id: ElementId,
    pub metric_ids: Vec<MetricId>,
    pub values: Vec<Option<MetricValue>>,
}

impl MetricPayload {
    pub fn new(
        time: Timestamp,
        element_id: ElementId,
        metric_ids: Vec<MetricId>,
        values: Vec<Option<MetricValue>>,
    ) -> Self {
        Self {
            time,
            element_id,
            metric_ids,
            values,
        }
    }
}

#[derive(Deserialize, Serialize, Debug, Default, Clone)]
pub struct MetricQuery {
    pub start_time: Option<i64>,
    pub end_time: Option<i64>,
    pub element_id: Option<u64>,
    pub parent_id: Option<u64>,
    pub metric_id: Option<u32>,
}

impl MetricQuery {
    pub fn new(
        start_time: Option<i64>,
        end_time: Option<i64>,
        element_id: Option<u64>,
        parent_id: Option<u64>,
        metric_id: Option<u32>,
    ) -> Self {
        Self {
            start_time,
            end_time,
            element_id,
            parent_id,
            metric_id,
        }
    }
}