Example #1
0
 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"))))
async def get_random(goblin_app, vertex_label=None):
    session = await goblin_app.session()
    for i in range(10):
        has = ["random", P.gte(random.random())]
        if vertex_label:
            has.insert(0, vertex_label)
        traversal = project_vertex(session.g.V().has(*has).order().by(
            "random", Order.asc).limit(1))
        result = await traversal.toList()
        if len(result):
            break
    else:
        return None
    for entry in result:
        cleanup_vertex(entry, goblin_app)
    return result[0]
Example #3
0
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 entities_timeline(g, timerange, dataset):
    result = []

    person_count = g.V().has('face_id', P.gte(0)).order().by('face_id', Order.desc)\
        .values('face_id').limit(1).toList()[0]+1
    print person_count
    for i in range(person_count):
        image_id = g.V().has('face_id', i).out().hasLabel('image')\
            .has('datetime', P.inside(timerange[0], timerange[1])).order().by('datetime', Order.asc)\
            .dedup().valueMap().toList()
        if len(image_id) != 0:
            result.append(image_id)
    print 'sad', result
    tags = g.V().hasLabel('tag').values('tag_id').toList()
    for tag in tags:
        print tag
        image_id = g.V().has('tag_id', tag).out().hasLabel('bbox').out().hasLabel('image')\
            .has('datetime', P.inside(timerange[0], timerange[1])).order().by('datetime', Order.asc)\
            .dedup().valueMap().toList()
        if len(image_id) != 0:
            result.append(image_id)
    print 'sadd', {'nodes': result}
    return result
Example #5
0
 def createdAtLeast(self, number):
     return self.outE("created").count().is_(P.gte(number))
Example #6
0
 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"))))
Example #7
0
 def createdAtLeast(self, number):
     return self.outE("created").count().is_(P.gte(number))