This commit is contained in:
wea_ondara
2020-01-27 11:58:19 +01:00
parent d2057842a7
commit da8896eadd
2 changed files with 64 additions and 7 deletions

View File

@@ -58,6 +58,33 @@ def load(folder):
return users, posts, firstcontrib, sumcontrib
def readVotes(folder):
file = folder + "/Votes.xml"
prefix = "readVotes: "
printnoln(prefix + "reading xml file ...")
now = cms()
items = [elem for event, elem in et.iterparse(file) if elem.tag == "row"]
rprint(prefix + "reading xml file ... took " + str(cms() - now) + "ms")
votes = dmt(items).map(mapvote, prefix + "mapping votes").getresults()
print(prefix + "done")
return votes
def mapvote(item):
tags = ['PostId', 'VoteTypeId', 'CreationDate']
datetags = ['CreationDate']
vote = {tag: getTag(item, tag) for tag in tags}
for tag in datetags:
if vote[tag] is not None:
vote[tag] = datetime.fromisoformat(vote[tag])
else:
print("map vote: tag " + tag + " is None: " + str(vote))
return vote
def computesumcontrib(posts):
x1 = dmt(posts).map(lambda q: q['OwnerUserId'], "calc sum contrib q").getresults()
x2 = dmt(posts).map(lambda q: [a['OwnerUserId'] for a in q['Answers']], "calc sum contrib a").getresults()