diff --git a/python/fastsim/simdrive.py b/python/fastsim/simdrive.py index 196763415..1ee94abdf 100644 --- a/python/fastsim/simdrive.py +++ b/python/fastsim/simdrive.py @@ -209,7 +209,7 @@ def __init_objects__(self, cyc: cycle.Cycle, veh: vehicle.Vehicle): def init_arrays(self): self.i = 1 # initialize step counter for possible use outside sim_drive_walk() - cyc_len = self.cyc.len + cyc_len = len(self.cyc) # Component Limits -- calculated dynamically self.cur_max_fs_kw_out = np.zeros(cyc_len, dtype=np.float64) @@ -487,7 +487,7 @@ def activate_eco_cruise( params = self.sim_params params.idm_allow = True if not by_microtrip: - if self.cyc0.len > 0 and self.cyc0.time_s[-1] > 0.0: + if len(self.cyc0) > 0 and self.cyc0.time_s[-1] > 0.0: params.idm_v_desired_m_per_s = self.cyc0.dist_m.sum() / self.cyc0.time_s[-1] else: params.idm_v_desired_m_per_s = 0.0 diff --git a/python/fastsim/tests/test_simdrive.py b/python/fastsim/tests/test_simdrive.py index bec2fdcaf..90647e48a 100644 --- a/python/fastsim/tests/test_simdrive.py +++ b/python/fastsim/tests/test_simdrive.py @@ -262,12 +262,12 @@ def test_that_vehdb_single_files_simulate(self): if USE_PYTHON: sd = simdrive.SimDrive(cyc, veh) sd.sim_drive() - self.assertEqual(sd.i, sd.cyc0.len) + self.assertEqual(sd.i, len(sd.cyc0)) if USE_RUST: sd = simdrive.RustSimDrive(cyc.to_rust(), veh.to_rust()) sd.sim_drive() - self.assertEqual(sd.i, sd.cyc0.len) + self.assertEqual(sd.i, len(sd.cyc0)) class TestSimDriveVec(unittest.TestCase): def test_sim_drive_vec(self): diff --git a/rust/fastsim-core/src/cycle.rs b/rust/fastsim-core/src/cycle.rs index 0e1daa879..39a2e2b3f 100644 --- a/rust/fastsim-core/src/cycle.rs +++ b/rust/fastsim-core/src/cycle.rs @@ -494,6 +494,10 @@ impl RustCycleCache { } } + pub fn __len__(&self) -> usize { + self.len() + } + #[allow(clippy::type_complexity)] pub fn __getnewargs__(&self) -> (Vec, Vec, Vec, Vec, &str) { (self.time_s.to_vec(), self.mps.to_vec(), self.grade.to_vec(), self.road_type.to_vec(), &self.name) @@ -606,11 +610,6 @@ impl RustCycleCache { self.dt_s().to_vec() } #[getter] - /// cycle length - pub fn get_len(&self) -> usize { - self.len() - } - #[getter] /// distance for each time step based on final speed pub fn get_dist_m(&self) -> Vec { self.dist_m().to_vec()