Skip to main content

redispatch_xml/types/
period.rs

1//! Time period types (`TimeInterval`, `Resolution`, `Period`, `Point`) used in scheduled time series.
2use serde::{Deserialize, Serialize};
3
4use crate::types::{AttrV, Decimal3, TimeInterval};
5
6// ── Quarter-hour Reason ───────────────────────────────────────────────────────
7
8/// A reason code + optional free-text explanation, attached to an
9/// `ActivationDocument` interval (within a `Period`).
10///
11/// Up to 2 `Reason` elements may appear per `Interval` in an
12/// `ActivationDocument`.
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14pub struct Reason {
15    /// ENTSO-E reason code (e.g. `"A44"`, `"A95"`, `"Z05"`).
16    #[serde(rename = "ReasonCode")]
17    pub code: AttrV<String>,
18    /// Optional free-text reason description (max 512 chars).
19    #[serde(
20        rename = "ReasonText",
21        default,
22        skip_serializing_if = "Option::is_none"
23    )]
24    pub text: Option<String>,
25}
26
27// ── Quarter-hour Interval ─────────────────────────────────────────────────────
28
29/// A single quarter-hour (or longer) power value within a `Period`.
30///
31/// `pos` is 1-indexed (1–100 for a 25-hour DST day). `qty` is the power or
32/// percentage value for the interval, in the unit specified by the parent
33/// time series (`MeasureUnit`).
34#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
35pub struct Interval {
36    /// Quarter-hour position within the day (1–100).
37    #[serde(rename = "Pos")]
38    pub pos: AttrV<u8>,
39    /// Power or percentage quantity for this interval.
40    #[serde(rename = "Qty")]
41    pub qty: AttrV<Decimal3>,
42    /// Optional reason codes (0–2); present only in `ActivationDocument`.
43    #[serde(rename = "Reason", default, skip_serializing_if = "Vec::is_empty")]
44    pub reasons: Vec<Reason>,
45}
46
47// ── Period (attr-v document family) ──────────────────────────────────────────
48
49/// A quarter-hour delivery period used in `ActivationDocument`,
50/// `PlannedResourceScheduleDocument`, `NetworkConstraintDocument`, and
51/// `Kostenblatt`.
52///
53/// The `time_interval` covers one complete calendar day (UTC).
54/// `resolution` is always `"PT15M"` (15-minute granularity), giving 92–100
55/// intervals per day depending on DST transitions.
56#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
57pub struct Period {
58    /// The UTC day this period covers (`yyyy-mm-ddThh:mmZ/yyyy-mm-ddThh:mmZ`).
59    #[serde(rename = "TimeInterval")]
60    pub time_interval: AttrV<TimeInterval>,
61    /// Sampling resolution; always `"PT15M"`.
62    #[serde(rename = "Resolution")]
63    pub resolution: AttrV<String>,
64    /// Quarter-hour intervals for this period (92–100 per standard day).
65    #[serde(rename = "Interval", default)]
66    pub intervals: Vec<Interval>,
67}