Skip to content

Commit

Permalink
core: stdcm: fix how we access the next stop duration
Browse files Browse the repository at this point in the history
  • Loading branch information
eckter authored and younesschrifi committed May 15, 2024
1 parent 4222bfa commit 31078d8
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 103 deletions.
2 changes: 1 addition & 1 deletion core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMEdge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ data class STDCMEdge(
)
} else {
// New edge on the same block, after a stop
val stopDuration = graph.steps[waypointIndex + 1].duration!!
val stopDuration = graph.getFirstStopAfterIndex(waypointIndex)!!.duration!!
STDCMNode(
totalTime + timeStart + stopDuration,
endSpeed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ internal constructor(
getStopOnBlock(graph, infraExplorer.getCurrentBlock(), startOffset, waypointIndex) !=
null
if (!endAtStop) return null
return graph.steps[waypointIndex + 1].duration!!
return graph.getFirstStopAfterIndex(waypointIndex)!!.duration!!
}

/** Creates a single STDCM edge, adding the given amount of delay */
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,9 @@ class STDCMGraph(
}
return res
}

/** Returns the first step with a stop after the given index, if any. */
fun getFirstStopAfterIndex(i: Int): STDCMStep? {
return steps.withIndex().firstOrNull { it.index > i && it.value.stop }?.value
}
}
184 changes: 104 additions & 80 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,10 @@ components:
- $ref: '#/components/schemas/EditoastRollingStockErrorNameAlreadyUsed'
- $ref: '#/components/schemas/EditoastRollingStockErrorRollingStockIsLocked'
- $ref: '#/components/schemas/EditoastRollingStockErrorRollingStockIsUsed'
- $ref: '#/components/schemas/EditoastSTDCMErrorInfraNotFound'
- $ref: '#/components/schemas/EditoastSTDCMErrorInvalidPathItem'
- $ref: '#/components/schemas/EditoastSTDCMErrorRollingStockNotFound'
- $ref: '#/components/schemas/EditoastSTDCMErrorTimetableNotFound'
- $ref: '#/components/schemas/EditoastScenarioErrorInfraNotFound'
- $ref: '#/components/schemas/EditoastScenarioErrorNotFound'
- $ref: '#/components/schemas/EditoastScenarioErrorNotFound'
Expand All @@ -896,10 +900,6 @@ components:
- $ref: '#/components/schemas/EditoastSpriteErrorsFileNotFound'
- $ref: '#/components/schemas/EditoastSpriteErrorsUnknownSignalingSystem'
- $ref: '#/components/schemas/EditoastStdcmErrorInfraNotFound'
- $ref: '#/components/schemas/EditoastStdcmErrorInfraNotFound'
- $ref: '#/components/schemas/EditoastStdcmErrorInvalidPathItem'
- $ref: '#/components/schemas/EditoastStdcmErrorRollingStockNotFound'
- $ref: '#/components/schemas/EditoastStdcmErrorTimetableNotFound'
- $ref: '#/components/schemas/EditoastStudyErrorNotFound'
- $ref: '#/components/schemas/EditoastStudyErrorStartDateAfterEndDate'
- $ref: '#/components/schemas/EditoastTimetableErrorInfraNotFound'
Expand Down Expand Up @@ -2025,6 +2025,105 @@ components:
- status
- message
type: object
EditoastSTDCMErrorInfraNotFound:
properties:
context:
properties:
infra_id:
type: integer
required:
- infra_id
type: object
message:
type: string
status:
enum:
- 400
type: integer
type:
enum:
- editoast:stdcm_v2:InfraNotFound
type: string
required:
- type
- status
- message
type: object
EditoastSTDCMErrorInvalidPathItem:
properties:
context:
properties:
index:
type: integer
path_item:
type: object
required:
- index
- path_item
type: object
message:
type: string
status:
enum:
- 400
type: integer
type:
enum:
- editoast:stdcm_v2:InvalidPathItem
type: string
required:
- type
- status
- message
type: object
EditoastSTDCMErrorRollingStockNotFound:
properties:
context:
properties:
rolling_stock_id:
type: integer
required:
- rolling_stock_id
type: object
message:
type: string
status:
enum:
- 400
type: integer
type:
enum:
- editoast:stdcm_v2:RollingStockNotFound
type: string
required:
- type
- status
- message
type: object
EditoastSTDCMErrorTimetableNotFound:
properties:
context:
properties:
timetable_id:
type: integer
required:
- timetable_id
type: object
message:
type: string
status:
enum:
- 404
type: integer
type:
enum:
- editoast:stdcm_v2:TimetableNotFound
type: string
required:
- type
- status
- message
type: object
EditoastScenarioErrorInfraNotFound:
properties:
context:
Expand Down Expand Up @@ -2410,88 +2509,13 @@ components:
type: object
message:
type: string
status:
enum:
- 400
type: integer
type:
enum:
- editoast:stdcm_v2:InfraNotFound
type: string
required:
- type
- status
- message
type: object
EditoastStdcmErrorInvalidPathItem:
properties:
context:
properties:
index:
type: integer
path_item:
type: object
required:
- index
- path_item
type: object
message:
type: string
status:
enum:
- 400
type: integer
type:
enum:
- editoast:stdcm_v2:InvalidPathItem
type: string
required:
- type
- status
- message
type: object
EditoastStdcmErrorRollingStockNotFound:
properties:
context:
properties:
rolling_stock_id:
type: integer
required:
- rolling_stock_id
type: object
message:
type: string
status:
enum:
- 400
type: integer
type:
enum:
- editoast:stdcm_v2:RollingStockNotFound
type: string
required:
- type
- status
- message
type: object
EditoastStdcmErrorTimetableNotFound:
properties:
context:
properties:
timetable_id:
type: integer
required:
- timetable_id
type: object
message:
type: string
status:
enum:
- 404
type: integer
type:
enum:
- editoast:stdcm_v2:TimetableNotFound
- editoast:stdcm:InfraNotFound
type: string
required:
- type
Expand Down
2 changes: 2 additions & 0 deletions editoast/src/core/v2/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ pub struct SimulationRequest {
#[allow(clippy::large_enum_variant)]
pub enum SimulationResponse {
Success {
/// Simulation without any regularity margins
#[schema(value_type = ReportTrainV2)]
base: ReportTrain,
/// Simulation that takes into account the regularity margins
#[schema(value_type = ReportTrainV2)]
provisional: ReportTrain,
#[schema(inline)]
Expand Down
25 changes: 12 additions & 13 deletions editoast/src/views/v2/timetable/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ editoast_common::schemas! {

#[derive(Debug, Error, EditoastError, Serialize)]
#[editoast_error(base_id = "stdcm_v2")]
#[allow(clippy::enum_variant_names)]
enum StdcmError {
#[error("Infra {infra_id} does not exist")]
enum STDCMError {
#[error("Infrastrcture {infra_id} does not exist")]
InfraNotFound { infra_id: i64 },
#[error("Timetable {timetable_id} does not exist")]
#[editoast_error(status = 404)]
Expand Down Expand Up @@ -99,11 +98,11 @@ pub struct STDCMRequestPayload {
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, ToSchema)]
pub struct PathfindingItem {
struct PathfindingItem {
/// The stop duration in milliseconds, None if the train does not stop.
pub duration: Option<u64>,
duration: Option<u64>,
/// The associated location
pub location: PathItemLocation,
location: PathItemLocation,
}

const TWO_HOURS_IN_MILLISECONDS: u64 = 2 * 60 * 60 * 60;
Expand All @@ -117,7 +116,7 @@ const fn default_maximum_run_time() -> u64 {
}

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

Expand Down Expand Up @@ -150,12 +149,12 @@ async fn stdcm(

// 1. Retrieve Timetable / Infra / Trains / Simulation / Rolling Stock
let timetable = TimetableWithTrains::retrieve_or_fail(conn, timetable_id, || {
StdcmError::TimetableNotFound { timetable_id }
STDCMError::TimetableNotFound { timetable_id }
})
.await?;

let infra =
Infra::retrieve_or_fail(conn, infra_id, || StdcmError::InfraNotFound { infra_id }).await?;
Infra::retrieve_or_fail(conn, infra_id, || STDCMError::InfraNotFound { infra_id }).await?;

let (trains, _): (Vec<_>, _) = TrainSchedule::retrieve_batch(conn, timetable.train_ids).await?;

Expand All @@ -169,7 +168,7 @@ async fn stdcm(
.await?;

let rolling_stock = RollingStockModel::retrieve_or_fail(conn, data.rolling_stock_id, || {
StdcmError::RollingStockNotFound {
STDCMError::RollingStockNotFound {
rolling_stock_id: data.rolling_stock_id,
}
})
Expand Down Expand Up @@ -238,7 +237,7 @@ async fn parse_stdcm_steps(

let conn = &mut db_pool.get().await?;
let track_offsets = extract_location_from_path_items(conn, infra.id, &locations).await?;
let track_offsets = track_offsets.map_err::<StdcmError, _>(|err| err.into())?;
let track_offsets = track_offsets.map_err::<STDCMError, _>(|err| err.into())?;

Ok(track_offsets
.iter()
Expand All @@ -250,9 +249,9 @@ async fn parse_stdcm_steps(
.collect())
}

impl From<TrackOffsetExtractionError> for StdcmError {
impl From<TrackOffsetExtractionError> for STDCMError {
fn from(error: TrackOffsetExtractionError) -> Self {
StdcmError::InvalidPathItem {
STDCMError::InvalidPathItem {
index: error.index,
path_item: error.path_item,
}
Expand Down
8 changes: 4 additions & 4 deletions front/public/locales/en/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@
"InfraNotFound": "Infra {{infra_id}} does not exist"
},
"stdcm_v2": {
"InfraNotFound": "Infra {{infra_id}} does not exist",
"InvalidPathItem": "Path item {{index}} is invalid",
"RollingStockNotFound": "Rolling stock {{rolling_stock_id} does not exist",
"TimetableNotFound": "Timetable {{timetable_id}} does not exist"
"InfraNotFound": "Infrastructure '{{infra_id}}' does not exist",
"InvalidPathItem": "Path item '{{index}}' is invalid",
"RollingStockNotFound": "Rolling stock '{{rolling_stock_id}}' does not exist",
"TimetableNotFound": "Timetable '{{timetable_id}}' does not exist"
},
"study": {
"NotFound": "Study '{{study_id}}' could not be found",
Expand Down
8 changes: 4 additions & 4 deletions front/public/locales/fr/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@
"InfraNotFound": "Infrastructure {{infra_id}} non trouvée"
},
"stdcm_v2": {
"InfraNotFound": "Infrastructure {{infra_id}} non trouvée",
"InvalidPathItem": "Élément {{index}} du chemin non valide",
"RollingStockNotFound": "Matériel roulant {{rolling_stock_id} non trouvé",
"TimetableNotFound": "Grille horaire {{timetable_id}} non trouvée"
"InfraNotFound": "Infrastructure '{{infra_id}}' non trouvée",
"InvalidPathItem": "Élément '{{index}}' du chemin non valide",
"RollingStockNotFound": "Matériel roulant '{{rolling_stock_id}}' non trouvé",
"TimetableNotFound": "Grille horaire '{{timetable_id}}' non trouvée"
},
"study": {
"NotFound": "Etude '{{study_id}}' non trouvée",
Expand Down

0 comments on commit 31078d8

Please sign in to comment.