1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- '''
- 数据预处理类
- '''
- __author__ = 'lmstack'
- import pandas as pd
- import requests
- import json
- class OpenApi:
- def __init__(self):
- pass
- '''
- 获取 运维系统中故障相关的信息
- '''
- def get_device_fault(self, start_time="", end_time=""):
- # start_time = "2021-12-30 00:00:00"
- # end_time = "2021-12-31 00:00:00"
- url = 'http://open.li-ai.com.cn/admin/v1/deviceFault'
- headers = {'Content-Type':"application/json; charset=utf-8","token":"2A26DD0ADE53456D928562A17131A3B5"}
- data = {}
- if start_time != "":
- data['startTime'] = start_time
- if end_time != "":
- data['endTime'] = end_time
- response = requests.post(url, json=data, headers=headers)
- # df = pd.DataFrame(columns=['sn', 'imei','faultTime', 'updateTime', 'overTime', 'faultStatus', 'questionType', 'questionTypeText', 'childProblem','childProblemText'])
- df = pd.DataFrame(json.loads(response.text)["data"])
- # for d in json.loads(response.text)["data"]:
- # df = df.append(d, ignore_index=True)
- return df
-
- '''
- 获取 资产相关信息
- '''
- def get_asset(self, sn=""):
- # start_time = "2021-12-30 00:00:00"
- # end_time = "2021-12-31 00:00:00"
- url = 'http://open.li-ai.com.cn/admin/v1/deviceDetailInfo'
- headers = {'Content-Type':"application/json; charset=utf-8","token":"2A26DD0ADE53456D928562A17131A3B5"}
- data = {"id":sn}
- response = requests.post(url, json=data, headers=headers)
- # df = pd.DataFrame(columns=['sn', 'imei','faultTime', 'updateTime', 'overTime', 'faultStatus', 'questionType', 'questionTypeText', 'childProblem','childProblemText'])
- df = pd.DataFrame(json.loads(response.text)["data"])
- if len(df)>0:
- df2 = pd.DataFrame(list(df['basicAssetDto']))
- df2 = df2.drop(['imei','id', 'deviceType', 'deviceTypeText'],axis=1,errors='ignore')
- df3 = df.drop(['basicAssetDto'],axis=1)
- df = df2.join(df3.set_index('sn'),on='sn')
- return df
-
- '''
- 获取 iotp数据
- '''
- def get_last_data(self, sn=""):
- # start_time = "2021-12-30 00:00:00"
- # end_time = "2021-12-31 00:00:00"
- url = 'http://open.li-ai.com.cn/admin/v1/capacityAndLocation'
- headers = {'Content-Type':"application/json; charset=utf-8","token":"2A26DD0ADE53456D928562A17131A3B5"}
- data = {"id":sn}
- response = requests.post(url, json=data, headers=headers)
- df = pd.DataFrame(json.loads(response.text)["data"])
- if len(df)>0:
- df2 = pd.DataFrame(list(df['batteryLocationDto']))
- df3 = pd.DataFrame(list(df['batteryAccumDto']))
- df2 = df2.drop(['id','updateTime'],axis=1,errors='ignore')
- df3 = df3.drop(['id','updateTime'],axis=1,errors='ignore')
- df = df2.join(df3.set_index('sn'),on='sn')
- return df
-
- '''
- 获取 运维故障标签 数据
- '''
- def get_omp_fatult_tag(self, sn="", start_time='', end_time=''):
- url = 'http://open.li-ai.com.cn/admin/v1/queryFaultMsg'
- headers = {'Content-Type':"application/json; charset=utf-8","token":"2A26DD0ADE53456D928562A17131A3B5"}
- data = {}
- if sn != "":
- data['sn'] = sn
- if start_time != "":
- data['startTime'] = start_time
- if end_time != "":
- data['endTime'] = end_time
- response = requests.post(url, json=data, headers=headers)
- # df = pd.DataFrame(columns=['sn', 'imei','faultTime', 'updateTime', 'overTime', 'faultStatus', 'questionType', 'questionTypeText', 'childProblem','childProblemText'])
- df = pd.DataFrame(json.loads(response.text)["data"])
- # 剔除 [58,59,110,119,C490,C599,C307]
- if len(df)>0:
- df = df[~df['faultCode'].isin(["58","59",'110',"119","C490","C599","C307"])]
- df = df[df['endTime']!='0000-00-00 00:00:00']
- # for d in json.loads(response.text)["data"]:
- # df = df.append(d, ignore_index=True)
- return df
-
-
|