コード例 #1
0
def direct_competitor_similarity(active_restaurant_id, selected_restaurant_id):
    # Get active restaurant info for other routines
    active_restaurant_profile_df = algorithm.restaurant_profile(
        active_restaurant_id)
    #restaurant_profile = active_restaurant_profile_df.astype(str)                   # Issue #7
    #restaurant_profile = active_restaurant_profile_df

    # Get first/second order nodes for graph
    active_like_restaurants_df = algorithm.like_restaurants(
        active_restaurant_id, competitor_limit)

    # Pull off details on selected direct competitor similarity for upper right window
    restaurant_similarity = active_like_restaurants_df[
        active_like_restaurants_df['restaurant_id'] == selected_restaurant_id][
            [
                'shared_val', 'shared_score', 'overlap_val', 'overlap_score',
                'review_sim_val', 'review_sim_score', 'rate_sim_val',
                'rate_sim_score', 'zip_val', 'zip_score', 'compete_score'
            ]]

    # Get third order nodes for graph
    customer_prospects_df = algorithm.customer_prospects(
        active_like_restaurants_df, prospect_limit)

    # Transform graph info into nodes and links lists
    restaurant_graph_dict = algorithm.restaurant_graph(
        active_restaurant_id, active_restaurant_profile_df,
        active_like_restaurants_df, customer_prospects_df)

    # Get info for comparison bar graph
    nodes = restaurant_graph_dict[
        'nodes']  # Call these nodes and nodes_comparison
    nodes_comparison = nodes[nodes['order'] == 2][['name', 'score']]
    nodes_comparison.sort_values(by=['score'], ascending=False, inplace=True)
    nodes_comparison = nodes_comparison.round({'score': 2})

    ##likes
    restaurant_profile_df = algorithm.restaurant_profile(
        selected_restaurant_id)  # Not needed - delete

    # Prepare the like user nodes
    like_restaurants_df = algorithm.like_restaurants(
        selected_restaurant_id,
        competitor_limit)[['restaurant', 'restaurant_id', 'compete_score']]
    like_restaurants_df['restaurant'] = like_restaurants_df[
        'restaurant'].str.encode('utf8')
    like_restaurants_df['restaurant_id'] = like_restaurants_df[
        'restaurant_id'].str.encode('utf8')
    like_restaurants_df['compete_score'] = like_restaurants_df[
        'compete_score'].astype(str)
    like_restaurants_df = like_restaurants_df.drop_duplicates().head(
        like_limit)  # Issue #7
    return restaurant_similarity, nodes_comparison, like_restaurants_df
def direct_competitor_similarity(active_restaurant_id, selected_restaurant_id):

    ##restaurant_similarity_json
    active_restaurant_profile_df = algorithm.restaurant_profile(
        active_restaurant_id)
    # Returns restaurant details with categories and attributes csv lists

    active_like_restaurants_df = algorithm.like_restaurants(
        active_restaurant_id, competitor_limit)
    restaurant_similarity = active_like_restaurants_df[
        active_like_restaurants_df['restaurant_id'] == selected_restaurant_id][
            [
                'shared_val', 'shared_score', 'overlap_val', 'overlap_score',
                'rate_sim_val', 'rate_sim_score', 'zip_val', 'zip_score',
                'compete_score'
            ]].astype(str)
    restaurant_similarity_json = restaurant_similarity.to_json(
        orient='records')

    ##comparsion
    customer_prospects_df = algorithm.customer_prospects(
        active_like_restaurants_df, prospect_limit)

    restaurant_graph_dict = algorithm.restaurant_graph(
        active_restaurant_id, active_restaurant_profile_df,
        active_like_restaurants_df, customer_prospects_df)
    # Global nodes and links dataframes are created
    nodes = restaurant_graph_dict['nodes']
    nodes_users = nodes[nodes['order'] == 2][['name', 'score']]
    links = restaurant_graph_dict['links'].to_json(orient='records')
    nodes = restaurant_graph_dict['nodes'].to_json(orient="records")
    graph = {"links": links, "nodes": nodes}
    comparison_json = nodes_users.to_json(orient="records")

    ##likes
    restaurant_profile_df = algorithm.restaurant_profile(
        selected_restaurant_id)

    like_restaurants_df = algorithm.like_restaurants(selected_restaurant_id,
                                                     competitor_limit)
    like_restaurants = like_restaurants_df[[
        'restaurant', 'restaurant_id', 'compete_score'
    ]].astype(str).drop_duplicates().head(10)
    like_restaurants_json = like_restaurants.to_json(orient="records")

    result = {
        "graph": graph,
        "restaurant_similarity": restaurant_similarity_json,
        "comparison": comparison_json,
        "likes": like_restaurants_json
    }

    return result
