7 from urllib2 import unquote
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 if type(filename) is str:
29 filename=filename.decode('UTF-8')
31 cur.execute ("delete from tracks where filename=?" , (filename,))
45 name=name.decode('UTF-8')
51 cur.execute("insert into authors(name,description) values(?,?)", (author,''))
52 print "created author %s" % (author)
54 print "failed to create author %s" % (author)
62 printable = pygeocode.GeoName(start.lat,start.lon).printable
63 start_time = track.start_time()
64 full_duration = track.full_duration().total_seconds()
65 distance = track.distance()
66 filtered_distance = track.filtered_distance(max_speed=50)
67 ascent = track.elevation_gain()
68 descent = track.elevation_loss()
69 ((minlat,minlon),(maxlat,maxlon)) = track.bound_box()
71 gpx.author,name,filename,
72 track.sport,start_time,full_duration,
73 distance,filtered_distance,ascent,descent,
76 minlat,minlon,maxlat,maxlon
81 author,name,filename,sport,
83 distance,distance_filtered,
85 lat,lon,printable_location,minlat,minlon,maxlat,maxlon)
87 ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
91 print "created track %s" % (filename)
97 def write_tree_to_db(db,tree,filename):
102 write_parsed_to_db(db,gpx,filename)
104 def print_parsed_file(filename):
107 gpx.ReadFile(filename)
109 for track in gpx.tracks:
121 start = track.start()
123 printable = pygeocode.GeoName(start.lat,start.lon).printable
124 start_time = track.start_time()
125 full_duration = track.full_duration().total_seconds()
126 distance = track.distance()
127 filtered_distance = track.filtered_distance(max_speed=50)
128 ascent = track.elevation_gain()
129 descent = track.elevation_loss()
130 ((minlat,minlon),(maxlat,maxlon)) = track.bound_box()
132 gpx.author,name,filename.decode('UTF-8'),
133 track.sport,start_time,full_duration,
134 distance,filtered_distance,ascent,descent,
137 minlat,minlon,maxlat,maxlon