Skip to content

Commit

Permalink
Merge pull request #80 from NREL/apply-clippy-fix
Browse files Browse the repository at this point in the history
Apply `cargo clippy --fix`
  • Loading branch information
calbaker authored Dec 13, 2023
2 parents 08c12cc + acb73e2 commit c8671fc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion rust/fastsim-cli/tests/integration-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn test_that_cli_app_produces_result() {

#[test]
fn test_that_adopt_hd_option_works_as_expected() {
let expected_results = vec![
let expected_results = [
("adoptstring.json", "0.245"), // 0.245 kWh/mile
("adoptstring2.json", "7.906"), // 7.906 mpgge
("adoptstring3.json", "6.882"), // 6.882 mpgge
Expand Down
22 changes: 11 additions & 11 deletions rust/fastsim-core/src/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,22 +497,22 @@ impl RustCycleCache {
#[staticmethod]
pub fn from_dict(dict: &PyDict) -> anyhow::Result<Self> {
let time_s = Array::from_vec(PyAny::get_item(&dict, "time_s")?.extract()?);
let time_s = Array::from_vec(PyAny::get_item(dict, "time_s")?.extract()?);
let cyc_len = time_s.len();
Ok(Self {
time_s,
mps: Array::from_vec(PyAny::get_item(&dict, "mps")?.extract()?),
grade: if let Ok(value) = PyAny::get_item(&dict, "grade") {
mps: Array::from_vec(PyAny::get_item(dict, "mps")?.extract()?),
grade: if let Ok(value) = PyAny::get_item(dict, "grade") {
Array::from_vec(value.extract()?)
} else {
Array::default(cyc_len)
},
road_type: if let Ok(value) = PyAny::get_item(&dict, "road_type") {
road_type: if let Ok(value) = PyAny::get_item(dict, "road_type") {
Array::from_vec(value.extract()?)
} else {
Array::default(cyc_len)
},
name: PyAny::get_item(&dict, "name").and_then(String::extract).unwrap_or_default(),
name: PyAny::get_item(dict, "name").and_then(String::extract).unwrap_or_default(),
orphaned: false,
})
}
Expand Down Expand Up @@ -765,13 +765,13 @@ impl TryFrom<HashMap<String, Vec<f64>>> for RustCycle {
}
}

impl Into<HashMap<String, Vec<f64>>> for RustCycle {
fn into(self) -> HashMap<String, Vec<f64>> {
impl From<RustCycle> for HashMap<String, Vec<f64>> {
fn from(cyc: RustCycle) -> Self {
HashMap::from([
("time_s".into(), self.time_s.to_vec()),
("mps".into(), self.mps.to_vec()),
("grade".into(), self.grade.to_vec()),
("road_type".into(), self.road_type.to_vec()),
("time_s".into(), cyc.time_s.to_vec()),
("mps".into(), cyc.mps.to_vec()),
("grade".into(), cyc.grade.to_vec()),
("road_type".into(), cyc.road_type.to_vec()),
])
}
}
Expand Down
5 changes: 2 additions & 3 deletions rust/fastsim-core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,11 @@ pub fn multilinear(point: &[f64], grid: &[Vec<f64>], values: &ArrayD<f64>) -> an
Slice::from(lower..=lower + 1)
})
.to_owned();
let mut index_permutations = get_index_permutations(&interp_vals.shape());
let mut index_permutations = get_index_permutations(interp_vals.shape());
// This loop interpolates in each dimension sequentially
// each outer loop iteration the dimensionality reduces by 1
// `interp_vals` ends up as a 0-dimensional array containing only the final interpolated value
for dim in 0..n {
let diff = interp_diffs[dim];
for (dim, diff) in interp_diffs.iter().enumerate() {
let next_dim = n - 1 - dim;
let next_shape = vec![2; next_dim];
// Indeces used for saving results of this dimensions interpolation results
Expand Down
6 changes: 3 additions & 3 deletions rust/fastsim-core/src/vehicle_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ fn read_fuelecon_gov_emissions_to_hashmap(
if let Some(item) = ok_result {
if let Some(id_str) = item.get("id") {
if let Ok(id) = str::parse::<u32>(id_str) {
output.entry(id).or_insert_with(Vec::new);
output.entry(id).or_default();
if let Some(ers) = output.get_mut(&id) {
let emiss = EmissionsInfoFE {
efid: item.get("efid").unwrap().clone(),
Expand Down Expand Up @@ -1463,7 +1463,7 @@ pub fn get_fastsim_data_dir() -> Option<PathBuf> {
pub fn extract_zip(filepath: &Path, dest_dir: &Path) -> Result<(), anyhow::Error> {
let f = File::open(filepath)?;
let mut zip = zip::ZipArchive::new(f)?;
zip.extract(&dest_dir)?;
zip.extract(dest_dir)?;
Ok(())
}

Expand All @@ -1489,7 +1489,7 @@ pub fn download_file_from_url(url: &str, file_path: &Path) -> Result<(), anyhow:
return Err(anyhow!("No data available from {url}"));
}
{
let mut file = match File::create(&file_path) {
let mut file = match File::create(file_path) {
Err(why) => {
return Err(anyhow!(
"couldn't open {}: {}",
Expand Down

0 comments on commit c8671fc

Please sign in to comment.