Skip to content

Commit 34b84f6

Browse files
committed
editoast: prepare paced train endpoints
Signed-off-by: Youness CHRIFI ALAOUI <[email protected]>
1 parent e41cf30 commit 34b84f6

File tree

7 files changed

+1188
-616
lines changed

7 files changed

+1188
-616
lines changed

editoast/openapi.yaml

+225
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,173 @@ paths:
15391539
responses:
15401540
'204':
15411541
description: All paced_trains have been deleted
1542+
/paced_train/project_path:
1543+
post:
1544+
tags:
1545+
- paced_train
1546+
summary: Projects the space time curves and paths of a number of paced trains onto a given path
1547+
description: |-
1548+
- Returns 404 if the infra or any of the paced trains are not found
1549+
- Returns 200 with a hashmap of train_id to ProjectPathTrainResult
1550+
1551+
Paced trains that are invalid (pathfinding or simulation failed) are not included in the result
1552+
requestBody:
1553+
content:
1554+
application/json:
1555+
schema:
1556+
$ref: '#/components/schemas/ProjectPathForm'
1557+
required: true
1558+
responses:
1559+
'200':
1560+
description: Project Path Output
1561+
content:
1562+
application/json:
1563+
schema:
1564+
type: object
1565+
additionalProperties:
1566+
$ref: '#/components/schemas/ProjectPathTrainResult'
1567+
/paced_train/simulation_summary:
1568+
post:
1569+
tags:
1570+
- paced_train
1571+
summary: Associate each paced train id with its simulation summaries response
1572+
description: 'If the simulation fails, it associates the reason: pathfinding failed or running time failed'
1573+
requestBody:
1574+
content:
1575+
application/json:
1576+
schema:
1577+
type: object
1578+
required:
1579+
- infra_id
1580+
- ids
1581+
properties:
1582+
electrical_profile_set_id:
1583+
type: integer
1584+
format: int64
1585+
nullable: true
1586+
ids:
1587+
type: array
1588+
items:
1589+
type: integer
1590+
format: int64
1591+
uniqueItems: true
1592+
infra_id:
1593+
type: integer
1594+
format: int64
1595+
required: true
1596+
responses:
1597+
'200':
1598+
description: Associate each paced train id with its simulation summaries
1599+
content:
1600+
application/json:
1601+
schema:
1602+
type: object
1603+
additionalProperties:
1604+
$ref: '#/components/schemas/SimulationSummaryResult'
1605+
/paced_train/{id}:
1606+
get:
1607+
tags:
1608+
- timetable
1609+
- paced_train
1610+
summary: Get a paced train by its ID
1611+
parameters:
1612+
- name: id
1613+
in: path
1614+
required: true
1615+
schema:
1616+
type: integer
1617+
format: int64
1618+
responses:
1619+
'204':
1620+
description: The requested paced train
1621+
content:
1622+
application/json:
1623+
schema:
1624+
$ref: '#/components/schemas/PacedTrainResult'
1625+
put:
1626+
tags:
1627+
- timetable
1628+
- paced_train
1629+
parameters:
1630+
- name: id
1631+
in: path
1632+
required: true
1633+
schema:
1634+
type: integer
1635+
format: int64
1636+
requestBody:
1637+
content:
1638+
application/json:
1639+
schema:
1640+
$ref: '#/components/schemas/PacedTrainForm'
1641+
required: true
1642+
responses:
1643+
'200':
1644+
description: Paced train have been updated
1645+
content:
1646+
application/json:
1647+
schema:
1648+
$ref: '#/components/schemas/PacedTrainResult'
1649+
/paced_train/{id}/path:
1650+
get:
1651+
tags:
1652+
- paced_train
1653+
- pathfinding
1654+
summary: Get a path from a paced train given an infrastructure id and a paced train id
1655+
parameters:
1656+
- name: id
1657+
in: path
1658+
required: true
1659+
schema:
1660+
type: integer
1661+
format: int64
1662+
- name: infra_id
1663+
in: query
1664+
required: true
1665+
schema:
1666+
type: integer
1667+
format: int64
1668+
responses:
1669+
'200':
1670+
description: The path
1671+
content:
1672+
application/json:
1673+
schema:
1674+
$ref: '#/components/schemas/PathfindingResult'
1675+
'404':
1676+
description: Infrastructure or Train schedule not found
1677+
/paced_train/{id}/simulation:
1678+
get:
1679+
tags:
1680+
- train_schedule
1681+
summary: Retrieve the space, speed and time curve of a given train
1682+
parameters:
1683+
- name: id
1684+
in: path
1685+
required: true
1686+
schema:
1687+
type: integer
1688+
format: int64
1689+
- name: infra_id
1690+
in: query
1691+
required: true
1692+
schema:
1693+
type: integer
1694+
format: int64
1695+
- name: electrical_profile_set_id
1696+
in: query
1697+
required: false
1698+
schema:
1699+
type: integer
1700+
format: int64
1701+
nullable: true
1702+
responses:
1703+
'200':
1704+
description: Simulation Output
1705+
content:
1706+
application/json:
1707+
schema:
1708+
$ref: '#/components/schemas/SimulationResponse'
15421709
/projects:
15431710
get:
15441711
tags:
@@ -2765,6 +2932,54 @@ paths:
27652932
$ref: '#/components/schemas/TimetableResult'
27662933
'404':
27672934
description: Timetable not found
2935+
/timetable/paced_trains:
2936+
get:
2937+
tags:
2938+
- timetable
2939+
summary: Return a specific timetable with its associated paced trains
2940+
parameters:
2941+
- name: id
2942+
in: path
2943+
description: A timetable ID
2944+
required: true
2945+
schema:
2946+
type: integer
2947+
format: int64
2948+
- name: page
2949+
in: query
2950+
required: false
2951+
schema:
2952+
type: integer
2953+
format: int64
2954+
default: 1
2955+
minimum: 1
2956+
- name: page_size
2957+
in: query
2958+
required: false
2959+
schema:
2960+
type: integer
2961+
format: int64
2962+
default: 25
2963+
nullable: true
2964+
minimum: 1
2965+
responses:
2966+
'200':
2967+
description: Timetable with paced train ids
2968+
content:
2969+
application/json:
2970+
schema:
2971+
allOf:
2972+
- $ref: '#/components/schemas/PaginationStats'
2973+
- type: object
2974+
required:
2975+
- results
2976+
properties:
2977+
results:
2978+
type: array
2979+
items:
2980+
$ref: '#/components/schemas/PacedTrainResult'
2981+
'404':
2982+
description: Timetable not found
27682983
/timetable/{id}:
27692984
delete:
27702985
tags:
@@ -8419,6 +8634,16 @@ components:
84198634
type: string
84208635
description: Time between two occurrences, an ISO 8601 format is expected
84218636
example: PT15M
8637+
PacedTrainForm:
8638+
allOf:
8639+
- $ref: '#/components/schemas/PacedTrainBase'
8640+
- type: object
8641+
properties:
8642+
timetable_id:
8643+
type: integer
8644+
format: int64
8645+
description: Timetable attached to the train schedule
8646+
nullable: true
84228647
PacedTrainResult:
84238648
allOf:
84248649
- $ref: '#/components/schemas/PacedTrainBase'

