HAFAS/Stop.pm

filter: Statementstmt 80.2% 73 / 91 Branchbran 62.5% 15 / 24 Conditioncond 71.7% 33 / 46 MC/DCmcdc 60.0% 18 / 30 Subroutinesub 75.0% 6 / 8 Podpod 50.0% 2 / 4 totaltotal 72.4% 147 / 203 CC 32 SCAR 30.0
CC
32
Cov
75%
new
28.1
TO_JSON
12.0
messages
6.0
CRAP 20.0
« HAFAS/Product.pm ↑ Summary HAFAS/Polyline.pm »
1 package Travel::Status::DE::HAFAS::Stop;
2  
3 # vim:foldmethod=marker
4  
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶use parent 'Class::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 our $VERSION = '6.15';
12  
13 5 Travel::Status::DE::HAFAS::Stop->mk_ro_accessors(
14 qw(loc
15 rt_arr sched_arr arr arr_delay arr_cancelled prod_arr
16 rt_dep sched_dep dep dep_delay dep_cancelled prod_dep
17 delay direction
18 rt_platform sched_platform platform is_changed_platform
19 is_additional tz_offset
20 load
21 )
22 );
23  
24 # {{{ Constructor
25  
26 85 ▶sub new {
Subroutine new: called CC=25 SCAR=33.4
Pod documented
27 85 my ( $obj, %opt ) = @_;
28  
29 85 my $stop = $opt{stop};
30 85 my $common = $opt{common};
31 85 my $prodL = $opt{prodL};
32 85 my $date = $opt{date};
33 85 my $datetime_ref = $opt{datetime_ref};
34 85 my $hafas = $opt{hafas};
35 85 my $strp_obj = $opt{hafas}{strptime_obj};
36  
37 my $prod_arr
38 85 ▶ = defined $stop->{aProdX} ? $prodL->[ $stop->{aProdX} ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $stop->{'aProdX'} ? : 44 41 85
39 my $prod_dep
40 85 ▶ = defined $stop->{dProdX} ? $prodL->[ $stop->{dProdX} ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $stop->{'dProdX'} ? : 44 41 85
41  
42 # dIn. / aOut. -> may passengers enter / exit the train?
43  
44 85 ▶ my $sched_platform = $stop->{aPlatfS} // $stop->{dPlatfS};
Condition100%3/3
$stop->{"aPlatfS"} // $stop->{"dPlatfS"}
l!l&&r!l&&!r
40738
MC/DC100%2/2
$stop->{"aPlatfS"} // $stop->{"dPlatfS"}
$stop->{"aPlatfS"} $stop->{"dPlatfS"}
Truth table100%3/3
A // B
A= $stop->{"aPlatfS"}B= $stop->{"dPlatfS"}
ABresult
1X1
011
000
45 85 ▶ my $rt_platform = $stop->{aPlatfR} // $stop->{dPlatfR};
Condition66%2/3
$stop->{"aPlatfR"} // $stop->{"dPlatfR"}
l!l&&r!l&&!r
0184
MC/DC50%1/2
$stop->{"aPlatfR"} // $stop->{"dPlatfR"}
$stop->{"aPlatfR"} $stop->{"dPlatfR"}
Truth table66%2/3
A // B
A= $stop->{"aPlatfR"}B= $stop->{"dPlatfR"}
ABresult
1X1
011
000
46 85 ▶ my $changed_platform = $stop->{aPlatfCh} // $stop->{dPlatfCh};
Condition66%2/3
$stop->{"aPlatfCh"} // $stop->{"dPlatfCh"}
l!l&&r!l&&!r
0184
MC/DC50%1/2
$stop->{"aPlatfCh"} // $stop->{"dPlatfCh"}
$stop->{"aPlatfCh"} $stop->{"dPlatfCh"}
Truth table66%2/3
A // B
A= $stop->{"aPlatfCh"}B= $stop->{"dPlatfCh"}
ABresult
1X1
011
000
47  
48 85 my $arr_cancelled = $stop->{aCncl};
49 85 my $dep_cancelled = $stop->{dCncl};
50 85 my $is_additional = $stop->{isAdd};
51  
52 my $ref = {
53 loc => $opt{loc},
54 direction => $stop->{dDirTxt},
55 85 ▶ sched_platform => $sched_platform,
Condition100%3/3
$rt_platform // $sched_platform
l!l&&r!l&&!r
14638
MC/DC100%2/2
$rt_platform // $sched_platform
$rt_platform $sched_platform
Truth table100%3/3
A // B
A= $rt_platformB= $sched_platform
ABresult
1X1
011
000
56 rt_platform => $rt_platform,
57 is_changed_platform => $changed_platform,
58 platform => $rt_platform // $sched_platform,
59 arr_cancelled => $arr_cancelled,
60 dep_cancelled => $dep_cancelled,
61 is_additional => $is_additional,
62 prod_arr => $prod_arr,
63 prod_dep => $prod_dep,
64 };
65  
66 85 bless( $ref, $obj );
67  
68 my $sched_arr = $ref->handle_day_change(
69 input => $stop->{aTimeS},
70 offset => $stop->{aTZOffset},
71 85 date => $date,
72 strp_obj => $strp_obj,
73 ref => $datetime_ref
74 );
75  
76 my $rt_arr = $ref->handle_day_change(
77 input => $stop->{aTimeR},
78 offset => $stop->{aTZOffset},
79 85 date => $date,
80 strp_obj => $strp_obj,
81 ref => $datetime_ref
82 );
83  
84 my $sched_dep = $ref->handle_day_change(
85 input => $stop->{dTimeS},
86 offset => $stop->{dTZOffset},
87 85 date => $date,
88 strp_obj => $strp_obj,
89 ref => $datetime_ref
90 );
91  
92 my $rt_dep = $ref->handle_day_change(
93 input => $stop->{dTimeR},
94 offset => $stop->{dTZOffset},
95 85 date => $date,
96 strp_obj => $strp_obj,
97 ref => $datetime_ref
98 );
99  
100 $ref->{arr_delay}
101 85 ▶ = ( $sched_arr and $rt_arr )
Branch: 1 branch
BranchTrueFalseTotal
$sched_arr && $rt_arr ? : 15 70 85
Condition100%3/3
$sched_arr and $rt_arr
!ll&&!rl&&r
76315
MC/DC100%2/2
$sched_arr and $rt_arr
$sched_arr $rt_arr
Truth table100%3/3
A and B
A= $sched_arrB= $rt_arr
ABresult
0X0
100
111
102 ? ( $rt_arr->epoch - $sched_arr->epoch ) / 60
103 : undef;
104  
105 $ref->{dep_delay}
106 85 ▶ = ( $sched_dep and $rt_dep )
Branch: 1 branch
BranchTrueFalseTotal
$sched_dep && $rt_dep ? : 14 71 85
Condition100%3/3
$sched_dep and $rt_dep
!ll&&!rl&&r
413014
MC/DC100%2/2
$sched_dep and $rt_dep
$sched_dep $rt_dep
Truth table100%3/3
A and B
A= $sched_depB= $rt_dep
ABresult
0X0
100
111
107 ? ( $rt_dep->epoch - $sched_dep->epoch ) / 60
108 : undef;
109  
110 85 ▶ $ref->{delay} = $ref->{dep_delay} // $ref->{arr_delay};
Condition100%3/3
$ref->{"dep_delay"} // $ref->{"arr_delay"}
l!l&&r!l&&!r
14269
MC/DC100%2/2
$ref->{"dep_delay"} // $ref->{"arr_delay"}
$ref->{"dep_delay"} $ref->{"arr_delay"}
Truth table100%3/3
A // B
A= $ref->{"dep_delay"}B= $ref->{"arr_delay"}
ABresult
1X1
011
000
111  
112 85 $ref->{sched_arr} = $sched_arr;
113 85 $ref->{sched_dep} = $sched_dep;
114 85 $ref->{rt_arr} = $rt_arr;
115 85 $ref->{rt_dep} = $rt_dep;
116 85 ▶ $ref->{arr} = $rt_arr // $sched_arr;
Condition100%3/3
$rt_arr // $sched_arr
l!l&&r!l&&!r
15637
MC/DC100%2/2
$rt_arr // $sched_arr
$rt_arr $sched_arr
Truth table100%3/3
A // B
A= $rt_arrB= $sched_arr
ABresult
1X1
011
000
117 85 ▶ $ref->{dep} = $rt_dep // $sched_dep;
Condition100%3/3
$rt_dep // $sched_dep
l!l&&r!l&&!r
143041
MC/DC100%2/2
$rt_dep // $sched_dep
$rt_dep $sched_dep
Truth table100%3/3
A // B
A= $rt_depB= $sched_dep
ABresult
1X1
011
000
118  
119 85 my @messages;
120 85 ▶ for my $msg ( @{ $stop->{msgL} // [] } ) {
Condition100%2/2
$stop->{"msgL"} // []
l!l
580
MC/DC100%1/1
$stop->{"msgL"} // []
$stop->{"msgL"}
Truth table100%2/2
A
A= $stop->{"msgL"}
Aresult
11
00
121 7 ▶ if ( $msg->{type} eq 'REM' and defined $msg->{remX} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($msg->{'type'} eq 'REM' and defined $msg->{'remX'}) { } 7 0 7
elsif ($msg->{'type'} eq 'HIM' and defined $msg->{'himX'}) { } 0 0 0
Condition33%1/3
$msg->{"type"} eq "REM" and defined $msg->{"remX"}
!ll&&!rl&&r
007
MC/DC0%0/2
$msg->{"type"} eq "REM" and defined $msg->{"remX"}
$msg->{"type"} eq "REM" defined $msg->{"remX"}
Truth table33%1/3
A and B
A= $msg->{"type"} eq "REM"B= defined $msg->{"remX"}
ABresult
0X0
100
111
122 push( @messages,
123 7 $hafas->add_message( $opt{common}{remL}[ $msg->{remX} ] ) );
124 }
125 ▶ elsif ( $msg->{type} eq 'HIM' and defined $msg->{himX} ) {
Condition0%0/3
$msg->{"type"} eq "HIM" and defined $msg->{"himX"}
!ll&&!rl&&r
000
MC/DC0%0/2
$msg->{"type"} eq "HIM" and defined $msg->{"himX"}
$msg->{"type"} eq "HIM" defined $msg->{"himX"}
Truth table0%0/3
A and B
A= $msg->{"type"} eq "HIM"B= defined $msg->{"himX"}
ABresult
0X0
100
111
126 push( @messages,
127 0 $hafas->add_message( $opt{common}{himL}[ $msg->{himX} ], 1 ) );
128 }
129 else {
130 0 say "Unknown message type $msg->{type}";
131 }
132 }
133 85 $ref->{messages} = \@messages;
134  
135 85 $ref->{load} = {};
136 85 ▶ for my $tco_id ( @{ $stop->{dTrnCmpSX}{tcocX} // [] } ) {
Condition100%2/2
$stop->{"dTrnCmpSX"}{"tcocX"} // []
l!l
3055
MC/DC100%1/1
$stop->{"dTrnCmpSX"}{"tcocX"} // []
$stop->{"dTrnCmpSX"}{"tcocX"}
Truth table100%2/2
A
A= $stop->{"dTrnCmpSX"}{"tcocX"}
Aresult
11
00
137 60 my $tco_kv = $common->{tcocL}[$tco_id];
138  
139 # BVG has rRT (real-time?) and r (prognosed?); others only have r
140 60 ▶ my $load = $tco_kv->{rRT} // $tco_kv->{r};
Condition33%1/3
$tco_kv->{"rRT"} // $tco_kv->{"r"}
l!l&&r!l&&!r
0600
MC/DC0%0/2
$tco_kv->{"rRT"} // $tco_kv->{"r"}
$tco_kv->{"rRT"} $tco_kv->{"r"}
Truth table33%1/3
A // B
A= $tco_kv->{"rRT"}B= $tco_kv->{"r"}
ABresult
1X1
011
000
141  
142 # BVG uses 11 .. 13 rather than 1 .. 4
143 60 ▶ if ( defined $load and $load > 10 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $load and $load > 10) 0 60 60
Condition33%1/3
defined $load and $load > 10
!ll&&!rl&&r
0600
MC/DC0%0/2
defined $load and $load > 10
defined $load $load > 10
Truth table33%1/3
A and B
A= defined $loadB= $load > 10
ABresult
0X0
100
111
144 0 $load -= 10;
145 }
146  
147 60 $ref->{load}{ $tco_kv->{c} } = $load;
148 }
149  
150 85 return $ref;
151 }
152  
153 # }}}
154  
155 400 ▶sub handle_day_change {
Subroutine handle_day_change: called CC=5 SCAR=16.5
Pod undocumented
156 400 my ( $self, %opt ) = @_;
157 400 my $date = $opt{date};
158 400 my $timestr = $opt{input};
159 400 my $offset = $opt{offset};
160  
161 400 ▶ if ( not defined $timestr ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $timestr) 190 210 400
162 190 return;
163 }
164  
165 210 ▶ if ( length($timestr) == 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $timestr == 8) { } 2 208 210
166  
167 # arrival time includes a day offset
168 2 my $offset_date = $opt{ref}->clone;
169 2 $offset_date->add( days => substr( $timestr, 0, 2, q{} ) );
170 2 $offset_date = $offset_date->strftime('%Y%m%d');
171 2 $timestr = $opt{strp_obj}->parse_datetime("${offset_date}T${timestr}");
172 }
173 else {
174 208 $timestr = $opt{strp_obj}->parse_datetime("${date}T${timestr}");
175 }
176  
177 210 ▶ if ( defined $offset and $offset != $timestr->offset / 60 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset and $offset != $timestr->offset / 60) 0 210 210
Condition33%1/3
defined $offset and $offset != $timestr->offset / 60
!ll&&!rl&&r
02100
MC/DC0%0/2
defined $offset and $offset != $timestr->offset / 60
defined $offset $offset != $timestr->offset / 60
Truth table33%1/3
A and B
A= defined $offsetB= $offset != $timestr->offset / 60
ABresult
0X0
100
111
178 0 $self->{tz_offset} = $offset - $timestr->offset / 60;
179 0 $timestr->subtract( minutes => $self->{tz_offset} );
180 }
181  
182 210 return $timestr;
183 }
184  
185 0 ▶sub messages {
Subroutine messages: not called CC=2 SCAR=17.9
Pod documented
186 0 my ($self) = @_;
187  
188 0 ▶ if ( $self->{messages} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"messages"}) 0 0 0
189 0 return @{ $self->{messages} };
190 }
191 0 return;
192 }
193  
194 0 ▶sub TO_JSON {
Subroutine TO_JSON: not called CC=3 SCAR=24.8
Pod undocumented
195 0 my ($self) = @_;
196  
197 0 my $ret = { %{$self} };
198  
199 0 for my $k ( keys %{$ret} ) {
200 0 ▶ if ( ref( $ret->{$k} ) eq 'DateTime' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ret->{$k} eq "DateTime") 0 0 0
201 0 $ret->{$k} = $ret->{$k}->epoch;
202 }
203 }
204  
205 0 return $ret;
206 }
207  
208 5 1;
209  
210 __END__
« HAFAS/Product.pm ↑ Summary HAFAS/Polyline.pm »