예제 #1
0
 def setUp(self):
     self.login = FanNengAPI(endpoint_yw_app)
     self.login.yw_app_login(login_data)
     self.assertEqual(self.login.rest.response.status_code, 200)
     json = self.login.rest.json_result()
     self.openid = parser(json, '$.openId')[0]
     self.token = parser(json, '$.token')[0]
     self.headers = {'token': self.token}
예제 #2
0
 def setUp(self):
     self.login = FanNengAPI(endpoint_ywWeb_login)
     # self.login.mark(mark)
     # self.assertEqual(self.login.rest.response.status_code, 200)
     # check_vode = {"vcode": vcode, "mark": mark}
     # self.login.check_vcode(check_vode)
     # self.assertEqual(self.login.rest.response.status_code, 200)
     login_data_web = "username="******"&password=123abc"
     # login_data_web = {}
     self.login.login(login_data_web)
     self.assertEqual(self.login.rest.response.status_code, 200)
     json = self.login.rest.json_result()
     self.token = parser(json, '$.data')[0].get('ticket')
     self.headers = {'token': self.token}
     self.openid = parser(json, '$.data')[0].get('userEnt').get('openid')
예제 #3
0
 def tearDown(self):
     payload = {"token": self.token}
     self.logout = FanNengAPI(endpoint_yw_app)
     self.logout.rest.session.headers.update(self.headers)
     self.logout.yw_app_logout(payload)
     self.assertEqual(self.logout.rest.response.status_code, 200)
     json = self.logout.rest.json_result()
     code = parser(json, '$.code')[0]
     self.assertEqual(code, 0)
예제 #4
0
 def metric_code_all(self, cim_id):
     self.fn_cim = FanNengAPI(endpoint_yw_cim)
     self.fn_cim.rest.session.headers.update(self.headers)
     payload = {
         "deviceCimId": cim_id,
         "pageNumber": 0,
         "pageSize": 100000
     }
     self.fn_cim.post_get_cim_metric(payload)
     json = self.fn_cim.rest.json_result()
     metric_list = parser(json, '$.metricList')[0]
     return metric_list
예제 #5
0
 def metric_code(self, cim_id):
     self.fn_cim = FanNengAPI(endpoint_yw_cim)
     self.fn_cim.rest.session.headers.update(self.headers)
     payload = {
         "deviceCimId": cim_id,
         "pageNumber": 0,
         "pageSize": 100000
     }
     self.fn_cim.post_get_cim_metric(payload)
     json = self.fn_cim.rest.json_result()
     metric_list = parser(json, '$.metricList')[0]
     metric_code_list = []
     for data in metric_list:
         metric_code = {"cimId": 2, "metricId": "GSB_GSB01_FwInt", "name": "FwInt", "description": "1#燃气锅炉给水管累计流量"}
         metric_code.update(cimId=data.get("cimId"))
         metric_code.update(metricId=data.get("metricId"))
         metric_code.update(name=data.get("name"))
         metric_code.update(description=data.get("description"))
         metric_code_list.append(metric_code)
     return metric_code_list
예제 #6
0
 def cim_station_all(self):
     self.fn_cim = FanNengAPI(endpoint_yw_cim)
     # self.fn_cim.rest.session.headers.update(self.headers)
     payload = {
         "pageNumber": 0,
         "pageSize": 10000,
         "status": "OPR"
     }
     self.fn_cim.post_cim_station_all(payload)
     json = self.fn_cim.rest.json_result()
     containerList = parser(json, '$.containerList')[0]
     station_list = []
     for data in containerList:
         station = {"id": "CA02ES01", "name": "龙游城南工业园", "cimId": 2}
         station.update(id=data.get("containerId"))
         station.update(name=data.get("containerName"))
         station.update(cimId=data.get("cimId"))
         station_list.append(station)
     # print(station_list)
     return station_list
