summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Helper
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travelynx/Helper')
-rw-r--r--lib/Travelynx/Helper/DBDB.pm29
-rw-r--r--lib/Travelynx/Helper/HAFAS.pm22
-rw-r--r--lib/Travelynx/Helper/IRIS.pm4
3 files changed, 39 insertions, 16 deletions
diff --git a/lib/Travelynx/Helper/DBDB.pm b/lib/Travelynx/Helper/DBDB.pm
index b98a372..da3bfb1 100644
--- a/lib/Travelynx/Helper/DBDB.pm
+++ b/lib/Travelynx/Helper/DBDB.pm
@@ -31,14 +31,18 @@ sub has_wagonorder_p {
my $api_ts = $ts->strftime('%Y%m%d%H%M');
my $url
= "https://ist-wr.noncd.db.de/wagenreihung/1.0/${train_no}/${api_ts}";
- my $cache = $self->{cache};
+ my $cache = $self->{realtime_cache};
my $promise = Mojo::Promise->new;
if ( my $content = $cache->get("HEAD $url") ) {
if ( $content eq 'n' ) {
+ $self->{log}
+ ->debug("has_wagonorder_p(${train_no}/${api_ts}): n (cached)");
return $promise->reject;
}
else {
+ $self->{log}
+ ->debug("has_wagonorder_p(${train_no}/${api_ts}): y (cached)");
return $promise->resolve($content);
}
}
@@ -48,10 +52,14 @@ sub has_wagonorder_p {
sub {
my ($tx) = @_;
if ( $tx->result->is_success ) {
+ $self->{log}
+ ->debug("has_wagonorder_p(${train_no}/${api_ts}): a");
$cache->set( "HEAD $url", 'a' );
$promise->resolve('a');
}
else {
+ $self->{log}
+ ->debug("has_wagonorder_p(${train_no}/${api_ts}): n");
$cache->set( "HEAD $url", 'n' );
$promise->reject;
}
@@ -59,6 +67,7 @@ sub has_wagonorder_p {
}
)->catch(
sub {
+ $self->{log}->debug("has_wagonorder_p(${train_no}/${api_ts}): n");
$cache->set( "HEAD $url", 'n' );
$promise->reject;
return;
@@ -73,10 +82,12 @@ sub get_wagonorder_p {
my $url
= "https://ist-wr.noncd.db.de/wagenreihung/1.0/${train_no}/${api_ts}";
- my $cache = $self->{cache};
+ my $cache = $self->{realtime_cache};
my $promise = Mojo::Promise->new;
if ( my $content = $cache->thaw($url) ) {
+ $self->{log}
+ ->debug("get_wagonorder_p(${train_no}/${api_ts}): (cached)");
$promise->resolve($content);
return $promise;
}
@@ -89,11 +100,15 @@ sub get_wagonorder_p {
if ( $tx->result->is_success ) {
my $body = decode( 'utf-8', $tx->res->body );
my $json = JSON->new->decode($body);
+ $self->{log}
+ ->debug("get_wagonorder_p(${train_no}/${api_ts}): success");
$cache->freeze( $url, $json );
$promise->resolve($json);
}
else {
my $code = $tx->code;
+ $self->{log}->debug(
+ "get_wagonorder_p(${train_no}/${api_ts}): HTTP ${code}");
$promise->reject("HTTP ${code}");
}
return;
@@ -101,6 +116,8 @@ sub get_wagonorder_p {
)->catch(
sub {
my ($err) = @_;
+ $self->{log}
+ ->debug("get_wagonorder_p(${train_no}/${api_ts}): error ${err}");
$promise->reject($err);
return;
}
@@ -113,10 +130,11 @@ sub get_stationinfo_p {
my $url = "https://lib.finalrewind.org/dbdb/s/${eva}.json";
- my $cache = $self->{cache};
+ my $cache = $self->{main_cache};
my $promise = Mojo::Promise->new;
if ( my $content = $cache->thaw($url) ) {
+ $self->{log}->debug("get_stationinfo_p(${eva}): (cached)");
return $promise->resolve($content);
}
@@ -126,12 +144,16 @@ sub get_stationinfo_p {
my ($tx) = @_;
if ( my $err = $tx->error ) {
+ $self->{log}->debug(
+"get_stationinfo_p(${eva}): HTTP $err->{code} $err->{message}"
+ );
$cache->freeze( $url, {} );
$promise->reject("HTTP $err->{code} $err->{message}");
return;
}
my $json = $tx->result->json;
+ $self->{log}->debug("get_stationinfo_p(${eva}): success");
$cache->freeze( $url, $json );
$promise->resolve($json);
return;
@@ -139,6 +161,7 @@ sub get_stationinfo_p {
)->catch(
sub {
my ($err) = @_;
+ $self->{log}->debug("get_stationinfo_p(${eva}): Error ${err}");
$cache->freeze( $url, {} );
$promise->reject($err);
return;
diff --git a/lib/Travelynx/Helper/HAFAS.pm b/lib/Travelynx/Helper/HAFAS.pm
index 7671d78..538c8ea 100644
--- a/lib/Travelynx/Helper/HAFAS.pm
+++ b/lib/Travelynx/Helper/HAFAS.pm
@@ -199,7 +199,7 @@ sub get_journey_p {
return $promise;
}
-sub get_route_timestamps_p {
+sub get_route_p {
my ( $self, %opt ) = @_;
my $promise = Mojo::Promise->new;
@@ -219,13 +219,12 @@ sub get_route_timestamps_p {
sub {
my ($hafas) = @_;
my $journey = $hafas->result;
- my $ret = {};
+ my $ret = [];
my $polyline;
my $station_is_past = 1;
for my $stop ( $journey->route ) {
- my $name = $stop->loc->name;
- $ret->{$name} = $ret->{ $stop->loc->eva } = {
+ my $entry = {
name => $stop->loc->name,
eva => $stop->loc->eva,
sched_arr => _epoch( $stop->sched_arr ),
@@ -237,26 +236,27 @@ sub get_route_timestamps_p {
load => $stop->load
};
if ( $stop->tz_offset ) {
- $ret->{$name}{tz_offset} = $stop->tz_offset;
+ $entry->{tz_offset} = $stop->tz_offset;
}
if ( ( $stop->arr_cancelled or not $stop->sched_arr )
and ( $stop->dep_cancelled or not $stop->sched_dep ) )
{
- $ret->{$name}{isCancelled} = 1;
+ $entry->{isCancelled} = 1;
}
if (
$station_is_past
- and not $ret->{$name}{isCancelled}
+ and not $entry->{isCancelled}
and $now->epoch < (
- $ret->{$name}{rt_arr} // $ret->{$name}{rt_dep}
- // $ret->{$name}{sched_arr}
- // $ret->{$name}{sched_dep} // $now->epoch
+ $entry->{rt_arr} // $entry->{rt_dep}
+ // $entry->{sched_arr} // $entry->{sched_dep}
+ // $now->epoch
)
)
{
$station_is_past = 0;
}
- $ret->{$name}{isPast} = $station_is_past;
+ $entry->{isPast} = $station_is_past;
+ push( @{$ret}, $entry );
}
if ( $journey->polyline ) {
diff --git a/lib/Travelynx/Helper/IRIS.pm b/lib/Travelynx/Helper/IRIS.pm
index deed79a..f96aeb6 100644
--- a/lib/Travelynx/Helper/IRIS.pm
+++ b/lib/Travelynx/Helper/IRIS.pm
@@ -42,7 +42,7 @@ sub get_departures {
= Travel::Status::DE::IRIS::Stations::get_station($station);
if ( @station_matches == 1 ) {
- $station = $station_matches[0][0];
+ $station = $station_matches[0][2];
my $status = Travel::Status::DE::IRIS->new(
station => $station,
main_cache => $self->{main_cache},
@@ -109,7 +109,7 @@ sub get_departures_p {
= Travel::Status::DE::IRIS::Stations::get_station($station);
if ( @station_matches == 1 ) {
- $station = $station_matches[0][0];
+ $station = $station_matches[0][2];
my $promise = Mojo::Promise->new;
Travel::Status::DE::IRIS->new_p(
station => $station,