Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tesi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marco Aceti
Tesi
Commits
703f0b42
Verified
Commit
703f0b42
authored
Mar 16, 2023
by
Marco Aceti
Browse files
Options
Downloads
Patches
Plain Diff
Better handle partially cancelled trains
...with no arriving trains
parent
ddd19019
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2673
passed
Mar 16, 2023
Stage: test
Stage: lint
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/scraper/tests/test_train_stop.py
+4
-4
4 additions, 4 deletions
src/scraper/tests/test_train_stop.py
src/scraper/train.py
+17
-3
17 additions, 3 deletions
src/scraper/train.py
src/scraper/train_stop.py
+2
-2
2 additions, 2 deletions
src/scraper/train_stop.py
with
23 additions
and
9 deletions
src/scraper/tests/test_train_stop.py
+
4
−
4
View file @
703f0b42
...
...
@@ -40,13 +40,13 @@ def test_stop_time_assumption():
@pytest.mark.parametrize
(
"
data_file, expected_repr
"
,
[
(
"
train-stop_10860.json
"
,
"
@ Piacenza 09:07 ~ 09:07 +0.5m [5 ~ 5]
"
),
(
"
train-stop_3073.json
"
,
"
@ Arquata Scrivia 17:43 --> 17:44 [5]
"
),
(
"
train-stop_10860.json
"
,
"
@
(P)
Piacenza 09:07 ~ 09:07 +0.5m [5 ~ 5]
"
),
(
"
train-stop_3073.json
"
,
"
@
(F)
Arquata Scrivia 17:43 --> 17:44 [5]
"
),
(
"
train-stop_555.json
"
,
"
@ Latina 14:58 ~ 15:01 +3.5m --> 15:00 ~ 15:03 +3.5m [? ~ 2]
"
,
"
@
(F)
Latina 14:58 ~ 15:01 +3.5m --> 15:00 ~ 15:03 +3.5m [? ~ 2]
"
,
),
(
"
train-stop_22662.json
"
,
"
@ Treviglio 17:50 [2 TR Ovest]
"
),
(
"
train-stop_22662.json
"
,
"
@
(A)
Treviglio 17:50 [2 TR Ovest]
"
),
],
)
def
test_stop_repr
(
data_file
,
expected_repr
):
...
...
This diff is collapsed.
Click to expand it.
src/scraper/train.py
+
17
−
3
View file @
703f0b42
...
...
@@ -168,10 +168,21 @@ class Train:
# Assertion: there should always be at least two stops - the first and the last.
assert
len
(
self
.
stops
)
>=
2
#
ViaggiaTreno
bug: sometimes, the last stop is not marked as last
#
API
bug: sometimes, the last stop is not marked as last
logging
.
warning
(
f
"
{
self
.
category
}
{
self
.
number
}
has not a last stop.
"
)
if
len
(
list
(
filter
(
lambda
s
:
s
.
stop_type
==
tr_st
.
TrainStopType
.
LAST
,
self
.
stops
)))
==
0
:
# fmt: skip
self
.
stops
[
len
(
self
.
stops
)
-
1
].
stop_type
=
tr_st
.
TrainStopType
.
LAST
i
=
len
(
self
.
stops
)
-
1
while
i
>
0
:
if
self
.
stops
[
i
]
!=
tr_st
.
TrainStopType
.
CANCELLED
and
isinstance
(
self
.
stops
[
i
].
arrival
,
tr_st
.
TrainStopTime
):
break
i
-=
1
if
i
<
2
:
self
.
cancelled
=
True
return
self
.
stops
[
i
].
stop_type
=
tr_st
.
TrainStopType
.
LAST
def
fetch_trenord
(
self
)
->
None
:
"""
Try fetch more details about the train, using Trenord API.
"""
...
...
@@ -260,6 +271,9 @@ class Train:
if
not
self
.
_fetched
or
self
.
_phantom
:
return
None
if
self
.
cancelled
:
return
True
assert
isinstance
(
self
.
stops
,
list
)
arriving_stop
:
tr_st
.
TrainStop
=
next
(
filter
(
lambda
s
:
s
.
stop_type
==
tr_st
.
TrainStopType
.
LAST
,
self
.
stops
)
...
...
This diff is collapsed.
Click to expand it.
src/scraper/train_stop.py
+
2
−
2
View file @
703f0b42
...
...
@@ -213,7 +213,7 @@ class TrainStop:
if
stop_type_raw
==
"
O
"
:
stop_type
=
TrainStopType
.
FIRST
elif
stop_type_raw
==
"
F
"
:
stop_type
=
(
TrainStopType
.
STOP
,)
stop_type
=
TrainStopType
.
STOP
elif
stop_type_raw
==
"
D
"
:
stop_type
=
TrainStopType
.
LAST
else
:
...
...
@@ -238,7 +238,7 @@ class TrainStop:
)
def
__repr__
(
self
)
->
str
:
ret
=
f
"
@
{
self
.
station
.
name
}
"
ret
=
f
"
@
(
{
self
.
stop_type
.
value
}
)
{
self
.
station
.
name
}
"
if
self
.
stop_type
==
TrainStopType
.
FIRST
:
ret
+=
f
"
{
self
.
departure
}
"
elif
self
.
stop_type
==
TrainStopType
.
LAST
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment