summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-12-23 16:56:32 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-12-23 16:56:32 +0100
commit5f8332567182d1d44b5e79a5128f7babc754575e (patch)
tree631970bbf6d5d117ac3af8a7119cc74836a1d365 /lib
parenta75843f56d6e23cc9a1156dfb09b6fe6d81ff3f6 (diff)
Wagenreihung: Add train_powertype accessor
Diffstat (limited to 'lib')
-rw-r--r--lib/Travel/Status/DE/DBWagenreihung.pm33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/Travel/Status/DE/DBWagenreihung.pm b/lib/Travel/Status/DE/DBWagenreihung.pm
index e4f1d6c..2289383 100644
--- a/lib/Travel/Status/DE/DBWagenreihung.pm
+++ b/lib/Travel/Status/DE/DBWagenreihung.pm
@@ -265,6 +265,39 @@ sub train_no {
return $self->{data}{istformation}{zugnummer};
}
+sub train_powertype {
+ my ($self) = @_;
+
+ if ( exists $self->{train_powertype} ) {
+ return $self->{train_powertype};
+ }
+
+ my @wagons = $self->wagons;
+ my %ml = map { $_ => 0 } ( 90 .. 99 );
+
+ for my $wagon (@wagons) {
+
+ if ( not $wagon->uic_id or length( $wagon->uic_id ) != 12 ) {
+ next;
+ }
+
+ my $wagon_type = substr( $wagon->uic_id, 0, 2 );
+ if ( $wagon_type < 90 ) {
+ next;
+ }
+
+ $ml{$wagon_type}++;
+ }
+
+ my @likelihood = reverse sort { $ml{$a} <=> $ml{$b} } keys %ml;
+
+ if ( $ml{ $likelihood[0] } == 0 ) {
+ return $self->{train_powertype} = undef;
+ }
+
+ return $self->{train_powertype} = $likelihood[0];
+}
+
sub train_subtype {
my ($self) = @_;