コード例 #1
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,
                                      })))
コード例 #2
0
def draw_referenced_subgraph(g, transient_id):
    graph = drawing.spring_layout(
        _build_networkx_graph(
            g,
            g.V(transient_id).in_("has_identity").in_("member").next()))

    drawing.draw(title="Single identity group graph structure",
                 scatters=[drawing.edges_scatter(graph)] + list(
                     drawing.scatters_by_label(graph,
                                               attrs_to_skip=["pos"],
                                               sizes={
                                                   "identityGroup": 60,
                                                   "transientId": 20,
                                                   "persistentId": 40
                                               })),
                 annotations=drawing.edge_annotations(graph))
コード例 #3
0
def show(g, website_id):
    """Show users that visited website on more than one device."""

    transient_nodes_for_website = query_transient_nodes_for_website(
        g, website_id)
    website_node = query_website_node(g, website_id)

    raw_graph = create_graph_for_website_and_transient_nodes(
        website_node, transient_nodes_for_website)
    graph = drawing.spring_layout(raw_graph)

    drawing.draw(
        title="",
        scatters=[drawing.edges_scatter(graph)] +
        list(drawing.scatters_by_label(graph, attrs_to_skip=["pos"])),
    )
コード例 #4
0
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
                                      })),
    )
コード例 #5
0
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
                                      })),
    )