Skip to content

Commit

Permalink
Fix bug where loaded sessions persist event history
Browse files Browse the repository at this point in the history
  • Loading branch information
wsarce committed Aug 10, 2022
1 parent 9104e80 commit 9b0c625
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 40 deletions.
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enable-review: false
enable-woodway: false
first-time: true
fps: 8
logs-dir: C:\cometrics\1.2.1\logs
logs-dir: C:\cometrics\1.3.2\logs
patient-concerns: concerns.yml
phases:
- Assessment
Expand Down
9 changes: 8 additions & 1 deletion output_view_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ def start_session(self, recording_path=None):
self.ble_view.start_session()
if self.woodway_view:
self.woodway_view.start_session()
if self.video_view:
self.video_view.clear_event_treeview()
if self.key_view:
self.key_view.clear_sh_treeview()

def enable_video_slider(self):
if self.video_view.player:
Expand Down Expand Up @@ -1416,10 +1420,11 @@ def populate_event_treeview(self):

def clear_event_treeview(self):
clear_treeview(self.event_treeview)
self.event_treeview_parents = []
self.event_history = []

def populate_event_treeview_review(self):
self.reviewing = True
self.clear_event_treeview()
if self.event_history:
for i in range(0, len(self.event_history)):
bind = self.event_history[i]
Expand Down Expand Up @@ -2058,6 +2063,8 @@ def init_background_vars(self, keystroke_file):

def clear_sh_treeview(self):
clear_treeview(self.sh_treeview)
self.sh_treeview_parents = []
self.event_history = []

