2 Commit-ok bc6b6b0006 ... 6cce301f62

Szerző SHA1 Üzenet Dátum
  shangguanlie23 6cce301f62 Merge branch 'dev' of http://git.fast-fun.cn:92/lmstack/data_analyze_platform into dev 3 éve
  shangguanlie23 3406bf7240 更改项: 3 éve

+ 0 - 1
LIB/MIDDLE/SaftyCenter/DataSta/DataStatistics.py

@@ -58,7 +58,6 @@ class DataSta():
         FaultLvlCount=DataFrame(columns=['level','count'])
         FaultLvlCount=df_fltinfo.groupby('level').count().T.head(1).T
         FaultLvlCount=FaultLvlCount.reset_index(drop=False)
-        
         return FaultLvlCount
     def SftyWrngClsfy(df_fltinfo):
         DsnSaftyCode=[]

+ 12 - 8
LIB/MIDDLE/SaftyCenter/DataSta/main.py

@@ -35,16 +35,20 @@ def Week_Task():
     end_time=end_time.strftime('%Y-%m-%d')
     FltAlarmInfo,Celltype=DataSta.SaftyWarningSta(CS_Data,df_fltinfo,start_time,end_time)
     FaultLvlCount=DataSta.WeekInfoSta(df_fltinfo,start_time,end_time)
-    for i in range(1,6):
-        if not FaultLvlCount[FaultLvlCount['level']==i]['product_id'].empty:
-            all_period_fault_info.loc[0,'level'+str(i)+'_count']=int(FaultLvlCount[FaultLvlCount['level']==i]['product_id'].values)
-        else:
-            all_period_fault_info.loc[0,'level'+str(i)+'_count']=int(0)
+    lvl1=FaultLvlCount[FaultLvlCount['level']==1]['product_id'].values
+    lvl2=FaultLvlCount[FaultLvlCount['level']==2]['product_id'].values
+    lvl3=FaultLvlCount[FaultLvlCount['level']==3]['product_id'].values
+    lvl4=FaultLvlCount[FaultLvlCount['level']==4]['product_id'].values
+    lvl5=FaultLvlCount[FaultLvlCount['level']==5]['product_id'].values
     all_period_fault_info.loc[0,'factory']='骑享'
     all_period_fault_info.loc[0,'week']=toweek
+    all_period_fault_info.loc[0,'level1_count']=lvl1
+    all_period_fault_info.loc[0,'level2_count']=lvl2
+    all_period_fault_info.loc[0,'level3_count']=lvl3
+    all_period_fault_info.loc[0,'level4_count']=lvl4
+    all_period_fault_info.loc[0,'level5_count']=lvl5
     all_period_fault_info.loc[0,'solve_rate']=FltAlarmInfo.loc[0,'OprationManageRate']
-    all_period_fault_info.fillna(0,inplace=False)
-    print(all_period_fault_info)
+    
 def Minutes_Task():
     
     #............................获取数据................................
@@ -125,7 +129,7 @@ def Minutes_Task():
     all_statistic_info.loc[0,'controller_safety_risk_count']=SatftyCount.loc[0,'CtrlSaftyCodeCount']
     all_statistic_info.loc[0,'design_safety_risk_count']=SatftyCount.loc[0,'DsnSaftyCodeCount']
 #定时任务....................................................................................................................................................................... 
-Week_Task()
+#Week_Task()
 Minutes_Task()
 scheduler = BlockingScheduler()
 scheduler.add_job(Week_Task, 'interval', days=7, id='Week_Task')

+ 2 - 2
LIB/MIDDLE/SaftyCenter/diagfault/CBMSBatDiag.py

@@ -183,7 +183,7 @@ class BatDiag:
                     if cellvoltmax0>self.param.CellOvLv2 and cellvoltmax1>self.param.CellOvLv2:  #二级过压进入
                         time=self.bmstime[i]
                         code=12
