-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestMovement.py
More file actions
105 lines (94 loc) · 3.86 KB
/
testMovement.py
File metadata and controls
105 lines (94 loc) · 3.86 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
from noteMotion.noteMovement import create_note_position_function, MovementData, NoteData
from typeDefs import Map as MAP, BeatMap, Note
from bsor.Bsor import Bsor, make_bsor
from matplotlib import pyplot as plt
import numpy as np
from interpretMapFiles import create_map
from geometry import Vector3
import pandas as pd
TESTING_PATH = './testing/Bang/'
MOTION_FILE_NAME = '2.142857_32011.csv'
with open(TESTING_PATH + 'replay.bsor', 'rb') as f:
m = make_bsor(f)
mapFile = create_map(TESTING_PATH + 'map')
testBeatMap = mapFile.beatMaps[m.info.mode][m.info.difficulty]
position_function = create_note_position_function(mapFile, testBeatMap.notes[0], m)
actual = pd.read_csv(TESTING_PATH + 'motion/' + MOTION_FILE_NAME).to_numpy()
first_time = actual[0][0] - 0.001
last_time = actual[-1][0]
for index, frame in enumerate([frame for frame in m.frames if first_time <= frame.time <= last_time]):
predicted = position_function(frame.time, frame)
observed = Vector3(actual[index][1], actual[index][2], actual[index][3])
error = Vector3.distance(predicted, observed)
print("Predicted\tt =", round(frame.time, 5), "\t", round(predicted.x, 5), round(predicted.y, 5), round(predicted.z, 5))
print("Observed\tt =", round(actual[index][0], 5), "\t", round(observed.x, 5), round(observed.y, 5), round(observed.z, 5))
print("Error\t\tΔ =", round(error, 5), "\n")
# NUM_NOTES = 1
# position_funtions = [create_note_position_function(mapFile, testBeatMap.notes[i], m)
# for i in range(NUM_NOTES)]
#
#
#
# # for frame in m.frames[100:110]:
# # print(frame.time, position_function(frame.time, frame))
#
# ax = plt.figure().add_subplot(projection='3d')
#
# START_FRAME = 0
# END_FRAME = 900
#
#
# # NoteMovementInfo = MovementData(mapFile, )
#
#
# for i in range(NUM_NOTES):
# points = [position_funtions[i](frame.time, frame) for frame in m.frames[START_FRAME:END_FRAME]]
# points = np.array([[pos.x, pos.y, pos.z] for pos in points])
# ax.scatter(points[:, 0], points[:, 1], points[:, 2])
#
# NOTE_INDEX = 3
#
# cut_points = np.array([m.notes[i].cut.cutPoint for i in range(NUM_NOTES)])
#
# cut_point_vector = Vector3(*cut_points[NOTE_INDEX])
# #frame = min(m.frames, key=lambda f: abs(f.time - m.notes[NOTE_INDEX].event_time))
# frame = min(m.frames, key=lambda f: distance(position_funtions[NOTE_INDEX](f.time, f), cut_point_vector))
#
# # print('time difference: ', frame.time - m.notes[NOTE_INDEX].event_time)
# # print(position_funtions[NOTE_INDEX](frame.time, frame))
# # print('distance: ', (Vector3(*cut_points[NOTE_INDEX]) - position_funtions[NOTE_INDEX](frame.time, frame)).mag())
# # print(m.notes[NOTE_INDEX].cut.cutDistanceToCenter)
# print("-----")
# print(cut_point_vector - position_funtions[NOTE_INDEX](frame.time, frame))
#
#
# distances_for_closest_time_frames = []
# for i in range(NUM_NOTES):
# frame = min(m.frames, key=lambda f: abs(f.time - m.notes[i].event_time))
# distances_for_closest_time_frames.append(
# distance(position_funtions[i](frame.time, frame), Vector3(*cut_points[i]))
# )
# print(distances_for_closest_time_frames)
# avg_z_dist = sum(distances_for_closest_time_frames)/NUM_NOTES
# max_adjusted_distance = max((a - avg_z_dist for a in distances_for_closest_time_frames))
#
# diff_vector = cut_point_vector - position_funtions[NOTE_INDEX](frame.time, frame)
# diff_vector.z -= .25 # max_adjusted_distance
# print('distance between predicted note position and cutPoint: ', diff_vector.mag())
# print('cutDistanceToCenter: ', m.notes[NOTE_INDEX].cut.cutDistanceToCenter)
# print('diff: ', diff_vector.mag() - m.notes[NOTE_INDEX].cut.cutDistanceToCenter)
#
# ax.scatter(cut_points[:, 0], cut_points[:, 1], cut_points[:, 2], s=200)
#
# ax.set_xlabel('X')
# ax.set_ylabel('Y')
# ax.set_zlabel('Z')
#
# ax.set_xlim(-1, 1)
# ax.set_ylim(0, 2)
# ax.set_zlim(-1, 10)
#
# ax.view_init(roll=90)
# # ax.set_box_aspect(1, 1, 2)
#
# # plt.show()