Exemplo n.º 1
0
def handle_ma(res, mapping):
    tagged = {}

    df = MaRawData(res[0])
    tabs = ['DeathsReported (Report Date)', 'Testing2 (Report Date)',
            'Cases (Report Date)', 'Hospitalization from Hospitals']

    for tab in tabs:
        # report the last row
        partial = map_attributes(df[tab].iloc[-1], mapping, 'MA')
        tagged.update(partial)

    # positive pcr
    tests = df['TestingByDate (Test Date)'].filter(like='All Positive')
    tagged[Fields.SPECIMENS_POS.name] = tests.sum()['All Positive Molecular Tests']

    hosp = df['RaceEthnicityLast2Weeks']
    maxdate = hosp['Date'].max()
    tagged[Fields.HOSP.name] = hosp[hosp['Date'] == maxdate].sum()['Ever Hospitaltized']

    # weekly report:
    df = MaRawData(res[0], "Weekly Public Health Report - Raw Data")

    # recovered
    rec = df['Quarantine and Isolation'].sort_values('Date')
    recovered = rec[rec['Status'] == 'Total Cases Released from Isolation'].iloc[-1]['Residents']
    tagged[Fields.RECOVERED.name] = recovered
    antibody = df['Antibody'].sum()
    tagged[Fields.ANTIBODY_TOTAL_PEOPLE.name] = antibody['Total Tests']
    tagged[Fields.ANTIBODY_POS_PEOPLE.name] = antibody['Positive Tests']

    return tagged
def handle_ma(res, mapping):
    '''Returning a list of dictionaries (records)
    '''
    tagged = []
    # break the mapping to {file -> {mapping}}
    # not the most efficient, but the data is tiny
    tab_mapping = build_leveled_mapping(mapping)
    tabs = MaRawData(res[0])
    for tabname in tab_mapping.keys():
        df = tabs[tabname].rename(columns=tab_mapping[tabname])
        df[DATE] = pd.to_datetime(df[DATE])
        # TODO: FIX ME LATER
        # drop NaT values
        df = df.loc[df[DATE].notna()]
        # expect it to always exist (we control the file list)
        by_date = tab_mapping[tabname].pop(DATE_USED)
        df = df[tab_mapping[tabname].values()]

        # need to cumsum TestingByDate file
        if tabname.startswith('TestingByDate'):
            df = df.set_index(DATE).cumsum()
            df[DATE] = df.index

        df[DATE_USED] = by_date
        tagged.extend(df.to_dict(orient='records'))

    return tagged
Exemplo n.º 3
0
def handle_ma(res, mapping):
    '''Returning a list of dictionaries (records)
    '''
    tagged = []
    # break the mapping to {file -> {mapping}}
    # not the most efficient, but the data is tiny
    tab_mapping = {
        x.split(":")[0]: {}
        for x in mapping.keys() if x.find(':') > 0
    }
    for k, v in mapping.items():
        if k.find(':') < 0:
            continue
        tab, field = k.split(":")
        tab_mapping[tab][field] = v

    tabs = MaRawData(res[0])
    for tabname in tab_mapping.keys():
        if tabname.startswith('DateofDeath'):
            date_field = 'Date of Death'
        else:
            date_field = 'Date'
        df = tabs[tabname]
        # handle dates
        df[date_field] = pd.to_datetime(df[date_field])

        # expect it to always exist (we control the file list)
        by_date = tab_mapping[tabname].pop('BY_DATE')
        df = df.rename(
            columns=tab_mapping[tabname])[tab_mapping[tabname].values()]

        # need to cumsum TestingByDate file
        if tabname.startswith('TestingByDate'):
            df = df.set_index('DATE').cumsum()
            df['DATE'] = df.index

        df['BY_DATE'] = by_date
        tagged.extend(df.to_dict(orient='records'))

    return tagged