-                        faultlv=3
+                        faultlv=4
                         faultinfo='电芯{}过压二级'.format(cellvolt1.index(cellvoltmax1)+1)
                         faultadvice='联系用户询问用车场景,技术介入诊断'
                         self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, end_time, self.sn, code, faultlv, faultinfo, faultadvice]
@@ -240,7 +240,7 @@ class BatDiag:
                 if self.packvolt[i-1]>self.param.PackVoltOvLv2 and self.packvolt[i]>self.param.PackVoltOvLv2:   #电池包过压二级进入
                     time=self.bmstime[i]
                     code=18
-                    faultlv=3
+                    faultlv=4
                     faultinfo='电池包过压二级'
                     faultadvice='联系用户询问用车场景,技术介入诊断'
                     self.df_diag_ram.loc[len(self.df_diag_ram)]=[time, end_time, self.sn, code, faultlv, faultinfo, faultadvice]

+ 31 - 40
LIB/MIDDLE/SaftyCenter/diagfault/main.py

@@ -6,12 +6,13 @@ from LIB.BACKEND import DBManager, Log
 from sqlalchemy import create_engine
 import time, datetime
 from apscheduler.schedulers.blocking import BlockingScheduler
-from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload
+from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload as DBDownload
 from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import log
 from pandas.core.frame import DataFrame
 import datacompy
 from LIB.MIDDLE.SaftyCenter.Common import FeiShuData
-from LIB.MIDDLE.SaftyCenter.SaftyCenter.Common import QX_BatteryParam
+from LIB.MIDDLE.SaftyCenter.Common import QX_BatteryParam
+from LIB.MIDDLE.SaftyCenter.Common import DBDownload as DBDw
 
 #...................................电池包电芯安全诊断函数......................................................................................................................
 def diag_cal():
@@ -44,8 +45,7 @@ def diag_cal():
             print('SN:{},未找到对应电池类型!!!'.format(sn))
             continue
             # sys.exit()
-        param=QX_BatteryParam.BatteryInfo(celltype) 
-        print(sn)    
+        param=QX_BatteryParam.BatteryInfo(celltype)   
         #读取原始数据库数据........................................................................................................................................................
         dbManager = DBManager.DBManager()
         df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
@@ -71,8 +71,8 @@ def diag_cal():
         df_Diag_Ram_sn = df_Diag_Ram.loc[df_Diag_Ram['product_id']==sn]#历史故障
         df_Diag_Ram_sn_else = pd.concat([df_Diag_Ram,df_Diag_Ram_sn,df_Diag_Ram_sn]).drop_duplicates(subset=['product_id','code','start_time','Batpos','info'],keep=False)#sn之外的故障
         CellFltInfo = df_Diag_Ram_sn.drop('Batpos',axis=1)
-        df_Diag_Ram_fix = df_Diag_Ram.loc[df_Diag_Ram['Batpos'] == 1]
-        df_Diag_Ram_unfix = df_Diag_Ram.loc[df_Diag_Ram['Batpos'] == 0]
+        df_Diag_Ram_add = pd.DataFrame()
+        df_Diag_Ram_Update_change = pd.DataFrame()
         if not df_bms.empty:
             df_Diag_Batdiag_update_xq=SamplingSafty.main(sn,param,df_bms,CellFltInfo)#学琦计算故障   
             BatDiag=CBMSBatDiag.BatDiag(sn,celltype,df_bms, df_soh, df_uniform, CellFltInfo)#鹏飞计算
@@ -80,7 +80,6 @@ def diag_cal():
             df_Diag_Cal_Update_add = pd.concat([CellFltInfo,df_Diag_Batdiag_update_xq,df_Diag_Batdiag_update])#重新计算的该SN下的故障
             df_Diag_Cal_Update_temp = df_Diag_Cal_Update_add.drop_duplicates(subset=['product_id','start_time','end_time','code','info'], keep='first', inplace=False, ignore_index=False)#去除相同故障
             df_Diag_cal_early_unfix = pd.DataFrame()
