-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.py
60 lines (48 loc) · 1.87 KB
/
process.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
import pickle
from os import path
def calculate(direct_x, direct_y, cur_ball_x, cur_ball_y, side):
cur_ball_x += 2
cur_ball_y += 2
if side == "1P":
cross = 420
else:
cross = 80
m = direct_y/(direct_x if direct_x != 0 else 1)
candidate = (cross - cur_ball_y)/(m if m!= 0 else 1) + cur_ball_x -2
if candidate >= 0 and candidate <= 200:
return candidate
elif candidate > 200:
if int((candidate/200)) % 2 == 1:
return 200 - candidate % 200
else:
return candidate % 200
else:
candidate = abs(candidate)
if int((candidate/200)) % 2 == 0:
return candidate % 200
else:
return 200 - candidate % 200
def updataData(log):
destiFile = path.join(path.dirname(__file__), "data.pickle")
megadata = []
if path.exists(destiFile):
with open(destiFile,"rb") as rf:
megadata = pickle.load(rf)
megadata.extend(log)
with open(destiFile,"wb") as wf:
pickle.dump(megadata, wf)
with open(destiFile,"rb") as rf:
check = pickle.load(rf)
print("Data now has %d elements."%len(check))
if __name__ == '__main__':
filename = path.join(path.dirname(__file__), 'log', '37.pickle')
log = pickle.load((open(filename, 'rb')))
for i in log:
i["esti_1P"] = calculate(i["ball_speed"][0], i["ball_speed"][1], i["ball"][0], i["ball"][1], "1P")
i["esti_2P"] = calculate(i["ball_speed"][0], i["ball_speed"][1], i["ball"][0], i["ball"][1], "2P")
#use to print out unprocessed data
#print(i)
#change to correct estimation, please change all numbers here for each case
#for i in range(1535,1556): log[i]["esti_2P"] = 43.0
#!!!This will change data.pickle, be sure to comment out if not in use!!!
#updataData(log)