common_utils.py 958 Bytes
Newer Older
lcn's avatar
lcn committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
def get_electric_index(alarm_score):
    """
    根据报警分,返回用电安全指数
    :param alarm_score:
    :return:
    """
    if 0 <= alarm_score < 2:
        electric_use_score = -10 * alarm_score + 100
    elif 2 <= alarm_score < 5:
        electric_use_score = (-10 / 3) * alarm_score + (80 + 20 / 3)
    elif 5 <= alarm_score < 10:
        electric_use_score = -2 * alarm_score + 80
    elif 10 <= alarm_score < 20:
        electric_use_score = -6 * alarm_score + 120
    else:
        electric_use_score = 0
    return round(electric_use_score)


def carbon_index(energy_deviation):
    """根据能耗偏差,返回碳排指数"""
    if energy_deviation > 0.1:
        index_value = 100
    elif -0.1 < energy_deviation <= 0.1:
        index_value = 200 * energy_deviation + 80
    elif -0.2 < energy_deviation <= -0.1:
        index_value = 600 * energy_deviation + 120
    else:
        index_value = 0
    return round(index_value)