-            df_sn_car_fix = pd.DataFrame()
             df_Diag_Cal_finish = pd.DataFrame()
             df_Diag_cal_early_fix = pd.DataFrame()
             if not df_Diag_Cal_Update_temp.empty:
@@ -91,14 +90,13 @@ def diag_cal():
                 df_Diag_Cal_finish['Batpos'] = 1
                 df_Diag_Cal_new['Batpos'] = 0
                 df_feishu_sta = df_read_Yunw.loc[(df_read_Yunw['product_id'] == sn)]#飞书中该sn车辆状态
-                if df_feishu_sta.empty:
+                if df_feishu_sta.empty:#飞书中没有该sn记录故障的新增
                     df_Diag_cal_early_unfix = df_Diag_Cal_new#如果为新出故障,则直接记录在df_diag_frame中
                 else:
-                    df_Diag_cal_later = df_Diag_Cal_new.loc[df_Diag_Cal_new['start_time'] > max(df_feishu_sta['start_time'])]#故障表中故障时间晚于飞书记录时间
+                    df_Diag_cal_later = df_Diag_Cal_new.loc[df_Diag_Cal_new['start_time'] > max(df_feishu_sta['start_time'])]#故障表中故障时间晚于飞书记录时间的新增
                     df_Diag_cal_early = pd.concat([df_Diag_Cal_new,df_Diag_cal_later,df_Diag_cal_later]).drop_duplicates(subset=['product_id','code','start_time'],keep=False)#故障表中故障时间早于飞书记录时间
                     df_feishu_sta_latest = df_feishu_sta.loc[df_feishu_sta['start_time'] == max(df_feishu_sta['start_time'])]#飞书中该SN下的最新故障
                     df_feishu_diag_unfix = (df_feishu_sta_latest['advice'] == '需正常返仓') | (df_feishu_sta_latest['advice'] == '需紧急返仓')
-                    df_sn_car_unfix = pd.DataFrame()
                     if any(df_feishu_diag_unfix):
                         df_Diag_cal_early_unfix = df_Diag_Cal_new
                     else:
@@ -107,30 +105,18 @@ def diag_cal():
                 if not df_Diag_cal_early_fix.empty:
                     df_Diag_cal_early_fix['Batpos'] = 1
             df_Diag_Ram_Update = pd.concat([df_Diag_cal_early_unfix,df_Diag_cal_early_fix,df_Diag_Cal_finish])
