diff options
Diffstat (limited to 'lib/Travel/Status')
-rw-r--r-- | lib/Travel/Status/DE/DBWagenreihung.pm | 26 | ||||
-rw-r--r-- | lib/Travel/Status/DE/DBWagenreihung/Group.pm | 5 |
2 files changed, 24 insertions, 7 deletions
diff --git a/lib/Travel/Status/DE/DBWagenreihung.pm b/lib/Travel/Status/DE/DBWagenreihung.pm index 7d9be78..9dce04e 100644 --- a/lib/Travel/Status/DE/DBWagenreihung.pm +++ b/lib/Travel/Status/DE/DBWagenreihung.pm @@ -69,15 +69,25 @@ sub get_wagonorder { my $train_type = $self->{train_type}; my $train_number = $self->{train_number}; - my $datetime = $self->{departure}->clone->set_time_zone('UTC'); - my $json = $self->{from_json}; if ( not $json ) { - my $date = $datetime->strftime('%Y-%m-%d'); - my $time = $datetime->rfc3339 =~ s{(?=Z)}{.000}r; - my ( $content, $err ) = $self->get_with_cache( $cache, -"${api_base}?administrationId=80&category=${train_type}&date=${date}&evaNumber=${eva}&number=${train_number}&time=${time}" + my $datetime = $self->{departure}->clone->set_time_zone('UTC'); + my $date = $datetime->strftime('%Y-%m-%d'); + my $time = $datetime->rfc3339 =~ s{(?=Z)}{.000}r; + $self->{param} = { + administrationId => 80, + category => $train_type, + date => $date, + evaNumber => $eva, + number => $train_number, + time => $time + }; + my ( $content, $err ) = $self->get_with_cache( + $cache, + $api_base . '?' + . join( '&', + map { $_ . '=' . $self->{param}{$_} } keys %{ $self->{param} } ) ); if ($err) { @@ -212,6 +222,8 @@ sub parse_carriages { push( @group_carriages, $carriage_object ); push( @{ $self->{carriages} }, $carriage_object ); } + @group_carriages + = sort { $a->start_percent <=> $b->start_percent } @group_carriages; my $group_obj = Travel::Status::DE::DBWagenreihung::Group->new( json => $group, carriages => \@group_carriages, @@ -220,6 +232,8 @@ sub parse_carriages { push( @numbers, $group_obj->train_no ); } + @groups = sort { $a->start_percent <=> $b->start_percent } @groups; + @numbers = uniq @numbers; $self->{train_numbers} = \@numbers; diff --git a/lib/Travel/Status/DE/DBWagenreihung/Group.pm b/lib/Travel/Status/DE/DBWagenreihung/Group.pm index 5cd2b24..b6848ab 100644 --- a/lib/Travel/Status/DE/DBWagenreihung/Group.pm +++ b/lib/Travel/Status/DE/DBWagenreihung/Group.pm @@ -11,7 +11,7 @@ use List::Util qw(uniq); our $VERSION = '0.14'; Travel::Status::DE::DBWagenreihung::Group->mk_ro_accessors( - qw(train_no train_type description desc_short destination has_sectors model series) + qw(train_no train_type description desc_short destination has_sectors model series start_percent end_percent) ); # {{{ Rolling Stock Models @@ -97,6 +97,9 @@ sub new { $ref->{has_sectors} = 1; } + $ref->{start_percent} = $ref->{carriages}[0]->start_percent; + $ref->{end_percent} = $ref->{carriages}[-1]->end_percent; + bless( $ref, $obj ); $ref->parse_description; |