-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwkplot
executable file
·182 lines (138 loc) · 3.33 KB
/
wkplot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/perl -w
#
# Copyright (c) 2008 Rainer Clasen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms described in the file LICENSE included in this
# distribution.
#
use strict;
use warnings;
use Getopt::Long;
use Workout;
use Workout::Chart::Workout;
use Gtk2 '-init';
use Glib qw/ TRUE FALSE /;
use MyChart::Gtk;
use I18N::Langinfo qw(langinfo CODESET);
my $charset = langinfo(CODESET);
binmode STDIN, ":encoding($charset)";
binmode STDOUT, ":encoding($charset)";
binmode STDERR, ":encoding($charset)";
my $recint;
my @itype;
my @delta;
my @fields;
my $debug;
my $wanthelp;
my $needhelp;
# TODO: allow selection of graphs per file
# TODO: write chart image to file
# TODO: suppress plots during block gaps
if( ! GetOptions(
"debug!" => \$debug,
"delta|d=s" => \@delta,
"fields=s" => \@fields,
"help!" => \$wanthelp,
"itype=s" => \@itype,
"recint=f" => \$recint,
)){
$needhelp++;
}
if( $wanthelp ){
print <<EOF;
$0 [opt] <fname> ...
display graph for workout(s)
Options:
--itype=<type>,... file types for input files
--delta=<d1>,... per file time-shift in seconds
--recint=<sec> resample data to recint before plotting
--fields=<f1>,... fields to plot: ele, spd, cad, hr, pwr
--debug print debug output
--help this cruft
EOF
exit 0;
}
@fields = split( /,/, join(',',@fields));
if( grep { ! /^(?:spd|cad|ele|pwr|hr|torque|temp|deconv|grad|accel|vspd)$/ } @fields ){
print STDERR "invalid field\n";
$needhelp++;
}
@fields = (qw/ ele spd cad hr pwr /) unless @fields;
@delta = split( /,/, join(',',@delta));
if( grep { ! /^-?\d+$/ } @delta ){
print STDERR "invalid delta\n";
$needhelp++;
}
@itype = split(/,/,join(',',@itype)) if @itype;
if( ! @ARGV ){
print STDERR "missing input files\n";
$needhelp++;
}
if( $needhelp ){
print STDERR "please use $0 --help for usage info\n";
exit 1;
}
my $wkdb = Workout->new;
my %tresh;
foreach my $f ( @fields ){
my %a;
foreach my $n ( qw( min max tic_step tic_num tic_at label_fmt ) ){
my $v = $wkdb->config("chart_${f}_$n");
next unless defined $v;
$a{$n} = $v;
}
$tresh{$f} = \%a;
}
my $title = "wkplot: ". $ARGV[0];
$title .= ", ..." if @ARGV > 1;
my $win = Gtk2::Window->new;
$win->set_title( $title );
$win->signal_connect( 'destroy' => sub { Gtk2->main_quit } );
$win->signal_connect( 'size-request' => sub {
my( $self, $req ) = @_;
$req->width( 600 );
$req->height( 300 );
1;
} );
my $box = Gtk2::VBox->new;
$win->add( $box );
# graph
my $chart = Workout::Chart::Workout->new({
xscale => 'time',
fields => \%tresh,
debug => $debug,
});
my $graph = MyChart::Gtk->new(
chart => $chart,
);
foreach my $fname ( @ARGV ){
my $d = shift @delta;
my $t = shift @itype;
my $wk = Workout::file_read( $fname, {
ftype => $t,
debug => $debug,
} );
$wk = Workout::filter( 'Timeshift', $wk, {
debug => $debug,
delta => $d,
}) if $d;
$wk = Workout::filter( 'Resample', $wk, {
debug => $debug,
recint => $recint,
}) if $recint;
$chart->add_workout( $wk );
}
$box->pack_start( $graph, 1, 1, 0 );
my $hbox = Gtk2::HBox->new;
$box->pack_start( $hbox, 0, 0, 0 );
# TODO: zoom controls
# Quit
my $quit = Gtk2::Button->new( 'Quit' );
$quit->signal_connect( clicked => sub {
my( $button, $window ) = @_;
$window->destroy;
}, $win );
$hbox->pack_start( $quit, 1, 0, 0 );
$win->show_all;
Gtk2->main;