Loading bin/dbwagenreihung +63 −6 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use utf8; our $VERSION = '0.00'; use List::Util qw(min); use Travel::Status::DE::IRIS; use Travel::Status::DE::DBWagenreihung; Loading @@ -27,16 +28,72 @@ if (@trains != 1) { my $wr = Travel::Status::DE::DBWagenreihung->new( departure => $trains[0]->sched_departure, developer_mode => 1, train_number => $train_number, ); for my $section ($wr->sections) { my $section_length = $section->{end_percent} - $section->{start_percent}; my $spacing_left = int(($section_length - 2) / 2) - 1; my $spacing_right = int(($section_length - 2) / 2); if ($section_length % 2) { $spacing_left++; } printf("|%s%s%s|", ' ' x $spacing_left, $section->{name}, ' ' x $spacing_right ); } print "\n"; my @start_percentages = map { $_->{position}{start_percent} } $wr->wagons; print ' ' x ((min @start_percentages) - 1); print '['; for my $wagon ($wr->wagons) { my $wagon_length = $wagon->{position}->{end_percent} - $wagon->{position}->{start_percent}; my $spacing_left = int($wagon_length / 2) - 2; my $spacing_right = int($wagon_length / 2) - 1; if ($wagon_length % 2) { $spacing_left++; } my $wagon_desc = $wagon->number || '?'; if ($wagon->is_locomotive or $wagon->is_powercar) { $wagon_desc = '<->'; } printf("%s%3s%s", ' ' x $spacing_left, $wagon_desc, ' ' x $spacing_right); } print "]\n"; print ' ' x (min @start_percentages); for my $wagon ($wr->wagons) { printf("%s %2s", $wagon->section, $wagon->number || 'X'); if ($wagon->class_type == 12) { print(" 1/2"); my $wagon_length = $wagon->{position}->{end_percent} - $wagon->{position}->{start_percent}; my $spacing_left = int($wagon_length / 2) - 2; my $spacing_right = int($wagon_length / 2) - 1; if ($wagon_length % 2) { $spacing_left++; } elsif ($wagon->class_type) { printf(" %d", $wagon->class_type); my $class = ''; if ($wagon->class_type == 1) { $class = ' 1 '; } elsif ($wagon->class_type == 2) { $class = ' 2 '; } print("\n"); elsif ($wagon->class_type == 12) { $class = '1/2'; } printf("%s%3s%s", ' ' x $spacing_left, $class, ' ' x $spacing_right); } print "\n"; lib/Travel/Status/DE/DBWagenreihung.pm +22 −3 Original line number Diff line number Diff line Loading @@ -67,9 +67,6 @@ sub get_wagonorder { return; } my $json = $self->{json}->decode($content); if ($self->{developer_mode}) { say $self->{json}->pretty->encode($json); } if (exists $json->{error}) { $self->{errstr} = 'Backend error: ' . $json->{error}{msg}; Loading @@ -86,6 +83,27 @@ sub error { return $self->{errstr}; } sub sections { my ($self) = @_; if (exists $self->{sections}) { return @{$self->{sections}}; } for my $section (@{$self->{data}{istformation}{halt}{allSektor}}) { my $pos = $section->{positionamgleis}; push(@{$self->{sections}}, { name => $section->{sektorbezeichnung}, start_percent => $pos->{startprozent}, end_percent => $pos->{endeprozent}, start_meters => $pos->{startmeter}, end_meters => $pos->{endemeter}, }); } return @{$self->{sections} // []}; } sub wagons { my ($self) = @_; Loading @@ -98,6 +116,7 @@ sub wagons { push(@{$self->{wagons}}, Travel::Status::DE::DBWagenreihung::Wagon->new(%{$wagon})); } } @{$self->{wagons}} = sort { $a->{position}->{start_percent} <=> $b->{position}->{start_percent} } @{$self->{wagons}}; return @{$self->{wagons} // []}; } Loading lib/Travel/Status/DE/DBWagenreihung/Wagon.pm +23 −8 Original line number Diff line number Diff line Loading @@ -11,32 +11,47 @@ use Carp qw(cluck); our $VERSION = '0.00'; Travel::Status::DE::DBWagenreihung::Wagon->mk_ro_accessors( qw(class_type has_bistro number section) qw(class_type has_bistro is_locomotive is_powercar number section) ); sub new { my ( $obj, %opt ) = @_; my $ref = \%opt; my $ref = {}; $ref->{class_type} = 0; $ref->{has_bistro} = 0; $ref->{number} = $ref->{wagenordnungsnummer}; $ref->{section} = $ref->{fahrzeugsektor}; $ref->{is_locomotive} = 0; $ref->{is_powercar} = 0; $ref->{number} = $opt{wagenordnungsnummer}; $ref->{section} = $opt{fahrzeugsektor}; if ($ref->{kategorie} =~ m{SPEISEWAGEN}) { if ($opt{kategorie} =~ m{SPEISEWAGEN}) { $ref->{has_bistro} = 1; } elsif ($opt{kategorie} eq 'LOK') { $ref->{is_locomotive} = 1; } elsif ($opt{kategorie} eq 'TRIEBKOPF') { $ref->{is_powercar} = 1; } if ($ref->{fahrzeugtyp} =~ m{^AB}) { if ($opt{fahrzeugtyp} =~ m{AB}) { $ref->{class_type} = 12; } elsif ($ref->{fahrzeugtyp} =~ m{^A}) { elsif ($opt{fahrzeugtyp} =~ m{A}) { $ref->{class_type} = 1; } elsif ($ref->{fahrzeugtyp} =~ m{^B|^WR}) { elsif ($opt{fahrzeugtyp} =~ m{B|WR}) { $ref->{class_type} = 2; } my $pos = $opt{positionamhalt}; $ref->{position}{start_percent} = $pos->{startprozent}; $ref->{position}{end_percent} = $pos->{endeprozent}; $ref->{position}{start_meters} = $pos->{startmeter}; $ref->{position}{end_meters} = $pos->{endemeter}; return bless( $ref, $obj ); } Loading Loading
bin/dbwagenreihung +63 −6 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use utf8; our $VERSION = '0.00'; use List::Util qw(min); use Travel::Status::DE::IRIS; use Travel::Status::DE::DBWagenreihung; Loading @@ -27,16 +28,72 @@ if (@trains != 1) { my $wr = Travel::Status::DE::DBWagenreihung->new( departure => $trains[0]->sched_departure, developer_mode => 1, train_number => $train_number, ); for my $section ($wr->sections) { my $section_length = $section->{end_percent} - $section->{start_percent}; my $spacing_left = int(($section_length - 2) / 2) - 1; my $spacing_right = int(($section_length - 2) / 2); if ($section_length % 2) { $spacing_left++; } printf("|%s%s%s|", ' ' x $spacing_left, $section->{name}, ' ' x $spacing_right ); } print "\n"; my @start_percentages = map { $_->{position}{start_percent} } $wr->wagons; print ' ' x ((min @start_percentages) - 1); print '['; for my $wagon ($wr->wagons) { my $wagon_length = $wagon->{position}->{end_percent} - $wagon->{position}->{start_percent}; my $spacing_left = int($wagon_length / 2) - 2; my $spacing_right = int($wagon_length / 2) - 1; if ($wagon_length % 2) { $spacing_left++; } my $wagon_desc = $wagon->number || '?'; if ($wagon->is_locomotive or $wagon->is_powercar) { $wagon_desc = '<->'; } printf("%s%3s%s", ' ' x $spacing_left, $wagon_desc, ' ' x $spacing_right); } print "]\n"; print ' ' x (min @start_percentages); for my $wagon ($wr->wagons) { printf("%s %2s", $wagon->section, $wagon->number || 'X'); if ($wagon->class_type == 12) { print(" 1/2"); my $wagon_length = $wagon->{position}->{end_percent} - $wagon->{position}->{start_percent}; my $spacing_left = int($wagon_length / 2) - 2; my $spacing_right = int($wagon_length / 2) - 1; if ($wagon_length % 2) { $spacing_left++; } elsif ($wagon->class_type) { printf(" %d", $wagon->class_type); my $class = ''; if ($wagon->class_type == 1) { $class = ' 1 '; } elsif ($wagon->class_type == 2) { $class = ' 2 '; } print("\n"); elsif ($wagon->class_type == 12) { $class = '1/2'; } printf("%s%3s%s", ' ' x $spacing_left, $class, ' ' x $spacing_right); } print "\n";
lib/Travel/Status/DE/DBWagenreihung.pm +22 −3 Original line number Diff line number Diff line Loading @@ -67,9 +67,6 @@ sub get_wagonorder { return; } my $json = $self->{json}->decode($content); if ($self->{developer_mode}) { say $self->{json}->pretty->encode($json); } if (exists $json->{error}) { $self->{errstr} = 'Backend error: ' . $json->{error}{msg}; Loading @@ -86,6 +83,27 @@ sub error { return $self->{errstr}; } sub sections { my ($self) = @_; if (exists $self->{sections}) { return @{$self->{sections}}; } for my $section (@{$self->{data}{istformation}{halt}{allSektor}}) { my $pos = $section->{positionamgleis}; push(@{$self->{sections}}, { name => $section->{sektorbezeichnung}, start_percent => $pos->{startprozent}, end_percent => $pos->{endeprozent}, start_meters => $pos->{startmeter}, end_meters => $pos->{endemeter}, }); } return @{$self->{sections} // []}; } sub wagons { my ($self) = @_; Loading @@ -98,6 +116,7 @@ sub wagons { push(@{$self->{wagons}}, Travel::Status::DE::DBWagenreihung::Wagon->new(%{$wagon})); } } @{$self->{wagons}} = sort { $a->{position}->{start_percent} <=> $b->{position}->{start_percent} } @{$self->{wagons}}; return @{$self->{wagons} // []}; } Loading
lib/Travel/Status/DE/DBWagenreihung/Wagon.pm +23 −8 Original line number Diff line number Diff line Loading @@ -11,32 +11,47 @@ use Carp qw(cluck); our $VERSION = '0.00'; Travel::Status::DE::DBWagenreihung::Wagon->mk_ro_accessors( qw(class_type has_bistro number section) qw(class_type has_bistro is_locomotive is_powercar number section) ); sub new { my ( $obj, %opt ) = @_; my $ref = \%opt; my $ref = {}; $ref->{class_type} = 0; $ref->{has_bistro} = 0; $ref->{number} = $ref->{wagenordnungsnummer}; $ref->{section} = $ref->{fahrzeugsektor}; $ref->{is_locomotive} = 0; $ref->{is_powercar} = 0; $ref->{number} = $opt{wagenordnungsnummer}; $ref->{section} = $opt{fahrzeugsektor}; if ($ref->{kategorie} =~ m{SPEISEWAGEN}) { if ($opt{kategorie} =~ m{SPEISEWAGEN}) { $ref->{has_bistro} = 1; } elsif ($opt{kategorie} eq 'LOK') { $ref->{is_locomotive} = 1; } elsif ($opt{kategorie} eq 'TRIEBKOPF') { $ref->{is_powercar} = 1; } if ($ref->{fahrzeugtyp} =~ m{^AB}) { if ($opt{fahrzeugtyp} =~ m{AB}) { $ref->{class_type} = 12; } elsif ($ref->{fahrzeugtyp} =~ m{^A}) { elsif ($opt{fahrzeugtyp} =~ m{A}) { $ref->{class_type} = 1; } elsif ($ref->{fahrzeugtyp} =~ m{^B|^WR}) { elsif ($opt{fahrzeugtyp} =~ m{B|WR}) { $ref->{class_type} = 2; } my $pos = $opt{positionamhalt}; $ref->{position}{start_percent} = $pos->{startprozent}; $ref->{position}{end_percent} = $pos->{endeprozent}; $ref->{position}{start_meters} = $pos->{startmeter}; $ref->{position}{end_meters} = $pos->{endemeter}; return bless( $ref, $obj ); } Loading