コード例 #3
0
def restaurant_profile(restaurant_id):

    # Get details for profile window
    restaurant_profile_df = algorithm.restaurant_profile(restaurant_id)
    #restaurant_profile = restaurant_profile_df.astype(str)        # Issue #7
    restaurant_profile = restaurant_profile_df

    # Get first/second order nodes for graph, and info for like nodes across bottom of page
    like_restaurants_df = algorithm.like_restaurants(restaurant_id,
                                                     competitor_limit)
    #like_restaurants_str_df = like_restaurants_df[['restaurant', 'restaurant_id', 'compete_score']].astype(str).drop_duplicates().head(like_limit)     # Issue #7
    like_restaurants_str_df = like_restaurants_df[[
        'restaurant', 'restaurant_id', 'compete_score'
    ]].drop_duplicates().head(like_limit)

    # Get third order nodes for graph
    customer_prospects_df = algorithm.customer_prospects(
        like_restaurants_df, prospect_limit)

    # Transform graph info into nodes and links lists
    restaurant_graph_dict = algorithm.restaurant_graph(restaurant_id,
                                                       restaurant_profile_df,
                                                       like_restaurants_df,
                                                       customer_prospects_df)

    return restaurant_profile, restaurant_graph_dict, like_restaurants_str_df
def rating_of_restaurant(active_user_id,
                         restaurant_id,
                         lmu_limit=20,
                         reco_limit=30,
                         competitor_limit=20):

    # Get details for profile window
    user_profile_df = algorithm.user_profile(active_user_id)

    # Get first/second order nodes for graph, and info for bar graph comparison
    # This is for explore mode, all like nodes are LMU for active users
    like_users_df = algorithm.like_users(user_profile_df, active_user_id,
                                         lmu_limit)

    # Get third order nodes for graph
    recommended_restaurants_df = algorithm.recommended_restaurants(
        like_users_df, reco_limit)
    #display(recommended_restaurants_df)

    # Get all the restaurants name and score inforamtion to build the comparision bar graph
    user_graph_dict = algorithm.user_graph(user_id, user_profile_df,
                                           like_users_df,
                                           recommended_restaurants_df)
    nodes = user_graph_dict['nodes']
    nodes_restaurants = nodes[nodes['order'] == 1][['name', 'score']]
    links = user_graph_dict['links'].to_json(orient='records')
    nodes = user_graph_dict['nodes'].to_json(orient="records")
    graph = {"links": links, "nodes": nodes}
    comparison_json = nodes_restaurants.to_json(orient="records")

    # Returns details of how user rated restaurant
    rating_df = algorithm.user_restaurant_rating(active_user_id, restaurant_id)
    rating = rating_df[[
        'restaurant', 'user', 'rating', 'date', 'review', 'useful', 'funny',
        'cool'
    ]].astype(str)
    rating_json = rating.to_json(orient='records')

    #return the likes nodes at the bottom
    restaurant_profile_df = algorithm.restaurant_profile(restaurant_id)
    #Returns restaurant details with categories and attributes csv lists

    like_restaurants_df = algorithm.like_restaurants(restaurant_id,
                                                     competitor_limit)
    like_restaurants = like_restaurants_df[[
        'restaurant', 'restaurant_id', 'compete_score'
    ]].astype(str).drop_duplicates().head(10)
    like_restaurants_json = like_restaurants.to_json(orient="records")

    result = {
        "graph": graph,
        "rating": rating_json,
        "comparison": comparison_json,
        "likes": like_restaurants_json
    }
    return result
