예제 #1
0
def test_location_search():
  num_correct = 0
  num_wrong = 0
  num_invalid = 0
  wrong_locs = []
  counter = 1

  events_cursor = events_fb_collection.find({}, {'_id': False})
  if events_cursor.count() > 0:
    for event in events_cursor:
      print("~~~~~~~ " + str(counter) + " ~~~~~~~" + " WR: " + str(num_wrong))
      counter = counter + 1
      if 'place' in event and 'location' in event['place']:
        loc = get_location_search_result(event['place']['name'])
        if loc != "There were no results!":
          # Latitude and longitude are significant to the 4th digit, but 3rd to be safe
          event_lat = event['place']['location'].get('latitude', 420)
          event_long = event['place']['location'].get('longitude', 420)
          lat_diff = abs(loc['latitude'] - event_lat)
          long_diff = abs(loc['longitude'] - event_long)
          if lat_diff < 0.0015 and long_diff < 0.0015:
            print("Correct")
            num_correct = num_correct + 1
          else:
            print("Wrong")
            num_wrong = num_wrong + 1
            wrong_locs.append({
              "event": {
                "place_name": event['place']['name'], 
                "place_latitude": event['place']['location'].get('latitude', 420),
                "place_longitude": event['place']['location'].get('longitude', 420)
              },
              "loc": {
                "loc_name": loc['name'],
                "loc_alt_names": loc['alternative_names'],
                "loc_latitude": loc['latitude'],
                "loc_longitude": loc['longitude']
              }
            }) 
        else:
          print("Invalid Loc")
          num_invalid = num_invalid + 1
          wrong_locs.append({
              "event": {
                "place_name": event['place']['name'], 
                "place_latitude": event['place']['location'].get('latitude', 420),
                "place_longitude": event['place']['location'].get('longitude', 420)
              },
              "loc": "NONE"
            }) 
  else:
      print('Cannot find any events!')

  # Output typically contains name, city, country, latitude, longitude, state, 
  # street, and zip for each location
  return jsonify({'num_correct': num_correct, 'num_wrong': num_wrong, 'num_invalid': num_invalid, 'wrong_locs': wrong_locs})
예제 #2
0
def filter_by_popular(search_dict, threshold=50):
    # Sort events by # of interested
    sorted_events = []
    events_cursor = events_fb_collection.find(search_dict).sort(
        'interested_count', -1)

    if events_cursor.count() > 0:
        print("filter_by_popular with threshold {0}".format(threshold))
        for event in events_cursor:
            processed_event = event_utils.process_event_info(event)
            if processed_event['properties']['stats'].get(
                    'attending', 0
            ) >= threshold or processed_event['properties']['stats'].get(
                    'interested', 0) >= threshold:
                sorted_events.append(processed_event)
    else:
        print('No events found with attributes: {\'start_time\': date_regex}')

    return sorted_events
def gatherCategorizedEvents():
    """:Description: Return panda dataframe of events with category, description, and name"""
    allCategorizedEvents = []
    allEvents = events_fb_collection.find({}, {
        "category": 1,
        "description": 1,
        "name": 1,
        "hoster": 1,
        "_id": 0
    })
    count = 0
    for e in allEvents:
        count += 1
        e['hoster'] = e['hoster']['name']
        if 'category' in e and 'description' in e and 'name' in e:
            allCategorizedEvents.append(e)
    modernEvents = reduceCategories(allCategorizedEvents)
    print(count, "total events, learning from the", len(modernEvents),
          "well categorized events")
    return pd.DataFrame(modernEvents)
예제 #4
0
def get_locations_from_collection():
    # Iterate through all events and get list of unique venues
    places = []

    # Every time there are new events, check location info and update db if necessary
    events_cursor = events_fb_collection.find({"place": {"$exists": True}})

    if not events_cursor or events_cursor.count() <= 0:
        return 'Cannot find any events with locations!'

    for event in events_cursor:
        place = {}

        # Add location info to place dict
        if 'location' in event['place']:
            place['location'] = event['place']['location']
        if 'name' in event['place']:
            place['location']['name'] = event['place']['name']

        place = location_processor.process_event_location_info(place, places)

    return places