# Path: pytrainer/lib/gpx.py
# class Gpx:
#     def __init__(self, data_path = None, filename = None, trkname = None):
#     def getMaxValues(self):
#     def getDate(self):
#     def getTrackRoutes(self):
#     def getUnevenness(self):
#     def getTrackList(self):
#     def getHeartRateAverage(self):
#     def getCalories(self):
#     def getStart_time(self):
#     def getLaps(self):
#     def _getValues(self):
#     def _distance_between_points(self, lat1, lon1, lat2, lon2):
#     def _calculate_speed(self, dist_elapsed, time_elapsed, smoothing_factor=3):
#     def getStartTimeFromGPX(self, gpxFile):
#             JITTER_VALUE = 0  #Elevation changes less than this value are not counted in +-
#         RADIANS_PER_DEGREE = 0.01745329252
#         DEGREES_PER_RADIAN = 57.29577951
# 
# Path: pytrainer/upgrade/context.py
# UPGRADE_CONTEXT = None


from pytrainer.lib import gpx
from pytrainer.upgrade.context import UPGRADE_CONTEXT
from sqlalchemy.sql.expression import text
import logging
import os.path
import sqlalchemy
    import migrate.versioning.exceptions as ex1
    import migrate.changeset.exceptions as ex2

#       lap info added in version 1.9.0
def upgrade(migrate_engine=None):
    if migrate_engine is None:
        # sqlalchemy-migrate 0.5.4 does not provide migrate engine to upgrade scripts
        migrate_engine = sqlalchemy.create_engine(UPGRADE_CONTEXT.db_url)
    logging.info("Populating laps details columns")
    resultset = migrate_engine.execute(text("select distinct record from laps where intensity is null"))
    record_ids = []
    for row in resultset:
        record_ids.append(row["record"])
    resultset.close()
    for record_id in record_ids:
        gpx_file = UPGRADE_CONTEXT.conf_dir + "/gpx/{0}.gpx".format(record_id)
        if os.path.isfile(gpx_file):

# Path: pytrainer/lib/gpx.py
# class Gpx:
#     def __init__(self, data_path = None, filename = None, trkname = None):
#     def getMaxValues(self):
#     def getDate(self):
#     def getTrackRoutes(self):
#     def getUnevenness(self):
#     def getTrackList(self):
#     def getHeartRateAverage(self):
#     def getCalories(self):
#     def getStart_time(self):
#     def getLaps(self):
#     def _getValues(self):
#     def _distance_between_points(self, lat1, lon1, lat2, lon2):
#     def _calculate_speed(self, dist_elapsed, time_elapsed, smoothing_factor=3):
#     def getStartTimeFromGPX(self, gpxFile):
#             JITTER_VALUE = 0  #Elevation changes less than this value are not counted in +-
#         RADIANS_PER_DEGREE = 0.01745329252
#         DEGREES_PER_RADIAN = 57.29577951
# 
# Path: pytrainer/upgrade/context.py
# UPGRADE_CONTEXT = None


# Path: pytrainer/upgrade/versions/011_populate_lap_details.py
from pytrainer.lib import gpx
from pytrainer.upgrade.context import UPGRADE_CONTEXT
from sqlalchemy.sql.expression import text
import logging
import os.path
import sqlalchemy
    import migrate.versioning.exceptions as ex1
    import migrate.changeset.exceptions as ex2


#       lap info added in version 1.9.0
def upgrade(migrate_engine=None):
    if migrate_engine is None:
        # sqlalchemy-migrate 0.5.4 does not provide migrate engine to upgrade scripts
        migrate_engine = sqlalchemy.create_engine(UPGRADE_CONTEXT.db_url)
    logging.info("Populating laps details columns")
    resultset = migrate_engine.execute(text("select distinct record from laps where intensity is null"))
    record_ids = []
    for row in resultset:
        record_ids.append(row["record"])
    resultset.close()
    for record_id in record_ids:
        gpx_file = UPGRADE_CONTEXT.conf_dir + "/gpx/{0}.gpx".format(record_id)
        if os.path.isfile(gpx_file):

            gpx_record = gpx.Gpx(filename=gpx_file)