|
|
import os |
|
|
from lib.utilities import serialize |
|
|
from lib.data_helpers import data_utils |
|
|
from lib.experiment_specs import study_config |
|
|
|
|
|
|
|
|
def select_test_appcodes(mc): |
|
|
""" |
|
|
purpose: selects a set of appcodes whose data will be used to test the pipeline quickly. Specifically, |
|
|
it selects 50 active appcodes (i.e. have use data in past 3 days) and 25 appcodes inactive appcodes |
|
|
|
|
|
input: the clean master user df |
|
|
""" |
|
|
last_survey_complete = data_utils.get_last_survey() |
|
|
code = study_config.surveys[last_survey_complete]["Code"] |
|
|
print(f"\n Selecting test codes. last survey complete is {last_survey_complete}") |
|
|
active_appcodes = list(mc.loc[(mc[f"{code}_Complete"]=="Complete")&(mc["ActiveStatus"]=="Normal"),"AppCode"]) |
|
|
inactive_appcodes = list(mc.loc[(mc[f"R_Complete"]!="Complete"),"AppCode"]) |
|
|
test_codes = {"AppCode":active_appcodes[50:100]+inactive_appcodes[25:50]} |
|
|
serialize.save_pickle(test_codes, path = os.path.join("data","external","dropbox_confidential_test","TestCodes"),df_bool = False) |
|
|
return test_codes |
|
|
|
|
|
def save_test_df(df, path): |
|
|
""" |
|
|
subsets the df to include testcodes |
|
|
|
|
|
Parameters |
|
|
---------- |
|
|
df - any df that is about to get saved |
|
|
path - the path to save the df (in the test data folders) |
|
|
|
|
|
""" |
|
|
|
|
|
config_user_dict = serialize.open_yaml("config_user.yaml") |
|
|
if config_user_dict["local"]["test"] == False: |
|
|
test_codes = serialize.open_pickle(os.path.join("data", "external", "dropbox_confidential_test", "TestCodes"), df_bool=False) |
|
|
test_appcodes = test_codes["AppCode"] |
|
|
df = df.loc[df["AppCode"].isin(test_appcodes)] |
|
|
|
|
|
serialize.save_pickle(df,path) |
|
|
|
|
|
print(df.dtypes) |
|
|
try: |
|
|
serialize.save_hdf(df, path) |
|
|
except: |
|
|
print("couldn't save hdf!") |