Skip to content

Commit

Permalink
refactor cyc.len into len(cyc)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Carow authored and Kyle Carow committed Nov 30, 2023
1 parent e7313a4 commit 9f61ed5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions python/fastsim/simdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/fastsim/tests/test_simdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 4 additions & 5 deletions rust/fastsim-core/src/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ impl RustCycleCache {
}
}
pub fn __len__(&self) -> usize {
self.len()
}
#[allow(clippy::type_complexity)]
pub fn __getnewargs__(&self) -> (Vec<f64>, Vec<f64>, Vec<f64>, Vec<f64>, &str) {
(self.time_s.to_vec(), self.mps.to_vec(), self.grade.to_vec(), self.road_type.to_vec(), &self.name)
Expand Down Expand Up @@ -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<f64> {
self.dist_m().to_vec()
Expand Down

0 comments on commit 9f61ed5

Please sign in to comment.