editoast/src/views/mod.rs

+45
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod paced_train;
1010
pub mod pagination;
1111
pub mod params;
1212
pub mod path;
13+
pub mod projection;
1314
pub mod projects;
1415
pub mod rolling_stock;
1516
pub mod scenario;
@@ -69,15 +70,19 @@ use tower_http::trace::TraceLayer;
6970
use tracing::info;
7071
use tracing::warn;
7172
use url::Url;
73+
use utoipa::IntoParams;
7274
use utoipa::ToSchema;
7375

7476
use crate::client::get_app_version;
7577
use crate::core::mq_client;
78+
use crate::core::pathfinding::PathfindingInputError;
79+
use crate::core::pathfinding::PathfindingNotFound;
7680
use crate::core::version::CoreVersionRequest;
7781
use crate::core::AsCoreRequest;
7882
use crate::core::CoreClient;
7983
use crate::core::CoreError;
8084
use crate::core::{self};
85+
use crate::error::InternalError;
8186
use crate::error::Result;
8287
use crate::error::{self};
8388
use crate::generated_data;
@@ -122,6 +127,8 @@ crate::routes! {
122127

123128
editoast_common::schemas! {
124129
Version,
130+
SimulationSummaryResult,
131+
InfraIdQueryParam,
125132

126133
editoast_common::schemas(),
127134
editoast_schemas::schemas(),
@@ -140,6 +147,7 @@ editoast_common::schemas! {
140147
pagination::schemas(),
141148
path::schemas(),
142149
projects::schemas(),
150+
projection::schemas(),
143151
rolling_stock::schemas(),
144152
scenario::schemas(),
145153
scenario::macro_nodes::schemas(),
@@ -156,6 +164,43 @@ struct ListId {
156164
ids: HashSet<i64>,
157165
}
158166

167+
#[derive(Debug, Default, Clone, Serialize, Deserialize, IntoParams, ToSchema)]
168+
#[into_params(parameter_in = Query)]
169+
pub struct InfraIdQueryParam {
170+
infra_id: i64,
171+
}
172+
173+
#[derive(Debug, Serialize, ToSchema)]
174+
#[serde(tag = "status", rename_all = "snake_case")]
175+
enum SimulationSummaryResult {
176+
/// Minimal information on a simulation's result
177+
Success {
178+
/// Length of a path in mm
179+
length: u64,
180+
/// Travel time in ms
181+
time: u64,
182+
/// Total energy consumption of a train in kWh
183+
energy_consumption: f64,
184+
/// Final simulation time for each train schedule path item.
185+
/// The first value is always `0` (beginning of the path) and the last one, the total time of the simulation (end of the path)
186+
path_item_times_final: Vec<u64>,
187+
/// Provisional simulation time for each train schedule path item.
188+
/// The first value is always `0` (beginning of the path) and the last one, the total time of the simulation (end of the path)
189+
path_item_times_provisional: Vec<u64>,
190+
/// Base simulation time for each train schedule path item.
191+
/// The first value is always `0` (beginning of the path) and the last one, the total time of the simulation (end of the path)
192+
path_item_times_base: Vec<u64>,
193+
},
194+
/// Pathfinding not found
195+
PathfindingNotFound(PathfindingNotFound),
196+
/// An error has occurred during pathfinding
197+
PathfindingFailure { core_error: InternalError },
198+
/// An error has occurred during computing
199+
SimulationFailed { error_type: String },
200+
/// InputError
201+
PathfindingInputError(PathfindingInputError),
202+
}
203+
159204
/// Represents the bundle of information about the issuer of a request
160205
/// that can be extracted form recognized headers.
161206
#[derive(Debug, Clone)]

0 commit comments

Comments
 (0)