summaryrefslogtreecommitdiff
path: root/lib/Travel
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-05-19 11:25:26 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-05-19 11:25:26 +0200
commit9cbf0881382baef851023add18989409d95b9ea5 (patch)
tree4d56cc483dd28792e59f08f3501beecef3ae39e3 /lib/Travel
parent7324ee46e037910a718da459759ffdb6888507ec (diff)
check if wagons have invalid positions
Diffstat (limited to 'lib/Travel')
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung.pm43
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung/Wagon.pm11
2 files changed, 46 insertions, 8 deletions
diff --git a/lib/Travel/Status/DE/DBWagenreihung.pm b/lib/Travel/Status/DE/DBWagenreihung.pm
index cadee0b..2d50a0f 100644
--- a/lib/Travel/Status/DE/DBWagenreihung.pm
+++ b/lib/Travel/Status/DE/DBWagenreihung.pm
@@ -100,6 +100,29 @@ sub direction {
return $self->{direction};
}
+sub has_bad_wagons {
+ my ($self) = @_;
+
+ if ( defined $self->{has_bad_wagons} ) {
+ return $self->{has_bad_wagons};
+ }
+
+ for my $group ( @{ $self->{data}{istformation}{allFahrzeuggruppe} } ) {
+ for my $wagon ( @{ $group->{allFahrzeug} } ) {
+ my $pos = $wagon->{positionamhalt};
+ if ( $pos->{startprozent} eq ''
+ or $pos->{endeprozent} eq ''
+ or $pos->{startmeter} eq ''
+ or $pos->{endemeter} eq '' )
+ {
+ return $self->{has_bad_wagons} = 1;
+ }
+ }
+ }
+
+ return $self->{has_bad_wagons} = 0;
+}
+
sub origins {
my ($self) = @_;
@@ -306,13 +329,15 @@ sub wagons {
for my $group ( @{ $self->{data}{istformation}{allFahrzeuggruppe} } ) {
for my $wagon ( @{ $group->{allFahrzeug} } ) {
- push(
- @{ $self->{wagons} },
- Travel::Status::DE::DBWagenreihung::Wagon->new( %{$wagon} )
- );
+ my $wagon_object
+ = Travel::Status::DE::DBWagenreihung::Wagon->new( %{$wagon} );
+ push( @{ $self->{wagons} }, $wagon_object );
+ if ( not $wagon_object->{position}{valid} ) {
+ $self->{has_bad_wagons} = 1;
+ }
}
}
- if ( @{ $self->{wagons} // [] } > 1 ) {
+ if ( @{ $self->{wagons} // [] } > 1 and not $self->has_bad_wagons ) {
if ( $self->{wagons}[0]->{position}{start_percent}
> $self->{wagons}[-1]->{position}{start_percent} )
{
@@ -322,9 +347,11 @@ sub wagons {
$self->{direction} = 0;
}
}
- @{ $self->{wagons} } = sort {
- $a->{position}->{start_percent} <=> $b->{position}->{start_percent}
- } @{ $self->{wagons} };
+ if ( not $self->has_bad_wagons ) {
+ @{ $self->{wagons} } = sort {
+ $a->{position}->{start_percent} <=> $b->{position}->{start_percent}
+ } @{ $self->{wagons} };
+ }
# ->train_subtype calls ->wagons, so this call must not be made before
# $self->{wagons} has beet set.
diff --git a/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm b/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm
index e7d4fbe..0d59314 100644
--- a/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm
+++ b/lib/Travel/Status/DE/DBWagenreihung/Wagon.pm
@@ -111,6 +111,17 @@ sub new {
$ref->{position}{start_meters} = $pos->{startmeter};
$ref->{position}{end_meters} = $pos->{endemeter};
+ if ( $pos->{startprozent} eq ''
+ or $pos->{endeprozent} eq ''
+ or $pos->{startmeter} eq ''
+ or $pos->{endemeter} eq '' )
+ {
+ $ref->{position}{valid} = 0;
+ }
+ else {
+ $ref->{position}{valid} = 1;
+ }
+
return $self;
}