def get_raw_score_for_place(place_id: str):
    dm = PlaceDataManager()
    place = dm.find_one_place_by_id(place_id)
    if place is None:
        return 0
    refresh_score_for_entity(place, place_senti_lifetime_in_days)
    return place['senti_score']
Example #2
0
def create_place():
    dm = PlaceDataManager()
    # request should be {'name': 'p1', 'senti_socre': '5.2' .....}
    decoded_json = request.get_data().decode("utf-8")
    posted_dict = json.loads(decoded_json)
    dm.insert_one_place(posted_dict)
    action_handler.generate_dynamic_score_for_place(posted_dict)
    return json.dumps(posted_dict)
Example #3
0
def search_place():
    filter = search_parameter_to_db_filter(request.args)
    dm = PlaceDataManager()
    print('filtering by' + filter.__str__())
    place_dicts = dm.find_places_by_filter(filter)
    for place in place_dicts:
        action_handler.generate_dynamic_score_for_place(place)

    return json.dumps({'places': place_dicts})
Example #4
0
def insert_events_and_places():
    #create data managers
    em = EventDataManager()
    pm = PlaceDataManager()
    glennen = pm.create_empty_place()
    glennen['name'] = 'Yost'
    glennen['type'] = 'StudyLocation'
    glennen['geo_coordinates'] = Point((123, 45.2))
    glennen['senti_score'] = 400
    glennen['rating_average'] = 0
    pm.insert_one_place(glennen)
Example #5
0
def replace_one_place():
    dm = PlaceDataManager()
    # request should be {"name": 'e1', 'senti_socre': '5.2' .....}
    decoded_json = request.get_data().decode("utf-8")
    posted_dict = json.loads(decoded_json)
    place_id = posted_dict['place_id']
    if not place_id.__contains__('pl-'):
        raise Exception('invalid input')
    place = dm.replace_one_place(posted_dict)
    action_handler.generate_dynamic_score_for_place(place)
    return json.dumps(place)
def test():
    location = 'Tomlinson'
    location = sanitize_location(location)
    place = PlaceDataManager().find_one_by_filter(
        {'name': common.generate_search_query(location)})
    print(place)
    print(reply_for_place(place))
Example #7
0
def update_place(place_id: str):
    if not place_id.__contains__('pl-'):
        raise Exception('invalid input')
    dm = PlaceDataManager()
    # update request should be {"updates": [{"key":"some_key", "new_value","some_value"},  ... ]}
    decoded_json = request.get_data().decode("utf-8")
    posted_dict = json.loads(decoded_json)
    updates = posted_dict['updates']
    # each update
    for update in updates:
        key = update['key']
        new_value = update['new_value']
        dm.update_one_place(place_id=place_id, key=key, new_val=new_value)
    place = dm.find_one_place_by_id(place_id)
    action_handler.generate_dynamic_score_for_place(place)
    return json.dumps(place)
def on_message_received_for_place(place_id: str, message: dict):
    dm = PlaceDataManager()
    place = dm.find_one_place_by_id(place_id)
    precondition_check_for_required_keys(entity=place,
                                         required_keys=[
                                             'senti_score',
                                             'senti_score_updated_time',
                                             'mood_tag_counter'
                                         ])

    refresh_score_for_entity(entity=place,
                             lifetime_in_days=place_senti_lifetime_in_days)
    if message['type'] == 'rating' or message['type'] == 'review':
        on_rating_received(place, message)
    if message['type'] != 'rating':
        on_message_received(place, message)
    dm.replace_one_place(place)
Example #9
0
def find_location_and_place(data_object):
    location = data_object['result']['parameters']['location']
    location = sanitize_location(location)
    place = PlaceDataManager().find_one_by_filter({'name': common.generate_search_query(location)})
    # place = {'name': "Tomlinson Food Court",
    #          'rating_average': 3.3,
    #          'senti_score': 16,
    #          'coordinate': {"type": "Point",
    #                         "coordinates": [100.0, 0.0]}
    #          }
    return location, place