def add_session_event(self, events):
for event in events:
Expand Down
97 changes: 64 additions & 33 deletions patient_data_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,23 @@ def __init__(self, parent, x, y, height, width, patient_file, prim_session_numbe
self.start_label = Label(self.patient_frames[frame_select], text="Session Start Time: " + session_time,
anchor=NW, font=field_font)
self.start_label.place(x=5, y=patient_y, anchor=NW)
info_count += 1
info_count += 1
if not info_count % field_count and frame_count != 1:
frame_select += 1
patient_y = 30
else:
patient_y += field_offset / 2

self.patient_vars[PatientDataVar.PATIENT_NAME].set(self.patient.name)
if self.patient.medical_record_number:
self.patient_vars[PatientDataVar.MRN].set(self.patient.medical_record_number)
self.patient_vars[PatientDataVar.SESS_NUM].set(prim_session_number)

load_session_button = Button(self.patient_frames[frame_select], text="Load Existing Session", font=field_font,
command=self.check_load_session)
load_session_button.place(x=(width / 2), y=patient_y, anchor=N, width=width * 0.88)

self.current_patient_field = 0
self.patient_frames[self.current_patient_field].place(x=self.x, y=self.y)
self.patient_entries[0].focus()
Expand All @@ -224,7 +235,7 @@ def __init__(self, parent, x, y, height, width, patient_file, prim_session_numbe
values=(bind[1],),
tags=(treeview_bind_tags[i % 2]))

self.patient_vars[PatientDataVar.SESS_NUM].trace('w', self.check_load_session)
# self.patient_vars[PatientDataVar.SESS_NUM].trace('w', self.check_load_session)

if debug:
self.patient_vars[PatientDataVar.SESS_LOC].set("Debug")
Expand All @@ -241,25 +252,42 @@ def show_dur_key(self, i):
def hide_dur_key(self, i):
self.bind_treeview.item(str(len(self.freq_bindings) + i), tags=treeview_bind_tags[(len(self.freq_bindings) + i) % 2])

def check_load_session(self, *args):
def check_prim_sessions(self, session_number):
for prim_file in self.caller.prim_files:
with open(prim_file, 'r') as f:
json_file = json.load(f)
if str(session_number) == json_file['Session Number']:
return prim_file
return None

def check_reli_sessions(self, session_number):
for reli_file in self.caller.reli_files:
with open(reli_file, 'r') as f:
json_file = json.load(f)
if str(session_number) == json_file['Session Number']:
return reli_file
return None

def check_load_session(self):
session_number = self.patient_vars[PatientDataVar.SESS_NUM].get()
if bool(re.match('^[0-9]+$', session_number)):
session_number = int(session_number) - 1
if session_number:
if self.patient_vars[PatientDataVar.PRIM_DATA].get() == "Primary":
if session_number < len(self.caller.prim_files):
print(f"INFO: Loading primary data session {self.patient_vars[PatientDataVar.SESS_NUM].get()}")
self.session_file = session_file = self.caller.prim_files[session_number]
session_video_file = os.path.join(pathlib.Path(session_file).parent, pathlib.Path(session_file).stem + ".mp4")
if os.path.exists(session_video_file):
self.caller.ovu.video_view.video_file = session_video_file
with open(session_file, 'r') as f:
self.session_json = session_json = json.load(f)
session_json_events = session_json["Event History"]
self.caller.ovu.key_view.clear_sh_treeview()
self.caller.ovu.key_view.add_session_event(session_json_events)
self.caller.ovu.video_view.add_event_history(session_json_events)
self.caller.ovu.video_view.populate_event_treeview_review()
self.session_loaded = True
self.session_file = session_file = self.check_prim_sessions(session_number)
if session_file:
if os.path.exists(session_file):
print(f"INFO: Loading primary data session {self.patient_vars[PatientDataVar.SESS_NUM].get()}")
session_video_file = os.path.join(pathlib.Path(session_file).parent, pathlib.Path(session_file).stem + ".mp4")
if os.path.exists(session_video_file):
self.caller.ovu.video_view.video_file = session_video_file
with open(session_file, 'r') as f:
self.session_json = session_json = json.load(f)
session_json_events = session_json["Event History"]
self.caller.ovu.key_view.clear_sh_treeview()
self.caller.ovu.video_view.clear_event_treeview()
self.caller.ovu.key_view.add_session_event(session_json_events)
self.caller.ovu.video_view.add_event_history(session_json_events)
self.caller.ovu.video_view.populate_event_treeview_review()
self.session_loaded = True
else:
self.caller.ovu.key_view.clear_sh_treeview()
self.caller.ovu.video_view.clear_event_treeview()
Expand All @@ -269,21 +297,24 @@ def check_load_session(self, *args):
else:
self.session_loaded = False
elif self.patient_vars[PatientDataVar.PRIM_DATA].get() == "Reliability":
if session_number < len(self.caller.reli_files):
print(f"INFO: Loading reliability data session {self.patient_vars[PatientDataVar.SESS_NUM].get()}")
self.caller.ovu.key_view.clear_sh_treeview()
self.session_file = session_file = self.caller.reli_files[session_number]
session_video_file = os.path.join(pathlib.Path(session_file).parent,
pathlib.Path(session_file).stem + ".mp4")
if os.path.exists(session_video_file):
self.caller.ovu.video_view.video_file = session_video_file
with open(session_file, 'r') as f:
self.session_json = session_json = json.load(f)
session_json_events = session_json["Event History"]
self.caller.ovu.key_view.add_session_event(session_json_events)
self.caller.ovu.video_view.add_event_history(session_json_events)
self.caller.ovu.video_view.populate_event_treeview_review()
self.session_loaded = True
self.session_file = session_file = self.check_reli_sessions(session_number)
if session_file:
if os.path.exists(session_file):
print(f"INFO: Loading reliability data session {self.patient_vars[PatientDataVar.SESS_NUM].get()}")
self.caller.ovu.key_view.clear_sh_treeview()
session_video_file = os.path.join(pathlib.Path(session_file).parent,
pathlib.Path(session_file).stem + ".mp4")
if os.path.exists(session_video_file):
self.caller.ovu.video_view.video_file = session_video_file
with open(session_file, 'r') as f:
self.session_json = session_json = json.load(f)
session_json_events = session_json["Event History"]
self.caller.ovu.key_view.clear_sh_treeview()
self.caller.ovu.video_view.clear_event_treeview()
self.caller.ovu.key_view.add_session_event(session_json_events)
self.caller.ovu.video_view.add_event_history(session_json_events)
self.caller.ovu.video_view.populate_event_treeview_review()
self.session_loaded = True
else:
self.caller.ovu.key_view.clear_sh_treeview()
self.caller.ovu.video_view.clear_event_treeview()
Expand Down
19 changes: 15 additions & 4 deletions session_manager_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def save_session(self):
x = {
"Session Date": self.session_date,
"Session Start Time": self.session_time,
"Session Start Timestamp": EmpaticaE4.get_unix_timestamp(self.now),
"Session Start Timestamp": self.session_start_timestamp,
"Session End Timestamp": EmpaticaE4.get_unix_timestamp(),
"Session Time": self.stf.session_time,
"Pause Time": self.stf.break_time,
Expand Down Expand Up @@ -399,7 +399,20 @@ def start_session(self):
"Woodway view is not present when it should be!")
print("ERROR: Something went wrong with starting session, Woodway view is not present when it should be")
return

session_fields = self.pdf.get_session_fields()
reli = '_R' if session_fields["Primary Data"] == "Reliability" else ''
output_session_file = path.join(self.session_dir,
self.config.get_data_folders()[1],
session_fields["Primary Data"],
f"{session_fields['Session Number']}"
f"{session_fields['Assessment Name'][:2]}"
f"{session_fields['Condition Name'][:2]}"
f"{self.session_file_date}{reli}.json")
if os.path.exists(output_session_file):
messagebox.showerror("Session Exists", f"The selected session already exists!\n{output_session_file}")
print(f"ERROR: The selected session already exists {output_session_file}")
return
self.session_start_timestamp = EmpaticaE4.get_unix_timestamp()
self.now = now = datetime.datetime.today()
self.session_date = now.strftime("%B %d, %Y")
self.session_file_date = now.strftime("%B")[:3] + now.strftime("%d") + now.strftime("%Y")
Expand All @@ -409,8 +422,6 @@ def start_session(self):
self.pdf.lock_session_fields()
self.stf.lock_session_fields()
# Start the session
session_fields = self.pdf.get_session_fields()
reli = '_R' if session_fields["Primary Data"] == "Reliability" else ''
self.ovu.start_session(recording_path=path.join(self.session_dir,
self.config.get_data_folders()[1],
session_fields["Primary Data"],
Expand Down
2 changes: 1 addition & 1 deletion ui_params.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cometrics_version = "1.3.1"
cometrics_version = "1.3.2"
ui_title = f"cometrics v{cometrics_version}"

cometrics_data_root = fr'C:\cometrics'
Expand Down

0 comments on commit 9b0c625

Please sign in to comment.