Example #1
0
def run_refresh(filename):
    proj_filter = []

    with dax.XnatUtils.get_interface() as xnat:
        proj_filter = utils.get_user_favorites(xnat)
        df = get_data(xnat, proj_filter)

    save_data(df, filename)

    return df
Example #2
0
def run_refresh(filename):
    proj_filter = []
    proc_filter = []
    scan_filter = []

    # force a requery
    with dax.XnatUtils.get_interface() as xnat:
        proj_filter = utils.get_user_favorites(xnat)
        df = get_data(xnat, proj_filter, proc_filter, scan_filter)

    save_data(df, filename)

    return df
Example #3
0
def load_stats_data():
    my_redcaps = []
    df = pd.DataFrame()

    # Load assr data
    logging.debug('loading stats data')

    try:
        # Read inputs yaml as dictionary
        with open(REDCAP_FILE, 'rt') as file:
            redcap_data = yaml.load(file, yaml.SafeLoader)
    except EnvironmentError:
        logging.info('REDCap settings file not found, not loading stats')
        df = pd.DataFrame(columns=static_columns())
        return df

    api_url = redcap_data['api_url']

    with dax.XnatUtils.get_interface() as xnat:
        my_projects = utils.get_user_favorites(xnat)

    # Filter the list of redcaps based on our project access
    for r in redcap_data['projects']:
        name = r['name']

        try:
            (proj, proc, res) = parse_redcap_name(name)
        except ValueError:
            continue

        if (proj in my_projects):
            my_redcaps.append(r)

    # Load data from each redcap
    icount = len(my_redcaps)
    for i, r in enumerate(my_redcaps):
        name = r['name']
        api_key = r['key']
        (proj, proc, res) = parse_redcap_name(name)
        logging.info('{}/{} loading redcap:{}'.format(i+1, icount, name))
        try:
            cur_df = load_redcap_stats(api_url, api_key)
            df = pd.concat([df, cur_df], ignore_index=True, sort=False)
        except Exception as err:
            logging.error('error exporting redcap:{}:{}'.format(name, err))
            import traceback
            traceback.print_exc()
            continue

    # Rename columns
    df.rename(columns=STATS_RENAME, inplace=True)

    # Filter out columns we don't want by keeping intersection
    _static = static_columns()
    _var = get_vars()
    _keep = df.columns
    _keep = [x for x in _keep if (x in _var or x in _static)]
    #print('_keep', _keep)
    df = df[_keep]

    # return the stats data
    logging.info('loaded {} stats'.format(len(df)))
    return df