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: add weight field to operational points path_properties #10275

Merged
merged 1 commit into from
Jan 9, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,10 @@ fun parseRJSInfra(rjsInfra: RJSInfra): RawInfra {
props["chLongLabel"] = sncf.chLongLabel
props["trigram"] = sncf.trigram
}
val weight = operationalPoint.weight
if (weight != null) {
props["weight"] = weight
}
if (opPart.extensions?.sncf != null) props["kp"] = opPart.extensions!!.sncf!!.kp
val partId =
builder.operationalPointPart(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ public class RJSOperationalPoint implements Identified {
@Nullable
public RJSOperationalPointExtensions extensions;

@Nullable
public String weight;

public RJSOperationalPoint(
String id, List<RJSOperationalPointPart> parts, @Nullable RJSOperationalPointExtensions extensions) {
String id,
List<RJSOperationalPointPart> parts,
@Nullable RJSOperationalPointExtensions extensions,
@Nullable String weight) {
this.id = id;
this.parts = parts;
this.extensions = extensions;
this.weight = weight;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ data class OperationalPointResponse(
val id: String,
val part: OperationalPointPartResponse,
val extensions: OperationalPointExtensions?,
val position: Offset<Path>
val position: Offset<Path>,
val weight: Long?
)

data class OperationalPointPartResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ private fun makeOperationalPoints(
val opExtensions =
if (opSncfExtension == null && opIdExtension == null) null
else OperationalPointExtensions(opSncfExtension, opIdExtension)
val weight = if (opPartProps["weight"] == null) null else opPartProps["weight"]!!.toLong()
val opResult =
OperationalPointResponse(operationalPointId, opPartResult, opExtensions, offset)
OperationalPointResponse(operationalPointId, opPartResult, opExtensions, offset, weight)
res.add(opResult)
}
return res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class PathPropEndpointTest : ApiTest() {
OperationalPointSncfExtension(0, "BV", "BV", "0", "WS"),
OperationalPointIdentifierExtension("West_station", 2)
),
Offset(650.meters)
Offset(650.meters),
null
),
OperationalPointResponse(
"West_station",
Expand All @@ -74,7 +75,8 @@ class PathPropEndpointTest : ApiTest() {
OperationalPointSncfExtension(0, "BV", "BV", "0", "WS"),
OperationalPointIdentifierExtension("West_station", 2)
),
Offset(2450.meters)
Offset(2450.meters),
null
)
)
assertEquals(parsed.operationalPoints, oPs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,15 @@ class PathfindingTest : ApiTest() {
RJSOperationalPoint(
"new_op_1",
listOf(RJSOperationalPointPart("ne.micro.foo_a", 200.0, null)),
null,
null
)
)
rjsInfra.operationalPoints.add(
RJSOperationalPoint(
"new_op_2",
listOf(RJSOperationalPointPart("ne.micro.bar_a", 0.0, null)),
null,
null
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ class PathPropertiesTests {
),
RJSOperationalPointExtensions(
RJSOperationalPointSncfExtension(0, "BV", "B", "0", "TRI"),
null
)
null,
),
null
),
RJSOperationalPoint(
"point2",
Expand All @@ -147,6 +148,7 @@ class PathPropertiesTests {
),
RJSOperationalPointPart("TA1", 1_950.0, null),
),
null,
null
)
)
Expand Down
7 changes: 7 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8010,6 +8010,7 @@ components:
- id
- part
- position
- weight
properties:
extensions:
$ref: '#/components/schemas/OperationalPointExtensions'
Expand All @@ -8024,6 +8025,12 @@ components:
format: int64
description: Distance from the beginning of the path in mm
minimum: 0
weight:
type: integer
format: int32
description: Importance of the operational point
nullable: true
minimum: 0
description: Operational points along the path
nullable: true
slopes:
Expand Down
3 changes: 3 additions & 0 deletions editoast/src/core/path_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ pub struct OperationalPointOnPath {
extensions: OperationalPointExtensions,
/// Distance from the beginning of the path in mm
position: u64,
/// Importance of the operational point
#[schema(required)]
weight: Option<u8>,
}

/// Zones along a path. Each value is associated to a range of the path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ export const sampleWithMultipleOperationalPoints: NonNullable<
},
},
position: 0,
weight: null,
},
{
id: 'Mid_West_station',
Expand All @@ -625,6 +626,7 @@ export const sampleWithMultipleOperationalPoints: NonNullable<
},
},
position: 12050000,
weight: null,
},
{
id: 'Mid_East_station',
Expand All @@ -639,6 +641,7 @@ export const sampleWithMultipleOperationalPoints: NonNullable<
},
},
position: 26500000,
weight: null,
},
];

Expand Down Expand Up @@ -687,5 +690,6 @@ export const sampleWithOneOperationalPoint: OperationalPoint[] = [
},
},
position: 4069000,
weight: null,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => {
},
},
position: 0,
weight: null,
},
{
id: '2',
Expand All @@ -52,6 +53,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => {
position: 7746000,
},
position: 9246000,
weight: null,
},
{
id: 'Mid_West_station',
Expand All @@ -66,6 +68,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => {
},
},
position: 12050000,
weight: null,
},
{
id: 'Mid_East_station',
Expand All @@ -80,6 +83,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => {
},
},
position: 26500000,
weight: null,
},
]);
});
Expand Down Expand Up @@ -108,6 +112,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => {
position: 6481000,
},
position: 0,
weight: null,
},
{
id: 'Mid_West_station',
Expand All @@ -122,6 +127,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => {
},
},
position: 4069000,
weight: null,
},
{
id: '2',
Expand All @@ -136,6 +142,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => {
position: 679000,
},
position: 4198000,
weight: null,
},
{
id: '3',
Expand All @@ -150,6 +157,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => {
position: 883000,
},
position: 4402000,
weight: null,
},
]);
});
Expand Down Expand Up @@ -178,6 +186,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => {
position: 6481000,
},
position: 0,
weight: null,
},
{
id: '2',
Expand All @@ -192,6 +201,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => {
position: 4733000,
},
position: 1748000,
weight: null,
},
]);
});
Expand Down Expand Up @@ -220,6 +230,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => {
},
},
position: 0,
weight: null,
},
{
id: 'Mid_West_station',
Expand All @@ -234,6 +245,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => {
},
},
position: 12050000,
weight: null,
},
{
id: 'Mid_East_station',
Expand All @@ -248,6 +260,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => {
},
},
position: 26500000,
weight: null,
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const upsertMapWaypointsInOperationalPoints = (
},
part: { track: step.track, position: step.offset },
position: positionOnPath,
weight: null,
};

waypointCounter += 1;
Expand Down
2 changes: 2 additions & 0 deletions front/src/common/api/generatedEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2567,6 +2567,8 @@ export type PathProperties = {
part: OperationalPointPart;
/** Distance from the beginning of the path in mm */
position: number;
/** Importance of the operational point */
weight: number | null;
}[]
| null;
slopes?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('formatStops', () => {
position: 0,
track: 'track',
},
weight: null,
},
];
const expected = [{ position: { start: 0 }, value: 'name ch' }];
Expand Down
Loading