-
Notifications
You must be signed in to change notification settings - Fork 0
/
countCommentsLikes.py
executable file
·102 lines (79 loc) · 3.07 KB
/
countCommentsLikes.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
import scipy
import os
import myFunctions as m
from scipy import stats
from scipy.stats import mode
def stats():
f = open("statsData.csv","w")
List = os.listdir("USA")
path = "USA/"
import sys
grandTotalComments = []
grandTotalLikes = []
totalLikes = {}
totalComments = {}
averageLikes = {}
averageComments = {}
stdDevLikes = {}
stdDevComments = {}
modeLikes = {}
modeComments = {}
medianLikes = {}
medianComments = {}
avoidList = []
count = 0
f.write("School"+","+"averageLikes"+","+"stdDevLikes"+","+"medianLikes"+","+"modeLikes"+","+"averageComments"+","+"stdDevComments"+","+"medianComments"+","+"modeComments"+"\n")
for Filename in List:
Filename = path + Filename
if "posts" not in Filename:
avoidList += [Filename]
continue
lines = open(Filename).readlines()
if len(lines)<3:
avoidList += [Filename]
continue
count +=1
prefix = Filename.split("posts.csv")[0]
totalLikes[prefix] = []
totalComments[prefix] = []
for line in lines[1:]:
columns = line.split("|")
try:
numLikes = int(columns[3])
numComments = int(columns[4])
totalLikes[prefix] += [numLikes]
totalComments[prefix] += [numComments]
except:
pass
averageLikes[prefix] = str(scipy.mean(totalLikes[prefix]))
averageComments[prefix] = str(scipy.mean(totalComments[prefix]))
stdDevLikes[prefix] = str(scipy.std(totalLikes[prefix]))
stdDevComments[prefix] = str(scipy.std(totalComments[prefix]))
medianLikes[prefix] = str(scipy.median(totalLikes[prefix]))
medianComments[prefix] = str(scipy.median(totalComments[prefix]))
modeLikes[prefix] = str(mode(totalLikes[prefix])[0][0])
modeComments[prefix] = str(mode(totalComments[prefix])[0][0])
grandTotalComments += totalComments[prefix]
grandTotalLikes += totalLikes[prefix]
f.write(prefix.split("USA/").pop()+","+averageLikes[prefix]+","+stdDevLikes[prefix]+","+medianLikes[prefix]+","+modeLikes[prefix]+ ","+ averageComments[prefix]+","+stdDevComments[prefix]+","+medianComments[prefix]+","+modeComments[prefix]+"\n")
averageTotalLikes = scipy.mean(grandTotalLikes)
averageTotalComments = scipy.mean(grandTotalComments)
stdDevTotalLikes = scipy.std(grandTotalLikes)
stdDevTotalComments = scipy.std(grandTotalComments)
medianTotalLikes = scipy.median(grandTotalLikes)
medianTotalComments = scipy.median(grandTotalComments)
modeTotalLikes = mode(grandTotalLikes)[0][0]
modeTotalComments = mode(grandTotalComments)[0][0]
print "Stats calculated. See statsComplete.dat for overall stats and statsData.csv for individual FCB stats"
f.close()
f = open("statsComplete.dat","w")
m.fileWrite(f, "Entire dataset stats")
m.fileWrite(f, "averagelikes: "+str(averageTotalLikes))
m.fileWrite(f, "averagecomments: " +str(averageTotalComments))
m.fileWrite(f, "stdDevlikes: "+str(stdDevTotalLikes))
m.fileWrite(f, "stdDevcomments: "+str(stdDevTotalComments))
m.fileWrite(f, "medianlikes: "+str(medianTotalLikes))
m.fileWrite(f, "mediancomments: " +str(medianTotalComments))
m.fileWrite(f, "modelikes: "+str(modeTotalLikes))
m.fileWrite(f, "modecomments: "+str(modeTotalComments))
stats()