Exemplo n.º 1
0
def risk_nutrition(id_user, comp=False, db=None):
    """
    Give a risk using nutrition information
    WARNING: untested rules
    """
    if db is None:
        db = create_database_connection()

    score = 0
    if not comp:
        return 0
    # obtain the responses
    ans = db.get_responses_category(id_user=id_user, phase=2)
    # load the rules file
    table = read_csv('food_model.csv', sep=';')
    for _, row in table.iterrows():
        # Item Table Group
        table_ = round(row['Table'])

        answer = ans[row['Item']]
        if row['Daily'].strip().lower() == 'yes':
            answer *= 7

        if table_ == 1:
            score += table_1(group=row['Group'], n=answer)
        elif table_ == 2:
            score += table_2(answer)
        elif table_ == 3:
            score += table_3(answer)

    return score * 10 / table.shape[0]
Exemplo n.º 2
0
def risk_activity(id_user, comp=False, db=None):
    if db is None:
        db = create_database_connection()

    if not comp:
        return 0

    ans = db.get_responses_category(id_user=id_user, phase=3)
    # compute the METS-min/week
    METS = ans[0] * ans[1] * 8 + ans[2] * ans[3] * 4 + ans[4] * ans[5] * 3.3
    # this have to be reviewed for sure!
    superior_limit = 1800
    return (min(METS, superior_limit) / superior_limit) * 100
Exemplo n.º 3
0
def obesity_risk(id_user, completed=None, network=True):
    """
    Update for "explained version"
    :param network:
    :param id_user:
    :param completed:
    :return: score, dict with the subscores
    """
    # make connection
    db = create_database_connection()
    if completed is None:
        completed = db.check_completed(id_user)

    # coeficient for each part
    coef = (0.33, 0.34, 0.33)

    bmi_score, bmi = risk_bmi(id_user, db)
    part_1 = bmi_score * coef[0]
    part_2 = risk_nutrition(id_user, completed[1], db) * coef[1]
    part_3 = risk_activity(id_user, completed[2], db) * coef[2]

    network_correction, n_contacts, mean_contacts = 0, 0, 0

    raw_wakaestado = min(part_1 + part_2 + part_3, 100)
    if network:
        network_correction, n_contacts, mean_contacts = network_influence(
            id_user, raw_wakaestado, db, all(completed))

    final_wakaestado = min(raw_wakaestado + network_correction, 100)
    # pack the different parts
    partial_scores = {
        'wakascore': final_wakaestado,
        'bmi_score': bmi_score,
        'nutrition': part_2 / coef[1],
        'activity': part_3 / coef[2],
        'network': network_correction * 10,  # visualizacion
        'bmi': bmi,
        'n_contacts': n_contacts,
        'mean_contacts': ceil(mean_contacts)
    }

    # store the last wakaestado
    db.set_last_wakaestado(id_user, final_wakaestado)
    # close stuff
    db.close()
    del db
    return final_wakaestado, partial_scores
Exemplo n.º 4
0
def risk_bmi(id_user, db=None):
    """
    Gives a risk score
    this is a modular function in order be easier to update
    """
    if db is None:
        db = create_database_connection()
    bmi = db.getBMI(id_user)
    if bmi == 0:  # sanity check
        return 0, 0

    if bmi >= 40:
        return 0, bmi
    elif 35 <= bmi < 40:
        return 25, bmi
    elif 30 <= bmi < 35:
        return 50, bmi
    elif 25 <= bmi < 30:
        return 75, bmi
    elif bmi < 25:
        return 100, bmi
Exemplo n.º 5
0
                time.sleep(float(environ.get('CONSULTING_TIME', 0.4)))
            else:
                # if no messages lets be *more* gentle with telegram servers
                time.sleep(float(environ.get('NO_MESSAGE_TIME', 0.8)))

        except Exception as e:
            logger.error(e)
            logger.error('Bot to sleep!')
            time.sleep(float(environ.get('ERROR_TIME', 2)))


if __name__ == '__main__':
    # TODO QUESTIONS ON CACHE FOR NEXT VERSION
    init_date = datetime.datetime.now()

    db = create_database_connection()
    db.setup()
    # caching the number of questions
    nq_category = db.n_questions()

    # very important, this password is used to serve the data as file
    password_data = environ.get('PASSWORD_DATA')

    # default language
    def_lang_ = environ.get('DEFAULT_LANG', 'es')

    # link to the network
    network_link = environ.get('NETWORK_LINK').replace('_', '\\_')
    network_filename = environ.get('NETWORK_FILENAME', 'netweb').lower()
    # god mode
    god_mode = environ.get('GOD_MODE').lower()