-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmoothen
55 lines (46 loc) · 2.34 KB
/
smoothen
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
#!/usr/bin/env python2
from smoothify import extractgpx,smoothen,upload,functions
import argparse
import os
from datetime import datetime
p = argparse.ArgumentParser(description='''Smoothen activity on Strava.''')
p.add_argument('-a', '--activity-id' , default=0 , help="activity id, latest activity is taken by default.")
p.add_argument('-g', '--no-graph' , action='store_true', help="do not create png file showing original and smoothened data.")
p.add_argument('-u', '--no-upload' , action='store_true' , help="do not upload smoothened data to Strava.")
p.add_argument('-d', '--dry-run' , action='store_true' , help="do not overwrite original activity when attempting to upload to Strava.")
p.add_argument('-c', '--cleanup' , action='store_true' , help="delete created files after uploading activity.")
p.add_argument('-s', '--algo' , default=2 , help="smoothening algorithm.")
args = p.parse_args()
token=functions.gettoken()
activity,client = extractgpx.main(args.activity_id)
if not activity == None :
gpxsmooth,lat,lon,ele,latsmooth,lonsmooth,elesmooth = smoothen.main('{}.gpx'.format(activity.id),args.algo)
if not args.no_graph :
functions.plotfiles('{}.png'.format(activity.id),'{}.gpx'.format(activity.id),'{}_smooth.gpx'.format(activity.id))
options = ""
if not args.dry_run :
options = options + "-o "
options = options + "-A " + activity.type
if not args.no_upload :
snd = 0
upl = options+" -f "+str(activity.id)+"_smooth.gpx"
newactivity = upload.main(upl)
if newactivity:
snd = float(newactivity.distance)
# print some processing info
sod = float(activity.distance)
god = functions.distance(lat,lon,ele)
gnd = functions.distance(latsmooth,lonsmooth,elesmooth)
rgod = (god-sod)/sod*100
rgnd = (gnd-sod)/sod*100
print('Strava old distance: {0:.0f}m'.format(sod))
if not args.no_upload :
rsnd = (snd-sod)/sod*100
print('Strava new distance: {0:.0f}m ({1:.2f}%)'.format(snd,rsnd))
print('Old gpx distance: {0:.0f}m ({1:.2f}%)'.format(god,rgod))
print('New gpx distance: {0:.0f}m ({1:.2f}%)'.format(gnd,rgnd))
if args.cleanup :
os.remove(activity_id+".gpx")
os.remove(activity_id+"_smooth.gpx")
os.remove(activity_id+".png")
print('Removed created files')