Skip to content

Commit

Permalink
editoast, front: import, filter and send to core temporary speed limits
Browse files Browse the repository at this point in the history
  - Add a temporary_speed_limits table creation migration script.
  - Add a temporary speed limit creation endpoint.
  - Add the active temporary speed limits which are active during
    an stdcm search to the stdcm request sent to core.

Signed-off-by: Sh099078 <[email protected]>
  • Loading branch information
Sh099078 committed Oct 2, 2024
1 parent b54cdb4 commit 9df74e1
Show file tree
Hide file tree
Showing 19 changed files with 687 additions and 17 deletions.
31 changes: 31 additions & 0 deletions editoast/editoast_models/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,34 @@ diesel::table! {
}
}

diesel::table! {
use diesel::sql_types::*;
use postgis_diesel::sql_types::*;

temporary_speed_limit (id) {
id -> Int8,
start_date_time -> Timestamptz,
end_date_time -> Timestamptz,
speed_limit -> Float8,
track_ranges -> Jsonb,
#[max_length = 255]
obj_id -> Varchar,
temporary_speed_limit_group_id -> Int8,
}
}

diesel::table! {
use diesel::sql_types::*;
use postgis_diesel::sql_types::*;

temporary_speed_limit_group (id) {
id -> Int8,
creation_date -> Timestamptz,
#[max_length = 255]
name -> Varchar,
}
}

