HAFAS/Stop.pm

filter: Statementstmt 80.2% 73 / 91 Branchbran 62.5% 15 / 24 Conditioncond 70.6% 41 / 58 MC/DCmcdc 52.9% 18 / 34 Subroutinesub 75.0% 6 / 8 Podpod 50.0% 2 / 4 totaltotal 70.7% 155 / 219 CC 36 SCAR 32.2
CC
36
Cov
75%
new
34.6
TO_JSON
12.0
messages
6.0
CRAP 25.1
« HAFAS/StopFinder.pm ↑ Summary HAFAS/Product.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.25';
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=29 SCAR=35.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 my $sched_platform = $stop->{aPlatfS} // $stop->{dPlatfS}
45 85 ▶ // $stop->{aPltfS}{txt} // $stop->{dPltfS}{txt};
Condition77%7/9
(($stop->{"aPlatfS"} // $stop->{"dPlatfS"}) // $stop->{"aPltfS"}{"txt"}) // $stop->{"dPltfS"}{"txt"}
l!l&&r!l&&!r
47038
($stop->{"aPlatfS"} // $stop->{"dPlatfS"}) // $stop->{"aPltfS"}{"txt"}
l!l&&r!l&&!r
47038
$stop->{"aPlatfS"} // $stop->{"dPlatfS"}
l!l&&r!l&&!r
40738
MC/DC50%2/4
(($stop->{"aPlatfS"} // $stop->{"dPlatfS"}) // $stop->{"aPltfS"}{"txt"}) // $stop->{"dPltfS"}{"txt"}
$stop->{"aPlatfS"} $stop->{"dPlatfS"} $stop->{"aPltfS"}{"txt"} $stop->{"dPltfS"}{"txt"}
Truth table60%3/5
A // B // C // D
A= $stop->{"aPlatfS"}B= $stop->{"dPlatfS"}C= $stop->{"aPltfS"}{"txt"}D= $stop->{"dPltfS"}{"txt"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
46 my $rt_platform = $stop->{aPlatfR} // $stop->{dPlatfR}
47 85 ▶ // $stop->{aPltfR}{txt} // $stop->{dPltfR}{txt};
Condition66%6/9
(($stop->{"aPlatfR"} // $stop->{"dPlatfR"}) // $stop->{"aPltfR"}{"txt"}) // $stop->{"dPltfR"}{"txt"}
l!l&&r!l&&!r
1084
($stop->{"aPlatfR"} // $stop->{"dPlatfR"}) // $stop->{"aPltfR"}{"txt"}
l!l&&r!l&&!r
1084
$stop->{"aPlatfR"} // $stop->{"dPlatfR"}
l!l&&r!l&&!r
0184
MC/DC25%1/4
(($stop->{"aPlatfR"} // $stop->{"dPlatfR"}) // $stop->{"aPltfR"}{"txt"}) // $stop->{"dPltfR"}{"txt"}
$stop->{"aPlatfR"} $stop->{"dPlatfR"} $stop->{"aPltfR"}{"txt"} $stop->{"dPltfR"}{"txt"}
Truth table40%2/5
A // B // C // D
A= $stop->{"aPlatfR"}B= $stop->{"dPlatfR"}C= $stop->{"aPltfR"}{"txt"}D= $stop->{"dPltfR"}{"txt"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
48 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
49  
50 85 my $arr_cancelled = $stop->{aCncl};
51 85 my $dep_cancelled = $stop->{dCncl};
52 85 my $is_additional = $stop->{isAdd};
53  
54 my $ref = {
55 loc => $opt{loc},
56 direction => $stop->{dDirTxt},
57 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
58 rt_platform => $rt_platform,
59 is_changed_platform => $changed_platform,
60 platform => $rt_platform // $sched_platform,
61 arr_cancelled => $arr_cancelled,
62 dep_cancelled => $dep_cancelled,
63 is_additional => $is_additional,
64 prod_arr => $prod_arr,
65 prod_dep => $prod_dep,
66 };
67  
68 85 bless( $ref, $obj );
69  
70 my $sched_arr = $ref->handle_day_change(
71 input => $stop->{aTimeS},
72 offset => $stop->{aTZOffset},
73 85 date => $date,
74 strp_obj => $strp_obj,
75 ref => $datetime_ref
76 );
77  
78 my $rt_arr = $ref->handle_day_change(
79 input => $stop->{aTimeR},
80 offset => $stop->{aTZOffset},
81 85 date => $date,
82 strp_obj => $strp_obj,
83 ref => $datetime_ref
84 );
85  
86 my $sched_dep = $ref->handle_day_change(
87 input => $stop->{dTimeS},
88 offset => $stop->{dTZOffset},
89 85 date => $date,
90 strp_obj => $strp_obj,
91 ref => $datetime_ref
92 );
93  
94 my $rt_dep = $ref->handle_day_change(
95 input => $stop->{dTimeR},
96 offset => $stop->{dTZOffset},
97 85 date => $date,
98 strp_obj => $strp_obj,
99 ref => $datetime_ref
100 );
101  
102 $ref->{arr_delay}
103 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
104 ? ( $rt_arr->epoch - $sched_arr->epoch ) / 60
105 : undef;
106  
107 $ref->{dep_delay}
108 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
109 ? ( $rt_dep->epoch - $sched_dep->epoch ) / 60
110 : undef;
111  
112 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
113  
114 85 $ref->{sched_arr} = $sched_arr;
115 85 $ref->{sched_dep} = $sched_dep;
116 85 $ref->{rt_arr} = $rt_arr;
117 85 $ref->{rt_dep} = $rt_dep;
118 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
119 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
120  
121 85 my @messages;
122 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
123 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
124 push( @messages,
125 7 $hafas->add_message( $opt{common}{remL}[ $msg->{remX} ] ) );
126 }
127 ▶ 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
128 push( @messages,
129 0 $hafas->add_message( $opt{common}{himL}[ $msg->{himX} ], 1 ) );
130 }
131 else {
132 0 say "Unknown message type $msg->{type}";
133 }
134 }
135 85 $ref->{messages} = \@messages;
136  
137 85 $ref->{load} = {};
138 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
139 60 my $tco_kv = $common->{tcocL}[$tco_id];
140  
141 # BVG has rRT (real-time?) and r (prognosed?); others only have r
142 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
143  
144 # BVG uses 11 .. 13 rather than 1 .. 4
145 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
146 0 $load -= 10;
147 }
148  
149 60 $ref->{load}{ $tco_kv->{c} } = $load;
150 }
151  
152 85 return $ref;
153 }
154  
155 # }}}
156  
157 400 ▶sub handle_day_change {
Subroutine handle_day_change: called CC=5 SCAR=16.5
Pod undocumented
158 400 my ( $self, %opt ) = @_;
159 400 my $date = $opt{date};
160 400 my $timestr = $opt{input};
161 400 my $offset = $opt{offset};
162  
163 400 ▶ if ( not defined $timestr ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $timestr) 190 210 400
164 190 return;
165 }
166  
167 210 ▶ if ( length($timestr) == 8 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $timestr == 8) { } 2 208 210
168  
169 # arrival time includes a day offset
170 2 my $offset_date = $opt{ref}->clone;
171 2 $offset_date->add( days => substr( $timestr, 0, 2, q{} ) );
172 2 $offset_date = $offset_date->strftime('%Y%m%d');
173 2 $timestr = $opt{strp_obj}->parse_datetime("${offset_date}T${timestr}");
174 }
175 else {
176 208 $timestr = $opt{strp_obj}->parse_datetime("${date}T${timestr}");
177 }
178  
179 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
180 0 $self->{tz_offset} = $offset - $timestr->offset / 60;
181 0 $timestr->subtract( minutes => $self->{tz_offset} );
182 }
183  
184 210 return $timestr;
185 }
186  
187 0 ▶sub messages {
Subroutine messages: not called CC=2 SCAR=17.9
Pod documented
188 0 my ($self) = @_;
189  
190 0 ▶ if ( $self->{messages} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"messages"}) 0 0 0
191 0 return @{ $self->{messages} };
192 }
193 0 return;
194 }
195  
196 0 ▶sub TO_JSON {
Subroutine TO_JSON: not called CC=3 SCAR=24.8
Pod undocumented
197 0 my ($self) = @_;
198  
199 0 my $ret = { %{$self} };
200  
201 0 for my $k ( keys %{$ret} ) {
202 0 ▶ if ( ref( $ret->{$k} ) eq 'DateTime' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ret->{$k} eq "DateTime") 0 0 0
203 0 $ret->{$k} = $ret->{$k}->epoch;
204 }
205 }
206  
207 0 return $ret;
208 }
209  
210 5 1;
211  
212 __END__
« HAFAS/StopFinder.pm ↑ Summary HAFAS/Product.pm »