Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 79 additions & 4 deletions src/fix8.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ def ascii_to_csv_converter(self):
# convert and save csv file
mini_emtk.read_EyeLink1000(ascii_file, new_correction_file_name)


def json_to_csv_converter(self):
# open json file through file dialog limit to .asc files
qfd = QFileDialog()
Expand All @@ -662,8 +661,7 @@ def json_to_csv_converter(self):
# convert and save csv file
dataframe = self.json_to_df(json_file)
dataframe.to_csv(new_correction_file_name, index=False)



def csv_to_json_converter(self):
# open csv file through file dialog limit to .asc files
qfd = QFileDialog()
Expand Down Expand Up @@ -704,7 +702,6 @@ def csv_to_json_converter(self):

with open(f"{new_correction_file_name}", "w") as f:
json.dump(corrected_fixations, f)


def eyelink_experiment_to_csv_converter(self):
''' convert eyelink experiment to csv files from ASCII and runtime folder '''
Expand All @@ -720,6 +717,84 @@ def eyelink_experiment_to_csv_converter(self):
self.show_error_message("Warning", "Conversion may take a while")
mini_emtk.read_EyeLink1000_experiment(ascii_file, save_folder, runtime_folder=runtime_folder)

#convert eyevec file into json data file with correct format
def eyevec_to_json_converter(self):

# open csv file contain eyevec format data through file dialog limit to .asc files
qfd = QFileDialog()
csv_file = qfd.getOpenFileName(self.ui, "Select CSV file", "", "CSV Files (*.csv)")[0]

if csv_file == "":
self.show_error_message("Error", "No file selected")
return

# ask user for file name to save csv through file dialog
qfd = QFileDialog()
default_file_name = csv_file.replace('.csv', '') + '.json'
new_correction_file_name, _ = qfd.getSaveFileName(self.ui, "Save converted json file", default_file_name)

if new_correction_file_name == "":
self.show_error_message("Error", "No file selected")
return

if '.json' not in new_correction_file_name:
new_correction_file_name += '.json'

self.show_error_message("Warning", "Conversion may take a while")

file_number = 1
fixations = [] #the output list of fixation
converted_list = [] #keep track of the data as it converts from csv to a list of strings

with open(csv_file, 'r') as file:

#loop through each line
#convert csv file to a list of strings
for line in file:

start_index = 0

#loop through character to separate csv:
for cur_index in range(len(line)):

#slice if current character is ;
if line[cur_index] == ';':
converted_list.append(line[start_index:cur_index])
start_index = cur_index + 1

#loop through the converted_list, which contain the converted list of string
#find keep points where FIXATION_END to add to the fixation list that will be outputed
for index in range(len(converted_list)):

#if the end time is found, then add values to fixation
if converted_list[index] == "FIXATION_END":

#calculate fixation time using start and end time
start_time = float(converted_list[index + 2])
end_time = float(converted_list[index + 3])
fixation_time = float(end_time - start_time)
fixation_time /= 1000

#find the x and y position of gaze
x_position = float(converted_list[index + 4])
y_position = float(converted_list[index + 5])
fixations.append([x_position, y_position, fixation_time])

#if the end of the recording file is found, output into a json file
if converted_list[index] == "RECORDING_END":

#generate correct filename
dot_loc = new_correction_file_name.find('.')
output_file_name = new_correction_file_name[:dot_loc] + "_" + str(file_number) + new_correction_file_name[dot_loc:]
file_number += 1

#generate output fixation and outpu as json file
corrected_fixations = {'fixations': fixations}
with open(f"{output_file_name}", "w") as f:
json.dump(corrected_fixations, f)

fixations = []

def outlier_duration_filter(self):
minimum_value = 0.1
maximum_value = 5
Expand Down
2 changes: 1 addition & 1 deletion src/mini_emtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,4 +1120,4 @@ def get_fixation_count(hit_test_output, line, part):

fixations_on_same_part_and_line = hit_test_output[(hit_test_output["part"] == part) & (hit_test_output["line"] == line)]

return len(fixations_on_same_part_and_line)
return len(fixations_on_same_part_and_line)
4 changes: 3 additions & 1 deletion src/ui_main_window.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


from qt_material import QtStyleTools, list_themes
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import Qt
Expand Down Expand Up @@ -488,6 +487,7 @@ def init_UI(self):
self.json_to_csv_converter_action = QAction("JSON to CSV (one trial)", self)
self.csv_to_json_converter_action = QAction("CSV to JSON (one trial)", self)
self.eyelink_experiment_to_csv_converter_action = QAction("Eyelink Experiment to CSV", self)
self.eyevec_to_json_converter_action = QAction("Eyevec to JSON Convert", self)

self.assign_line_1_action = QAction("Assign to Line 1", self)
self.assign_line_2_action = QAction("Assign to Line 2", self)
Expand Down Expand Up @@ -620,6 +620,7 @@ def init_UI(self):
self.converters_menu.addAction(self.json_to_csv_converter_action)
self.converters_menu.addAction(self.csv_to_json_converter_action)
self.converters_menu.addAction(self.eyelink_experiment_to_csv_converter_action)
self.converters_menu.addAction(self.eyevec_to_json_converter_action)

# add menu item called "Style" to the menu bar
self.menu_style = self.menuBar().addMenu("Appearance")
Expand Down Expand Up @@ -760,6 +761,7 @@ def init_UI(self):
self.json_to_csv_converter_action.triggered.connect(self.fix8.json_to_csv_converter)
self.csv_to_json_converter_action.triggered.connect(self.fix8.csv_to_json_converter)
self.eyelink_experiment_to_csv_converter_action.triggered.connect(self.fix8.eyelink_experiment_to_csv_converter)
self.eyevec_to_json_converter_action.triggered.connect(self.fix8.eyevec_to_json_converter)

self.assign_line_1_action.triggered.connect(lambda: self.fix8.assign_fixation_to_line(1))
self.assign_line_2_action.triggered.connect(lambda: self.fix8.assign_fixation_to_line(2))
Expand Down