forked from ronilp/Finding-Influencers-in-Social-Networks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclusterLevelResults.py
41 lines (36 loc) · 976 Bytes
/
clusterLevelResults.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
from database import getFullInfluenceScoreCollection, getclusterLevelResultCollection
def clusterLevelResults():
scoreCollection = getFullInfluenceScoreCollection()
clusterResCollection = getclusterLevelResultCollection()
numCluster = len(scoreCollection.find_one()['score'])
clusterResCollection.drop()
for i in range(numCluster):
doc = {}
i = str(i)
doc['_id'] = i
doc['users'] = []
clusterResCollection.insert(doc)
for scores in scoreCollection.find():
fid = scores['_id']
name = scores['name']
userScore = scores['score']
for i in range(len(userScore)):
doc = {}
doc['id'] = fid
doc['name'] = name
doc['score'] = userScore[i]
cluster = str(i)
print i, doc
clusterResCollection.update({'_id' : cluster},
{
'$push' : {
'users' : {
'$each' : [doc],
'$sort' : {'score': -1},
'$slice' : -1000
}
}
}
,upsert = False)
if __name__ == '__main__':
clusterLevelResults()