def rating_by_user(active_restaurant_id, user_id):

    restaurant_profile_df = algorithm.restaurant_profile(active_restaurant_id)

    like_restaurants_df = algorithm.like_restaurants(restaurant_id,
                                                     competitor_limit)
    # Returns name and restaurant_id info to build like restaurant nodes at bottom of screen.
    # (Also provides info for bar graph in Analyze mode when a second order node is selected)

    customer_prospects_df = algorithm.customer_prospects(
        like_restaurants_df, prospect_limit)

    restaurant_graph_dict = algorithm.restaurant_graph(restaurant_id,
                                                       restaurant_profile_df,
                                                       like_restaurants_df,
                                                       customer_prospects_df)
    # Global nodes and links dataframes are created
    nodes = restaurant_graph_dict['nodes']
    nodes_users = nodes[nodes['order'] == 1][['name', 'score']]
    links = restaurant_graph_dict['links'].to_json(orient='records')
    nodes = restaurant_graph_dict['nodes'].to_json(orient="records")
    graph = {"links": links, "nodes": nodes}
    comparison_json = nodes_users.to_json(orient="records")

    rating_df = algorithm.user_restaurant_rating(user_id, active_restaurant_id)
    # Returns details of how restaurant was rated by user
    rating = rating_df[[
        'restaurant', 'user', 'rating', 'date', 'review', 'useful', 'funny',
        'cool'
    ]].astype(str)
    rating_json = rating.to_json(orient='records')

    ##likes json
    user_profile_df = algorithm.user_profile(user_id)
    # Get first/second order nodes for graph, and info for like nodes across bottom of page
    # This is for explore mode, all like nodes are LMU for active users
    like_users_df = algorithm.like_users(user_profile_df, user_id, lmu_limit)
    like_users = like_users_df[['user', 'user_id', 'lmu_score'
                                ]].astype(str).drop_duplicates().head(10)
    like_users_json = like_users.to_json(orient="records")

    result = {
        "graph": graph,
        "rating": rating_json,
        "comparison": comparison_json,
        "likes": like_users_json
    }

    return result
コード例 #6
0
def rating_of_restaurant(active_user_id, restaurant_id):
    # Get active user info for other routines
    user_profile_df = algorithm.user_profile(active_user_id)
    #user_profile = user_profile_df.astype(str)       # Issue #7
    #user_profile = user_profile_df

    # Get first/second order nodes for graph
    like_users_df = algorithm.like_users(user_profile_df, active_user_id,
                                         lmu_limit)

    # Get third order nodes for graph
    recommended_restaurants_df = algorithm.recommended_restaurants(
        like_users_df, reco_limit)
    # display(recommended_restaurants_df)

    # Transform graph info into nodes and links lists
    user_graph_dict = algorithm.user_graph(active_user_id, user_profile_df,
                                           like_users_df,
                                           recommended_restaurants_df)

    nodes = user_graph_dict['nodes']
    nodes_comparison = nodes[nodes['order'] == 1][['name', 'score']]
    nodes_comparison.sort_values(by=['score'], ascending=False, inplace=True)
    nodes_comparison = nodes_comparison.round({'score': 2})

    # Returns details of how active user rated restaurant
    rating_df = algorithm.user_restaurant_rating(active_user_id, restaurant_id)
    #rating = rating_df[['restaurant', 'user', 'rating', 'date', 'review', 'useful', 'funny', 'cool']].astype(str)   # Issue #7
    rating = rating_df[[
        'restaurant', 'user', 'rating', 'date', 'review', 'useful', 'funny',
        'cool'
    ]]

    # return the likes nodes at the bottom            # Also use algorithm.like_restaurants for comparison bar graph
    like_restaurants_df = algorithm.like_restaurants(restaurant_id,
                                                     competitor_limit)
    like_restaurants_df['restaurant'] = like_restaurants_df[
        'restaurant'].str.encode('utf8')
    like_restaurants_str_df = like_restaurants_df[[
        'restaurant', 'restaurant_id', 'compete_score'
    ]].astype(str).drop_duplicates().head(like_limit)  # Issue #7

    # Return doesn't match View.py which will expect graph_dict, like, rating, comparison
    return rating, nodes_comparison, like_restaurants_str_df
