Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve energy model error #27

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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