def draw_referenced_subgraph(g, website_url, thank_you_page_url, since, min_visited_count): raw_graph = _build_networkx_graph(g, website_url, thank_you_page_url, since) persistent_nodes = [ node for node, attr in raw_graph.nodes(data=True) if attr["label"] == "persistentId" ] graph_with_pos_computed = drawing.layout( raw_graph, nx.shell_layout, nlist=[[website_url], [ node for node, attr in raw_graph.nodes(data=True) if attr["label"] == "transientId" ], [ node for node, attr in raw_graph.nodes(data=True) if attr["label"] == "persistentId" ], [thank_you_page_url]]) # update positions and change node label raw_graph.nodes[thank_you_page_url]["pos"] += (0, 0.75) for node in persistent_nodes: has_visited_thank_you_page = False visited_at_least_X_times = False for check_name, value in raw_graph.nodes[node]["visited_events"].items( ): if ">=" in check_name and value > 0: if "thank" in check_name: has_visited_thank_you_page = True elif value > min_visited_count: visited_at_least_X_times = True if (has_visited_thank_you_page or not visited_at_least_X_times): for _, to in raw_graph.edges(node): raw_graph.nodes[to]["opacity"] = 0.25 raw_graph.nodes[node]["opacity"] = 0.25 drawing.draw( title= "User devices that visited ecommerce websites and optionally converted", scatters=[drawing.edges_scatter(graph_with_pos_computed)] + list( drawing.scatters_by_label(graph_with_pos_computed, attrs_to_skip=["pos", "opacity"], sizes={ "transientId": 10, "transientId-audience": 10, "persistentId": 20, "persistentId-audience": 20, "website": 30, "thankYouPage": 30, })))
def compute_subgraph_pos(query_results, thank_you_page): """Given query results compute subgraph positions.""" for persistent_id, raw_graph in _build_networkx_graph_single( query_results=query_results, thank_you_page=thank_you_page, max_ts_delta=300): raw_graph.nodes[thank_you_page]["label"] = "thank-you-page" graph_with_pos_computed = drawing.layout(raw_graph, _custom_layout) yield persistent_id, graph_with_pos_computed
def draw_referenced_subgraph(g, root_url): graph = _build_networkx_graph( root_url, query_results=_get_transient_ids( _get_persistent_ids_which_visited_website(g, root_url), root_url).next()) graph = drawing.layout(graph, nx.kamada_kawai_layout) drawing.draw( title="Brand interaction", scatters=[drawing.edges_scatter(graph)] + list( drawing.scatters_by_label(graph, attrs_to_skip=["pos"], sizes={ "websiteGroup": 30, "transientId": 10, "persistentId": 15, "website": 10 })), )
def draw_refrenced_subgraph(g, transient_id): raw_graph = _build_networkx_graph( g, g.V(transient_id).in_("has_identity").in_("member").next()) graph_with_pos_computed = drawing.layout(raw_graph, nx.spring_layout, iterations=2500) drawing.draw( title="Part of single household activity on the web", scatters=[drawing.edges_scatter(graph_with_pos_computed)] + list( drawing.scatters_by_label(graph_with_pos_computed, attrs_to_skip=["pos"], sizes={ "identityGroup": 30, "transientId": 15, "persistentId": 20, "websiteGroup": 15, "website": 10 })), )
def draw_referenced_subgraph(g, website_url, categories_limit=3, search_time_limit_in_seconds=15): average_profile = _get_categories_popular_across_audience_of_website( g, website_url, categories_limit=categories_limit).toList() average_profile = dict( chain(*category.items()) for category in average_profile) similar_audience = _query_users_activities_stats( g, website_url, average_profile, search_time_limit_in_seconds=search_time_limit_in_seconds) similar_audience = similar_audience.limit(15).toList() graph = _build_graph(average_profile, similar_audience) iabs = [ n for n, params in graph.nodes(data=True) if params["label"] == "IAB" ] avg_iabs = [ n for n in iabs if graph.node[n]["category"] in average_profile ] graph_with_pos_computed = drawing.layout( graph, nx.shell_layout, nlist=[ ["averageBuyer"], avg_iabs, set(iabs) - set(avg_iabs), [ n for n, params in graph.nodes(data=True) if params["label"] == "persistentId" ], [ n for n, params in graph.nodes(data=True) if params["label"] == "transientId" ], ]) # update positions for name in set(iabs) - set(avg_iabs): node = graph_with_pos_computed.node[name] node["pos"] = [node["pos"][0], node["pos"][1] - 1.75] for name in ["averageBuyer"] + avg_iabs: node = graph_with_pos_computed.node[name] node["pos"] = [node["pos"][0], node["pos"][1] + 1.75] node = graph_with_pos_computed.node["averageBuyer"] node["pos"] = [node["pos"][0], node["pos"][1] + 1] drawing.draw( title= "User devices that visited ecommerce websites and optionally converted", scatters=list( drawing.edge_scatters_by_label( graph_with_pos_computed, dashes={ "interestedInButNotSufficient": "dash", "interestedIn": "solid" })) + list( drawing.scatters_by_label(graph_with_pos_computed, attrs_to_skip=["pos", "opacity"], sizes={ "averageBuyer": 30, "IAB": 10, "persistentId": 20 })))