Skip to content

Commit 92fbf8b

Browse files
authored
Merge pull request #9 from compmem/task_test
Task test
2 parents 428df0c + 000d88e commit 92fbf8b

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
import platform
66

77
CURRENT_OS: str = platform.system()
8+
89
API_BASE_URL: str = 'https://mlc.nimh.nih.gov/cogmood'
9-
#API_BASE_URL='http://127.0.0.1:5000'
10+
# API_BASE_URL='http://127.0.0.1:5000'
11+
# API_BASE_URL: str = 'NOSERVER'
12+
1013
API_SALT: str = 'SALT'
1114
VERIFY: bool = False
1215
RUNNING_FROM_EXECUTABLE: bool = getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS')

main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@
116116
error_screen(error='Failed to Retrieve Identifier: ' + exp.worker_id_dict['content'],
117117
message='Contact Dylan Nielson')
118118
# Handles case where retrieval of worker id is default placeholder
119-
with Elif(exp.worker_id_dict['content'] == CogBatt_config.WORKER_ID_PLACEHOLDER_VALUE):
119+
with Elif((exp.worker_id_dict['content'] == CogBatt_config.WORKER_ID_PLACEHOLDER_VALUE)
120+
and (CogBatt_config.API_BASE_URL != 'NOSERVER')):
120121
error_screen(error='Non-Unique Identifier',
121122
message='Contact Dylan Nielson')
122123
# Error screen for failed GET request to retrieve blocks

utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ def get_blocks_to_run(worker_id: str, code: str | None = None) -> list[str] | di
2828
Returns:
2929
dict: A dictionary with 'status' as success or error, and 'content' containing either the blocks list or an error message.
3030
"""
31+
if API_BASE_URL == 'NOSERVER':
32+
logging.info('API_BASE_URL set to NOSERVER, faking server responses')
33+
tasks = ["rdm", "flkr", "bart", "cab"]
34+
reformatted_tasks = []
35+
for bn in [0, 1]:
36+
for tt in tasks:
37+
reformatted_tasks.append({'task_name':tt, 'block_number': bn})
38+
logging.info(f'Reformatted task list: {reformatted_tasks}')
39+
return {'status': 'success', 'content': reformatted_tasks}
3140
url = f'{API_BASE_URL}/taskcontrol'
3241
if WORKER_ID_SOURCE == 'EXECUTABLE':
3342
params = {'worker_id': worker_id}
@@ -103,6 +112,10 @@ def upload_block(worker_id: str, block_name: str, data_directory: str, slog_file
103112
Returns:
104113
dict: A dictionary with 'status' ('success' or 'error') and 'content' (message or error details).
105114
"""
115+
if API_BASE_URL == 'NOSERVER':
116+
logging.info('API_BASE_URL set to NOSERVER, skipping upload')
117+
return {"status": "success", "content": "Data upload skipped."}
118+
106119
url = f"{API_BASE_URL}/taskcontrol"
107120
slog_file_path = Path(data_directory) / slog_file_name
108121

@@ -169,12 +182,13 @@ def retrieve_worker_id() -> dict[str, str]:
169182
dict: A dictionary with 'status' and 'content' containing the worker ID or error message.
170183
"""
171184
if RUNNING_FROM_EXECUTABLE:
185+
172186
# Select appropriate worker ID retrieval function based on OS
173187
os_worker_id_function = {
174188
'Windows': _read_exe_worker_id,
175189
'Darwin': _read_app_worker_id
176190
}.get(CURRENT_OS, lambda: {'status': 'error', 'content': 'Unsupported OS'})
177-
191+
178192
return os_worker_id_function()
179193

180194
return {'status': 'error', 'content': 'Not running from an executable'}

0 commit comments

Comments
 (0)