def get_activity_of_early_adopters()

in identity-resolution/notebooks/identity-graph/nepytune/usecase/purchase_path.py [0:0]


def get_activity_of_early_adopters(g, thank_you_page_url, skip_single_transients=False, limit=5):
    """
    Given thank you page url, find first early adopters of the product.

    In other words:
        * find first few persistent identities (or transient if they're not matched with any user)
          that visited given thank you page
        * extract their *whole* activity on the domain of the thank_you_page
    """
    return (
        g.V(thank_you_page_url)
        .hasLabel("website").as_("thank_you")
        .in_("links_to").as_("website_group")
        .select("thank_you")
        .inE("visited")
        .order().by("ts")
        .choose(
            constant(skip_single_transients).is_(P.eq(True)),
            where(outV().in_("has_identity")),
            identity()
        )
        .choose(
            outV().in_("has_identity"),
            project(
                "type", "id", "purchase_ts"
            )
                .by(constant("persistent"))
                .by(outV().in_("has_identity"))
                .by(values("ts")),
            project(
                "type", "id", "purchase_ts"
            )
                .by(constant("transient"))
                .by(outV())
                .by(values("ts"))
        ).dedup("id").limit(limit)
        .choose(
            select("type").is_("persistent"),
            project(
                "persistent_id", "transient_id", "purchase_ts"
            ).by(select("id").values("pid"))
             .by(select("id").out("has_identity").fold())
             .by(select("purchase_ts")),
            project("persistent_id", "transient_id", "purchase_ts")
                .by(constant(""))
                .by(select("id").fold())
                .by(select("purchase_ts"))
        ).project("persistent_id", "purchase_ts", "devices", "visits")
            .by(select("persistent_id"))
            .by(select("purchase_ts"))
            .by(select("transient_id").unfold().group().by(values("uid")).by(values("type")))
            .by(
                select("transient_id").unfold().outE("visited").order().by("ts")
                .where(
                    inV().in_("links_to").where(P.eq("website_group"))
                )
                .project(
                    "transientId", "url", "ts"
                ).by("uid").by("visited_url").by("ts").fold())
    )