Skip to content

Commit

Permalink
Merge pull request #27 from NREL/ndr/energy-model-error
Browse files Browse the repository at this point in the history
Improve energy model error
  • Loading branch information
nreinicke authored Nov 10, 2023
2 parents f3ea12b + ce42163 commit d1468e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/notebooks/open_street_maps_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"\n",
"The energy cost coefficient indicates how much we should factor energy into our route search, 0.0 indicating that we should not factor in energy at all (shortest time route) and 1.0 indicating that we should only factor energy in (least energy route)\n",
"\n",
"The `model_name` parameter specifies which energy model to use. This can anything that was included in the config as a ``[traveral.energy_models]]` section. We'll use the 2016 Toyota Camry."
"The `model_name` parameter specifies which energy model to use. This can anything that was included in the config as a `[[traveral.energy_models]]` section. We'll use the 2016 Toyota Camry."
]
},
{
Expand Down Expand Up @@ -807,7 +807,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.0"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
17 changes: 5 additions & 12 deletions rust/routee-compass-powertrain/src/routee/speed_grade_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ use std::sync::Arc;

const ZERO_ENERGY: f64 = 1e-9;

const NO_MODEL_NAME_ERROR: &str = r#"
Expected key 'model_name' in requeset to specify which routee-powertrain model to use.
Try adding the following to your request:
{
"model_name": "2016_TOYOTA_Camry_4cyl_2WD"
}
"#;

pub struct SpeedGradeModel {
pub service: Arc<SpeedGradeModelService>,
pub model_record: Arc<SpeedGradePredictionModelRecord>,
Expand Down Expand Up @@ -174,7 +166,7 @@ impl TryFrom<(Arc<SpeedGradeModelService>, &serde_json::Value)> for SpeedGradeMo
let prediction_model_name = conf
.get("model_name".to_string())
.ok_or(TraversalModelError::BuildError(
NO_MODEL_NAME_ERROR.to_string(),
"No 'model_name' key provided in query".to_string(),
))?
.as_str()
.ok_or(TraversalModelError::BuildError(
Expand All @@ -184,10 +176,11 @@ impl TryFrom<(Arc<SpeedGradeModelService>, &serde_json::Value)> for SpeedGradeMo

let model_record = match service.energy_model_library.get(&prediction_model_name) {
None => {
let model_names: Vec<&String> = service.energy_model_library.keys().collect();
return Err(TraversalModelError::BuildError(format!(
"No energy model found with name {}",
prediction_model_name
)))
"No energy model found with model_name = '{}', try one of: {:?}",
prediction_model_name, model_names
)));
}
Some(mr) => mr.clone(),
};
Expand Down

0 comments on commit d1468e7

Please sign in to comment.