예제 #1
0
def getDBwaypoints(usertid, lat_min, lat_max, lon_min, lon_max):

    waypoints = []

    lat_min = float(lat_min)
    lat_max = float(lat_max)
    lon_min = float(lon_min)
    lon_max = float(lon_max)

    dbconn()
    query = Waypoint.select().where((Waypoint.lat >= lat_min)
                                    & (Waypoint.lat <= lat_max)
                                    & (Waypoint.lon >= lon_min)
                                    & (Waypoint.lon <= lon_max))

    for q in query:

        if q.rad is None:
            continue

        wp = {
            'lat': float(q.lat),
            'lon': float(q.lon),
            'name': q.waypoint,
            'rad': q.rad,
        }
        waypoints.append(wp)

    return waypoints
예제 #2
0
파일: pista.py 프로젝트: dhozac/pista
def getDBwaypoints(usertid, lat_min, lat_max, lon_min, lon_max):

    waypoints = []

    lat_min = float(lat_min)
    lat_max = float(lat_max)
    lon_min = float(lon_min)
    lon_max = float(lon_max)

    dbconn()
    query = Waypoint.select().where(
                    (Waypoint.lat >= lat_min) &
                    (Waypoint.lat <= lat_max) &
                    (Waypoint.lon >= lon_min) &
                    (Waypoint.lon <= lon_max)
                )

    for q in query:

        if q.rad is None:
            continue

        wp = {
            'lat'  : float(q.lat),
            'lon'  : float(q.lon),
            'name' : q.waypoint,
            'rad'  : q.rad,
        }
        waypoints.append(wp)

    return waypoints
예제 #3
0
파일: waypoints.py 프로젝트: padelt/pista
    def load_waypoints(self):

        wplist = []
        for w in Waypoint.select():
            try:
                lat     = float(w.lat)
                lon     = float(w.lon)
                meters  = int(w.rad)
                desc    = w.waypoint
                wptopic   = w.topic.replace('/waypoints', '')

                if meters == 0:
                    continue

                onepoint = WayPoint(lat, lon, meters, desc)
                wplist.append(onepoint)
                log.debug("Loading {0}".format(onepoint))

                if self.maptopic:
                    fence_data = {
                        '_type'    : 'fence',
                        'lat'      : lat,
                        'lon'      : lon,
                        'radius'   : meters,
                        'waypoint' : desc,
                    }
                    # I need a "key" to publish to maptopic so that one waypoint
                    # doesn't clobber the previous if both were originally to 
                    # same topic.

                    unique = "{0}-{1}-{2}".format(wptopic, lat, lon)
                    hash_object = hashlib.sha1(unique)
                    unique_sha = hash_object.hexdigest()

                    try:
                        # fence_topic = self.maptopic + "/" + unique_sha
                        fence_topic = self.maptopic.format(wptopic) + "/" + unique_sha
                        self.mosq.publish(fence_topic, json.dumps(fence_data), qos=0, retain=True)
                        log.debug("FENCE: {0} -> {1}".format(fence_topic, json.dumps(fence_data)))
                    except Exception, e:
                        log.warn("Cannot publish fence: {0}".format(str(e)))
            except:
                pass

        return wplist