diff --git a/src/autora/experiment_runner/experimentation_manager/firebase/__init__.py b/src/autora/experiment_runner/experimentation_manager/firebase/__init__.py index 80f050d..255374c 100644 --- a/src/autora/experiment_runner/experimentation_manager/firebase/__init__.py +++ b/src/autora/experiment_runner/experimentation_manager/firebase/__init__.py @@ -1,6 +1,7 @@ import time -from typing import Any +from typing import Any, Optional import numpy as np +import pandas as pd import warnings import firebase_admin @@ -43,8 +44,10 @@ def _sequence_to_db_object(iterable, save=False): warnings.warn('Converting np.int64 to int to store in Firestore, may loose precision') if is_float64: warnings.warn('Converting np.float64 to float to store in Firestore, may loose precision') - return {i: int(t) if isinstance(t, np.integer) else float(t) if isinstance(t, np.floating) else t if isinstance(t, - dict) else json.dumps( + return {i: int(t) if isinstance(t, np.integer) else float(t) if isinstance(t, + np.floating) else t if isinstance( + t, + dict) else json.dumps( t) for i, t in enumerate(iterable)} @@ -235,7 +238,8 @@ def set_up_experiment_db( """ app, seq_col = _get_collection(collection_name, firebase_credentials) condition_dict = _sequence_to_db_object(condition) - _set_up_experiment_db(seq_col, condition_dict, doc_out, doc_in, col_observation, col_condition, is_append) + _set_up_experiment_db(seq_col, condition_dict, doc_out, doc_in, col_observation, col_condition, + is_append) firebase_admin.delete_app(app) @@ -276,7 +280,8 @@ def send_conditions( _set_meta(seq_col, condition_dict, doc_meta, is_append) # setup db for conditions and observations - _set_up_experiment_db(seq_col, condition_dict, doc_out, doc_in, col_observation, col_condition, is_append) + _set_up_experiment_db(seq_col, condition_dict, doc_out, doc_in, col_observation, col_condition, + is_append) firebase_admin.delete_app(app) @@ -319,7 +324,8 @@ def get_observations(collection_name: str, def check_firebase_status( - collection_name: str, firebase_credentials: dict, time_out: int, pids_aborted: list = [] + collection_name: str, firebase_credentials: dict, time_out: Optional[int] = None, + pids_aborted: list = [] ) -> str: """ check the status of the condition @@ -337,7 +343,6 @@ def check_firebase_status( (2) finished -> collection of observations is finished (3) unavailable -> all conditions are running, recruitment should be paused """ - if not firebase_admin._apps: cred = credentials.Certificate(firebase_credentials) app = firebase_admin.initialize_app(cred) @@ -362,9 +367,7 @@ def check_firebase_status( is_aborted = False if "pId" in value: is_aborted = value['pId'] in pids_aborted - # check weather the started condition has timed out, if so, reset start_time and - # set available True - if time_from_started > time_out or is_aborted: + if is_aborted: doc_ref_meta.update({key: {"start_time": None, "finished": False, "pId": None}}) available = True else: @@ -377,3 +380,6 @@ def check_firebase_status( return "finished" # if all start_times are set, but there is no data for all of them, pause the condition return "unavailable" + + +