def add_run(gpx, name,act_type,filename,polyline): conn = sqlite3.connect('%s/activities.db' % filebase) cursor = conn.cursor() cursor.execute("""CREATE TABLE if not exists activities (id INTEGER PRIMARY KEY AUTOINCREMENT,name text, act_date text, distance text, speed text, act_type text,filename text,polyline text)""") sql = "INSERT INTO activities VALUES (?,?,?,?,?,?,?,?)" start_time, end_time = gpx.get_time_bounds() l2d='{:.3f}'.format(gpx.length_2d() / 1000.) moving_time, stopped_time, moving_distance, stopped_distance, max_speed = gpx.get_moving_data() print(max_speed) #print('%sStopped distance: %sm' % stopped_distance) maxspeed = 'Max speed: {:.2f}km/h'.format(max_speed * 60. ** 2 / 1000. if max_speed else 0) duration = '{:.2f}'.format(gpx.get_duration() / 60) print("-------------------------") print(name) print(start_time) print(l2d) print(maxspeed) print("-------------------------") try: cursor.execute(sql, [None, name,start_time,l2d,duration,act_type,filename,polyline]) conn.commit() except sqlite3.Error as er: print("-------------______---_____---___----____--____---___-----") print(er) conn.close()
def add_run(gpx, name, act_type, filename, polyline): conn = sqlite3.connect("%s/activities.db" % filebase) cursor = conn.cursor() cursor.execute( """CREATE TABLE if not exists activities (id INTEGER PRIMARY KEY AUTOINCREMENT,name text, act_date text, distance text, speed text, act_type text,filename text,polyline text)""" ) sql = "INSERT INTO activities VALUES (?,?,?,?,?,?,?,?)" start_time, end_time = gpx.get_time_bounds() l2d = "{:.3f}".format(gpx.length_2d() / 1000.0) moving_time, stopped_time, moving_distance, stopped_distance, max_speed = gpx.get_moving_data() print(max_speed) # print('%sStopped distance: %sm' % stopped_distance) maxspeed = "Max speed: {:.2f}km/h".format(max_speed * 60.0 ** 2 / 1000.0 if max_speed else 0) duration = "Duration: {:.2f}min".format(gpx.get_duration() / 60) print("-------------------------") print(name) print(start_time) print(l2d) print(maxspeed) print("-------------------------") try: cursor.execute(sql, [None, name, start_time, l2d, duration, act_type, filename, polyline]) conn.commit() except sqlite3.Error as er: print(er) conn.close()
pset = next(s for s in psets.find('photosets').findall('photoset') if s.find('title').text == ALBUM) print('This album has {} photos'.format(pset.get('photos'))) except StopIteration: print('Flickr album {} not found!'.format(ALBUM)) sys.exit(1) # combine all GPS tracks into one gpx = gpxpy.gpx.GPX() for t in TRACKS: print('Processing GPS track {}'.format(t)) f = open(t, 'r') g = gpxpy.parse(f) gpx.tracks.extend(g.tracks) time_bounds = gpx.get_time_bounds() print('These tracks start at {} and end at {}'.format(time_bounds.start_time, time_bounds.end_time)) for photo in flickr.walk_set(pset.get('id')): id = photo.get('id') p = flickr.photos.getInfo(photo_id=id) taken = p.find('photo').find('dates').get('taken') taken_dt = datetime.datetime.strptime( taken, '%Y-%m-%d %H:%M:%S') + datetime.timedelta(hours=OFFSET) trackpoints = gpx.get_location_at(taken_dt) print('Photo {} was taken on {} at {}'.format(id, taken_dt, trackpoints)) for tp in trackpoints: print('Trying to geotag it now...') resp = flickr.photos.geo.setLocation(photo_id=id, lat=unicode(tp.latitude),
def gpx_covid_regulations_check_compliance(gpx_file, domicile): d_max = 1.0 d_runner = 0.0 gpx = gpxpy.parse(gpx_file) for track in gpx.tracks: for segment in track.segments: for point in segment.points: gps_pos = Position_GPS(point.longitude, point.latitude, "") distance = domicile.calculateDistanceVolOiseau(gps_pos) if distance > d_max and distance > d_runner: d_runner = distance # # Quelques rappels sur les timezones et conversions de timestamps créés avec une timezone UTC # But de cette manipulation: pas trouvé de documentation sur le package GpxPi pour changer la timezone... # et données Strava utilisent UTC comme Timezone et Paris est à UTC+2 (GMT+1) # donc on utilse la fonction astimezone de la classe datetime :-) # utc = timezone('UTC') paris = timezone('Europe/Paris') berlin = timezone('Europe/Berlin') tokyo = timezone('Asia/Tokyo') new_york = timezone('America/New_York') los_angeles = timezone('America/Los_Angeles') paris_time = datetime.now(paris) berlin_time = datetime.now(berlin) tokyo_time = datetime.now(tokyo) new_york_time = datetime.now(new_york) los_angeles_time = datetime.now(los_angeles) utc_time = datetime.now(utc) # print("UTC Time", utc_time) # print("Europe/Paris", paris_time.strftime('%Y-%m-%d_%H-%M-%S')) # print("Europe/Berlin", berlin_time.strftime('%Y-%m-%d_%H-%M-%S')) # print("Asia/Tokyo", tokyo_time.strftime('%Y-%m-%d_%H-%M-%S')) # print("America/New_York", new_york_time.strftime('%Y-%m-%d_%H-%M-%S')) # print("America/Los_Angeles", los_angeles_time.strftime('%Y-%m-%d_%H-%M-%S')) locale.setlocale(locale.LC_TIME, 'fr_FR') time_bound = gpx.get_time_bounds() #print("Old Timezone", time_bound.start_time.tzinfo) start_time = time_bound.start_time.astimezone(paris) #print("New Timezone", start_time.tzinfo) end_time = time_bound.end_time.astimezone(paris) day = start_time.strftime('%A %d %B %Y') hour = start_time.strftime('%Hh%M') elapsed_time = gpx.get_duration() distance2d = gpx.length_2d() / 1000 distance3d = gpx.length_3d() / 1000 duration_OK = True distance_OK = True amende = False exceeded_time = 0 exceeded_distance = 0 if d_runner > d_max: distance_OK = False exceeded_distance = d_runner - d_max if elapsed_time > 3600: duration_OK = False exceeded_time = elapsed_time - 3600 if not (duration_OK and distance_OK): amende = True return day, hour, amende, distance3d, elapsed_time, distance_OK, duration_OK, exceeded_time, exceeded_distance