-            df_Diag_Ram_Update.sort_values(by = ['start_time'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序
-            df_temp5 = pd.concat([df_Diag_Ram_Update,df_Diag_Ram_sn_else])
-            df_Diag_Ram_sum = df_temp5.drop_duplicates(subset=['product_id','start_time','end_time','code','info'], keep='first', inplace=False, ignore_index=False)#去除相同故障
-            df_tempnum = df_Diag_Ram_sum.groupby(['product_id']).size()#获取每个sn的故障总数
-            col1 = df_tempnum[df_tempnum>1].reset_index()[['product_id']]#多故障sn号
-            col2 = df_tempnum[df_tempnum==1].reset_index()[['product_id']]#单故障sn号
-            df_temp1 = pd.DataFrame()
-            if not col1.empty:
-                for item in col1['product_id']:
-                    temp_data = df_Diag_Ram_sum.loc[df_Diag_Ram_sum['product_id'] == item]
-                    temp_data.sort_values(by = ['start_time'], axis = 0, ascending=True,inplace=True)#对故障信息按照时间进行排序
-                    df_temp1 = df_temp1.append(temp_data)
-            df_temp2 = pd.merge(col2,df_Diag_Ram_sum,on=["product_id"])#单故障码数据筛选
-            df_temp3 = pd.concat([df_temp1,df_temp2])#多故障及单故障合并
-            df_temp4 = df_temp3.reset_index(drop=True)
-            df_Diag_Ram = df_temp4
-            df_Diag_Ram_fix = df_Diag_Ram.loc[df_Diag_Ram['Batpos'] == 1]
-            df_Diag_Ram_unfix = df_Diag_Ram.loc[df_Diag_Ram['Batpos'] == 0]
-        if len(df_Diag_Ram) > 0:#历史及现有故障
+            df_Diag_Ram_Update.sort_values(by = ['start_time'], axis = 0, ascending=True,inplace=True)#该sn下当次诊断的故障状态
+            df_Diag_Ram_add = pd.concat([df_Diag_Ram_Update,df_Diag_Ram_sn,df_Diag_Ram_sn]).drop_duplicates(subset=['start_time','code'],keep=False)#此次判断中新增故障
+            df_Diag_Ram_Update_old = pd.concat([df_Diag_Ram_Update,df_Diag_Ram_add,df_Diag_Ram_add]).drop_duplicates(subset=['start_time','code'],keep=False)#此次判断中新增故障
+            df_Diag_Ram_Update_change = pd.concat([df_Diag_Ram_Update_old,df_Diag_Ram_sn,df_Diag_Ram_sn]).drop_duplicates(subset=['start_time','code','Batpos'],keep=False)#此次判断中新增故障
+            df_Diag_Ram = pd.concat([df_Diag_Ram_sn_else,df_Diag_Cal_new])
+
+        if (len(df_Diag_Ram_add) > 0) | (len(df_Diag_Ram_Update_change) > 0):#历史及现有故障
             df_Diag_Ram.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\01Screen_Problem\result.csv',index=False,encoding='GB18030')
-        if len(df_Diag_Ram_fix) > 0:#故障车辆已返仓
-            df_Diag_Ram_fix.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\01Screen_Problem\result_fix.csv',index=False,encoding='GB18030')
-        if len(df_Diag_Ram_unfix) > 0:#故障车辆未返仓
-            df_Diag_Ram_unfix.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\01Screen_Problemm\result_unfix.csv',index=False,encoding='GB18030')
+        if len(df_Diag_Ram_add) > 0:#新增故障
+            df_Diag_Ram_add.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\01Screen_Problem\result_add.csv',index=False,encoding='GB18030')
+        if len(df_Diag_Ram_Update_change) > 0:#更改故障
+            df_Diag_Ram_Update_change.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\01Screen_Problemm\result_change.csv',index=False,encoding='GB18030')
         end=time.time()
         print(end-start)
 
@@ -158,13 +144,18 @@ if __name__ == "__main__":
     mylog=log.Mylog('log_diag.txt','error')
     mylog.logcfg()
     #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取................
-    result=pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\01Screen_Problem\result.csv',encoding='gbk')
-    
-    # df_Diag_Ram=result[result['end_time']=='0000-00-00 00:00:00']
-    df_Diag_Ram=result#[result['Batpos'] == 0]#将故障依然存在的赋值
-    print('----------------输入--------')
-    print(df_Diag_Ram)
-    print('-------计算中-----------')
+    host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
+    port=3306
+    db='safety_platform'
+    user='qx_read'
+    password='Qx@123456'
+    mode=2
+    tablename2='all_fault_info'
+    DBRead = DBDw.DBDownload(host, port, db, user, password,mode)
+    with DBRead as DBRead:
+        df_Diag_Ram = DBRead.getdata('start_time','end_time','product_id','code','level','info','advice','Batpos',tablename=tablename2,factory='骑享',sn='',timename='',st='',sp='')
+    # result=pd.read_csv(r'D:\Work\Code_write\data_analyze_platform\USER\01Screen_Problem\result.csv',encoding='gbk')
+
     #定时任务.......................................................................................................................................................................
     scheduler = BlockingScheduler()
     scheduler.add_job(diag_cal, 'interval', seconds=300, id='diag_job')

BIN
df_file.xlsx