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: update temporary speed limit groups import endpoint #9381

Merged
merged 1 commit into from
Nov 25, 2024
Merged
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
2 changes: 2 additions & 0 deletions editoast/editoast_models/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ diesel::table! {
timetable_id -> Int8,
search_window_begin -> Timestamptz,
search_window_end -> Timestamptz,
temporary_speed_limit_group_id -> Nullable<Int8>,
}
}

Expand Down Expand Up @@ -798,6 +799,7 @@ diesel::joinable!(search_signal -> infra_object_signal (id));
diesel::joinable!(search_study -> study (id));
diesel::joinable!(stdcm_search_environment -> electrical_profile_set (electrical_profile_set_id));
diesel::joinable!(stdcm_search_environment -> infra (infra_id));
diesel::joinable!(stdcm_search_environment -> temporary_speed_limit_group (temporary_speed_limit_group_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));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE stdcm_search_environment
DROP COLUMN IF EXISTS temporary_speed_limit_group_id;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE stdcm_search_environment
ADD COLUMN temporary_speed_limit_group_id int8 REFERENCES temporary_speed_limit_group(id);
129 changes: 129 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,51 @@ paths:
minimum: 0
'404':
description: Infra ID not found
/infra/{infra_id}/delimited_area:
get:
tags:
- delimited_area
summary: Computes all tracks between a set of `entries` locations and a set of `exits` locations
description: |-
Returns any track between one of the `entries` and one of the `exits`, i.e. any track that can
be reached from an entry before reaching an exit.
To prevent a missing exit to cause the graph traversal to never stop exploring, the exploration
stops when a maximum distance is reached and no exit has been found.
parameters:
- name: infra_id
in: path
description: An existing infra ID
required: true
schema:
type: integer
format: int64
requestBody:
content:
application/json:
schema:
type: object
required:
- track_ranges
properties:
track_ranges:
type: array
items:
$ref: '#/components/schemas/DirectionalTrackRange'
required: true
responses:
'200':
description: The track ranges between a list entries and exits.
content:
application/json:
schema:
type: object
required:
- track_ranges
properties:
track_ranges:
type: array
items:
$ref: '#/components/schemas/DirectionalTrackRange'
/infra/{infra_id}/errors:
get:
tags:
Expand Down Expand Up @@ -3486,6 +3531,15 @@ components:
force:
type: boolean
description: force the deletion even if it's used
DelimitedAreaResponse:
type: object
required:
- track_ranges
properties:
track_ranges:
type: array
items:
$ref: '#/components/schemas/DirectionalTrackRange'
Detector:
type: object
required:
Expand Down Expand Up @@ -3519,6 +3573,22 @@ components:
maxLength: 255
minLength: 1
additionalProperties: false
DirectedLocation:
type: object
required:
- track
- position
- direction
properties:
direction:
$ref: '#/components/schemas/Direction'
position:
type: number
format: double
track:
type: string
maxLength: 255
minLength: 1
Direction:
type: string
enum:
Expand Down Expand Up @@ -4061,6 +4131,30 @@ components:
type: string
enum:
- editoast:DatabaseAccessError
EditoastDelimitedAreaErrorInvalidLocations:
type: object
required:
- type
- status
- message
properties:
context:
type: object
required:
- invalid_locations
properties:
invalid_locations:
type: array
message:
type: string
status:
type: integer
enum:
- 400
type:
type: string
enum:
- editoast:delimited_area:InvalidLocations
EditoastDocumentErrorsNotFound:
type: object
required:
Expand Down Expand Up @@ -4213,6 +4307,7 @@ components:
- $ref: '#/components/schemas/EditoastCoreErrorGenericCoreError'
- $ref: '#/components/schemas/EditoastCoreErrorUnparsableErrorOutput'
- $ref: '#/components/schemas/EditoastDatabaseAccessErrorDatabaseAccessError'
- $ref: '#/components/schemas/EditoastDelimitedAreaErrorInvalidLocations'
- $ref: '#/components/schemas/EditoastDocumentErrorsNotFound'
- $ref: '#/components/schemas/EditoastEditionErrorInfraIsLocked'
- $ref: '#/components/schemas/EditoastEditionErrorSplitTrackSectionBadOffset'
Expand Down Expand Up @@ -6538,6 +6633,33 @@ components:
properties:
state:
$ref: '#/components/schemas/InfraState'
InputError:
oneOf:
- type: object
required:
- TrackDoesNotExist
properties:
TrackDoesNotExist:
type: string
- type: object
required:
- LocationOutOfBounds
properties:
LocationOutOfBounds:
type: object
required:
- track
- position
- track_length
properties:
position:
type: number
format: double
track:
type: string
track_length:
type: number
format: double
InternalError:
type: object
required:
Expand Down Expand Up @@ -9916,6 +10038,9 @@ components:
search_window_end:
type: string
format: date-time
temporary_speed_limit_group_id:
type: integer
format: int64
timetable_id:
type: integer
format: int64
Expand Down Expand Up @@ -9943,6 +10068,10 @@ components:
search_window_end:
type: string
format: date-time
temporary_speed_limit_group_id:
type: integer
format: int64
nullable: true
timetable_id:
type: integer
format: int64
Expand Down
11 changes: 11 additions & 0 deletions editoast/src/infra_cache/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ impl<'a> Graph<'a> {
.map(|groups| groups.keys().cloned().collect())
.unwrap_or_default()
}

