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

API add stops details to the report #1930

Merged
merged 1 commit into from
Sep 21, 2022
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
2 changes: 2 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,8 @@ components:
time: { type: number, format: float }
position: { type: number, format: float }
duration: { type: number, format: float }
line_code: { type: number }
track_number: { type: number }
route_aspects:
type: array
items:
Expand Down
44 changes: 23 additions & 21 deletions api/osrd_infra/views/train_schedule/standalone_simulation_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ def convert_simulation_results(
route_begin_occupancy, route_end_occupancy = convert_route_occupancies(
simulation_result["route_occupancies"], projection_path_payload, departure_time
)
route_aspects = project_signal_updates(
simulation_result["signal_updates"], projection_path_payload, departure_time
)
route_aspects = project_signal_updates(simulation_result["signal_updates"], projection_path_payload, departure_time)

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

for update in signal_updates:
results.append({
"signal_id": update["signal_id"],
"time_start": update["time_start"] + departure_time,
"time_end": update["time_end"] + departure_time,
"color": update["color"],
"blinking": update["blinking"],
"aspect_label": update["aspect_label"]
})
results.append(
{
"signal_id": update["signal_id"],
"time_start": update["time_start"] + departure_time,
"time_end": update["time_end"] + departure_time,
"color": update["color"],
"blinking": update["blinking"],
"aspect_label": update["aspect_label"],
}
)
return results


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

for update in updates_by_route_id[route_id]:
results.append({
"signal_id": update["signal_id"],
"route_id": route_id,
"time_start": update["time_start"] + departure_time,
"time_end": update["time_end"] + departure_time,
"position_start": start_pos,
"position_end": end_pos,
"color": update["color"],
"blinking": update["blinking"]
})
results.append(
{
"signal_id": update["signal_id"],
"route_id": route_id,
"time_start": update["time_start"] + departure_time,
"time_end": update["time_end"] + departure_time,
"position_start": start_pos,
"position_end": end_pos,
"color": update["color"],
"blinking": update["blinking"],
}
)
start_pos = end_pos
return results

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ public sealed interface TrackEdge permits SwitchBranch, TrackSection {

/** Returns a list of ranges, each having a set of blocked loading gauge type */
ImmutableRangeMap<Double, LoadingGaugeConstraint> getLoadingGaugeConstraints();

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
package fr.sncf.osrd.infra.api.tracks.undirected;

public non-sealed interface TrackSection extends TrackEdge {}
public non-sealed interface TrackSection extends TrackEdge {

/** Returns line code */
int getLineCode();

/** Returns track number */
int getTrackNumber();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class TrackSectionImpl implements TrackSection {
private final LineString geo;
private final LineString sch;
private final ImmutableRangeMap<Double, LoadingGaugeConstraint> loadingGaugeConstraints;
private final int trackNumber;
private final int lineCode;

@Override
@ExcludeFromGeneratedCodeCoverage
Expand All @@ -37,17 +39,21 @@ public TrackSectionImpl(
ImmutableSet<OperationalPoint> operationalPoints,
LineString geo,
LineString sch,
ImmutableRangeMap<Double, LoadingGaugeConstraint> loadingGaugeConstraints
ImmutableRangeMap<Double, LoadingGaugeConstraint> loadingGaugeConstraints,
int trackNumber,
int lineCode
) {
this.length = length;
this.id = id;
this.operationalPoints = operationalPoints;
this.geo = geo;
this.sch = sch;
this.loadingGaugeConstraints = loadingGaugeConstraints;
this.trackNumber = trackNumber;
this.lineCode = lineCode;
}

/** Constructor with empty operational points and geometry */
/** Constructor with empty operational points, geometry, line code and track number */
public TrackSectionImpl(
double length,
String id
Expand All @@ -58,6 +64,8 @@ public TrackSectionImpl(
this.geo = null;
this.sch = null;
this.operationalPoints = ImmutableSet.of();
this.trackNumber = 0;
this.lineCode = 0;
speedSections = new EnumMap<>(Direction.class);
for (var dir : Direction.values())
speedSections.put(dir, ImmutableRangeMap.of());
Expand Down Expand Up @@ -103,6 +111,16 @@ public ImmutableRangeMap<Double, LoadingGaugeConstraint> getLoadingGaugeConstrai
return loadingGaugeConstraints;
}

@Override
public int getLineCode() {
return lineCode;
}

@Override
public int getTrackNumber() {
return trackNumber;
}

@Override
public LineString getGeo() {
return geo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ private TrackSectionImpl makeTrackSection(RJSTrackSection track) {
ImmutableSet.copyOf(operationalPointsPerTrack.get(track.id)),
track.geo,
track.sch,
buildLoadingGaugeLimits(track.loadingGaugeLimits)
buildLoadingGaugeLimits(track.loadingGaugeLimits),
track.trackNumber,
track.lineCode
);
builder.addEdge(begin, end, edge);
edge.gradients = makeGradients(track);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.sncf.osrd.railjson.schema.infra;

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

@Json(name = "line_code")
public int lineCode;

@Json(name = "track_number")
public int trackNumber;

public RJSTrackSection(String id, double length) {
this.id = id;
this.length = length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public static ResultTrain run(
var stops = new ArrayList<ResultStops>();
for (var stop : schedule.stops) {
var stopTime = ResultPosition.interpolateTime(stop.position, headPositions);
stops.add(new ResultStops(stopTime, stop.position, stop.duration));
var location = trainPath.findLocation(stop.position);
stops.add(new ResultStops(stopTime, stop.position, stop.duration,
location.track().getLineCode(), location.track().getTrackNumber()));
}

// Compute events
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
package fr.sncf.osrd.standalone_sim.result;

import com.squareup.moshi.Json;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public record ResultStops(double time, double position, double duration) {
@SuppressFBWarnings("URF_UNREAD_FIELD")
public class ResultStops {
double time;
double position;
double duration;
@Json(name = "line_code")
int lineCode;
@Json(name = "track_number")
int trackNumber;

/** RestultStops constructor */
public ResultStops(double time, double position, double duration, int lineCode, int trackNumber) {
this.time = time;
this.position = position;
this.duration = duration;
this.lineCode = lineCode;
this.trackNumber = trackNumber;
}
}
68 changes: 41 additions & 27 deletions tests/fuzzer/fuzzer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from dataclasses import dataclass
from enum import Enum
from typing import Dict, Tuple, Iterable, List, Set
import json
import random
import time
from collections import defaultdict
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
from typing import Dict, Iterable, List, Set, Tuple

import requests
from pathlib import Path

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


class ErrorType(str, Enum):
PATHFINDING = "PATHFINDING",
PATHFINDING = "PATHFINDING"
SCHEDULE = "SCHEDULE"
RESULT = "RESULT"

Expand All @@ -38,14 +38,16 @@ class InfraGraph:


def make_error(error_type: ErrorType, code: int, error: str, infra_name: str, path_payload: Dict, **kwargs):
raise FailedTest({
"error_type": error_type.value,
"code": code,
"error": error,
"infra_name": infra_name,
"path_payload": path_payload,
**kwargs,
})
raise FailedTest(
{
"error_type": error_type.value,
"code": code,
"error": error,
"infra_name": infra_name,
"path_payload": path_payload,
**kwargs,
}
)


def run_test(infra: InfraGraph, base_url: str, infra_id: int, infra_name: str):
Expand All @@ -70,25 +72,37 @@ def run_test(infra: InfraGraph, base_url: str, infra_id: int, infra_name: str):
if r.status_code // 100 == 4:
print("ignore: invalid user input")
return
make_error(ErrorType.SCHEDULE, r.status_code, r.content.decode("utf-8"), infra_name, path_payload,
schedule_payload=schedule_payload)
make_error(
ErrorType.SCHEDULE,
r.status_code,
r.content.decode("utf-8"),
infra_name,
path_payload,
schedule_payload=schedule_payload,
)

schedule_id = r.json()["ids"][0]
r = requests.get(f"{base_url}train_schedule/{schedule_id}/result/", timeout=TIMEOUT)
if r.status_code // 100 != 2:
make_error(ErrorType.RESULT, r.status_code, r.content.decode("utf-8"), infra_name, path_payload,
schedule_payload=schedule_payload, schedule_id=schedule_id)
make_error(
ErrorType.RESULT,
r.status_code,
r.content.decode("utf-8"),
infra_name,
path_payload,
schedule_payload=schedule_payload,
schedule_id=schedule_id,
)

payload = r.json()
assert "line_code" in payload["base"]["stops"][0]
assert "track_number" in payload["base"]["stops"][0]

print("test PASSED")


def run(
base_url: str,
infra_id: int,
n_test: int = 1000,
log_folder: Path = None,
infra_name: str = None,
seed: int = 0
base_url: str, infra_id: int, n_test: int = 1000, log_folder: Path = None, infra_name: str = None, seed: int = 0
):
"""
Runs every test
Expand Down Expand Up @@ -317,10 +331,10 @@ def make_random_ranges(path_length: float) -> List[Dict]:
transitions.sort()
for begin, end in zip(transitions[:1], transitions[1:]):
yield {
"begin_position": begin,
"end_position": end,
"value": make_random_allowance_value(end - begin),
}
"begin_position": begin,
"end_position": end,
"value": make_random_allowance_value(end - begin),
}


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