def test_P(self): # verify that the order of operations is respected assert "and(eq(a),lt(b))" == str(P.eq("a").and_(P.lt("b"))) assert "and(or(lt(b),gt(c)),neq(d))" == str( P.lt("b").or_(P.gt("c")).and_(P.neq("d"))) assert "and(or(lt(b),gt(c)),or(neq(d),gte(e)))" == str( P.lt("b").or_(P.gt("c")).and_(P.neq("d").or_(P.gte("e"))))
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()))
def test_enums(self): statics.load_statics(globals()) assert isinstance(list_, Cardinality) assert list_ is Cardinality.list_ # assert isinstance(eq(2), P) assert eq(2) == P.eq(2) # assert isinstance(first, Pop) assert first == Pop.first statics.unload_statics(globals())
def get_onestop_flights_from_janus(from_, to, context): try: res = ( g.V() .hasLabel("airport") .has("id", "9600276f-608f-4325-a037-f185848f2e28") .bothE("departing") .otherV() .as_("flight1") .hasLabel("flight") .values("flight_duration") .as_("fd") .select("flight1") .values("flight_time") .math("_ + fd + 60") .as_("flight1_time") .select("flight1") .bothE("arriving") .otherV() .hasLabel("airport") .bothE("departing") .otherV() .as_("flight2") .hasLabel("flight") .values("flight_time") .math("_ - flight1_time") .is_(P.gte(0)) .where("flight1", P.eq("flight2")) .by("airlines") .select("flight2") .bothE("arriving") .otherV() .hasLabel("airport") .has("id", "ebc645cd-ea42-40dc-b940-69456b64d2dd") .select("flight1", "flight2") .by(__.valueMap()) .limit(20) .toList() ) for i in range(0, len(res)): res[i] = merge_flight_data(get_values(res[i])) return res except Exception as e: print(e)
def upsert_edge(record, edge_mapping, g): edge_label = edge_mapping['edge_label'] # Simple logic, requiring that Vertices must exist before edge can be added. # Ensure all lookup values are present first out_lookup_values = get_lookup_values( record, edge_mapping['out_vertex']['lookup_properties']) in_lookup_values = get_lookup_values( record, edge_mapping['in_vertex']['lookup_properties']) if out_lookup_values is None or in_lookup_values is None: return try: traversal = g.V().hasLabel(edge_mapping['out_vertex']['vertex_label']) insertion_traversal = __.V().hasLabel( edge_mapping['out_vertex']['vertex_label']) for prop_key, lookup_value in out_lookup_values.items(): traversal = traversal.has(prop_key, lookup_value) insertion_traversal = insertion_traversal.has( prop_key, lookup_value) traversal = traversal.as_('out').V().hasLabel( edge_mapping['in_vertex']['vertex_label']) insertion_traversal = insertion_traversal.as_('out2').V().hasLabel( edge_mapping['in_vertex']['vertex_label']) for prop_key, lookup_value in in_lookup_values.items(): traversal = traversal.has(prop_key, lookup_value) insertion_traversal = insertion_traversal.has( prop_key, lookup_value) insertion_traversal = insertion_traversal.addE(edge_label).from_( 'out2') traversal = traversal.as_('in').inE(edge_label).as_('e').outV().where( P.eq('out')).fold().coalesce(__.unfold(), insertion_traversal).next() except: print("Edge error - skipping: {0}({1}) --{2}-> {3}({4})".format( edge_mapping['out_vertex']['vertex_label'], out_lookup_values, edge_label, edge_mapping['in_vertex']['vertex_label'], in_lookup_values))
def test_P(self): # verify that the order of operations is respected assert "and(eq(a),lt(b))" == str(P.eq("a").and_(P.lt("b"))) assert "and(or(lt(b),gt(c)),neq(d))" == str(P.lt("b").or_(P.gt("c")).and_(P.neq("d"))) assert "and(or(lt(b),gt(c)),or(neq(d),gte(e)))" == str( P.lt("b").or_(P.gt("c")).and_(P.neq("d").or_(P.gte("e"))))