コード例 #7
0
def rating_by_user(active_restaurant_id, user_id):
    # Get active restaurant info for other routines
    restaurant_profile_df = algorithm.restaurant_profile(active_restaurant_id)
    #restaurant_profile = restaurant_profile_df.astype(str)       # Issue #7
    #restaurant_profile = restaurant_profile_df

    # Get first/second order nodes for graph
    like_restaurants_df = algorithm.like_restaurants(active_restaurant_id,
                                                     competitor_limit)

    # Get third order nodes for graph
    customer_prospects_df = algorithm.customer_prospects(
        like_restaurants_df, prospect_limit)

    # Transform graph info into nodes and links lists
    restaurant_graph_dict = algorithm.restaurant_graph(active_restaurant_id,
                                                       restaurant_profile_df,
                                                       like_restaurants_df,
                                                       customer_prospects_df)

    # Get info for comparison bar graph
    nodes = restaurant_graph_dict['nodes']
    nodes_comparison = nodes[nodes['order'] == 1][['name', 'score']]
    nodes_comparison.sort_values(by=['score'], ascending=False, inplace=True)
    nodes_comparison = nodes_comparison.round({'score': 2})

    # Returns details of how active restaurant was rated by selected user
    rating_df = algorithm.user_restaurant_rating(user_id, active_restaurant_id)
    #rating_str_df = rating_df[['restaurant', 'user', 'rating', 'date', 'review', 'useful', 'funny', 'cool']].astype(str)      # Issue #7
    rating_str_df = rating_df[[
        'restaurant', 'user', 'rating', 'date', 'review', 'useful', 'funny',
        'cool'
    ]]

    ## Get info for like nodes across bottom of page
    user_profile_df = algorithm.user_profile(user_id)
    like_users_df = algorithm.like_users(user_profile_df, user_id, lmu_limit)
    #like_users_str_df = like_users_df[['user', 'user_id', 'lmu_score']].astype(str).drop_duplicates().head(like_limit)        # Issue #7
    like_users_str_df = like_users_df[['user', 'user_id', 'lmu_score'
                                       ]].drop_duplicates().head(like_limit)

    # Return should be: restaurant_graph_dict, like_users, rating, nodes_comparison
    return rating_str_df, nodes_comparison, like_users_str_df
def restaurant_profile(restaurant_id):

    # Get details for profile window
    restaurant_profile_df = algorithm.restaurant_profile(restaurant_id)
    restaurant_profile = restaurant_profile_df.astype(str)
    restaurant_profile_json = restaurant_profile.to_json(orient="records")
    #display(restaurant_profile_json)

    # Get first/second order nodes for graph, and info for like nodes across bottom of page
    like_restaurants_df = algorithm.like_restaurants(restaurant_id,
                                                     competitor_limit)
    like_restaurants = like_restaurants_df[[
        'restaurant', 'restaurant_id', 'compete_score'
    ]].astype(str).drop_duplicates().head(10)
    like_restaurants_json = like_restaurants.to_json(orient="records")
    #display(like_restaurants_json)

    # Get third order nodes for graph
    customer_prospects_df = algorithm.customer_prospects(
        like_restaurants_df, prospect_limit)
    #display(customer_prospects_df)

    # Transform graph info into nodes and links lists
    restaurant_graph_dict = algorithm.restaurant_graph(restaurant_id,
                                                       restaurant_profile_df,
                                                       like_restaurants_df,
                                                       customer_prospects_df)
    #display(restaurant_graph_dict)
    links = restaurant_graph_dict['links'].to_json(orient='records')
    nodes = restaurant_graph_dict['nodes'].to_json(orient="records")
    graph = {"links": links, "nodes": nodes}

    result = {
        "profile": restaurant_profile_json,
        "graph": graph,
        "likes": like_restaurants_json
    }

    return result
def restaurant_similarity(selected_restaurant_id,
                          like_restaurant_id,
                          competitor_limit=20):

    selected_restaurant_profile_df = algorithm.restaurant_profile(
        selected_restaurant_id)

    selected_like_restaurants_df = algorithm.like_restaurants(
        selected_restaurant_id, competitor_limit)

    restaurant_similarity = selected_like_restaurants_df[
        selected_like_restaurants_df['restaurant_id'] == like_restaurant_id]

    restaurant_similarity_df = restaurant_similarity[[
        'shared_val', 'shared_score', 'overlap_val', 'overlap_score',
        'review_sim_val', 'review_sim_score', 'rate_sim_val', 'rate_sim_score',
        'zip_val', 'zip_score', 'compete_score'
    ]].drop_duplicates().astype(str)

    restaurant_similarity_json = restaurant_similarity_df.to_json(
        orient="records")

    return restaurant_similarity_json
