Skip to content

Commit

Permalink
editoast: add timetable import endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
flomonster committed Sep 5, 2023
1 parent 01d697a commit 451d16d
Show file tree
Hide file tree
Showing 16 changed files with 570 additions and 104 deletions.
39 changes: 20 additions & 19 deletions editoast/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion editoast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ reqwest = { version = "0.11", features = ["json"] }
osm4routing = "0.5.8"
osmpbfreader = "0.16.0"
itertools = "0.11"
utoipa = { version = "3.5", features = ["actix_extras"] }
utoipa = { version = "3.5", features = ["actix_extras", "chrono", "uuid"] }
atty = "0.2.14"

[dev-dependencies]
Expand Down
115 changes: 115 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,95 @@ components:
required:
- name
- tags
TimetableImportItem:
properties:
path:
items:
$ref: '#/components/schemas/TimetableImportPathStep'
type: array
rolling_stock:
example: 2TGV2N2
type: string
trains:
items:
$ref: '#/components/schemas/TimetableImportTrain'
type: array
required:
- rolling_stock
- path
- trains
type: object
TimetableImportPathLocation:
discriminator:
propertyName: type
oneOf:
- properties:
offset:
format: double
type: number
track_section:
type: string
type:
enum:
- track_offset
type: string
required:
- track_section
- offset
- type
type: object
- properties:
type:
enum:
- operational_point
type: string
uic:
format: int64
type: integer
required:
- uic
- type
type: object
TimetableImportPathSchedule:
properties:
arrival_time:
format: date-time
type: string
departure_time:
format: date-time
type: string
required:
- arrival_time
- departure_time
type: object
TimetableImportPathStep:
properties:
location:
$ref: '#/components/schemas/TimetableImportPathLocation'
schedule:
additionalProperties:
$ref: '#/components/schemas/TimetableImportPathSchedule'
example:
'7015':
arrival_time: 2023-08-17T09:46:00+02:00
departure_time: 2023-08-17T09:56:00+02:00
type: object
required:
- location
type: object
TimetableImportTrain:
properties:
departure_time:
example: 2023-08-17T08:46:00+02:00
format: date-time
type: string
name:
example: '7015'
type: string
required:
- name
- departure_time
type: object
TimetableWithSchedulesDetails:
properties:
id:
Expand Down Expand Up @@ -4633,6 +4722,32 @@ paths:
summary: Retrieve a timetable and its train schedules
tags:
- timetable
post:
description: Import a timetable
parameters:
- description: Timetable id
in: path
name: id
required: true
schema:
format: int64
minimum: 0
type: integer
requestBody:
content:
application/json:
schema:
items:
$ref: '#/components/schemas/TimetableImportItem'
type: array
description: ''
required: true
responses:
'204':
description: Timetable was successfully imported
summary: Import a timetable
tags:
- timetable
/timetable/{id}/conflicts/:
get:
parameters:
Expand Down
14 changes: 10 additions & 4 deletions editoast/src/core/pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{AsCoreRequest, Json};
pub type PathfindingWaypoints = Vec<Vec<Waypoint>>;

/// A Core pathfinding request, see also [PathfindingResponse]
#[derive(Debug, Serialize)]
#[derive(Debug, Clone, Serialize)]
pub struct PathfindingRequest {
infra: i64,
expected_version: String,
Expand Down Expand Up @@ -71,10 +71,11 @@ impl Waypoint {
}
}

pub fn bidirectional(track_section: String, offset: f64) -> [Self; 2] {
pub fn bidirectional<T: AsRef<str>>(track_section: T, offset: f64) -> [Self; 2] {
let track = track_section.as_ref().to_string();
[
Self::new(track_section.clone(), offset, Direction::StartToStop),
Self::new(track_section, offset, Direction::StopToStart),
Self::new(track.clone(), offset, Direction::StartToStop),
Self::new(track, offset, Direction::StopToStart),
]
}
}
Expand All @@ -98,4 +99,9 @@ impl PathfindingRequest {
self.rolling_stocks.append(rolling_stocks);
self
}

/// Returns the number of waypoints in the request
pub fn nb_waypoints(&self) -> usize {
self.waypoints.len()
}
}
7 changes: 4 additions & 3 deletions editoast/src/core/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::models::{
Allowance, Pathfinding, PathfindingPayload, ResultTrain, RoutePath, ScheduledPoint,
SignalSighting, ZoneUpdate,
};
use crate::schema::rolling_stock::RollingStock;
use crate::schema::rolling_stock::{RollingStock, RollingStockComfortType};
use crate::schema::TrackLocation;
use geos::geojson::JsonValue;
use serde_derive::{Deserialize, Serialize};
Expand Down Expand Up @@ -40,15 +40,16 @@ pub struct CoreTrainSchedule {
pub allowances: Vec<Allowance>,
pub stops: Vec<TrainStop>,
pub tag: Option<String>,
pub comfort: String,
pub comfort: RollingStockComfortType,
pub power_restriction_ranges: Option<JsonValue>,
pub options: Option<JsonValue>,
}

/// One must be specified between `position` and `location`.
#[derive(Debug, Clone, Serialize)]
pub struct TrainStop {
pub position: Option<f64>,
pub location: TrackLocation,
pub location: Option<TrackLocation>,
pub duration: f64,
}

Expand Down
23 changes: 22 additions & 1 deletion editoast/src/models/infra_objects/operational_point.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//! Provides the [OperationalPointModel] model

use crate::error::Result;
use crate::{schema::OperationalPoint, tables::osrd_infra_operationalpointmodel};
use derivative::Derivative;
use diesel::{result::Error as DieselError, ExpressionMethods, QueryDsl};
use diesel::sql_types::{Array, BigInt};
use diesel::{result::Error as DieselError, sql_query};
use diesel::{ExpressionMethods, QueryDsl};
use diesel_async::{AsyncPgConnection as PgConnection, RunQueryDsl};
use editoast_derive::Model;
use serde::{Deserialize, Serialize};

Expand All @@ -18,3 +22,20 @@ pub struct OperationalPointModel {
pub data: diesel_json::Json<OperationalPoint>,
pub infra_id: i64,
}

impl OperationalPointModel {
/// Retrieve a list of operational points from the database
pub async fn retrieve_from_uic(
conn: &mut PgConnection,
infra_id: i64,
uic: Vec<i64>,
) -> Result<Vec<Self>> {
let query = "SELECT * FROM osrd_infra_operationalpointmodel
WHERE infra_id = $1 AND (data->'extensions'->'identifier'->'uic')::integer = ANY($2)".to_string();
Ok(sql_query(query)
.bind::<BigInt, _>(infra_id)
.bind::<Array<BigInt>, _>(uic)
.load(conn)
.await?)
}
}
17 changes: 17 additions & 0 deletions editoast/src/models/rolling_stock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,23 @@ impl RollingStockModel {
liveries,
})
}

/// Retrieve a rolling stock by its name
pub async fn retrieve_by_name(
conn: &mut PgConnection,
rs_name: String,
) -> Result<Option<Self>> {
use crate::tables::osrd_infra_rollingstock::dsl::*;
match osrd_infra_rollingstock
.filter(name.eq(rs_name))
.get_result::<Self>(conn)
.await
{
Ok(rs) => Ok(Some(rs)),
Err(DieselError::NotFound) => Ok(None),
Err(e) => Err(e.into()),
}
}
}

#[async_trait]
Expand Down
Loading

0 comments on commit 451d16d

Please sign in to comment.