Exemple #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
Exemple #2
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
Exemple #3
0
    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