/// Given an endpoint return all its neighbours indiscriminately
/// of their group.
pub fn get_all_neighbours(&'a self, track_endpoint: &TrackEndpoint) -> Vec<&'a TrackEndpoint> {
let groups = self.links.get(track_endpoint);
if let Some(groups) = groups {
groups.values().copied().collect::<Vec<_>>()
} else {
Vec::new()
}
}
}

#[cfg(test)]
Expand Down
13 changes: 13 additions & 0 deletions editoast/src/models/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use crate::models::Scenario;
use crate::models::Study;
use crate::models::Tags;

use super::temporary_speed_limits::TemporarySpeedLimitGroup;

pub fn project_changeset(name: &str) -> Changeset<Project> {
Project::changeset()
.name(name.to_owned())
Expand Down Expand Up @@ -296,6 +298,17 @@ pub async fn create_work_schedule_group(conn: &mut DbConnection) -> WorkSchedule
.expect("Failed to create empty work schedule group")
}

pub async fn create_temporary_speed_limit_group(
conn: &mut DbConnection,
) -> TemporarySpeedLimitGroup {
TemporarySpeedLimitGroup::changeset()
.name("Empty temporary speed limit group".to_string())
.creation_date(Utc::now().naive_utc())
.create(conn)
.await
.expect("Failed to create empty temporary speed limit group")
}

pub async fn create_work_schedules_fixture_set(
conn: &mut DbConnection,
work_schedules: Vec<Changeset<WorkSchedule>>,
Expand Down
38 changes: 31 additions & 7 deletions editoast/src/models/stdcm_search_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub struct StdcmSearchEnvironment {
pub timetable_id: i64,
pub search_window_begin: NaiveDateTime,
pub search_window_end: NaiveDateTime,
#[schema(nullable = false)]
#[serde(skip_serializing_if = "Option::is_none")]
pub temporary_speed_limit_group_id: Option<i64>,
}

impl StdcmSearchEnvironment {
Expand Down Expand Up @@ -69,9 +72,10 @@ pub mod test {
use super::*;
use crate::models::electrical_profiles::ElectricalProfileSet;
use crate::models::fixtures::{
create_electrical_profile_set, create_empty_infra, create_timetable,
create_work_schedule_group,
create_electrical_profile_set, create_empty_infra, create_temporary_speed_limit_group,
create_timetable, create_work_schedule_group,
};
use crate::models::temporary_speed_limits::TemporarySpeedLimitGroup;
use crate::models::timetable::Timetable;
use crate::models::work_schedules::WorkScheduleGroup;
use crate::models::Infra;
Expand All @@ -80,16 +84,24 @@ pub mod test {

pub async fn stdcm_search_env_fixtures(
conn: &mut DbConnection,
) -> (Infra, Timetable, WorkScheduleGroup, ElectricalProfileSet) {
) -> (
Infra,
Timetable,
WorkScheduleGroup,
TemporarySpeedLimitGroup,
ElectricalProfileSet,
) {
let infra = create_empty_infra(conn).await;
let timetable = create_timetable(conn).await;
let work_schedule_group = create_work_schedule_group(conn).await;
let temporary_speed_limit_group = create_temporary_speed_limit_group(conn).await;
let electrical_profile_set = create_electrical_profile_set(conn).await;

(
infra,
timetable,
work_schedule_group,
temporary_speed_limit_group,
electrical_profile_set,
)
}
Expand All @@ -101,13 +113,19 @@ pub mod test {
StdcmSearchEnvironment::count(&mut db_pool.get_ok(), Default::default())
.await
.expect("failed to count STDCM envs");
let (infra, timetable, work_schedule_group, electrical_profile_set) =
stdcm_search_env_fixtures(&mut db_pool.get_ok()).await;
let (
infra,
timetable,
work_schedule_group,
temporary_speed_limit_group,
electrical_profile_set,
) = stdcm_search_env_fixtures(&mut db_pool.get_ok()).await;

let changeset_1 = StdcmSearchEnvironment::changeset()
.infra_id(infra.id)
.electrical_profile_set_id(Some(electrical_profile_set.id))
.work_schedule_group_id(Some(work_schedule_group.id))
.temporary_speed_limit_group_id(Some(temporary_speed_limit_group.id))
.timetable_id(timetable.id)
.search_window_begin(NaiveDate::from_ymd_opt(2024, 1, 1).unwrap().into())
.search_window_end(NaiveDate::from_ymd_opt(2024, 1, 15).unwrap().into());
Expand Down Expand Up @@ -158,13 +176,19 @@ pub mod test {
StdcmSearchEnvironment::delete_all(&mut db_pool.get_ok())
.await
.expect("failed to delete envs");
let (infra, timetable, work_schedule_group, electrical_profile_set) =
stdcm_search_env_fixtures(&mut db_pool.get_ok()).await;
let (
infra,
timetable,
work_schedule_group,
temporary_speed_limit_group,
electrical_profile_set,
) = stdcm_search_env_fixtures(&mut db_pool.get_ok()).await;

let too_old = StdcmSearchEnvironment::changeset()
.infra_id(infra.id)
.electrical_profile_set_id(Some(electrical_profile_set.id))
.work_schedule_group_id(Some(work_schedule_group.id))
.temporary_speed_limit_group_id(Some(temporary_speed_limit_group.id))
.timetable_id(timetable.id)
.search_window_begin(NaiveDate::from_ymd_opt(2024, 1, 1).unwrap().into())
.search_window_end(NaiveDate::from_ymd_opt(2024, 1, 15).unwrap().into());
Expand Down
Loading
Loading