예제 #7
0
    def ailoadForecasting(self, time, queries, loadType=4):
        # loadType = 预测类型(1 heatWater,2elec,3cool,4steam,默认值4)
        # time = 时间戳,预测time时间后(结果不含time)的12个小时的值,只接收整点
        # staId = 站ID,字符串类型
        # equipID = 设备,字符串类型
        # metric = 采集点,字符串类型
        # equipMK = 设备标识
        list1 = []
        sumtim = 503
        # metric1 = "UES."+metric
        # queries = [{"aggregator": "none", "downsample": "1h-first-zero", "metric": metric1, "tags":
        #    {"equipID": equipID, "staId": staId, "equipMK": equipMK}}]
        # 获取time时间前504小时数据
        json1 = self.opstpdatereduce(time, sumtim, queries)
        payload = {
            "inputData": {
                'CEU_FIQ303_FsIntLP': json1
            },
            "containerID": "containerID",
            "loadType": loadType,
            "targetDeviceID": "targetDeviceID",
            "nextNum": "24",
            "modelType": "loadPredict",
            "bakParamMap": {}
        }

        self.load = AiAPI(url)
        self.load.load_forecasting(payload)
        try:
            self.assertEqual(self.load.rest.response.status_code, 200)
            json3 = self.load.rest.json_result()
            msg1 = parser(json3, '$.data.loads')[0]
            targetDeviceID = msg1[1]['targetDeviceID']
            self.assertEqual(targetDeviceID, 'targetDeviceID')
        except:
            print("AI接口错误")
            raise TypeError
        for i in msg1:
            zd = {"time": i['time'], "value": i['value']}
            list1.append(zd)
        return list1
예제 #8
0
 def equipment_code(self, cim_id, device_type):
     self.fn_cim = FanNengAPI(endpoint_yw_cim)
     self.fn_cim.rest.session.headers.update(self.headers)
     payload = {
         "containerCimId": cim_id,
         "deviceType": device_type,
         "pageNumber": 1,
         "pageSize": 100000
     }
     self.fn_cim.post_get_cim_device(payload)
     json = self.fn_cim.rest.json_result()
     device_list = parser(json, '$.deviceList')[0]
     equipment_code_list = []
     for data in device_list:
         equip_code = {"cimId": 2, "deviceId": "HRSG_HRSG01", "description": "蒸汽型余热锅炉"}
         equip_code.update(cimId=data.get("cimId"))
         equip_code.update(deviceId=data.get("deviceId"))
         value = data.get("description")  # + '_' + data.get("deviceName")
         equip_code.update(description=value)
         equipment_code_list.append(equip_code)
     return equipment_code_list
