Example #1
0
def assemble(kL, rL, conf):

    #ufmt.pprint(conf)
    #sys.exit()

    # labels are in the first column
    labels = generate_labels(kL, conf)
    
    # these are the rows, values converted to str
    pL = []
    for vL in rL:    
        pL.append([str(n) for n in vL])
        
    # next add dates as the first row
    
    if not conf['no_dates']:
        dL = get_dates(conf)
        if conf['rate']:
            dL.append('stat')
        pL = [dL] + pL
   
    # add a space to the first col, first row
    labels = [''] + labels
        
    if conf['total']:
        # add a space to the first col, last row
        labels.append('total')
    
        # conf['totals'] contains the actual values
        tL = conf['totals_line']
        if conf['rate']:
            tL.append(round(umath.stat(tL), 3))   
            
        # convert the last row to str as well                     
        last = [str(v) for v in tL]
        pL += [last]
    
    # add an extra 2 spaces to each value in the last column
    if conf['rate']:
        for vL in pL:
            vL[-1] = '  ' + vL[-1]
        
    return labels, pL
Example #2
0
import sys, os
base = os.environ.get('covid_base')

sys.path.insert(0, base)
sys.path.insert(1, base + '/myutil')
from ustrings import us_states
from umath import stat

from all_states import rL, labels

#------
us_states['DC'] = 'DC'
states = [us_states[e] for e in labels]

values = []
for vL in rL:
    st = stat(vL[-15:])
    values.append(st)

#---------------------

import plotly.express as px

fig = px.choropleth(locations=states,
                    locationmode="USA-states",
                    color=values,
                    scope="usa")

fig.show()
Example #3
0
def calc(kL, rL, conf):
    if conf['verbose']:
        pprint(conf, 'fmt')

    # here is where we trim according to -n
    rL = trim_columns(rL, conf)

    conf['totals_line'] = umath.totals(rL)

    # if normalizing
    # also adjust totals to total population

    if conf['pop']:
        kL, nL, total_pop = do_pop_normalization(kL, rL)

        tL = conf['totals_line']
        conf['totals_line'] = normalize(total_pop, tL)

        rL = nL

    if conf['average']:
        rL = compute_average(rL, conf)

    pL = []

    # special case b/c eu key not in keylist

    if 'eu' in conf['names']:
        if kL[0] == ';;;Austria':
            if conf['only']:
                tL = [str(n) for n in conf['totals_line']]
                return [';;;eu'], [conf['totals_line']]

    # compute stats based on the last 7 days
    # unless we trimmed above to fewer than 7 values
    i = 7

    # sort only
    if not conf['rate']:

        if conf['sort']:
            pL = []
            for kL, vL in zip(kL, rL):
                pL.append([kL, vL])

            # sort on the latest value
            pL.sort(key=lambda t: t[1][-1], reverse=True)

            kL = [t[0] for t in pL]
            rL = [t[1] for t in pL]

    # stats (rate) +/- sort
    elif conf['rate']:

        # keep each stat as float until after sort
        stats = [round(umath.stat(vL[-i:]), 3) for vL in rL]

        for kL, vL, st in zip(kL, rL, stats):
            pL.append([kL, vL, st])

        if conf['sort']:
            # sort on the statistic
            pL.sort(key=lambda t: t[2], reverse=True)

        kL = []
        rL = []
        for t in pL:
            kL.append(t[0])
            t[1] += [str(t[2]).ljust(5)]
            rL.append(t[1])

    # trim the rows at this time
    # totals are calculated but not yet attached

    if conf['N']:
        N = conf['N']
        rL = rL[:N]
        kL = kL[:N]

    return kL, rL
Example #4
0
# we do not need to filter:
# sL = counties['features']
# sL = [e for e in sL if e[u'properties'][u'STATE'] == fips]

#--------------------

# we need to construct a pandas data frame with
# fips stats

kL = []
for state in states:
    skL = ukeys.key_list_for_search_term(D, state, mode='state')
    kL.extend(skL)

rL = [D[k]['cases'][-10:] for k in kL]
sL = [umath.stat(vL) for vL in rL]

sL = [umath.quintiles(n) for n in sL]

#--------------------

fips = [ukeys.fips_for_key(k) for k in kL]

#--------------------

import pandas as pd

df = pd.DataFrame({'fips': fips, 'stat': sL})

#print(df)
Example #5
0
#--------------------

# we need to construct a pandas data frame with
# fips stats

sys.path.insert(1, base + '/analysis')

from all_states import states, rL

# dict from 'Alabama' to 'AL'
from ustates import states
from ustates import state_to_abbrev as stD

abbrev = [stD[state] for state in states]

st = [umath.stat(vL[-7:]) for vL in rL]

#--------------------

import pandas as pd

df = pd.DataFrame(data={'state': abbrev, 'value': st})

#--------------------

import plotly.express as px

from ucolors import cL

fig = px.choropleth(df,
                    locations=abbrev,