Skip to content

Commit bc92d0c

Browse files
committed
api: add stops details to the report
1 parent 583b3f6 commit bc92d0c

File tree

10 files changed

+124
-54
lines changed

10 files changed

+124
-54
lines changed

api/openapi.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,8 @@ components:
843843
time: { type: number, format: float }
844844
position: { type: number, format: float }
845845
duration: { type: number, format: float }
846+
line_code: { type: number }
847+
track_number: { type: number }
846848
route_aspects:
847849
type: array
848850
items:

api/osrd_infra/views/train_schedule/standalone_simulation_report.py

+23-21
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ def convert_simulation_results(
6666
route_begin_occupancy, route_end_occupancy = convert_route_occupancies(
6767
simulation_result["route_occupancies"], projection_path_payload, departure_time
6868
)
69-
route_aspects = project_signal_updates(
70-
simulation_result["signal_updates"], projection_path_payload, departure_time
71-
)
69+
route_aspects = project_signal_updates(simulation_result["signal_updates"], projection_path_payload, departure_time)
7270

7371
speeds = [{**speed, "time": speed["time"] + departure_time} for speed in simulation_result["speeds"]]
7472
stops = [{**stop, "time": stop["time"] + departure_time} for stop in simulation_result["stops"]]
@@ -161,14 +159,16 @@ def build_signal_updates(signal_updates, departure_time):
161159
results = []
162160

163161
for update in signal_updates:
164-
results.append({
165-
"signal_id": update["signal_id"],
166-
"time_start": update["time_start"] + departure_time,
167-
"time_end": update["time_end"] + departure_time,
168-
"color": update["color"],
169-
"blinking": update["blinking"],
170-
"aspect_label": update["aspect_label"]
171-
})
162+
results.append(
163+
{
164+
"signal_id": update["signal_id"],
165+
"time_start": update["time_start"] + departure_time,
166+
"time_end": update["time_end"] + departure_time,
167+
"color": update["color"],
168+
"blinking": update["blinking"],
169+
"aspect_label": update["aspect_label"],
170+
}
171+
)
172172
return results
173173

174174

@@ -189,16 +189,18 @@ def project_signal_updates(signal_updates, projection_path_payload: PathPayload,
189189
end_pos += track_range.length()
190190

191191
for update in updates_by_route_id[route_id]:
192-
results.append({
193-
"signal_id": update["signal_id"],
194-
"route_id": route_id,
195-
"time_start": update["time_start"] + departure_time,
196-
"time_end": update["time_end"] + departure_time,
197-
"position_start": start_pos,
198-
"position_end": end_pos,
199-
"color": update["color"],
200-
"blinking": update["blinking"]
201-
})
192+
results.append(
193+
{
194+
"signal_id": update["signal_id"],
195+
"route_id": route_id,
196+
"time_start": update["time_start"] + departure_time,
197+
"time_end": update["time_end"] + departure_time,
198+
"position_start": start_pos,
199+
"position_end": end_pos,
200+
"color": update["color"],
201+
"blinking": update["blinking"],
202+
}
203+
)
202204
start_pos = end_pos
203205
return results
204206

core/src/main/java/fr/sncf/osrd/infra/api/tracks/undirected/TrackEdge.java

+1
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ public sealed interface TrackEdge permits SwitchBranch, TrackSection {
3939

4040
/** Returns a list of ranges, each having a set of blocked loading gauge type */
4141
ImmutableRangeMap<Double, LoadingGaugeConstraint> getLoadingGaugeConstraints();
42+
4243
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
package fr.sncf.osrd.infra.api.tracks.undirected;
22

3-
public non-sealed interface TrackSection extends TrackEdge {}
3+
public non-sealed interface TrackSection extends TrackEdge {
4+
5+
/** Returns line code */
6+
int getLineCode();
7+
8+
/** Returns track number */
9+
int getTrackNumber();
10+
}

core/src/main/java/fr/sncf/osrd/infra/implementation/tracks/undirected/TrackSectionImpl.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class TrackSectionImpl implements TrackSection {
2020
private final LineString geo;
2121
private final LineString sch;
2222
private final ImmutableRangeMap<Double, LoadingGaugeConstraint> loadingGaugeConstraints;
23+
private int trackNumber = 0;
24+
private int lineCode = 0;
2325

2426
@Override
2527
@ExcludeFromGeneratedCodeCoverage
@@ -37,14 +39,18 @@ public TrackSectionImpl(
3739
ImmutableSet<OperationalPoint> operationalPoints,
3840
LineString geo,
3941
LineString sch,
40-
ImmutableRangeMap<Double, LoadingGaugeConstraint> loadingGaugeConstraints
42+
ImmutableRangeMap<Double, LoadingGaugeConstraint> loadingGaugeConstraints,
43+
int trackNumber,
44+
int lineCode
4145
) {
4246
this.length = length;
4347
this.id = id;
4448
this.operationalPoints = operationalPoints;
4549
this.geo = geo;
4650
this.sch = sch;
4751
this.loadingGaugeConstraints = loadingGaugeConstraints;
52+
this.trackNumber = trackNumber;
53+
this.lineCode = lineCode;
4854
}
4955

5056
/** Constructor with empty operational points and geometry */
@@ -103,6 +109,16 @@ public ImmutableRangeMap<Double, LoadingGaugeConstraint> getLoadingGaugeConstrai
103109
return loadingGaugeConstraints;
104110
}
105111

112+
@Override
113+
public int getLineCode() {
114+
return lineCode;
115+
}
116+
117+
@Override
118+
public int getTrackNumber() {
119+
return trackNumber;
120+
}
121+
106122
@Override
107123
public LineString getGeo() {
108124
return geo;

core/src/main/java/fr/sncf/osrd/infra/implementation/tracks/undirected/UndirectedInfraBuilder.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ private TrackSectionImpl makeTrackSection(RJSTrackSection track) {
195195
ImmutableSet.copyOf(operationalPointsPerTrack.get(track.id)),
196196
track.geo,
197197
track.sch,
198-
buildLoadingGaugeLimits(track.loadingGaugeLimits)
198+
buildLoadingGaugeLimits(track.loadingGaugeLimits),
199+
track.trackNumber,
200+
track.lineCode
199201
);
200202
builder.addEdge(begin, end, edge);
201203
edge.gradients = makeGradients(track);

core/src/main/java/fr/sncf/osrd/railjson/schema/infra/RJSTrackSection.java

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.sncf.osrd.railjson.schema.infra;
22

3+
import com.squareup.moshi.Json;
34
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
45
import fr.sncf.osrd.railjson.schema.common.ID;
56
import fr.sncf.osrd.railjson.schema.common.Identified;
@@ -23,6 +24,12 @@ public class RJSTrackSection implements Identified {
2324
public LineString geo;
2425
public LineString sch;
2526

27+
@Json(name = "line_code")
28+
public int lineCode;
29+
30+
@Json(name = "track_number")
31+
public int trackNumber;
32+
2633
public RJSTrackSection(String id, double length) {
2734
this.id = id;
2835
this.length = length;

core/src/main/java/fr/sncf/osrd/standalone_sim/ScheduleMetadataExtractor.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public static ResultTrain run(
5050
var stops = new ArrayList<ResultStops>();
5151
for (var stop : schedule.stops) {
5252
var stopTime = ResultPosition.interpolateTime(stop.position, headPositions);
53-
stops.add(new ResultStops(stopTime, stop.position, stop.duration));
53+
var location = trainPath.findLocation(stop.position);
54+
stops.add(new ResultStops(stopTime, stop.position, stop.duration,
55+
location.track().getLineCode(), location.track().getTrackNumber()));
5456
}
5557

5658
// Compute events
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
package fr.sncf.osrd.standalone_sim.result;
22

3+
import com.squareup.moshi.Json;
34
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
45

5-
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
6-
public record ResultStops(double time, double position, double duration) {
6+
@SuppressFBWarnings("URF_UNREAD_FIELD")
7+
public class ResultStops {
8+
double time;
9+
double position;
10+
double duration;
11+
@Json(name = "line_code")
12+
int lineCode;
13+
@Json(name = "track_number")
14+
int trackNumber;
15+
16+
/** RestultStops constructor */
17+
public ResultStops(double time, double position, double duration, int lineCode, int trackNumber) {
18+
this.time = time;
19+
this.position = position;
20+
this.duration = duration;
21+
this.lineCode = lineCode;
22+
this.trackNumber = trackNumber;
23+
}
724
}

tests/fuzzer/fuzzer.py

+41-27
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from dataclasses import dataclass
2-
from enum import Enum
3-
from typing import Dict, Tuple, Iterable, List, Set
41
import json
52
import random
63
import time
74
from collections import defaultdict
5+
from dataclasses import dataclass
6+
from enum import Enum
7+
from pathlib import Path
8+
from typing import Dict, Iterable, List, Set, Tuple
89

910
import requests
10-
from pathlib import Path
1111

1212
URL = "http://127.0.0.1:8000/"
1313
TIMEOUT = 15
@@ -25,7 +25,7 @@ class FailedTest(Exception):
2525

2626

2727
class ErrorType(str, Enum):
28-
PATHFINDING = "PATHFINDING",
28+
PATHFINDING = "PATHFINDING"
2929
SCHEDULE = "SCHEDULE"
3030
RESULT = "RESULT"
3131

@@ -38,14 +38,16 @@ class InfraGraph:
3838

3939

4040
def make_error(error_type: ErrorType, code: int, error: str, infra_name: str, path_payload: Dict, **kwargs):
41-
raise FailedTest({
42-
"error_type": error_type.value,
43-
"code": code,
44-
"error": error,
45-
"infra_name": infra_name,
46-
"path_payload": path_payload,
47-
**kwargs,
48-
})
41+
raise FailedTest(
42+
{
43+
"error_type": error_type.value,
44+
"code": code,
45+
"error": error,
46+
"infra_name": infra_name,
47+
"path_payload": path_payload,
48+
**kwargs,
49+
}
50+
)
4951

5052

5153
def run_test(infra: InfraGraph, base_url: str, infra_id: int, infra_name: str):
@@ -70,25 +72,37 @@ def run_test(infra: InfraGraph, base_url: str, infra_id: int, infra_name: str):
7072
if r.status_code // 100 == 4:
7173
print("ignore: invalid user input")
7274
return
73-
make_error(ErrorType.SCHEDULE, r.status_code, r.content.decode("utf-8"), infra_name, path_payload,
74-
schedule_payload=schedule_payload)
75+
make_error(
76+
ErrorType.SCHEDULE,
77+
r.status_code,
78+
r.content.decode("utf-8"),
79+
infra_name,
80+
path_payload,
81+
schedule_payload=schedule_payload,
82+
)
7583

7684
schedule_id = r.json()["ids"][0]
7785
r = requests.get(f"{base_url}train_schedule/{schedule_id}/result/", timeout=TIMEOUT)
7886
if r.status_code // 100 != 2:
79-
make_error(ErrorType.RESULT, r.status_code, r.content.decode("utf-8"), infra_name, path_payload,
80-
schedule_payload=schedule_payload, schedule_id=schedule_id)
87+
make_error(
88+
ErrorType.RESULT,
89+
r.status_code,
90+
r.content.decode("utf-8"),
91+
infra_name,
92+
path_payload,
93+
schedule_payload=schedule_payload,
94+
schedule_id=schedule_id,
95+
)
96+
97+
payload = r.json()
98+
assert "line_code" in payload["base"]["stops"][0]
99+
assert "track_number" in payload["base"]["stops"][0]
81100

82101
print("test PASSED")
83102

84103

85104
def run(
86-
base_url: str,
87-
infra_id: int,
88-
n_test: int = 1000,
89-
log_folder: Path = None,
90-
infra_name: str = None,
91-
seed: int = 0
105+
base_url: str, infra_id: int, n_test: int = 1000, log_folder: Path = None, infra_name: str = None, seed: int = 0
92106
):
93107
"""
94108
Runs every test
@@ -317,10 +331,10 @@ def make_random_ranges(path_length: float) -> List[Dict]:
317331
transitions.sort()
318332
for begin, end in zip(transitions[:1], transitions[1:]):
319333
yield {
320-
"begin_position": begin,
321-
"end_position": end,
322-
"value": make_random_allowance_value(end - begin),
323-
}
334+
"begin_position": begin,
335+
"end_position": end,
336+
"value": make_random_allowance_value(end - begin),
337+
}
324338

325339

326340
def make_random_allowances(path_length: float) -> List[Dict]:

0 commit comments

Comments
 (0)