コード例 #1
0
def suggest_friends(login, type="interest"):
    if type == "interest":
        suggested_friends = graph.data(
            "MATCH (p1:User {email: '%s'})-[x:RATED]->(m:Movie)<-[y:RATED]-(p2:User) WHERE NOT EXISTS( (p1)-[:FRIEND]->(p2)) WITH COUNT(m) AS numbermovies, SUM(x.stars * y.stars) AS xyDotProduct, SQRT(REDUCE(xDot=0.0, a IN COLLECT(x.stars) | xDot + a ^ 2)) AS xLength, SQRT(REDUCE(yDot = 0.0, b IN COLLECT(y.stars) | yDot + b^2)) AS yLength, p1, p2 RETURN p2.login,numbermovies ORDER BY xyDotProduct / (xLength * yLength) DESC LIMIT 100;"
            % (login))
        return (suggested_friends)
    elif type == "fof":
        fof = graph.data(
            "Match (u:User) where u.email contains '%s' Match(u)-[: FRIEND] -> (otherperson) - [: FRIEND]->(fof) WHERE NOT EXISTS( (u)-[:FRIEND]->(fof) ) return fof.login,fof.name"
            % (login))
        return (fof)
コード例 #2
0
def rated_movies(login):
    if login:
        movies_rated = graph.data(
            "Match (u:User)-[:RATED]->(m:Movie) Where u.email contains '%s' return count(m)"
            % (login))
        return movies_rated
    else:
        movies = graph.data(
            "Match (m:Movie)<-[r:RATED]-() return m,Count(*) AS num ORDER BY num desc Limit 25"
        )
        return movies
コード例 #3
0
def signup(request):
    if request.method == "POST":
        username = request.POST.get("username")
        email = request.POST.get("email").lower()
        password = request.POST.get("password")
        password = crypt.crypt(password)
        User = graph.data(
            "MATCH (n:User) WHERE n.login = '******' OR n.email ='%s' RETURN count(n) , n"
            % (username, email))

        if User:
            if User[0]["n"]["email"] == email:
                return HttpResponse("Email exists")
            else:
                return HttpResponse("Username exists")
        else:
            tx = graph.begin()
            a = Node("User",
                     name=username,
                     login=username,
                     email=email,
                     password=password)
            tx.create(a)
            tx.commit()
            request.session['email'] = email
            return HttpResponse("Success")
コード例 #4
0
def signin(request):
    if request.method == "POST":
        email = request.POST.get("email").lower()
        password = request.POST.get("password")
        User = graph.data("MATCH (n:User) WHERE n.email ='%s' RETURN  n" %
                          (email))
        if User:
            valid_password = crypt.crypt(
                password, User[0]["n"]["password"]) == User[0]["n"]["password"]
            if valid_password:
                print("user in")
                request.session['email'] = email
                return HttpResponse("Success")
            else:
                return HttpResponse("Wrong Password")
        else:
            return HttpResponse("User does not exists")
コード例 #5
0
def suggest_movies(login):
    movies_suggested = graph.data(
        "match (u:User) where u.email contains '%s' match (u)-[:FRIEND]->(ot)-[:RATED]-(rec) where not exists ((u)-[:RATED]->(rec)) return collect(rec.title) as rec,ot.login as name"
        % (login))
    return movies_suggested