-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwkmodify
More file actions
executable file
·169 lines (135 loc) · 3.38 KB
/
wkmodify
File metadata and controls
executable file
·169 lines (135 loc) · 3.38 KB
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
#!/usr/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.
#
# TODO: pod
use strict;
use warnings;
use Workout;
use Getopt::Long;
use I18N::Langinfo qw(langinfo CODESET);
my $charset = langinfo(CODESET);
binmode STDIN, ":encoding($charset)";
binmode STDOUT, ":encoding($charset)";
binmode STDERR, ":encoding($charset)";
my $itype;
my $start;
my $delta;
my $note;
my $sport;
my $slope;
my $circum;
my $zeropos;
my $athletename;
my $recalc_power;
my $docalc;
my $debug;
my $needhelp;
my $wanthelp;
if( ! GetOptions(
'athlete=s' => \$athletename,
'calc!' => \$docalc,
'circum=i' => \$circum,
'debug!' => \$debug,
'delta|d=i' => \$delta,
'help!' => \$wanthelp,
'itype=s' => \$itype,
'note=s' => \$note,
'sport=s' => \$sport,
'recalc-power!' => \$recalc_power,
'slope=f' => \$slope,
'start=s' => \$start,
'zeropos=i' => \$zeropos,
)){
$needhelp++;
}
if( $wanthelp ){
print <<EOF;
$0 [opt] <input file>
modify workout attributes
Options:
--start=<yyyy-mm-dd h:m:s> set new start time
--delta=<sec> add delta to start time
--note=<n> set note
--sport=<n> set sport
--calc recalculate summaries
--recalc-power recalculate power based on new slope/zeropos
--slope=<x> set slope (SRM)
--circum=<x> set wheel circumference (SRM)
--zeropos=<x> set zero offset (SRM)
--athlete=<name> set athlete name (SRM)
--debug enable debuging output
--help this help
EOF
exit 0;
}
if( @ARGV != 1 ){
print STDERR "you need to specify a single input file\n";
$needhelp++;
}
if( $needhelp ){
print STDERR "use --help for usage info\n";
exit 1;
}
my $fname = shift;
my $src = Workout::file_read( $fname, {
ftype => $itype,
debug => $debug,
} );
if( $recalc_power && ($zeropos || $slope) ){
my $old_slope = $src->meta_field('slope');
my $old_zeropos = $src->meta_field('zeropos');
$slope ||= $old_slope;
$zeropos ||= $old_zeropos;
my $dst = $src->new( {
debug => $debug,
recint => $src->recint,
} );
$dst->from( Workout::filter( 'PwrFix', $src, {
old_slope => $old_slope,
new_slope => $slope,
old_zeropos => $old_zeropos,
new_zeropos => $zeropos,
}) );
$src = $dst;
}
if( $start ){
if( my( $year,$mon,$day, $hour, $min, $sec, $nsec ) =
($start =~ /^(?:(\d\d\d\d)-(\d+)-(\d+)\s+)?(\d+):(\d+)(?::(\d+)(\.\d+)?)?$/ )){
my $fdate = DateTime->from_epoch(
time_zone => 'local',
epoch => $src->time_start,
);
my $sdate = DateTime->new(
year => $year || $fdate->year,
month => $mon || $fdate->month,
day => $day || $fdate->day,
hour => $hour,
minute => $min,
second => $sec || $fdate->second,
nanosecond => $nsec * 1000000000 || $fdate->nanosecond,
);
$delta = $sdate->hires_epoch - $src->time_start;
} elsif( my( $stime ) = ($start =~ /^(\d+)$/ ) ){
$delta = $stime - $src->time_start;
} else {
print STDERR "invalid start time\n";
exit 1;
}
}
$delta && $src->time_add_delta( $delta );
foreach my $attr ( qw( note sport slope circum zeropos athletename )){
my $v = eval "\$$attr";
next unless defined $v;
$src->meta_field( $attr, $v );
}
if( $docalc || $recalc_power || $delta ){
$src->meta_prune_all;
}
$src->write( "$fname.wkmodify" );
unlink $fname or die "unlink $fname failed: $!";
rename "$fname.wkmodify", $fname;