wip
This commit is contained in:
37
posthist.py
37
posthist.py
@@ -24,6 +24,7 @@ def main(folder, intervl):
|
||||
activeusercounts = []
|
||||
answerstonewusers = []
|
||||
sentimentstonewusers = []
|
||||
activitynewusers = []
|
||||
imgmagickcmd = IMAGE_MAGICK
|
||||
for (option_date_from, option_date_to) in intervals:
|
||||
print(option_date_from.strftime("%d-%m-%Y"), option_date_to.strftime("%d-%m-%Y"))
|
||||
@@ -37,9 +38,21 @@ def main(folder, intervl):
|
||||
for p in newposts:
|
||||
postcounts[p['OwnerUserId']].append(p)
|
||||
i = i + 1
|
||||
# for a in p['Answers']:
|
||||
# postcounts[p['OwnerUserId']].append(a)
|
||||
postcounts = {id: len(pc) for (id, pc) in postcounts.items()}
|
||||
activeusercounts.append(((option_date_from, option_date_to), len(postcounts.keys())))
|
||||
|
||||
activitynewusersinmonth = defaultdict(int)
|
||||
for p in newposts:
|
||||
if firstcontrib[p['OwnerUserId']] + timedelta(days=DAYS_NEW_USER) > p['CreationDate']:
|
||||
activitynewusersinmonth[p['OwnerUserId']] += 1
|
||||
for a in p['Answers']:
|
||||
if firstcontrib[a['OwnerUserId']] + timedelta(days=DAYS_NEW_USER) > a['CreationDate']:
|
||||
activitynewusersinmonth[p['OwnerUserId']] += 1
|
||||
activitysum = sum(activitynewusersinmonth.values())
|
||||
activitynewusers.append(((option_date_from, option_date_to), activitysum / len(activitynewusersinmonth)))
|
||||
|
||||
histfilename = outputdir + "posthist_" + folder.split("/")[-1] + "_" + option_date_from.strftime("%d-%m-%Y") + "_" + option_date_to.strftime("%d-%m-%Y") + "-i" + str(intervl)
|
||||
|
||||
histdata = [pc for pc in postcounts.values()]
|
||||
@@ -73,8 +86,10 @@ def main(folder, intervl):
|
||||
# plot posts diagram
|
||||
fig = plt.figure(figsize=(16, 12))
|
||||
plt.plot([x[0] for (x, y) in activeusercounts], [y for (x, y) in activeusercounts])
|
||||
plt.xlabel('time')
|
||||
plt.ylabel('#active users')
|
||||
plt.yscale('log')
|
||||
plt.ylim(bottom=0.001)
|
||||
plt.ylim(bottom=1)
|
||||
plt.title("Active users")
|
||||
fig.savefig(outputdir + "activeusers-i" + str(intervl) + ".png", bbox_inches='tight')
|
||||
plt.close(fig)
|
||||
@@ -82,9 +97,11 @@ def main(folder, intervl):
|
||||
# plot answers to new users diagram
|
||||
fig = plt.figure(figsize=(16, 12))
|
||||
plt.plot([x[0] for (x, y) in answerstonewusers], [y for (x, y) in answerstonewusers])
|
||||
plt.xlabel('time')
|
||||
plt.ylabel('#answers per question of a new user')
|
||||
plt.yscale('log')
|
||||
plt.ylim(bottom=0.001)
|
||||
plt.title("#Answers to new users")
|
||||
plt.ylim(bottom=1)
|
||||
plt.title("Answers to new users")
|
||||
fig.savefig(outputdir + "answerstonewusers-i" + str(intervl) + ".png", bbox_inches='tight')
|
||||
plt.close(fig)
|
||||
|
||||
@@ -93,13 +110,25 @@ def main(folder, intervl):
|
||||
plt.plot([x[0] for (x, y) in sentimentstonewusers], [b for (x, [y, b, n, g]) in sentimentstonewusers], label="Neg. answer")
|
||||
plt.plot([x[0] for (x, y) in sentimentstonewusers], [n for (x, [y, b, n, g]) in sentimentstonewusers], label="Neu. answer")
|
||||
plt.plot([x[0] for (x, y) in sentimentstonewusers], [g for (x, [y, b, n, g]) in sentimentstonewusers], label="Pos. answer")
|
||||
plt.xlabel('time')
|
||||
plt.ylabel('sentiment')
|
||||
plt.yscale('log')
|
||||
plt.ylim(bottom=0.001)
|
||||
plt.ylim(bottom=1)
|
||||
plt.legend(loc="upper right")
|
||||
plt.title("Sentiments of answers to new users")
|
||||
fig.savefig(outputdir + "sentimentstonewusers-i" + str(intervl) + ".png", bbox_inches='tight')
|
||||
plt.close(fig)
|
||||
|
||||
# plot activity for new users
|
||||
fig = plt.figure(figsize=(16, 12))
|
||||
plt.plot([x[0] for (x, y) in activitynewusers], [y for x, y in activitynewusers], label="activity")
|
||||
plt.xlabel('time')
|
||||
plt.ylabel('#questions or answers created by a new user')
|
||||
plt.legend(loc="upper right")
|
||||
plt.title("Average activity per new user")
|
||||
fig.savefig(outputdir + "activitynewusers-i" + str(intervl) + ".png", bbox_inches='tight')
|
||||
plt.close(fig)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# execute only if run as a script
|
||||
|
||||
Reference in New Issue
Block a user