OpenApi.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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