hydr_structures/structures/control/snapshot/
package.rs1use super::super::{
4 ControlDecisionSchedule, ControlInitialState, ControlState, ControlStepDiagnostics,
5 OperatingControlBatch, OperatingControlDefinition, SampledControlTiming,
6};
7use crate::structures::{StructureElement, StructureError};
8use numr::dtype::DType;
9use numr::runtime::Runtime;
10
11pub const OPERATING_CONTROL_SNAPSHOT_SCHEMA: &str = "hydr-operating-control-checkpoint-2";
13pub const OPERATING_CONTROL_CONTRACT_VERSION: &str = "hydr-operating-control-numr-cpu-1";
15
16#[derive(Clone, Debug, PartialEq)]
18pub struct OperatingControlSnapshotData {
19 pub schema: String,
21 pub contract: String,
23 pub elements: Vec<StructureElement>,
25 pub definitions: Vec<OperatingControlDefinition>,
27 pub initial_states: Vec<ControlInitialState>,
29 pub schedule: ControlDecisionSchedule,
31 pub timing: SampledControlTiming,
33 pub time_s: f64,
35 pub next_decision_index: usize,
37 pub accepted_steps: usize,
39 pub states: Vec<ControlState>,
41 pub last_step: Option<ControlStepDiagnostics>,
43}
44#[derive(Clone, Debug)]
46pub struct OperatingControlSnapshot<R: Runtime<DType = DType>> {
47 pub(super) batch: OperatingControlBatch<R>,
48}
49impl<R: Runtime<DType = DType>> OperatingControlSnapshot<R> {
50 pub fn time(&self) -> f64 {
52 self.batch.time()
53 }
54 pub fn data(&self) -> Result<OperatingControlSnapshotData, StructureError> {
56 self.batch.snapshot_data()
57 }
58}
59impl<R: Runtime<DType = DType>> OperatingControlBatch<R> {
60 pub fn snapshot(&self) -> OperatingControlSnapshot<R> {
62 OperatingControlSnapshot {
63 batch: self.clone(),
64 }
65 }
66 pub fn snapshot_data(&self) -> Result<OperatingControlSnapshotData, StructureError> {
68 Ok(OperatingControlSnapshotData {
69 schema: OPERATING_CONTROL_SNAPSHOT_SCHEMA.into(),
70 contract: OPERATING_CONTROL_CONTRACT_VERSION.into(),
71 elements: self.elements().to_vec(),
72 definitions: self.definitions().to_vec(),
73 initial_states: self.initial_states().to_vec(),
74 schedule: self.schedule().clone(),
75 timing: self.timing().clone(),
76 time_s: self.time,
77 next_decision_index: self.next_decision,
78 accepted_steps: self.steps,
79 states: self.states()?,
80 last_step: self.last_step()?,
81 })
82 }
83}