Esempio n. 1
0
def createPlace(bar, metro_index):
    if  not 'neighborhoods' in bar['location'] or not 'categories' in bar:
        return   
    lat = bar['location']['coordinate']['latitude']
    lng = bar['location']['coordinate']['longitude']
    neighborhood = bar['location']['neighborhoods'][0]
    bar_categories = map(lambda value:value[0], bar['categories'])
    rating = determineRating(bar['rating_img_url'])
    weight = rating
    the_range = 5.

    if (not neighborhood in neighborhoods.inv_neighborhood_list):
        neighborhood_index = -1
        # logging.warn('Dumping neighborhood: %s' % neighborhood)
        # return
    else:
        neighborhood_index = neighborhoods.inv_neighborhood_list[neighborhood]
    for category in bar_categories:
        if (category in categories.inv_category_list):
            category_index = categories.inv_category_list[category]
            new_data = DataPoint(location=db.GeoPt(float(lat), float(lng)),
                        time=datetime.datetime.now(),
                        weight=weight,
                        range=the_range,
                        category = category_index,
                        neighborhood = neighborhood_index,
                        url = bar['url'],
                        rating = rating,
                        placeName = bar['name'],
                        metro = metro_index)
#            logging.info('Adding name: %s, category: %s, metro: %s' % (bar['name'], getCategory(category_index), getMetro(metro_index)))
            new_data.update_location()
            new_data.put()
Esempio n. 2
0
 def get_data(self, zoom, layer, lat_north, lng_west, range_lat, range_lng):
   log.info("GeoRange: (%6.4f, %6.4f) ZoomStep: (%6.4f, %6.4f)" % (lat_north, lng_west, range_lat, range_lng))
   log.info("Range: (%6.4f - %6.4f), (%6.4f - %6.4f)" % (min(90, max(-90, lat_north + range_lat)), lat_north, min(180, max(-180, lng_west + range_lng)), lng_west))
   return DataPoint.bounding_box_fetch(
       DataPoint.all(),
       geotypes.Box(min(90, max(-90, lat_north + range_lat)),
           min(180, max(-180, lng_west + range_lng)),
           lat_north,
           lng_west),
       max_results=1000, )
Esempio n. 3
0
 def get_data(self, zoom, layer, lat_north, lng_west, range_lat, range_lng,
              category, metro):
     log.info("GeoRange: (%6.4f, %6.4f) ZoomStep: (%6.4f, %6.4f)" %
              (lat_north, lng_west, range_lat, range_lng))
     log.info("Range: (%6.4f - %6.4f), (%6.4f - %6.4f)" %
              (min(90, max(-90, lat_north + range_lat)), lat_north,
               min(180, max(-180, lng_west + range_lng)), lng_west))
     return DataPoint.bounding_box_fetch(
         DataPoint.all().filter('category',
                                category).filter('metro', metro),
         geotypes.Box(min(90, max(-90, lat_north + range_lat)),
                      min(180, max(-180, lng_west + range_lng)), lat_north,
                      lng_west),
         max_results=1000)
Esempio n. 4
0
    def get(self):
        from google.appengine.ext import db
        from gheatae.point import DataPoint
        from google.appengine.ext.db import GeoPt

        dps = DataPoint.all();
        for dp in dps:
            dp.delete()
Esempio n. 5
0
def createPlace(bar, metro_index):
    if not 'neighborhoods' in bar['location'] or not 'categories' in bar:
        return
    lat = bar['location']['coordinate']['latitude']
    lng = bar['location']['coordinate']['longitude']
    neighborhood = bar['location']['neighborhoods'][0]
    bar_categories = map(lambda value: value[0], bar['categories'])
    rating = determineRating(bar['rating_img_url'])
    weight = rating
    the_range = 5.

    if (not neighborhood in neighborhoods.inv_neighborhood_list):
        neighborhood_index = -1
        # logging.warn('Dumping neighborhood: %s' % neighborhood)
        # return
    else:
        neighborhood_index = neighborhoods.inv_neighborhood_list[neighborhood]
    for category in bar_categories:
        if (category in categories.inv_category_list):
            category_index = categories.inv_category_list[category]
            new_data = DataPoint(location=db.GeoPt(float(lat), float(lng)),
                                 time=datetime.datetime.now(),
                                 weight=weight,
                                 range=the_range,
                                 category=category_index,
                                 neighborhood=neighborhood_index,
                                 url=bar['url'],
                                 rating=rating,
                                 placeName=bar['name'],
                                 metro=metro_index)
            #            logging.info('Adding name: %s, category: %s, metro: %s' % (bar['name'], getCategory(category_index), getMetro(metro_index)))
            new_data.update_location()
            new_data.put()
