-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetStatsOld.py
executable file
·322 lines (279 loc) · 11.9 KB
/
getStatsOld.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
from __future__ import division
import scipy
from scipy import stats
from scipy.stats import mode
from processUnis import *
from mapUnis import *
import sys
qPosts,allPosts = processPosts()
comments = processCommentsForQuestions()
def postStats(posts):
stats = {}
numLikes = []
zeroLikes = 0
numComments = []
zeroComments = 0
length = []
neglected = 0
for post in posts:
try:
numLikes += [int(post['numLikes'])]
numComments += [int(post['numComments'])]
if int(post['numComments']) == 0 :
zeroComments += 1
if int(post['numLikes']) == 0:
zeroLikes +=1
length += [len(post['message'])]
except:
neglected += 1
stats['meanLikes'] = str(scipy.mean(numLikes))
stats['meanComments'] = str(scipy.mean(numComments))
stats['meanLength'] = str(scipy.mean(length))
stats['stdLikes'] = str(scipy.std(numLikes))
stats['stdComments'] = str(scipy.std(numComments))
stats['stdLength'] = str(scipy.std(length))
stats['medianLikes'] = str(scipy.median(numLikes))
stats['medianComments'] = str(scipy.median(numComments))
stats['medianLength'] = str(scipy.median(length))
try:
stats['modeLikes'] = str(mode(numLikes)[0][0])
except:
stats['modeLikes'] = "0"
try:
stats['modeComments'] = str(mode(numComments)[0][0])
except:
stats['modeComments'] = "0"
try:
stats['modeLength'] = str(mode(length)[0][0])
except:
stats['modeLength'] = "0"
stats['numLikes'] = numLikes
stats['numComments'] = numComments
stats['zeroLikes'] = zeroLikes
stats['zeroComments'] = zeroComments
stats['length'] = length
stats['neglected'] = neglected
return stats
def commentStats(comments):
numLikes = []
numComments = []
uniqueCommentors = []
uniqueNames = []
length = []
stats = {}
count = 0
for postID in comments:
count += 1
try:
commentsPost = comments[postID]
for comment in commentsPost:
uniqueCommentors += [comment['userID']]
uniqueNames += [comment['userName']]
numLikes += [int(comment['likeCount'])]
length += [len(comment['message'])]
numComments += [len(commentsPost)]
except:
print postID
uniqueCommentors = list(set(uniqueCommentors))
stats['numUniqueCommentors'] = len(uniqueCommentors)
stats['numComments'] = len(numComments)
stats['meanLikes'] = str(scipy.mean(numLikes))
stats['stdLikes'] = str(scipy.std(numLikes))
stats['medianLikes'] = str(scipy.median(numLikes))
try:
stats['modeLikes'] = str(mode(numLikes)[0][0])
except:
stats['modeLikes'] = "0"
stats['meanLength'] = str(scipy.mean(length))
stats['stdLength'] = str(scipy.std(length))
stats['medianLength'] = str(scipy.median(length))
try:
stats['modeLength'] = str(mode(length)[0][0])
except:
stats['modeLength'] = "0"
stats['numLikes'] = numLikes
stats['uniqueCommentors'] = uniqueCommentors
stats['length'] = length
return stats
#print commentStats(comments['New York University'])
def main():
print "main"
allStat = {}
questionStat = {}
commentStat = {}
count = 0
numLikes = []
numAllLikes = []
numComments = []
numAllComments = []
postAllLength = []
postlength = []
commentlength = []
numUniqueCommentors = 0
numAllPosts = numQPosts = 0
uniStats = cleanUniDict()
f = open("StatsByUnis2.csv","w")
f.write("Uni| Population | Tuition Cost | Religious | State | R or D State (last election) | (All)Number of posts| (All) Total No. of Comments|(All) Mean Post Length | (All) S.D. Post Length | (All) Median Post Length | (All) Mode Post Length | (All) Mean No. of Comments | (All) S.D. No. of Comments | (All) Median No. of Comments | (All) Mode No. of Comments | (All) Mean No. of Likes | (All) S.D. No. of Likes | (All) Median No. of Likes | (All) Mode No. of Likes | (Question) Number of question posts | (Question) Percent % of posts which are questions| (Question) Total No.of Comments |(Question) Mean Post Length | (Question) S.D. Post Length | (Question) Median Post Length | (Question) Mode Post Length | (Question) Mean No. of Comments | (Question) S.D. No. of Comments | (Question) Median No. of Comments | (Question) Mode No. of Comments | (Question) Mean No. of Likes | (Question) S.D. No. of Likes | (Question) Median No. of Likes | (Question) Mode No. of Likes | (Question) No. of unique Commentors | (Question) No. of comments per unique commentor | (Question) Mean Length of comments| (Question) S.D. Length of comments | (Question) Median Length of comments | (Question) Mode Length of comments\n")
for uni in qPosts.keys():
total = len(allPosts[uni])
questions = len(qPosts[uni])
percent = (questions/total) * 100
questionStat[uni] = postStats(qPosts[uni])
allStat[uni] = postStats(allPosts[uni])
commentStat[uni] = commentStats(comments[uni])
if commentStat[uni]['numUniqueCommentors'] == 0 or commentStat[uni]['numComments'] ==0 :
commentorPer = 0
else:
commentorPer = commentStat[uni]['numComments']/commentStat[uni]['numUniqueCommentors']
f.write(uni + "|" + uniStats["size")+"|"+uniStats["tuition"]+"|"+uniStats["isReligious")+"|"+uniStats["state"]+"|"+uniStats["politics"]+"|"+str(len(allPosts[uni]) + "|"+str(sum(allStat[uni]['numComments']))+"|")
f.write(allStat[uni]['meanLength']+"|"+allStat[uni]['stdLength']+"|"+allStat[uni]['medianLength']+"|"+allStat[uni]['modeLength']+"|")
f.write(allStat[uni]['meanComments']+"|"+allStat[uni]['stdComments']+"|"+allStat[uni]['medianComments']+"|"+allStat[uni]['modeComments']+"|"+allStat[uni]['meanLikes']+"|"+allStat[uni]['stdLikes']+"|"+allStat[uni]['medianLikes']+"|"+allStat[uni]['modeLikes']+"|"+)
f.write(len(qPosts[uni])+"|"+percent+"|"+sum(questionStat[uni]['numComments'])+"|"+questionStat[uni]['meanLength']+"|"+questionStat[uni]['stdLength']+"|"+questionStat[uni]['medianLength']+"|"+questionStat[uni]['modeLength']+"|")
f.write(questionStat[uni]['meanComments']+"|"+questionStat[uni]['stdComments']+"|"+questionStat[uni]['medianComments']+"|"+questionStat[uni]['modeComments']+"|"+questionStat[uni]['meanLikes']+"|"+questionStat[uni]['stdLikes']+"|"+questionStat[uni]['medianLikes']+"|"+questionStat[uni]['modeLikes']+"|"+)
f.write(commentStat[uni]['numUniqueCommentors']+"|"+commentorPer+"|"+commentStat[uni]['meanLength']+"|"+commentStat[uni]['stdLength']+"|"+commentStat[uni]['medianLength']+"|"+commentStat[uni]['modeLength']+"\n")
break
'''
print "*******************"+uni+"*********************"
print "Overall Stats (i.e. not just Questions but entire FCB) :-"
print
print "Total number of posts in "+uni+" FCB(/s) :",len(allPosts[uni])
print "post length(number of characters in a post) : "
print "Mean : ",allStat[uni]['meanLength']
print "Standard Deviation :",allStat[uni]['stdLength']
print "Median :",allStat[uni]['medianLength']
print "Mode :",allStat[uni]['modeLength']
print
print "Total number of comments for posts in entire FCB",sum(allStat[uni]['numComments'])
print
print "No. of Comments :-"
print "Mean : ", allStat[uni]['meanComments']
print "Std. Dev. : ", allStat[uni]['stdComments']
print "Median : ",allStat[uni]['medianComments']
print "Mode : ",allStat[uni]['modeComments']
print
print "No. of Likes:-"
print "Mean: ", allStat[uni]['meanLikes']
print "Std. Dev:" , allStat[uni]['stdLikes']
print "Median :",allStat[uni]['medianLikes']
print "Mode :",allStat[uni]['modeLikes']
print
print "Number of posts with zero Comments",allStat[uni]['zeroComments']
print "Number of posts with zero Likes",allStat[uni]['zeroLikes']
print
print
print "Question Stats :-"
print
print
print "Total number of question posts in "+uni+" FCB(/s) :",len(qPosts[uni])
print "Percent of questions in the FCB :",percent
print "Total number of comments for posts with questions in entire FCB(number of characters in a post)",sum(questionStat[uni]['numComments'])
print
print "Length of posts (with questions) :- "
print "Mean : ",questionStat[uni]['meanLength']
print "Std.Dev :" , questionStat[uni]['stdLength']
print "Median :",questionStat[uni]['medianLength']
print "Mode :",questionStat[uni]['modeLength']
print "No. of Comments :-"
print "Mean : "+questionStat[uni]['meanComments']
print "Std. Dev : ", questionStat[uni]['stdComments']
print "Median :",questionStat[uni]['medianComments']
print "Mode :",questionStat[uni]['modeComments']
print "No. of Likes :-"
print "Mean : ", questionStat[uni]['meanLikes']
print "Std. Dev : ", questionStat[uni]['stdLikes']
print "Median : ",questionStat[uni]['medianLikes']
print "Mode : ",questionStat[uni]['modeLikes']
print
print "Number of unique Commentors", commentStat[uni]['numUniqueCommentors']
print "Number of comments per unique commentor",commentorPer
print
print "Length of comments :-"
print "Mean :",commentStat[uni]['meanLength']
print "Std.Dev :",commentStat[uni]['stdLength']
print "Median :",commentStat[uni]['medianLength']
print "Mode :",commentStat[uni]['modeLength']
print
print "Number of question posts with zero Comments",questionStat[uni]['zeroComments']
print "Number of question posts with zero Likes",questionStat[uni]['zeroLikes']
print
print "Note: The mean for number of Likes and Comments indicate the number of comments and likes per post.Also the high number of posts with zero Comments/Likes explains 0 Mode and sometimes 0 Median"
print questionStat[uni]['stdLikes']
print allStat[uni]['medianComments']
print questionStat[uni]['neglected']
print percent
print commentorPer
numAllLikes += allStat[uni]['numLikes']
numAllComments += allStat[uni]['numComments']
numLikes += questionStat[uni]['numLikes']
numComments += questionStat[uni]['numComments']
numAllPosts += len(allPosts[uni])
numQPosts += len(qPosts[uni])
postAllLength += allStat[uni]['length']
postlength += questionStat[uni]['length']
commentlength += commentStat[uni]['length']
numUniqueCommentors += commentStat[uni]['numUniqueCommentors']
count += 1
print count
commentorPer = sum(numAllComments)/numUniqueCommentors
print "*****************************Overall Stats************************"
print "All Posts (i.e. not only Questions) "
print "------------------------------------"
print
print "Total posts :" ,numAllPosts
print
print "No. of Likes on Posts :-"
print "Mean : ",scipy.mean(numAllLikes)
print "Std.Dev : ",scipy.std(numAllLikes)
print "Median : ",scipy.median(numAllLikes)
print "Mode : ", mode(numAllLikes)[0][0]
print
print "No. of Comments on Posts :-"
print "Mean : ",scipy.mean(numAllComments)
print "Std.Dev : ",scipy.std(numAllComments)
print "Median : ",scipy.median(numAllComments)
print "Mode : ", mode(numAllComments)[0][0]
print
print "Length on Posts :-"
print "Mean : ",scipy.mean(postAllLength)
print "Std.Dev : ",scipy.std(postAllLength)
print "Median : ",scipy.median(postAllLength)
print "Mode : ", mode(postAllLength)[0][0]
print
print
print "For Posts with Questions :"
print "------------------------------------"
print
print "Total posts with Questions :" ,numQPosts
print "% of questions ", (numQPosts/numAllPosts) * 100
print
print "No. of Likes on Posts :-"
print "Mean : ",scipy.mean(numLikes)
print "Std.Dev : ",scipy.std(numLikes)
print "Median : ",scipy.median(numLikes)
print "Mode : ", mode(numLikes)[0][0]
print
print "No. of Comments on Posts :-"
print "Mean : ",scipy.mean(numComments)
print "Std.Dev : ",scipy.std(numComments)
print "Median : ",scipy.median(numComments)
print "Mode : ", mode(numComments)[0][0]
print
print "Length of Posts with Questions:-"
print "Mean : ",scipy.mean(postlength)
print "Std.Dev : ",scipy.std(postlength)
print "Median : ",scipy.median(postlength)
print "Mode : ", mode(postlength)[0][0]
print
print "Length of Comments for Posts with Questions:-"
print "Mean : ",scipy.mean(commentlength)
print "Std.Dev : ",scipy.std(commentlength)
print "Median : ",scipy.median(commentlength)
print "Mode : ", mode(commentlength)[0][0]
print
print "Number of uniqueCommentors", numUniqueCommentors
print "Avg. number of comments per uniqueCommentor : ", sum(numComments)/numUniqueCommentors
'''
#Total Posts for a board
#Total number of questions for a board
#Percentage
#main()