Skip to content

Commit

Permalink
bug: check finished even if no start time
Browse files Browse the repository at this point in the history
  • Loading branch information
younesStrittmatter committed Jun 28, 2024
1 parent f80ee53 commit 77c72ae
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)}


Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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"



0 comments on commit 77c72ae

Please sign in to comment.