@@ -98,33 +98,37 @@ def print_gpx_info(gpx, gpx_file,gpx_name,act_type):
9898 print_gpx_part_info (gpx )
9999 add_run (gpx ,gpx_name ,act_type ,gpx_file ,"" )
100100
101- def add_run (gpx_part ,name ,act_type ,filename ,polyline ):
101+ def add_run (gpx_part , name , act_type , filename , polyline ):
102102 conn = sqlite3 .connect ('%s/activities.db' % filebase )
103103 cursor = conn .cursor ()
104104 cursor .execute ("""CREATE TABLE if not exists activities
105105 (id INTEGER PRIMARY KEY AUTOINCREMENT,name text, act_date text, distance text,
106- speed text, act_type text,filename text,polyline text)""" )
106+ speed text, act_type text, filename text, polyline text)""" )
107107 sql = "INSERT INTO activities VALUES (?,?,?,?,?,?,?,?)"
108+
108109 start_time , end_time = gpx_part .get_time_bounds ()
109- #l2d='{:.3f}'.format(gpx.length_2d() / 1000.)
110- l2d = '{:.3f}' .format (gpx_part .length_2d () / 1000. )
111110 moving_time , stopped_time , moving_distance , stopped_distance , max_speed = gpx_part .get_moving_data ()
112- print (max_speed )
113- #print('%sStopped distance: %sm' % stopped_distance)
114- maxspeed = 'Max speed: {:.2f}km/h' .format (max_speed * 60. ** 2 / 1000. if max_speed else 0 )
115- duration = '{:.2f}' .format (gpx_part .get_duration () / 60 )
116-
117- print ("-------------------------" )
118- print (name )
119- print (start_time )
120- print (l2d )
121- print (maxspeed )
122- print ("-------------------------" )
111+
112+ length_2d = gpx_part .length_2d ()
113+ l2d = '{:.3f}' .format (length_2d / 1000. if length_2d is not None else 0 )
114+
115+ maxspeed = 'Max speed: {:.2f}km/h' .format (max_speed * 60. ** 2 / 1000. if max_speed is not None else 0 )
116+
117+ duration = gpx_part .get_duration ()
118+ duration_formatted = '{:.2f}' .format (duration / 60 if duration is not None else 0 )
119+
120+ # print("-------------------------")
121+ # print(name)
122+ # print(start_time)
123+ # print(l2d)
124+ # print(maxspeed)
125+ # print("-------------------------")
126+
123127 try :
124- cursor .execute (sql , [None , name ,start_time ,l2d ,duration , act_type ,filename ,polyline ])
128+ cursor .execute (sql , [None , name , start_time , l2d , duration_formatted , act_type , filename , polyline ])
125129 conn .commit ()
126130 except sqlite3 .Error as er :
127- print ("-------------______---_____---___----____--____---___- ----" )
131+ print ("----sql error ----" )
128132 print (er )
129133 conn .close ()
130134
0 commit comments