Skip to content
Open
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
3 changes: 0 additions & 3 deletions editoast/.dockerignore

This file was deleted.

19 changes: 14 additions & 5 deletions editoast/Cargo.lock

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

4 changes: 2 additions & 2 deletions editoast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ tracing-opentelemetry = { version = "0.33.0", default-features = false, features
"tracing-log",
] }
tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
uom = { version = "0.38.0", default-features = false, features = ["f64", "si"] }
unit_system = { path = "./unit_system" }
url = { version = "2.5.8", features = ["serde"] }
urlencoding = "2.1.3"
utoipa = { git = "https://github.com/osrd-project/utoipa.git", rev = "5103a24a6d6", features = [
Expand Down Expand Up @@ -250,7 +250,7 @@ tower-http = { version = "0.7", features = [
] }
tracing.workspace = true
tracing-subscriber.workspace = true
uom.workspace = true
unit_system.workspace = true
url.workspace = true
utoipa.workspace = true
uuid.workspace = true
Expand Down
1 change: 0 additions & 1 deletion editoast/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ serde_json.workspace = true
tracing.workspace = true
tracing-opentelemetry.workspace = true
tracing-subscriber.workspace = true
uom.workspace = true
url.workspace = true
utoipa.workspace = true

Expand Down
6 changes: 1 addition & 5 deletions editoast/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub mod geometry;
mod hash_rounded_float;
pub mod rangemap_utils;
pub mod tracing;
pub mod units;

use std::collections::HashSet;
use std::hash::Hash;
Expand Down Expand Up @@ -35,10 +34,7 @@ pub struct Version {
/// Allows implementing Eq for floats considering all NaN values to be equal
///
/// Tip: provide this to Educe.
pub fn float_eq<V>(a: &V, b: &V) -> bool
where
V: uom::num_traits::Num + uom::num_traits::float::TotalOrder + uom::Conversion<V>,
{
pub fn float_eq(a: &f64, b: &f64) -> bool {
matches!(a.total_cmp(b), std::cmp::Ordering::Equal)
}

Expand Down
1 change: 1 addition & 0 deletions editoast/core_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tokio.workspace = true
tokio-stream = "0.1.18"
tracing.workspace = true
tracing-opentelemetry.workspace = true
unit_system.workspace = true
url.workspace = true
utoipa.workspace = true
uuid.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions editoast/core_client/src/conflict_detection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use common::units::quantities::Offset;
use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
use unit_system::quantities::Offset;
use utoipa::ToSchema;
use uuid::Uuid;

Expand Down Expand Up @@ -65,7 +65,7 @@ pub struct Conflict {
/// (`trains_requirements` and `work_schedules`) and response.
/// Example: `1970-01-01T00:00:00Z` for calendar timetables; the timetable start for hourly
/// timetables.
#[serde(with = "common::units::millisecond::i64")]
#[serde(with = "unit_system::units::millisecond::i64")]
pub start_time: Offset,
/// Duration of the conflict in ms.
pub duration: u64,
Expand All @@ -90,7 +90,7 @@ pub struct ConflictRequirement {
/// (`trains_requirements` and `work_schedules`) and response.
/// Example: `1970-01-01T00:00:00Z` for calendar timetables; the timetable start for hourly
/// timetables.
#[serde(with = "common::units::millisecond::i64")]
#[serde(with = "unit_system::units::millisecond::i64")]
#[schema(value_type = i64)]
pub start_time: Offset,
/// Duration of the time range in ms (difference between the latest end time and the earliest start_time for any zone use in this conflict).
Expand Down
14 changes: 7 additions & 7 deletions editoast/core_client/src/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ use std::collections::BTreeMap;
use std::collections::HashMap;
use std::hash::Hash;

use common::units;
use common::units::quantities::Acceleration;
use common::units::quantities::Deceleration;
use common::units::quantities::Length;
use common::units::quantities::Mass;
use common::units::quantities::Time;
use common::units::quantities::Velocity;
use educe::Educe;
use schemas::rolling_stock::EffortCurves;
use schemas::rolling_stock::EtcsBrakeParams;
Expand All @@ -20,6 +13,13 @@ use schemas::train_schedule::ReceptionSignal;
use schemas::train_schedule::TrainScheduleOptions;
use serde::Deserialize;
use serde::Serialize;
use unit_system::quantities::Acceleration;
use unit_system::quantities::Deceleration;
use unit_system::quantities::Length;
use unit_system::quantities::Mass;
use unit_system::quantities::Time;
use unit_system::quantities::Velocity;
use unit_system::units;
use utoipa::ToSchema;

use super::RawError;
Expand Down
2 changes: 1 addition & 1 deletion editoast/core_task/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ serde_json.workspace = true
tokio.workspace = true
tokio-stream.workspace = true
tracing.workspace = true
uom.workspace = true
unit_system.workspace = true

[dev-dependencies]
cache = { workspace = true, features = ["mock"] }
Expand Down
10 changes: 5 additions & 5 deletions editoast/core_task/src/envs/simulation/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ pub struct SimulationTrainParameters {
power_restrictions: rangemap::RangeMap<ScheduleItemIndex, String>,
margins: rangemap::RangeMap<ScheduleItemIndex, MarginValue>,

#[educe(Hash(method(common::units::meter_per_second::hash)))]
#[educe(PartialEq(method(common::units::meter_per_second::eq)))]
initial_speed: uom::si::f64::Velocity,
#[educe(Hash(method(unit_system::units::meter_per_second::hash)))]
#[educe(PartialEq(method(unit_system::units::meter_per_second::eq)))]
initial_speed: unit_system::quantities::Velocity,
constraint_distribution: Distribution,
comfort: Comfort,
speed_limit_tag: Option<String>,
Expand All @@ -73,7 +73,7 @@ impl ScheduleItem {

impl SimulationTrainParameters {
pub fn new(
initial_speed: uom::si::f64::Velocity,
initial_speed: unit_system::quantities::Velocity,
constraint_distribution: Distribution,
comfort: Comfort,
speed_limit_tag: Option<String>,
Expand Down Expand Up @@ -103,7 +103,7 @@ impl SimulationTrainParameters {
&self.margins
}

pub fn initial_speed(&self) -> uom::si::f64::Velocity {
pub fn initial_speed(&self) -> unit_system::quantities::Velocity {
self.initial_speed
}

Expand Down
4 changes: 1 addition & 3 deletions editoast/core_task/src/envs/simulation/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ pub(super) fn build_request(
values: margin_values,
},
power_restrictions,
initial_speed: params
.initial_speed()
.get::<uom::si::velocity::meter_per_second>(),
initial_speed: unit_system::units::meter_per_second::from(params.initial_speed()),
comfort: params.comfort(),
constraint_distribution: params.constraint_distribution(),
speed_limit_tag: params.speed_limit_tag().map(|s| s.to_owned()),
Expand Down
17 changes: 16 additions & 1 deletion editoast/editoast_derive/src/annotate_units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,28 @@ fn get_abbreviation(value: &str) -> Option<&'static str> {
"meter" => Some("Length in m"),
"millimeter" => Some("Length in mm"),
"meter_per_second" => Some("Velocity in m·s⁻¹"),
"kilometer_per_hour" => Some("Velocity in km·h⁻¹"),
"meter_per_second_squared" => Some("Acceleration in m·s⁻²"),
"newton_per_kg" => Some("Acceleration in N·kg⁻¹"),
"newton_per_ton" => Some("Acceleration in N·t⁻¹"),
"kilogram" => Some("Mass in kg"),
"ton" => Some("Mass in t"),
"newton" => Some("Solid Friction in N"),
"kilonewton" => Some("Solid Friction in kN"),
"kilogram_per_second" => Some("Viscosity friction in kg·s⁻¹"),
"newton_per_meter_per_second" => Some("Viscosity friction in N·(m/s)⁻¹"),
"newton_per_kilometer_per_hour" => Some("Viscosity friction in N·(km/h)⁻¹"),
"hertz" => Some("Viscosity friction per weight in s⁻¹"),
"newton_per_meter_per_second_per_kilogram" => {
Some("Viscosity friction per weight in N·(m/s)⁻¹·kg⁻¹")
}
"kilogram_per_meter" => Some("Aerodynamic drag in kg·m⁻¹"),
"kilogram_per_second" => Some("Viscosity friction in kg·s⁻¹"),
"newton_per_meter_per_second_squared" => Some("Aerodynamic drag in N·(m/s)⁻²"),
"kilonewton_per_kilometer_per_hour_squared" => Some("Aerodynamic drag in kN·(km/h)⁻²"),
"per_meter" => Some("Aerodynamic drag per kg in m⁻¹"),
"newton_per_meter_per_second_squared_per_kilogram" => {
Some("Aerodynamic drag per kg in N·(m/s)⁻²·kg⁻¹")
}
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion editoast/editoast_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub fn search_config_store(input: proc_macro::TokenStream) -> proc_macro::TokenS
/// * `#[model(to_string)]`: calls `to_string()` before writing the field to the database and calls `String::from` after reading (diesel column type: String)
/// * `#[model(to_enum)]`: is converted as `u8` before writing the field to the database and calls `FromRepr::from_repr` after reading (diesel column type: TinyInt)
/// * `#[model(remote = "T")]`: calls `Into::<T>::into` before writing the field to the database and calls `T::from` after reading (diesel column type: T)
/// * `#[model(uom_unit = "path::to::unit")]`: the value is the path to an unit defined in common, e.g. `"common::units::meter"`
/// * `#[model(uom_unit = "path::to::unit")]`: the value is the path to an unit defined in common, e.g. `"unit_system::units::meter"`
/// * `#[model(geo)]` **TODO**: TBD
/// * `#[model(non_null_array = "T")]`: wraps type `T` into an `Option<T>` when interfacing with diesel to satisfy the nullable property of postgres arrays
///
Expand Down
2 changes: 1 addition & 1 deletion editoast/models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ thiserror.workspace = true
tokio.workspace = true
tokio-postgres.workspace = true
tracing.workspace = true
uom.workspace = true
unit_system.workspace = true
url.workspace = true
utoipa.workspace = true
uuid.workspace = true
Expand Down
14 changes: 7 additions & 7 deletions editoast/models/src/rolling_stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ mod power_restrictions;
use std::collections::HashMap;
use std::collections::HashSet;

use common::units;
use common::units::quantities::Acceleration;
use common::units::quantities::Deceleration;
use common::units::quantities::Length;
use common::units::quantities::Mass;
use common::units::quantities::Time;
use common::units::quantities::Velocity;
use editoast_derive::Model;
use schemas::rolling_stock::EffortCurves;
use schemas::rolling_stock::EnergySource;
Expand All @@ -20,6 +13,13 @@ use schemas::rolling_stock::RollingStockMetadata;
use schemas::rolling_stock::SupportedSignalingSystem;
use serde::Deserialize;
use serde::Serialize;
use unit_system::quantities::Acceleration;
use unit_system::quantities::Deceleration;
use unit_system::quantities::Length;
use unit_system::quantities::Mass;
use unit_system::quantities::Time;
use unit_system::quantities::Velocity;
use unit_system::units;
use utoipa::ToSchema;

use crate::prelude::*;
Expand Down
4 changes: 2 additions & 2 deletions editoast/models/src/timetable.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use common::units::millisecond;
use common::units::quantities::Offset;
use database::DatabaseError;
use database::tables::sql_types;
use diesel::prelude::*;
Expand All @@ -15,6 +13,8 @@ use editoast_derive::Model;
use itertools::Itertools as _;
use std::collections::HashSet;
use std::ops::DerefMut as _;
use unit_system::quantities::Offset;
use unit_system::units::millisecond;

use database::DbConnection;

Expand Down
12 changes: 6 additions & 6 deletions editoast/models/src/towed_rolling_stock.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use common::units;
use common::units::quantities::Acceleration;
use common::units::quantities::Deceleration;
use common::units::quantities::Length;
use common::units::quantities::Mass;
use common::units::quantities::Velocity;
use editoast_derive::Model;
use schemas::rolling_stock::RollingResistancePerWeight;
use serde::Deserialize;
use serde::Serialize;
use unit_system::quantities::Acceleration;
use unit_system::quantities::Deceleration;
use unit_system::quantities::Length;
use unit_system::quantities::Mass;
use unit_system::quantities::Velocity;
use unit_system::units;

use crate::prelude::*;

Expand Down
8 changes: 4 additions & 4 deletions editoast/models/src/train_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::prelude::*;
use crate::rolling_stock::TrainMainCategory;
use crate::tags::Tags;
use chrono::Duration as ChronoDuration;
use common::units::millisecond;
use common::units::quantities::Offset;
use derive_more::Display;
use editoast_derive::Model;
use itertools::Itertools as _;
Expand All @@ -24,6 +22,8 @@ use schemas::train_schedule::TrainScheduleOptions;
use serde::Deserialize;
use serde::Serialize;
use std::fmt::Display;
use unit_system::quantities::Offset;
use unit_system::units::millisecond;
use utoipa::ToSchema;

#[derive(Debug, Clone, Model)]
Expand All @@ -37,7 +37,7 @@ pub struct TrainSchedule {
pub labels: Tags,
pub rolling_stock_name: String,
pub train_schedule_set_id: i64,
#[model(uom_unit = "common::units::millisecond::i64")]
#[model(uom_unit = "unit_system::units::millisecond::i64")]
/// For calendar timetables: elapsed ms since 1970-01-01T00:00:00Z.
/// For hourly timetables: elapsed ms since the timetable start.
pub start_time: Offset,
Expand Down Expand Up @@ -504,14 +504,14 @@ mod tests {

use super::OccurrenceId;
use super::TrainSchedule;
use common::units::quantities::Offset;
use database::DbConnectionPoolV2;
use pretty_assertions::assert_eq;
use rstest::rstest;
use schemas::TrainScheduleExceptionChangeGroups;
use schemas::fixtures::ms_since_epoch;
use schemas::paced_train::RollingStockCategoryChangeGroup;
use schemas::paced_train::StartTimeChangeGroup;
use unit_system::quantities::Offset;

use crate::prelude::*;
use schemas::train_schedule::Comfort;
Expand Down
2 changes: 1 addition & 1 deletion editoast/schemas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ serde_json.workspace = true
serde_with.workspace = true
strum.workspace = true
thiserror.workspace = true
uom.workspace = true
unit_system.workspace = true
utoipa.workspace = true
uuid.workspace = true

Expand Down
Loading
Loading