Ejemplo 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()
Ejemplo n.º 2
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()
Ejemplo n.º 3
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))
Ejemplo n.º 4
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))