예제 #9
0
 def loadTranslation(self, time1):
     # 负荷平移
     # time1 = 时间戳,是结束平移的时间,返回结果是龙游的平移结果
     # offset 负数是向前移,正数是向后移
     # moveCost 移动之后的总成本
     staId = "CA02ES01"
     time = time1
     sumtim = 24
     queries = [{
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "SFSX",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "DZWJ",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "TRHX",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "HDL",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "WMSC",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "XBZJ",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "LGSL",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "TNSP",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "CXLY",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "JDKJ",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "SSSX",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "LCCW",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "HGYSY",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "YMLY",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "TMZY",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "QLBZJ",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "DDMN",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "FDLHC",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "CDSX",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "LYXCL",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "MHSP",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "FTZZ",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "JDJJ",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "ZYH",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "HSGM",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "SJSJ",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "CYHG",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "NNHZY",
             "staId": staId,
             "equipMK": "CEU"
         }
     }, {
         "aggregator": "none",
         "metric": "UES.FsIntLP",
         "tags": {
             "equipID": "LHDD",
             "staId": staId,
             "equipMK": "CEU"
         }
     }]
     ca = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
           [], [], [], [], [], [], [], [], [], [], [], [], []]
     ca1 = [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
            [], [], [], [], [], [], [], [], [], [], [], [], []]
     self.entId1 = [
         "FIQ202_顺丰水洗蒸汽累计流量", "FIQ204_德州五金蒸汽累计流量", "FIQ205_天瑞化学蒸汽累计流量",
         "FIQ206_惠多利蒸汽累计流量", "FIQ207_外贸笋厂蒸汽累计流量", "FIQ208_信邦助剂蒸汽累计流量",
         "FIQ209_利光塑料蒸汽累计流量", "FIQ210_铜鸟食品蒸汽累计流量", "FIQ211_百依家纺蒸汽累计流量",
         "FIQ214_九鼎科技蒸汽累计流量", "FIQ215_苏盛水洗蒸汽累计流量", "FIQ216_鹿成宠物蒸汽累计流量",
         "FIQ217_桦固优实业蒸汽累计流量", "FIQ218_元美铝业蒸汽累计流量", "FIQ219_特美纸业蒸汽累计流量",
         "FIQ220_群力标准件蒸汽累计流量", "FIQ221_大地毛呢蒸汽累计流量", "FIQ222_福德利花材蒸汽累计流量",
         "FIQ240_辰东水洗蒸汽累计流量", "FIQ241_力源新材料蒸汽累计流量", "FIQ244_美哈食品蒸汽累计流量",
         "FIQ251_福田造纸蒸汽累计流量", "FIQ252_家德家具蒸汽累计流量", "FIQ212_正一煌蒸汽流量累计流量",
         "FIQ213_汉桑工贸蒸汽流量累计流量", "FIQ261_瞬杰塑胶蒸汽流量累计流量",
         "FIQ203_辰阳化工蒸汽流量累计流量", "FIQ253_年年虹纸业蒸汽累计流量", "FIQ201_龙辉电镀蒸汽累计流量"
     ]
     # 查询大数据接口
     aa = self.getz3(time, sumtim, queries, ca)
     vo = []
     for i in range(len(queries)):
         for ii in range(sumtim):
             vo.append(aa[i][ii]['value'])
         ca1[i].append(vo)
         vo = []
     # 拼请求AI平移接口参数
     self.entIdA = [[self.entId1[0], ca1[0][0], 1, 2, 24],
                    [self.entId1[1], ca1[1][0], 1, 2, 24],
                    [self.entId1[2], ca1[2][0], 1, 2, 24],
                    [self.entId1[3], ca1[3][0], 1, 2, 24],
                    [self.entId1[4], ca1[4][0], 1, 2, 24],
                    [self.entId1[5], ca1[5][0], 1, 2, 24],
                    [self.entId1[6], ca1[6][0], 1, 2, 24],
                    [self.entId1[7], ca1[7][0], 1, 2, 24],
                    [self.entId1[8], ca1[8][0], 1, 2, 24],
                    [self.entId1[9], ca1[9][0], 1, 2, 24],
                    [self.entId1[10], ca1[10][0], 1, 2, 24],
                    [self.entId1[11], ca1[11][0], 1, 2, 24],
                    [self.entId1[12], ca1[12][0], 1, 2, 24],
                    [self.entId1[13], ca1[13][0], 1, 2, 24],
                    [self.entId1[14], ca1[14][0], 1, 2, 24],
                    [self.entId1[15], ca1[15][0], 1, 2, 24],
                    [self.entId1[16], ca1[16][0], 1, 2, 24],
                    [self.entId1[17], ca1[17][0], 1, 2, 24],
                    [self.entId1[18], ca1[18][0], 1, 2, 24],
                    [self.entId1[19], ca1[19][0], 1, 2, 24],
                    [self.entId1[20], ca1[20][0], 1, 2, 24],
                    [self.entId1[21], ca1[21][0], 1, 2, 24],
                    [self.entId1[22], ca1[22][0], 1, 2, 24],
                    [self.entId1[23], ca1[23][0], 1, 2, 24],
                    [self.entId1[24], ca1[24][0], 1, 2, 24],
                    [self.entId1[25], ca1[25][0], 1, 2, 24],
                    [self.entId1[26], ca1[26][0], 1, 2, 24],
                    [self.entId1[27], ca1[27][0], 1, 2, 24],
                    [self.entId1[28], ca1[28][0], 1, 2, 24]]
     section = [{
         "from": "0",
         "to": "5",
         "cost": "312.09236845454546"
     }, {
         "from": "5",
         "to": "10",
         "cost": "261.94823166393445"
     }, {
         "from": "10",
         "to": "15",
         "cost": "235.61446645312498"
     }, {
         "from": "15",
         "to": "25",
         "cost": "240.16313305555556"
     }, {
         "from": "25",
         "to": "35",
         "cost": "225.15273123529408"
     }]
     payload = self.translationDate(self.entIdA, section)
     # print(payload)
     total = self.translationCost(self.entIdA, section)
     self.load = AiAPI(url2)
     self.load.load_translation(payload)
     self.assertEqual(self.load.rest.response.status_code, 200)
     json1 = self.load.rest.json_result()
     # print(json.dumps(json1))
     try:
         moveCost = float(parser(json1, '$.data.moveCost')[0])
     except:
         print("负荷平移接口返回错误'\n'请求参数:%s'\n'接口返回:%s" % (payload, json1))
         raise TypeError
     returnEntId = parser(json1, '$.data.moveData')[0]
     returnEntId1 = []
     returnEntId2 = []
     for i in range(len(self.entIdA)):
         returnEntId1.append(str(self.entIdA[i][0]))
         returnEntId2.append(str(returnEntId[i]['entId']))
     # 对比2个列表,验证返回的entId
     self.assertListEqual(returnEntId1, returnEntId2)
     # 计算平移后成本
     tota2 = self.translationAfterCost(self.entIdA, json1, section)
     if moveCost != tota2:
         raise TypeError
     else:
         return json1