コード例 #10
0
def restaurant_similarity(selected_restaurant_id, like_restaurant_id):

    selected_restaurant_profile_df = algorithm.restaurant_profile(
        selected_restaurant_id)  # Not needed

    # Get information on all the like nodes and their similarity scores
    selected_like_restaurants_df = algorithm.like_restaurants(
        selected_restaurant_id, competitor_limit)

    # Get similarity info on the particular like node that was clicked
    restaurant_similarity = selected_like_restaurants_df[
        selected_like_restaurants_df['restaurant_id'] == like_restaurant_id]

    #restaurant_similarity_df = restaurant_similarity[
    #    ['shared_val', 'shared_score', 'overlap_val', 'overlap_score', 'review_sim_val', 'review_sim_score',
    #     'rate_sim_val', 'rate_sim_score', 'zip_val', 'zip_score', 'compete_score']].drop_duplicates().astype(str)   # Issue #7
    restaurant_similarity_df = restaurant_similarity[[
        'shared_val', 'shared_score', 'overlap_val', 'overlap_score',
        'review_sim_val', 'review_sim_score', 'rate_sim_val', 'rate_sim_score',
        'zip_val', 'zip_score', 'compete_score'
    ]].drop_duplicates()

    # If Frontend can't preserve graph, then we'll need to include much more
    return restaurant_similarity_df
def customer_prospect_relevance(active_restaurant_id, selected_user_id):

    ##pre-calcualtion
    active_restaurant_profile_df = algorithm.restaurant_profile(
        active_restaurant_id)
    active_like_restaurants_df = algorithm.like_restaurants(
        active_restaurant_id, competitor_limit)
    customer_prospects_df = algorithm.customer_prospects(
        like_restaurants_df, prospect_limit)
    restaurant_graph_dict = algorithm.restaurant_graph(restaurant_id,
                                                       restaurant_profile_df,
                                                       like_restaurants_df,
                                                       customer_prospects_df)

    ##graph
    links = restaurant_graph_dict['links'].to_json(orient='records')
    nodes = restaurant_graph_dict['nodes'].to_json(orient="records")
    graph = {"links": links, "nodes": nodes}

    ##relevance
    customer_prospect_relevance = customer_prospects_df[
        customer_prospects_df['user_id'] == selected_user_id]
    relevance_df = customer_prospect_relevance[[
        'restaurant', 'user_rating', 'compete_score', 'contribution',
        'relevancy'
    ]]
    if (customer_prospect_relevance.shape[0] == 1):
        avg_rating = customer_prospect_relevance['avg_rating'].values[0]
        user_similarity = 5.0
        user_contribution = avg_rating * user_similarity
        user_relevancy = customer_prospect_relevance['relevancy'].values[0]

        user_df = pd.DataFrame({
            'restaurant': ["User's Average Rating"],
            "user_rating": [avg_rating],
            "compete_score": [user_similarity],
            "contribution": [user_contribution],
            "relevancy": [user_relevancy]
        })

        relevance_df = pd.concat([relevance_df, user_df], axis=0)

    relevance = relevance_df.astype(str)
    relevance_json = relevance.to_json(orient='records')

    ##comparison
    nodes = restaurant_graph_dict['nodes']
    nodes_restaurants = nodes[nodes['order'] == 3][['name', 'score']]
    comparison_json = nodes_restaurants.to_json(orient="records")

    ##likes
    selected_user_profile_df = algorithm.user_profile(selected_user_id)
    selected_like_users_df = algorithm.like_users(selected_user_profile_df,
                                                  selected_user_id, lmu_limit)
    like_users = selected_like_users_df[[
        'user', 'user_id', 'lmu_score'
    ]].astype(str).drop_duplicates().head(10)
    like_users_json = like_users.to_json(orient="records")

    result = {
        "graph": graph,
        "relevance": relevance_json,
        "comparison": comparison_json,
        "likes": like_users_json
    }
    return result
