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: refactor: renamed many structs for consistency #9810

Merged
merged 1 commit into from
Nov 21, 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
12 changes: 6 additions & 6 deletions editoast/src/core/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ use crate::core::AsCoreRequest;
use crate::core::Json;

#[derive(Debug, Serialize)]
pub struct STDCMRequest {
pub struct Request {
/// Infrastructure id
pub infra: i64,
/// Infrastructure expected version
pub expected_version: String,

// Pathfinding inputs
/// List of waypoints. Each waypoint is a list of track offset.
pub path_items: Vec<STDCMPathItem>,
pub path_items: Vec<PathItem>,
/// The loading gauge of the rolling stock
pub rolling_stock_loading_gauge: LoadingGaugeType,
/// List of supported signaling systems
Expand Down Expand Up @@ -62,18 +62,18 @@ pub struct STDCMRequest {
}

#[derive(Debug, Serialize)]
pub struct STDCMPathItem {
pub struct PathItem {
/// The track offsets of the path item
pub locations: Vec<TrackOffset>,
/// Stop duration in milliseconds. None if the train does not stop at this path item.
pub stop_duration: Option<u64>,
/// If specified, describes when the train may arrive at the location
pub step_timing_data: Option<STDCMStepTimingData>,
pub step_timing_data: Option<StepTimingData>,
}

/// Contains the data of a step timing, when it is specified
#[derive(Debug, Serialize)]
pub struct STDCMStepTimingData {
pub struct StepTimingData {
/// Time the train should arrive at this point
pub arrival_time: DateTime<Utc>,
/// Tolerance for the arrival time, when it arrives before the expected time, in ms
Expand Down Expand Up @@ -131,7 +131,7 @@ pub enum Response {
},
}

impl AsCoreRequest<Json<Response>> for STDCMRequest {
impl AsCoreRequest<Json<Response>> for Request {
const METHOD: reqwest::Method = reqwest::Method::POST;
const URL_PATH: &'static str = "/v2/stdcm";

Expand Down
3 changes: 1 addition & 2 deletions editoast/src/views/timetable/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use crate::core::pathfinding::InvalidPathItem;
use crate::core::pathfinding::PathfindingResultSuccess;
use crate::core::simulation::PhysicsConsistParameters;
use crate::core::simulation::{RoutingRequirement, SimulationResponse, SpacingRequirement};
use crate::core::stdcm::STDCMRequest;
use crate::core::AsCoreRequest;
use crate::core::CoreClient;
use crate::error::Result;
Expand Down Expand Up @@ -210,7 +209,7 @@ async fn stdcm(
let work_schedules = stdcm_request.get_work_schedules(conn).await?;

// 5. Build STDCM request
let stdcm_request = STDCMRequest {
let stdcm_request = crate::core::stdcm::Request {
infra: infra.id,
expected_version: infra.version.clone(),
rolling_stock_loading_gauge: rolling_stock.loading_gauge,
Expand Down
8 changes: 3 additions & 5 deletions editoast/src/views/timetable/stdcm/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use serde::Serialize;
use utoipa::ToSchema;

use crate::core::pathfinding::PathfindingInputError;
use crate::core::stdcm::STDCMPathItem;
use crate::core::stdcm::STDCMStepTimingData;
use crate::error::Result;
use crate::models::temporary_speed_limits::TemporarySpeedLimit;
use crate::models::towed_rolling_stock::TowedRollingStockModel;
Expand Down Expand Up @@ -224,7 +222,7 @@ impl Request {
&self,
conn: &mut DbConnection,
infra_id: i64,
) -> Result<Vec<STDCMPathItem>> {
) -> Result<Vec<crate::core::stdcm::PathItem>> {
let locations: Vec<_> = self.steps.iter().map(|item| &item.location).collect();

let path_item_cache = PathItemCache::load(conn, infra_id, &locations).await?;
Expand All @@ -240,11 +238,11 @@ impl Request {
Ok(track_offsets
.iter()
.zip(&self.steps)
.map(|(track_offset, path_item)| STDCMPathItem {
.map(|(track_offset, path_item)| crate::core::stdcm::PathItem {
stop_duration: path_item.duration,
locations: track_offset.to_vec(),
step_timing_data: path_item.timing_data.as_ref().map(|timing_data| {
STDCMStepTimingData {
crate::core::stdcm::StepTimingData {
arrival_time: timing_data.arrival_time,
arrival_time_tolerance_before: timing_data.arrival_time_tolerance_before,
arrival_time_tolerance_after: timing_data.arrival_time_tolerance_after,
Expand Down
Loading