tmp4.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. def exec(obj):
  2. def data_pretreatment(map):
  3. def get_value(str):
  4. end = len(str)
  5. if '.' in str:
  6. end = str.index('.')
  7. return int(str[:end])
  8. parameters = {k: get_value(v) for k, v in map.items()}
  9. scores = []
  10. for k, v in parameters.items():
  11. result = 0
  12. if k == 'bh10006':
  13. if v == 0:
  14. result = 100
  15. elif 0 < v <= 15:
  16. result = 80
  17. elif 15 < v <= 25:
  18. result = 60
  19. elif 25 < v <= 35:
  20. result = 40
  21. elif 35 < v <= 50:
  22. result = 20
  23. elif v > 50:
  24. result = 0
  25. scores.append((0.069857492, result))
  26. elif k == 'bh10018':
  27. if v == 0:
  28. result = 85
  29. elif v == 1:
  30. result = 100
  31. elif v == 2:
  32. result = 50
  33. elif v == 3:
  34. result = 10
  35. scores.append((0.048865349, result))
  36. elif k == 'bh10025':
  37. if v == 0:
  38. result = 100
  39. elif v == 1:
  40. result = 90
  41. elif v == 2:
  42. result = 80
  43. elif v == 3:
  44. result = 50
  45. elif v == 4:
  46. result = 40
  47. elif v == 5:
  48. result = 30
  49. elif v == 6:
  50. result = 10
  51. elif v > 6:
  52. result = 0
  53. scores.append((0.0467602, result))
  54. elif k == "bh10022":
  55. if v == 0:
  56. result = 100
  57. elif v == 1:
  58. result = 70
  59. elif v == 2:
  60. result = 35
  61. elif v == 3:
  62. result = 5
  63. scores.append((0.039446769, result))
  64. elif k == "bh10019":
  65. if v == 0:
  66. result = 80
  67. elif v == 1:
  68. result = 100
  69. elif v == 2:
  70. result = 40
  71. elif v == 3:
  72. result = 5
  73. scores.append((0.045120359, result))
  74. elif k == "bh10023":
  75. if v == 0:
  76. result = 100
  77. elif v == 1:
  78. result = 70
  79. elif v == 2:
  80. result = 40
  81. elif v == 3:
  82. result = 10
  83. scores.append((0.043568957, result))
  84. elif k == "bh10009":
  85. if v == 0:
  86. result = 100
  87. elif 0 < v <= 15:
  88. result = 80
  89. elif 15 < v <= 25:
  90. result = 60
  91. elif 25 < v <= 35:
  92. result = 40
  93. elif 35 < v <= 50:
  94. result = 20
  95. elif v > 50:
  96. result = 0
  97. scores.append((0.092601792, result))
  98. elif k == "bh10016":
  99. if v == 0:
  100. result = 85
  101. elif v == 1:
  102. result = 100
  103. elif v == 2:
  104. result = 50
  105. elif v == 3:
  106. result = 8
  107. scores.append((0.056671171, result))
  108. elif k == "bh10024":
  109. if v == 0:
  110. result = 100
  111. elif v == 1:
  112. result = 70
  113. elif v == 2:
  114. result = 50
  115. elif v == 3:
  116. result = 25
  117. elif v == 4:
  118. result = 5
  119. scores.append((0.049505696, result))
  120. elif k == "bh10017":
  121. if v == 0:
  122. result = 75
  123. elif v == 1:
  124. result = 100
  125. elif v == 2:
  126. result = 40
  127. elif v == 3:
  128. result = 10
  129. scores.append((0.052926182, result))
  130. elif k == "bh10027":
  131. if v == 0:
  132. result = 100
  133. elif v == 1:
  134. result = 60
  135. elif v > 1:
  136. result = 0
  137. scores.append((0.054838899, result))
  138. elif k == "cnName":
  139. if v == 0:
  140. result = 100
  141. elif v == 1:
  142. result = 90
  143. elif v == 2:
  144. result = 85
  145. elif v == 3:
  146. result = 80
  147. elif 4 <= v <= 8:
  148. result = 70
  149. elif 8 < v <= 12:
  150. result = 50
  151. elif 12 < v <= 15:
  152. result = 30
  153. elif v > 15:
  154. result = 0
  155. scores.append((0.071630387, result))
  156. elif k == "cnNameLM":
  157. if v == 0:
  158. result = 100
  159. elif v == 1:
  160. result = 90
  161. elif v == 2:
  162. result = 85
  163. elif v == 3:
  164. result = 80
  165. elif 4 <= v <= 8:
  166. result = 70
  167. elif 8 < v <= 12:
  168. result = 50
  169. elif 12 < v <= 15:
  170. result = 30
  171. elif v > 15:
  172. result = 0
  173. scores.append((0.066097986, result))
  174. elif k == "cnRuleType":
  175. if v == 0:
  176. result = 100
  177. elif v == 1:
  178. result = 90
  179. elif v == 2:
  180. result = 70
  181. elif v == 3:
  182. result = 40
  183. elif v == 4:
  184. result = 0
  185. scores.append((0.072776513, result))
  186. elif k == "personCheatIndices":
  187. if v == -1:
  188. result = -1
  189. elif v == 0:
  190. result = 100
  191. elif v == 1:
  192. result = 80
  193. elif v == 2:
  194. result = 60
  195. elif v == 3:
  196. result = 40
  197. elif v > 3:
  198. result = 0
  199. scores.append((0.0736, result))
  200. return scores
  201. def coalesce(scores):
  202. hb_score = 0
  203. flag = False
  204. for p in scores:
  205. coefficient = p[0]
  206. score = p[1]
  207. if score == -1:
  208. flag = True
  209. hb_score += coefficient * score / 0.884267752
  210. hb_score = round(hb_score, 10)
  211. if flag:
  212. return 70
  213. else:
  214. return hb_score
  215. def is_numeric(value):
  216. try:
  217. float(value)
  218. return True
  219. except ValueError:
  220. return False
  221. keys = ['bh10022', 'cnRuleType', 'bh10025', 'bh10024', 'bh10023', 'bh10019', 'personCheatIndices', 'bh10018', 'bh10006', 'cnNameLM', 'bh10017', 'bh10016', 'bh10027', 'huhhuhuhuhuResult', 'cnName', 'bh10009']
  222. obj = {key: obj[key] for key in keys if key in keys}
  223. for key in obj.keys():
  224. if not is_numeric(obj[key]):
  225. obj['abc'] = 70
  226. break
  227. if obj["personCheatIndices"] == "-1":
  228. obj['abc'] = 70
  229. else:
  230. result = coalesce(data_pretreatment(obj))
  231. obj['abc'] = result
  232. return obj
  233. print(exec({
  234. "bh10022": "1",
  235. "cnRuleType": "2",
  236. "child_flow_base_url": "http://rxdp-flow:8080",
  237. "bh10025": "1.38",
  238. "bh10024": "3",
  239. "bh10023": "2",
  240. "bh10019": "3",
  241. "personCheatIndices": "0",
  242. "bh10018": "2",
  243. "flow_reused_global_flag": "0.0",
  244. "bh10006": "14",
  245. "cnNameLM": "21",
  246. "bh10017": "3",
  247. "bh10016": "2",
  248. "bh10027": "0",
  249. "huhhuhuhuhuResult": "50.9627708497",
  250. "current_flow_ip_address": "172.16.45.34",
  251. "cnName": "21",
  252. "bh10009": "23",
  253. "flow_process_trace": {
  254. "20014": []
  255. },
  256. "abc": "70.0"
  257. }))