Example #1
0
    def distribution_for_ages(self, start, end):
        """Assumes incoming "rated" edges and filters based on the age of the "user".

        Produces a map where the key is the rating and the value is the number of times that rating was given.
        This step validates that the start age should exclude minors (i.e. 18 and older).
        """
        if start < 18:
            raise ValueError('Age must be 18 or older')
        if start > end:
            raise ValueError('Start age must be greater than end age')
        if end > 120:
            raise ValueError('Now you are just being crazy')

        return self.filter(outV().has(KEY_AGE, P.between(start, end))).group().by(KEY_RATING).by(count())
def _get_transient_ids(query, root_url):
    return (query.select("persistent_ids").unfold().group().by("pid").by(
        out("has_identity").outE("visited").
        has(  # do not go through links_to, as it causes neptune memory errors
            "visited_url", P.between(root_url, root_url + "/zzz")).valueMap(
                "uid", "visited_url").dedup().limit(15).fold()))