Skip to content

Commit

Permalink
fixup! editoast: add stdcm v2 endpoint for editoast
Browse files Browse the repository at this point in the history
  • Loading branch information
younesschrifi committed May 13, 2024
1 parent e6cb4aa commit 5e3136d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
10 changes: 8 additions & 2 deletions editoast/src/core/v2/stdcm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;

use crate::core::pathfinding::PathfindingResponse;
use crate::core::v2::simulation::RoutingRequirement;
use crate::core::v2::simulation::SpacingRequirement;
use chrono::DateTime;
Expand Down Expand Up @@ -45,7 +46,7 @@ pub struct STDCMRequest {
pub rolling_stock: PhysicsRollingStock,

// STDCM search parameters
pub train_requirements: HashMap<i64, TrainRequirement>,
pub trains_requirements: HashMap<i64, TrainRequirement>,
/// Numerical integration time step in milliseconds. Use default value if not specified.
pub time_step: Option<u64>,
pub start_time: DateTime<Utc>,
Expand Down Expand Up @@ -88,7 +89,12 @@ pub enum STDCMResponse {
path: PathfindingResultSuccess,
departure_time: DateTime<Utc>,
},
NotFound,
PathNotFound {
pathfinding_failure: PathfindingResponse,
},
SimulationNotFound {
simulation_failure: SimulationResponse,
},
}

impl AsCoreRequest<Json<STDCMResponse>> for STDCMRequest {
Expand Down
18 changes: 12 additions & 6 deletions editoast/src/views/v2/timetable/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use serde::Serialize;
use std::collections::HashMap;
use std::sync::Arc;
use thiserror::Error;
use utoipa::IntoParams;
use utoipa::ToSchema;

use crate::core::v2::simulation::SimulationResponse;
Expand Down Expand Up @@ -115,6 +116,11 @@ const fn default_maximum_run_time() -> u64 {
TWELVE_HOURS_IN_MILLISECONDS
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, IntoParams, ToSchema)]
pub struct InfraIdQueryParam {
infra: i64,
}

/// Compute a STDCM and return the simulation result
#[utoipa::path(
tag = "stdcm",
Expand All @@ -132,17 +138,17 @@ async fn stdcm(
redis_client: Data<RedisClient>,
core_client: Data<CoreClient>,
id: Path<i64>,
infra: Query<i64>,
query: Query<InfraIdQueryParam>,
data: Json<STDCMRequestPayload>,
) -> Result<Json<STDCMResponse>> {
let conn = &mut db_pool.clone().get().await?;
let db_pool = db_pool.into_inner();
let core_client = core_client.into_inner();
let timetable_id = id.into_inner();
let infra_id = infra.into_inner();
let infra_id = query.into_inner().infra;
let data = data.into_inner();

// 1. Retrieve Timetable / Infra / Trains / Simultion / Rolling Stock
// 1. Retrieve Timetable / Infra / Trains / Simulation / Rolling Stock
let timetable = TimetableWithTrains::retrieve_or_fail(conn, timetable_id, || {
StdcmError::TimetableNotFound { timetable_id }
})
Expand Down Expand Up @@ -170,13 +176,13 @@ async fn stdcm(
.await?;

// 2. Build core request
let mut train_requirements = HashMap::new();
let mut trains_requirements = HashMap::new();
for (train, sim) in trains.iter().zip(simulations) {
let final_output = match sim {
SimulationResponse::Success { final_output, .. } => final_output,
_ => continue,
};
train_requirements.insert(
trains_requirements.insert(
train.id,
TrainRequirement {
start_time: train.start_time,
Expand All @@ -203,7 +209,7 @@ async fn stdcm(
comfort: data.comfort,
path_items,
start_time: data.start_time,
train_requirements,
trains_requirements,
maximum_departure_delay: Some(data.maximum_departure_delay),
maximum_run_time: data.maximum_run_time,
speed_limit_tag: data.speed_limit_tags,
Expand Down

0 comments on commit 5e3136d

Please sign in to comment.