def recommended_restaurant_relevance(active_user_id, selected_restaurant_id):

    active_user_profile_df = algorithm.user_profile(active_user_id)
    active_like_users_df = algorithm.like_users(active_user_profile_df,
                                                active_user_id, lmu_limit)
    recommended_restaurants_df = algorithm.recommended_restaurants(
        active_like_users_df, reco_limit)
    user_graph_dict = algorithm.user_graph(active_user_id,
                                           active_user_profile_df,
                                           active_like_users_df,
                                           recommended_restaurants_df)

    ##graph
    links = user_graph_dict['links'].to_json(orient='records')
    nodes = user_graph_dict['nodes'].to_json(orient="records")
    graph = {"links": links, "nodes": nodes}

    ##relevance
    reco_restaurant_relevance = recommended_restaurants_df[
        recommended_restaurants_df['restaurant_id'] == selected_restaurant_id]
    relevance_df = reco_restaurant_relevance[[
        'user', 'lmu_rating', 'lmu_score', 'contribution', 'relevancy'
    ]]
    if (reco_restaurant_relevance.shape[0] == 1):
        avg_rating = reco_restaurant_relevance['avg_rating'].values[0]
        restaurant_similarity = 5.0
        restaurant_contribution = avg_rating * restaurant_similarity
        restaurant_relevancy = reco_restaurant_relevance['relevancy'].values[0]

        restaurant_df = pd.DataFrame({
            'user': ["Restaurant's Average Rating"],
            "lmu_rating": [avg_rating],
            "lmu_score": [restaurant_similarity],
            "contribution": [restaurant_contribution],
            "relevancy": [restaurant_relevancy]
        })

        relevance_df = pd.concat([relevance_df, restaurant_df], axis=0)

    relevance = relevance_df.astype(str)
    relevance_json = relevance.to_json(orient='records')

    ##comparison
    nodes = user_graph_dict['nodes']
    nodes_users = nodes[nodes['order'] == 3][['name', 'score']]
    comparison_json = nodes_users.to_json(orient="records")

    ##likes
    selected_restaurant_profile_df = algorithm.restaurant_profile(
        selected_restaurant_id)
    selected_like_restaurants_df = algorithm.like_restaurants(
        selected_restaurant_id, competitor_limit)
    like_restaurants = selected_like_restaurants_df[[
        'restaurant', 'restaurant_id', 'compete_score'
    ]].astype(str).drop_duplicates().head(10)
    like_restaurants_json = like_restaurants.to_json(orient="records")

    result = {
        "graph": graph,
        "relevance": relevance_json,
        "comparison": comparison_json,
        "likes": like_restaurants_json
    }

    return result
コード例 #13
0
def customer_prospect_relevance(active_restaurant_id, selected_user_id):
    # Get active restaurant info for other routines
    active_restaurant_profile_df = algorithm.restaurant_profile(
        active_restaurant_id)
    #restaurant_profile = active_restaurant_profile_df.astype(str)           # Issue #7
    #restaurant_profile = active_restaurant_profile_df

    # Get first/second order nodes for graph
    active_like_restaurants_df = algorithm.like_restaurants(
        active_restaurant_id, competitor_limit)

    # Get third order nodes for graph
    customer_prospects_df = algorithm.customer_prospects(
        active_like_restaurants_df, prospect_limit)

    # Transform graph info into nodes and links lists
    restaurant_graph_dict = algorithm.restaurant_graph(
        active_restaurant_id, active_restaurant_profile_df,
        active_like_restaurants_df, customer_prospects_df)

    ## Pull off details on selected customer prospect relevance for upper right window
    customer_prospect_relevance = customer_prospects_df[
        customer_prospects_df['user_id'] == selected_user_id]
    relevance_df = customer_prospect_relevance[[
        'restaurant', 'user_rating', 'compete_score', 'contribution',
        'relevancy'
    ]]
    if (customer_prospect_relevance.shape[0] == 1):
        avg_rating = customer_prospect_relevance['avg_rating'].values[0]
        user_similarity = 5.0
        user_contribution = avg_rating * user_similarity
        user_relevancy = customer_prospect_relevance['relevancy'].values[0]

        user_df = pd.DataFrame({
            'restaurant': ["User's Average Rating"],
            "user_rating": [avg_rating],
            "compete_score": [user_similarity],
            "contribution": [user_contribution],
            "relevancy": [user_relevancy]
        })

        relevance_df = pd.concat([relevance_df, user_df], axis=0)

    #relevance = relevance_df.astype(str)             # Issue #7
    relevance = relevance_df

    # Get info for comparison bar graph
    nodes = restaurant_graph_dict['nodes']
    nodes_comparison = nodes[nodes['order'] == 3][['name', 'score']]
    nodes_comparison.sort_values(by=['score'], ascending=False, inplace=True)
    nodes_comparison = nodes_comparison.round({'score': 2})

    # Prepare the like user nodes
    selected_user_profile_df = algorithm.user_profile(selected_user_id)
    selected_like_users_df = algorithm.like_users(selected_user_profile_df,
                                                  selected_user_id, lmu_limit)
    #like_users_str_df = selected_like_users_df[['user', 'user_id', 'lmu_score']].astype(str).drop_duplicates().head(like_limit)       # Issue #7
    like_users_str_df = selected_like_users_df[[
        'user', 'user_id', 'lmu_score'
    ]].drop_duplicates().head(like_limit)

    # restaurant_graph_dict, like_users, relevance, nodes_comparison
    return relevance, nodes_comparison, like_users_str_df
