# 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
                    move.ascent_time += time_diff
                elif altitude_diff < 0:
                    move.descent += -altitude_diff
                    move.descent_time += time_diff

        # Store sample for next cycle
        previous_sample = sample

    # Temperature
    temperatures = np.asarray([sample.temperature for sample in samples if sample.temperature], dtype=float)
    if len(temperatures) > 0:
        move.temperature_min = np.min(temperatures)
        move.temperature_max = np.max(temperatures)

    # Heart rate
    hrs = np.asarray([sample.hr for sample in samples if sample.hr], dtype=float)
    if len(hrs) > 0:
        move.hr_min = np.min(hrs)
        move.hr_max = np.max(hrs)


def heart_rate(hr):
    if hr is None:
        return None
    return float(hr) / 60.0


def associate_activities(user, before=None, after=None):
    assert user.has_strava()
    moves_by_date_time = {}

# 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

                    move.ascent_time += time_diff
                elif altitude_diff < 0:
                    move.descent += -altitude_diff
                    move.descent_time += time_diff

        # Store sample for next cycle
        previous_sample = sample

    # Temperature
    temperatures = np.asarray([sample.temperature for sample in samples if sample.temperature], dtype=float)
    if len(temperatures) > 0:
        move.temperature_min = np.min(temperatures)
        move.temperature_max = np.max(temperatures)

    # Heart rate
    hrs = np.asarray([sample.hr for sample in samples if sample.hr], dtype=float)
    if len(hrs) > 0:
        move.hr_min = np.min(hrs)
        move.hr_max = np.max(hrs)


def heart_rate(hr):
    if hr is None:
        return None
    return float(hr) / 60.0


def associate_activities(user, before=None, after=None):
    assert user.has_strava()
    moves_by_date_time = {}

    for id, date_time in db.session.query(Sample.move_id, func.min(Sample.utc)) \