#!/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()