def get_dynamic_score_for_geolocation(long: float,
                                      lat: float,
                                      radius: float = 1000):
    nearby_events = edm.find_events_near(long=long, lat=lat, radius=radius)
    nearby_events_score = aggregate_raw_score_from_entities_distance_based(
        nearby_events, event_senti_lifetime_in_days, long, lat, radius)

    nearby_places = PlaceDataManager().find_places_near(long=long,
                                                        lat=lat,
                                                        radius=radius)
    nearby_places_score = aggregate_raw_score_from_entities_distance_based(
        nearby_places, place_senti_lifetime_in_days, long, lat, radius)
    dynamic_score = nearby_places_score + nearby_events_score
    return dynamic_score
def create_all_restaurants():
    pm = PlaceDataManager()
    qdoba = create_qdoba()
    potbelly = create_potbelly()
    jimmyjohns = create_jimmy_johns()
    kenkos = create_kenkos()
    panera = create_panera_bread()
    chipotle = create_chipotle()
    pm.insert_one_place(qdoba)
    pm.insert_one_place(potbelly)
    pm.insert_one_place(jimmyjohns)
    pm.insert_one_place(kenkos)
    pm.insert_one_place(panera)
    pm.insert_one_place(chipotle)
    pm.insert_one_place(create_pacific_east())
Example #12
0
def get_one_place(place_id: str):
    place = PlaceDataManager().find_one_place_by_id(place_id)
    action_handler.generate_dynamic_score_for_place(place)
    return json.dumps(place)
Example #13
0
def create_campus_buildings_and_events():
    pm = PlaceDataManager()
    yost = cb_and_sl.create_yost()
    strosacker = cb_and_sl.create_strosacker()
    nord = cb_and_sl.create_nord()
    white = cb_and_sl.create_white()
    glennan = cb_and_sl.create_glennan()
    bingham = cb_and_sl.create_bingham()
    tink = cb_and_sl.create_tink()
    thwing = cb_and_sl.create_thwing()
    veale = cb_and_sl.create_veale()
    pm.insert_one_place(yost)
    pm.insert_one_place(strosacker)
    pm.insert_one_place(nord)
    pm.insert_one_place(white)
    pm.insert_one_place(glennan)
    pm.insert_one_place(bingham)
    pm.insert_one_place(tink)
    pm.insert_one_place(veale)

    em = EventDataManager()
    cs_presentation = create_cs_presentation(white)
    bio_pres = create_bio_presentation(bingham)
    basketball = create_basketball_game(veale)
    lect = create_lecture(strosacker)
    undergrad = create_undergrad(tink)
    karaoke = create_karaoke(thwing)
    em.insert_event_one(cs_presentation)
    em.insert_event_one(bio_pres)
    em.insert_event_one(basketball)
    em.insert_event_one(lect)
    em.insert_event_one(undergrad)
    em.insert_event_one(karaoke)
Example #14
0
def generatePlaces():
    pm = PlaceDataManager()
    nord = pm.insert_one_place(place_nord_dict)
    olin = pm.insert_one_place(place_olin_dict)
    white = pm.insert_one_place(place_white_dict)
    smith = pm.insert_one_place(place_smith_dict)
