mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
test(scenarios): a switch thrown under a train, standing, facing and trailing (#472)
* test(scenarios): on_track check of the black box
The runner reads the map of the tracks from the black box (the track
records, one for each way of a switch). The new on_track check takes
the vehicles of the case and, in every state the black box has of
them, wants the middle of each within max_offset (0.5 m) of the line of
a track, and two coupled vehicles no more than max_detour (5 m) farther
apart along the tracks than in a straight line. A vehicle thrown
sideways, or with its bogies on two tracks that part, is off the line;
a coach running beside the locomotive it is coupled to, on the next
track, is hundreds of metres away from it along the tracks.
* test(scenarios): a switch thrown under a train, standing, facing and trailing
Six cases on td.scn for the review of #289, point 2b: a switch of
Stacja1 thrown by an event under an EU07 with three coaches. The train
has to keep to the rails (on_track) and the AI to the route it is
really on (a signal at stop of the case on track 1).
On staging an axle on a switch keeps the way it ran onto but leaves
the switch by the way it is set to now, and the AI does not scan its
route again for a switch that changed behind the head of the train.
Trailing through the switch (standing, or running) is fine: the first
wheels from the frog end push the switch back. Facing, three cases
fail and are marked xfail:
- thrown with the locomotive on the switch: it jumps sideways at the
end of the switch, the train goes to track 1, and the AI, still on
the route of track 2, runs past the signal of track 1 at 40 km/h;
- thrown just behind the locomotive: the locomotive runs on along
track 2 and the coaches coupled to it along track 1, for 900 m;
- thrown under the standing train, which then leaves: a coach runs
with a bogie on each track, 2.3 m off both, and the AI reads the
signals of track 1 while running on track 2.
Nothing derails, with physics.derailment monitor or new. There is no
small fix: the axle keeping to its way was in the stack and taken out
before the merge (c268673c), and an interlocking of switches under
trains would change what sceneries can do.
* test(scenarios): the trailing case passes only once the switch was thrown, on_track allows a coach's chord on a curve by default
This commit is contained in:
@@ -499,6 +499,34 @@ back on (`LineContactorsHeldByLocalConverterSwitch()`, the part of #276 in `dete
|
||||
the `converteron` hint), is in the cab only: no command of a scenery or of the train's cables sets
|
||||
`ConverterAllowLocal`, and nobody sits in a cab in the test mode, so the switch is always on in a case.
|
||||
|
||||
The `eu07_td_switch_*` cases (fragment `td_switch_thrown.scn`, the review of #289, point 2b) throw a switch of
|
||||
Stacja1 by an event under an EU07 with three coaches and check that the train keeps to the rails (`on_track`) and that
|
||||
the AI keeps to the route it is really on. Both switches of the station have their points towards the line and the
|
||||
way to track 2 straight (position 0), to track 1 curved (position 1); the ends of the two ways are 1.9 m apart, the
|
||||
tracks 4.6 m. `zwr01` at the west end is run through facing by a train running into the station, `zwr02` at the east
|
||||
end trailing by one leaving it. The throw is an event set off once, by the rear axle of the locomotive running onto a
|
||||
track (`event1`/`event2` of it, which only the vehicle with the driver sets off) or by a launcher 5 s after the start;
|
||||
a driver that stands cold gets its order (`vars.order`) from `event0` of its track, after the throw where the train
|
||||
stands over the switch. On track 1 a signal at stop of the case's own stands at z 1100: the train has to stop before
|
||||
it (`event0` of `tdo_n1725` passes the test, running onto `tdo_n1734` fails it); on track 2 the exit signal `stacja1_k`
|
||||
at stop. What they showed on `staging` of 2026-11-22 (f15ea405), where an axle on a switch keeps the way it ran onto
|
||||
(the segment it took when it got onto the switch) but leaves the switch by the way it is set to now, and the AI does
|
||||
not scan its route again for a switch that changed behind the head of the train:
|
||||
|
||||
| case | throw | result |
|
||||
| --- | --- | --- |
|
||||
| `eu07_td_switch_facing_control` | none, set to track 1 from the start | passes: stops before the signal of track 1 |
|
||||
| `eu07_td_switch_thrown_facing_head` | `zwr01` to track 1 with the locomotive on the switch | `xfail`: the locomotive jumps sideways at the end of the switch (0.78 m off the track in the black box), the whole train goes to track 1, and the AI, still on the route of track 2, runs past the signal of track 1 at 40 km/h |
|
||||
| `eu07_td_switch_thrown_facing_behind` | `zwr01` to track 1 with the locomotive just past it | `xfail`: the locomotive runs on along track 2 and the coaches coupled to it along track 1, side by side, for 900 m |
|
||||
| `eu07_td_switch_thrown_standing_facing` | `zwr01` to track 1 under the standing train, which then leaves facing | `xfail`: the second coach runs with a bogie on each track, its body 2.3 m off both; the AI, which scans from the last vehicle, reads the signals of track 1 while it runs on track 2 (a signal passed at danger, `stacja1_j`) |
|
||||
| `eu07_td_switch_thrown_standing_trailing` | `zwr02` to track 1 under the standing train, which then leaves trailing | passes: the first wheels coming from track 2 push the switch back (as through any switch set against them from the frog end) |
|
||||
| `eu07_td_switch_thrown_trailing` | `zwr02` to track 2 under the coaches of the timetable train leaving track 1 | passes: the switch is pushed back, the train stops at Przystanek after 1402 m |
|
||||
|
||||
Nothing derails in any of them with `physics.derailment monitor` (the default; the monitor reported nothing either),
|
||||
and the three `xfail` cases run with `physics.derailment new` came out the same to the metre: the criteria of
|
||||
derailment look at the curve, the cant and the speed of a vehicle, not at its bogies being on two tracks. Nor does the
|
||||
coupler between a locomotive and a coach 4.6 m beside it break.
|
||||
|
||||
### Cases on a mission of a scenery
|
||||
|
||||
The cases made from players' reports (eu07/maszyna#421, #506, #524, #525) run a whole mission
|
||||
@@ -615,6 +643,19 @@ the row instead, logged by builds from this branch on.
|
||||
- `master_controller` `from_distance`, `to_distance`, `at_most`: the master controller stays at or below the
|
||||
position between the two distances, e.g. at 0 where the scenery tells the driver to coast.
|
||||
|
||||
- `on_track` `vehicles`, optional `max_offset` (0.75 m), `max_detour` (5 m): every vehicle whose name starts with
|
||||
`vehicles` (e.g. `{{vehicle}}`, the train of the case) keeps to the rails in the black box, in each of its states:
|
||||
its middle is within `max_offset` of the line of a track (level distance, the map of the tracks of the black box),
|
||||
and of two vehicles coupled to each other the way along the tracks from one to the other (through the ends of the
|
||||
tracks that meet) is no more than `max_detour` longer than the straight line between them. A vehicle with its
|
||||
bogies on two tracks that part, or thrown sideways, is off the line; a coach running on beside the locomotive it is
|
||||
coupled to, on the next track, has a way to it hundreds of metres long. A coach on a curve of 300 m, through the
|
||||
S of a switch, was up to 0.38 m off. The middle of a vehicle is the middle of the chord between its pivots, so on
|
||||
a curve of radius R a vehicle running right is a^2 / 8R off the track, a being the distance of the pivots: a 19.5 m
|
||||
coach 0.59 m at R 80, 0.79 m at R 60. The default suits curves down to about R 65 for such a coach; a case with
|
||||
tighter curves sets more. The black box lists a vehicle once a second, so a jump between two lists shows up only
|
||||
as it is at the next one.
|
||||
|
||||
New check types go in `CHECKS` in `run.py`; each gets the physicslog rows and the check's
|
||||
parameters and returns `(passed, detail)`. Checks on the log go in `LOG_CHECKS` and get the
|
||||
text of `log.txt` instead of the rows. Checks on the black box (`blackbox_doc.md` in the root of
|
||||
|
||||
52
tests/scenarios/cases/eu07_td_switch_facing_control.json
Normal file
52
tests/scenarios/cases/eu07_td_switch_facing_control.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"description": "Switch under a train, the control of the facing cases (#289 review 2b): an EU07 with three coaches runs from the west line into Stacja1 on td.scn, facing through switch zwr01, which is set to track 1 from the start (keyctrl02, with the entry signal at 40). Nothing is thrown. The train has to stop before a signal at stop on track 1 and stay on the rails.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_switch_thrown.scn",
|
||||
"vars": {
|
||||
"trainsets": [
|
||||
"trainset none start 80.0 0.0",
|
||||
"node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 0 0 enddynamic",
|
||||
"endtrainset"
|
||||
],
|
||||
"route": "node -1 0 autotest_route_launcher eventlauncher 0 0 0 -1 none 1034 keyctrl02 end",
|
||||
"throw": "zwr01_1",
|
||||
"trigger": "",
|
||||
"order": "Shunt -1 0"
|
||||
},
|
||||
"track_events": {
|
||||
"start": "event0 autotest_wake",
|
||||
"tdo_n1725": [
|
||||
"event2 autotest_signal1_info",
|
||||
"event0 autotest_pass"
|
||||
],
|
||||
"tdo_n1734": [
|
||||
"eventall1 autotest_fail",
|
||||
"eventall2 autotest_fail"
|
||||
]
|
||||
},
|
||||
"test_config": [
|
||||
"test.timeout 400",
|
||||
"test.standstill 120"
|
||||
],
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{
|
||||
"type": "starts",
|
||||
"min_speed": 30,
|
||||
"within": 200
|
||||
},
|
||||
{
|
||||
"type": "on_track",
|
||||
"vehicles": "{{vehicle}}",
|
||||
"max_offset": 0.6
|
||||
},
|
||||
{
|
||||
"type": "log_lacks",
|
||||
"pattern": "Bad driving"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"description": "Switch thrown under a train running facing through it (#289 review 2b): as eu07_td_switch_thrown_facing_head, but zwr01 is thrown to track 1 when the locomotive has left the switch for track 2 (event of tor2p, set off by its rear axle), with the coaches still before and on the switch. A train cannot run on two tracks at once: every vehicle has to keep to the line of a track, whatever the throw does to them.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_switch_thrown.scn",
|
||||
"vars": {
|
||||
"trainsets": [
|
||||
"trainset none start 80.0 0.0",
|
||||
"node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 0 0 enddynamic",
|
||||
"endtrainset"
|
||||
],
|
||||
"route": "node -1 0 autotest_route_launcher eventlauncher 0 0 0 -1 none 1034 keyctrl01 end",
|
||||
"throw": "zwr01_1 zwr01_V40",
|
||||
"trigger": "",
|
||||
"order": "Shunt -1 0"
|
||||
},
|
||||
"track_events": {
|
||||
"start": "event0 autotest_wake",
|
||||
"tor2p": [
|
||||
"event1 autotest_throw",
|
||||
"event2 autotest_throw"
|
||||
],
|
||||
"tdo_n109": "event0 autotest_pass"
|
||||
},
|
||||
"test_config": [
|
||||
"test.timeout 400",
|
||||
"test.standstill 120"
|
||||
],
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{
|
||||
"type": "starts",
|
||||
"min_speed": 30,
|
||||
"within": 200
|
||||
},
|
||||
{
|
||||
"type": "on_track",
|
||||
"vehicles": "{{vehicle}}",
|
||||
"max_offset": 0.6
|
||||
},
|
||||
{
|
||||
"type": "log_lacks",
|
||||
"pattern": "Bad driving"
|
||||
}
|
||||
],
|
||||
"xfail": "#289 review 2b, as before the stack (TrkFoll reverted in c268673c): the axles still on the switch leave it by the way it is set to now, those behind it take that way too, so the coaches go to track 1 and the locomotive they are coupled to runs on along track 2, 4.6 m beside them, with nothing derailed or broken"
|
||||
}
|
||||
57
tests/scenarios/cases/eu07_td_switch_thrown_facing_head.json
Normal file
57
tests/scenarios/cases/eu07_td_switch_thrown_facing_head.json
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"description": "Switch thrown under a train running facing through it (#289 review 2b): as eu07_td_switch_facing_control, but the way is set to track 2 (keyctrl01) and zwr01 is thrown to track 1 when the locomotive has run onto the switch with both its bogies (event of the switch track, set off by its rear axle). The locomotive and the train behind it have to go on to track 1 and stay on the rails, and the AI has to stop before the signal at stop on track 1.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_switch_thrown.scn",
|
||||
"vars": {
|
||||
"trainsets": [
|
||||
"trainset none start 80.0 0.0",
|
||||
"node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 0 0 enddynamic",
|
||||
"endtrainset"
|
||||
],
|
||||
"route": "node -1 0 autotest_route_launcher eventlauncher 0 0 0 -1 none 1034 keyctrl01 end",
|
||||
"throw": "zwr01_1 zwr01_V40",
|
||||
"trigger": "",
|
||||
"order": "Shunt -1 0"
|
||||
},
|
||||
"track_events": {
|
||||
"start": "event0 autotest_wake",
|
||||
"zwr01": [
|
||||
"event1 autotest_throw",
|
||||
"event2 autotest_throw"
|
||||
],
|
||||
"tdo_n1725": [
|
||||
"event2 autotest_signal1_info",
|
||||
"event0 autotest_pass"
|
||||
],
|
||||
"tdo_n1734": [
|
||||
"eventall1 autotest_fail",
|
||||
"eventall2 autotest_fail"
|
||||
]
|
||||
},
|
||||
"test_config": [
|
||||
"test.timeout 400",
|
||||
"test.standstill 120"
|
||||
],
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{
|
||||
"type": "starts",
|
||||
"min_speed": 30,
|
||||
"within": 200
|
||||
},
|
||||
{
|
||||
"type": "on_track",
|
||||
"vehicles": "{{vehicle}}",
|
||||
"max_offset": 0.6
|
||||
},
|
||||
{
|
||||
"type": "log_lacks",
|
||||
"pattern": "Bad driving"
|
||||
}
|
||||
],
|
||||
"xfail": "#289 review 2b, as before the stack (TrkFoll reverted in c268673c): an axle keeps the way of the switch it ran onto but leaves by the way the switch is set to now, so the locomotive jumps 1.9 m sideways at the end of the switch, an axle at a time; and the AI keeps the route it scanned before the throw (a switch behind the head of the train is not scanned again), so on track 1 it brakes for the exit signal of track 2 and runs past the signal at stop of track 1 at 40 km/h"
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"description": "Switch thrown under a standing train, which then leaves facing through it (#289 review 2b): an EU07 with three coaches stands cold across zwr01 on td.scn, the locomotive on track 2, the last coaches over the switch, which is set to track 2. 5 s after the start the switch is thrown to track 1; then the driver gets the order to go, into the station, facing through the switch. Every vehicle has to keep to the line of a track.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_switch_thrown.scn",
|
||||
"vars": {
|
||||
"trainsets": [
|
||||
"trainset none tor2p 50.0 0.0",
|
||||
"node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 0 0 enddynamic",
|
||||
"endtrainset"
|
||||
],
|
||||
"route": "",
|
||||
"throw": "zwr01_1 zwr01_V40",
|
||||
"trigger": [
|
||||
"event autotest_throw_later multiple 5 none autotest_throw endevent",
|
||||
"node -1 0 autotest_throw_launcher eventlauncher 0 0 0 -1 none 1034 autotest_throw_later end"
|
||||
],
|
||||
"order": "Shunt -1 0"
|
||||
},
|
||||
"track_events": {
|
||||
"tor2p": "event0 autotest_wake_after_throw",
|
||||
"tdo_n109": "event0 autotest_pass"
|
||||
},
|
||||
"test_config": [
|
||||
"test.timeout 400",
|
||||
"test.standstill 120"
|
||||
],
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{
|
||||
"type": "starts",
|
||||
"min_speed": 20,
|
||||
"within": 200
|
||||
},
|
||||
{
|
||||
"type": "on_track",
|
||||
"vehicles": "{{vehicle}}",
|
||||
"max_offset": 0.6
|
||||
},
|
||||
{
|
||||
"type": "log_lacks",
|
||||
"pattern": "Bad driving"
|
||||
}
|
||||
],
|
||||
"xfail": "#289 review 2b, as before the stack (TrkFoll reverted in c268673c): the axles that stood on the switch leave it by the way it is set to now, so the second coach runs with one bogie on track 2 and the other on track 1, 4.6 m apart, its body 2.3 m off both, with nothing derailed or broken; and the AI scans its route from the last vehicle through the switch as now set, reads the signals of track 1 while it runs on track 2, and its head is counted past the exit signal of track 1 at stop"
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"description": "Switch thrown under a standing train, which then leaves trailing through it (#289 review 2b): an EU07 with three coaches stands cold across zwr02 on td.scn, the locomotive on the line, the coaches behind it over the switch and on track 2, the switch set to track 2. 5 s after the start it is thrown to track 1; then the driver gets the order to go, out to the line. The wheels coming from track 2 push the switch back over (as through any switch set against them from the frog end); every vehicle has to keep to the line of a track. Passes once the locomotive runs onto tdo_n176, with the train clear of the switch.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_switch_thrown.scn",
|
||||
"vars": {
|
||||
"trainsets": [
|
||||
"trainset none tdo_n145 40.0 0.0",
|
||||
"node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 0 0 enddynamic",
|
||||
"endtrainset"
|
||||
],
|
||||
"route": "",
|
||||
"throw": "zwr02_1 zwr02_v40",
|
||||
"trigger": [
|
||||
"event autotest_throw_later multiple 5 none autotest_throw endevent",
|
||||
"node -1 0 autotest_throw_launcher eventlauncher 0 0 0 -1 none 1034 autotest_throw_later end"
|
||||
],
|
||||
"order": "Obey_train 0 0"
|
||||
},
|
||||
"track_events": {
|
||||
"tdo_n145": "event0 autotest_wake_after_throw",
|
||||
"tdo_n176": [
|
||||
"event1 autotest_pass_running",
|
||||
"event2 autotest_pass_running"
|
||||
]
|
||||
},
|
||||
"test_config": [
|
||||
"test.timeout 400",
|
||||
"test.standstill 120",
|
||||
"test.no_movement_before_pass no"
|
||||
],
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{
|
||||
"type": "starts",
|
||||
"min_speed": 10,
|
||||
"within": 200
|
||||
},
|
||||
{
|
||||
"type": "on_track",
|
||||
"vehicles": "{{vehicle}}",
|
||||
"max_offset": 0.6
|
||||
},
|
||||
{
|
||||
"type": "log_lacks",
|
||||
"pattern": "Bad driving"
|
||||
}
|
||||
]
|
||||
}
|
||||
56
tests/scenarios/cases/eu07_td_switch_thrown_trailing.json
Normal file
56
tests/scenarios/cases/eu07_td_switch_thrown_trailing.json
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"description": "Switch thrown under a train running trailing through it (#289 review 2b): the td/rozklad timetable train, an EU07 with three coaches, leaves track 1 of Stacja1 on td.scn through zwr02 from its frog end; when the locomotive has run onto the line (event of tdo_n145, set off by its rear axle) the switch is thrown to track 2 under the coaches. The wheels coming from track 1 push it back over; the train has to stay on the rails and run its timetable to the stop at Przystanek.",
|
||||
"base_scenery": "td.scn",
|
||||
"time": "10:34",
|
||||
"fragment": "td_switch_thrown.scn",
|
||||
"vars": {
|
||||
"trainsets": [
|
||||
"trainset td/rozklad tdo_n1734 0.0 0.1",
|
||||
"node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic",
|
||||
"node -1 0 {{vehicle}}_c3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 0 0 enddynamic",
|
||||
"endtrainset"
|
||||
],
|
||||
"route": "node -1 0 autotest_route_launcher eventlauncher 0 0 0 -1 none 1034 keyctrl04 end",
|
||||
"throw": "zwr02_0 zwr02_vmax",
|
||||
"trigger": "",
|
||||
"order": "Obey_train 0 0"
|
||||
},
|
||||
"track_events": {
|
||||
"tdo_n145": [
|
||||
"event1 autotest_throw",
|
||||
"event2 autotest_throw"
|
||||
]
|
||||
},
|
||||
"duration": 300,
|
||||
"timeout": 600,
|
||||
"checks": [
|
||||
{
|
||||
"type": "starts",
|
||||
"min_speed": 20,
|
||||
"within": 240
|
||||
},
|
||||
{
|
||||
"type": "stops",
|
||||
"moving_speed": 20,
|
||||
"stop_speed": 1.0,
|
||||
"hold": 0,
|
||||
"min_distance": 1380,
|
||||
"max_distance": 1420
|
||||
},
|
||||
{
|
||||
"type": "on_track",
|
||||
"vehicles": "{{vehicle}}",
|
||||
"max_offset": 0.6
|
||||
},
|
||||
{
|
||||
"type": "log_lacks",
|
||||
"pattern": "Bad driving"
|
||||
},
|
||||
{
|
||||
"type": "log_contains",
|
||||
"pattern": "EVENT LAUNCHED.*: autotest_throw_done$"
|
||||
}
|
||||
]
|
||||
}
|
||||
45
tests/scenarios/cases/td_switch_thrown.scn
Normal file
45
tests/scenarios/cases/td_switch_thrown.scn
Normal file
@@ -0,0 +1,45 @@
|
||||
// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed.
|
||||
// a switch of Stacja1 thrown by an event while a train stands or runs over it (the review of MaSzyna-EU07/maszyna#289,
|
||||
// point 2b). Both switches of the station have their points (point 1) towards the line and two ways from there to
|
||||
// the station: position 0 straight to track 2 (x 0.4), position 1 curved to track 1 (x 2.3 at the end of the switch,
|
||||
// x 5.0 further on). The events of zwrp34r300.inc / zwrl34r300.inc: <switch>+ sets position 0, <switch>- position 1
|
||||
// (and the speed of the switch: none on the straight, 40 on the curve).
|
||||
// - zwr01, west end: points at z 336, the ways end at z 370 (tor2p, track 2; tdo_n1641, track 1). A train running
|
||||
// towards z 2000 (into the station) goes through it facing, from the points.
|
||||
// - zwr02, east end: points at z 1436 (tdo_n145, the line), the ways end at z 1402 (tor2k, track 2; tdo_n1744,
|
||||
// track 1). A train running towards z 2000 (out of the station) goes through it trailing, from the frog end.
|
||||
// A trainset faces point 2 of its track (towards z 2000 on all these tracks): the first vehicle has its front as many
|
||||
// metres past point 1 as the trainset says, the others stand behind it.
|
||||
{{trainsets}}
|
||||
|
||||
// the way set at the start, if any (a launcher with a positive time fires once at that hour, the scenery starts
|
||||
// at 10:34)
|
||||
{{route}}
|
||||
|
||||
// the throw (vars.throw), once: whichever of the events hung on the tracks of the case (track_events) or the
|
||||
// launcher (vars.trigger) sets it off first, the memory cell keeps the others from doing it again
|
||||
node -1 0 autotest_thrown memcell 0 0 0 thrown 0 0 none endmemcell
|
||||
event autotest_throw multiple 0 autotest_thrown {{throw}} autotest_throw_done condition memcompare * 0 * endevent
|
||||
event autotest_throw_done UpdateValues 0 autotest_thrown * 1 * endevent
|
||||
{{trigger}}
|
||||
|
||||
// a driver of a trainset of velocity 0 sleeps until it gets an order. event0 of the track its vehicle stands on
|
||||
// (track_events) gives it, once: vars.order, e.g. Shunt -1 0 (go on shunting with the whole train; a proceed aspect
|
||||
// of a main signal ahead turns that into a train run) or Obey_train 0 0. autotest_wake gives it at once,
|
||||
// autotest_wake_after_throw only once the switch has been thrown (for a train standing over the switch)
|
||||
node -1 0 autotest_ordered memcell 0 0 0 ordered 0 0 none endmemcell
|
||||
event autotest_wake_after_throw multiple 0 autotest_thrown autotest_wake condition memcompare * 1 * endevent
|
||||
event autotest_wake multiple 0 autotest_ordered autotest_order autotest_order_given condition memcompare * 0 * endevent
|
||||
event autotest_order PutValues 0 none 0 0 0 {{order}} endevent
|
||||
event autotest_order_given UpdateValues 0 autotest_ordered * 1 * endevent
|
||||
|
||||
// a signal at stop on track 1 for a train running towards z 2000: the memory cell stands beside the track at z 1100
|
||||
// and event2 of tdo_n1725 (z 1065-1165, track_events) reads it. A train on track 1 has to stop before it, with its head
|
||||
// on tdo_n1725, where event0 passes the test; running onto tdo_n1734 (z 1165-1265) beyond the signal fails it. On
|
||||
// track 2 the train stops before the exit signal stacja1_k (z 1316, at stop all the time), with its head on tdo_n109
|
||||
// (z 1236-1336)
|
||||
node -1 0 autotest_signal1 memcell 5.04488 0.2 1100.0 SetVelocity 0 0 none endmemcell
|
||||
event autotest_signal1_info getvalues 0 autotest_signal1 endevent
|
||||
event autotest_pass UpdateValues 0 __test.result stopped_before_the_signal 1 * endevent
|
||||
event autotest_fail UpdateValues 0 __test.result ran_past_the_signal_of_track_1 0 * endevent
|
||||
event autotest_pass_running UpdateValues 0 __test.result ran_clear_of_the_switch 1 * endevent
|
||||
@@ -27,6 +27,7 @@ Usage:
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import heapq
|
||||
import json
|
||||
import os
|
||||
import math
|
||||
@@ -300,6 +301,7 @@ def read_text(path: Path | None) -> str:
|
||||
# physicslog/<scenery>_<date>.blackbox. A header, then records: a byte of the kind, the length, the content
|
||||
BLACKBOX_MAGIC = b"EU07BBX\0"
|
||||
BLACKBOX_HEADER = 12 # the magic, the version of the format, two bytes reserved
|
||||
BLACKBOX_TRACK = 0x10 # the map: a rail track, or one way of a switch, as points along it
|
||||
BLACKBOX_VEHICLE = 0x12 # a vehicle: its number and its name
|
||||
BLACKBOX_VEHICLES = 0x21 # once a second: the vehicles which moved, changed speed or got another driver
|
||||
BLACKBOX_COUPLING = 0x37 # a coupler of a vehicle coupled, uncoupled, or its hoses and cables changed
|
||||
@@ -329,9 +331,20 @@ class VehicleState:
|
||||
driver: int # 0 none, 1 a user, 2 the AI
|
||||
|
||||
|
||||
@dataclass
|
||||
class Track:
|
||||
"""A `track` record: a plain track, or one way of a switch (several records under the number of the switch)."""
|
||||
number: int
|
||||
name: str
|
||||
kind: int # 0 a plain track, 1 a way of a switch
|
||||
branch: int # the switch position this way is taken in
|
||||
points: list[tuple[float, float, float]]
|
||||
|
||||
|
||||
@dataclass
|
||||
class Blackbox:
|
||||
vehicles: dict[int, str] = field(default_factory=dict) # names by number
|
||||
tracks: list[Track] = field(default_factory=list) # the map, in the order written
|
||||
couplings: list[Coupling] = field(default_factory=list) # in the order written
|
||||
states: dict[int, list[VehicleState]] = field(default_factory=dict) # of each vehicle by number, in time order
|
||||
end_time: float = 0.0 # of the last `vehicles` record
|
||||
@@ -347,8 +360,22 @@ def find_blackbox(game_dir: Path, scenery: str, since: float) -> Path | None:
|
||||
return max(files, key=lambda p: p.stat().st_mtime, default=None)
|
||||
|
||||
|
||||
def _blackbox_text(content: bytes, start: int) -> tuple[str, int]:
|
||||
"""A text of a black box record at `start`, and where the field after it begins."""
|
||||
# its length in 7 bit groups, low first, the high bit set on all but the last
|
||||
size, shift = 0, 0
|
||||
while True:
|
||||
byte = content[start]
|
||||
start += 1
|
||||
size |= (byte & 0x7F) << shift
|
||||
shift += 7
|
||||
if byte < 0x80:
|
||||
break
|
||||
return content[start: start + size].decode("utf-8", errors="replace"), start + size
|
||||
|
||||
|
||||
def read_blackbox(path: Path | None) -> Blackbox | None:
|
||||
"""The vehicles and the coupling records of a black box; None when there is none or it can't be read."""
|
||||
"""The map, the vehicles and the coupling records of a black box; None when there is none or it can't be read."""
|
||||
try:
|
||||
data = path.read_bytes() if path else b""
|
||||
except FileNotFoundError:
|
||||
@@ -366,16 +393,14 @@ def read_blackbox(path: Path | None) -> Blackbox | None:
|
||||
at += 5 + length
|
||||
if kind == BLACKBOX_VEHICLE:
|
||||
number, = struct.unpack_from("<I", content)
|
||||
# a text: its length in 7 bit groups, low first, the high bit set on all but the last
|
||||
size, shift, start = 0, 0, 4
|
||||
while True:
|
||||
byte = content[start]
|
||||
start += 1
|
||||
size |= (byte & 0x7F) << shift
|
||||
shift += 7
|
||||
if byte < 0x80:
|
||||
break
|
||||
box.vehicles[number] = content[start: start + size].decode("utf-8", errors="replace")
|
||||
box.vehicles[number], _ = _blackbox_text(content, 4)
|
||||
elif kind == BLACKBOX_TRACK:
|
||||
# the number, the name, the kind, the switch position of the way, the category, the points
|
||||
number, = struct.unpack_from("<I", content)
|
||||
name, start = _blackbox_text(content, 4)
|
||||
track_kind, branch, _, count = struct.unpack_from("<BBBI", content, start)
|
||||
points = [struct.unpack_from("<3f", content, start + 7 + 12 * i) for i in range(count)]
|
||||
box.tracks.append(Track(number, name, track_kind, branch, points))
|
||||
elif kind == BLACKBOX_VEHICLES:
|
||||
# the time, a keyframe mark, the count, then 25 bytes a vehicle: number, position, heading, speed, driver
|
||||
when, _, count = struct.unpack_from("<dBI", content)
|
||||
@@ -923,6 +948,159 @@ def check_moves(box, vehicle, min_speed, direction="front"):
|
||||
return True, f"{vehicle} runs {direction} end leading: {min_speed} km/h at t={first.time:.1f}s, up to {sign * fastest.speed:.1f} km/h"
|
||||
|
||||
|
||||
def _along_track(track, x, z):
|
||||
"""Where the point (x, z) lies by the track: its level distance [m] from the line of the track, and how far along
|
||||
the track [m] from its first point that nearest point of the line is."""
|
||||
best, at, run_length = math.inf, 0.0, 0.0
|
||||
if len(track.points) == 1:
|
||||
return math.hypot(x - track.points[0][0], z - track.points[0][2]), 0.0
|
||||
for (ax, _, az), (bx, _, bz) in zip(track.points, track.points[1:]):
|
||||
dx, dz = bx - ax, bz - az
|
||||
length = dx * dx + dz * dz
|
||||
share = 0.0 if length == 0.0 else max(0.0, min(1.0, ((x - ax) * dx + (z - az) * dz) / length))
|
||||
offset = math.hypot(x - (ax + share * dx), z - (az + share * dz))
|
||||
if offset < best:
|
||||
best, at = offset, run_length + share * math.sqrt(length)
|
||||
run_length += math.sqrt(length)
|
||||
return best, at
|
||||
|
||||
|
||||
def _track_length(track):
|
||||
return sum(math.hypot(b[0] - a[0], b[2] - a[2]) for a, b in zip(track.points, track.points[1:]))
|
||||
|
||||
|
||||
def _track_label(track):
|
||||
return f"{track.name or '#' + str(track.number)}" + (f" (way {track.branch})" if track.kind == 1 else "")
|
||||
|
||||
|
||||
class _TrackMap:
|
||||
"""The tracks of a black box as a network: the ends of the tracks (and of the ways of the switches) that meet are
|
||||
one node, each track an edge of its length between its two ends."""
|
||||
|
||||
JOINT = 0.3 # ends closer than this [m], level, meet
|
||||
|
||||
def __init__(self, tracks):
|
||||
self.tracks = tracks
|
||||
self.lengths = [_track_length(t) for t in tracks]
|
||||
nodes = [] # (x, z) of each node
|
||||
self.ends = [] # the nodes of the first and the last point of each track
|
||||
for track in tracks:
|
||||
pair = []
|
||||
for x, _, z in (track.points[0], track.points[-1]):
|
||||
node = next((i for i, (nx, nz) in enumerate(nodes) if math.hypot(nx - x, nz - z) < self.JOINT), None)
|
||||
if node is None:
|
||||
nodes.append((x, z))
|
||||
node = len(nodes) - 1
|
||||
pair.append(node)
|
||||
self.ends.append(tuple(pair))
|
||||
self.edges = {} # node: [(other node, length)]
|
||||
for (a, b), length in zip(self.ends, self.lengths):
|
||||
self.edges.setdefault(a, []).append((b, length))
|
||||
self.edges.setdefault(b, []).append((a, length))
|
||||
|
||||
def places(self, position, max_offset):
|
||||
"""The tracks the position lies on: within max_offset [m] of their line, (track index, offset, along)."""
|
||||
x, _, z = position
|
||||
found = [(i, *_along_track(t, x, z)) for i, t in enumerate(self.tracks)]
|
||||
near = [f for f in found if f[1] <= max_offset]
|
||||
return near or [min(found, key=lambda f: f[1])]
|
||||
|
||||
def distance(self, one, other, limit):
|
||||
"""The shortest way [m] along the tracks between two places (track index, offset, along), up to `limit`
|
||||
(beyond it, infinity)."""
|
||||
(i, _, s), (j, _, t) = one, other
|
||||
if i == j:
|
||||
return abs(s - t)
|
||||
start = {self.ends[i][0]: s, self.ends[i][1]: self.lengths[i] - s}
|
||||
goal = {self.ends[j][0]: t, self.ends[j][1]: self.lengths[j] - t}
|
||||
reached = dict(start)
|
||||
queue = [(cost, node) for node, cost in start.items()]
|
||||
heapq.heapify(queue)
|
||||
best = math.inf
|
||||
while queue:
|
||||
cost, node = heapq.heappop(queue)
|
||||
if cost > reached.get(node, math.inf) or cost >= min(best, limit):
|
||||
continue
|
||||
if node in goal:
|
||||
best = min(best, cost + goal[node])
|
||||
for nxt, length in self.edges.get(node, []):
|
||||
if cost + length < reached.get(nxt, math.inf):
|
||||
reached[nxt] = cost + length
|
||||
heapq.heappush(queue, (cost + length, nxt))
|
||||
return best if best <= limit else math.inf
|
||||
|
||||
|
||||
def _coupled_pairs(box, chosen, upto):
|
||||
"""The pairs of vehicles (by number) among `chosen` whose couplers hold each other at the time `upto`."""
|
||||
held = {}
|
||||
for c in box.couplings:
|
||||
if c.time > upto:
|
||||
break
|
||||
held[(c.vehicle, c.side)] = (c.other, c.flags)
|
||||
return {tuple(sorted((vehicle, other))) for (vehicle, _), (other, flags) in held.items()
|
||||
if flags & COUPLING_COUPLER and vehicle in chosen and other in chosen}
|
||||
|
||||
|
||||
def check_on_track(box, vehicles, max_offset=0.75, max_detour=5.0):
|
||||
"""Every vehicle whose name starts with `vehicles` stays on the line of a track in every state the black box has of
|
||||
it, and the vehicles coupled to each other stay on one way: the way along the tracks from one to the other is no
|
||||
more than `max_detour` [m] longer than the straight line between them. A vehicle thrown sideways has its middle off
|
||||
any track; one with its bogies on two tracks that part too, once they are apart; and a train whose vehicles went
|
||||
two ways at a switch runs on with two coupled vehicles on two tracks, side by side, with the way between them back
|
||||
through the switch."""
|
||||
if not box.tracks:
|
||||
return False, "the black box has no map of the tracks"
|
||||
chosen = {number: name for number, name in box.vehicles.items() if name.lower().startswith(vehicles.lower())}
|
||||
if not chosen:
|
||||
return False, f"the black box has no vehicle named {vehicles}..."
|
||||
network = _TrackMap(box.tracks)
|
||||
# the states of the chosen vehicles by time: a vehicle is listed when it moved, or every 60 s
|
||||
times = sorted({s.time for number in chosen for s in box.states.get(number, [])})
|
||||
if not times:
|
||||
return False, f"the black box has no state of {', '.join(chosen.values())}"
|
||||
latest, index, places = {}, {number: 0 for number in chosen}, {}
|
||||
worst_offset, worst_detour, failures = None, None, []
|
||||
for when in times:
|
||||
for number in chosen:
|
||||
states = box.states.get(number, [])
|
||||
while index[number] < len(states) and states[index[number]].time <= when:
|
||||
latest[number] = states[index[number]]
|
||||
index[number] += 1
|
||||
for number, state in latest.items():
|
||||
if (number, state.time) in places:
|
||||
continue
|
||||
places[(number, state.time)] = network.places(state.position, max_offset)
|
||||
nearest = min(places[(number, state.time)], key=lambda p: p[1])
|
||||
if worst_offset is None or nearest[1] > worst_offset[0]:
|
||||
worst_offset = (nearest[1], chosen[number], state, box.tracks[nearest[0]])
|
||||
for one, other in _coupled_pairs(box, chosen, when):
|
||||
if one not in latest or other not in latest:
|
||||
continue
|
||||
straight = math.dist(latest[one].position, latest[other].position)
|
||||
at_one, at_other = places[(one, latest[one].time)], places[(other, latest[other].time)]
|
||||
way = min(network.distance(a, b, straight + 1000.0) for a in at_one for b in at_other)
|
||||
detour = way - straight
|
||||
if worst_detour is None or detour > worst_detour[0]:
|
||||
worst_detour = (detour, chosen[one], chosen[other], when, at_one, at_other)
|
||||
offset, name, state, track = worst_offset
|
||||
where = f"{name} at t={state.time:.1f}s ({abs(state.speed):.1f} km/h) {offset:.2f} m off {_track_label(track)}"
|
||||
if offset > max_offset:
|
||||
failures.append(f"{where}, more than {max_offset} m")
|
||||
detail = f"the farthest off a track {where}"
|
||||
if worst_detour is not None:
|
||||
detour, one, other, when, at_one, at_other = worst_detour
|
||||
tracks = (f"{_track_label(box.tracks[min(at_one, key=lambda p: p[1])[0]])} and "
|
||||
f"{_track_label(box.tracks[min(at_other, key=lambda p: p[1])[0]])}")
|
||||
length = "no way along the tracks" if math.isinf(detour) else f"the way along the tracks {detour:.1f} m longer than the straight line"
|
||||
said = f"{one} and {other}, coupled, at t={when:.1f}s on {tracks}: {length}"
|
||||
if detour > max_detour:
|
||||
failures.append(f"{said}, more than {max_detour} m")
|
||||
detail += f"; of the coupled ones {said}"
|
||||
if failures:
|
||||
return False, "; ".join(failures)
|
||||
return True, f"{len(chosen)} vehicle(s), {detail}"
|
||||
|
||||
|
||||
# checks on the black box of the run rather than on the physicslog rows
|
||||
BLACKBOX_CHECKS = {
|
||||
"couples": check_couples,
|
||||
@@ -930,6 +1108,7 @@ BLACKBOX_CHECKS = {
|
||||
"driver_changes": check_driver_changes,
|
||||
"stops_driverless": check_stops_driverless,
|
||||
"moves": check_moves,
|
||||
"on_track": check_on_track,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user