def reccomend_blood_pressure(blood_pressure):
    recommendation_to_user = ""

    if blood_pressure >= 140 / 90:
        if blood_pressure >= 160 / 100:
            recommendation_to_user += "Blood Pressure is in danger levels, these levels are in need of medication\n"
        else:
            recommendation_to_user += "Blood Pressure is High but still not too serious, changes of lifestyle is important \n"

        recommendation_to_user += "Alcohol affects and causes Blood Pressure also \n" \
                                "More then 4 cups of caffeine also affects Blood Pressure \n"
    elif blood_pressure <= 90 / 60:
        recommendation_to_user += "Blood pressure is low, be carefull from diziness and fainting\n"

    elif (blood_pressure < 140 / 90) and (blood_pressure > 90 / 60):
        recommendation_to_user += "Blood pressure is in ideal boundaries \n"

    return str(recommendation_to_user)

def reccomend_body_weight(body_mass_index, time_spend_exercising_minutes):
    recommendation_to_user = ""

    if body_mass_index >= 25:
        recommendation_to_user += "Body mass is overweight, you should increase your exercising time \n"
        if time_spend_exercising_minutes < 150:
            recommendation_to_user += "Exercising time has to be at least 150 minutes per week \n"
    elif body_mass_index <= 18.5:
        recommendation_to_user += "Body mass is underweight, increase the amount of food you having \n"
    else:
        recommendation_to_user += "Body mass in normal levels, keep your diet \n"

    return str(recommendation_to_user)

def is_overweight(body_mass_index):
    if (body_mass_index >= 25):
        return True
    else:
        return False

def weight_difference (body_weight, body_weight_previous_day, number_of_last_row_index):
    recommendation_to_user = ""

    if number_of_last_row_index > 1:
        if (body_weight_previous_day > body_weight):
            weight_lost = str(body_weight_previous_day - body_weight)
            recommendation_to_user += "You have lost  " + weight_lost + "kg,  congrats! Keep up the good work. \n"
        elif (body_weight_previous_day < body_weight):
            recommendation_to_user += "You are putting on weight, change you lifestyle \n"
        else:
            recommendation_to_user += "No change of body weight, try harder \n"

    return str(recommendation_to_user)

def smoking_reccomend(cigarettes_smoked_per_day):
    recommendation_to_user = ""

    if cigarettes_smoked_per_day >= 20:
        recommendation_to_user += "Cut on smoking, 1 per day carries 40â€“50 percent of the risk for coronary heart disease and stroke \n"
    elif cigarettes_smoked_per_day>0:
        recommendation_to_user += "You are not a heavy smoker, but 1 per day carries 40â€“50 percent of the risk for coronary heart disease and stroke \n"
    else:
        recommendation_to_user += "You are not a smoker, that's very good! Stay away from cigarettes."

    return str(recommendation_to_user)


def refresh():
    from data import csv_reader


    number_of_last_row_index = csv_reader.lastline()
    row_for_weight_comparisson_index = number_of_last_row_index - 1

    values_from_CSV = csv_reader.lastRowInfo(number_of_last_row_index)

    if (values_from_CSV[0] == -1):
        return "Input some data to get some calculations."
    else:
        blood_pressure = values_from_CSV[0]
        body_mass_index = values_from_CSV[1]
        body_weight = values_from_CSV[2]
        time_spend_exercising_minutes = values_from_CSV[3]
        cigarettes_smoked_per_day = values_from_CSV[4]

        recommendation_to_user = reccomend_blood_pressure(blood_pressure)
        recommendation_to_user += reccomend_body_weight(body_mass_index, time_spend_exercising_minutes)
        is_user_overweight = is_overweight(body_mass_index)
        if is_user_overweight:
            body_weight_previous_day = csv_reader.semiLastRowWeightComparisson(row_for_weight_comparisson_index)
            recommendation_to_user += weight_difference(body_weight, body_weight_previous_day,
                                                                    number_of_last_row_index)
        recommendation_to_user += smoking_reccomend(cigarettes_smoked_per_day)

        return recommendation_to_user


