Exemple #1
0
 def test_creation(self):
     t1 = Trail()
     t1.name = "Testtrail1"
     t1.owner = User.objects.get(pk=1)
     t1.waypoints = MultiLineString(
         LineString(
             (48.75118072, 8.539638519, 712),
             (48.75176078, 8.541011810, 696),
             (48.75133635, 8.545153141, 556),
             (48.75067140, 8.545582294, 531),
         )
     )
     t1.save()
     self.assertIsNotNone(t1.created, "timestamp has not been added automatically")
     self.assertIsNotNone(t1.edited, "timestamp has not been added automatically")
     t1.name = "Testtrail"
     t1.save()
     self.assertGreater(t1.edited, t1.created, "edited timestamp was not updated after save operation")
 def testRelationships(self):
     res = Resort()
     res.name = "Test Resort"
     res.id = 123
     trail = Trail()
     trail.name = "Test Trail"
     trail.id = 222
     photo = Photo()
     photo.name = "Test Trail photo"
     photo.id = 222
     photo.trail = trail
     trail.photos.append(photo)
     res.trails.append(trail)
     res.photos.append(photo)
     self.acc.insertData([res])
     self.assertEqual(self.acc.queryResort(123).name, "Test Resort")
     self.assertEqual(
         self.acc.queryResort(123).trails[0].name, "Test Trail")
     self.assertEqual(
         self.acc.queryResort(123).photos[0].name, "Test Trail photo")
     self.assertEqual(
         self.acc.queryTrail(222).photos[0].name, "Test Trail photo")
 def testInsertMerge2(self):
     res = Resort()
     res.name = "Test Insert Resort"
     res.id = 2
     t1 = Trail()
     t1.id = 1
     t2 = Trail()
     t2.id = 1
     res.trails.append(t1)
     res.trails.append(t2)
     self.acc.insertData([res])
     self.assertIsNone(self.acc.queryResort(2))
Exemple #4
0
    def test_import(self):
        """
        Uses the load module to read gpx data, which contains long, lat and altitude
        """
        path = os.path.dirname(__file__)
        gpx_file = os.path.join(path, "data/BadWildbad.gpx")
        self.assertTrue(os.path.exists(gpx_file))
        ls = GPXReader(gpx_file)
        self.assertIsNotNone(ls.to_linestring())

        t1 = Trail()
        t1.name = "Testtrail GPX"
        t1.owner = User.objects.get(pk=1)
        t1.waypoints = ls.to_linestring()
        t1.save()
        self.assertIsNotNone(t1.created, "timestamp has not been added automatically")
        self.assertIsNotNone(t1.edited, "timestamp has not been added automatically")
 def testQueryTrail(self):
     trail = Trail()
     trail.name = "Test Query Trail"
     trail.id = 50
     self.acc.insertData([trail])
     self.assertEqual(self.acc.queryTrail(50).name, "Test Query Trail")
Exemple #6
0
from app import db
from models import Trail, User, Comment
import json
import os


# load geojson data into a dict
file = os.path.join('static', 'trailheadsjson.geojson')
with open(file) as data:
    geo = json.load(data)


# create objects for insertion into database
for feature in geo['features']:
    trail = Trail(trailname=feature['properties']['PrimaryName'],
                  use=feature['properties']['Comments'])
    db.session.add(trail)
    db.session.commit()
db.create_all()
Exemple #7
0
def createtrail(t, ytdata):
    trail = Trail(name=t['name'], id=t['id'])
    trail.difficulty = t['difficulty']
    trail.summary = t['summary']
    trail.stars = t['stars']
    trail.starVotes = t['starVotes']
    trail.lat = t['latitude']
    trail.lon = t['longitude']
    trail.length = t['length']
    trail.ascent = t['ascent']
    trail.descent = t['descent']
    trail.img = t['imgMedium']
    trail.youtubeid = ytdata['items'][0]['id']['videoId']
    return trail
Exemple #8
0
def getTrails(lon, lat, cnt, resort, trails):
    """
    gets all trails nearby given lat and long
    associates all created trails with resortid
    """
    data = None
    try:
        if resort is None:
            data = fetch.fetchJSON(
                'https://www.hikingproject.com/data/get-trails?lat=' +
                str(lat) + '&lon=' + str(lon) + '&maxDistance=10&maxResults=' +
                str(cnt) +
                '&sort=distance&key=200217902-4d9f4e11973eb6aa502e868e55361062'
            )
        else:
            data = fetch.fetchJSON(
                'https://www.hikingproject.com/data/get-trails?lat=' +
                str(resort.lat) + '&lon=' + str(resort.lon) +
                '&maxDistance=10&maxResults=' + str(cnt) +
                '&sort=distance&key=200217902-4d9f4e11973eb6aa502e868e55361062'
            )
    except ValueError as e:
        return trails
    for t in data['trails']:
        if t['id'] not in trails:
            trail = Trail(name=t['name'], id=t['id'])
            trail.difficulty = t['difficulty'] if 'difficulty' in t else None
            trail.summary = t['summary'] if 'summary' in t else None
            trail.stars = t['stars'] if 'stars' in t else None
            trail.starVotes = t['starVotes'] if 'starVotes' in t else None
            trail.lat = t['latitude'] if 'latitude' in t else None
            trail.lon = t['longitude'] if 'longitude' in t else None
            trail.length = t['length'] if 'length' in t else None
            trail.ascent = t['ascent'] if 'ascent' in t else None
            trail.descent = t['descent'] if 'descent' in t else None
            try:
                youtubedata = fetch.fetchJSON(
                    'https://www.googleapis.com/youtube/v3/search?q=' +
                    trail.name + ' trail' +
                    '&part=snippet&type=video&maxResults=25&key=AIzaSyDRwflQaI1Zq5bqKVQJ2YBDHb7l7oD1L2o'
                )
                trail.youtubeid = youtubedata['items'][0]['id']['videoId']
            except ValueError:
                trail.youtubeid = None
            except IndexError:
                trail.youtubeid = None
            trails[t['id']] = trail
        resort.trails.append(trails[t['id']])
    return trails