Beispiel #1
0
def scotland_hospitalizations(data_path, params):
    df = pd.read_excel(data_path, 'Table 2 - Hospital Care', skiprows=4)
    df = df.rename(columns={
        df.columns[1]: 'icu_current',
        df.columns[4]: 'hospitalized_current',
    })
    df = date_utils.parse_date(df, params)
    df = region_utils.join_region_codes(df, params)
    return df
Beispiel #2
0
def scotland_hospitalizations(params):
    data_path = path_utils.most_recent_data(params)['path']
    df = pd.read_excel(data_path, 'Table 2 - Hospital Care', skiprows=4)
    df = df.rename(columns={
        df.columns[1]: "icu_current",
        df.columns[4]: "hospitalized_current",
    })
    df = date_utils.parse_date(df, params)
    df = region_utils.join_region_codes(df, params)
    return df
Beispiel #3
0
def save_member_info(vars):
    user_id = vars.user_id
    member_id = vars.member_id
    member_info = vars.member_info
    if 'facePhotoURL' in member_info:
        del member_info.facePhotoURL  #it is saved separately, not updated in client and can only destroy here
    if member_info:
        new_member = not member_info.id
        #--------------handle dates - old version------------------
        date_fields = []
        for k in member_info:
            if k.startswith("date_of_") and k.endswith('_str'):
                date_fields.append(k)
        for df in date_fields:
            k = df[:-4]
            member_info[df], member_info[k] = date_of_date_str(member_info[df])
        #--------------handle dates - new version------------------
        tbl = db.TblMembers
        for fld in tbl:
            if fld.type == 'date':
                fld_str_name = fld.name + '_string'
                fld_span_name = fld.name + '_span_size'
                fld_scale_name = fld.name + '_scale'
                if fld_str_name not in tbl or fld_span_name not in tbl:
                    continue
                if fld_str_name in member_info:
                    date_scale, date = parse_date(member_info[fld_str_name])
                    member_info[fld.name] = date
                    member_info[fld_scale_name] = date_scale

        #--------------handle dates - end--------------------------
        result = insert_or_update(db.TblMembers, **member_info)
        if isinstance(result, dict):
            return dict(errors=result['errors'])
        member_id = result
        member_rec = get_member_rec(member_id)
        if new_member:
            member_rec.facePhotoURL = photos_folder(
                'profile_photos') + "dummy_face.png"
        member_rec = json_to_storage(member_rec)
        ws_messaging.send_message(key='MEMBER_LISTS_CHANGED',
                                  group='ALL',
                                  member_rec=member_rec,
                                  new_member=new_member)
    result = Storage(info=member_info)
    if member_id:
        result.member_id = member_id
    #todo: read-modify-write below?
    ##get_member_names() #todo: needed if we use caching again
    return result
Beispiel #4
0
def default_read_function(params):
    source_params = params['path']
    read_params = None
    if 'read' in params['load']:
        read_params = params['load']['read']
    data_path, _ = most_recent_data(source_params['dir'],
                                    source_params['file'])
    file_extension = source_params['file'].split('.')[1]
    default_args = {
        'csv': {
            'encoding': None,
            'delimiter': None
        },
        'xlsx': {
            'sheet_name': 0,
            'skiprows': None,
            'skipfooter': 0
        }
    }
    read_args = default_args[file_extension]
    if read_params:
        for k in read_args.keys():
            if k in read_params:
                read_args[k] = read_params[k]
    if file_extension == 'csv':
        data_df = pd.read_csv(data_path,
                              delimiter=read_args['delimiter'],
                              encoding=read_args['encoding'])
    elif file_extension == 'xlsx':
        data_df = pd.read_excel(data_path,
                                sheet_name=read_args['sheet_name'],
                                skiprows=read_args['skiprows'],
                                skipfooter=read_args['skipfooter'])

    data_df = date_utils.parse_date(data_df, params)
    data_df = rename_data_columns(data_df, params)

    return data_df