Ejemplo n.º 1
0
def getStackInfo(que, i, sta_codes, ah_stas, sta_names):
    try:
        print('***********正在计算“' + sta_names[i] + '”强度中***********')
        obj = getStaWork(sta_data_date, end_data_date, sta_code=sta_codes[i])
        rs_en = obj.getDataByBAS()[0]
        rs_ah = obj.getDataByCLS(ah_sta=ah_stas[i])[0]
        #    rs_ah=obj.getDataByCLS(ah_sta=ah_stas[i],isEndAhCount=True)[0]
        #    return
        #     print(rs_en)
        if rs_ah is not False and rs_en is not False:
            #确保目录存在
            mkdir('./strengths/' + sta_names[i])
            write = pd.ExcelWriter(r'./strengths/' + sta_names[i] + '/' +
                                   sta_data_date.split(' ')[0] + '强度数据统计.xlsx')
            rs_ah.to_excel(write, '簇累计充放容量数据', index=False)
            rs_en.to_excel(write, '堆累计充放电量数据', index=False)
            write.save()
            print('√√√√√√√√√√√√ data is saved! √√√√√√√√√√√√')
        else:
            print('data not need to save!')
    except:
        print(sta_names[i] + '‘s data get meet error!')
        traceback.print_exc()
    print(que.get())
    que.task_done()
Ejemplo n.º 2
0
def getStackInfo(que, i, sta_codes, ah_stas, sta_names, sta_data_date,
                 end_data_date):
    global need_data
    print('***********正在计算“' + sta_names[i] + '”强度中***********')
    obj = getStaWork(sta_data_date, end_data_date, sta_code=sta_codes[i])
    rs_en = obj.getDataByBAS()[0]
    #     rs_ah=[]

    #     rs_ah=obj.getDataByCLS(ah_sta=ah_stas[i])[0]
    #     rs_ah=obj.getDataByCLS(ah_sta=ah_stas[i],isEndAhCount=True)[0]

    #     if  rs_en is not False:
    #         mkdir('./strengths/'+sta_names[i])
    #         write=pd.ExcelWriter(r'./strengths/'+sta_names[i]+'/'+sta_data_date.split(' ')[0]+'强度数据统计.xlsx')
    #         rs_en.to_excel(write,'堆累计充放电量数据',index=False)
    #         write.save()
    #         print('√√√√√√√√√√√√ data is saved! √√√√√√√√√√√√')
    #     print(rs_en)
    if rs_en is not False:
        #     if rs_ah is not False and rs_en is not False and rs_en.ix[0,5]>0:
        #确保目录存在
        mkdir('./201906_product_files/' + sta_names[i])
        write = pd.ExcelWriter(r'./201906_product_files/' + sta_names[i] +
                               '/' + sta_data_date.split(' ')[0] +
                               '强度数据统计.xlsx')
        #         rs_ah.to_excel(write,'簇累计充放容量数据',index=False)
        rs_en.to_excel(write, '堆累计充放电量数据', index=False)
        write.save()
        print('√√√√√√√√√√√√ data is saved! √√√√√√√√√√√√')
    else:
        print('data not need to save!')
    print(que.get())
    que.task_done()
