blib/lib/Health/BladderDiary/GenTable.pm

filter: Statementstmt 50.3% 78 / 155 Branchbran 32.7% 36 / 110 Conditioncond 18.9% 7 / 37 MC/DCmcdc 8.3% 2 / 24 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 39.0% 130 / 333 CC 74 SCAR 55.5
CC
74
Cov
40%
gen_bladder_diary_table_from_entries
375.1
__ANON__
174.2
BEGIN
1.0
CRAP 257.0
↑ Summary
1 package Health::BladderDiary::GenTable;
2  
3 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4 2 our $DATE = '2020-12-10'; # DATE
5 2 our $DIST = 'Health-BladderDiary-GenTable'; # DIST
6 2 our $VERSION = '0.007'; # VERSION
7  
8 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 our @EXPORT_OK = qw(gen_bladder_diary_table_from_entries);
14  
15 2 our %SPEC;
16  
17 $SPEC{gen_bladder_diary_table_from_entries} = {
18 2 v => 1.1,
19 summary => 'Create bladder diary table from bladder diary entries',
20 args => {
21 entries => {
22 schema => 'str*',
23 req => 1,
24 pos => 0,
25 cmdline_src => 'stdin_or_file',
26 },
27 yesterday_last_urination_entry => {
28 schema => 'str*',
29 cmdline_aliases => {y=>{}},
30 },
31 date => {
32 schema => ['date*', 'x.perl.coerce_to' => 'DateTime'],
33 cmdline_aliases => {d=>{}},
34 },
35 },
36 };
37 2 ▶sub gen_bladder_diary_table_from_entries {
Subroutine gen_bladder_diary_table_from_entries: called CC=36 SCAR=59.3
Pod documented
38 2 my %args = @_;
39  
40 2 my @unparsed_entries;
41 SPLIT_ENTRIES: {
42 2 ▶ if ($args{entries} =~ /\S\R\R+\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'entries'} =~ /\S\R\R+\S/) { } 1 1 2
43 # there is a blank line between non-blanks, assume entries are
44 # written in paragraphs
45 1 @unparsed_entries = split /\R\R+/, $args{entries};
46 1 for (@unparsed_entries) {
47 3 s/\R+/ /g;
48 3 s/\s+\z//;
49 }
50 } else {
51 # there are no blank lines, assume entries are written as individual
52 # lines
53 1 @unparsed_entries = split /^/, $args{entries};
54 }
55 2 for (@unparsed_entries) {
56 6 s/\R+/ /g;
57 6 s/\s+\z//;
58 }
59 } # SPLIT_ENTRIES
60  
61 6 ▶ my $code_parse_entry = sub {
Subroutine __ANON__: called CC=39 SCAR=51.6
62 6 my ($uentry, $label) = @_;
63 6 my $uentry0 = $uentry;
64 6 my @warnings;
65  
66 6 ▶ $uentry =~ s/\A(\d\d)[:.]?(\d\d)(?:-(\d\d)[:.]?(\d\d))?\s*//
Branch: 1 branch
BranchTrueFalseTotal
$uentry =~ s/\A(\d\d)[:.]?(\d\d)(?:-(\d\d)[:.]?(\d\d))?\s*// or return [400, "Entry ${label}: invalid time, please start with hhmm or hh:mm: $uentry0"] 6 0 6
67 or return [400, "Entry $label: invalid time, please start with hhmm or hh:mm: $uentry0"];
68 6 my ($h, $m, $h2, $m2) = ($1, $2, $3, $4);
69 6 ▶ $uentry =~ s/(\w+):?\s*//
Branch: 1 branch
BranchTrueFalseTotal
$uentry =~ s/(\w+):?\s*// or return [400, "Entry ${label}: event (e.g. drink, urinate) expected: $uentry"] 6 0 6
70 or return [400, "Entry $label: event (e.g. drink, urinate) expected: $uentry"];
71 6 my $event = $1;
72 6 ▶ if ($event eq 'u' || $event eq 'urin') { $event = 'urinate' }
Branch: 3 branches
BranchTrueFalseTotal
if ($event eq 'u' or $event eq 'urin') { } 2 4 6
elsif ($event eq 'd') { } 2 2 4
elsif ($event eq 'c') { } 0 2 2
Condition66%2/3
$event eq "u" or $event eq "urin"
l!l&&r!l&&!r
204
MC/DC50%1/2
$event eq "u" or $event eq "urin"
$event eq "u" $event eq "urin"
Truth table66%2/3
A or B
A= $event eq "u"B= $event eq "urin"
ABresult
1X1
011
000
73 2 elsif ($event eq 'd') { $event = 'drink' }
74 0 elsif ($event eq 'c') { $event = 'comment' }
75 6 ▶ $event =~ /\A(drink|eat|poop|urinate|comment)\z/
Branch: 1 branch
BranchTrueFalseTotal
$event =~ /\A(drink|eat|poop|urinate|comment)\z/ or return [400, "Entry ${label}: unknown event '${event}', please choose eat|drink|poop|urinate|comment"] 6 0 6
76 or return [400, "Entry $label: unknown event '$event', please choose eat|drink|poop|urinate|comment"];
77  
78 6 my $parsed_entry = {
79 # XXX check that time is monotonically increasing
80 time => sprintf("%02d.%02d", $h, $m),
81 _event => $event,
82 _h => $h,
83 _m => $m,
84 _time => $h*60 + $m,
85 _raw => $uentry0,
86 };
87  
88 # scrape key-value pairs from unparsed entry
89 6 my %kv;
90 6 ▶ while ($uentry =~ /(\w+)=(.+?)(?=[,.]?\s+\w+=|[.]?\s*\z)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uentry =~ /(\w+)=(.+?)(?=[,.]?\s+\w+=|[.]?\s*\z)/g) 6 6 12
91 6 $kv{$1} = $2;
92 }
93 #use DD; dd \%kv;
94 6 for my $k (sort keys %kv) {
95 6 ▶ unless ($k =~ /\A(vol|type|comment|urgency|color)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($k =~ /\A(vol|type|comment|urgency|color)\z/) 0 6 6
96 0 push @warnings, "Entry $label: unknown key '$k'";
97 }
98 }
99  
100 6 for my $k (qw/vol type comment urgency color/) {
101 30 ▶ if (defined $kv{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $kv{$k}) 6 24 30
102 6 $parsed_entry->{$k} = $kv{$k};
103 }
104 }
105  
106 6 ▶ $uentry =~ /\b(\d+)ml\b/ and $parsed_entry->{vol} //= $1;
Branch: 1 branch
BranchTrueFalseTotal
$uentry =~ /\b(\d+)ml\b/ and $parsed_entry->{"vol"} //= $1 4 2 6
Condition33%1/3
$parsed_entry->{"vol"} //= $1
l!l&&r!l&&!r
040
MC/DC0%0/2
$parsed_entry->{"vol"} //= $1
$parsed_entry->{"vol"} $1
Truth table33%1/3
A //= B
A= $parsed_entry->{"vol"}B= $1
ABresult
1X1
011
000
107 6 ▶ $uentry =~ /\bv(\d+)\b/ and $parsed_entry->{vol} //= $1;
Branch: 1 branch
BranchTrueFalseTotal
$uentry =~ /\bv(\d+)\b/ and $parsed_entry->{"vol"} //= $1 0 6 6
Condition0%0/3
$parsed_entry->{"vol"} //= $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$parsed_entry->{"vol"} //= $1
$parsed_entry->{"vol"} $1
Truth table0%0/3
A //= B
A= $parsed_entry->{"vol"}B= $1
ABresult
1X1
011
000
108 6 ▶ $uentry =~ /\bu([0-9]|10)\b/ and $parsed_entry->{urgency} //= $1;
Branch: 1 branch
BranchTrueFalseTotal
$uentry =~ /\bu([0-9]|10)\b/ and $parsed_entry->{"urgency"} //= $1 2 4 6
Condition33%1/3
$parsed_entry->{"urgency"} //= $1
l!l&&r!l&&!r
020
MC/DC0%0/2
$parsed_entry->{"urgency"} //= $1
$parsed_entry->{"urgency"} $1
Truth table33%1/3
A //= B
A= $parsed_entry->{"urgency"}B= $1
ABresult
1X1
011
000
109 6 ▶ $uentry =~ /\bc([0-6](?:\.5)?)\b/ and $parsed_entry->{color} //= do {
Branch: 1 branch
BranchTrueFalseTotal
$uentry =~ /\bc([0-6](?:\.5)?)\b/ and $parsed_entry->{"color"} //= do { if ($1 == 0) { "0/6 clear"; } elsif ($1 == "0.5") { "0-1/6 clear to light yellow"; } elsif ($1 == 1) { "1/6 light yellow"; } elsif ($1 == "1.5") { "1-2/6 light yellow to yellow"; } elsif ($1 == 2) { "2/6 yellow"; } elsif ($1 == "2.5") { "2-3/6 yellow to dark yellow"; } elsif ($1 == 3) { "3/6 dark yellow"; } elsif ($1 == 4) { "4/6 amber"; } elsif ($1 == 5) { "5/6 brown"; } elsif ($1 == 6) { "6/6 red"; } } 2 4 6
Condition33%1/3
$parsed_entry->{"color"} //= do { if ($1 == 0) { "0/6 clear"; } elsif ($1 == "0.5") { "0-1/6 clear to light yellow"; } elsif ($1 == 1) { "1/6 light yellow"; } elsif ($1 == "1.5") { "1-2/6 light yellow to yellow"; } elsif ($1 == 2) { "2/6 yellow"; } elsif ($1 == "2.5") { "2-3/6 yellow to dark yellow"; } elsif ($1 == 3) { "3/6 dark yellow"; } elsif ($1 == 4) { "4/6 amber"; } elsif ($1 == 5) { "5/6 brown"; } elsif ($1 == 6) { "6/6 red"; } }
l!l&&r!l&&!r
020
MC/DC0%0/2
$parsed_entry->{"color"} //= do { if ($1 == 0) { "0/6 clear"; } elsif ($1 == "0.5") { "0-1/6 clear to light yellow"; } elsif ($1 == 1) { "1/6 light yellow"; } elsif ($1 == "1.5") { "1-2/6 light yellow to yellow"; } elsif ($1 == 2) { "2/6 yellow"; } elsif ($1 == "2.5") { "2-3/6 yellow to dark yellow"; } elsif ($1 == 3) { "3/6 dark yellow"; } elsif ($1 == 4) { "4/6 amber"; } elsif ($1 == 5) { "5/6 brown"; } elsif ($1 == 6) { "6/6 red"; } }
$parsed_entry->{"color"} do { if ($1 == 0) { "0/6 clear"; } elsif ($1 == "0.5") { "0-1/6 clear to light yellow"; } elsif ($1 == 1) { "1/6 light yellow"; } elsif ($1 == "1.5") { "1-2/6 light yellow to yellow"; } elsif ($1 == 2) { "2/6 yellow"; } elsif ($1 == "2.5") { "2-3/6 yellow to dark yellow"; } elsif ($1 == 3) { "3/6 dark yellow"; } elsif ($1 == 4) { "4/6 amber"; } elsif ($1 == 5) { "5/6 brown"; } elsif ($1 == 6) { "6/6 red"; } }
Truth table33%1/3
A //= B
A= $parsed_entry->{"color"}B= do { if ($1 == 0) { "0/6 clear"; } elsif ($1 == "0.5") { "0-1/6 clear to light yellow"; } elsif ($1 == 1) { "1/6 light yellow"; } elsif ($1 == "1.5") { "1-2/6 light yellow to yellow"; } elsif ($1 == 2) { "2/6 yellow"; } elsif ($1 == "2.5") { "2-3/6 yellow to dark yellow"; } elsif ($1 == 3) { "3/6 dark yellow"; } elsif ($1 == 4) { "4/6 amber"; } elsif ($1 == 5) { "5/6 brown"; } elsif ($1 == 6) { "6/6 red"; } }
ABresult
1X1
011
000
110 2 ▶ if ($1 == 0) { '0/6 clear' } # very good
Branch: 10 branches
BranchTrueFalseTotal
if ($1 == 0) { } 2 0 2
elsif ($1 == 0.5) { } 0 0 0
elsif ($1 == 1) { } 0 0 0
elsif ($1 == 1.5) { } 0 0 0
elsif ($1 == 2) { } 0 0 0
elsif ($1 == 2.5) { } 0 0 0
elsif ($1 == 3) { } 0 0 0
elsif ($1 == 4) { } 0 0 0
elsif ($1 == 5) { } 0 0 0
elsif ($1 == 6) { } 0 0 0
111 0 elsif ($1 == 0.5) { '0-1/6 clear to light yellow' } # good
112 0 elsif ($1 == 1) { '1/6 light yellow' } # good
113 0 elsif ($1 == 1.5) { '1-2/6 light yellow to yellow' } # good
114 0 elsif ($1 == 2) { '2/6 yellow' } # fair
115 0 elsif ($1 == 2.5) { '2-3/6 yellow to dark yellow' } # fair
116 0 elsif ($1 == 3) { '3/6 dark yellow' } # light dehydrated
117 0 elsif ($1 == 4) { '4/6 amber' } # dehydrated
118 0 elsif ($1 == 5) { '5/6 brown' } # very dehydrated
119 0 elsif ($1 == 6) { '6/6 red' } # severe dehydrated
120 };
121  
122 6 ▶ if ($event eq 'drink') {
Branch: 3 branches
BranchTrueFalseTotal
if ($event eq 'drink') { } 4 2 6
elsif ($event eq 'eat') { } 0 2 2
elsif ($event eq 'urinate') { } 2 0 2
123 return [400, "Entry $label: please specify volume for $event"]
124 4 ▶ unless defined $parsed_entry->{vol};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parsed_entry->{"vol"} 0 4 4
125 4 ▶ $parsed_entry->{type} //= "water";
Condition100%2/2
$parsed_entry->{"type"} //= "water"
l!l
22
MC/DC100%1/1
$parsed_entry->{"type"} //= "water"
$parsed_entry->{"type"}
Truth table100%2/2
A
A= $parsed_entry->{"type"}
Aresult
11
00
126 } elsif ($event eq 'eat') {
127 0 ▶ $parsed_entry->{type} //= "food";
Condition0%0/2
$parsed_entry->{"type"} //= "food"
l!l
00
MC/DC0%0/1
$parsed_entry->{"type"} //= "food"
$parsed_entry->{"type"}
Truth table0%0/2
A
A= $parsed_entry->{"type"}
Aresult
11
00
128 } elsif ($event eq 'urinate') {
129 return [400, "Entry $label: please specify volume for $event"]
130 2 ▶ unless defined $parsed_entry->{vol};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parsed_entry->{"vol"} 0 2 2
131 $parsed_entry->{"ucomment"} = "poop" .
132 2 ▶ ($parsed_entry->{comment} ? ": $parsed_entry->{comment}" : "");
Branch: 1 branch
BranchTrueFalseTotal
$parsed_entry->{'comment'} ? : 0 2 2
133 }
134  
135 6 [200, "OK", $parsed_entry, {'func.warnings'=>\@warnings}];
136 2 }; # code_parse_entry
137  
138 2 my @urinations;
139 my @intakes;
140 PARSE_ENTRIES: {
141 2 my $i = 0;
142 2 for my $uentry (@unparsed_entries) {
143 6 $i++;
144 6 my $res = $code_parse_entry->($uentry, "#$i");
145 6 ▶ return $res unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 6 6
146  
147 6 my $parsed_entry = $res->[2];
148 6 my $event = delete $parsed_entry->{_event};
149 6 ▶ if ($event eq 'drink') {
Branch: 3 branches
BranchTrueFalseTotal
if ($event eq 'drink') { } 4 2 6
elsif ($event eq 'eat') { } 0 2 2
elsif ($event eq 'urinate') { } 2 0 2
150 4 push @intakes, $parsed_entry;
151 } elsif ($event eq 'eat') {
152 0 push @intakes, $parsed_entry;
153 } elsif ($event eq 'urinate') {
154 2 push @urinations, $parsed_entry;
155 }
156 }
157 } # PARSE_ENTRIES
158  
159 2 ▶ if ($args{_raw}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"_raw"}) 2 0 2
160 2 return [200, "OK", {
161 intakes => \@intakes,
162 urinations => \@urinations,
163 }];
164 }
165  
166 0 my $yesterday_last_urination_parsed_entry;
167 0 ▶ if ($args{yesterday_last_urination_entry}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"yesterday_last_urination_entry"}) 0 0 0
168 my $res = $code_parse_entry->(
169 0 $args{yesterday_last_urination_entry}, "yesterday's urination");
170 0 ▶ return $res unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
171 0 $yesterday_last_urination_parsed_entry = $res->[2];
172 0 my $event = delete $yesterday_last_urination_parsed_entry->{_event};
173 0 ▶ unless ($event eq 'urinate') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($event eq "urinate") 0 0 0
174 0 return [400, "Yesterday's urination event must be 'urinate', not $event"];
175 }
176 }
177  
178 0 my @rows;
179 0 my $ivol_cum = 0;
180 0 my $uvol_cum = 0;
181 my $prev_utime = $yesterday_last_urination_parsed_entry ?
182 0 ▶ $yesterday_last_urination_parsed_entry->{_time} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$yesterday_last_urination_parsed_entry ? : 0 0 0
183 0 my $num_drink = 0;
184 0 my $num_urinate = 0;
185 GROUP_INTO_HOURS: {
186 0 my $h = do {
187 0 ▶ my $hi = @intakes ? $intakes[0]{_h} : undef;
Branch: 1 branch
BranchTrueFalseTotal
@intakes ? : 0 0 0
188 0 ▶ my $hu = @urinations ? $urinations[0]{_h} : undef;
Branch: 1 branch
BranchTrueFalseTotal
@urinations ? : 0 0 0
189 0 ▶ my $h = $hi // $hu;
Condition0%0/3
$hi // $hu
l!l&&r!l&&!r
000
MC/DC0%0/2
$hi // $hu
$hi $hu
Truth table0%0/3
A // B
A= $hiB= $hu
ABresult
1X1
011
000
190 0 ▶ $h = $hi if defined $hi && $hi < $h;
Branch: 1 branch
BranchTrueFalseTotal
if defined $hi and $hi < $h 0 0 0
Condition0%0/3
defined $hi and $hi < $h
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hi and $hi < $h
defined $hi $hi < $h
Truth table0%0/3
A and B
A= defined $hiB= $hi < $h
ABresult
0X0
100
111
191 0 ▶ $h = $hu if defined $hu && $hu < $h;
Branch: 1 branch
BranchTrueFalseTotal
if defined $hu and $hu < $h 0 0 0
Condition0%0/3
defined $hu and $hu < $h
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hu and $hu < $h
defined $hu $hu < $h
Truth table0%0/3
A and B
A= defined $huB= $hu < $h
ABresult
0X0
100
111
192 0 $h;
193 };
194 0 while (1) {
195 0 ▶ last unless @intakes || @urinations;
Branch: 1 branch
BranchTrueFalseTotal
unless @intakes or @urinations 0 0 0
Condition0%0/3
@intakes or @urinations
l!l&&r!l&&!r
000
MC/DC0%0/2
@intakes or @urinations
@intakes @urinations
Truth table0%0/3
A or B
A= @intakesB= @urinations
ABresult
1X1
011
000
196  
197 0 my @hour_rows;
198 0 ▶ push @hour_rows, {time => sprintf("%02d.00-%02d.00", $h, $h+1 <= 23 ? $h+1 : 0)};
Branch: 1 branch
BranchTrueFalseTotal
$h + 1 <= 23 ? : 0 0 0
199  
200 0 my $j = 0;
201 0 ▶ while (@intakes && $intakes[0]{_h} == $h) {
Branch: 1 branch
BranchTrueFalseTotal
if (@intakes and $intakes[0]{"_h"} == $h) 0 0 0
Condition0%0/3
@intakes and $intakes[0]{"_h"} == $h
!ll&&!rl&&r
000
MC/DC0%0/2
@intakes and $intakes[0]{"_h"} == $h
@intakes $intakes[0]{"_h"} == $h
Truth table0%0/3
A and B
A= @intakesB= $intakes[0]{"_h"} == $h
ABresult
0X0
100
111
202 0 my $entry = shift @intakes;
203 0 $hour_rows[$j]{"intake type"} = $entry->{type};
204 0 $hour_rows[$j]{itime} = $entry->{time};
205 0 $hour_rows[$j]{"icomment"} = $entry->{comment};
206 0 ▶ if (defined $entry->{vol}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $entry->{"vol"}) 0 0 0
207 0 $num_drink++;
208 0 $hour_rows[$j]{"ivol (ml)"} = $entry->{vol};
209 0 $ivol_cum += $entry->{vol};
210 0 $hour_rows[$j]{"ivol cum"} = $ivol_cum;
211 }
212 0 $j++;
213 }
214  
215 0 $j = 0;
216 0 ▶ while (@urinations && $urinations[0]{_h} == $h) {
Branch: 1 branch
BranchTrueFalseTotal
if (@urinations and $urinations[0]{"_h"} == $h) 0 0 0
Condition0%0/3
@urinations and $urinations[0]{"_h"} == $h
!ll&&!rl&&r
000
MC/DC0%0/2
@urinations and $urinations[0]{"_h"} == $h
@urinations $urinations[0]{"_h"} == $h
Truth table0%0/3
A and B
A= @urinationsB= $urinations[0]{"_h"} == $h
ABresult
0X0
100
111
217 0 my $entry = shift @urinations;
218 0 $hour_rows[$j]{"urin/defec time"} = $entry->{time};
219 0 $hour_rows[$j]{"color (0-6)"} = $entry->{color};
220 0 $hour_rows[$j]{"ucomment"} = $entry->{comment};
221 0 $hour_rows[$j]{"urgency (0-10)"} = $entry->{urgency};
222 0 ▶ if (defined $entry->{vol}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $entry->{"vol"}) 0 0 0
223 0 $num_urinate++;
224 0 $hour_rows[$j]{"uvol (ml)"} = $entry->{vol};
225 0 $uvol_cum += $entry->{vol};
226 0 $hour_rows[$j]{"uvol cum"} = $uvol_cum;
227 0 my $mins_diff;
228 0 ▶ if (defined $prev_utime) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prev_utime) 0 0 0
229 0 ▶ $mins_diff = $prev_utime > $entry->{_time} ? (24*60+$entry->{_time} - $prev_utime) : ($entry->{_time} - $prev_utime);
Branch: 1 branch
BranchTrueFalseTotal
$prev_utime > $entry->{'_time'} ? : 0 0 0
230 }
231 #$hour_rows[$j]{"utimediff"} = $mins_diff;
232 $hour_rows[$j]{"urate (ml/h)"} = defined($prev_utime) ?
233 0 ▶ sprintf("%.0f", $entry->{vol} / $mins_diff * 60) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $prev_utime ? : 0 0 0
234 }
235 0 $j++;
236  
237 0 $prev_utime = $entry->{_time};
238 }
239 0 push @rows, @hour_rows;
240 0 $h++;
241 0 ▶ $h = 0 if $h >= 24;
Branch: 1 branch
BranchTrueFalseTotal
if $h >= 24 0 0 0
242 }
243 } # GROUP_INTO_HOURS
244  
245 ADD_SUMMARY_ROWS: {
246 0 push @rows, {};
247  
248 0 push @rows, {
249 time => 'freq drink/urin',
250 'itime' => $num_drink,
251 'urin/defec time' => $num_urinate,
252 };
253 0 ▶ push @rows, {
Branch: 2 branches
BranchTrueFalseTotal
$num_drink ? : 0 0 0
$num_urinate ? : 0 0 0
254 time => 'avg (ml)',
255 'ivol (ml)' => sprintf("%.0f", $num_drink ? $ivol_cum / $num_drink : 0),
256 'uvol (ml)' => sprintf("%.0f", $num_urinate ? $uvol_cum / $num_urinate : 0),
257 };
258 }
259  
260 # return result
261  
262 0 [200, "OK", \@rows, {
263 'table.fields' => [
264 'time',
265 'intake type',
266 'itime',
267 'ivol (ml)',
268 'ivol cum',
269 'icomment', # intake comment
270 'urin/defec time',
271 'uvol (ml)',
272 'uvol cum',
273 'urate (ml/h)',
274 'color (0-6)',
275 'urgency (0-10)',
276 'ucomment', # urinate comment
277 ],
278 'table.field_aligns' => [
279 'left', #'time',
280 'left', #'intake type',
281 'left', #'itime',
282 'right', #'ivol (ml)',
283 'right', #'ivol cum',
284 'left', #'icomment',
285 'left', #'urin/defec time',
286 'right', #'uvol (ml)',
287 'right', #'uvol cum',
288 'right', #'urate (ml/h)',
289 'left', #'color (0-6)',
290 'left', #'urgency (0-10)',
291 'left', #'ucomment',
292 ],
293 }];
294 }
295  
296 2 1;
297 # ABSTRACT: Create bladder diary table from entries
298  
299 __END__
↑ Summary