use super::super::{
ControlDecisionSchedule, ControlInitialState, ControlState, ControlStepDiagnostics,
OperatingControlBatch, OperatingControlDefinition, SampledControlTiming,
};
use crate::structures::{StructureElement, StructureError};
use numr::dtype::DType;
use numr::runtime::Runtime;
pub const OPERATING_CONTROL_SNAPSHOT_SCHEMA: &str = "hydr-operating-control-checkpoint-2";
pub const OPERATING_CONTROL_CONTRACT_VERSION: &str = "hydr-operating-control-numr-cpu-1";
#[derive(Clone, Debug, PartialEq)]
pub struct OperatingControlSnapshotData {
pub schema: String,
pub contract: String,
pub elements: Vec<StructureElement>,
pub definitions: Vec<OperatingControlDefinition>,
pub initial_states: Vec<ControlInitialState>,
pub schedule: ControlDecisionSchedule,
pub timing: SampledControlTiming,
pub time_s: f64,
pub next_decision_index: usize,
pub accepted_steps: usize,
pub states: Vec<ControlState>,
pub last_step: Option<ControlStepDiagnostics>,
}
#[derive(Clone, Debug)]
pub struct OperatingControlSnapshot<R: Runtime<DType = DType>> {
pub(super) batch: OperatingControlBatch<R>,
}
impl<R: Runtime<DType = DType>> OperatingControlSnapshot<R> {
pub fn time(&self) -> f64 {
self.batch.time()
}
pub fn data(&self) -> Result<OperatingControlSnapshotData, StructureError> {
self.batch.snapshot_data()
}
}
impl<R: Runtime<DType = DType>> OperatingControlBatch<R> {
pub fn snapshot(&self) -> OperatingControlSnapshot<R> {
OperatingControlSnapshot {
batch: self.clone(),
}
}
pub fn snapshot_data(&self) -> Result<OperatingControlSnapshotData, StructureError> {
Ok(OperatingControlSnapshotData {
schema: OPERATING_CONTROL_SNAPSHOT_SCHEMA.into(),
contract: OPERATING_CONTROL_CONTRACT_VERSION.into(),
elements: self.elements().to_vec(),
definitions: self.definitions().to_vec(),
initial_states: self.initial_states().to_vec(),
schedule: self.schedule().clone(),
timing: self.timing().clone(),
time_s: self.time,
next_decision_index: self.next_decision,
accepted_steps: self.steps,
states: self.states()?,
last_step: self.last_step()?,
})
}
}