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

editoast: PacedTrain: add simulation summary and simulation endpoints #11022

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
39 changes: 32 additions & 7 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5140,9 +5140,10 @@ components:
- $ref: '#/components/schemas/EditoastOperationErrorInvalidPatch'
- $ref: '#/components/schemas/EditoastOperationErrorModifyId'
- $ref: '#/components/schemas/EditoastOperationErrorObjectNotFound'
- $ref: '#/components/schemas/EditoastPacedTrainErrorBatchPacedTrainNotFound'
- $ref: '#/components/schemas/EditoastPacedTrainErrorBatchNotFound'
- $ref: '#/components/schemas/EditoastPacedTrainErrorDatabase'
- $ref: '#/components/schemas/EditoastPacedTrainErrorPacedTrainNotFound'
- $ref: '#/components/schemas/EditoastPacedTrainErrorInfraNotFound'
- $ref: '#/components/schemas/EditoastPacedTrainErrorNotFound'
- $ref: '#/components/schemas/EditoastPaginationErrorInvalidPage'
- $ref: '#/components/schemas/EditoastPaginationErrorInvalidPageSize'
- $ref: '#/components/schemas/EditoastPathfindingErrorInfraNotFound'
Expand Down Expand Up @@ -5637,7 +5638,7 @@ components:
type: string
enum:
- editoast:operation:ObjectNotFound
EditoastPacedTrainErrorBatchPacedTrainNotFound:
EditoastPacedTrainErrorBatchNotFound:
type: object
required:
- type
Expand All @@ -5660,7 +5661,7 @@ components:
type:
type: string
enum:
- editoast:paced_train:BatchPacedTrainNotFound
- editoast:paced_train:BatchNotFound
EditoastPacedTrainErrorDatabase:
type: object
required:
Expand All @@ -5680,7 +5681,31 @@ components:
type: string
enum:
- editoast:paced_train:Database
EditoastPacedTrainErrorPacedTrainNotFound:
EditoastPacedTrainErrorInfraNotFound:
type: object
required:
- type
- status
- message
properties:
context:
type: object
required:
- infra_id
properties:
infra_id:
type: integer
message:
type: string
status:
type: integer
enum:
- 404
type:
type: string
enum:
- editoast:paced_train:InfraNotFound
EditoastPacedTrainErrorNotFound:
type: object
required:
- type
Expand All @@ -5703,7 +5728,7 @@ components:
type:
type: string
enum:
- editoast:paced_train:PacedTrainNotFound
- editoast:paced_train:NotFound
EditoastPaginationErrorInvalidPage:
type: object
required:
Expand Down Expand Up @@ -8570,7 +8595,7 @@ components:
timetable_id:
type: integer
format: int64
description: Timetable attached to the train schedule
description: Timetable attached to the paced train
nullable: true
PacedTrainResult:
allOf:
Expand Down
23 changes: 23 additions & 0 deletions editoast/src/models/paced_train.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::models::train_schedule::TrainSchedule;
use chrono::DateTime;
use chrono::Duration as ChronoDuration;
use chrono::Utc;
Expand Down Expand Up @@ -50,6 +51,28 @@ pub struct PacedTrain {
pub step: ChronoDuration,
}

impl PacedTrain {
pub fn into_first_occurrence(self) -> TrainSchedule {
TrainSchedule {
id: self.id,
train_name: self.train_name,
labels: self.labels.into(),
rolling_stock_name: self.rolling_stock_name,
timetable_id: self.timetable_id,
path: self.path,
start_time: self.start_time,
schedule: self.schedule,
margins: self.margins,
initial_speed: self.initial_speed,
comfort: self.comfort,
constraint_distribution: self.constraint_distribution,
speed_limit_tag: self.speed_limit_tag,
power_restrictions: self.power_restrictions,
options: self.options,
}
}
}

impl From<PacedTrainBase> for PacedTrainChangeset {
fn from(
PacedTrainBase {
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/views/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ pub struct InfraIdQueryParam {
infra_id: i64,
}

#[derive(Debug, Serialize, ToSchema)]
#[derive(Debug, PartialEq, Serialize, Deserialize, ToSchema)]
#[serde(tag = "status", rename_all = "snake_case")]
enum SimulationSummaryResult {
pub enum SimulationSummaryResult {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to change the visibility? If I understand correctly, it's only used in submodules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also need it for tests.

/// Minimal information on a simulation's result
Success {
/// Length of a path in mm
Expand Down
Loading
Loading