def build(self):
   self.create_results_table()
   states = utils.get_states()
   election_years = utils.get_election_years(base_dir=BASE_DIR)
   house_files = utils.get_election_files(BASE_DIR, election_years, 'house', states)
   for hfile in house_files:
     self.parse_results_data(hfile)
 def build(self):
   self.base_dir = BASE_DIR + 'divisions/'
   self.create_electorates_table()
   states = utils.get_states()
   election_years = utils.get_election_years(base_dir=BASE_DIR)
   election_files = utils.get_election_files(BASE_DIR, election_years, 'house', states)
   for efile in election_files:
     self.parse_electorate_file(efile)
def state():
    if request.method == 'POST':
        jobs = df[df.state == request.form['state']].groupby(
            'soc_id').first().reset_index()
        jobs = [job[1] for job in jobs.iterrows()]
        return render_template('state_list.html',
                               jobs=jobs,
                               no_jobs=len(jobs),
                               state=request.form['state'])
    else:
        return render_template('state_search.html', states=utils.get_states())
 def build(self):
     self.create_parties_table()
     states = utils.get_states()
     election_years = utils.get_election_years(base_dir=BASE_DIR)
     house_files = utils.get_election_files(BASE_DIR, election_years, "house", states)
     senate_files = utils.get_election_files(BASE_DIR, election_years, "senate", states)
     party_dictionary = {}
     for fdata in house_files:
         self.parse_party_data(fdata, party_dictionary)
     for sdata in senate_files:
         self.parse_party_data(sdata, party_dictionary)
     self.insert_party_data(party_dictionary)
def _get_us_jobs():
    with open('jobs_250.json', 'r') as f:
        product = utils.tag_job_product(json.loads(''.join(f.readlines())))
        df = pd.DataFrame(product,
                          columns=[
                              'soc_id', 'title', 'company', 'location',
                              'remote', 'relocation', 'tag'
                          ])
    tmp_columns = df.location.str.split(',', expand=True)
    df['city'] = tmp_columns[0].str.strip()
    df['state'] = tmp_columns[1].str.strip()
    df = df.drop('location', axis=1)
    return df[df.state.apply(lambda state: state in utils.get_states())]
Exemple #6
0
    def __init__(self):
        self.states = get_states()
        self.reports_file = 'reports.json'
        self.reports_dir = 'reports/'
        self.image_dir = 'static/images/'
        self.api_endpoint = 'https://covid-api.com/api/'
        self.dates_file = 'dates.json'
        self.first_date = '2020-04-16'
        self.dates = get_dates(self.first_date)
        self.reports = []
        self.reports_parsed = []

        dump_json(self.dates_file, self.dates)
Exemple #7
0
 def __init__(self):
     self.states = get_states()
     self.dates_file = 'dates.json'
     self.reports_file = 'reports.json'
     self.reports = load_json(self.reports_file)
     self.dates = load_json(self.dates_file)
     self.danger = []
     self.deaths = []
     self.confirmed = []
     self.fatality = []
     self.deaths_growth = []
     self.confirmed_growth = []
     self.fatality_growth = []
     self.scoreboard_items = 10
Exemple #8
0
def get_geoid_list(params):
    logging.info("enter get_geoid_list")
    if params['queryGeoMode'] == 'states':
        # process included states
        states = params['queryLocation']
        state_mode = params['queryLocationMode']
        state_year = params['queryCensusYear']
        if state_year not in census_years:
            # only certain years are included
            raise ValueError(
                'Selected census year is {}, but only {} are supported'.format(
                    state_year, census_years))
        if state_mode == 'include':
            if len(states) > 0:
                include_states = states
            else:
                # no query states are defined, return error
                raise ValueError(
                    'Query mode is "include" but no state is included in query'
                )
        elif state_mode == 'exclude':
            include_states = set(get_states()) - set(states)
            if len(include_states) == 0:
                raise ValueError(
                    'Query mode is "exclude" but all states are included in query'
                )
        else:
            raise ValueError('Query state mode is incorrect')
        # query census tracts
        query = {}
        query = query_mapping_states(params, include_states, query)
        results = db_map['census_tracts_{}'.format(state_year)].find(query)
        logging.info('query census tracts data: {}\n{}\n\n'.format(
            str(query), str(results.count())))
        GEOID_list = [r['GEOID'] for r in results]
    elif params['queryGeoMode'] == 'geo':
        GEOID_list = geo_find_census_tracts(params)
    else:
        raise ValueError('Query mode is incorrect')
    return GEOID_list
