script/na2png

filter: Statementstmt 88.8% 16 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.6% 22 / 24 CC 1 SCAR 0.5
CC
1
Cov
89%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/NetAthlon2/RAW.pm ↑ Summary
1 #!/usr/bin/env perl
2  
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Getopt::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use NetAthlon2::RAW;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 0 ▶use GD::Graph;
Subroutine BEGIN: called CC=1 SCAR=2.6
9 use GD::Graph::lines;
10  
11 my (%opts, @data);
12 $opts{'l'} = 4;
13 $opts{'s'} = 600;
14 $opts{'t'} = &File::Basename::basename($0, '.pl');
15 $opts{'t'} =~ s/na2//;
16  
17 sub usage () {
18 printf "Usage: %s [-h] [-l width] [-s size] [-t type] <input file(s)>\n",
19 &File::Basename::basename($0, '.pl');
20 printf "\t-h\t\tThis help screen\n";
21 printf "\t-l <width>\tLine width (defaults to $opts{'l'})\n";
22 printf "\t-s <size>\tImage size (defaults to $opts{'s'})\n";
23 printf "\t-t <type>\tImage type (defaults to $opts{'t'})\n";
24 exit 0;
25 }
26  
27 sub x_format {
28 my $value = shift;
29  
30 return sprintf("%.2dh %2.2d\' %2.2d\"", int($value / 3600), int(($value % 3600) / 60), int($value % 60));
31 }
32  
33 getopts('hl:s:t:', \%opts);
34  
35 &usage if ( $opts{'h'} || ! scalar @ARGV );
36  
37 {
38 no warnings "once";
39 $NetAthlon2::RAW::timeDelta = 5;
40 }
41 my $t = NetAthlon2::RAW->new ();
42  
43 die "Could not new NetAthlon2::RAW\n" if ( ! defined $t );
44  
45 foreach my $file ( @ARGV ) {
46 my $d = $t->parse($file);
47 die "Could not read return data from NetAthlon2::RAW::parse($file)\n"
48 if ( ! defined $d );
49  
50 # save the data we want to graph
51 my (@c, @h, @s, @p, @t);
52 map {
53 push @t, $_->{'Elapsed Time'};
54 push @h, $_->{'Heart Rate'};
55 push @c, $_->{'Cadence'};
56 push @s, $_->{'Speed'} * 10;
57 push @p, $_->{'Watts'};
58 } @{$d->{'Check Points'}};
59 @data = ( [ @t ], [ @h ], [ @c ], [ @s ], [ @p ] );
60 my $y_max = $d->{'Max Watts'};
61
62 # Use GD to create the image file
63 my $img = new GD::Graph::lines((4 * $opts{'s'}/3), $opts{'s'});
64 $img->set(
65 x_label => 'Time (Minutes)',
66 x_min_value => 0,
67 x_max_value => $d->{'Sample Rate'} * scalar @{$d->{'Check Points'}},
68 x_number_format => \&x_format,
69 x_label_position => 1/2,
70 x_labels_vertical => 1,
71 y_label => 'Heart Rate (BPM) / Cadence (RPM) / Speed x 10 (MPH) / Power (Watts)',
72 y_min_value => 0,
73 y_max_value => $y_max,
74 x_tick_number => 8,
75 box_axis => 0,
76 line_width => $opts{'l'},
77 title => 'Performance Data over Time',
78 dclrs => [ 'red', 'purple', 'green', 'blue', ],
79 transparent => 0,
80 );
81 $img->set_text_clr('black');
82 $img->set_legend('Heart Rate', 'Cadence', 'Speed', 'Power');
83 my $gd = $img->plot(\@data) ||
84 die "Could not create GD object (" . $img->error . ")\n";
85  
86 # Create the output file
87 my $format = $opts{'t'};
88 my $outfile = &File::Basename::basename($file, '.RAW') . '.' . $format;
89 open (OUT, ">$outfile") || die "Could not create file ($outfile)\n";
90 binmode OUT;
91 print OUT $gd->$format() ||
92 die "Could not write data to ($outfile)\n";
93 close OUT;
94 }
95  
96 exit 0;
« blib/lib/NetAthlon2/RAW.pm ↑ Summary