/AccuTime_Statistic.py

https://gitlab.com/m10774708/dotcode · Python · 746 lines · 613 code · 82 blank · 51 comment · 60 complexity · 21e12f5f2fba2c689306baf20eb68428 MD5 · raw file

  1. import numpy as np
  2. import pandas as pd
  3. import traceback
  4. import os
  5. import time
  6. import datetime
  7. import gc
  8. import PaperCommon as pc
  9. if __name__ == '__main__':
  10. '''Insert average correct percentage every y seconds from AccuTime to AccuTime_sta'''
  11. choice = input("開始執行程式(y)Yes(other)No:")
  12. if choice.upper() != 'Y':
  13. os._exit(0)
  14. startTime = time.time()
  15. peo = 0 #有紀錄的玩家
  16. countInsert = 0 #insert的筆數
  17. sectionDegree = pc.sections_degrees()
  18. playerDegree = pc.players_degrees()
  19. database = 'dotCode'
  20. game = 'Duck'
  21. db = pc.clientDB(database)
  22. #一般秒用x, ylog秒用m, nZ用p, q Zlog用u, v
  23. x = 999999
  24. y = 10
  25. m = 20
  26. n = 0.1
  27. p = 500
  28. q = 1
  29. u = 2
  30. v = 0.01
  31. #原資料庫建索引
  32. collection = 'AccuTime'
  33. ct = pc.clientCT(database, collection)
  34. #1.依關卡
  35. ct.create_index([('gameCode', 1), ('sectionId', 1), ('gameStar', 1), ('accuTime_sec', 1)])
  36. ct.create_index([('sectionId', 1), ('gameStar', 1), ('accuTime_sec', 1)])
  37. #2.依難度
  38. ct.create_index([('gameCode', 1), ('eloDegree', 1), ('gameStar', 1),('accuTime_sec', 1)])
  39. ct.create_index([('eloDegree', 1), ('gameStar', 1),('accuTime_sec', 1)])
  40. #3.依時間
  41. ct.create_index([('gameCode', 1), ('accuTime_sec', 1)])
  42. ct.create_index([('accuTime_sec', 1)])
  43. #4.依玩家等級
  44. ct.create_index([('gameCode', 1), ('playerDegree_kmeans', 1), ('gameStar', 1),('accuTime_sec', 1)])
  45. ct.create_index([('playerDegree_kmeans', 1), ('gameStar', 1),('accuTime_sec', 1)])
  46. #新資料庫建索引
  47. #1.依關卡
  48. db.AccuTime_sta.create_index([('gameCode', 1), ('sectionId', 1), ('seconds', 1), ('tickTime', 1), ('gameStar', 1)])
  49. db.AccuTimeLog_sta.create_index([('gameCode', 1), ('sectionId', 1), ('seconds_log', 1), ('tickTime', 1), ('gameStar', 1)])
  50. #2.依難度
  51. db.AccuTime_sta.create_index([('gameCode', 1), ('sectionId', 1), ('seconds', 1), ('tickTime', 1), ('gameStar', 1), ('difficulty', 1), ('eloDegree', 1)])
  52. db.AccuTimeLog_sta.create_index([('gameCode', 1), ('sectionId', 1), ('seconds_log', 1), ('tickTime', 1), ('gameStar', 1), ('difficulty', 1), ('eloDegree', 1)])
  53. #3.依時間(AccuTime_sta與AccuTimeLog_sta不建與難度相同)
  54. db.AccuTimeZ_sta.create_index([('gameCode', 1), ('seconds_z', 1), ('tickTime', 1), ('gameStar', 1)])
  55. AccuTime_count = 0
  56. AccuTimeLog_count = 0
  57. AccuTimeZ_count = 0
  58. maxSection = pc.find_maxSection(game)
  59. sectionId, item_difficulty, eloDegree = pc.add_difficulty(game, 1)
  60. ##step1依關卡)
  61. print("insert {} data by section".format(game))
  62. for section in range(1, maxSection+1):
  63. allPeople, allCorrectness, allTryCount = [], [], []
  64. allPeople = pc.create_lists(1, int(x//y)+2, 0)
  65. allCorrectness = pc.create_lists(1, int(x//y)+2, 0)
  66. allTryCount = pc.create_lists(1, int(x//y)+2, 0)
  67. allPeople_log, allCorrectness_log, allTryCount_log = [], [], []
  68. allPeople_log = pc.create_lists(0, int(m//n)+1, 0)
  69. allCorrectness_log = pc.create_lists(0, int(m//n)+1, 0)
  70. allTryCount_log = pc.create_lists(0, int(m//n)+1, 0)
  71. passPeople, passCorrectness, passTryCount = [], [], []
  72. passPeople = pc.create_lists(1, int(x//y)+2, 0)
  73. passCorrectness = pc.create_lists(1, int(x//y)+2, 0)
  74. passTryCount = pc.create_lists(1, int(x//y)+2, 0)
  75. passPeople_log,passCorrectness_log, passTryCount_log = [], [], []
  76. passPeople_log = pc.create_lists(0, int(m//n)+1, 0)
  77. passCorrectness_log = pc.create_lists(0, int(m//n)+1, 0)
  78. passTryCount_log = pc.create_lists(0, int(m//n)+1, 0)
  79. for star in range(0, 5):
  80. people, correctness, tryCount = [], [], []
  81. people = pc.create_lists(1, int(x//y)+2, 0)
  82. correctness = pc.create_lists(1, int(x//y)+2, 0)
  83. tryCount = pc.create_lists(1, int(x//y)+2, 0)
  84. people_log, correctness_log, tryCount_log= [], [], []
  85. people_log = pc.create_lists(0, int(m//n)+1, 0)
  86. correctness_log = pc.create_lists(0, int(m//n)+1, 0)
  87. tryCount_log = pc.create_lists(0, int(m//n)+1, 0)
  88. for one in ct.find({"gameCode":game, "sectionId":section, "gameStar":star, "accuTime_sec":{"$gt":0, "$lte":x}}):
  89. try:
  90. a = int(one['accuTime_sec']//y)
  91. people[a] += 1
  92. correctness[a] += one['correctPercentage']
  93. tryCount[a] += one['tryCount']
  94. allPeople[a] += 1
  95. allCorrectness[a] += one['correctPercentage']
  96. allTryCount[a] += one['tryCount']
  97. if star > 0:
  98. passPeople[a] += 1
  99. passCorrectness[a] += one['correctPercentage']
  100. passTryCount[a] += one['tryCount']
  101. b = int(one['logAccuTime_sec']//n)+24
  102. people_log[b] += 1
  103. correctness_log[b] += one['correctPercentage']
  104. tryCount_log[b] += one['tryCount']
  105. allPeople_log[b] += 1
  106. allCorrectness_log[b] += one['correctPercentage']
  107. allTryCount_log[b] += one['tryCount']
  108. if star > 0:
  109. passPeople_log[b] += 1
  110. passCorrectness_log[b] += one['correctPercentage']
  111. passTryCount_log[b] += one['tryCount']
  112. except:
  113. traceback.print_exc()
  114. #分星星
  115. #
  116. for seconds, i_count, i_correct, i_try in zip(range(y, x+y+1, y), people, correctness, tryCount):
  117. if i_count > 0:
  118. #print("seconds:", seconds, "i_count:", i_count, "try", i_try, "i_correct:", i_correct/i_count)
  119. #os.system("pause")
  120. AccuTime_sta_dict = {"gameCode":game,
  121. "sectionId":section,
  122. "seconds":seconds,
  123. "tickTime":y,
  124. "gameStar":star,
  125. "people":i_count,
  126. "difficulty":item_difficulty[section-1],
  127. "eloDegree":eloDegree[section-1],
  128. "avgCorrectness":i_correct/i_count,
  129. "avgTryCount":i_try/i_count,
  130. "step":"1-1"
  131. }
  132. db.AccuTime_sta.update_one({"gameCode":game, "sectionId":section, "seconds":seconds, "tickTime":y, "gameStar":star}, {'$set':AccuTime_sta_dict}, upsert = True)
  133. AccuTime_count += 1
  134. #Log秒
  135. for seconds_log, i_count_log, i_correct_log, i_try_log in zip(np.arange(-2.4, m+n, n), people_log, correctness_log, tryCount_log):
  136. if i_count_log > 0:
  137. AccuTimeLog_sta_dict = {"gameCode":game,
  138. "sectionId":section,
  139. "seconds_log":round(seconds_log, 2),
  140. "tickTime":n,
  141. "gameStar":star,
  142. "people":i_count_log,
  143. "difficulty":item_difficulty[section-1],
  144. "eloDegree":eloDegree[section-1],
  145. "avgCorrectness":i_correct_log/i_count_log,
  146. "avgTryCount":i_try_log/i_count_log,
  147. "step":"1-1"
  148. }
  149. db.AccuTimeLog_sta.update_one({"gameCode":game, "sectionId":section, "seconds_log":round(seconds_log, 2), "tickTime":n, "gameStar":star}, {'$set':AccuTimeLog_sta_dict}, upsert = True)
  150. AccuTimeLog_count += 1
  151. del people, correctness, tryCount, people_log, correctness_log, tryCount_log
  152. gc.collect()
  153. #不分星
  154. #
  155. for seconds_all, i_count_all, i_correct_all, i_try_all in zip(range(y, x+y+1, y), allPeople, allCorrectness, allTryCount):
  156. if i_count_all > 0:
  157. #print("seconds:", seconds, "i_count:", i_count, "i_correct:", i_correct)
  158. AccuTimeAll_sta_dict = {"gameCode":game,
  159. "sectionId":section,
  160. "seconds":seconds_all,
  161. "tickTime":y,
  162. "gameStar":5, #5是不分星星數
  163. "people":i_count_all,
  164. "difficulty":item_difficulty[section-1],
  165. "eloDegree":eloDegree[section-1],
  166. "avgCorrectness":i_correct_all/i_count_all,
  167. "avgTryCount":i_try_all/i_count_all,
  168. "step":"1-2"
  169. }
  170. db.AccuTime_sta.update_one({"gameCode":game, "sectionId":section, "seconds":seconds_all, "tickTime":y, "gameStar":5}, {'$set':AccuTimeAll_sta_dict}, upsert = True)
  171. AccuTime_count += 1
  172. #log秒
  173. for seconds_all_log, i_count_all_log, i_correct_all_log, i_try_all_log, in zip(np.arange(-2.4, m+n, n), allPeople_log, allCorrectness_log, allTryCount_log):
  174. if i_count_all_log > 0:
  175. AccuTimeAllLog_sta_dict = {"gameCode":game,
  176. "sectionId":section,
  177. "seconds_log":round(seconds_all_log, 2),
  178. "tickTime":n,
  179. "gameStar":5, #5是不分星星數
  180. "people":i_count_all_log,
  181. "difficulty" : item_difficulty[section-1],
  182. "eloDegree" : eloDegree[section-1],
  183. "avgCorrectness" : i_correct_all_log/i_count_all_log,
  184. "avgTryCount" : i_try_all_log/i_count_all_log,
  185. "step":"1-2"
  186. }
  187. db.AccuTimeLog_sta.update_one({"gameCode":game, "sectionId":section, "seconds_log":round(seconds_all_log, 2), "tickTime":n, "gameStar":5}, {'$set':AccuTimeAllLog_sta_dict}, upsert = True)
  188. AccuTimeLog_count += 1
  189. del allPeople, allCorrectness ,allTryCount, allPeople_log, allCorrectness_log, allTryCount_log
  190. gc.collect()
  191. #只算有過關
  192. #
  193. for seconds_pass, i_count_pass, i_correct_pass, i_try_pass in zip(range(y, x+y+1, y), passPeople, passCorrectness, passTryCount):
  194. if i_count_pass > 0:
  195. AccuTimePass_sta_dict = {"gameCode":game,
  196. "sectionId":section,
  197. "seconds":seconds_pass,
  198. "tickTime":y,
  199. "gameStar":6, #6是有過關
  200. "people":i_count_pass,
  201. "difficulty":item_difficulty[section-1],
  202. "eloDegree":eloDegree[section-1],
  203. "avgCorrectness":i_correct_pass/i_count_pass,
  204. "avgTryCount":i_try_pass/i_count_pass,
  205. "step":"1-3"
  206. }
  207. db.AccuTime_sta.update_one({"gameCode":game, "sectionId":section, "seconds":seconds_pass, "tickTime":y, "gameStar":6}, {'$set':AccuTimePass_sta_dict}, upsert = True)
  208. AccuTime_count += 1
  209. #log秒
  210. for seconds_pass_log, i_count_pass_log, i_correct_pass_log, i_try_pass_log, in zip(np.arange(-2.4, m+n, n), passPeople_log, passCorrectness_log, passTryCount_log):
  211. if i_count_pass_log > 0:
  212. AccuTimePassLog_sta_dict = {"gameCode":game,
  213. "sectionId":section,
  214. "seconds_log":round(seconds_pass_log, 2),
  215. "tickTime":n,
  216. "gameStar":6, #6是有過關
  217. "people":i_count_pass_log,
  218. "difficulty" : item_difficulty[section-1],
  219. "eloDegree" : eloDegree[section-1],
  220. "avgCorrectness" : i_correct_pass_log/i_count_pass_log,
  221. "avgTryCount" : i_try_pass_log/i_count_pass_log,
  222. "step":"1-3"
  223. }
  224. db.AccuTimeLog_sta.update_one({"gameCode":game, "sectionId":section, "seconds_log":round(seconds_pass_log, 2), "tickTime":n, "gameStar":6}, {'$set':AccuTimePassLog_sta_dict}, upsert = True)
  225. AccuTimeLog_count += 1
  226. del passPeople, passCorrectness ,passTryCount, passPeople_log, passCorrectness_log, passTryCount_log
  227. gc.collect()
  228. ##step2依難度等級
  229. print("insert %s data by difficulty degree" %game)
  230. playerDegree = [num for num in range ]
  231. for i in range(0, len(degree)):
  232. allPeople, allCorrectness, alltryCount = [], [], []
  233. allPeople = pc.create_lists(1, int(x//y)+2, 0)
  234. allCorrectness = pc.create_lists(1, int(x//y)+2, 0)
  235. alltryCount = pc.create_lists(1, int(x//y)+2, 0)
  236. allPeople_log, allCorrectness_log, alltryCount_log = [], [], []
  237. allPeople_log = pc.create_lists(0, int(m//n)+1, 0)
  238. allCorrectness_log = pc.create_lists(0, int(m//n)+1, 0)
  239. alltryCount_log = pc.create_lists(0, int(m//n)+1, 0)
  240. passPeople, passCorrectness, passtryCount = [], [], []
  241. passPeople = pc.create_lists(1, int(x//y)+2, 0)
  242. passCorrectness = pc.create_lists(1, int(x//y)+2, 0)
  243. passtryCount = pc.create_lists(1, int(x//y)+2, 0)
  244. passPeople_log, passCorrectness_log, passtryCount_log = [], [], []
  245. passPeople_log = pc.create_lists(0, int(m//n)+1, 0)
  246. passCorrectness_log = pc.create_lists(0, int(m//n)+1, 0)
  247. passtryCount_log = pc.create_lists(0, int(m//n)+1, 0)
  248. for star in range(0, 5):
  249. people, correctness, tryCount = [], [], []
  250. people = pc.create_lists(1, int(x//y)+2, 0)
  251. correctness = pc.create_lists(1, int(x//y)+2, 0)
  252. tryCount = pc.create_lists(1, int(x//y)+2, 0)
  253. people_log, correctness_log, tryCount_log = [], [], []
  254. people_log = pc.create_lists(1, int(m//n)+2, 0)
  255. correctness_log = pc.create_lists(1, int(m//n)+2, 0)
  256. tryCount_log = pc.create_lists(1, int(m//n)+2, 0)
  257. for two in ct.find({"gameCode":game, "eloDegree":degree[i], "gameStar":star, "accuTime_sec":{"$gt":0, "$lte":x}}):
  258. try:
  259. a = int(two['accuTime_sec'] // y)
  260. people[a] += 1
  261. correctness[a] += two['correctPercentage']
  262. tryCount[a] += two['tryCount']
  263. allPeople[a] += 1
  264. allCorrectness[a] += two['correctPercentage']
  265. alltryCount[a] += two['tryCount']
  266. if star > 0:
  267. passPeople[a] += 1
  268. passCorrectness[a] += two['correctPercentage']
  269. passtryCount[a] += two['tryCount']
  270. b = int(two['logAccuTime_sec']//n)+24
  271. people_log[b] += 1
  272. correctness_log[b] += two['correctPercentage']
  273. tryCount_log[b] += two['tryCount']
  274. allPeople_log[b] += 1
  275. allCorrectness_log[b] += two['correctPercentage']
  276. alltryCount_log[b] += two['tryCount']
  277. if star > 0:
  278. passPeople_log[b] += 1
  279. passCorrectness_log[b] += two['correctPercentage']
  280. passtryCount_log[b] += two['tryCount']
  281. except:
  282. print(two)
  283. #分星星
  284. for seconds, i_count, i_correct, i_try in zip(range(y, x+y+1, y), people, correctness, tryCount):
  285. if i_count > 0:
  286. #print("seconds:", seconds, "i_count:", i_count, "try", i_try, "correct:", i_correct/i_count)
  287. #os.system("pause")
  288. AccuTime_sta_dict = {"gameCode":game,
  289. "sectionId":0,
  290. "seconds":seconds,
  291. "tickTime":y,
  292. "gameStar":star,
  293. "people":i_count,
  294. "difficulty":None,
  295. "eloDegree":degree[i],
  296. "avgCorrectness":i_correct/i_count,
  297. "avgTryCount":i_try/i_count,
  298. "step":"2-1"
  299. }
  300. db.AccuTime_sta.update_one({"gameCode": game,
  301. "sectionId":0,
  302. "seconds":seconds,
  303. "tickTime":y,
  304. "gameStar":star,
  305. "difficulty":None,
  306. "eloDegree":degree[i]
  307. },
  308. {'$set': AccuTime_sta_dict},
  309. upsert = True
  310. )
  311. AccuTime_count += 1
  312. for seconds_log, i_count_log, i_correct_log, i_try_log in zip(np.arange(-2.4, m+n, n), people_log, correctness_log, tryCount_log):
  313. if i_count_log > 0:
  314. AccuTimeLog_sta_dict = {"gameCode":game,
  315. "sectionId":0,
  316. "seconds_log":round(seconds_log, 2),
  317. "tickTime":n,
  318. "gameStar":star,
  319. "people":i_count_log,
  320. "difficulty":None,
  321. "eloDegree":degree[i],
  322. "avgCorrectness":i_correct_log/i_count_log,
  323. "avgTryCount":i_try_log/i_count_log,
  324. "step":"2-1"
  325. }
  326. db.AccuTimeLog_sta.update_one({"gameCode":game, "seconds_log":round(seconds_log, 2), "tickTime":n, "gameStar":star, "difficulty":None, "eloDegree":degree[i]}, {'$set':AccuTimeLog_sta_dict}, upsert = True)
  327. AccuTimeLog_count += 1
  328. del people, correctness, tryCount, people_log, correctness_log, tryCount_log
  329. gc.collect()
  330. #不分星
  331. #
  332. for seconds_all, i_count_all, i_correct_all, i_try_all in zip(range(y, x+y+1, y), allPeople, allCorrectness, alltryCount):
  333. if i_count_all > 0:
  334. #print("seconds:", seconds, "i_count:", i_count, "correct:", correct)
  335. AccuTimeALL_sta_dict = {"gameCode" : game,
  336. "sectionId": 0,
  337. "seconds": seconds_all,
  338. "tickTime" : y,
  339. "gameStar" : 5,
  340. "people" : i_count_all,
  341. "difficulty" : None,
  342. "eloDegree" : degree[i],
  343. "avgCorrectness" : i_correct_all/i_count_all,
  344. "avgTryCount" : i_try_all/i_count_all,
  345. "step":"2-2"
  346. }
  347. db.AccuTime_sta.update_one({"gameCode":game,
  348. "sectionId":0,
  349. "seconds":seconds_all,
  350. "tickTime":y,
  351. "gameStar":5,
  352. "difficulty":None,
  353. "eloDegree":degree[i]
  354. },
  355. {'$set': AccuTimeALL_sta_dict},
  356. upsert = True
  357. )
  358. AccuTime_count += 1
  359. #log秒
  360. for seconds_all_log, i_count_all_log, i_correct_all_log, i_try_all_log in zip(np.arange(-2.4, m+n, n), allPeople_log, allCorrectness_log, alltryCount_log):
  361. if i_count_all_log > 0:
  362. AccuTimeAllLog_sta_dict = {"gameCode":game,
  363. "sectionId":0,
  364. "seconds_log":round(seconds_all_log, 2),
  365. "tickTime":n,
  366. "gameStar":5,
  367. "people":i_count_all_log,
  368. "difficulty":None,
  369. "eloDegree":degree[i],
  370. "avgCorrectness":i_correct_all_log/i_count_all_log,
  371. "avgTryCount":i_try_all_log/i_count_all_log,
  372. "step":"2-2"
  373. }
  374. db.AccuTimeLog_sta.update_one({"gameCode":game, "sectionId":0, "seconds_log":round(seconds_all_log, 2), "tickTime":n, "gameStar":5, "difficulty":None, "eloDegree":degree[i]}, {'$set': AccuTimeAllLog_sta_dict}, upsert = True)
  375. AccuTimeLog_count += 1
  376. del allPeople, allCorrectness, alltryCount, allPeople_log, allCorrectness_log, alltryCount_log
  377. gc.collect()
  378. #只算有過關
  379. #
  380. for seconds_pass, i_count_pass, i_correct_pass, i_try_pass in zip(range(y, x+y+1, y), passPeople, passCorrectness, passtryCount):
  381. if i_count_pass > 0:
  382. #print("seconds:", seconds, "i_count:", i_count, "correct:", correct)
  383. AccuTimePass_sta_dict = {"gameCode" : game,
  384. "sectionId": 0,
  385. "seconds": seconds_pass,
  386. "tickTime" : y,
  387. "gameStar" : 6,
  388. "people" : i_count_pass,
  389. "difficulty" : None,
  390. "eloDegree" : degree[i],
  391. "avgCorrectness" : i_correct_pass/i_count_pass,
  392. "avgTryCount" : i_try_pass/i_count_pass,
  393. "step":"2-3"
  394. }
  395. db.AccuTime_sta.update_one({"gameCode":game,
  396. "sectionId":0,
  397. "seconds":seconds_pass,
  398. "tickTime":y,
  399. "gameStar":6,
  400. "difficulty":None,
  401. "eloDegree":degree[i]
  402. },
  403. {'$set': AccuTimePass_sta_dict},
  404. upsert = True
  405. )
  406. AccuTime_count += 1
  407. #log秒
  408. for seconds_pass_log, i_count_pass_log, i_correct_pass_log, i_try_pass_log in zip(np.arange(-2.4, m+n, n), passPeople_log, passCorrectness_log, passtryCount_log):
  409. if i_count_pass_log > 0:
  410. AccuTimePassLog_sta_dict = {"gameCode":game,
  411. "sectionId":0,
  412. "seconds_log":round(seconds_pass_log, 2),
  413. "tickTime":n,
  414. "gameStar":6,
  415. "people":i_count_pass_log,
  416. "difficulty":None,
  417. "eloDegree":degree[i],
  418. "avgCorrectness":i_correct_pass_log/i_count_pass_log,
  419. "avgTryCount":i_try_pass_log/i_count_pass_log,
  420. "step":"2-3"
  421. }
  422. db.AccuTimeLog_sta.update_one({"gameCode":game, "sectionId":0, "seconds_log":round(seconds_pass_log, 2), "tickTime":n, "gameStar":6, "difficulty":None, "eloDegree":degree[i]}, {'$set':AccuTimePassLog_sta_dict}, upsert = True)
  423. AccuTimeLog_count += 1
  424. del passPeople, passCorrectness, passtryCount, passPeople_log, passCorrectness_log, passtryCount_log
  425. gc.collect()
  426. ##step3依時間
  427. print("insert %s data by time" %game)
  428. #這裡跟Difficulty相關的欄位是用來平均難度
  429. allPeople, allCorrectness, allDifficulty, allTryCount = [], [], [], []
  430. allPeople = pc.create_lists(0, int(x//y)+1, 0)
  431. allCorrectness = pc.create_lists(0, int(x//y)+1, 0)
  432. allDifficulty = pc.create_lists(0, int(x//y)+1, 0)
  433. allTryCount = pc.create_lists(0, int(x//y)+1, 0)
  434. allPeople_log, allCorrectness_log, allDifficulty_log, allTryCount_log = [], [], [], []
  435. allPeople_log = pc.create_lists(0, int(m//n)+1, 0)
  436. allCorrectness_log = pc.create_lists(0, int(m//n)+1, 0)
  437. allDifficulty_log = pc.create_lists(0, int(m//n)+1, 0)
  438. allTryCount_log = pc.create_lists(0, int(m//n)+1, 0)
  439. passPeople, passCorrectness, passDifficulty, passTryCount = [], [], [], []
  440. passPeople = pc.create_lists(0, int(x//y)+1, 0)
  441. passCorrectness = pc.create_lists(0, int(x//y)+1, 0)
  442. passDifficulty = pc.create_lists(0, int(x//y)+1, 0)
  443. passTryCount = pc.create_lists(0, int(x//y)+1, 0)
  444. passPeople_log, passCorrectness_log, passDifficulty_log, passTryCount_log = [], [], [], []
  445. passPeople_log = pc.create_lists(0, int(m//n)+1, 0)
  446. passCorrectness_log = pc.create_lists(0, int(m//n)+1, 0)
  447. passDifficulty_log = pc.create_lists(0, int(m//n)+1, 0)
  448. passTryCount_log = pc.create_lists(0, int(m//n)+1, 0)
  449. allzPeople, allzCorrectness, allzDifficulty, allzTryCount = [], [], [], []
  450. allzPeople = pc.create_lists(0, int(p//q)+1, 0)
  451. allzCorrectness = pc.create_lists(0, int(p//q)+1, 0)
  452. allzDifficulty = pc.create_lists(0, int(p//q)+1, 0)
  453. allzTryCount = pc.create_lists(0, int(p//q)+1, 0)
  454. for star in range(0, 5):
  455. people, correctness, tryCount, difficulty = [], [], [], []
  456. people = pc.create_lists(1, int(x//y)+2, 0)
  457. correctness = pc.create_lists(1, int(x//y)+2, 0)
  458. tryCount = pc.create_lists(1, int(x//y)+2, 0)
  459. difficulty = pc.create_lists(1, int(x//y)+2, 0)
  460. people_log, correctness_log, tryCount_log, difficulty_log = [], [], [], []
  461. people_log = pc.create_lists(1, int(m//n)+2, 0)
  462. correctness_log = pc.create_lists(1, int(m//n)+2, 0)
  463. tryCount_log = pc.create_lists(1, int(m//n)+2, 0)
  464. difficulty_log = pc.create_lists(1, int(m//n)+2, 0)
  465. zPeople, zCorrectness, zDifficulty, zTryCount = [], [], [], []
  466. zPeople = pc.create_lists(0, int(p//q)+1, 0)
  467. zCorrectness = pc.create_lists(0, int(p//q)+1, 0)
  468. zDifficulty = pc.create_lists(0, int(p//q)+1, 0)
  469. zTryCount = pc.create_lists(0, int(p//q)+1, 0)
  470. zPeople_log, zCorrectness_log, zDifficulty_log, zTryCount_log = [], [], [], []
  471. zPeople_log = pc.create_lists(0, int(u//v)+1, 0)
  472. zCorrectness_log = pc.create_lists(0, int(u//v)+1, 0)
  473. zDifficulty_log = pc.create_lists(0, int(u//v)+1, 0)
  474. zTryCount_log = pc.create_lists(0, int(u//v)+1, 0)
  475. error = 0
  476. for three in ct.find({"gameCode":game, "gameStar":star, "accuTime_sec":{"$gt":0, "$lte":x}}):
  477. try:
  478. a = int(three['accuTime_sec'] // y)
  479. people[a] += 1
  480. correctness[a] += three['correctPercentage']
  481. difficulty[a] += three['difficulty']
  482. tryCount[a] += three['tryCount']
  483. allPeople[a] += 1
  484. allCorrectness[a] += three['correctPercentage']
  485. allDifficulty[a] += three['difficulty']
  486. allTryCount[a] += three['tryCount']
  487. if star > 0:
  488. passPeople[a] += 1
  489. passCorrectness[a] += three['correctPercentage']
  490. passDifficulty[a] += three['difficulty']
  491. passTryCount[a] += three['tryCount']
  492. b = int(three['logAccuTime_sec']//n)+24
  493. people_log[b] += 1
  494. correctness_log[b] += three['correctPercentage']
  495. difficulty_log[b] += three['difficulty']
  496. tryCount_log[b] += three['tryCount']
  497. allPeople_log[b] += 1
  498. allCorrectness_log[b] += three['correctPercentage']
  499. allDifficulty_log[b] += three['difficulty']
  500. allTryCount_log[b] += three['tryCount']
  501. if star > 0:
  502. passPeople_log[b] += 1
  503. passCorrectness_log[b] += three['correctPercentage']
  504. passDifficulty_log[b] += three['difficulty']
  505. passTryCount_log[b] += three['tryCount']
  506. #c = int(three['ZTime']//q)+8
  507. c = int(three['ZTime']//q)+1
  508. zPeople[c] += 1
  509. zCorrectness[c] += three['correctPercentage']
  510. zDifficulty[c] += three['difficulty']
  511. zTryCount[c] += three['tryCount']
  512. allzPeople[c] += 1
  513. allzCorrectness[c] += three['correctPercentage']
  514. allzDifficulty[c] += three['difficulty']
  515. allzTryCount[c] += three['tryCount']
  516. except:
  517. error += 1
  518. #print(error, three)
  519. #分星星
  520. #
  521. for seconds, i_count, i_correct, i_try, i_difficulty in zip(range(y, x+y+1, y), people, correctness, tryCount, difficulty):
  522. if i_count > 0:
  523. AccuTime_sta_dict = {"gameCode":game,
  524. "sectionId":0,
  525. "seconds":seconds,
  526. "tickTime":y,
  527. "gameStar":star,
  528. "people":i_count,
  529. "difficulty":i_difficulty/i_count,
  530. "eloDegree":'n',
  531. "avgCorrectness":i_correct/i_count,
  532. "avgTryCount":i_try/i_count,
  533. "step":"3-1"
  534. }
  535. db.AccuTime_sta.update_one({"gameCode":game, "sectionId":0, "seconds":seconds, "tickTime":y, "gameStar":star, "eloDegree":'n'}, {'$set':AccuTime_sta_dict}, upsert = True)
  536. AccuTime_count += 1
  537. #Log秒
  538. for seconds_log, i_count_log, i_correct_log, i_try_log, i_difficulty_log in zip(np.arange(-2.4, m+n, n), people_log, correctness_log, tryCount_log, difficulty_log):
  539. if i_count_log > 0:
  540. AccuTimeLog_sta_dict = {"gameCode":game,
  541. "sectionId":0,
  542. "seconds_log":round(seconds_log, 2),
  543. "tickTime":n,
  544. "gameStar":star,
  545. "people":i_count_log,
  546. "difficulty":i_difficulty_log/i_count_log,
  547. "eloDegree":'n',
  548. "avgCorrectness":i_correct_log/i_count_log,
  549. "avgTryCount":i_try_log/i_count_log,
  550. "step":"3-1"
  551. }
  552. db.AccuTimeLog_sta.update_one({"gameCode":game, "sectionId":0, "seconds_log":round(seconds_log, 2), "tickTime":n, "gameStar":star, "eloDegree":'n'}, {'$set':AccuTimeLog_sta_dict}, upsert = True)
  553. AccuTimeLog_count += 1
  554. #ZTime
  555. #for z_seconds, z_count, z_correct, z_try, z_difficulty in zip(np.arange(-1, p+q, q), zPeople, zCorrectness, zTryCount, zDifficulty):
  556. for z_seconds, z_count, z_correct, z_try, z_difficulty in zip(range(-1, p+q, q), zPeople, zCorrectness, zTryCount, zDifficulty):
  557. if z_count > 0:
  558. AccuTimeZ_sta_dict = {"gameCode":game,
  559. "sectionId":0,
  560. "seconds_z":z_seconds,#round(z_seconds, 2),
  561. "tickTime":q,
  562. "gameStar":star,
  563. "people":z_count,
  564. "difficulty":z_difficulty/z_count,
  565. "eloDegree":'n',
  566. "avgCorrectness":z_correct/z_count,
  567. "avgTryCount":z_try/z_count,
  568. "step":"3-1"
  569. }
  570. db.AccuTimeZ_sta.update_one({"gameCode":game, "sectionId":0, "seconds_z":z_seconds, "tickTime":q, "gameStar":star}, {'$set':AccuTimeZ_sta_dict}, upsert = True)
  571. AccuTimeZ_count += 1
  572. del people, correctness, tryCount, difficulty, people_log, correctness_log, tryCount_log, difficulty_log, zPeople, zCorrectness, zTryCount, zDifficulty
  573. gc.collect()
  574. #不分星星
  575. #
  576. for seconds_all, i_count_all, i_correct_all, i_difficulty_all, i_try_all in zip(range(0, x+y, y), allPeople, allCorrectness, allDifficulty, allTryCount):
  577. if i_count_all > 0:
  578. AccuTimeAll_sta_dict = {"gameCode":game,
  579. "sectionId":0,
  580. "seconds":seconds_all,
  581. "tickTime":y,
  582. "gameStar":5,
  583. "people":i_count_all,
  584. "difficulty":i_difficulty_all/i_count_all,
  585. "eloDegree":'n',
  586. "avgCorrectness":i_correct_all/i_count_all,
  587. "avgTryCount":i_try_all/i_count_all,
  588. "step":"3-2"
  589. }
  590. db.AccuTime_sta.update_one({"gameCode":game, "sectionId":0, "seconds":seconds_all, "tickTime":y, "gameStar":5, "eloDegree":'n'}, {'$set':AccuTimeAll_sta_dict}, upsert = True)
  591. AccuTime_count += 1
  592. #log秒
  593. for seconds_all_log, i_count_all_log, i_correct_all_log, i_difficulty_all_log, i_try_all_log in zip(np.arange(-2.4, m+n, n), allPeople_log, allCorrectness_log, allDifficulty_log, allTryCount_log):
  594. if i_count_all_log > 0:
  595. AccuTimeAllLog_sta_dict = {"gameCode":game,
  596. "sectionId":0,
  597. "seconds_log":round(seconds_all_log, 2),
  598. "tickTime":n,
  599. "gameStar":5,
  600. "people":i_count_all_log,
  601. "difficulty":i_difficulty_all_log/i_count_all_log,
  602. "eloDegree":'n',
  603. "avgCorrectness":i_correct_all_log/i_count_all_log,
  604. "avgTryCount":i_try_all_log/i_count_all_log,
  605. "step":"3-2"
  606. }
  607. db.AccuTimeLog_sta.update_one({"gameCode":game, "sectionId":0, "seconds_log":round(seconds_all_log, 2), "tickTime":n, "gameStar":5, "eloDegree":'n'},{'$set':AccuTimeAllLog_sta_dict}, upsert = True)
  608. AccuTimeLog_count += 1
  609. del allPeople, allCorrectness, allDifficulty, allTryCount, allPeople_log, allCorrectness_log, allDifficulty_log, allTryCount_log
  610. gc.collect()
  611. #只算過關
  612. #
  613. for seconds_pass, i_count_pass, i_correct_pass, i_difficulty_pass, i_try_pass in zip(range(0, x+y, y), passPeople, passCorrectness, passDifficulty, passTryCount):
  614. if i_count_pass > 0:
  615. AccuTimePass_sta_dict = {"gameCode":game,
  616. "sectionId":0,
  617. "seconds":seconds_pass,
  618. "tickTime":y,
  619. "gameStar":6, #6是有過關
  620. "people":i_count_pass,
  621. "difficulty":i_difficulty_pass/i_count_pass,
  622. "eloDegree":'n',
  623. "avgCorrectness":i_correct_pass/i_count_pass,
  624. "avgTryCount":i_try_pass/i_count_pass,
  625. "step":"3-3"
  626. }
  627. db.AccuTime_sta.update_one({"gameCode":game, "sectionId":0, "seconds":seconds_pass, "tickTime":y, "gameStar":6, "eloDegree":'n'}, {'$set':AccuTimePass_sta_dict}, upsert = True)
  628. AccuTime_count += 1
  629. #log秒
  630. for seconds_pass_log, i_count_pass_log, i_correct_pass_log, i_difficulty_pass_log, i_try_pass_log in zip(np.arange(-2.4, m+n, n), passPeople_log, passCorrectness_log, passDifficulty_log, passTryCount_log):
  631. if i_count_pass_log > 0:
  632. AccuTimePassLog_sta_dict = {"gameCode":game,
  633. "sectionId":0,
  634. "seconds_log":round(seconds_pass_log, 2),
  635. "tickTime":n,
  636. "gameStar":6, #6是有過關
  637. "people":i_count_pass_log,
  638. "difficulty":i_difficulty_pass_log/i_count_pass_log,
  639. "eloDegree":'n',
  640. "avgCorrectness":i_correct_pass_log/i_count_pass_log,
  641. "avgTryCount":i_try_pass_log/i_count_pass_log,
  642. "step":"3-3"
  643. }
  644. db.AccuTimeLog_sta.update_one({"gameCode":game, "sectionId":0, "seconds_log":round(seconds_pass_log, 2), "tickTime":n, "gameStar":6, "eloDegree":'n'},{'$set':AccuTimePassLog_sta_dict}, upsert = True)
  645. AccuTimeLog_count += 1
  646. for seconds_z_all, i_count_z_all, i_correct_z_all, i_difficulty_z_all, i_try_z_all in zip(range(-1, p+q, q), allzPeople, allzCorrectness, allzDifficulty, allzTryCount):
  647. if i_count_z_all > 0:
  648. AccuTimeZAll_sta_dict = {"gameCode":game,
  649. "sectionId":0,
  650. "seconds_z":seconds_z_all,
  651. "tickTime":q,
  652. "gameStar":5,
  653. "people":i_count_z_all,
  654. "difficulty":i_difficulty_z_all/i_count_z_all,
  655. "eloDegree":'n',
  656. "avgCorrectness":i_correct_z_all/i_count_z_all,
  657. "avgTryCount":i_try_z_all/i_count_z_all,
  658. "step":"3-3"
  659. }
  660. db.AccuTimeZ_sta.update_one({"gameCode":game, "sectionId":0, "seconds_z":seconds_z_all, "tickTime":q, "gameStar":5, "eloDegree":'n'}, {'$set':AccuTimeZAll_sta_dict}, upsert = True)
  661. AccuTime_count += 1
  662. del passPeople, passCorrectness ,passDifficulty, passTryCount, passPeople_log, passCorrectness_log, passDifficulty_log, passTryCount_log, allzPeople, allzCorrectness, allzDifficulty, allzTryCount
  663. gc.collect()
  664. pc.pass_time(startTime, time.time())