File size: 1,892 Bytes
8a79f2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)

    """
    # only subset the df if the run is not a test b/c during a test run, the file has already been subsetted!
    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!")