# Path: _import.py
# def postprocess_move(move):
# 
#     if move.public is None:
#         move.public = False
# 
#     gps_samples = [sample for sample in move.samples if sample.sample_type and sample.sample_type.startswith('gps-')]
# 
#     if gps_samples:
#         first_sample = gps_samples[0]
#         latitude = first_sample.latitude
#         longitude = first_sample.longitude
# 
#         if latitude and longitude:
#             geo_locator = Nominatim(user_agent='openmoves.net')
#             location = geo_locator.reverse("%f, %f" % (radian_to_degree(latitude), radian_to_degree(longitude)), timeout=60)
#             move.location_address = location.address
#             move.location_raw = location.raw
# 
# Path: filters.py
# def degree_to_radian(value):
#     if value is None:
#         return None
#     return math.radians(value)
# 
# def celcius_to_kelvin(value):
#     if value is None:
#         return None
#     return value + 273.15
# 
# Path: model.py
# class JsonEncodedDict(TypeDecorator):
# class Device(db.Model):
# class User(db.Model):
# class UserPreference(db.Model):
# class Move(db.Model):
# class Sample(db.Model):
# class MoveEdit(db.Model):
# class AlembicVersion(db.Model):
#     def process_bind_param(self, value, dialect):
#     def process_result_value(self, value, dialect):
#     def is_authenticated(self):
#     def is_active(self):
#     def is_anonymous(self):
#     def has_strava(self):
#     def get_strava_access_token(self):
#     def get_id(self):
#     def __init__(self, key, value):


from datetime import datetime, timedelta
from sqlalchemy.sql import func
from _import import postprocess_move
from filters import degree_to_radian, celcius_to_kelvin
from model import User, Device, Move, Sample, db
import numpy as np
import pytz
import stravalib
import gpx_import
        start_date = activity.start_date
        if activity.id in moves_by_strava_activity_id:
            move_id = moves_by_strava_activity_id[activity.id]
        elif start_date in moves_by_date_time:
            move_id = moves_by_date_time[start_date]
        else:
            for date_time in moves_by_date_time.keys():
                start_date_delta = abs(date_time - start_date)
                start_date_local_delta = abs(date_time - activity.start_date_local.replace(tzinfo=pytz.UTC))
                max_delta = timedelta(seconds=30)

                if start_date_delta <= max_delta or start_date_local_delta <= max_delta:
                    move_id = moves_by_date_time[date_time]
                    break

            if not move_id:
                potential_moves = []
                for date_time in moves_by_date_time.keys():
                    start_date_delta = abs(date_time - start_date)
                    if -MAX_DATE_TIME_OFFSET <= start_date_delta <= MAX_DATE_TIME_OFFSET:
                        potential_moves.append(moves_by_date_time[date_time])

                if len(potential_moves) == 1:
                    move_id = potential_moves[0]
                elif len(potential_moves) > 1:
                    # too many candidates found
                    pass

        if not move_id:
            new_strava_activities.append(activity)

# Path: _import.py
# def postprocess_move(move):
# 
#     if move.public is None:
#         move.public = False
# 
#     gps_samples = [sample for sample in move.samples if sample.sample_type and sample.sample_type.startswith('gps-')]
# 
#     if gps_samples:
#         first_sample = gps_samples[0]
#         latitude = first_sample.latitude
#         longitude = first_sample.longitude
# 
#         if latitude and longitude:
#             geo_locator = Nominatim(user_agent='openmoves.net')
#             location = geo_locator.reverse("%f, %f" % (radian_to_degree(latitude), radian_to_degree(longitude)), timeout=60)
#             move.location_address = location.address
#             move.location_raw = location.raw
# 
# Path: filters.py
# def degree_to_radian(value):
#     if value is None:
#         return None
#     return math.radians(value)
# 
# def celcius_to_kelvin(value):
#     if value is None:
#         return None
#     return value + 273.15
# 
# Path: model.py
# class JsonEncodedDict(TypeDecorator):
# class Device(db.Model):
# class User(db.Model):
# class UserPreference(db.Model):
# class Move(db.Model):
# class Sample(db.Model):
# class MoveEdit(db.Model):
# class AlembicVersion(db.Model):
#     def process_bind_param(self, value, dialect):
#     def process_result_value(self, value, dialect):
#     def is_authenticated(self):
#     def is_active(self):
#     def is_anonymous(self):
#     def has_strava(self):
#     def get_strava_access_token(self):
#     def get_id(self):
#     def __init__(self, key, value):


# Path: strava.py
from datetime import datetime, timedelta
from sqlalchemy.sql import func
from _import import postprocess_move
from filters import degree_to_radian, celcius_to_kelvin
from model import User, Device, Move, Sample, db
import numpy as np
import pytz
import stravalib
import gpx_import

        start_date = activity.start_date
        if activity.id in moves_by_strava_activity_id:
            move_id = moves_by_strava_activity_id[activity.id]
        elif start_date in moves_by_date_time:
            move_id = moves_by_date_time[start_date]
        else:
            for date_time in moves_by_date_time.keys():
                start_date_delta = abs(date_time - start_date)
                start_date_local_delta = abs(date_time - activity.start_date_local.replace(tzinfo=pytz.UTC))
                max_delta = timedelta(seconds=30)

                if start_date_delta <= max_delta or start_date_local_delta <= max_delta:
                    move_id = moves_by_date_time[date_time]
                    break

            if not move_id:
                potential_moves = []
                for date_time in moves_by_date_time.keys():
                    start_date_delta = abs(date_time - start_date)
                    if -MAX_DATE_TIME_OFFSET <= start_date_delta <= MAX_DATE_TIME_OFFSET:
                        potential_moves.append(moves_by_date_time[date_time])

                if len(potential_moves) == 1:
                    move_id = potential_moves[0]
                elif len(potential_moves) > 1:
                    # too many candidates found
                    pass

        if not move_id:
            new_strava_activities.append(activity)

        elif activity.id in moves_by_strava_activity_id: