def person2votesProposals(p_eid): """ all proposals votings of a given person p_eid in a given instance g.i_eid in temporal descending order, i.e. propVotes[0] contains the latest vote, propVotes[-1] contains the oldest vote. """ q = """START p=node({peid}), inst=node({ieid}) MATCH p-[v:votes]->pr<-[:hasProposal]-inst WHERE pr.element_type="proposal" RETURN v.created, v.pro, pr.title, ID(pr) ORDER BY v.created DESC """ propVotes = db.cypher.table(q, dict(peid=p_eid, ieid=g.i_eid))[1] # Fetch the votes from neo4j ... propVotesDict = [ dict(created=date_diff(datetime.utcfromtimestamp(p[0]), datetime.today()), pro=p[1], title=p[2], p_eid=p[3]) for p in propVotes ] # ... and create a dict-object ... return propVotesDict # ... and return it.
def person2proposals(p_eid): """ all proposals of a given person p_eid in a given instance g.i_eid in descending order, i.e. props[1] contains the newest proposal, props[-1] contains the oldest proposal. """ q = """START p=node({peid}), inst=node({ieid}) MATCH p-[i:issued]->pr<-[:hasProposal]-inst WHERE pr.element_type="proposal" RETURN ID(pr), pr.title, pr.datetime_created ORDER BY pr.datetime_created DESC """ props = db.cypher.table(q, dict(peid=p_eid, ieid=g.i_eid))[1] # Fetch the proposals from neo4j ... propsDict = [ dict(created=date_diff(datetime.utcfromtimestamp(p[2]), datetime.today()), title=p[1], p_eid=p[0]) for p in props ] # ... and create a dict-object ... return propsDict # ... and return it.
def person2comments(p_eid): """ all comments of a given person p_eid in a given instance g.i_eid in descending order, i.e. comments[1] contains the newest comment, comments[-1] contains the oldest comment. """ q = """START p=node({peid}), inst=node({ieid}) MATCH p-[i:issuesComment]->co<-[:hasComment]-pr<-[:hasProposal]-inst WHERE co.element_type="comment" RETURN ID(co), co.title, co.datetime_created, ID(pr) ORDER BY co.datetime_created DESC """ comments = db.cypher.table(q, dict(peid=p_eid, ieid=g.i_eid))[1] # Fetch the comments from neo4j ... commentsDict = [ dict(created=date_diff(datetime.utcfromtimestamp(c[2]), datetime.today()), title=c[1], c_eid=c[0], p_eid=c[3]) for c in comments ] # ... and create a dict-object ... return commentsDict # ... and return it.
def person2votesComments(p_eid): ''' all comments votings of a given person p_eid in a given instance g.i_eid in temporal descending order, i.e. coVotes[0] contains the latest vote, copVotes[-1] contains the oldest vote. ''' q = '''START p=node({peid}), inst=node({ieid}) MATCH p-[v:votes]->co<-[:hasComment]-pr<-[:hasProposal]-inst WHERE co.element_type="comment" RETURN v.created, v.pro, co.title, ID(co), ID(pr) ORDER BY v.created DESC ''' coVotes = db.cypher.table(q,dict(peid=p_eid, ieid=g.i_eid))[1] # Fetch the votes from neo4j ... coVotesDict = [dict(created = date_diff(datetime.utcfromtimestamp(c[0]), datetime.today()), pro = c[1], title = c[2], c_eid = c[3], p_eid = c[4]) for c in coVotes] # ... and create a dict-object ... return coVotesDict # ... and return it.
def getReceivedDelegations(eid): q='''START i=node({userID}) MATCH i <- [:delegationPerson] - hyperEdge , hyperEdge<-[:personDelegation]-person,hyperEdge -[r?:delegationProposal|delegationParlament]->type, instance -[:instanceHasDelegation] -> hyperEdge WHERE ID(instance) ={i_eid} RETURN ID(hyperEdge),hyperEdge.datetime_created,ID(person), person.username,TYPE(r),ID(type),type.title''' delegations = db.cypher.table(q,dict(i_eid=eid, userID=session['userId']))[1] delegationsDict = [dict(delegationID=p[0], delegationCreated = date_diff(datetime.utcfromtimestamp(p[1]), datetime.today()), username = p[3], p_eid = p[2], delegationtype=p[4], typeID=p[5], title=p[6] ) for p in delegations] return delegationsDict
def person2proposals(p_eid): ''' all proposals of a given person p_eid in a given instance g.i_eid in descending order, i.e. props[1] contains the newest proposal, props[-1] contains the oldest proposal. ''' q = '''START p=node({peid}), inst=node({ieid}) MATCH p-[i:issued]->pr<-[:hasProposal]-inst WHERE pr.element_type="proposal" RETURN ID(pr), pr.title, pr.datetime_created ORDER BY pr.datetime_created DESC ''' props = db.cypher.table(q, dict( peid=p_eid, ieid=g.i_eid))[1] # Fetch the proposals from neo4j ... propsDict = [ dict(created=date_diff(datetime.utcfromtimestamp(p[2]), datetime.today()), title=p[1], p_eid=p[0]) for p in props ] # ... and create a dict-object ... return propsDict # ... and return it.
def person2votesProposals(p_eid): ''' all proposals votings of a given person p_eid in a given instance g.i_eid in temporal descending order, i.e. propVotes[0] contains the latest vote, propVotes[-1] contains the oldest vote. ''' q = '''START p=node({peid}), inst=node({ieid}) MATCH p-[v:votes]->pr<-[:hasProposal]-inst WHERE pr.element_type="proposal" RETURN v.created, v.pro, pr.title, ID(pr) ORDER BY v.created DESC ''' propVotes = db.cypher.table(q, dict( peid=p_eid, ieid=g.i_eid))[1] # Fetch the votes from neo4j ... propVotesDict = [ dict(created=date_diff(datetime.utcfromtimestamp(p[0]), datetime.today()), pro=p[1], title=p[2], p_eid=p[3]) for p in propVotes ] # ... and create a dict-object ... return propVotesDict # ... and return it.
def i2Dict(i_eid, loggedUserEid=None): """ i_eid = instance Collects information about an instance: title, body, created, numberUsers, numberVotes, numberProposals, numberComments""" instance = db.instances.get(i_eid) d = dict(title=instance.title, body=instance.body, eid=i_eid) d["created"] = date_diff(instance.datetime_created, datetime.today()) d["numberUsers"] = len(list(instance.outV("hasPeople"))) proposals = list(instance.outV("hasProposal")) d["numberProposals"] = len(proposals) d["numberVotes"] = sum([len(list(p.inE("votes"))) for p in proposals]) d["numberComments"] = sum([len(list(p.outE("hasComment"))) for p in proposals]) # Alternatively, the following Cypher-Query could be used: # q = '''START i=node({i_eid}) # MATCH i-[:hasProposal]->p-[:hasComment]->c # RETURN count(c)''' # d['numberComments'] = db.cypher.table(q,dict(i_eid=i_eid))[1][0][0] return d
def person2comments(p_eid): ''' all comments of a given person p_eid in a given instance g.i_eid in descending order, i.e. comments[1] contains the newest comment, comments[-1] contains the oldest comment. ''' q = '''START p=node({peid}), inst=node({ieid}) MATCH p-[i:issuesComment]->co<-[:hasComment]-pr<-[:hasProposal]-inst WHERE co.element_type="comment" RETURN ID(co), co.title, co.datetime_created, ID(pr) ORDER BY co.datetime_created DESC ''' comments = db.cypher.table(q, dict( peid=p_eid, ieid=g.i_eid))[1] # Fetch the comments from neo4j ... commentsDict = [ dict(created=date_diff(datetime.utcfromtimestamp(c[2]), datetime.today()), title=c[1], c_eid=c[0], p_eid=c[3]) for c in comments ] # ... and create a dict-object ... return commentsDict # ... and return it.
def i2Dict(i_eid, loggedUserEid=None): ''' i_eid = instance Collects information about an instance: title, body, created, numberUsers, numberVotes, numberProposals, numberComments''' instance = db.instances.get(i_eid) d = dict(title=instance.title, body=instance.body, eid=i_eid) d['created'] = date_diff(instance.datetime_created, datetime.today()) d['numberUsers'] = len(list(instance.outV('hasPeople'))) proposals = list(instance.outV('hasProposal')) d['numberProposals'] = len(proposals) d['numberVotes'] = sum([len(list(p.inE('votes'))) for p in proposals]) d['numberComments'] = sum( [len(list(p.outE('hasComment'))) for p in proposals]) # Alternatively, the following Cypher-Query could be used: # q = '''START i=node({i_eid}) # MATCH i-[:hasProposal]->p-[:hasComment]->c # RETURN count(c)''' # d['numberComments'] = db.cypher.table(q,dict(i_eid=i_eid))[1][0][0] return d
def person2votesComments(p_eid): ''' all comments votings of a given person p_eid in a given instance g.i_eid in temporal descending order, i.e. coVotes[0] contains the latest vote, copVotes[-1] contains the oldest vote. ''' q = '''START p=node({peid}), inst=node({ieid}) MATCH p-[v:votes]->co<-[:hasComment]-pr<-[:hasProposal]-inst WHERE co.element_type="comment" RETURN v.created, v.pro, co.title, ID(co), ID(pr) ORDER BY v.created DESC ''' coVotes = db.cypher.table(q, dict( peid=p_eid, ieid=g.i_eid))[1] # Fetch the votes from neo4j ... coVotesDict = [ dict(created=date_diff(datetime.utcfromtimestamp(c[0]), datetime.today()), pro=c[1], title=c[2], c_eid=c[3], p_eid=c[4]) for c in coVotes ] # ... and create a dict-object ... return coVotesDict # ... and return it.
def v2Dict(eid, loggedUserEid=None): """ v = proposal OR comment The resulting dict-Object d collects - the person which issued the proposal/comment, - the vote-counts - the creation date """ v = db.vertices.get(eid) d = dict(title=v.title, body=v.body, eid=eid, ups=v.ups, downs=v.downs) users = issuer(eid) d["username"] = users[0].username if users else None d["userid"] = users[0].eid if users else None d["voteCountUp"] = countVotesUp(eid) d["voteCountDown"] = countVotesDown(eid) d["created"] = date_diff(v.datetime_created, datetime.today()) if loggedUserEid: loggedUser = db.people.get(loggedUserEid) votes = [voteEdge for voteEdge in loggedUser.outE("votes") if voteEdge.inV() == v] if votes: d["upvoted"] = votes[0].pro == 1 d["downvoted"] = votes[0].pro == 0 return d
def v2Dict(eid, loggedUserEid=None): ''' v = proposal OR comment The resulting dict-Object d collects - the person which issued the proposal/comment, - the vote-counts - the creation date ''' v = db.vertices.get(eid) d = dict(title=v.title, body=v.body, eid=eid, ups=v.ups, downs=v.downs) users = issuer(eid) d['username'] = users[0].username if users else None d['userid'] = users[0].eid if users else None d['voteCountUp'] = countVotesUp(eid) d['voteCountDown'] = countVotesDown(eid) d['created'] = date_diff(v.datetime_created, datetime.today()) if loggedUserEid: loggedUser = db.people.get(loggedUserEid) votes = [ voteEdge for voteEdge in loggedUser.outE('votes') if voteEdge.inV() == v ] if votes: d['upvoted'] = (votes[0].pro == 1) d['downvoted'] = (votes[0].pro == 0) return d
def utc2str(utc): return date_diff(datetime.utcfromtimestamp(utc), datetime.today())
def utc2str(utc): return date_diff(datetime.utcfromtimestamp(utc),datetime.today())