# 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

    activity_string = map_type(activity.type)

    result = db.session.query(Move.activity_type).filter(Move.activity == activity_string).first()
    if result:
        activity_type, = result
    else:
        activity_type = None

    device = find_device(current_user)

    move = Move()
    move.user = current_user
    move.duration = activity.elapsed_time
    move.ascent = float(activity.total_elevation_gain)
    move.speed_avg = float(activity.average_speed)
    move.hr_avg = heart_rate(activity.average_heartrate)
    move.temperature_avg = celcius_to_kelvin(activity.average_temp)
    move.device = device
    move.date_time = activity.start_date_local
    move.activity = activity_string
    move.activity_type = activity_type
    move.distance = float(activity.distance)
    move.import_date_time = datetime.now()
    move.import_module = __name__
    move.strava_activity_id = activity_id
    move.public = False
    move.source = "Strava activity id=%d; external_id='%s'" % (activity_id, activity.external_id)

    if streams:

# 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


    activity_string = map_type(activity.type)

    result = db.session.query(Move.activity_type).filter(Move.activity == activity_string).first()
    if result:
        activity_type, = result
    else:
        activity_type = None

    device = find_device(current_user)

    move = Move()
    move.user = current_user
    move.duration = activity.elapsed_time
    move.ascent = float(activity.total_elevation_gain)
    move.speed_avg = float(activity.average_speed)
    move.hr_avg = heart_rate(activity.average_heartrate)
    move.temperature_avg = celcius_to_kelvin(activity.average_temp)
    move.device = device
    move.date_time = activity.start_date_local
    move.activity = activity_string
    move.activity_type = activity_type
    move.distance = float(activity.distance)
    move.import_date_time = datetime.now()
    move.import_module = __name__
    move.strava_activity_id = activity_id
    move.public = False
    move.source = "Strava activity id=%d; external_id='%s'" % (activity_id, activity.external_id)

    if streams:

        lengths = set([len(streams[stream].data) for stream in streams])