def reccomend_blood_pressure(blood_pressure):
    recommendation_to_user = ""

    if blood_pressure >= 140 / 90:
        if blood_pressure >= 160 / 100:
            recommendation_to_user += "Blood Pressure is in danger levels, these levels are in need of medication\n"
        else:
            recommendation_to_user += "Blood Pressure is High but still not too serious, changes of lifestyle is important \n"

        recommendation_to_user += "Alcohol affects and causes Blood Pressure also \n" \
                                "More then 4 cups of caffeine also affects Blood Pressure \n"
    elif blood_pressure <= 90 / 60:
        recommendation_to_user += "Blood pressure is low, be carefull from diziness and fainting\n"

    elif (blood_pressure < 140 / 90) and (blood_pressure > 90 / 60):
        recommendation_to_user += "Blood pressure is in ideal boundaries \n"

    return str(recommendation_to_user)

def reccomend_body_weight(body_mass_index, time_spend_exercising_minutes):
    recommendation_to_user = ""

    if body_mass_index >= 25:
        recommendation_to_user += "Body mass is overweight, you should increase your exercising time \n"
        if time_spend_exercising_minutes < 150:
            recommendation_to_user += "Exercising time has to be at least 150 minutes per week \n"
    elif body_mass_index <= 18.5:
        recommendation_to_user += "Body mass is underweight, increase the amount of food you having \n"
    else:
        recommendation_to_user += "Body mass in normal levels, keep your diet \n"

    return str(recommendation_to_user)

def is_overweight(body_mass_index):
    if (body_mass_index >= 25):
        return True
    else:
        return False

def weight_difference (body_weight, body_weight_previous_day, number_of_last_row_index):
    recommendation_to_user = ""

    if number_of_last_row_index > 1:
        if (body_weight_previous_day > body_weight):
            weight_lost = str(body_weight_previous_day - body_weight)
            recommendation_to_user += "You have lost  " + weight_lost + "kg,  congrats! Keep up the good work. \n"
        elif (body_weight_previous_day < body_weight):
            recommendation_to_user += "You are putting on weight, change you lifestyle \n"
        else:
            recommendation_to_user += "No change of body weight, try harder \n"

    return str(recommendation_to_user)

def smoking_reccomend(cigarettes_smoked_per_day):
    recommendation_to_user = ""

    if cigarettes_smoked_per_day >= 20:
        recommendation_to_user += "Cut on smoking, 1 per day carries 40â€“50 percent of the risk for coronary heart disease and stroke \n"
    elif cigarettes_smoked_per_day>0:
        recommendation_to_user += "You are not a heavy smoker, but 1 per day carries 40â€“50 percent of the risk for coronary heart disease and stroke \n"
    else:
        recommendation_to_user += "You are not a smoker, that's very good! Stay away from cigarettes."

    return str(recommendation_to_user)


def refresh():
    from data import csv_reader


    number_of_last_row_index = csv_reader.lastline()
    row_for_weight_comparisson_index = number_of_last_row_index - 1

    values_from_CSV = csv_reader.lastRowInfo(number_of_last_row_index)

    if (values_from_CSV[0] == -1):
        return "Input some data to get some calculations."
    else:
        blood_pressure = values_from_CSV[0]
        body_mass_index = values_from_CSV[1]
        body_weight = values_from_CSV[2]
        time_spend_exercising_minutes = values_from_CSV[3]
        cigarettes_smoked_per_day = values_from_CSV[4]

        recommendation_to_user = reccomend_blood_pressure(blood_pressure)
        recommendation_to_user += reccomend_body_weight(body_mass_index, time_spend_exercising_minutes)
        is_user_overweight = is_overweight(body_mass_index)
        if is_user_overweight:
            body_weight_previous_day = csv_reader.semiLastRowWeightComparisson(row_for_weight_comparisson_index)
            recommendation_to_user += weight_difference(body_weight, body_weight_previous_day,
                                                                    number_of_last_row_index)
        recommendation_to_user += smoking_reccomend(cigarettes_smoked_per_day)

        return recommendation_to_user

