summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorD. Scott Boggs <scott@tams.tech>2023-01-29 11:17:18 -0500
committerD. Scott Boggs <scott@tams.tech>2023-01-29 11:17:18 -0500
commit7285fac2c3527e93cfa3d12efc1245ff783ca370 (patch)
tree2469ed65481c2d0342e37a2bc163cf9fdf200ae1
parent4b5ddb167cdbe5f3b7484402a338ad76b8f2e1f5 (diff)
Add Admin::Measure entity type
-rw-r--r--entities/src/admin/measure.rs37
-rw-r--r--entities/src/admin/mod.rs2
-rw-r--r--entities/src/ids.rs1
3 files changed, 40 insertions, 0 deletions
diff --git a/entities/src/admin/measure.rs b/entities/src/admin/measure.rs
new file mode 100644
index 0000000..7d93d6c
--- /dev/null
+++ b/entities/src/admin/measure.rs
@@ -0,0 +1,37 @@
+use serde::{Deserialize, Serialize};
+use time::{serde::iso8601, OffsetDateTime};
+
+use crate::{conversion, MeasureKey};
+
+/// Represents quantitative data about the server.
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct Measure {
+ /// The unique keystring for the requested measure.
+ pub key: MeasureKey,
+ /// The units associated with this data item’s value, if applicable.
+ pub unit: Option<String>,
+ /// The numeric total associated with the requested measure.
+ #[serde(with = "conversion::string_to_u64")]
+ pub total: u64,
+ /// A human-readable formatted value for this data item.
+ pub human_value: String,
+ /// The numeric total associated with the requested measure, in the previous
+ /// period. Previous period is calculated by subtracting the start_at and
+ /// end_at dates, then offsetting both start and end dates backwards by the
+ /// length of the time period.
+ #[serde(with = "conversion::string_to_u64")]
+ pub previous_total: u64,
+ /// The data available for the requested measure, split into daily buckets.
+ pub data: Vec<Data>,
+}
+
+/// One day's bucket of data in a measure.
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct Data {
+ /// Midnight on the requested day in the time period.
+ #[serde(with = "iso8601")]
+ pub date: OffsetDateTime,
+ /// The numeric value for the requested measure.
+ #[serde(with = "conversion::string_to_u64")]
+ pub value: u64,
+}
diff --git a/entities/src/admin/mod.rs b/entities/src/admin/mod.rs
index b912132..7eed267 100644
--- a/entities/src/admin/mod.rs
+++ b/entities/src/admin/mod.rs
@@ -5,6 +5,7 @@ pub mod dimension;
pub mod domain;
pub mod email_domain_block;
pub mod ip_block;
+pub mod measure;
pub use account::*;
pub use canonical_email_block::*;
@@ -12,3 +13,4 @@ pub use cohort::{Cohort, CohortFrequency};
pub use dimension::Dimension;
pub use email_domain_block::EmailDomainBlock;
pub use ip_block::IpBlock;
+pub use measure::Measure;
diff --git a/entities/src/ids.rs b/entities/src/ids.rs
index ce87588..30f8244 100644
--- a/entities/src/ids.rs
+++ b/entities/src/ids.rs
@@ -54,4 +54,5 @@ define_ids!(
AllowDomainId,
DomainBlockId,
EmailDomainBlockId,
+ MeasureKey,
);