Example #15
0
def insert():
    place_proto = places_data_manager.min_place_dict
    event_proto = event_data_manager.min_event_dict

    white = place_proto.copy()
    white['name'] = 'White Building at CWRU'
    white['senti_score'] = 8
    white['rating_average'] = 2.8
    white['rating_count'] = 6
    white['geo_coordinates'] = Point((100.003, 10))

    tink = place_proto.copy()
    tink['name'] = 'Tinkham Veale University Center'
    tink['senti_score'] = 2
    tink['rating_average'] = 4.20
    tink['rating_count'] = 7
    tink['geo_coordinates'] = Point((100.001, 10.001))

    tomlinson = place_proto.copy()
    tomlinson['name'] = 'Tomlinson Food Court'
    tomlinson['senti_score'] = -6
    tomlinson['rating_average'] = 2.1
    tomlinson['rating_count'] = 12
    tomlinson['geo_coordinates'] = Point((100.002, 10))

    melt = place_proto.copy()
    melt['name'] = 'Melt University'
    melt['senti_score'] = 2
    melt['rating_average'] = 0
    melt['rating_count'] = 0
    melt['geo_coordinates'] = Point((100.0011, 10.001))

    pdm = PlaceDataManager()
    edm = EventDataManager()
    pdm.insert_one_place(white)
    pdm.insert_one_place(tink)
    pdm.insert_one_place(tomlinson)
    pdm.insert_one_place(melt)

    ece = event_proto.copy()
    ece['name'] = 'Electrical and computer engineering senior project presentations'
    ece['description'] = 'People from the EE and CE departments presenting their stuff'
    ece['senti_score'] = 2
    ece['place_id'] = white['place_id']
    ece['location'] = 'white'
    ece['geo_coordinates'] = Point((100.003, 10.0003))

    cmp = event_proto.copy()
    cmp['name'] = 'Computer science senior project presentations Day 2'
    cmp['description'] = 'our project, Evention is presenting at this event'
    cmp['senti_score'] = 15
    cmp['place_id'] = white['place_id']
    cmp['location'] = 'white'
    cmp['geo_coordinates'] = Point((100.0032, 10.0001))

    food_week = event_proto.copy()
    food_week[
        'name'] = 'Bon Appetit International Week Gourmet and Wine Tasting'
    food_week[
        'description'] = 'Enjoy great food from Bon Appetit that comes from all over' \
                         ' the world. Absolutely amazing food. Note that Meal swipes ' \
                         'cannot be used to enjoy this food.'
    food_week['senti_score'] = -7
    food_week['place_id'] = tomlinson['place_id']
    food_week['location'] = 'Tomlinson'
    food_week['geo_coordinates'] = Point((100.0021, 10.0004))

    edm.insert_event_one(ece)
    edm.insert_event_one(cmp)
    edm.insert_event_one(food_week)
Example #16
0
def create_all_cb_and_sl():
    pm = PlaceDataManager()
    yost = create_yost()
    strosacker = create_strosacker()
    nord = create_nord()
    white = create_white()
    glennan = create_glennan()
    bingham = create_bingham()
    tink = create_tink()
    thwing = create_thwing()
    veale = create_veale()
    pm.insert_one_place(yost)
    pm.insert_one_place(strosacker)
    pm.insert_one_place(nord)
    pm.insert_one_place(white)
    pm.insert_one_place(glennan)
    pm.insert_one_place(bingham)
    pm.insert_one_place(tink)
    pm.insert_one_place(veale)
    ksl = create_ksl()
    glennan_lounge = create_glennan_lounge()
    b_lounge = create_bingham_lounge()
    wade = create_wade_commons()
    pm.insert_one_place(ksl)
    pm.insert_one_place(glennan_lounge)
    pm.insert_one_place(b_lounge)
    pm.insert_one_place(wade)
from app.data_managers.places_data_manager import PlaceDataManager
from app.data_managers.event_data_manager import EventDataManager
from app.sentiment import emotion
from geopy.distance import great_circle
from multiprocessing import Pool
import functools

import geojson
'''this file handles the bottom layer that adds comment-senti-score to raw scores for entities'''
'''this is lifetime, 'tao', in millisecond'''
event_senti_lifetime_in_days = 2
place_senti_lifetime_in_days = 5
delete_threshold = 0.02
seconds_per_day = 86400
edm = EventDataManager()
pdm = PlaceDataManager()
'''calculate dynamic score for entities'''


def generate_dynamic_score_for_event(event: dict, radius: float = 1000):
    event['dynamic_senti_score'] = event['senti_score']
    if 'place_id' in event and event['place_id'] != '':
        place_score = get_raw_score_for_place(event['place_id'])
    else:
        place_score = 0

    if 'geo_coordinates' in event and event['geo_coordinates'] != geojson.Point(
        (0, 0)):
        nearby_events = EventDataManager().find_events_near(
            long=event['geo_coordinates']['coordinates'][0],
            lat=event['geo_coordinates']['coordinates'][1],