Esempio n. 6
0
    def get_data(self, zoom, layer, **extras):
        """
    Extras will contain these keys:
        - lat_north: The north-most latitude of the bounding box
        - lng_west: The west-most longitude of the bounding box
        - range_lat: The range of the bounding box latitude
        - range_lng: The range of the bounding box longitude
    """
        lat_north = extras["lat_north"]
        lng_west = extras["lng_west"]
        range_lat = extras["range_lat"]
        range_lng = extras["range_lng"]

        # log.info("GeoRange: (%6.4f, %6.4f) ZoomStep: (%6.4f, %6.4f)" % (lat_north, lng_west, range_lat, range_lng))
        # log.info("Range: (%6.4f - %6.4f), (%6.4f - %6.4f)" % (min(90, max(-90, lat_north + range_lat)), lat_north, min(180, max(-180, lng_west + range_lng)), lng_west))

        return DataPoint.bounding_box_fetch(
            DataPoint.all(),
            geotypes.Box(
                min(90, max(-90, lat_north + range_lat)), min(180, max(-180, lng_west + range_lng)), lat_north, lng_west
            ),
            max_results=1000,
        )
Esempio n. 7
0
                assert cmd in ('add', 'del',
                               'upd'), "'%s' invalid command" % cmd
                assert float(lat), "lat invalid"
                assert float(lng), "lng invalid"
                assert datetime.datetime.fromtimestamp(
                    int(timeOccured)), "time invalid"
                assert int(weight), "weight invalid"
                assert int(range), "weight invalid"
            except AssertionError, err:
                log.error(err.args[0])
                self.respondError(err)
                return
        else:
            self.respondError("Invalid path")
            return

        self.response.headers['Content-Type'] = "text/plain"
        if cmd == "add":
            # Actually add the data specified
            new_data = DataPoint(location=db.GeoPt(float(lat), float(lng)),
                                 time=datetime.datetime.fromtimestamp(
                                     int(timeOccured)),
                                 weight=int(weight),
                                 range=int(range))
            new_data.update_location()
            new_data.put()
            log.info("Data Stored")
            self.response.out.write("Data Stored")

        log.info("Start-End: %2.2f" % (time.clock() - st))
Esempio n. 8
0
      try:
        assert raw.count('/') == 7, "%d /'s" % raw.count('/')
        foo, bar, cmd, lat, lng, timeOccured, weight, range = raw.split('/')
        assert cmd in ('add', 'del', 'upd'), "'%s' invalid command" % cmd
        assert float(lat), "lat invalid"
        assert float(lng), "lng invalid"
        assert datetime.datetime.fromtimestamp(int(timeOccured)), "time invalid"
        assert int(weight), "weight invalid"
        assert int(range), "weight invalid"
      except AssertionError, err:
        log.error(err.args[0])
        self.respondError(err)
        return
    else:
      self.respondError("Invalid path")
      return

    self.response.headers['Content-Type'] = "text/plain"
    if cmd == "add":
      # Actually add the data specified
      new_data = DataPoint(location=db.GeoPt(float(lat), float(lng)),
                           time=datetime.datetime.fromtimestamp(int(timeOccured)),
                           weight=int(weight),
                           range=int(range))
      new_data.update_location()
      new_data.put()
      log.info("Data Stored")
      self.response.out.write("Data Stored")

    log.info("Start-End: %2.2f" % (time.clock() - st))
Esempio n. 9
0
 def get_data(self, zoom, layer, x, y):
     return [
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
         DataPoint(location=GeoPt(37.2344, 82.34)),
     ]