def show_electricity_consumption_diff(dt_in, freq=8, p="true"):
    dates_result1 = date_interval(dt_in, freq)
    dates1 = dates_result1[0]  # x轴的时间序列
    step1 = dates_result1[1]  # 时间间隔的步长
    # 计算系统负荷
    system_capacity = formula.cal_system_capacity(dt_in)
    # 计算原系统模拟用电量/COP
    power_simulate, cop = formula.cal_simulated_power(dt_in, 1, dt_in['冷却水管出水温度(℃)'], dt_in['冷供水管供水温度(℃)'],
                                                      system_capacity)
    # 计算新系统主机+蓄冷泵用电量
    power_retrofit = 0
    for i in range(1, 5):
        power_retrofit += dt_in['CH{}功率(KW)'.format(i)]
    power_retrofit += dt_in['KAP6功率(KW)']
    # 计算原系统、新系统电费
    electric_charge_simulate = formula.cal_electric_charge(dt_in, power_simulate, group='day')
    electric_charge_retrofit = formula.cal_electric_charge(dt_in, power_retrofit, group='day')
    # print('原系统主机累计电费:%s\r\n新系统主机+蓄冷泵累计电费:%s' % (electric_charge_simulate, electric_charge_retrofit))
    # print('power_simulate %s\r\n power_retrofit %s' % (power_simulate, power_retrofit))
    # print("cal again,check if cache work")
    if p == "fales":
        pass
        # 绘图
        # fig = plt.subplot()
        # plt.xticks(list(np.arange(0, dt_in.index[-1], step1)), tuple(dates1), rotation=30)  # x轴的时间间隔设置
        # fig.plot(power_simulate, color=color[5], label='原系统模拟主机用电')
        # fig.plot(power_retrofit, label='新系统主机+蓄冷泵用电')
        # fig.set_title('新旧系统用电对比')
        # fig.set_ylabel('功率(kw)')
        # fig.grid()
        # fig.legend()
        # plt.show()
    else:
        return [power_simulate, power_retrofit, dates1, electric_charge_simulate, electric_charge_retrofit]
def show_system_capacity(dt_in, freq=48):
    dates_result1 = date_interval(dt_in, freq)
    dates1 = dates_result1[0]  # x轴的时间序列
    step1 = dates_result1[1]  # 时间间隔的步长
    # 计算系统负荷
    system_capacity = formula.cal_system_capacity(dt_in)
    # 计算原系统模拟用电量/COP
    power_sum, cop = formula.cal_simulated_power(dt_in, 1, dt_in['冷却水管出水温度(℃)'], dt_in['冷供水管供水温度(℃)'], system_capacity)
def show_equip_power(dt_in, freq=8):
    dates_result1 = date_interval(dt_in, freq)
    dates1 = dates_result1[0]  # x轴的时间序列
    step1 = dates_result1[1]  # 时间间隔的步长
    power_chiller = 0
    for i in range(1, 5):
        power_chiller += dt_in['CH{}功率(KW)'.format(i)]
    power_cooling = dt_in['KAP2功率(KW)'] + dt_in['KAP4功率(KW)']
    power_cooled = dt_in['KAP1功率(KW)'] + dt_in['KAP5功率(KW)']
def showbug_TemBiased(dt_input, search='冷冻水', freq=12):
    '''
    显示四台主机的冷冻/冷却回水温度
    :param dt_input:
    :param search:
    :param freq:
        freq默认是2h
    :return:
    '''
    dates_result1 = date_interval(dt_input, freq)
    dates1 = dates_result1[0]  # x轴的时间序列
    step1 = dates_result1[1]  # 时间间隔的步长
def show_temp_4ax(dt_in, search='冷冻水', freq=6):
    '''
    同时显示4台主机的水温
    :param dt_in:
        传入的数据
    :param search:
        search可以是冷冻水或者冷却水
    :param freq:
        freq默认是2h
    :return:
    '''
    dates_result1 = date_interval(dt_in, freq)
    dates1 = dates_result1[0]  # x轴的时间序列
    step1 = dates_result1[1]  # 时间间隔的步长
