Skip to content
GitLab
Explore
Sign in
derf
travelynx
Compare revisions
64e0ee57683389587f5ff9dc282318a85014ccd5 to 875ec1c3e551b9d31c64fd67a83738dbfa90b86d
Commits on Source (2)
store tz_offset in route data if present
· c9e5bfae
Birte Kristina Friesel
authored
Apr 03, 2024
c9e5bfae
Request polylines for HAFAS journeys as well; only store sensible ones
· 875ec1c3
Birte Kristina Friesel
authored
Apr 07, 2024
Decreases severity of #99 Fixes #108
875ec1c3
Hide whitespace changes
Inline
Side-by-side
lib/Travelynx.pm
View file @
875ec1c3
...
...
@@ -536,7 +536,10 @@ sub startup {
my
$promise
=
Mojo::
Promise
->
new
;
$self
->
hafas
->
get_journey_p
(
trip_id
=>
$train_id
)
->
then
(
$self
->
hafas
->
get_journey_p
(
trip_id
=>
$train_id
,
with_polyline
=>
1
)
->
then
(
sub
{
my
(
$journey
)
=
@_
;
my
$found
;
...
...
@@ -579,6 +582,93 @@ sub startup {
data
=>
{
trip_id
=>
$journey
->
id
}
);
my
$polyline
;
if
(
$journey
->
polyline
)
{
my
@station_list
;
my
@coordinate_list
;
for
my
$coord
(
$journey
->
polyline
)
{
if
(
$coord
->
{
name
}
)
{
push
(
@coordinate_list
,
[
$coord
->
{
lon
},
$coord
->
{
lat
},
$coord
->
{
eva
}
]
);
push
(
@station_list
,
$coord
->
{
name
}
);
}
else
{
push
(
@coordinate_list
,
[
$coord
->
{
lon
},
$coord
->
{
lat
}
]
);
}
}
# equal length → polyline only consists of straight
# lines between stops. that's not helpful.
if
(
@station_list
==
@coordinate_list
)
{
$self
->
log
->
debug
(
'
Ignoring polyline for
'
.
$journey
->
line
.
'
as it only consists of straight lines between stops.
'
);
}
else
{
$polyline
=
{
from_eva
=>
(
$journey
->
route
)[
0
]
->
loc
->
eva
,
to_eva
=>
(
$journey
->
route
)[
-
1
]
->
loc
->
eva
,
coords
=>
\
@coordinate_list
,
};
}
}
if
(
$polyline
)
{
my
$coords
=
$polyline
->
{
coords
};
my
$from_eva
=
$polyline
->
{
from_eva
};
my
$to_eva
=
$polyline
->
{
to_eva
};
my
$polyline_str
=
JSON
->
new
->
encode
(
$coords
);
my
$pl_res
=
$db
->
select
(
'
polylines
',
['
id
'],
{
origin_eva
=>
$from_eva
,
destination_eva
=>
$to_eva
,
polyline
=>
$polyline_str
},
{
limit
=>
1
}
);
my
$polyline_id
;
if
(
my
$h
=
$pl_res
->
hash
)
{
$polyline_id
=
$h
->
{
id
};
}
else
{
eval
{
$polyline_id
=
$db
->
insert
(
'
polylines
',
{
origin_eva
=>
$from_eva
,
destination_eva
=>
$to_eva
,
polyline
=>
$polyline_str
},
{
returning
=>
'
id
'
}
)
->
hash
->
{
id
};
};
if
(
$@
)
{
$self
->
log
->
warn
(
"
add_route_timestamps: insert polyline: $@
"
);
}
}
if
(
$polyline_id
)
{
$self
->
in_transit
->
set_polyline_id
(
uid
=>
$uid
,
db
=>
$db
,
polyline_id
=>
$polyline_id
);
}
}
# mustn't be called during a transaction
if
(
not
$opt
{
in_transaction
}
)
{
$self
->
run_hook
(
$uid
,
'
checkin
'
);
...
...
lib/Travelynx/Helper/HAFAS.pm
View file @
875ec1c3
...
...
@@ -172,7 +172,7 @@ sub get_journey_p {
journey
=>
{
id
=>
$opt
{
trip_id
},
},
with_polyline
=>
0
,
with_polyline
=>
$opt
{
with_polyline
}
,
cache
=>
$self
->
{
realtime_cache
},
promise
=>
'
Mojo::Promise
',
user_agent
=>
$self
->
{
user_agent
}
->
request_timeout
(
10
),
...
...
@@ -236,6 +236,9 @@ sub get_route_timestamps_p {
dep_delay
=>
$stop
->
dep_delay
,
load
=>
$stop
->
load
};
if
(
$stop
->
tz_offset
)
{
$ret
->
{
$name
}{
tz_offset
}
=
$stop
->
tz_offset
;
}
if
(
(
$stop
->
arr_cancelled
or
not
$stop
->
sched_arr
)
and
(
$stop
->
dep_cancelled
or
not
$stop
->
sched_dep
)
)
{
...
...
lib/Travelynx/Model/InTransit.pm
View file @
875ec1c3
...
...
@@ -139,6 +139,9 @@ sub add {
}
]
);
if
(
defined
$j_stop
->
tz_offset
)
{
$route
[
-
1
][
2
]{
tz_offset
}
=
$j_stop
->
tz_offset
;
}
}
$db
->
insert
(
'
in_transit
',
...
...
@@ -156,7 +159,7 @@ sub add {
train_id
=>
$journey
->
id
,
sched_departure
=>
$stop
->
{
sched_dep
},
real_departure
=>
$stop
->
{
rt_dep
}
//
$stop
->
{
sched_dep
},
route
=>
$json
->
encode
(
[
@route
]
),
route
=>
$json
->
encode
(
\
@route
),
data
=>
JSON
->
new
->
encode
(
{
rt
=>
$stop
->
{
rt_dep
}
?
1
:
0
}
),
}
);
...
...
@@ -737,6 +740,9 @@ sub update_arrival_hafas {
}
]
);
if
(
defined
$j_stop
->
tz_offset
)
{
$route
[
-
1
][
2
]{
tz_offset
}
=
$j_stop
->
tz_offset
;
}
}
my
$res_h
=
$db
->
select
(
'
in_transit
',
['
route
'],
{
user_id
=>
$uid
}
)
...
...