diesel::table! {
use diesel::sql_types::*;
use postgis_diesel::sql_types::*;
Expand Down Expand Up @@ -749,6 +777,7 @@ diesel::joinable!(stdcm_search_environment -> infra (infra_id));
diesel::joinable!(stdcm_search_environment -> timetable (timetable_id));
diesel::joinable!(stdcm_search_environment -> work_schedule_group (work_schedule_group_id));
diesel::joinable!(study -> project (project_id));
diesel::joinable!(temporary_speed_limit -> temporary_speed_limit_group (temporary_speed_limit_group_id));
diesel::joinable!(train_schedule -> timetable (timetable_id));
diesel::joinable!(work_schedule -> work_schedule_group (work_schedule_group_id));

Expand Down Expand Up @@ -797,6 +826,8 @@ diesel::allow_tables_to_appear_in_same_query!(
search_track,
stdcm_search_environment,
study,
temporary_speed_limit,
temporary_speed_limit_group,
timetable,
train_schedule,
work_schedule,
Expand Down
2 changes: 2 additions & 0 deletions editoast/editoast_schemas/src/infra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ editoast_common::schemas! {
track_location::schemas(),
track_offset::schemas(),
track_section::schemas(),
track_range::schemas(),
directional_track_range::schemas(),
}
4 changes: 4 additions & 0 deletions editoast/editoast_schemas/src/infra/track_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

editoast_common::schemas! {
TrackRange,
}

#[derive(Debug, Derivative, Clone, Deserialize, Serialize, PartialEq, ToSchema)]
#[serde(deny_unknown_fields)]
#[derivative(Default)]
Expand Down
2 changes: 2 additions & 0 deletions editoast/migrations/2024-09-06-153144_add_ltv_table/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE temporary_speed_limit;
DROP TABLE temporary_speed_limit_group;
19 changes: 19 additions & 0 deletions editoast/migrations/2024-09-06-153144_add_ltv_table/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE TABLE temporary_speed_limit_group(
id int8 PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
creation_date timestamptz NOT NULL,
name varchar(255) NOT NULL UNIQUE
);

CREATE TABLE temporary_speed_limit (
id int8 PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
start_date_time timestamptz NOT NULL,
end_date_time timestamptz NOT NULL,
speed_limit float8 NOT NULL,
track_ranges jsonb NOT NULL,
obj_id VARCHAR(255) NOT NULL,
temporary_speed_limit_group_id int8 NOT NULL REFERENCES temporary_speed_limit_group(id) ON DELETE CASCADE,
CONSTRAINT valid_time_period CHECK (start_date_time < end_date_time)
);

CREATE INDEX "temporary_speed_limit_date_time" ON "temporary_speed_limit" ("start_date_time");
CREATE INDEX "temporary_speed_limit_end_date_time" ON "temporary_speed_limit" ("end_date_time");
88 changes: 88 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,61 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/StdcmSearchEnvironment'
/temporary_speed_limit_group:
post:
tags:
- temporary_speed_limits
requestBody:
content:
application/json:
schema:
type: object
required:
- speed_limit_group_name
- speed_limits
properties:
speed_limit_group_name:
type: string
speed_limits:
type: array
items:
type: object
required:
- start_date_time
- end_date_time
- track_ranges
- speed_limit
- obj_id
properties:
end_date_time:
type: string
format: date-time
obj_id:
type: string
speed_limit:
type: number
format: double
start_date_time:
type: string
format: date-time
track_ranges:
type: array
items:
$ref: '#/components/schemas/DirectionalTrackRange'
required: true
responses:
'201':
description: The id of the created temporary speed limit group.
content:
application/json:
schema:
type: object
required:
- group_id
properties:
group_id:
type: integer
format: int64
/timetable:
post:
tags:
Expand Down Expand Up @@ -2393,6 +2448,10 @@ paths:
type: array
items:
$ref: '#/components/schemas/PathfindingItem'
temporary_speed_limit_group_id:
type: integer
format: int64
nullable: true
time_gap_after:
type: integer
format: int64
Expand Down Expand Up @@ -3880,6 +3939,7 @@ components:
- $ref: '#/components/schemas/EditoastSpriteErrorsUnknownSignalingSystem'
- $ref: '#/components/schemas/EditoastStudyErrorNotFound'
- $ref: '#/components/schemas/EditoastStudyErrorStartDateAfterEndDate'
- $ref: '#/components/schemas/EditoastTemporarySpeedLimitErrorNameAlreadyUsed'
- $ref: '#/components/schemas/EditoastTimetableErrorInfraNotFound'
- $ref: '#/components/schemas/EditoastTimetableErrorNotFound'
- $ref: '#/components/schemas/EditoastTrainScheduleErrorBatchTrainScheduleNotFound'
Expand Down Expand Up @@ -5048,6 +5108,30 @@ components:
type: string
enum:
- editoast:study:StartDateAfterEndDate
EditoastTemporarySpeedLimitErrorNameAlreadyUsed:
type: object
required:
- type
- status
- message
properties:
context:
type: object
required:
- name
properties:
name:
type: string
message:
type: string
status:
type: integer
enum:
- 400
type:
type: string
enum:
- editoast:temporary_speed_limit:NameAlreadyUsed
EditoastTimetableErrorInfraNotFound:
type: object
required:
Expand Down Expand Up @@ -8199,6 +8283,10 @@ components:
type: array
items:
$ref: '#/components/schemas/PathfindingItem'
temporary_speed_limit_group_id:
type: integer
format: int64
nullable: true
time_gap_after:
type: integer
format: int64
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/core/conflict_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::core::{AsCoreRequest, Json};

use super::simulation::RoutingRequirement;
use super::simulation::SpacingRequirement;
use super::stdcm::LightWorkSchedule;
use super::stdcm::WorkSchedule;

editoast_common::schemas! {
ConflictDetectionResponse,
Expand Down Expand Up @@ -39,7 +39,7 @@ pub struct TrainRequirements {
#[derive(Debug, Serialize)]
pub struct WorkSchedulesRequest {
pub start_time: DateTime<Utc>,
pub work_schedule_requirements: HashMap<i64, LightWorkSchedule>,
pub work_schedule_requirements: HashMap<i64, WorkSchedule>,
}

#[derive(Debug, Deserialize, ToSchema)]
Expand Down
11 changes: 11 additions & 0 deletions editoast/src/core/pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ pub struct TrackRange {
pub direction: Direction,
}

impl From<editoast_schemas::infra::DirectionalTrackRange> for TrackRange {
fn from(value: editoast_schemas::infra::DirectionalTrackRange) -> Self {
TrackRange {
track_section: value.track,
begin: (value.begin * 1000.).round() as u64,
end: (value.end * 1000.).round() as u64,
direction: value.direction,
}
}
}

impl TrackRange {
#[cfg(test)]
/// Creates a new `TrackRange`.
Expand Down
18 changes: 15 additions & 3 deletions editoast/src/core/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use serde::Serialize;
use utoipa::ToSchema;

use super::pathfinding::PathfindingResultSuccess;
use super::pathfinding::TrackRange;
use super::simulation::PhysicsRollingStock;
use super::simulation::SimulationResponse;
use crate::core::{AsCoreRequest, Json};
Expand Down Expand Up @@ -55,7 +56,9 @@ pub struct STDCMRequest {
/// Margin to apply to the whole train
pub margin: Option<MarginValue>,
/// List of planned work schedules
pub work_schedules: Vec<LightWorkSchedule>,
pub work_schedules: Vec<WorkSchedule>,
/// List of applicable temporary speed limits between the train departure and arrival
pub temporary_speed_limits: Vec<TemporarySpeedLimit>,
}

#[derive(Debug, Serialize)]
Expand All @@ -79,9 +82,9 @@ pub struct STDCMStepTimingData {
pub arrival_time_tolerance_after: u64,
}

/// Lighter description of a work schedule, only contains what's relevant
/// Lighter description of a work schedule, with only the relevant information for core
#[derive(Debug, Serialize)]
pub struct LightWorkSchedule {
pub struct WorkSchedule {
/// Start time as a time delta from the stdcm start time in ms
pub start_time: u64,
/// End time as a time delta from the stdcm start time in ms
Expand All @@ -90,6 +93,15 @@ pub struct LightWorkSchedule {
pub track_ranges: Vec<UndirectedTrackRange>,
}

/// Lighter description of a work schedule with only the relevant information for core
#[derive(Debug, Serialize)]
pub struct TemporarySpeedLimit {
/// Speed limitation in m/s
pub speed_limit: f64,
/// Track ranges on which the speed limitation applies
pub track_ranges: Vec<TrackRange>,
}

/// A range on a track section.
/// `begin` is always less than `end`.
#[derive(Serialize, Deserialize, Clone, Debug, ToSchema, Hash, PartialEq, Eq)]
Expand Down
1 change: 1 addition & 0 deletions editoast/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod rolling_stock_model;
pub mod scenario;
pub mod stdcm_search_environment;
pub mod study;
pub mod temporary_speed_limits;
pub mod timetable;
pub mod train_schedule;
pub mod work_schedules;
Expand Down
43 changes: 43 additions & 0 deletions editoast/src/models/temporary_speed_limits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use chrono::NaiveDateTime;
use editoast_derive::Model;
use editoast_models::tables::{temporary_speed_limit, temporary_speed_limit_group};
use editoast_schemas::infra::DirectionalTrackRange;
use serde::Serialize;

use crate::core::stdcm::TemporarySpeedLimit as CoreTemporarySpeedLimit;

#[derive(Debug, Clone, Model)]
#[model(table = temporary_speed_limit_group)]
#[model(gen(ops = crd, batch_ops = c, list))]
pub struct TemporarySpeedLimitGroup {
pub id: i64,
pub creation_date: NaiveDateTime,
pub name: String,
}

#[derive(Debug, Serialize, Clone, Model)]
#[model(table = temporary_speed_limit)]
#[model(gen(ops = cr, batch_ops = c, list))]
pub struct TemporarySpeedLimit {
pub id: i64,
pub start_date_time: NaiveDateTime,
pub end_date_time: NaiveDateTime,
pub speed_limit: f64,
#[model(json)]
pub track_ranges: Vec<DirectionalTrackRange>,
pub obj_id: String,
pub temporary_speed_limit_group_id: i64,
}

impl From<TemporarySpeedLimit> for CoreTemporarySpeedLimit {
fn from(value: TemporarySpeedLimit) -> Self {
CoreTemporarySpeedLimit {
speed_limit: value.speed_limit,
track_ranges: value
.track_ranges
.into_iter()
.map(|track_range| track_range.into())
.collect(),
}
}
}
2 changes: 2 additions & 0 deletions editoast/src/views/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod speed_limit_tags;
pub mod sprites;
pub mod stdcm_search_environment;
pub mod study;
pub mod temporary_speed_limits;
pub mod timetable;
pub mod train_schedule;
pub mod work_schedules;
Expand Down Expand Up @@ -77,6 +78,7 @@ crate::routes! {
&sprites,
&stdcm_search_environment,
&work_schedules,
&temporary_speed_limits,
&train_schedule,
&timetable,
&path,
Expand Down
1 change: 0 additions & 1 deletion editoast/src/views/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ editoast_common::schemas! {
pathfinding::schemas(),
projection::schemas(),
properties::schemas(),
TrackRange,
}

#[derive(Debug, Error, EditoastError)]
Expand Down
Loading

0 comments on commit 9df74e1

Please sign in to comment.