-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulticpu_yh.py
More file actions
131 lines (110 loc) · 5.02 KB
/
multicpu_yh.py
File metadata and controls
131 lines (110 loc) · 5.02 KB
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
from new_analyzer_yh import factor_integration
from multiprocessing import Process, Queue, freeze_support
from bson.objectid import ObjectId
from pymongo import MongoClient
import multiprocessing
from time import sleep
import os, sys
def __main__():
f_id = 0 #input
keyid = 747
analyzer = run_factor_integration(keyid, f_id)
analyzer.run()
analyzer.factor_norm()
class run_factor_integration:
def __init__(self, keyid, fid):
self.cores = multiprocessing.cpu_count()
if self.cores > 3 :
self.cores -= 1
self.client = MongoClient('203.255.92.141:27017', connect=False)
self.PUBLIC = self.client['PUBLIC']
self.new_max_factor = self.PUBLIC['new_factor']
self.ID = self.client['ID']
self.Domestic = self.ID['Domestic']
self.keyid = keyid
self.fid = fid
def run(self):
print("??")
authorSize = self.ID['Domestic'].find({"keyId":self.keyid, "fid":self.fid}).count()
processList = []
if None == self.new_max_factor.find_one({'keyId': self.keyid,"fid":self.fid}):
# self.new_max_factor.insert({'keyId': self.keyid,"fid":self.fid},{'keyId': self.keyid,"fid":self.fid, 'Quality' : -1, 'accuracy' : -1, 'recentness' : -1, 'coop': -1 })
self.new_max_factor.insert({'keyId': self.keyid,"fid":self.fid},{'keyId': self.keyid,"fid":self.fid, 'ntisQual' : -1, 'remainQual' : -1,'accuracy' : -1, 'recentness' : -1, 'coop': -1 })
th = 100 # each core handle 100 or more data
sizeDict = {}
perData = int(authorSize / self.cores)
if perData > th :
last = 0
for i in range(self.cores-1) :
sizeDict[last] = last+perData
last += perData
sizeDict[last] = authorSize
else :
sizeDict[0] = authorSize
# 이 코드는 코어수를 기반으로 총 data를 나눠준다. 하지만 총 데이터가 100개 이하이면 나누지 않는다.
# print(sizeDict)
processList = []
for key in sizeDict :
acl = None
acl = factor_integration(key, sizeDict[key], self.fid ,self.keyid)
print("run")
if __name__ == "__main__":
p = Process(target= acl.run)
processList.append(p)
p.start()
for p in processList :
p.join()
self.factor_norm()
def factor_norm(self):
max_factor = self.new_max_factor.find_one({'keyId':self.keyid})
# max_qual = max_factor['Quality']
# real_qual = 1 / max_qual
max_ntisQual = max_factor['ntisQual']
max_remainQual = max_factor['remainQual']
norm_ntisQual_factor = 1/ max_ntisQual
norm_remainQual_factor = 1/ max_remainQual
max_acc = max_factor['accuracy']
max_recentness = max_factor['recentness']
max_coop = max_factor['coop']
real_recentness = 1 / max_recentness
if max_coop == 0: real_coop = max_coop
elif max_coop != 0: real_coop = 1/ max_coop
self.ID['test'].update_many(
{"keyId":self.keyid, "fid":self.fid}, [
{"$set" : {
"factor.coop":{"$multiply": ["$factor.coop", real_coop]},
"factor.qunt":{
"$sum":[
{"$multiply": [real_recentness, "$factor.qunt", 0.5]},
"$factor.lct"
]},
# "factor.qual":{"$multiply": ["$factor.qual", real_qual]},
"factor.qual":{
"$multiply": [
{"$sum":[
{"$multiply" : ["$factor.ntisQual", norm_ntisQual_factor]},
{"$multiply" : ["$factor.remainQual", norm_remainQual_factor]}
]},
0.5]},
"score" : {'$sum':[
# {"$multiply": ["$factor.qual", real_qual, 25]},
{"$multiply": [
{"$multiply" : [{"$sum" : [
{"$multiply" : ["$factor.ntisQual", norm_ntisQual_factor]},
{"$multiply" : ["$factor.remainQual", norm_remainQual_factor]}
]}, 0.5]}, 25]},
{"$multiply": ["$factor.acc", 25]},
{"$multiply": ["$factor.coop", real_coop, 25]},
{"$multiply": [
{"$sum":[
{"$multiply": [real_recentness, "$factor.qunt", 0.5]},
"$factor.lct"]}, 25]}
]}}}])
print("종료")
__main__()
# #[{"$multiply": ["$factor.qual", real_qual, 25]}]
# db.test.updateMany({}, [
# {"$set" :
# {"score_t" :
# {'$sum':[{"$multiply": ["$factor.qual", 100, 25]}, {"$multiply": ["$factor.acc", 25]},{"$multiply": ["$factor.coop", 25]},{"$multiply": ["$factor.qunt", 25]}]
# }}}])