7 from urllib.parse import unquote
9 import pyrungps.pygeocode
13 def check_db_for_training(db,sport,timestamp):
15 conn = sqlite3.connect(db)
16 conn.text_factory = str
19 cur.execute ("select count(*) from tracks where sport=? and start_time=?" , (sport,timestamp))
20 return cur.fetchall()[0][0]
22 def write_parsed_to_db(db,gpx,filename):
24 conn = sqlite3.connect(db)
25 conn.text_factory = str
28 cur.execute ("delete from tracks where filename=?" , (filename,))
46 cur.execute("insert into authors(name,description) values(?,?)", (author,''))
47 print("created author %s" % (author))
49 print("failed to create author %s" % (author))
54 print("processing...")
57 printable = pygeocode.GeoName(start.lat,start.lon).printable
58 start_time = track.start_time()
59 full_duration = track.full_duration().total_seconds()
60 distance = track.distance()
61 filtered_distance = track.filtered_distance(max_speed=50)
62 ascent = track.elevation_gain()
63 descent = track.elevation_loss()
64 ((minlat,minlon),(maxlat,maxlon)) = track.bound_box()
66 gpx.author,name,filename,
67 track.sport,start_time,full_duration,
68 distance,filtered_distance,ascent,descent,
71 minlat,minlon,maxlat,maxlon
76 author,name,filename,sport,
78 distance,distance_filtered,
80 lat,lon,printable_location,minlat,minlon,maxlat,maxlon)
82 ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
86 print("created track %s" % (filename))
92 def write_tree_to_db(db,tree,filename):
97 write_parsed_to_db(db,gpx,filename)
99 def print_parsed_file(filename):
102 gpx.ReadFile(filename)
104 for track in gpx.tracks:
116 start = track.start()
118 printable = pygeocode.GeoName(start.lat,start.lon).printable
119 start_time = track.start_time()
120 full_duration = track.full_duration().total_seconds()
121 distance = track.distance()
122 filtered_distance = track.filtered_distance(max_speed=50)
123 ascent = track.elevation_gain()
124 descent = track.elevation_loss()
125 ((minlat,minlon),(maxlat,maxlon)) = track.bound_box()
127 gpx.author,name,filename,
128 track.sport,start_time,full_duration,
129 distance,filtered_distance,ascent,descent,
132 minlat,minlon,maxlat,maxlon