OpenApi.py 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. '''
  2. 数据预处理类
  3. '''
  4. __author__ = 'lmstack'
  5. import pandas as pd
  6. import requests
  7. import json
  8. class OpenApi:
  9. def __init__(self):
  10. pass
  11. '''
  12. 获取 运维系统中故障相关的信息
  13. '''
  14. def get_device_fault(self, start_time="", end_time=""):
  15. # start_time = "2021-12-30 00:00:00"
  16. # end_time = "2021-12-31 00:00:00"
  17. url = 'http://open.li-ai.com.cn/admin/v1/deviceFault'
  18. headers = {'Content-Type':"application/json; charset=utf-8","token":"2A26DD0ADE53456D928562A17131A3B5"}
  19. data = {}
  20. if start_time != "":
  21. data['startTime'] = start_time
  22. if end_time != "":
  23. data['endTime'] = end_time
  24. response = requests.post(url, json=data, headers=headers)
  25. # df = pd.DataFrame(columns=['sn', 'imei','faultTime', 'updateTime', 'overTime', 'faultStatus', 'questionType', 'questionTypeText', 'childProblem','childProblemText'])
  26. df = pd.DataFrame(json.loads(response.text)["data"])
  27. # for d in json.loads(response.text)["data"]:
  28. # df = df.append(d, ignore_index=True)
  29. return df
  30. '''
  31. 获取 资产相关信息
  32. '''
  33. def get_asset(self, sn=""):
  34. # start_time = "2021-12-30 00:00:00"
  35. # end_time = "2021-12-31 00:00:00"
  36. url = 'http://open.li-ai.com.cn/admin/v1/deviceDetailInfo'
  37. headers = {'Content-Type':"application/json; charset=utf-8","token":"2A26DD0ADE53456D928562A17131A3B5"}
  38. data = {"id":sn}
  39. response = requests.post(url, json=data, headers=headers)
  40. # df = pd.DataFrame(columns=['sn', 'imei','faultTime', 'updateTime', 'overTime', 'faultStatus', 'questionType', 'questionTypeText', 'childProblem','childProblemText'])
  41. df = pd.DataFrame(json.loads(response.text)["data"])
  42. if len(df)>0:
  43. df2 = pd.DataFrame(list(df['basicAssetDto']))
  44. df2 = df2.drop(['imei','id', 'deviceType', 'deviceTypeText'],axis=1,errors='ignore')
  45. df3 = df.drop(['basicAssetDto'],axis=1)
  46. df = df2.join(df3.set_index('sn'),on='sn')
  47. return df
  48. '''
  49. 获取 iotp数据
  50. '''
  51. def get_last_data(self, sn=""):
  52. # start_time = "2021-12-30 00:00:00"
  53. # end_time = "2021-12-31 00:00:00"
  54. url = 'http://open.li-ai.com.cn/admin/v1/capacityAndLocation'
  55. headers = {'Content-Type':"application/json; charset=utf-8","token":"2A26DD0ADE53456D928562A17131A3B5"}
  56. data = {"id":sn}
  57. response = requests.post(url, json=data, headers=headers)
  58. df = pd.DataFrame(json.loads(response.text)["data"])
  59. if len(df)>0:
  60. df2 = pd.DataFrame(list(df['batteryLocationDto']))
  61. df3 = pd.DataFrame(list(df['batteryAccumDto']))
  62. df2 = df2.drop(['id','updateTime'],axis=1,errors='ignore')
  63. df3 = df3.drop(['id','updateTime'],axis=1,errors='ignore')
  64. df = df2.join(df3.set_index('sn'),on='sn')
  65. return df
  66. '''
  67. 获取 运维故障标签 数据
  68. '''
  69. def get_omp_fatult_tag(self, sn="", start_time='', end_time=''):
  70. url = 'http://open.li-ai.com.cn/admin/v1/queryFaultMsg'
  71. headers = {'Content-Type':"application/json; charset=utf-8","token":"2A26DD0ADE53456D928562A17131A3B5"}
  72. data = {}
  73. if sn != "":
  74. data['sn'] = sn
  75. if start_time != "":
  76. data['startTime'] = start_time
  77. if end_time != "":
  78. data['endTime'] = end_time
  79. response = requests.post(url, json=data, headers=headers)
  80. # df = pd.DataFrame(columns=['sn', 'imei','faultTime', 'updateTime', 'overTime', 'faultStatus', 'questionType', 'questionTypeText', 'childProblem','childProblemText'])
  81. df = pd.DataFrame(json.loads(response.text)["data"])
  82. # 剔除 [58,59,110,119,C490,C599,C307]
  83. if len(df)>0:
  84. df = df[~df['faultCode'].isin(["58","59",'110',"119","C490","C599","C307"])]
  85. df = df[df['endTime']!='0000-00-00 00:00:00']
  86. # for d in json.loads(response.text)["data"]:
  87. # df = df.append(d, ignore_index=True)
  88. return df