Skip to content
Merged
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
24 changes: 22 additions & 2 deletions pupil_src/shared_modules/surface_tracker/background_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,11 @@ def _export_marker_detections(self):
marker_cache = file_methods.Persistent_Dict(self.marker_cache_path)
marker_cache = marker_cache["marker_cache"]

incomplete_marker_cache_detected = False

file_path = os.path.join(self.metrics_dir, "marker_detections.csv")

try:
file_path = os.path.join(self.metrics_dir, "marker_detections.csv")
with open(file_path, "w", encoding="utf-8", newline="") as csv_file:
csv_writer = csv.writer(csv_file, delimiter=",")
csv_writer.writerow(
Expand All @@ -382,7 +385,19 @@ def _export_marker_detections(self):
)
)
for idx, serialized_markers in enumerate(marker_cache):
for m in map(Surface_Marker.deserialize, serialized_markers):
if serialized_markers is None:
# set flag to break from outer loop
incomplete_marker_cache_detected = True

if incomplete_marker_cache_detected:
break # outer loop

for sm in serialized_markers:
if sm is None:
# set flag to break from outer loop
incomplete_marker_cache_detected = True
break # inner loop
m = Surface_Marker.deserialize(sm)
flat_corners = [x for c in m.verts_px for x in c[0]]
assert len(flat_corners) == 8 # sanity check
csv_writer.writerow(
Expand All @@ -393,6 +408,11 @@ def _export_marker_detections(self):
)
)
finally:
if incomplete_marker_cache_detected:
logger.error("Marker detection not finished. No data will be exported.")
# Delete incomplete marker cache export file
os.remove(file_path)

# Delete the temporary marker cache created by the offline surface tracker
os.remove(self.marker_cache_path)
self.marker_cache_path = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,17 @@ def on_notify(self, notification):
break

elif notification["subject"] == "should_export":

if self.cache_filler is not None:
logger.error("Marker detection not finished. No data will be exported.")
return

if self.gaze_on_surf_buffer_filler is not None:
logger.error(
"Surface gaze mapping not finished. No data will be exported."
)
return

# Create new marker cache temporary file
# Backgroud exporter is responsible of removing the temporary file when finished
file_handle, marker_cache_path = tempfile.mkstemp()
Expand Down