# Path: filters.py
# def radian_to_degree(value):
#     return math.degrees(value)
# 
# Path: model.py
# class Sample(db.Model):
#     __tablename__ = 'sample'
#     id = db.Column(db.Integer, name='id', primary_key=True)
# 
#     move_id = db.Column(db.Integer, db.ForeignKey(Move.id), name='move_id', nullable=False)
#     move = db.relationship(Move, backref=db.backref('samples', lazy='dynamic'))
# 
#     sample_type = db.Column(db.String, name='sample_type')
#     time = db.Column(db.Interval, name='time')
#     utc = db.Column(db.DateTime, name='utc')
# 
#     distance = db.Column(db.Float, name='distance')
#     speed = db.Column(db.Float, name='speed')
#     temperature = db.Column(db.Float, name='temperature')
# 
#     hr = db.Column(db.Float, name='hr')
#     energy_consumption = db.Column(db.Float, name='energy_consumption')
#     relative_performance_level = db.Column(db.Float, name='relative_performance_level')
# 
#     vertical_speed = db.Column(db.Float, name='vertical_speed')
#     sea_level_pressure = db.Column(db.Float, name='sea_level_pressure')
# 
#     gps_altitude = db.Column(db.Float, name='gps_altitude')
#     gps_heading = db.Column(db.Float, name='gps_heading')
#     gps_speed = db.Column(db.Float, name='gps_speed')
#     gps_hdop = db.Column(db.Float, name='gps_hdop')
# 
#     number_of_satellites = db.Column(db.Integer, name='number_of_satellites')
# 
#     latitude = db.Column(db.Float, name='latitude')
#     longitude = db.Column(db.Float, name='longitude')
# 
#     altitude = db.Column(db.Integer, name='altitude')
# 
#     ehpe = db.Column(db.Float, name='ehpe')  # Estimated Horizontal Position Error
# 
#     cadence = db.Column(db.Float, name='cadence')
# 
#     nav_type = db.Column(db.Integer, name='nav_type')
#     nav_valid = db.Column(db.String, name='nav_valid')
#     nav_type_explanation = db.Column(db.String, name='nav_type_explanation')
# 
#     events = db.Column(JsonEncodedDict(4096), name='events')
#     satellites = db.Column(JsonEncodedDict(4096), name='satellites')
#     apps_data = db.Column(JsonEncodedDict(4096), name='apps_data')


from datetime import timedelta, datetime
from geopy.geocoders import Nominatim
from filters import radian_to_degree
from model import Sample
import re
import sqlalchemy
        for child in sample_node.iterchildren():
            tag = normalize_tag(child.tag)
            value = child.text

            if tag == 'events':
                sample.events = parse_json(child)
            elif tag == 'satellites':
                sample.satellites = parse_json(child)
            elif tag == 'apps_data':
                sample.apps_data = parse_json(child)
            else:
                set_attr(sample, tag, value)

        yield sample


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')

# Path: filters.py
# def radian_to_degree(value):
#     return math.degrees(value)
# 
# Path: model.py
# class Sample(db.Model):
#     __tablename__ = 'sample'
#     id = db.Column(db.Integer, name='id', primary_key=True)
# 
#     move_id = db.Column(db.Integer, db.ForeignKey(Move.id), name='move_id', nullable=False)
#     move = db.relationship(Move, backref=db.backref('samples', lazy='dynamic'))
# 
#     sample_type = db.Column(db.String, name='sample_type')
#     time = db.Column(db.Interval, name='time')
#     utc = db.Column(db.DateTime, name='utc')
# 
#     distance = db.Column(db.Float, name='distance')
#     speed = db.Column(db.Float, name='speed')
#     temperature = db.Column(db.Float, name='temperature')
# 
#     hr = db.Column(db.Float, name='hr')
#     energy_consumption = db.Column(db.Float, name='energy_consumption')
#     relative_performance_level = db.Column(db.Float, name='relative_performance_level')
# 
#     vertical_speed = db.Column(db.Float, name='vertical_speed')
#     sea_level_pressure = db.Column(db.Float, name='sea_level_pressure')
# 
#     gps_altitude = db.Column(db.Float, name='gps_altitude')
#     gps_heading = db.Column(db.Float, name='gps_heading')
#     gps_speed = db.Column(db.Float, name='gps_speed')
#     gps_hdop = db.Column(db.Float, name='gps_hdop')
# 
#     number_of_satellites = db.Column(db.Integer, name='number_of_satellites')
# 
#     latitude = db.Column(db.Float, name='latitude')
#     longitude = db.Column(db.Float, name='longitude')
# 
#     altitude = db.Column(db.Integer, name='altitude')
# 
#     ehpe = db.Column(db.Float, name='ehpe')  # Estimated Horizontal Position Error
# 
#     cadence = db.Column(db.Float, name='cadence')
# 
#     nav_type = db.Column(db.Integer, name='nav_type')
#     nav_valid = db.Column(db.String, name='nav_valid')
#     nav_type_explanation = db.Column(db.String, name='nav_type_explanation')
# 
#     events = db.Column(JsonEncodedDict(4096), name='events')
#     satellites = db.Column(JsonEncodedDict(4096), name='satellites')
#     apps_data = db.Column(JsonEncodedDict(4096), name='apps_data')


# Path: _import.py
from datetime import timedelta, datetime
from geopy.geocoders import Nominatim
from filters import radian_to_degree
from model import Sample
import re
import sqlalchemy

        for child in sample_node.iterchildren():
            tag = normalize_tag(child.tag)
            value = child.text

            if tag == 'events':
                sample.events = parse_json(child)
            elif tag == 'satellites':
                sample.satellites = parse_json(child)
            elif tag == 'apps_data':
                sample.apps_data = parse_json(child)
            else:
                set_attr(sample, tag, value)

        yield sample


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)