Skip to content

Commit

Permalink
Merge pull request #106 from NREL/fix/skip-serializing-empty-history
Browse files Browse the repository at this point in the history
skip serializing history if empty
  • Loading branch information
calbaker authored Jan 14, 2025
2 parents 981edf4 + 6b4ef5f commit f9a1d7e
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions rust/altrios-core/src/consist/consist_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub struct Consist {
#[serde(default)]
#[serde(skip_serializing_if = "EqDefault::eq_default")]
pub state: ConsistState,
#[serde(skip_serializing_if = "ConsistStateHistoryVec::is_empty", default)]
/// Custom vector of [Self::state]
pub history: ConsistStateHistoryVec,
#[api(skip_set, skip_get)] // custom needed for this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ pub struct Locomotive {
#[api(skip_set, skip_get)]
save_interval: Option<usize>,
/// Custom vector of [Self::state]
#[serde(default)]
#[serde(skip_serializing_if = "LocomotiveStateHistoryVec::is_empty", default)]
pub history: LocomotiveStateHistoryVec,
#[serde(default = "utils::return_true")]
/// If true, requires power demand to not exceed consist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ pub struct ElectricDrivetrain {
/// Time step interval between saves. 1 is a good option. If None, no saving occurs.
pub save_interval: Option<usize>,
/// Custom vector of [Self::state]
#[serde(default)]
#[serde(
skip_serializing_if = "ElectricDrivetrainStateHistoryVec::is_empty",
default
)]
pub history: ElectricDrivetrainStateHistoryVec,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ pub struct FuelConverter {
/// time step interval between saves. 1 is a good option. If None, no saving occurs.
pub save_interval: Option<usize>,
/// Custom vector of [Self::state]
#[serde(default)]
#[serde(
skip_serializing_if = "FuelConverterStateHistoryVec::is_empty",
default
)]
pub history: FuelConverterStateHistoryVec, // TODO: spec out fuel tank size and track kg of fuel
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub struct Generator {
/// Time step interval between saves. 1 is a good option. If None, no saving occurs.
pub save_interval: Option<usize>,
/// Custom vector of [Self::state]
#[serde(default)]
#[serde(skip_serializing_if = "GeneratorStateHistoryVec::is_empty", default)]
pub history: GeneratorStateHistoryVec,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ pub struct ReversibleEnergyStorage {
pub soc_lo_ramp_start: Option<si::Ratio>,
/// Time step interval at which history is saved
pub save_interval: Option<usize>,
#[serde(default)]
#[serde(
skip_serializing_if = "ReversibleEnergyStorageStateHistoryVec::is_empty",
default
)]
/// Custom vector of [Self::state]
pub history: ReversibleEnergyStorageStateHistoryVec,
}
Expand Down
2 changes: 1 addition & 1 deletion rust/altrios-core/src/train/friction_brakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct FricBrake {
#[serde(default)]
#[serde(skip_serializing_if = "EqDefault::eq_default")]
pub state: FricBrakeState,
#[serde(default)]
#[serde(skip_serializing_if = "FricBrakeStateHistoryVec::is_empty", default)]
/// Custom vector of [Self::state]
pub history: FricBrakeStateHistoryVec,
pub save_interval: Option<usize>,
Expand Down
2 changes: 1 addition & 1 deletion rust/altrios-core/src/train/set_speed_train_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ pub struct SetSpeedTrainSim {
pub train_res: TrainRes,
#[api(skip_set)]
path_tpc: PathTpc,
#[serde(default)]
/// Custom vector of [Self::state]
#[serde(skip_serializing_if = "TrainStateHistoryVec::is_empty", default)]
pub history: TrainStateHistoryVec,
#[api(skip_set, skip_get)]
save_interval: Option<usize>,
Expand Down
2 changes: 1 addition & 1 deletion rust/altrios-core/src/train/speed_limit_train_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ pub struct SpeedLimitTrainSim {
#[api(skip_set)]
pub braking_points: BrakingPoints,
pub fric_brake: FricBrake,
#[serde(default)]
/// Custom vector of [Self::state]
#[serde(skip_serializing_if = "TrainStateHistoryVec::is_empty", default)]
pub history: TrainStateHistoryVec,
#[api(skip_set, skip_get)]
save_interval: Option<usize>,
Expand Down

0 comments on commit f9a1d7e

Please sign in to comment.