Browse Source

故障打标签预处理

lmstack 3 năm trước cách đây
mục cha
commit
70f08daec1
2 tập tin đã thay đổi với 70 bổ sung2 xóa
  1. 43 1
      LIB/BACKEND/DataPreProcess.py
  2. 27 1
      LIB/BACKEND/OPENAPI/OpenApi.py

+ 43 - 1
LIB/BACKEND/DataPreProcess.py

@@ -15,6 +15,7 @@ import numpy as np
 import pdb
 from numba import jit
 from LIB.BACKEND import Tools
+from LIB.BACKEND.OPENAPI import OpenApi
 
 class DataPreProcess:
     def __init__(self):
@@ -486,4 +487,45 @@ class DataPreProcess:
         if len(set(df_bms[df_bms['data_status_after_combine']=='charge']['data_split_by_status_after_combine'])) > 0 :
             res_record['charge'] = (res_record['charge'])/len(set(df_bms[df_bms['data_status_after_combine']=='charge']['data_split_by_status_after_combine']))
         return df_bms, df_gps, res_record
-        
+    
+    '''
+    为故障数据打标签
+    sn: 电池编码
+    df_bms: 本电池编码对应的bms数据
+    '''
+    def data_fault_tag(self, sn='', df_bms=pd.DataFrame()):
+        if sn =='':
+            raise Exception("请输入sn")
+        o = OpenApi.OpenApi()
+        df_fault = o.get_omp_fatult_tag(sn=sn)
+        df_data = df_bms.copy()
+        df_data['fault_tag'] = None
+        if len(df_fault) > 0:
+            # 遍历本sn的故障
+            for index in df_fault.index:
+                startT = df_fault.loc[index, 'faultTime']
+                endT = df_fault.loc[index, 'endTime']
+                tagTypeText = df_fault.loc[index, 'tagTypeText']
+                childTagText = df_fault.loc[index, 'childTagText']
+                tagType = df_fault.loc[index, 'tagType']
+                childTag = df_fault.loc[index, 'childTag']
+                # 故障标签拼接
+                new_tag = []
+                if pd.isnull(tagType) or len(tagTypeText) <= 0:
+                    continue
+                elif pd.isnull(childTag) or len(childTagText) <= 0:
+                    new_tag.append(tagTypeText)
+                else:
+                    for child in childTagText.split(";"):
+                        new_tag.append(tagTypeText+':' + child)
+                        
+                # 原始数据对应故障时间的index
+                for index2 in df_data[(df_data['时间戳']>=startT) & (df_data['时间戳']<endT)].index:
+                    old_tag = df_data.loc[index2, 'fault_tag']
+                    if pd.isnull(old_tag) or len(old_tag) <= 0:
+                        df_data.loc[index2,'fault_tag'] = ';'.join(new_tag)
+                    else:
+                        tag = old_tag.split(";")
+                        tag.extend(new_tag)
+                        df_data.loc[index2,'fault_tag'] = ';'.join(list(set(tag)))
+        return df_data

+ 27 - 1
LIB/BACKEND/OPENAPI/OpenApi.py

@@ -69,4 +69,30 @@ class OpenApi:
             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
+        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
+    
+