Skip to content

Commit 76fba80

Browse files
committed
minor updates everywhere
1 parent b74778a commit 76fba80

File tree

4 files changed

+55
-22
lines changed

4 files changed

+55
-22
lines changed

Analysis/GeneralDataProcessing.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
eye_tracker_shift_hours = 4
2424

25-
def concat_files4data_source(filenames, path, index_col):
25+
def concat_files4data_source(filenames, path, index_col, sep=','):
2626
df_result = pd.DataFrame()
2727
for filename in filenames:
28-
df_addition = pd.read_csv(path + filename)
28+
df_addition = pd.read_csv(path + filename, sep=sep)
2929
df_addition.set_index(index_col, inplace=True)
3030
df_result = pd.concat([df_result, df_addition])
3131

@@ -34,13 +34,14 @@ def concat_files4data_source(filenames, path, index_col):
3434
data_dict = {}
3535

3636
data_sources = [
37-
'arduino_0',
38-
'arduino_1',
39-
'arduino_2',
37+
# 'arduino_0',
38+
# 'arduino_1',
39+
# 'arduino_2',
4040
'polar_heart_rate',
41-
'face_temperature',
41+
# 'face_temperature',
4242
'eye_tracker',
43-
'input',
43+
'mouse',
44+
'keyboard',
4445
'EEG',
4546
]
4647

@@ -58,6 +59,7 @@ def concat_files4data_source(filenames, path, index_col):
5859

5960
# for arduino_id in [0, 1, 2]:
6061
for data_source in data_sources:
62+
sep = ','
6163
# df4arduino = pd.DataFrame()
6264
# filename_prefix = f'arduino_{arduino_id}'
6365
# data_source = f'arduino_{arduino_id}'
@@ -73,18 +75,42 @@ def concat_files4data_source(filenames, path, index_col):
7375
path2data_source = data_path4player + data_source + '/'
7476
filenames = sorted(os.listdir(path2data_source))
7577
filenames_filtered = [filename for filename in filenames if not (filename.startswith('game') or filename.startswith('.'))]
76-
df_data_source = concat_files4data_source(filenames_filtered, path2data_source, index_col='Timestamp')
78+
if data_source == 'eye_tracker':
79+
filenames_filtered = [filename for filename in filenames_filtered if filename.startswith('tobii_pro_gaze')]
80+
index_col = '#timestamp'
81+
elif data_source in ['mouse', 'keyboard', 'EEG']:
82+
index_col = 'time'
83+
sep = ';'
84+
else:
85+
index_col = 'Timestamp'
86+
87+
# pd.read_csv(path2data_source + filenames_filtered[0], sep=';')
88+
df_data_source = concat_files4data_source(filenames_filtered, path2data_source, index_col=index_col, sep=sep)
89+
df_data_source.index.name = 'Timestamp'
90+
91+
if data_source == 'eye_tracker':
92+
# break
93+
df_data_source.index = pd.to_datetime(df_data_source.index + 3600 * 4 * 1000, unit='ms')
94+
df_data_source.index = df_data_source.index.astype(str)
95+
df_data_source.index = [index.replace(' ', '-') for index in df_data_source.index]
96+
# df_data_source.index = df_data_source.index.apply(lambda x: x.timestamp())
97+
98+
# df_data_source.rename(columns={'#timestamp': 'Timestamp'}, inplace=True)
99+
# df_data_source.set_index(['Timestamp'], inplace=True)
77100
# df_data_source.index = pd.to_datetime(df_data_source.index)
78101
# df_data_source.index = df_data_source.index.apply(lambda x: x.timestamp())
79102
df_data_source.sort_index(inplace=True)
80103

104+
81105
for n_row, row in games_start_end_times.iterrows():
82106
game_num = row['game_num']
83107
game_start_time = row['game_start']
84108
game_end_time = row['game_end']
85109
path4game_folder = data_path4player + data_source + '/' + f'game_{game_num}'
86110
if not os.path.exists(path4game_folder):
87111
os.mkdir(path4game_folder)
112+
113+
# break
88114
mask4game = (game_start_time < df_data_source.index) & (df_data_source.index < game_end_time)
89115
df_data_source.loc[mask4game].to_csv(data_path4player + data_source + '/' + f'game_{game_num}/' + data_source + '.csv')
90116

@@ -97,14 +123,14 @@ def concat_files4data_source(filenames, path, index_col):
97123
# player_data_dict[data_source] = df_data_source
98124

99125
# ### Eye tracker
100-
# filenames_with_prefix = [filename for filename in filenames if filename.startswith('tobii')]
126+
# # filenames_with_prefix = [filename for filename in filenames if filename.startswith('tobii')]
101127
# df_eyetracker = concat_files4data_source(filenames_with_prefix, index_col='#timestamp')
102128
# df_eyetracker.index = pd.to_datetime(df_eyetracker.index + 3600 * 4 * 1000, unit='ms')
103-
# # df_eyetracker.index = df_eyetracker.index.apply(lambda x: x.timestamp())
129+
# df_eyetracker.index = df_eyetracker.index.apply(lambda x: x.timestamp())
104130
# df_eyetracker.sort_index(inplace=True)
105131
# df_eyetracker = df_eyetracker.resample('1s').mean()
106132
# player_data_dict['eye_tracker'] = df_eyetracker
107-
133+
#
108134
# data_dict[player_id] = player_data_dict
109135