コード例 #14
0
def recommended_restaurant_relevance(active_user_id, selected_restaurant_id):
    # Get active restaurant info for other routines
    active_user_profile_df = algorithm.user_profile(active_user_id)
    #user_profile = active_user_profile_df.astype(str)              # Issue #7
    #user_profile = active_user_profile_df

    # Get first/second order nodes for graph
    active_like_users_df = algorithm.like_users(active_user_profile_df,
                                                active_user_id, lmu_limit)

    # Get third order nodes for graph
    recommended_restaurants_df = algorithm.recommended_restaurants(
        active_like_users_df, reco_limit)

    # Transform graph info into nodes and links lists
    user_graph_dict = algorithm.user_graph(active_user_id,
                                           active_user_profile_df,
                                           active_like_users_df,
                                           recommended_restaurants_df)

    # Pull off details on selected recommended restaurant relevance for upper right window
    reco_restaurant_relevance = recommended_restaurants_df[
        recommended_restaurants_df['restaurant_id'] == selected_restaurant_id]
    relevance_df = reco_restaurant_relevance[[
        'user', 'lmu_rating', 'lmu_score', 'contribution', 'relevancy'
    ]]
    if (reco_restaurant_relevance.shape[0] == 1):
        avg_rating = reco_restaurant_relevance['avg_rating'].values[0]
        restaurant_similarity = 5.0
        restaurant_contribution = avg_rating * restaurant_similarity
        restaurant_relevancy = reco_restaurant_relevance['relevancy'].values[0]

        restaurant_df = pd.DataFrame({
            'user': ["Restaurant's Average Rating"],
            "lmu_rating": [avg_rating],
            "lmu_score": [restaurant_similarity],
            "contribution": [restaurant_contribution],
            "relevancy": [restaurant_relevancy]
        })

        relevance_df = pd.concat([relevance_df, restaurant_df], axis=0)

    #relevance = relevance_df.astype(str)               # Issue #7
    relevance = relevance_df

    # Get info for comparison bar graph
    nodes = user_graph_dict['nodes']
    nodes_comparison = nodes[nodes['order'] == 3][['name', 'score'
                                                   ]]  # nodes_comparison
    nodes_comparison.sort_values(by=['score'], ascending=False, inplace=True)
    nodes_comparison = nodes_comparison.round({'score': 2})

    # Prepare the like restaurant nodes
    selected_like_restaurants_df = algorithm.like_restaurants(
        selected_restaurant_id,
        competitor_limit)[['restaurant', 'restaurant_id', 'compete_score']]
    selected_like_restaurants_df['restaurant'] = selected_like_restaurants_df[
        'restaurant'].str.encode('utf8')
    selected_like_restaurants_df[
        'restaurant_id'] = selected_like_restaurants_df[
            'restaurant_id'].str.encode('utf8')
    selected_like_restaurants_df[
        'compete_score'] = selected_like_restaurants_df[
            'compete_score'].astype(str)
    selected_like_restaurants_df = selected_like_restaurants_df.drop_duplicates(
    ).head(like_limit)  # Issue #7
    return relevance, nodes_comparison, selected_like_restaurants_df