Skip to content

Commit

Permalink
commited vehicle and build now checks that's it correct rather than c…
Browse files Browse the repository at this point in the history
…opying

added feature gate
  • Loading branch information
calbaker committed Sep 20, 2024
1 parent 042f283 commit 0577b9b
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 22 deletions.
8 changes: 1 addition & 7 deletions python/fastsim/tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ def test_list_resources_for_cycle(self):

def test_list_resources_for_vehicles(self):
"check if list_resources works for RustVehicle"
# NOTE: at the time of writing this test,
# there are no vehicle assets in resources.
# Therefore, we expect to get an empty vector.
# If resources are committed, this test should
# fail and we should use the following assert:
# self.assertTrue(len(resources) > 0)
rv = vehicle.Vehicle.from_vehdb(1).to_rust()
resources = rv.list_resources()
self.assertTrue(len(resources) == 0)
self.assertTrue(len(resources) == 1)
24 changes: 9 additions & 15 deletions rust/fastsim-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,16 @@ fn main() {
}

check_files_consistent(&prepath);

// make sure at least one vehicle is available in the `from_resources`
let veh_path_in_python = PathBuf::from(format!(
// "{}/{}/vehdb/2017_Toyota_Highlander_3.5_L.yaml",
"{}/{}/vehdb/2017_Toyota_Highlander_3.5_L.yaml",
env::current_dir().unwrap().as_os_str().to_str().unwrap(),
prepath
));
assert!(veh_path_in_python.exists());
let veh_path_in_rust = PathBuf::from(format!(
"{}/resources/vehicles/2017_Toyota_Highlander_3.5_L.yaml",
env::current_dir().unwrap().as_os_str().to_str().unwrap()
));
println!("{:?}", &veh_path_in_rust);
std::fs::copy(veh_path_in_python, veh_path_in_rust).unwrap();
}

/// Checks if rust and python resource files are consistent
fn check_files_consistent(prepath: &String) {
let truth_files = [
format!(
"{}/{}/vehdb/2017_Toyota_Highlander_3.5_L.yaml",
env::current_dir().unwrap().as_os_str().to_str().unwrap(),
prepath
),
format!(
"{}/{}/longparams.json",
env::current_dir().unwrap().as_os_str().to_str().unwrap(),
Expand All @@ -62,6 +52,10 @@ fn check_files_consistent(prepath: &String) {
];

let compare_files = [
format!(
"{}/resources/vehicles/2017_Toyota_Highlander_3.5_L.yaml",
env::current_dir().unwrap().as_os_str().to_str().unwrap()
),
format!(
"{}/resources/longparams.json",
env::current_dir().unwrap().as_os_str().to_str().unwrap()
Expand Down
168 changes: 168 additions & 0 deletions rust/fastsim-core/resources/vehicles/2017_Toyota_Highlander_3.5_L.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
---
scenario_name: 2017 Toyota Highlander 3.5 L
selection: 0
veh_year: 2017
veh_pt_type: Conv
drag_coef: 0.1966
frontal_area_m2: 6.0
glider_kg: 791.0702892
veh_cg_m: 0.53
drive_axle_weight_frac: 0.59
wheel_base_m: 2.72
cargo_kg: 136.0
veh_override_kg: 2270.0
comp_mass_multiplier: 1.4
fs_max_kw: 1000.0
fs_secs_to_peak_pwr: 1.0
fs_kwh: 590.0
fs_kwh_per_kg: 9.89473291
fc_max_kw: 220.0
fc_pwr_out_perc:
v: 1
dim:
- 12
data:
- 0.0
- 0.005
- 0.015
- 0.04
- 0.06
- 0.1
- 0.14
- 0.2
- 0.4
- 0.6
- 0.8
- 1.0
fc_eff_map:
v: 1
dim:
- 12
data:
- 0.1
- 0.12
- 0.16
- 0.22
- 0.28
- 0.33
- 0.35
- 0.36
- 0.35
- 0.34
- 0.32
- 0.3
fc_eff_type: SI
fc_sec_to_peak_pwr: 6.0
fc_base_kg: 61.0
fc_kw_per_kg: 0.47
min_fc_time_on: 30.0
idle_fc_kw: 0.0
mc_max_kw: 0.0
mc_pwr_out_perc:
v: 1
dim:
- 11
data:
- 0.0
- 0.02
- 0.04
- 0.06
- 0.08
- 0.1
- 0.2
- 0.4
- 0.6
- 0.8
- 1.0
mc_eff_map:
v: 1
dim:
- 11
data:
- 0.12
- 0.16
- 0.21
- 0.29
- 0.35
- 0.42
- 0.75
- 0.92
- 0.93
- 0.93
- 0.92
mc_sec_to_peak_pwr: 5.0
mc_pe_kg_per_kw: 0.83
mc_pe_base_kg: 21.6
ess_max_kw: 0.0
ess_max_kwh: 0.0
ess_kg_per_kwh: 44.0
ess_base_kg: 0.0
ess_round_trip_eff: 0.834
ess_life_coef_a: 110.0
ess_life_coef_b: -0.68
min_soc: 0.4
max_soc: 0.8
ess_dischg_to_fc_max_eff_perc: 0.0
ess_chg_to_fc_max_eff_perc: 0.0
wheel_inertia_kg_m2: 0.82
num_wheels: 4.0
wheel_rr_coef: 0.009449
wheel_radius_m: 0.326
wheel_coef_of_fric: 0.7
max_accel_buffer_mph: 60.0
max_accel_buffer_perc_of_useable_soc: 0.2
perc_high_acc_buf: 0.0
mph_fc_on: 47.0
kw_demand_fc_on: 100.0
max_regen: 0.9
stop_start: false
force_aux_on_fc: false
alt_eff: 1.0
chg_eff: 0.86
aux_kw: 0.7
trans_kg: 114.0
trans_eff: 0.875
ess_to_fuel_ok_error: 0.005
small_motor_power_kw: 7.5
large_motor_power_kw: 75.0
regen_a: 500.0
regen_b: 0.99
charging_on: false
max_roadway_chg_kw:
v: 1
dim:
- 6
data:
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
modern_max: 0.95
veh_kg: 2270.0
max_trac_mps2: 3.5652415399547075
ess_mass_kg: 0.0
mc_mass_kg: 0.0
fc_mass_kg: 0.0
fs_mass_kg: 0.0
val_udds_mpgge: 22.0
val_hwy_mpgge: 32.0
val_comb_mpgge: 25.6
val_udds_kwh_per_mile: .nan
val_hwy_kwh_per_mile: .nan
val_comb_kwh_per_mile: .nan
val_cd_range_mi: .nan
val_const65_mph_kwh_per_mile: .nan
val_const60_mph_kwh_per_mile: .nan
val_const55_mph_kwh_per_mile: .nan
val_const45_mph_kwh_per_mile: .nan
val_unadj_udds_kwh_per_mile: .nan
val_unadj_hwy_kwh_per_mile: .nan
val0_to60_mph: .nan
val_ess_life_miles: .nan
val_range_miles: .nan
val_veh_base_cost: .nan
val_msrp: .nan
fc_peak_eff_override: ~
mc_peak_eff_override: ~
1 change: 1 addition & 0 deletions rust/fastsim-core/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ mod tests {
use crate::imports::SerdeAPI;

#[test]
#[cfg(feature = "resources")]
fn test_list_resources() {
let cyc_resource_list = crate::cycle::RustCycle::list_resources();
assert!(cyc_resource_list.len() == 3);
Expand Down

0 comments on commit 0577b9b

Please sign in to comment.