110136

EEG/cortex-v2-example/python/example.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ async def do_stuff(cortex):
3131
# session_ids = []
3232
# session_id2player_id = {}
3333
for headset_id in cortex.headsets:
34+
if not headset_id.startswith('INSIGHT'):
35+
continue
36+
3437
await cortex.create_session(activate=True, headset_id=headset_id)
3538
# session_ids.append(new_session_id)
3639

InputLogger/InputLogger.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
TIME_FORMAT4FILES = '%Y-%m-%d-%H-%M-%S'
99
TIME_FORMAT = '%Y-%m-%d-%H:%M:%S.%f'
10+
sep = ';'
1011

1112
queue_mouse = Queue(maxsize=10000)
1213
queue_keyboard = Queue(maxsize=10000)
@@ -18,8 +19,8 @@
1819

1920
filename_mouse = f'data/mouse_{current_datetime4files}.csv'
2021
filename_keyboard = f'data/keyboard_{current_datetime4files}.csv'
21-
header_mouse = 'time,event,x,y,params'
22-
header_keyboard = 'time,event,button'
22+
header_mouse = f'time{sep}event{sep}x{sep}y{sep}params'
23+
header_keyboard = f'time{sep}event{sep}button'
2324

2425
def get_current_time():
2526
return datetime.now().strftime(TIME_FORMAT)
@@ -35,7 +36,7 @@ def mouse_on_move(x, y):
3536
params = {}
3637
params_str = json.dumps(params)
3738

38-
msg = f'{current_time},{event},{x},{y},{params_str}'
39+
msg = f'{current_time}{sep}{event}{sep}{x}{sep}{y}{sep}{params_str}'
3940
queue_mouse.put(msg)
4041

4142

@@ -53,7 +54,7 @@ def mouse_on_click(x, y, button, pressed):
5354
params['button'] = button.name
5455
params_str = json.dumps(params)
5556

56-
msg = f'{current_time},{event},{x},{y},{params_str}'
57+
msg = f'{current_time}{sep}{event}{sep}{x}{sep}{y}{sep}{params_str}'
5758
queue_mouse.put(msg)
5859

5960
def mouse_on_scroll(x, y, dx, dy):
@@ -67,7 +68,7 @@ def mouse_on_scroll(x, y, dx, dy):
6768
params['dy'] = dy
6869
params_str = json.dumps(params)
6970

70-
msg = f'{current_time},{event},{x},{y},{params_str}'
71+
msg = f'{current_time}{sep}{event}{sep}{x}{sep}{y}{sep}{params_str}'
7172
queue_mouse.put(msg)
7273

7374

@@ -79,10 +80,10 @@ def keyboard_on_press(key):
7980
else:
8081
button_name = key.name
8182

82-
if button_name == ',': # We won't lose much but simplify the format
83+
if button_name == sep: # We won't lose much but simplify the format
8384
return
8485

85-
msg = f'{current_time},{event},{button_name}'
86+
msg = f'{current_time}{sep}{event}{sep}{button_name}'
8687
queue_keyboard.put(msg)
8788

8889

@@ -94,10 +95,10 @@ def keyboard_on_release(key):
9495
else:
9596
button_name = key.name
9697

97-
if button_name == ',': # We won't lose much but simplify the format
98+
if button_name == sep: # We won't lose much but simplify the format
9899
return
99100

100-
msg = f'{current_time},{event},{button_name}'
101+
msg = f'{current_time}{sep}{event}{sep}{button_name}'
101102
queue_keyboard.put(msg)
102103

103104

PolarDataCollection/file_parsing.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import os
44
import json
55

6-
TIME_FORMAT = "%Y-%m-%d-%H-%M-%S"
6+
TIME_FORMAT4FILES = "%Y-%m-%d-%H-%M-%S"
7+
TIME_FORMAT = "%Y-%m-%d-%H:%M:%S"
78
TIME_FORMAT_FIT = "%Y-%m-%dT%H:%M:%SZ"
89
players_list = json.load(open('players_credentials.json'))
910

@@ -34,14 +35,16 @@
3435

3536
df2add = pd.DataFrame(data2add)[['hr']]
3637
df2add.index = pd.to_datetime(start_time) + df2add.index
38+
df2add.index = [index_value.strftime(TIME_FORMAT) for index_value in df2add.index]
3739
df2add.rename(columns={'hr': 'heart_rate'}, inplace=True)
3840
df2add.index.name = 'Timestamp'
3941

4042
df4player = pd.concat([df4player, df2add])
4143

4244
if len(df4player):
4345
df4player = df4player.sort_index()
44-
suffix = df4player.index[0].strftime(TIME_FORMAT)
46+
# suffix = df4player.index[0].strftime(TIME_FORMAT4FILES)
47+
suffix = df4player.index[0].replace(':', '-')
4548

4649
df4player.to_csv(f'output/player_{player_id}/heart_rate_{suffix}.csv')
4750
else:

0 commit comments

Comments
 (0)