Skip to content

Commit

Permalink
Disabling post-session data transfer as discussed in lab meeting (#395)
Browse files Browse the repository at this point in the history
* Disabling post-session data transfer as discussed in lab meeting

* Making batch script for data transfer. Updating scrupt to automatically fetch the current server config.

* Updating iPhone dump to be automatically detect the server name and only run if the device is assigned to the current server

* Fixing broken dump (iPhone no longr needs device args if not using LSL)
  • Loading branch information
boubre authored Apr 1, 2024
1 parent 87c6166 commit 1b6af22
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 22 deletions.
16 changes: 9 additions & 7 deletions extras/dump_iphone_video.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import neurobooth_os.iout.iphone as iphone
from neurobooth_os.iout.lsl_streamer import get_device_assignment
import neurobooth_os.config as cfg
import re
import os
Expand Down Expand Up @@ -26,8 +27,8 @@ def neurobooth_dump(args: argparse.Namespace) -> None:
args
Command line arguments.
"""
session_root = cfg.neurobooth_config.server_by_name(args.server).local_data_dir
logger = logging.getLogger(APP_LOG_NAME)
session_root = cfg.neurobooth_config.current_server().local_data_dir
logger.debug(f'Session Root: {session_root}')

# Connect to the iPhone
Expand Down Expand Up @@ -146,12 +147,6 @@ def parse_arguments() -> argparse.Namespace:
type=int,
help='Specify a timeout (in seconds) for each file retrieval. Default is 10 min. No timeout if <= 0.'
)
parser.add_argument(
'--server',
default='acquisition',
type=str,
help='Specify the server to run on so the proper value of local_data_dir is used. Default is "acquisition".'
)
args = parser.parse_args()

if args.delete_zero_byte:
Expand All @@ -171,6 +166,13 @@ def main():
logger = make_db_logger()
iphone.DISABLE_LSL = True

# Check if we should be running the dump on this machine.
server_name = cfg.get_server_name_from_env()
if get_device_assignment('IPhone_dev_1') != server_name:
logger.debug(f'IPhone not assigned to {server_name}.')
return

# Run and time the dump.
args = parse_arguments()
t0 = datetime.datetime.now()
logger.info('Running Dump')
Expand Down
2 changes: 1 addition & 1 deletion neurobooth_os/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Neurobooth OS"""

__version__ = "0.0.29.1"
__version__ = "0.0.30"
5 changes: 3 additions & 2 deletions neurobooth_os/iout/iphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ def __init__(self, name, sess_id="", mock=False, device_args: DeviceArgs = None,
self.iphone_sessionID = sess_id
self.name = name
self.mock = mock
self.device_id = device_args.device_id
self.sensor_ids = device_args.sensor_ids
if not DISABLE_LSL: # Device and sensor IDs are only needed if streaming data to LSL.
self.device_id = device_args.device_id
self.sensor_ids = device_args.sensor_ids
self.enable_timeout_exceptions = enable_timeout_exceptions
self.streaming = False
self.streamName = "IPhoneFrameIndex"
Expand Down
17 changes: 17 additions & 0 deletions neurobooth_os/iout/lsl_streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ def start_yeti_stream(_, device_args):
]


class DeviceNotFoundException(Exception):
"""Exception raised when a given device ID cannot be found."""
pass


def get_device_assignment(device_id: str) -> str:
"""
Return the server a device is assigned to. Raises a DeviceNotFoundException if the device is not found.
:param device_id: The ID of the device.
:return: The full name of the assigned server.
"""
for server_name, device_list in SERVER_ASSIGNMENTS.items():
if device_id in device_list:
return server_name
raise DeviceNotFoundException(f'{device_id} is not assigned to any server.')


# --------------------------------------------------------------------------------
# Handle the device life cycle
# --------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion neurobooth_os/server_acq.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
call %NB_CONDA_INSTALL%\Scripts\activate.bat %NB_CONDA_ENV%
start /W ipython --pdb %NB_INSTALL%\neurobooth_os\server_acq.py
start /W ipython %NB_INSTALL%\neurobooth_os\transfer_data.py acquisition
1 change: 0 additions & 1 deletion neurobooth_os/server_ctr.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
call %NB_CONDA_INSTALL%\Scripts\activate.bat %NB_CONDA_ENV%
start /W ipython --pdb %NB_INSTALL%\neurobooth_os\gui.py
start /W ipython %NB_INSTALL%\neurobooth_os\transfer_data.py control
1 change: 0 additions & 1 deletion neurobooth_os/server_stm.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
call %NB_CONDA_INSTALL%\Scripts\activate.bat %NB_CONDA_ENV%
start /W ipython --pdb %NB_INSTALL%\neurobooth_os\server_stm.py
start /W ipython %NB_INSTALL%\neurobooth_os\transfer_data.py presentation
3 changes: 3 additions & 0 deletions neurobooth_os/transfer_data.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
call %NB_CONDA_INSTALL%\Scripts\activate.bat %NB_CONDA_ENV%
start /W ipython %NB_INSTALL%\extras\dump_iphone_video.py
start /W ipython %NB_INSTALL%\neurobooth_os\transfer_data.py
10 changes: 1 addition & 9 deletions neurobooth_os/transfer_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import argparse

from neurobooth_os import config
from neurobooth_os.util.constants import NODE_NAMES
from neurobooth_os.log_manager import make_db_logger


Expand All @@ -18,7 +17,7 @@ def log_output(pipe):

def main(args: argparse.Namespace):
destination = config.neurobooth_config.remote_data_dir
source = config.neurobooth_config.server_by_name(args.source_node_name).local_data_dir
source = config.neurobooth_config.current_server().local_data_dir

try:
# Move data to remote
Expand All @@ -39,17 +38,10 @@ def main(args: argparse.Namespace):


def parse_arguments() -> argparse.Namespace:

parser = argparse.ArgumentParser(
prog='transfer_data',
description='Transfer data copies data from local folders into remote storage.',
)

parser.add_argument(
'source_node_name', # positional argument
choices=NODE_NAMES,
help=f'You must provide the name of the node to transfer data from, which must be one of {NODE_NAMES}'
)
args = parser.parse_args()
return args

Expand Down

0 comments on commit 1b6af22

Please sign in to comment.