From b682508bc6e0500853c45bddac23d32e92ab6e94 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 2 Jan 2019 15:05:45 +0100 Subject: Add train_subtype accessor (ICE 1 / 2 / 3 / 4 / T / IC2) --- lib/Travel/Status/DE/DBWagenreihung.pm | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'lib/Travel/Status') diff --git a/lib/Travel/Status/DE/DBWagenreihung.pm b/lib/Travel/Status/DE/DBWagenreihung.pm index 7f5d486..8b0d6cc 100644 --- a/lib/Travel/Status/DE/DBWagenreihung.pm +++ b/lib/Travel/Status/DE/DBWagenreihung.pm @@ -155,6 +155,64 @@ sub train_no { return $self->{data}{istformation}{zugnummer}; } +sub train_subtype { + my ($self) = @_; + + my @wagons = $self->wagons; + + my %ml = ( + 'ICE 1' => 0, + 'ICE 2' => 0, + 'ICE 3' => 0, + 'ICE 3 V' => 0, + 'ICE 4' => 0, + 'ICE T 411' => 0, + 'ICE T 415' => 0, + 'IC2' => 0, + ); + + for my $wagon (@wagons) { + if ( $wagon->model == 401 + or ( $wagon->model >= 801 and $wagon->model <= 804 ) ) + { + $ml{'ICE 1'}++; + } + elsif ( $wagon->model == 402 + or ( $wagon->model >= 805 and $wagon->model <= 808 ) ) + { + $ml{'ICE 2'}++; + } + elsif ( $wagon->model == 403 or $wagon->model == 406 ) { + $ml{'ICE 3'}++; + } + elsif ( $wagon->model == 407 ) { + $ml{'ICE 3 V'}++; + } + elsif ( $wagon->model == 412 or $wagon->model == 812 ) { + $ml{'ICE 4'}++; + } + elsif ( $wagon->model == 411 ) { + $ml{'ICE T 411'}++; + } + elsif ( $wagon->model == 415 ) { + $ml{'ICE T 415'}++; + } + elsif ( $wagon->is_dosto ) { + $ml{'IC2'}++; + } + } + + my @likelihood = reverse sort { $ml{$a} <=> $ml{$b} } keys %ml; + + if ( $ml{ $likelihood[0] } <= 2 ) { + + # inconclusive + return '???'; + } + + return $likelihood[0]; +} + sub wagons { my ($self) = @_; -- cgit v1.2.3