summaryrefslogtreecommitdiff
path: root/lib/Travel/Status
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-07-30 11:22:00 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2024-07-30 11:22:00 +0200
commitefb13e90e8352c54741832a6f5d950b011c79998 (patch)
tree57459a019ab9e032b58e254be50d15cb9430560d /lib/Travel/Status
parentd3b0c61cc20facb45b52533459ed139cea8df9a9 (diff)
sort carriages and groups
Diffstat (limited to 'lib/Travel/Status')
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung.pm26
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung/Group.pm5
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;