Unverified Commit 25f08895 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Guard maximum-likelihood model parser behind country code selection

Todo: also check UIC type (e.g. 91 / 94)
parent eaa9b41e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ use Carp qw(cluck);
our $VERSION = '0.31';
Travel::Status::DE::DBRIS::Formation::Carriage->mk_ro_accessors(
	qw(class_type is_closed is_dosto is_locomotive is_powercar
	  number model section uic_id type
	  number model section uic_id country type
	  start_meters end_meters length_meters start_percent end_percent length_percent
	  has_priority_seats has_ac has_quiet_zone has_bahn_comfort has_wheelchair_space
	  has_wheelchair_toilet has_family_zone has_infant_cabin has_info has_bistro
@@ -51,6 +51,7 @@ sub new {

	if ( defined $ref->{uic_id} ) {
		$ref->{uic_id} =~ s{ ^ \d{11} \K - }{}x;
		$ref->{country} = substr( $ref->{uic_id}, 2, 2 );
	}
	if ( defined $ref->{model} ) {
		$ref->{model} =~ s{^.....(...)...-?.(?:-.)?$}{$1}
+171 −165
Original line number Diff line number Diff line
@@ -497,10 +497,8 @@ sub parse_model {
			next;
		}

		if ( $carriage->model == 23 ) {
			$ml{'023'}++;
		}
		elsif ($carriage->model == 91
		if ( $carriage->country == 80 ) {
			if (   $carriage->model == 91
				or $carriage->model == 491
				or $carriage->model == 791
				or $carriage->model == 891 )
@@ -660,10 +658,18 @@ sub parse_model {
			elsif ( $self->train_type eq 'IC' and $carriage->is_dosto ) {
				$ml{'IC2.TWIN'}++;
			}
		elsif ( substr( $carriage->uic_id, 4, 4 ) eq '4011' ) {
		}
		elsif ( $carriage->country == 81 ) {
			if ( substr( $carriage->uic_id, 4, 4 ) eq '4011' ) {
				$ml{'011'}++;
			}
		}
		elsif ( $carriage->country == 82 ) {
			if ( $carriage->model == 23 ) {
				$ml{'023'}++;
			}
		}
	}

	my @likelihood = reverse sort { $ml{$a} <=> $ml{$b} } keys %ml;