in identity-resolution/notebooks/identity-graph/nepytune/usecase/undecided_users.py [0:0]
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,
}
)
)
)