# Path: models.py
# class Point(Base):
#     __tablename__ = 'points'
#     __table_args__ = {'schema': 'mineturer'}
#     pid = Column('pid', Integer, primary_key=True)
#     geom = Column(Geometry(geometry_type='POINT', srid=4326))
#     time = Column('time', DateTime)
#     ele = Column('ele', Numeric)
#     hr = Column('hr', Numeric)
#     tripid = Column(Integer, ForeignKey('mineturer.trips.tripid'))
#     trip = relationship(Trip, primaryjoin=tripid == Trip.id)
# 
#     def __init__(self, trip=None, geom=None, time=None, ele=None, hr=None):
#         self.trip = trip
#         self.geom = from_shape(geom, srid=4326)
#         self.time = time
#         self.ele = ele
#         self.hr = hr
# 
#     def __repr__(self):
#         return '<Point %r>' % (self.pid)
# 
# Path: xml_code/gpx11.py
# def parseString(inString, silence=False):
#     from StringIO import StringIO
#     doc = parsexml_(StringIO(inString))
#     rootNode = doc.getroot()
#     rootTag, rootClass = get_root_tag(rootNode)
#     if rootClass is None:
#         rootTag = 'gpxType'
#         rootClass = gpxType
#     rootObj = rootClass.factory()
#     rootObj.build(rootNode)
#     # Enable Python to collect the space used by the DOM.
#     doc = None
#     if not silence:
#         sys.stdout.write('<?xml version="1.0" ?>\n')
#         rootObj.export(
#             sys.stdout, 0, name_=rootTag,
#             namespacedef_='')
#     return rootObj
# 
# Path: xml_code/gpx10.py
# def parseString(inString, silence=False):
#     from StringIO import StringIO
#     doc = parsexml_(StringIO(inString))
#     rootNode = doc.getroot()
#     rootTag, rootClass = get_root_tag(rootNode)
#     if rootClass is None:
#         rootTag = 'gpx'
#         rootClass = gpx
#     rootObj = rootClass.factory()
#     rootObj.build(rootNode)
#     # Enable Python to collect the space used by the DOM.
#     doc = None
#     if not silence:
#         sys.stdout.write('<?xml version="1.0" ?>\n')
#         rootObj.export(
#             sys.stdout, 0, name_=rootTag,
#             namespacedef_='xmlns:gpx="http://www.topografix.com/GPX/1/0"')
#     return rootObj


from shapely.geometry import Point
from models import Point as MTPoint
from xml_code.gpx11 import parseString as parse11
from xml_code.gpx10 import parseString as parse10
import xml.etree.ElementTree as ET
# -*- coding: utf-8 -*-




def parse_gpx_11(data):
    gpx = parse11(data, True)
    points = []
    for track in gpx.get_trk():
        for segment in track.get_trkseg():
            for track_point in segment.get_trkpt():
                points.append(MTPoint(
                    geom=Point(track_point.get_lon(), track_point.get_lat()),
                    time=track_point.get_time(),
                    ele=track_point.get_ele()
                ))
    return points


def parse_gpx_10(data):
    gpx = parse10(data, True)
    points = []
    for track in gpx.get_trk():
        for segment in track.get_trkseg():
            for track_point in segment.get_trkpt():

# Path: models.py
# class Point(Base):
#     __tablename__ = 'points'
#     __table_args__ = {'schema': 'mineturer'}
#     pid = Column('pid', Integer, primary_key=True)
#     geom = Column(Geometry(geometry_type='POINT', srid=4326))
#     time = Column('time', DateTime)
#     ele = Column('ele', Numeric)
#     hr = Column('hr', Numeric)
#     tripid = Column(Integer, ForeignKey('mineturer.trips.tripid'))
#     trip = relationship(Trip, primaryjoin=tripid == Trip.id)
# 
#     def __init__(self, trip=None, geom=None, time=None, ele=None, hr=None):
#         self.trip = trip
#         self.geom = from_shape(geom, srid=4326)
#         self.time = time
#         self.ele = ele
#         self.hr = hr
# 
#     def __repr__(self):
#         return '<Point %r>' % (self.pid)
# 
# Path: xml_code/gpx11.py
# def parseString(inString, silence=False):
#     from StringIO import StringIO
#     doc = parsexml_(StringIO(inString))
#     rootNode = doc.getroot()
#     rootTag, rootClass = get_root_tag(rootNode)
#     if rootClass is None:
#         rootTag = 'gpxType'
#         rootClass = gpxType
#     rootObj = rootClass.factory()
#     rootObj.build(rootNode)
#     # Enable Python to collect the space used by the DOM.
#     doc = None
#     if not silence:
#         sys.stdout.write('<?xml version="1.0" ?>\n')
#         rootObj.export(
#             sys.stdout, 0, name_=rootTag,
#             namespacedef_='')
#     return rootObj
# 
# Path: xml_code/gpx10.py
# def parseString(inString, silence=False):
#     from StringIO import StringIO
#     doc = parsexml_(StringIO(inString))
#     rootNode = doc.getroot()
#     rootTag, rootClass = get_root_tag(rootNode)
#     if rootClass is None:
#         rootTag = 'gpx'
#         rootClass = gpx
#     rootObj = rootClass.factory()
#     rootObj.build(rootNode)
#     # Enable Python to collect the space used by the DOM.
#     doc = None
#     if not silence:
#         sys.stdout.write('<?xml version="1.0" ?>\n')
#         rootObj.export(
#             sys.stdout, 0, name_=rootTag,
#             namespacedef_='xmlns:gpx="http://www.topografix.com/GPX/1/0"')
#     return rootObj


# Path: parse_gpx.py
from shapely.geometry import Point
from models import Point as MTPoint
from xml_code.gpx11 import parseString as parse11
from xml_code.gpx10 import parseString as parse10
import xml.etree.ElementTree as ET

# -*- coding: utf-8 -*-




def parse_gpx_11(data):
    gpx = parse11(data, True)
    points = []
    for track in gpx.get_trk():
        for segment in track.get_trkseg():
            for track_point in segment.get_trkpt():
                points.append(MTPoint(
                    geom=Point(track_point.get_lon(), track_point.get_lat()),
                    time=track_point.get_time(),
                    ele=track_point.get_ele()
                ))
    return points


def parse_gpx_10(data):
    gpx = parse10(data, True)
    points = []
    for track in gpx.get_trk():
        for segment in track.get_trkseg():
            for track_point in segment.get_trkpt():

                points.append(MTPoint(