Ejemplo n.º 3
0
 def webfile(self, Jizu, start_date, end_date):
     '''
     keys:
         Jizu:机组是系统1或2
         start_date:起始时间
         end_date:结束时间
     return:
         data:AGC,电池的联合数据(时标对应的)
         time:时标,对应x轴
         bat:电池系统1和2的联合数据(时标都存在的)
         Agc:Agc数据(没做时标的联合,可能数据更大)
     '''
     if start_date is None and end_date is None:
         print('接口查询必须给定时间和电站')
         data = 0
         time = 0
     elif Jizu is None:
         print('请在运行前给出所属机组')
     else:
         sta_data_date = start_date
         end_data_date = end_date
         a, b, c, d = self._Dataexist(sta_data_date, end_data_date)
         if self.i in d:
             A = getAPI.getStaWork(sta_data_date, end_data_date,
                                   self.Aim_codes)
             bat, df1, df2 = A.getEMSBat()
             if Jizu == 1:
                 jizu = '01'
                 Agc = A.getEMSAgc(jizu)
             else:
                 jizu = '02'
                 Agc = A.getEMSAgc(jizu)
             DF = pd.merge(bat,
                           Agc,
                           right_index=True,
                           left_index=True,
                           how='inner')
             time = pd.to_datetime(DF.index, format='%Y-%m-%d %H:%M:%S')
             time.columns = ['time']
             data = pd.DataFrame(columns=['Agc', 'Pdg', 'Pall', 'Pbat'])
             data['Agc'], data['Pdg'], data['Pbat'] = DF[jizu + 'AGC'], DF[
                 jizu + '机组出力'], DF['01储能'] + DF['02储能']
             data['Pall'] = data['Pdg'] + data['Pbat']
             data.index = pd.to_datetime(data.index, format=None)
             bat.index = pd.to_datetime(bat.index, format=None)
             Agc.index = pd.to_datetime(Agc.index, format=None)
         elif self.i in c:
             print(self.Aim_names_Chinese + '无数据,请尝试换一个电站')
             print('经查询:电站' + str(a) + '无数据 \n' + '电站' + str(b) + '有数据')
             data = pd.DataFrame()
             bat = pd.DataFrame()
             Agc = pd.DataFrame()
             time = 0
     return data, time, bat, Agc
Ejemplo n.º 4
0
def getStackInfo(i,sta_codes,ah_stas,sta_names):
    print('***********正在计算“'+sta_names[i]+'”强度中***********')
    obj=getStaWork(sta_data_date, end_data_date,sta_code=sta_codes[i])
    rs_en=obj.getDataByBAS()
    rs_ah=obj.getDataByCLS(ah_sta=ah_stas[i])
    if rs_ah is not False and rs_en is not False and rs_en.ix[0,2]>0:
        #确保目录存在
        mkdir('./strengths/'+sta_names[i])
        write=pd.ExcelWriter(r'./strengths/'+sta_names[i]+'/'+sta_data_date.split(' ')[0]+'强度数据统计.xlsx')
        rs_ah.to_excel(write,'簇累计充放容量数据')
        rs_en.to_excel(write,'堆累计充放电量数据')
        write.save()
        print('√√√√√√√√√√√√ data is saved! √√√√√√√√√√√√')
Ejemplo n.º 5
0
def getStackInfo(i, sta_codes, sta_names, sta_data_date, end_data_date):
    obj = getStaWork(sta_data_date, end_data_date, sta_code=sta_codes[i])
    #6-3-3 3pack sbox=5,ebox=6,sba=2,eba=3,scl=2,ecl=3,sp=2,ep=3
    rs = obj.getCellDataByPack()
    if len(rs) > 0:
        df_rs = pd.DataFrame(rs)
        df_rs = pd.concat(
            [pd.DataFrame([[sta_data_date, end_data_date]]), df_rs])
        df_rs.columns = ['描述', '电压']
        mkdir('./BMUQS/')
        df_rs.to_excel('./BMUQS/' + sta_data_date.split(' ')[0] +
                       sta_names[i] + '.xlsx',
                       index=False)
        print('发现如下问题[描述,12s电压],已存入BMUQS目录下')
    else:
        print('所选时间段内没有发现任何问题')
Ejemplo n.º 6
0
 def Dataexist(self, start_date, end_date):
     Nodata = []
     Nodata_loc = []
     Ysdata = []
     Ysdata_loc = []
     for i in range(0, len(self.index)):
         Aim_codes = self.sta_codes[self.index[i]]
         sta_data_date = start_date
         end_data_date = end_date
         A = getStaWork(sta_data_date, end_data_date, Aim_codes)
         print('开始检查电站:' + self.index_name[i])
         Agc1, Agc2 = A.getEMSexist()
         if Agc1.empty and Agc2.empty:
             Nodata.append(self.index_name[i])
             Nodata_loc.append(i)
         else:
             Ysdata.append(self.index_name[i])
             Ysdata_loc.append(i)
     return Nodata, Ysdata, Nodata_loc, Ysdata_loc
