Skip to content

Commit

Permalink
changes: (1) changed sleep function to qWait, (2) removed progress ba…
Browse files Browse the repository at this point in the history
…r and threading
  • Loading branch information
bartulem committed Jul 25, 2023
1 parent 2638fdb commit 72b9312
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# usv-playpen v0.2.8
# usv-playpen v0.2.9

<br>
<div align="center">
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='usv-playpen',
version='0.2.8',
version='0.2.9',
author='@bartulem',
author_email='mimica.bartul@gmail.com',
classifiers=[
Expand Down
31 changes: 9 additions & 22 deletions src/behavioral_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
Code to run experiments with Motif/Avisoft.
"""

from PyQt6.QtCore import (
QEventLoop,
QTimer
)
from PyQt6.QtTest import QTest
import configparser
import datetime
import glob
Expand All @@ -19,16 +16,6 @@
from send_email import Messenger


def _loop_time(delay_time):
"""time.sleep fails in PyQt6, so this is
a replacement function which achieves the
same goal
NB: the time unit is in ms!"""
loop = QEventLoop()
QTimer.singleShot(delay_time, loop.quit)
loop.exec()


class ExperimentController:

def __init__(self, email_receivers=None, exp_settings_dict=None, message_output=None):
Expand Down Expand Up @@ -166,7 +153,7 @@ def check_camera_vitals(self, camera_fr=None):
webbrowser.open(self.exp_settings_dict['video']['general']['monitor_url'])

# pause for N seconds
_loop_time(delay_time=2000)
QTest.qWait(2000)

self.api = api

Expand All @@ -180,7 +167,7 @@ def conduct_tracking_calibration(self):
filename='calibration',
duration=self.exp_settings_dict['calibration_duration'] * 60,
codec=self.exp_settings_dict['video']['general']['recording_codec'])
_loop_time(delay_time=1000*((self.exp_settings_dict['calibration_duration'] * 60) + 5))
QTest.qWait(1000*((self.exp_settings_dict['calibration_duration'] * 60) + 5))

self.message_output(f"Video calibration completed at {datetime.datetime.now().hour:02d}:{datetime.datetime.now().minute:02d}.{datetime.datetime.now().second:02d}")

Expand Down Expand Up @@ -306,15 +293,15 @@ def modify_audio_file(self):
f"{self.exp_settings_dict['avisoft_basedirectory']}Configurations{os.sep}RECORDER_USGH")

# pause for N seconds
_loop_time(delay_time=5000)
QTest.qWait(5000)

else:
if not os.path.isfile(f"{self.exp_settings_dict['avisoft_basedirectory']}Configurations{os.sep}RECORDER_USGH{os.sep}avisoft_config.ini"):
shutil.copy(f"{self.exp_settings_dict['config_settings_directory']}{os.sep}avisoft_config.ini",
f"{self.exp_settings_dict['avisoft_basedirectory']}Configurations{os.sep}RECORDER_USGH")

# pause for N seconds
_loop_time(delay_time=5000)
QTest.qWait(5000)

def conduct_behavioral_recording(self):
"""
Expand Down Expand Up @@ -402,7 +389,7 @@ def conduct_behavioral_recording(self):
start_hour_min_sec, total_dir_name_linux, total_dir_name_windows = self.get_custom_dir_names(now=self.api.call('schedule')['now'])

# pause for N seconds
_loop_time(delay_time=10000)
QTest.qWait(10000)

for directory in total_dir_name_windows:
if not os.path.isdir(f"{directory}{os.sep}video"):
Expand Down Expand Up @@ -436,12 +423,12 @@ def conduct_behavioral_recording(self):

# wait until cameras have finished recording
# pause for N extra seconds so audio is done, too
_loop_time(delay_time=1000*(10 + (self.exp_settings_dict['video_session_duration'] * 60)))
QTest.qWait(1000*(10 + (self.exp_settings_dict['video_session_duration'] * 60)))

self.message_output(f"Recording fully completed at {datetime.datetime.now().hour:02d}:{datetime.datetime.now().minute:02d}.{datetime.datetime.now().second:02d}.")

# pause for N seconds
_loop_time(delay_time=10000)
QTest.qWait(10000)

# close Avisoft recorder / browser post recording
# if self.exp_settings_dict['conduct_audio_recording']:
Expand Down Expand Up @@ -470,7 +457,7 @@ def conduct_behavioral_recording(self):
delete_after=del_files,
location=f"{lin_dir}/video")
while any(self.api.is_copying(_sn) for _sn in self.camera_serial_num):
_loop_time(delay_time=1000)
QTest.qWait(1000)

# copy audio files to another location
copy_data_dict = {'sync': [f"{self.exp_settings_dict['coolterm_basedirectory']}{os.sep}Data{os.sep}*.txt"]}
Expand Down
26 changes: 4 additions & 22 deletions src/usv_playpen_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import datetime
import os
import sys
import threading
from functools import partial
from pathlib import Path
import time
Expand Down Expand Up @@ -40,14 +39,14 @@
QWidget,
)

from behavioral_experiments import ExperimentController, _loop_time
from behavioral_experiments import ExperimentController
from preprocess_data import Stylist

if os.name == 'nt':
my_app_id = 'mycompany.myproduct.subproduct.version'
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(my_app_id)

app_name = 'USV Playpen'
app_name = 'USV Playpen v0.2.9'
experimenter_id = 'bartulem'
email_list_global = ''
config_dir_global = 'C:\\experiment_running_docs'
Expand Down Expand Up @@ -618,11 +617,6 @@ def record_four(self):
self.generalLayout.addWidget(self.txt_edit, 0, 0,
alignment=Qt.AlignmentFlag.AlignTop)

self.experiment_progress_bar = QProgressBar()
self.generalLayout.addWidget(self.experiment_progress_bar, 1, 0,
alignment=Qt.AlignmentFlag.AlignTop)
self.experiment_progress_bar.setStyleSheet('QProgressBar { min-width: 1030px; min-height: 30px;}')

self._save_modified_values_to_toml()

exp_settings_dict_final = toml.load(f"{self.settings_dict['general']['config_settings_directory']}{os.sep}behavioral_experiments_settings.toml")
Expand Down Expand Up @@ -1388,15 +1382,10 @@ def _start_processing(self):
self.run_processing.prepare_data_for_analyses()

def _start_calibration(self):
self.cal_thread = threading.Thread(self.run_exp.conduct_tracking_calibration())
self.cal_thread.start()
self.run_exp.conduct_tracking_calibration()

def _start_recording(self):
self.prog_bar_thread = threading.Thread(target=self._move_progress_bar)
self.prog_bar_thread.start()

self.rec_thread = threading.Thread(self.run_exp.conduct_behavioral_recording())
self.rec_thread.start()
self.run_exp.conduct_behavioral_recording()

def _enable_process_buttons(self):
self.button_map['Previous'].setEnabled(True)
Expand Down Expand Up @@ -1489,13 +1478,6 @@ def _location_on_the_screen(self):
top_left_point = QGuiApplication.primaryScreen().availableGeometry().topLeft()
self.move(top_left_point)

def _move_progress_bar(self):
time_to_sleep = int(round(self.experiment_time_sec * 10))
for i in range(101):
_loop_time(delay_time=time_to_sleep)
self.experiment_progress_bar.setValue(i)
self.experiment_time_sec = 0

def _message(self, s):
self.txt_edit.appendPlainText(s)

Expand Down

0 comments on commit 72b9312

Please sign in to comment.