-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess_data.py
executable file
·137 lines (102 loc) · 3.47 KB
/
preprocess_data.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
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
132
133
134
135
136
137
"""
Organizes experiment data.
Usage: python experiment_data.py stats_file.py
"""
import numpy as np
import sys
import datetime
from random import shuffle
EXPERIMENT_STATS_FILE = sys.argv[1]
AMATEURS = ["2017-06-18_20-46",
"2017-06-19_11-42",
"2017-06-19_12-07",
"2017-06-19_12-18",
"2017-06-19_12-46",
"2017-06-19_13-04",
"2017-06-19_13-45"]
EXPERTS = ["2017-06-19_18-02",
"2017-06-19_18-12",
"2017-06-19_18-20",
"2017-06-19_19-30"]
def cleanse(filename):
"""
Cleans and outputs the given experiment data as a list
:param filename:
return cleansed data
"""
moves = []
with open(filename) as test_input:
for line in test_input:
move = line.split("\n")[0]
moves.append([
float(move.split(" ")[0]), # Time
move.split(" ")[1].split("_")[0] # Action Type
])
return moves
def count_time(moves):
"""
Counts times between moves and their type
:param moves:
:return:
"""
action_times = []
starting_time = float(moves.pop(0)[0])
command_type = 0 # type 0 means the action involved changing the en
# type 1 means the action remained in the same en
for move in moves:
if move[1] == "vm":
action_times.append([
move[0] - starting_time, # time taken to since last command
command_type # type of command
])
starting_time = move[0]
command_type = 1
else:
command_type = 0
return action_times
amateur_times = [[], []]
expert_times = [[], []]
def input_all():
"""
Aggregates all experiment input
:return:
"""
for filename in AMATEURS:
for move in count_time(cleanse(
"../data/results/" + filename)):
amateur_times[move[1]].append(move[0])
for filename in EXPERTS:
for move in count_time(cleanse(
"../data/results/" + filename)):
expert_times[move[1]].append(move[0])
def get_stats(data):
"""
returns basic statistics for the input data
:param data:
:return:
"""
min = "min: " + str(np.min(data))
max = ", max: " + str(np.max(data))
median = ", median: " + str(np.median(data))
mean = "mean: " + str(np.mean(data))
return min + max + median + mean + "\n"
def all_stats():
"""
returns all general stats for the experiment data
:return:
"""
with open(EXPERIMENT_STATS_FILE, "w") as f:
f.write(str(datetime.date.today())) # date
f.write("\n" + str(len(AMATEURS)) + " amateur tests and "
+ str(len(EXPERTS)) + " expert tests.") # exp data
f.write("\nAmateurs changing entities:\n" + get_stats(amateur_times[0]))
f.write("\nAmateurs not changing entities\n" + get_stats(amateur_times[1]))
f.write("\nExperts changing entities:\n" + get_stats(expert_times[0]))
f.write("\nExperts not changing entities\n" + get_stats(expert_times[1]))
f.write("\nExperts were " + str(
np.mean(amateur_times[0] + amateur_times[1])
/ np.mean(expert_times[0] + expert_times[1])
) + " times faster.")
# Run
input_all()
all_stats()