Ejemplo n.º 7
0
Created on 2019年5月9日
下一步计划,插入多线程函数,可选模式,以簇或堆或箱或电站进行多线程
@author: 逻辑的使命
'''
from getAPI import getStaWork
import pandas as pd
from mkdir import mkdir

sta_data_date = "2019-04-19 00:00:00"
end_data_date = "2019-04-19 12:00:00"

if __name__ == '__main__':
    sta_config = pd.read_excel('./assets/sta_cl_ah_config.xlsx')
    sta_codes, sta_names = sta_config['code'], sta_config['name']
    sta_i = 1  #云河编号
    obj = getStaWork(sta_data_date, end_data_date, sta_code=sta_codes[sta_i])
    mkdir('./curs_datas/' + sta_names[sta_i])

    sbox, ebox = 1, 2
    sba, eba = 0, 2
    scl, ecl = 0, 3
    mode = ['getDateTime', 'getCurs']

    rs = obj.getDataByCLS(quickly=False,
                          sbox=sbox,
                          ebox=ebox,
                          sba=sba,
                          eba=eba,
                          scl=scl,
                          ecl=ecl,
                          mode=mode)
Ejemplo n.º 8
0
# -*- coding: utf-8 -*-
'''
Created on 2019年5月9日

@author: Administrator
'''
from getAPI import getStaWork

sta_data_date = "2019-02-01 00:00:00"
end_data_date = "2019-04-20 00:00:00"

if __name__ == '__main__':
    obj = getStaWork(sta_data_date, end_data_date, sta_code='0005')
    rs_curs = obj.getDataByCLS(quickly=False,
                               sbox=1,
                               ebox=2,
                               sba=1,
                               eba=2,
                               scl=0,
                               ecl=2,
                               mode='getCurs')
    rs_curs.columns = ['时间', '2箱2堆1簇', '2箱2堆2簇']
    print(rs_curs)
    rs_curs.to_csv('电流数据2-2-1/2.csv')
Ejemplo n.º 9
0
def getStackInfo(que, sta_i, sta_codes, sta_names):
    obj = getStaWork(sta_data_date, end_data_date, sta_code=sta_codes[sta_i])
    mkdir('./temp_datas/' + sta_names[sta_i])
    #默认 0 -1
    sbox, ebox = 0, -1
    sba, eba = 0, -1
    scl, ecl = 0, -1
    sp, ep = 0, -1
    #默认以包,簇,堆
    mode = ['']

    rs = obj.getCellDataByPack(quickly=False,
                               sbox=sbox,
                               ebox=ebox,
                               sba=sba,
                               eba=eba,
                               scl=scl,
                               ecl=ecl,
                               sp=sp,
                               ep=ep,
                               mode=mode)
    #     rs=pd.read_excel('D:\\python_works\\ClouPy\works\\API_Class\\temp_datas\\河北宣化电厂储能电站\\2019-05-26.xlsx',sheet_name=0,index_col=0)
    #     rs=np.array(rs)
    #     print(rs)
    pack_bmu_num = obj.pack_bmu_num
    if ebox == -1:
        ebox = obj.box_num
    if ep == -1:
        ep = obj.pack_num

#     rs=[[[25.0, 23.0, 2.0, 24.333333333333332], [25.0, 23.0, 1.0, 24.166666666666668], [26.0, 23.0, 1.0, 25.166666666666668], [25.0, 23.0, 1.0, 24.166666666666668], [25.0, 23.0, 1.0, 24.833333333333332], [25.0, 24.0, 1.0, 25.0], [25.0, 23.0, 1.0, 24.666666666666668], [25.0, 23.0, 2.0, 24.666666666666668], [25.0, 23.0, 1.0, 24.666666666666668], [25.0, 23.0, 1.0, 24.666666666666668], [25.0, 23.0, 1.0, 24.666666666666668], [25.0, 23.0, 1.0, 24.833333333333332], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN]], [[26.0, 23.0, 2.0, 24.555555555555557], [26.0, 23.0, 2.0, 24.62962962962963], [25.0, 23.0, 2.0, 24.555555555555557], [25.0, 23.0, 2.0, 24.77777777777778], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN],[np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN], [np.NaN,np.NaN,np.NaN,np.NaN]], [[26.0, 23.0, 2.0, 24.970807875084862], [np.NaN,np.NaN,np.NaN,np.NaN]]]

    print([eba, ep, pack_bmu_num])
    print(rs)
    #     obj.cl_num_list=[4,5]
    print(obj.cl_num_list)
    if len(rs) == len(mode):
        write = pd.ExcelWriter("./temp_datas/" + sta_names[sta_i] + '/' +
                               sta_data_date.split(' ')[0] + ".xlsx")
        for i in range(len(rs)):
            #对数据格式化处理,便于画图
            formatRs, ys, xs, fxs = [], [], [], []
            for box in range(sbox + 1, ebox + 1):
                boxformatRs = []  #每一箱
                Flag_ba = False
                if eba == -1:
                    eba = obj.ba_num_list[box - 1 - sbox]
                    print('%s-------:' % eba)
                    Flag_ba = True
                for ba in range(sba + 1, eba + 1):
                    xba = str(ba) + '堆'
                    A = sum(obj.ba_num_list[0:box - 1 - sbox]
                            )  #(box-sbox-1)*(eba-sba)#已经循环过的堆数
                    if mode[i] == 'getDTempsByBA':
                        try:
                            boxformatRs.append(rs[i][(ba - sba - 1) + A])
                            fxs.append(str(box) + '箱-' + xba)
                        except:
                            boxformatRs.append(
                                [np.NaN, np.NaN, np.NaN, np.NaN])
                        if box == sbox + 1:
                            xs.append(xba)
                    else:

                        if ecl == -1:
                            ecl = obj.cl_num_list[ba - 1 - sba +
                                                  A]  #(box-1-sbox)*(eba-sba)
                            print(ecl)
                            FLag = True
                        for cl in range(scl + 1, ecl + 1):
                            xcl = xba + '-' + str(cl)
                            #                             B=(A+(ba-sba-1))*(ecl-scl)
                            B = sum(
                                obj.cl_num_list[0:ba - 1 - sba +
                                                A])  #(box-1-sbox)*(eba-sba)
                            if mode[i] == 'getDTempsByCL':
                                try:
                                    boxformatRs.append(rs[i][(cl - scl - 1) +
                                                             B])
                                    fxs.append(str(box) + '箱-' + xcl)
                                except:
                                    boxformatRs.append(
                                        [np.NaN, np.NaN, np.NaN, np.NaN])
                                if box == sbox + 1:
                                    xs.append(xcl)
                            else:
                                for p in range(sp + 1, ep + 1):
                                    xp = xcl + '-Pack' + str(p)
                                    C = (B + (cl - scl - 1)) * (ep - sp)
                                    if mode[i] == 'getDTempsByPack':
                                        try:
                                            fxs.append(str(box) + '箱-' + xp)
                                            boxformatRs.append(
                                                rs[i][(p - sp - 1) + C])
                                        except:
                                            boxformatRs.append([
                                                np.NaN, np.NaN, np.NaN, np.NaN
                                            ])
                                        if box == sbox + 1:
                                            xs.append(xp)
                                    else:
                                        for bmu in range(1, pack_bmu_num + 1):
                                            xb = xp + '-BMU' + str(bmu)
                                            D = (C +
                                                 (p - sp - 1)) * pack_bmu_num
                                            if 'getDTempsByBMU' in mode:
                                                try:
                                                    fxs.append(
                                                        str(box) + '箱-' + xb)
                                                    boxformatRs.append(
                                                        rs[i][(bmu - 1) + D])
                                                except:
                                                    boxformatRs.append([
                                                        np.NaN, np.NaN, np.NaN,
                                                        np.NaN
                                                    ])
                                                if box == sbox + 1:
                                                    xs.append(xb)
                        if FLag:
                            ecl = -1
                if Flag_ba:
                    eba = -1
                formatRs.append(boxformatRs)
                ys.append('第%s箱' % box)

            if len(xs) > 0:
                xs_split = xs[0].split('-')
                if len(xs_split) == 1:
                    xlabel = '堆'
                    txt = '各堆'
                elif len(xs_split) == 2:
                    xlabel = '堆-簇'
                    txt = '各簇'
                elif len(xs_split) == 3:
                    xlabel = '堆-簇-包'
                    txt = '各包'
                elif len(xs_split) == 4:
                    xlabel = '堆-簇-包-BMU'
                    txt = '各BMU'
            #保留原格式数据到表格
            df_r = pd.DataFrame(rs[i])
            print(df_r)
            df_r.columns = ['最高温度/℃', '最低温度/℃', '最大温差/℃', '最大平均温度/℃']
            print(fxs)
            df_r.index = fxs
            df_r.to_excel(write, sta_names[sta_i] + txt + "温度数据", index=True)
            #画图最高温度与最大温差,最大平均与最低温度不画
            maxTs, max_dif_Ts = [], []

            for it_box in formatRs:
                maxTs.append([it[0] for it in it_box])
                max_dif_Ts.append([it[2] for it in it_box])
            df = pd.DataFrame(maxTs)
            #             print(df)
            df.index = ys
            df.columns = xs

            f, (ax1, ax2) = plt.subplots(figsize=(10, 8), nrows=2)
            cmap = sns.cubehelix_palette(start=1.5,
                                         rot=3,
                                         gamma=0.8,
                                         as_cmap=True)
            try:
                sns.heatmap(df,
                            linewidths=0.05,
                            ax=ax1,
                            annot=True,
                            annot_kws={'weight': 'bold'},
                            vmax=max(np.max(df)),
                            vmin=min(np.min(df)),
                            cmap=cmap)
                ax1.set_title(
                    sta_data_date.split(' ')[0] + sta_names[sta_i] + txt +
                    '最高温度')
                ax1.set_xlabel('')
                ax1.set_xticklabels([])  #设置x轴图例为空值
                ax1.set_ylabel('箱')
            except:
                print('图像绘制失败')
            df = pd.DataFrame(max_dif_Ts)
            df.index = ys
            df.columns = xs
            try:
                sns.heatmap(df,
                            ax=ax2,
                            cmap=sns.color_palette("Reds", 7),
                            cbar=False,
                            annot=True,
                            mask=df < max(np.max(df)),
                            annot_kws={
                                "weight": "bold",
                                'size': 25
                            })
                sns.heatmap(df,
                            linewidths=0.05,
                            vmax=max(np.max(df)),
                            vmin=min(np.min(df)),
                            cmap=sns.color_palette("Reds", 7),
                            ax=ax2,
                            annot=True,
                            mask=df >= max(np.max(df)))
                # rainbow为 matplotlib 的colormap名称
                ax2.set_title(
                    sta_data_date.split(' ')[0] + sta_names[sta_i] + txt +
                    '最大温差')
                ax2.set_xlabel(xlabel)
                ax2.set_ylabel('箱')
                plt.savefig("./temp_datas/" + sta_names[sta_i] + '/' +
                            sta_data_date.split(' ')[0] + txt +
                            '最高温度与最大温差.png')
            except:
                print('图像绘制失败')
        write.save()
    print(que.get())
    que.task_done()
Ejemplo n.º 10
0
'''
Created on 2019年8月7日