Exemple #9
0
        obs = data_in["channel" + str(action)][time +
                                               pretrain_length]  # Observe
        next_state = utils.state_gen(state_in, action, obs)  # Go to next state
        reward = obs  # Reward
        total_rewards += reward  # Total Reward
        exp_memory.add(
            (state_in, action, reward, next_state))  # Add in exp memory

        state_in = next_state
        history_input = next_state

        if (time > state_size
                or episode != 0):  # If sufficient minibatch is available
            batch = exp_memory.sample(batch_size)  # Sample without replacement
            states = utils.get_states(
                batch)  # Get state,action,reward and next state from memory
            actions = utils.get_actions(batch)
            rewards = utils.get_rewards(batch)
            next_state = utils.get_next_states(batch)

            feed_dict = {q_network.input_in: next_state}
            actuals_Q = sess.run(
                q_network.out_layer,
                feed_dict=feed_dict)  # Get the Q values for next state

            actuals = rewards + gamma * np.max(
                actuals_Q, axis=1)  # Make it actuals with discount factor
            actuals = actuals.reshape(batch_size)

            # Feed in here to get loss and optimise it
            loss, _ = sess.run(
Exemple #10
0
import datetime
import streamlit as st
import yaml

import utils

with open("params.yaml", "r") as f:
    params = yaml.load(f, yaml.Loader)

st.title("Progressão Temporal COVID-19 Brasil")

data = utils.load_data(os.path.join(params['data_dir'], params['fname']))

rolling = st.sidebar.number_input("Rolling", min_value=1, step=1, max_value=14)
estados = st.sidebar.multiselect("Estados", options=utils.get_states(data))
per_millon = st.sidebar.checkbox("Por milhão")
starting_date = st.sidebar.date_input("A partir da data:",
                                      min_value=utils.get_min_date(data),
                                      value=utils.get_min_date(data))
cum_sum = st.sidebar.checkbox("Acumulado")
brazil = st.sidebar.checkbox("Nacional")

utils.show_graph_by_states(data,
                           estados=estados,
                           rolling=rolling,
                           per_millon=per_millon,
                           cum_sum=cum_sum,
                           brazil=brazil,
                           starting_date=starting_date)
Exemple #11
0
sshmm.model = StateSplitingHMM.fit(
    sshmm.model, data['train']['xs'],
    args.max_iterations,
    args.n_jobs,
)
sshmm.plot(
    args,
    image_path=os.path.join(image_dir, f'sshmm_{sshmm.num_states:02}'),
    model=sshmm.model,
    cluster2utt=sshmm.cluster2utt,
)

for iteration in range(args.num_split):
    print(f'*'*20, f'iteration {iteration+1}', '*'*20, flush=True)
    model_json = json.loads(sshmm.model.to_json())
    state2emissionprob, _, _ = get_states(model_json)
    max_entropy_state = max(state2emissionprob.items(), key=lambda x: entropy(list(x[1].values())))[0]

    print("    Try temperal split")
    t_model, t_logprob, t_new = sshmm.fit_split(data['train']['xs'], max_entropy_state, sshmm.temperal_split)
    print()

    print("    Try vertical split")
    v_model, v_logprob, v_new = sshmm.fit_split(data['train']['xs'], max_entropy_state, sshmm.vertical_split)
    print()

    print(f"    LogProb: temperal = {t_logprob:.3f}; vertical = {v_logprob:.3f}")

    if t_logprob > v_logprob:
        print("    Choose temperal split")
        sshmm.model = t_model