Ejemplo n.º 1
0
def print_map(sensor):
    """Scan the board row by row and print colored tiles."""
    order = range(1, 9)
    for y in order:
        chars = (ap_at_state(x, y, sensor, in_ascii=True) for x in order)
        obj = html_print(' '.join(chars))
        display_html(obj)
Ejemplo n.º 2
0
def prediction_of_deaths(df, notification_percentual, pred):
    # With subotification, deaths prediction must be within the range of 0.5% and 3.0% of total cases
    if notification_percentual < 100:
        st.write(
            'With the present notification value of ' +
            str(notification_percentual) +
            "%, we apply the global mortality rate of 3.5% of total cases.")
        st.markdown(
            '[COVID-19 Global Mortality Rate](https://www.worldometers.info/coronavirus/coronavirus-death-rate/)'
        )
        prediction_of_deaths_3_100 = pred * 3.5 / 100
        st.markdown(
            "- Considering maximum death rate being around 3.5% of the total number of cases, we should expect ** "
            + str(int(round(prediction_of_deaths_3_100))) + "** deaths")
    else:
        plt.figure(figsize=(12, 8))
        add_real_data(df[:-2], "2 days ago", column='deaths')
        add_real_data(df[-2:-1], "yesterday", column='deaths')
        add_real_data(df[-1:], "today", column='deaths')
        add_logistic_curve(df[:-2],
                           "2 days ago",
                           column='deaths',
                           dashes=[8, 8])
        add_logistic_curve(df[:-1],
                           "yesterday",
                           column='deaths',
                           dashes=[4, 4])
        y_max = add_logistic_curve(df, "today", column='deaths')
        label_and_show_plot(plt, "Best logistic fit with the freshest data",
                            y_max)

        st.header('Prediction of deaths')
        st.pyplot(clear_figure=False)

        st.subheader('Predictions as of *today*, *yesterday* and *2 days ago*')

        print_prediction(df[:-2], "2 days ago", 'deaths')
        print_prediction(df[:-1], "yesterday", 'deaths')
        pred = print_prediction(df, "today", 'deaths')
        print()
        html_print("As of today, the total deaths should stabilize at <b>" +
                   str(int(round(pred))) + "</b>")
        # PREDICTION 2
        st.header('Deaths stabilization')
        st.markdown(
            "As of today, the total number of deaths should stabilize at **" +
            str(int(round(pred))) + "** cases.")
Ejemplo n.º 3
0
def visualize(generated_sentence, activation_values, cell_no):
    text_colours = []

    for char, val in zip(generated_sentence, activation_values):
        text_clr = (char, get_clr(val[cell_no]))
        text_colours.append(text_clr)

    html_colors = html_print(''.join(
        [cstr(ti, color=ci) for ti, ci in text_colours]))
    return html_colors
Ejemplo n.º 4
0
def print_colored_query_string(pw_rel_dfs):
    
    heads = {h: {} for h in set(pw_rel_dfs['ruleH_1']['HEAD'])}
    rules = {}
    for _, p in pw_rel_dfs['ruleOcc_2'][['ATOM', 'OCC']].iterrows():
        rules[(p['ATOM'], int(p['OCC']))] = {}
    
    true_heads = set(pw_rel_dfs['ruleHTrue_1']['HEAD'])
    true_rules = set([])
    for _, p in pw_rel_dfs['ruleOccTrue_2'][['ATOM', 'OCC']].iterrows():
        true_rules.add((p['ATOM'], int(p['OCC'])))
    
    for _, row in pw_rel_dfs['newHArc_3'].iterrows():
        pos = int(row['POS'])
        h = row['HEAD']
        var = row['VAR']
        heads[h][pos] = var
    for _, row in pw_rel_dfs['newArc_4'].iterrows():
        rule = (row['ATOM'], int(row['OCC']))
        pos = int(row['POS'])
        var = row['VAR']
        rules[rule][pos] = var
        
#     print(heads, rules, true_heads, true_rules)
    
    heads_htmls = []
    for h in sorted(heads.keys()):
        variables = [remove_double_quotes(heads[h][k]) for k in sorted(heads[h].keys())]
        heads_htmls.append(cstr('{}({})'.format(head_to_node(h), ','.join(variables)), 'green' if h in true_heads else 'red'))
    
    
    rules_htmls = []
    for (r, occ) in sorted(rules.keys()):
        variables = [remove_double_quotes(rules[(r,occ)][k]) for k in sorted(rules[(r,occ)].keys())]
        rules_htmls.append(cstr('{}({})'.format(head_to_node(r), ','.join(variables)), 'green' if (r,occ) in true_rules else 'red'))
    
#     display(html_print(cstr(' '.join(heads_htmls + rules_htmls))))
    
    
    heads_htmls_combined = cstr(' ; '.join(heads_htmls))
    rules_htmls_combined = cstr(', '.join(rules_htmls))
    display(html_print(cstr('{} :- {}.'.format(heads_htmls_combined, rules_htmls_combined))))
    
    eqls = []
    for _, row in pw_rel_dfs['eqOrd_3'].iterrows():
        eqls.append('{} = {}'.format(row['VAR1'], row['VAR2']))
    print('where' if len(eqls) > 0 else '')
    print(' and '.join(eqls))
Ejemplo n.º 5
0
def print_rewritten_query_string(pw_rel_dfs, html=True, display_q=True, include_ineqls=True):

    heads_htmls = get_substituted_query_heads(pw_rel_dfs, colored=True, html=html)
    rules_htmls = get_substituted_query_body_rules(pw_rel_dfs, colored=True, html=html)
    neqls = neq_rules(pw_rel_dfs)
    if include_ineqls:
        rules_htmls.extend(neqls)
    
    heads_htmls_combined = ' ; '.join(heads_htmls)
    rules_htmls_combined = ', '.join(rules_htmls)
    
    q_str = '{} :- {}.'.format(heads_htmls_combined, rules_htmls_combined)
    
    if html:
        q_str = cstr(q_str)
        if display_q:
            display(html_print(q_str))
    else:
        if display_q:
            print(q_str)
    return q_str
Ejemplo n.º 6
0
def print_fancy_rewrite(pw_rel_dfs, html=True, display_q=True):
    
    heads_htmls = get_original_query_heads(pw_rel_dfs, colored=True, html=html)
    rules_htmls = get_original_query_body_rules(pw_rel_dfs, colored=True, html=html)
    eq_grps = eq_groups(pw_rel_dfs, single_grps=True)
    eqls = ['='.join(map(remove_double_quotes, grp)) for grp in eq_grps]
    eqls = ['[{}]'.format(eq_grp) for eq_grp in eqls]
    
    heads_htmls_combined = ' ; '.join(heads_htmls)
    rules_htmls_combined = ', '.join(rules_htmls)
    eqls_combined = ''.join(eqls)
    if html:
        eqls_combined = cstr(eqls_combined, 'blue')
    
    q_str = '{} :- {}. % {}'.format(heads_htmls_combined, rules_htmls_combined, eqls_combined)
    
    if html:
        q_str = cstr(q_str)
        if display_q:
            display(html_print(q_str))
    else:
        if display_q:
            print(q_str)
    return q_str
Ejemplo n.º 7
0
 def print_coloured_text (self, coloured_text):
     return (html_print(" <br> ".join(np.array(coloured_text))))#[ordering[0:10]]))