def show_COP(dt_in, chillerid=4, freq=12):
    dates_result1 = date_interval(dt_in, freq)
    dates1 = dates_result1[0]  # x轴的时间序列
    step1 = dates_result1[1]  # 时间间隔的步长
    col_chwST_T = 'CH{}冷冻水出水温度(℃)'.format(chillerid)
    col_chwRT_T = 'CH{}冷冻水回水温度(℃)'.format(chillerid)
    col_chflow = 'CH{}冷冻水出水流量(m^3/h)'.format(chillerid)
    col_power = 'CH{}功率(KW)'.format(chillerid)
    # 计算冷量、cop
    capacity = 1000 * 4.186 * (dt_in.loc[:, col_chwRT_T] - dt_in.loc[:, col_chwST_T]) * dt_in.loc[:, col_chflow] / 3600
    capacity[capacity < 10] = 0
    cop = capacity.div(dt_in.loc[:, col_power])
    cop[cop == np.inf] = pd.NaT
    cop[cop == 0] = pd.NaT
def show_storage_analysis(dt_in, freq=48):
    dates_result1 = date_interval(dt_in, freq)
    dates1 = dates_result1[0]  # x轴的时间序列
    step1 = dates_result1[1]  # 时间间隔的步长
    # 计算系统负荷
    system_capacity = formula.cal_system_capacity(dt_in)
    # 计算蓄放冷量
    storage_capacity = 4.186 * 1000 * (dt_in['蓄冷槽进水温度(℃)'] - dt_in['蓄冷槽出水温度(℃)']) * dt_in['蓄冷槽出水流量(m^3/h)'] / 3600
    # 绘图,系统负荷/蓄冷量
    # fig = plt.subplot()
    # plt.xticks(list(np.arange(0, dt_in.index[-1], step1)), tuple(dates1), rotation=30)  # x轴的时间间隔设置
    # 计算累计蓄冷量、放冷量
    storage_sum = 0
    position_start = 0
    sign_pre = None  # 指示蓄冷还是放冷
    sign_get = True  # 指示是否取符号
    for sc, i, t in zip(storage_capacity, storage_capacity.index, dt_in['时   间']):
        # 把蓄放冷量较小值置0
        if -50 < sc < 50:
            sc = 0
            storage_capacity[i] = 0
        # 放置放冷量值的标签
        if not np.isnan(sc):
            # 第一次获得符号
            if sign_get:
                position_start = i
                sign_pre = formula.sign(sc)
                sign_get = False
                print('第一次获得符号%s' % sc)
            # 已获得符号,则比较下一次是否和上一次符号相同,增加累计置
            elif (sc > 0 and sign_pre == '+') or (sc < 0 and sign_pre == '-'):
                print('符号相同%s' % sc)
                storage_sum += sc * 5 / 60
            # sc==0,则可以打印累计结果
            elif sc == 0:
                print('打印结果%s' % sc)
                position_height = 100
                position_between = (i + position_start) / 2
                if -50 < storage_sum < 50:
                    position_height = 200
                if storage_sum > 0:
                    # fig.text(position_between, position_height, '累计放冷量为:%s' % np.round(storage_sum / 3.517))
                    storage_sum = 0
                elif storage_sum < 0:
                    # fig.text(position_between, -position_height, '累计蓄冷量为:%s' % -np.round(storage_sum / 3.517))
                    storage_sum = 0
                sign_get = True  # 打印结果后重置sign_pre,继续寻找第一个符号
            # 否则符号是直接变号了,可以打印累计结果
            else:
                print('打印结果%s' % sc)
                position_height = 100
                position_between = (i + position_start) / 2
                if -50 < storage_sum < 50:
                    position_height = 200
                if storage_sum > 0:
                    # fig.text(position_between, position_height, '累计放冷量为:%s' % np.round(storage_sum / 3.517))
                    storage_sum = 0
                elif storage_sum < 0:
                    # fig.text(position_between, -position_height, '累计蓄冷量为:%s' % -np.round(storage_sum / 3.517))
                    storage_sum = 0
                sign_pre = formula.sign(sc)  # 打印结果后重置sign_pre,继续寻找第一个符号