| 1 | package NetAthlon2::RAW; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use POSIX qw(mktime strftime localtime); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Socket qw(:DEFAULT :crlf); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 8 | require Exporter; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 8 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||||||||||
| 16 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||||||||||
| 17 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # This allows declaration use NetAthlon2::RAW qw(:all); | ||||||||||||||||||||||||||||
| 20 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||||||||||||||||||||
| 21 | # will save memory. | ||||||||||||||||||||||||||||
| 22 | 8 | our %EXPORT_TAGS = ( 'all' => [ qw() ] ); | |||||||||||||||||||||||||||
| 23 | 8 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} }); | |||||||||||||||||||||||||||
| 24 | 8 | our @EXPORT = qw(); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 8 | our $VERSION = '0.31'; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 8 | our $timeDelta = 1; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 8 | local *FP; | |||||||||||||||||||||||||||
| 31 | 8 | local *DIR; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 1 | my ($class, %opts) = @_; | |||||||||||||||||||||||||||
| 35 | 1 | my ($self); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | $self = \%opts; | |||||||||||||||||||||||||||
| 38 | 1 | bless ($self, $class); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | return $self; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 7 | ▶ | sub open { | ||||||||||||||||||||||||||
|
Subroutine
open: called CC=5 SCAR=19.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 7 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 7 | ▶ | if ( defined $file && -f $file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $file and -f $file
MC/DC0%0/2
defined $file and -f $file
defined $file
-f $file
Truth table33%1/3
A and B
A= defined $fileB= -f $file
| |||||||||||||||||||||||||||||
| 47 | 7 | $self->{'file'} = $file; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 7 | ▶ | warn "Opening file ($file)\n" if ( exists $self->{'debug'} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 7 | ▶ | open (*FP, "< $file") || croak "Could not open $file"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 7 | return $self; | |||||||||||||||||||||||||||
| 52 | } else { | ||||||||||||||||||||||||||||
| 53 | 0 | croak "$file not a file"; | |||||||||||||||||||||||||||
| 54 | 0 | return undef; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 7 | ▶ | sub _parse_preamble { | ||||||||||||||||||||||||||
|
Subroutine
_parse_preamble: called CC=17 SCAR=31.4
| |||||||||||||||||||||||||||||
| 59 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | carp "First line not 251" | ||||||||||||||||||||||||||||
| 62 | 7 | ▶ | if ( $self->{'RAW'}[0] != 251 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 7 | $self->{'data'}->{'Sample Rate'} = int(${$self->{'RAW'}}[1]); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | carp "Line 3 not 1" | ||||||||||||||||||||||||||||
| 67 | 7 | ▶ | if ( $self->{'RAW'}[2] != 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # Hear Rate info | ||||||||||||||||||||||||||||
| 70 | ( $self->{'data'}->{'Heart Rate'}->{'Zone 1'}->{'Max'}, | ||||||||||||||||||||||||||||
| 71 | $self->{'data'}->{'Heart Rate'}->{'Zone 3'}->{'Max'} ) = | ||||||||||||||||||||||||||||
| 72 | 7 | split (/\s/, ${$self->{'RAW'}}[3]); | |||||||||||||||||||||||||||
| 73 | ( $self->{'data'}->{'Heart Rate'}->{'Zone 1'}->{'Min'}, | ||||||||||||||||||||||||||||
| 74 | $self->{'data'}->{'Heart Rate'}->{'Zone 3'}->{'Min'} ) = | ||||||||||||||||||||||||||||
| 75 | 7 | split (/\s/, ${$self->{'RAW'}}[4]); | |||||||||||||||||||||||||||
| 76 | ( $self->{'data'}->{'Heart Rate'}->{'Zone 2'}->{'Max'}, | ||||||||||||||||||||||||||||
| 77 | $self->{'data'}->{'Heart Rate'}->{'Anaerobic Threshold'} ) = | ||||||||||||||||||||||||||||
| 78 | 7 | split (/\s/, ${$self->{'RAW'}}[5]); | |||||||||||||||||||||||||||
| 79 | ( $self->{'data'}->{'Heart Rate'}->{'Zone 2'}->{'Min'}, | ||||||||||||||||||||||||||||
| 80 | $self->{'data'}->{'Heart Rate'}->{'Aerobic Threshold'} ) = | ||||||||||||||||||||||||||||
| 81 | 7 | split (/\s/, ${$self->{'RAW'}}[6]); | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # Store the start time (converting to UNIX timestamp) | ||||||||||||||||||||||||||||
| 84 | 7 | my ($mon, $day, $year, $hour, $h, $min, $m, $sec, $ampm); | |||||||||||||||||||||||||||
| 85 | 7 | ▶ | if ( $self->{'file'} =~ /Bike(\d{4})-(\d{2})-(\d{2}) (\d{1,2})-(\d{2})([ap]m)\.RAW$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 7 | $year = $1; | |||||||||||||||||||||||||||
| 87 | 7 | $mon = $2; | |||||||||||||||||||||||||||
| 88 | 7 | $day = $3; | |||||||||||||||||||||||||||
| 89 | 7 | $h = $4; | |||||||||||||||||||||||||||
| 90 | 7 | $m = $5; | |||||||||||||||||||||||||||
| 91 | 7 | $ampm = $6; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | warn "\tyear => $year, month => $mon, day => $day\n\thour => $h, minute => $m, $ampm\n" | ||||||||||||||||||||||||||||
| 94 | 7 | ▶ | if ( exists $self->{'debug'} && $self->{'debug'} >= 5 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $self->{"debug"} and $self->{"debug"} >= 5
MC/DC0%0/2
exists $self->{"debug"} and $self->{"debug"} >= 5
exists $self->{"debug"}
$self->{"debug"} >= 5
Truth table33%1/3
A and B
A= exists $self->{"debug"}B= $self->{"debug"} >= 5
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 7 | ▶ | if ( ${$self->{'RAW'}}[8] =~ m/^(\d{2})\.(\d{2})\.(\d{2})$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 7 | $hour = $1; | |||||||||||||||||||||||||||
| 98 | 7 | $min = $2; | |||||||||||||||||||||||||||
| 99 | 7 | $sec = $3; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | warn "\thour => $hour, minute => $min, second => $sec\n" | ||||||||||||||||||||||||||||
| 102 | 7 | ▶ | if ( exists $self->{'debug'} && $self->{'debug'} >= 5 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $self->{"debug"} and $self->{"debug"} >= 5
MC/DC0%0/2
exists $self->{"debug"} and $self->{"debug"} >= 5
exists $self->{"debug"}
$self->{"debug"} >= 5
Truth table33%1/3
A and B
A= exists $self->{"debug"}B= $self->{"debug"} >= 5
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # FIXME: There is a bug in some of the RAW data files as | ||||||||||||||||||||||||||||
| 105 | # the time encoded in the filename is 1 minute after the | ||||||||||||||||||||||||||||
| 106 | # time encoded in the file contents, hence the different | ||||||||||||||||||||||||||||
| 107 | # comparison for the minute field. | ||||||||||||||||||||||||||||
| 108 | 7 | my $mina = $h * 60 + $m; | |||||||||||||||||||||||||||
| 109 | 7 | my $minb = $hour * 60 + $min; | |||||||||||||||||||||||||||
| 110 | carp "Start time mismatch between file name (" | ||||||||||||||||||||||||||||
| 111 | 7 | ▶ | . $self->{'file'} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | . ") and file contents ($hour:$min)" | ||||||||||||||||||||||||||||
| 113 | if ( abs($mina-$minb) > $timeDelta ); | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | # deal with the noon and midnight hours. | ||||||||||||||||||||||||||||
| 116 | 7 | ▶ | $hour += 12 if ( $ampm eq 'pm' && $hour < 12 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ampm eq "pm" and $hour < 12
MC/DC50%1/2
$ampm eq "pm" and $hour < 12
$ampm eq "pm"
$hour < 12
Truth table66%2/3
A and B
A= $ampm eq "pm"B= $hour < 12
| |||||||||||||||||||||||||||||
| 117 | 7 | ▶ | $hour = 0 if ( $ampm eq 'am' && $hour == 12 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ampm eq "am" and $hour == 12
MC/DC0%0/2
$ampm eq "am" and $hour == 12
$ampm eq "am"
$hour == 12
Truth table33%1/3
A and B
A= $ampm eq "am"B= $hour == 12
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | warn "\thour => $hour\n" | ||||||||||||||||||||||||||||
| 120 | 7 | ▶ | if ( exists $self->{'debug'} && $self->{'debug'} >= 5 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $self->{"debug"} and $self->{"debug"} >= 5
MC/DC0%0/2
exists $self->{"debug"} and $self->{"debug"} >= 5
exists $self->{"debug"}
$self->{"debug"} >= 5
Truth table33%1/3
A and B
A= exists $self->{"debug"}B= $self->{"debug"} >= 5
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||
| 123 | 0 | carp "Can't verify performance start time (" . $self->{'RAW'}[8] . ")"; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | 7 | $self->{'data'}->{'Start Time'} = mktime($sec, $min, $hour, $day, ($mon-1), ($year-1900), 0, 0, -1); | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | # Verify our date and time conversion is correct | ||||||||||||||||||||||||||||
| 128 | 7 | my ($d) = strftime ("%Y-%m-%d %H:%M", localtime($self->{'data'}->{'Start Time'})); | |||||||||||||||||||||||||||
| 129 | 7 | ▶ | carp "Failed in Start Date parsing ($year-$mon-$day $hour:$min != $d)\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | if ( $d ne "$year-$mon-$day $hour:$min" ); | ||||||||||||||||||||||||||||
| 131 | } else { | ||||||||||||||||||||||||||||
| 132 | 0 | carp "Can't determine what day this performance data is from"; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 7 | ▶ | sub _parse_summary { | ||||||||||||||||||||||||||
|
Subroutine
_parse_summary: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 137 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | carp "Start of summary section line not 254" | ||||||||||||||||||||||||||||
| 140 | 7 | ▶ | if ( $self->{'RAW'}[-5] != 254 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 7 | my ($h, $m, $s, $f) = split (/\./, $self->{'RAW'}[-3] ); | |||||||||||||||||||||||||||
| 143 | 7 | chomp($f); | |||||||||||||||||||||||||||
| 144 | 7 | $self->{'data'}->{'Elapsed Time'} = ($h * 3600 + $m * 60 + $s + $f / 100) + 0.0; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # Reset the last Elapsed Time in the Check Points to match | ||||||||||||||||||||||||||||
| 147 | # the total Elapsed Time. | ||||||||||||||||||||||||||||
| 148 | 7 | $self->{'data'}->{'Check Points'}->[scalar @{$self->{'data'}->{'Check Points'}} - 1]->{'Elapsed Time'} | |||||||||||||||||||||||||||
| 149 | 7 | = $self->{'data'}->{'Elapsed Time'}; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | carp "Second to last line not 256" | ||||||||||||||||||||||||||||
| 152 | 7 | ▶ | if ( $self->{'RAW'}[-2] != 256 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 7 | my ($u); | |||||||||||||||||||||||||||
| 155 | ( $u, $self->{'data'}->{'Distance'}, $self->{'data'}->{'Cadence'} ) = | ||||||||||||||||||||||||||||
| 156 | 7 | split (/\s+/, ${$self->{'RAW'}}[-1]); | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 1935 | ▶ | sub _parse_line { | ||||||||||||||||||||||||||
|
Subroutine
_parse_line: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 160 | 1935 | my ($self, $line) = @_; | |||||||||||||||||||||||||||
| 161 | 1935 | my ($time, $dist); | |||||||||||||||||||||||||||
| 162 | 1935 | chomp $line; | |||||||||||||||||||||||||||
| 163 | 1935 | chop $line; | |||||||||||||||||||||||||||
| 164 | 1935 | my ($hr, $u, $speed, $power, $cadence, $grade, $alt) = split /\s/, $line; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | $time = $self->{'data'}->{'Sample Rate'} * | ||||||||||||||||||||||||||||
| 167 | ( exists $self->{'data'}->{'Check Points'} | ||||||||||||||||||||||||||||
| 168 | 1935 | ▶ | ? scalar @{$self->{'data'}->{'Check Points'}} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | : 0); | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # Insert a calculated distance for this Sample Rate, | ||||||||||||||||||||||||||||
| 172 | # which will be used in calculating the Average Speed. | ||||||||||||||||||||||||||||
| 173 | $dist = ( $speed / 10 ) * | ||||||||||||||||||||||||||||
| 174 | ( exists $self->{'data'}->{'Check Points'} | ||||||||||||||||||||||||||||
| 175 | 1935 | ▶ | ? ($self->{'data'}->{'Sample Rate'} / 3600) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | : 0); | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 1935 | push @{$self->{'data'}->{'Check Points'}}, | |||||||||||||||||||||||||||
| 179 | { | ||||||||||||||||||||||||||||
| 180 | 'Elapsed Time' => $time, | ||||||||||||||||||||||||||||
| 181 | 'Calculated Distance' => $dist, | ||||||||||||||||||||||||||||
| 182 | 'Heart Rate' => $hr, | ||||||||||||||||||||||||||||
| 183 | 'Grade' => $grade / 10, | ||||||||||||||||||||||||||||
| 184 | 'Speed' => $speed / 10, | ||||||||||||||||||||||||||||
| 185 | 'Watts' => $power, | ||||||||||||||||||||||||||||
| 186 | 'Cadence' => $cadence, | ||||||||||||||||||||||||||||
| 187 | 'Altitude' => $alt, | ||||||||||||||||||||||||||||
| 188 | }; | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 7 | ▶ | sub _add_averages { | ||||||||||||||||||||||||||
|
Subroutine
_add_averages: called CC=17 SCAR=28.4
| |||||||||||||||||||||||||||||
| 192 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | # Calculate some useful averages | ||||||||||||||||||||||||||||
| 195 | 7 | my ( $c, $cc, $w, $wc, $hr, $hrc, $dist ) = ( 0, 0, 0, 0, 0, 0, 0 ); | |||||||||||||||||||||||||||
| 196 | map { | ||||||||||||||||||||||||||||
| 197 | 1935 | ▶ | if ( $_->{'Cadence'} > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 1923 | $c += $_->{'Cadence'}; $cc++; | |||||||||||||||||||||||||||
| 199 | $self->{'data'}->{'Max Cadence'} = $_->{'Cadence'} | ||||||||||||||||||||||||||||
| 200 | 1923 | ▶ | if ( ! exists $self->{'data'}->{'Max Cadence'} || $self->{'data'}->{'Max Cadence'} < $_->{'Cadence'} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $self->{"data"}{"Max Cadence"} or $self->{"data"}{"Max Cadence"} < $_->{"Cadence"}
MC/DC100%2/2
not exists $self->{"data"}{"Max Cadence"} or $self->{"data"}{"Max Cadence"} < $_->{"Cadence"}
not exists $self->{"data"}{"Max Cadence"}
$self->{"data"}{"Max Cadence"} < $_->{"Cadence"}
Truth table100%3/3
not(A) or B
A= not exists $self->{"data"}{"Max Cadence"}B= $self->{"data"}{"Max Cadence"} < $_->{"Cadence"}
| |||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 1935 | ▶ | if ( $_->{'Speed'} > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | $self->{'data'}->{'Max Speed'} = $_->{'Speed'} | ||||||||||||||||||||||||||||
| 205 | 1928 | ▶ | if ( ! exists $self->{'data'}->{'Max Speed'} || $self->{'data'}->{'Max Speed'} < $_->{'Speed'} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $self->{"data"}{"Max Speed"} or $self->{"data"}{"Max Speed"} < $_->{"Speed"}
MC/DC100%2/2
not exists $self->{"data"}{"Max Speed"} or $self->{"data"}{"Max Speed"} < $_->{"Speed"}
not exists $self->{"data"}{"Max Speed"}
$self->{"data"}{"Max Speed"} < $_->{"Speed"}
Truth table100%3/3
not(A) or B
A= not exists $self->{"data"}{"Max Speed"}B= $self->{"data"}{"Max Speed"} < $_->{"Speed"}
| |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | # There is a bug when you have a warm up time, the first | ||||||||||||||||||||||||||||
| 208 | # checkpoint will have an unrealistic large value for Watts | ||||||||||||||||||||||||||||
| 209 | # and a zero value for Speed. | ||||||||||||||||||||||||||||
| 210 | 1928 | ▶ | if ( $_->{'Watts'} > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 1928 | $w += $_->{'Watts'}; $wc++; | |||||||||||||||||||||||||||
| 212 | $self->{'data'}->{'Max Watts'} = $_->{'Watts'} | ||||||||||||||||||||||||||||
| 213 | 1928 | ▶ | if ( ! exists $self->{'data'}->{'Max Watts'} || $self->{'data'}->{'Max Watts'} < $_->{'Watts'} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $self->{"data"}{"Max Watts"} or $self->{"data"}{"Max Watts"} < $_->{"Watts"}
MC/DC100%2/2
not exists $self->{"data"}{"Max Watts"} or $self->{"data"}{"Max Watts"} < $_->{"Watts"}
not exists $self->{"data"}{"Max Watts"}
$self->{"data"}{"Max Watts"} < $_->{"Watts"}
Truth table100%3/3
not(A) or B
A= not exists $self->{"data"}{"Max Watts"}B= $self->{"data"}{"Max Watts"} < $_->{"Watts"}
| |||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | 1935 | ▶ | if ( $_->{'Heart Rate'} > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 1857 | $hr += $_->{'Heart Rate'}; $hrc++; | |||||||||||||||||||||||||||
| 218 | $self->{'data'}->{'Max Heart Rate'} = $_->{'Heart Rate'} | ||||||||||||||||||||||||||||
| 219 | 1857 | ▶ | if ( ! exists $self->{'data'}->{'Max Heart Rate'} || $self->{'data'}->{'Max Heart Rate'} < $_->{'Heart Rate'} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $self->{"data"}{"Max Heart Rate"} or $self->{"data"}{"Max Heart Rate"} < $_->{"Heart Rate"}
MC/DC100%2/2
not exists $self->{"data"}{"Max Heart Rate"} or $self->{"data"}{"Max Heart Rate"} < $_->{"Heart Rate"}
not exists $self->{"data"}{"Max Heart Rate"}
$self->{"data"}{"Max Heart Rate"} < $_->{"Heart Rate"}
Truth table100%3/3
not(A) or B
A= not exists $self->{"data"}{"Max Heart Rate"}B= $self->{"data"}{"Max Heart Rate"} < $_->{"Heart Rate"}
| |||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | $dist += $_->{'Calculated Distance'} | ||||||||||||||||||||||||||||
| 222 | 1935 | ▶ | if ( ( $_->{'Calculated Distance'} + 0.0 ) > 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 7 | } @{$self->{'data'}->{'Check Points'}}; | |||||||||||||||||||||||||||
| 224 | 7 | ▶ | $self->{'data'}->{'Average Cadence'} = $c / $cc if ( $cc > 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 7 | ▶ | $self->{'data'}->{'Average Watts'} = $w / $wc if ( $wc > 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 7 | ▶ | $self->{'data'}->{'Average Heart Rate'} = $hr / $hrc if ( $hrc > 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | # BUG: The Distance listed in the file is the total distance | ||||||||||||||||||||||||||||
| 229 | # ridden, vs the Elapsed Time is not including any warmup time | ||||||||||||||||||||||||||||
| 230 | # For example, in the Bike2009-10-25 5-05.RAW test file, the | ||||||||||||||||||||||||||||
| 231 | # elapsed time is 2700 seconds (45 minutes), yet the distance traveled | ||||||||||||||||||||||||||||
| 232 | # is 16.87, which was covered in 60 minutes. Therefor, need to recaclute | ||||||||||||||||||||||||||||
| 233 | # the average speed based on the checkpoint's average speed. | ||||||||||||||||||||||||||||
| 234 | #$self->{'data'}->{'Average Speed'} = | ||||||||||||||||||||||||||||
| 235 | # $self->{'data'}->{'Distance'} / ($self->{'data'}->{'Elapsed Time'} / 3600); | ||||||||||||||||||||||||||||
| 236 | 7 | $self->{'data'}->{'Calculated Distance'} = $dist; | |||||||||||||||||||||||||||
| 237 | 7 | $self->{'data'}->{'Average Speed'} = $dist / ($self->{'data'}->{'Elapsed Time'} / 3600); | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 7 | ▶ | sub _verify_parse { | ||||||||||||||||||||||||||
|
Subroutine
_verify_parse: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 241 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | # Verify we got good data. The number of sample lines should be close | ||||||||||||||||||||||||||||
| 244 | # to Elapsed Time / Sample Rate. The 1.99 instead of 2 was determined | ||||||||||||||||||||||||||||
| 245 | # emperically, and probably due to samping error or clock flux. | ||||||||||||||||||||||||||||
| 246 | carp "Check Point Data does not match Sample Rate" | ||||||||||||||||||||||||||||
| 247 | 7 | if ( scalar @{$self->{'data'}->{'Check Points'}} != | |||||||||||||||||||||||||||
| 248 | 7 | ▶ | int($self->{'data'}->{'Elapsed Time'} / $self->{'data'}->{'Sample Rate'} + 1.99)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 7 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 252 | 7 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 253 | 7 | my ($cnt); | |||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 7 | ▶ | $self->open($file) || return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 7 | ▶ | warn "Reading contents of (" . $file . ")\n" if ( exists $self->{'debug'} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | # Change the input record seperator so we get the \r\n eaten by | ||||||||||||||||||||||||||||
| 260 | # perl itself, instead of having to code it in the regexes when | ||||||||||||||||||||||||||||
| 261 | # parsing the file data. | ||||||||||||||||||||||||||||
| 262 | { | ||||||||||||||||||||||||||||
| 263 | 7 | ▶ | local ($/) = $CRLF if ( $^O ne 'MSWin32' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 7 | @{$self->{'RAW'}} = <FP>; | |||||||||||||||||||||||||||
| 265 | 7 | chomp(@{$self->{'RAW'}}); | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 7 | $self->close(); | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | croak "Not enough data in file" | ||||||||||||||||||||||||||||
| 271 | 7 | ▶ | if ( scalar @{$self->{'RAW'}} < 14 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 7 | delete $self->{'data'}; | |||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | 7 | $self->_parse_preamble(); | |||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 7 | $self->_parse_line($self->{'RAW'}[7]); | |||||||||||||||||||||||||||
| 278 | 7 | ▶ | for ($cnt = 10; $cnt < scalar (@{$self->{'RAW'}}) - 5; $cnt++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | 1921 | $self->_parse_line($self->{'RAW'}[$cnt]); | |||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | 7 | $self->_parse_line($self->{'RAW'}[-4]); | |||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 7 | $self->_parse_summary(); | |||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 7 | $self->_add_averages(); | |||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 7 | $self->_verify_parse(); | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 7 | return ($self->{'data'}); | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 7 | ▶ | sub close { | ||||||||||||||||||||||||||
|
Subroutine
close: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 293 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 7 | ▶ | warn "Closing file (" . $self->{'file'} . ")\n" if ( exists $self->{'debug'} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | 7 | close (FP); | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 8 | 1; | |||||||||||||||||||||||||||
| 300 | __END__ | ||||||||||||||||||||||||||||