#!/usr/bin/env python import argparse import datetime import sys import gpx_parser def parse_args(): '''Shell argument parser.''' parser = argparse.ArgumentParser() parser.add_argument('infolder', help='Specify the in folder.') return parser.parse_args() def main(): args = parse_args() tracks = gpx_parser.Tracks(args.infolder) for year in range(2017, 2019): year_distance = 0.0 year_duration = 0 for month in range(1, 13): if month == 12: max_day = (datetime.date(year + 1, 1, 1) - datetime.timedelta(days=1)).day else: max_day = (datetime.date(year, month + 1, 1) - datetime.timedelta(days=1)).day for day in range(1, max_day): date_tracks = tracks.get(year, month, day) date_date = datetime.datetime(year, month, day) date_dist = 0.0 date_duration = 0 for track in date_tracks: date_dist += track.distance year_distance += track.distance date_duration += track.duration.total_seconds() year_duration += track.duration.total_seconds() if date_dist > 0.0: print date_date print ' Distance: ' + str(round(date_dist / 1000, 2)) + ' km' print ' Duration: ' + str(datetime.timedelta(seconds=int(round(date_duration, 0)))) print 'Average speed: ' + str(round(date_dist / date_duration * 3.6, 2)) + ' km/h' print '==================' print year print ' Distance: ' + str(round(year_distance / 1000, 2)) + ' km' print ' Duration: ' + str(datetime.timedelta(seconds=int(round(year_duration, 0)))) print 'Average speed: ' + str(round(year_distance / year_duration * 3.6, 2)) + ' km/h' print '==================' return 0 if __name__ == '__main__': sys.exit(main())