@author: JesisW
'''
from getAPI import getStaWork
import os
import sys
import pandas as pd

if __name__ == '__main__':
    #     sys.path
    #     os.chdir(sys.path[0])
    sta_config = pd.read_excel('./assets/sta_cl_ah_config.xlsx')
    index = [0, 1, 2, 5, 6, 7, 14, 15, 16, 33]  #调频电站序号
    sta_codes, sta_names = sta_config['code'], sta_config['name']
    Aim_codes, Aim_names = sta_codes[0], sta_names[0]
    a = getStaWork('2019-04-17 00:00:00', '2019-04-17 01:00:00', Aim_codes)
    df1, df2 = a.getEMSAgc()
Ejemplo n.º 11
0
def getStackInfo(que, i, sta_codes, sta_names, sta_data_date, end_data_date,
                 mode):
    sbox, ebox = 0, -1
    sba, eba = 0, -1
    scl, ecl = 0, -1
    sp, ep = 0, -1
    if len(mode) == 1 and 'sta' in mode:
        #i就表示电站id
        pass
    #mode=[id,'box']
    elif len(mode) == 2 and 'box' in mode:
        sbox, ebox = i, i + 1
        i = mode[0]
    elif len(mode) == 3 and 'ba' in mode:
        sba, eba = i, i + 1
        i = mode[0]
        sbox, ebox = mode[1], mode[1] + 1
    elif len(mode) == 4 and 'cl' in mode:
        scl, ecl = i, i + 1
        i = mode[0]
        sbox, ebox = mode[1], mode[1] + 1
        sba, eba = mode[2], mode[2] + 1
    elif len(mode) == 5 and 'pack' in mode:
        sp, ep = i, i + 1
        i = mode[0]
        sbox, ebox = mode[1], mode[1] + 1
        sba, eba = mode[2], mode[2] + 1
        scl, ecl = mode[3], mode[3] + 1
    obj = getStaWork(sta_data_date, end_data_date, sta_code=sta_codes[i])
    #6-3-3 3pack sbox=5,ebox=6,sba=2,eba=3,scl=2,ecl=3,sp=2,ep=3
    rs = obj.getCellDataByPack(sbox=sbox,
                               ebox=ebox,
                               sba=sba,
                               eba=eba,
                               scl=scl,
                               ecl=ecl,
                               sp=sp,
                               ep=ep)
    if len(rs) > 0:
        rs = rs[0]
        df_rs = pd.DataFrame(rs)
        df_rs = pd.concat(
            [pd.DataFrame([[sta_data_date, end_data_date]]), df_rs])
        df_rs.columns = ['描述', '电压']
        mkdir('./BMUQS/太阳宫/')
        fileH = './BMUQS/太阳宫/' + sta_data_date.split(' ')[0] + sta_names[i]
        if 'sta' in mode:
            fileN = fileH + '.xlsx'
        elif 'box' in mode:
            #             fileN=fileH+str(mode[0]+1)+'箱.xlsx'
            fileN = fileH + str(sbox + 1) + '箱.xlsx'
        elif 'ba' in mode:
            #             fileN=fileH+str(mode[0]+1)+'箱'+str(mode[1]+1)+'堆.xlsx'
            fileN = fileH + str(mode[1] + 1) + '箱' + str(sba + 1) + '堆.xlsx'
        elif 'cl' in mode:
            #             fileN=fileH+str(mode[0]+1)+'箱'+str(mode[1]+1)+'堆'+str(mode[2]+1)+'簇.xlsx'
            fileN = fileH + str(mode[1] + 1) + '箱' + str(
                mode[2] + 1) + '堆' + str(scl + 1) + '簇.xlsx'
        elif 'pack' in mode:
            #             fileN=fileH+str(mode[0]+1)+'箱'+str(mode[1]+1)+'堆'+str(mode[2]+1)+'簇'+str(mode[3]+1)+'包.xlsx'
            fileN = fileH + str(mode[1] + 1) + '箱' + str(
                mode[2] + 1) + '堆' + str(mode[3] + 1) + '簇' + str(sp +
                                                                  1) + '包.xlsx'
        else:
            print('添加更多模式...')
        df_rs.to_excel(fileN, index=False)
        print('发现如下问题[描述,12s电压],已存入BMUQS目录下')
    else:
        print('所选时间段内没有发现任何问题')
    print(que.get())
    que.task_done()