key / bicicalc

cyclo computer data cliculator (Garmin, Polar, PowerTap etc)

This URL has Read+Write access

bicicalc / bicicalc.py
100755 69 lines (55 sloc) 2.829 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
from optparse import OptionParser
from Bicicalc.Garmin.Tcx import history
from Bicicalc import calc, export
 
import sys
 
def main():
    parser = OptionParser()
    parser.need_dump = False
 
    # general options
    parser.add_option('-l', '--laps', type='str', action='append',
                      dest='lap_ranges', help='specify by lap(s): can be specified multiple laps.\n-l 2 or -l1-3 etc.')
    parser.add_option('--ftp', type='float', dest='ftp', help='set your functional threshould power')
    parser.add_option('--mp', type='int', dest='mp', help='n MP')
    parser.add_option('--crank-len', type='float', dest='cranklen', help='set crank length of your bike (mm)',
                      default=None)
 
    #
    parser.add_option('--dump-power-legspd', action='store_true', dest='dump_power_legspd',
                      help='dump power / leg-speed data')
 
    # dump options
    parser.add_option('--dump-csv', action='store_true', dest='dump_csv', help='dump csv data')
    parser.add_option('--dump-kml', action='store_true', dest='dump_kml', help='dump key hole markup')
    parser.add_option('--dump-profile', action='store_true', dest='dump_profile', help='dump course profile (distance/altitude)')
 
    # dump options specific kml format
    parser.add_option('--kml-name', action='store', dest='kml_name', help='name of kml file', default=' ')
    parser.add_option('--kml-description', action='store', dest='kml_desc', help='description of kml file', default='')
 
    # personal profile
    parser.add_option('--weight', action='store', dest='weight', type='float', help='weight in kilogram')
    parser.add_option('--age', action='store', dest='age', type='int', help='age')
    
    # for debug
    parser.add_option('--debug', action='store_true', dest='debug', help='enable debug mode (development only)')
    parser.add_option('--test', action='store_true', dest='test', help='run doctest')
    (options, args) = parser.parse_args()
 
    if len(args) < 1:
        sys.stderr.write('Usage: bicicalc.py [options] file\n')
        sys.exit(1)
 
    data=history.parseString(args[0])
 
    if options.dump_csv==True:
        export.csv(data)
    elif options.dump_kml==True:
        kml_vars={'name':options.kml_name, 'description':options.kml_desc}
        export.kml(data, kml_vars)
    elif options.dump_profile==True:
        export.profile(data)
    elif options.dump_power_legspd:
        if not options.cranklen:
            sys.stderr.write('ERROR:\nPower / Leg velocity needs cranklength. see --crank-len option\n')
            sys.exit(1)
        export.power_legspd(data, options.cranklen)
    elif options.mp:
        calc.peak_n_power(data, options.mp)
    else:
        calc.print_summary(data, options)
 
if __name__ == '__main__':
    main()