Browse Source

低电量和离线二次运算

lmstack 3 years ago
parent
commit
d8aeade684

+ 2 - 2
LIB/FRONTEND/CellStateEstimation/BatSafetyWarning/deploy.py

@@ -85,9 +85,9 @@ def saftywarning_cal():
             logger.info("pid-{} celltype-{} SN: {} START!".format(os.getpid(), celltype, sn))
 
             # 读取soh数据
-            df_soh = pd.read_sql("select time_st,sn,soh,cellsoh from cellstateestimation_soh where sn = '{}' order by add_time desc limit 1".format(sn), db_qxcas_engine)
+            df_soh = pd.read_sql("select time_st,sn,soh,cellsoh from cellstateestimation_soh where sn = '{}' order by id desc limit 1".format(sn), db_qxcas_engine)
 
-            #读取原始数据库数据........................................................................................................................................................
+            #读取原始数据库数据................................................................................id........................................................................
             dbManager = DBManager.DBManager()
             df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
             df_bms = df_data['bms']

+ 132 - 105
LIB/FRONTEND/SaftyCenter/DataDiag_Static/deploy.py

@@ -49,10 +49,11 @@ def diag_cal():
     #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取................``
     # print("select start_time, end_time, product_id, code, level, info, advice, factory from {}".format(tablename))
     try:
-        df_Diag_Ram=pd.read_sql("select start_time, end_time, product_id, code, level, info, advice, Batpos from all_fault_info where factory = '{}'".format('骑享'), db_engine)
+        df_Diag_Ram=pd.read_sql("select start_time, end_time, product_id, code, level, info, advice, Batpos from all_fault_info", db_engine)
     finally:
         db_engine.dispose()
-        
+    df_Diag_Ram=df_Diag_Ram.dropna(axis=1,how='any')
+    df_Diag_Ram=df_Diag_Ram.reset_index(drop=True)    
     #读取结果数据库数据........................................................................................................................................................
     host1='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
     port1=3306
@@ -96,6 +97,7 @@ def diag_cal():
     logger.info(" diag_cal START!")
 
     for i in range(0, len(df_sn)):
+        print(df_sn.loc[i, 'imei'])
         try:
             if df_sn.loc[i, 'imei'][5:9] == 'N640':
                 celltype=1 #6040三元电芯
@@ -107,10 +109,13 @@ def diag_cal():
                 celltype=3 #力信 50ah三元电芯
             elif df_sn.loc[i, 'imei'][3:5] == 'CL' and df_sn.loc[i, 'imei'][5:9] == 'N750': 
                 celltype=4 #CATL 50ah三元电芯
+            elif 'TJMCL'in sn: # 金茂
+                celltype=100 #CATL 50ah三元电芯
             else:
                 logger.info("pid-{} celltype-{} SN: {} SKIP!".format(os.getpid(), "未知", sn))
                 continue
             sn = df_sn.loc[i, 'sn']
+            factory = df_sn.loc[i, 'factory']
             logger.info("pid-{} celltype-{} SN: {} START!".format(os.getpid(), celltype, sn))
             # sys.exit()
             param=QX_BatteryParam.BatteryInfo(celltype)   
@@ -118,6 +123,8 @@ def diag_cal():
             dbManager = DBManager.DBManager()
             df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
             df_bms = df_data['bms']
+            df_bms=df_bms.dropna(subset=['总电流[A]'])
+            df_bms=df_bms.reset_index(drop=True)
             # with DBRead as DBRead:
             df_soh=DBRead.getdata('time_st,sn,soh,cellsoh', tablename=tablename1, sn=sn, timename='time_sp', st=start_time, sp=end_time)
             df_uniform=DBRead.getdata('time,sn,cellsoc_diff,cellmin_num,cellmax_num', tablename=tablename2, sn=sn, timename='time', st=start_time, sp=end_time)
@@ -132,14 +139,16 @@ def diag_cal():
             CellFltInfo = df_Diag_Ram_sn.drop('Batpos',axis=1)
             #获取当前故障电池的历史故障信息↑↑↑↑↑↑↑↑↑↑↑.......................................................................................................................................
             if not df_bms.empty:
-                df_Diag_Batdiag_update_xq=SamplingSafty.main(sn,param,df_bms,CellFltInfo)#学琦计算故障 
-                df_Diag_Batdiag_update_xq2=CtrlSafty.main(sn,param,df_bms,df_Diag_Batdiag_update_xq)
+                df_Diag_Batdiag_update_xq=SamplingSafty.main(sn,param,df_bms,CellFltInfo)#采样安全   
+                df_Diag_Batdiag_update_xq2=CtrlSafty.main(sn,param,df_bms,df_Diag_Batdiag_update_xq)#控制安全
   
                 batDiag=CBMSBatDiag.BatDiag(sn,celltype,df_bms, df_soh, df_uniform, df_Diag_Batdiag_update_xq2)#鹏飞计算
                 df_Diag_Batdiag_update=batDiag.diag()
                 # df_Diag_Batdiag_update=BatDiag.diag() 
             else:
                 df_Diag_Batdiag_update_xq=DataFrame(columns=['start_time','end_time','product_id','code','level','info','advice','Batpos'])
+                df_Diag_Batdiag_update_xq2=DataFrame(columns=['start_time','end_time','product_id','code','level','info','advice','Batpos'])
+
                 df_Diag_Batdiag_update=DataFrame(columns=['start_time','end_time','product_id','code','level','info','advice','Batpos'])
             df_Diag_Ram_add,df_Diag_Ram_Update=DiagDataMerge.DetaMerge(df_Diag_Ram_sn,df_Diag_Batdiag_update,df_OprtnSta,df_Diag_Ram_sn_else)
             # df_Diag_Ram.to_csv('df_Diag_Ram.csv')
@@ -148,7 +157,7 @@ def diag_cal():
             if len(df_Diag_Ram_add) > 0:#新增故障
                 
                 df_Diag_Ram_add.columns = ['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice', 'Batpos']
-                df_Diag_Ram_add['factory'] = '骑享'
+                df_Diag_Ram_add['factory'] = factory
                 df_Diag_Ram_add['add_time'] = datetime.datetime.now()
                 df_Diag_Ram_add.to_sql("all_fault_info",con=db_engine, if_exists="append",index=False)
                 # df_Diag_Ram_add.to_csv(r'D:\Work\Code_write\data_analyze_platform\USER\01Screen_Problem\result_add.csv',index=False,encoding='GB18030')
@@ -188,6 +197,8 @@ def diag_cal():
 #.................................统计程序...............................
 def DaTa_Sta_Week_Task():
     task_on=1
+    factory_info=['骑享','金茂换电']
+
     all_period_fault_info=DataFrame(columns=['factory','week','level1_count','level2_count','level3_count','level4_count','level5_count','solve_rate'])
     #............................获取数据................................
     toweek='Week'+time.strftime('%W')
@@ -209,28 +220,30 @@ def DaTa_Sta_Week_Task():
 
         DBRead=DBDw.DBDownload(host, port, db, user, password,mode)
         with DBRead as DBRead:
-            df_fltinfo=DBRead.getdata('product_id','level','code','start_time','end_time','batpos',tablename=tablename1,factory='骑享',sn='',timename='',st='',sp='')#dbdownload经过了改编
-        #............................获取时间................................      
-        end_time=datetime.datetime.now()
-        # end_time=datetime.datetime.strptime(end_time,'%Y-%m-%d')
-        start_time_week=end_time-datetime.timedelta(days=7)
-        start_time_week=start_time_week.strftime('%Y-%m-%d')
-        end_time=end_time.strftime('%Y-%m-%d')
-        FltAlarmInfo,Celltype=DataSta.SaftyWarningSta(df_fltinfo,start_time_week,end_time)
-        FaultLvlCount=DataSta.WeekInfoSta(df_fltinfo,start_time_week,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)
-        all_period_fault_info.loc[0,'factory']='骑享'
-        all_period_fault_info.loc[0,'week']=toweek
-        all_period_fault_info.loc[0,'solve_rate']=FltAlarmInfo.loc[0,'OprationManageRate']
-        all_period_fault_info.fillna(0,inplace=False)
-        if not all_period_fault_info.empty:
-            all_period_fault_info.to_sql('all_period_fault_info', db_engine, if_exists='append', index=False)
-        
-        logger.info("DaTa_Sta_Week_Task DONE!")
+            df_fltinfo=DBRead.getdata('product_id','level','code','start_time','end_time','batpos','factory',tablename=tablename1,factory='',sn='',timename='',st='',sp='')#dbdownload经过了改编
+        for j in range(0,len(factory_info)):
+            df_fltinfo=df_fltinfo[df_fltinfo['factory']==factory_info[j]]
+            #............................获取时间................................      
+            end_time=datetime.datetime.now()
+            # end_time=datetime.datetime.strptime(end_time,'%Y-%m-%d')
+            start_time_week=end_time-datetime.timedelta(days=7)
+            start_time_week=start_time_week.strftime('%Y-%m-%d')
+            end_time=end_time.strftime('%Y-%m-%d')
+            FltAlarmInfo,Celltype=DataSta.SaftyWarningSta(df_fltinfo,start_time_week,end_time,factory_info[j])
+            FaultLvlCount=DataSta.WeekInfoSta(df_fltinfo,start_time_week,end_time)
+            for i in range(1,6):
+                if not FaultLvlCount[FaultLvlCount['level']==i]['product_id'].empty:
+                    all_period_fault_info.loc[j,'level'+str(i)+'_count']=int(FaultLvlCount[FaultLvlCount['level']==i]['product_id'].values)
+                else:
+                    all_period_fault_info.loc[j,'level'+str(i)+'_count']=int(0)
+            all_period_fault_info.loc[j,'factory']=factory_info[j]
+            all_period_fault_info.loc[j,'week']=toweek
+            all_period_fault_info.loc[j,'solve_rate']=FltAlarmInfo.loc[0,'OprationManageRate']
+            all_period_fault_info.fillna(0,inplace=False)
+            if not all_period_fault_info.empty:
+                all_period_fault_info.to_sql('all_period_fault_info', db_engine, if_exists='append', index=False)
+            
+            logger.info("DaTa_Sta_Week_Task DONE!")
     except Exception as e:
         logger.error(traceback.format_exc)
         logger.error(u" 任务运行错误\n".format(), exc_info=True)
@@ -241,6 +254,8 @@ def DaTa_Sta_Week_Task():
     
 def DaTa_Sta_Minutes_Task():
     task_on=1
+    factory_info=['骑享','金茂换电']
+
     #............................获取数据................................
     host='172.16.121.236'
     port=3306
@@ -280,94 +295,95 @@ def DaTa_Sta_Minutes_Task():
         user, parse.quote_plus(password), host, port, db
     ))
     DBRead=DBDw.DBDownload(host, port, db, user, password,mode)
-    with DBRead as DBRead:
-        df_fltinfo=DBRead.getdata('product_id','level','code','start_time','batpos',tablename=tablename1,factory='骑享',sn='',timename='',st='',sp='')#dbdownload经过了改编
     
-    # df_Diag_Ram=pd.read_sql("select start_time, end_time, product_id, code, level, info, advice, Batpos from all_fault_info where factory = '{}' and Batpos=1".format('骑享'), db_engine)
-
-    #............................获取时间................................
+        #............................获取时间................................
     end_time=datetime.datetime.now()
     # end_time=datetime.datetime.strptime(end_time,'%Y-%m-%d')
     start_time=end_time-datetime.timedelta(days=1)
     start_time=start_time.strftime('%Y-%m-%d')
     end_time=end_time.strftime('%Y-%m-%d')
     #............................执行程序................................
-    FltAlarmInfo,Celltype=DataSta.SaftyWarningSta(df_fltinfo,start_time,end_time)
-    SatftyCount=DataSta.SftyWrngClsfy(df_fltinfo)
-    MaxAccumAh,TotalAccumAh,MaxCycle,MaxRunningHour,TotalRunHour=DataSta.AccumInfo(df_last_accum,df_FirstDataTime,end_time)
-    all_location_info=DataSta.FltBatPosition(df_last_pos,df_fltinfo)
-
     all_statistic_info=DataFrame(columns=['factory','total_alarm','alarm_total_today','alarm_not_close_today','alarm_close_today','alarm_uregent_total_today','alarm_uregent_close_today','alarm_uregent_not_close_today','run_time_total','dischrg_total','odo_total','max_dischrg_one','max_runtime_one','max_cycle_one','max_odo_one','alarm_close_total','alarm_total','cell_type','cell_type_count','cell_safety_risk_count','data_safety_risk_count','status_safety_risk_count','hv_safety_risk_count','system_safety_risk_count','sample_safety_risk_count','controller_safety_risk_count','design_safety_risk_count'])
-    all_statistic_info.loc[0,'factory']='骑享'
-    all_statistic_info.loc[0,'total_alarm']=FltAlarmInfo.loc[0,'SftyPlt_Data_Total']
-    all_statistic_info.loc[0,'alarm_total_today']=FltAlarmInfo.loc[0,'SftyPlt_Data_day']
-    all_statistic_info.loc[0,'alarm_close_today']=FltAlarmInfo.loc[0,'CS_Warning_day_Finish_Count']
-    all_statistic_info.loc[0,'alarm_not_close_today']=FltAlarmInfo.loc[0,'SftyPlt_Data_day']-FltAlarmInfo.loc[0,'CS_Warning_day_Finish_Count']
-    all_statistic_info.loc[0,'alarm_uregent_total_today']=FltAlarmInfo.loc[0,'SftyPlt_EmgcyData_day']
-    all_statistic_info.loc[0,'alarm_uregent_close_today']=FltAlarmInfo.loc[0,'SftyPlt_EmgcyData_day_Finish_Count']
-    all_statistic_info.loc[0,'alarm_uregent_not_close_today']=FltAlarmInfo.loc[0,'SftyPlt_EmgcyData_day']-FltAlarmInfo.loc[0,'SftyPlt_EmgcyData_day_Finish_Count']
-    all_statistic_info.loc[0,'run_time_total']=TotalRunHour
-    all_statistic_info.loc[0,'dischrg_total']=TotalAccumAh
-    all_statistic_info.loc[0,'odo_total']=0
-    all_statistic_info.loc[0,'max_dischrg_one']=MaxAccumAh
-    all_statistic_info.loc[0,'max_runtime_one']=MaxRunningHour
-    all_statistic_info.loc[0,'max_cycle_one']=MaxCycle
-    all_statistic_info.loc[0,'max_odo_one']=0
-    all_statistic_info.loc[0,'alarm_close_total']=FltAlarmInfo.loc[0,'CS_Warning_Total_Finish_Count']
-    all_statistic_info.loc[0,'alarm_total']=FltAlarmInfo.loc[0,'SftyPlt_Data_Total']
-    CellType=Celltype.columns.tolist()
-    CellType=','.join(CellType) 
-    all_statistic_info.loc[0,'cell_type']=str(CellType)
-    CellTypeCount=Celltype.loc[0].tolist()
-    CellTypeCount=[str(x) for x in CellTypeCount]
-    CellTypeCount=','.join(CellTypeCount) 
-    all_statistic_info.loc[0,'cell_type_count']=str(CellTypeCount)
-    all_statistic_info.loc[0,'cell_safety_risk_count']=SatftyCount.loc[0,'CellSaftyCount']
-    all_statistic_info.loc[0,'data_safety_risk_count']=SatftyCount.loc[0,'DataSaftyCodeCount']
-    all_statistic_info.loc[0,'status_safety_risk_count']=SatftyCount.loc[0,'StateSaftyCodeCount']
-    all_statistic_info.loc[0,'hv_safety_risk_count']=SatftyCount.loc[0,'HvSaftyCodeCount']
-    all_statistic_info.loc[0,'system_safety_risk_count']=SatftyCount.loc[0,'SysSaftyCodeCount']
-    all_statistic_info.loc[0,'sample_safety_risk_count']=SatftyCount.loc[0,'SamplingSatyCount']
-    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'] 
-    # all_statistic_info.to_csv('all_statistic_info.csv')
-#
-    try:
-        logger.info("DaTa_Sta_Minutes_Task START!")
-        # 更新统计信息
-        conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
-        cursor = conn.cursor()
-        sql = ''' update all_statistic_info set update_time='{}', total_alarm={}, alarm_total_today={}, alarm_close_today={}, alarm_not_close_today={},
-                    alarm_uregent_total_today={}, alarm_uregent_close_today={},alarm_uregent_not_close_today={},run_time_total={},dischrg_total={},
-                    odo_total={},max_dischrg_one={},max_runtime_one={},max_cycle_one={},max_odo_one={},alarm_close_total={},alarm_total={},cell_type='{}',
-                    cell_type_count='{}',cell_safety_risk_count={}, data_safety_risk_count={},status_safety_risk_count={},hv_safety_risk_count={},
-                    system_safety_risk_count={},sample_safety_risk_count={},controller_safety_risk_count={},design_safety_risk_count={}
-                    where factory='{}' 
-                    '''.format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), all_statistic_info.loc[0,'total_alarm'], all_statistic_info.loc[0,'alarm_total_today'],all_statistic_info.loc[0,'alarm_close_today'],
-                               all_statistic_info.loc[0,'alarm_not_close_today'],all_statistic_info.loc[0,'alarm_uregent_total_today'],all_statistic_info.loc[0,'alarm_uregent_close_today'],
-                               all_statistic_info.loc[0,'alarm_uregent_not_close_today'],all_statistic_info.loc[0,'run_time_total'],all_statistic_info.loc[0,'dischrg_total'],
-                               all_statistic_info.loc[0,'odo_total'],all_statistic_info.loc[0,'max_dischrg_one'],all_statistic_info.loc[0,'max_runtime_one'],
-                               all_statistic_info.loc[0,'max_cycle_one'],all_statistic_info.loc[0,'max_odo_one'],all_statistic_info.loc[0,'alarm_close_total'],
-                               all_statistic_info.loc[0,'alarm_total'],all_statistic_info.loc[0,'cell_type'],all_statistic_info.loc[0,'cell_type_count'],
-                               all_statistic_info.loc[0,'cell_safety_risk_count'],all_statistic_info.loc[0,'data_safety_risk_count'],all_statistic_info.loc[0,'status_safety_risk_count'],
-                               all_statistic_info.loc[0,'hv_safety_risk_count'],all_statistic_info.loc[0,'system_safety_risk_count'],all_statistic_info.loc[0,'sample_safety_risk_count'],
-                                all_statistic_info.loc[0,'controller_safety_risk_count'],all_statistic_info.loc[0,'design_safety_risk_count'],'骑享')
-        cursor.execute(sql)
-        conn.commit()
-        # 更新故障位置信息
-        if not all_location_info.empty:
-            sql = "delete from all_fault_location_info where factory='骑享'"
+    for j in range(0,len(factory_info)):
+        with DBRead as DBRead:
+            df_fltinfo=DBRead.getdata('product_id','level','code','start_time','batpos',tablename=tablename1,factory=factory_info[j],sn='',timename='',st='',sp='')#dbdownload经过了改编
+            
+        #............................执行程序................................
+        FltAlarmInfo,Celltype=DataSta.SaftyWarningSta(df_fltinfo,start_time,end_time,factory_info[j])
+        SatftyCount=DataSta.SftyWrngClsfy(df_fltinfo)
+        MaxAccumAh,TotalAccumAh,MaxCycle,MaxRunningHour,TotalRunHour=DataSta.AccumInfo(df_last_accum,df_FirstDataTime,end_time,factory_info[j])
+        all_location_info=DataSta.FltBatPosition(df_last_pos,df_fltinfo,factory_info[j])
+
+        all_statistic_info.loc[j,'factory']=factory_info[j]
+        all_statistic_info.loc[j,'total_alarm']=FltAlarmInfo.loc[0,'SftyPlt_Data_Total']
+        all_statistic_info.loc[j,'alarm_total_today']=FltAlarmInfo.loc[0,'SftyPlt_Data_day']
+        all_statistic_info.loc[j,'alarm_close_today']=FltAlarmInfo.loc[0,'CS_Warning_day_Finish_Count']
+        all_statistic_info.loc[j,'alarm_not_close_today']=FltAlarmInfo.loc[0,'SftyPlt_Data_day']-FltAlarmInfo.loc[0,'CS_Warning_day_Finish_Count']
+        all_statistic_info.loc[j,'alarm_uregent_total_today']=FltAlarmInfo.loc[0,'SftyPlt_EmgcyData_day']
+        all_statistic_info.loc[j,'alarm_uregent_close_today']=FltAlarmInfo.loc[0,'SftyPlt_EmgcyData_day_Finish_Count']
+        all_statistic_info.loc[j,'alarm_uregent_not_close_today']=FltAlarmInfo.loc[0,'SftyPlt_EmgcyData_day']-FltAlarmInfo.loc[0,'SftyPlt_EmgcyData_day_Finish_Count']
+        all_statistic_info.loc[j,'run_time_total']=TotalRunHour
+        all_statistic_info.loc[j,'dischrg_total']=TotalAccumAh
+        all_statistic_info.loc[j,'odo_total']=0
+        all_statistic_info.loc[j,'max_dischrg_one']=MaxAccumAh
+        all_statistic_info.loc[j,'max_runtime_one']=MaxRunningHour
+        all_statistic_info.loc[j,'max_cycle_one']=MaxCycle
+        all_statistic_info.loc[j,'max_odo_one']=0
+        all_statistic_info.loc[j,'alarm_close_total']=FltAlarmInfo.loc[0,'CS_Warning_Total_Finish_Count']
+        all_statistic_info.loc[j,'alarm_total']=FltAlarmInfo.loc[0,'SftyPlt_Data_Total']
+        CellType=Celltype.columns.tolist()
+        CellType=','.join(CellType) 
+        all_statistic_info.loc[0,'cell_type']=str(CellType)
+        CellTypeCount=Celltype.loc[0].tolist()
+        CellTypeCount=[str(x) for x in CellTypeCount]
+        CellTypeCount=','.join(CellTypeCount) 
+        all_statistic_info.loc[j,'cell_type_count']=str(CellTypeCount)
+        all_statistic_info.loc[j,'cell_safety_risk_count']=SatftyCount.loc[0,'CellSaftyCount']
+        all_statistic_info.loc[j,'data_safety_risk_count']=SatftyCount.loc[0,'DataSaftyCodeCount']
+        all_statistic_info.loc[j,'status_safety_risk_count']=SatftyCount.loc[0,'StateSaftyCodeCount']
+        all_statistic_info.loc[j,'hv_safety_risk_count']=SatftyCount.loc[0,'HvSaftyCodeCount']
+        all_statistic_info.loc[j,'system_safety_risk_count']=SatftyCount.loc[0,'SysSaftyCodeCount']
+        all_statistic_info.loc[j,'sample_safety_risk_count']=SatftyCount.loc[0,'SamplingSatyCount']
+        all_statistic_info.loc[j,'controller_safety_risk_count']=SatftyCount.loc[0,'CtrlSaftyCodeCount']
+        all_statistic_info.loc[j,'design_safety_risk_count']=SatftyCount.loc[0,'DsnSaftyCodeCount']
+        # all_statistic_info.to_csv('all_statistic_info.csv')
+    #
+        try:
+            logger.info("DaTa_Sta_Minutes_Task START!")
+            # 更新统计信息
+            conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
+            cursor = conn.cursor()
+            sql = ''' update all_statistic_info set update_time='{}', total_alarm={}, alarm_total_today={}, alarm_close_today={}, alarm_not_close_today={},
+                        alarm_uregent_total_today={}, alarm_uregent_close_today={},alarm_uregent_not_close_today={},run_time_total={},dischrg_total={},
+                        odo_total={},max_dischrg_one={},max_runtime_one={},max_cycle_one={},max_odo_one={},alarm_close_total={},alarm_total={},cell_type='{}',
+                        cell_type_count='{}',cell_safety_risk_count={}, data_safety_risk_count={},status_safety_risk_count={},hv_safety_risk_count={},
+                        system_safety_risk_count={},sample_safety_risk_count={},controller_safety_risk_count={},design_safety_risk_count={}
+                        where factory='{}' 
+                        '''.format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), all_statistic_info.loc[0,'total_alarm'], all_statistic_info.loc[0,'alarm_total_today'],all_statistic_info.loc[0,'alarm_close_today'],
+                                all_statistic_info.loc[0,'alarm_not_close_today'],all_statistic_info.loc[0,'alarm_uregent_total_today'],all_statistic_info.loc[0,'alarm_uregent_close_today'],
+                                all_statistic_info.loc[0,'alarm_uregent_not_close_today'],all_statistic_info.loc[0,'run_time_total'],all_statistic_info.loc[0,'dischrg_total'],
+                                all_statistic_info.loc[0,'odo_total'],all_statistic_info.loc[0,'max_dischrg_one'],all_statistic_info.loc[0,'max_runtime_one'],
+                                all_statistic_info.loc[0,'max_cycle_one'],all_statistic_info.loc[0,'max_odo_one'],all_statistic_info.loc[0,'alarm_close_total'],
+                                all_statistic_info.loc[0,'alarm_total'],all_statistic_info.loc[0,'cell_type'],all_statistic_info.loc[0,'cell_type_count'],
+                                all_statistic_info.loc[0,'cell_safety_risk_count'],all_statistic_info.loc[0,'data_safety_risk_count'],all_statistic_info.loc[0,'status_safety_risk_count'],
+                                all_statistic_info.loc[0,'hv_safety_risk_count'],all_statistic_info.loc[0,'system_safety_risk_count'],all_statistic_info.loc[0,'sample_safety_risk_count'],
+                                    all_statistic_info.loc[0,'controller_safety_risk_count'],all_statistic_info.loc[0,'design_safety_risk_count'],all_statistic_info.loc[j,'factory'])
             cursor.execute(sql)
-            all_location_info.to_sql('all_fault_location_info', db_engine, if_exists='append', index=False)
             conn.commit()
-        logger.info("DaTa_Sta_Minutes_Task DONE!")
+            # 更新故障位置信息
+            if not all_location_info.empty:
+                sql = "delete from all_fault_location_info where factory='骑享'"
+                cursor.execute(sql)
+                all_location_info.to_sql('all_fault_location_info', db_engine, if_exists='append', index=False)
+                conn.commit()
+            logger.info("DaTa_Sta_Minutes_Task DONE!")
 
-    except:
-        logger.error(traceback.format_exc)
-        logger.error(u"{},{} 任务运行错误\n".format(start_time,end_time), exc_info=True)
-    finally:
-        conn.close();
-        db_engine.dispose();
+        except:
+            logger.error(traceback.format_exc)
+            logger.error(u"{},{} 任务运行错误\n".format(start_time,end_time), exc_info=True)
+        finally:
+            conn.close();
+            db_engine.dispose();
     task_on=0
 
 
@@ -395,8 +411,19 @@ if __name__ == "__main__":
     res = cursor.fetchall()
     df_sn = pd.DataFrame(res, columns=['sn', 'imei', 'add_time'])
     df_sn = df_sn.reset_index(drop=True)
+    cursor.close()
     conn.close();
+    df_sn['factory'] = '骑享'
     
+    db = 'qx_cas'
+    conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
+    cursor = conn.cursor()
+    cursor.execute("select sn, factory from sn_list")
+    res = cursor.fetchall()
+    df_sn2 = pd.DataFrame(res, columns=['sn', 'factory'])
+    df_sn2['imei'] = ""
+    df_sn = pd.concat([df_sn, df_sn2], axis=0)
+    df_sn = df_sn.reset_index(drop=True)
     # # 数据库配置
     # host = 'rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
     # port = 3306
@@ -444,7 +471,7 @@ if __name__ == "__main__":
     #............................模块运行前,先读取数据库中所有结束时间为0的数据,需要从数据库中读取................``
     # print("select start_time, end_time, product_id, code, level, info, advice, factory from {}".format(tablename))
     try:
-        df_Diag_Ram=pd.read_sql("select start_time, end_time, product_id, code, level, info, advice, Batpos from all_fault_info where factory = '{}'".format('骑享'), db_engine)
+        df_Diag_Ram=pd.read_sql("select start_time, end_time, product_id, code, level, info, advice, Batpos from all_fault_info", db_engine)
     finally:
         db_engine.dispose()
     # result = result[['start_time', 'end_time', 'product_id', 'code', 'level', 'info', 'advice']]

+ 1 - 0
LIB/FRONTEND/SaftyCenter/LowSocAlarm/deploy.py

@@ -136,6 +136,7 @@ if __name__ == "__main__":
                 logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)
     try:
         if not low_soc_bat_list.empty:
+            low_soc_bat_list['add_time'] = datetime.datetime.now()
             low_soc_bat_list.to_sql("lowsoc_info",con=db_engine, if_exists="append",index=False)
             logger.info("入库成功!")
     finally:

+ 65 - 0
LIB/FRONTEND/SaftyCenter/LowSocAlarm/deploy_sta.py

@@ -0,0 +1,65 @@
+
+__author__ = 'lmstack'
+#coding=utf-8
+import os
+import datetime
+import pandas as pd
+from LIB.BACKEND import DBManager, Log
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+import time, datetime
+import dateutil.relativedelta
+import traceback
+from LIB.MIDDLE.CellStateEstimation.Common import log
+from LIB.MIDDLE.SaftyCenter.Low_Soc_Alarm import low_soc_alarm_sta
+from urllib import parse
+import pymysql
+from LIB.BACKEND import DBManager
+
+if __name__ == "__main__":
+    
+    
+    # 日志配置
+    now_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).replace(":","_")
+    log_path = 'log_sta/' + now_str
+    if not os.path.exists(log_path):
+        os.makedirs(log_path)
+    log = Log.Mylog(log_name='saftyCenter_lowsocsta', log_level = 'info')
+    log.set_file_hl(file_name='{}/info.log'.format(log_path), log_level='info', size=1024* 1024 * 100)
+    log.set_file_hl(file_name='{}/error.log'.format(log_path), log_level='error', size=1024* 1024 * 100)
+    logger = log.get_logger()
+
+    logger.info("pid is {}".format(os.getpid()))
+    try:
+        # 算法参数
+        host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
+        port=3306
+        db='qx_cas'
+        user='qx_algo_rw'
+        password='qx@123456'
+
+        db_qxcas_engine = create_engine(
+            "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
+                user, parse.quote_plus(password), host, port, db
+            ))
+
+        db = 'safety_platform'
+        conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
+        cursor = conn.cursor()
+        db_sp_engine = create_engine(
+            "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
+                user, parse.quote_plus(password), host, port, db
+            ))
+
+        logger.info("pid-{} START!".format(os.getpid()))
+        low_soc_alarm_sta.low_soc_alarm_sta(db_qxcas_engine, conn, db_sp_engine)
+        logger.info("pid-{} DONE!".format(os.getpid()))
+                    
+    except:
+        logger.error(traceback.format_exc)
+        logger.error("任务运行错误", exc_info=True)
+
+    db_sp_engine.dispose()
+    db_qxcas_engine.dispose()
+    conn.close()
+    

+ 4 - 0
LIB/FRONTEND/SaftyCenter/LowSocAlarm/run_sta.bat

@@ -0,0 +1,4 @@
+cd /d D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\SaftyCenter\LowSocAlarm
+title cal_saftyCenter_LowSocAlarmSta
+D:\env\py_pro\python.exe D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\SaftyCenter\LowSocAlarm\deploy_sta.py
+pause

+ 66 - 0
LIB/FRONTEND/SaftyCenter/Offline/deploy.py

@@ -0,0 +1,66 @@
+
+__author__ = 'lmstack'
+#coding=utf-8
+import os
+import datetime
+import pandas as pd
+from LIB.BACKEND import DBManager, Log
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+import time, datetime
+import dateutil.relativedelta
+import traceback
+from LIB.MIDDLE.CellStateEstimation.Common import log
+from LIB.MIDDLE.SaftyCenter.Offline import offline_alarm
+from urllib import parse
+import pymysql
+from LIB.BACKEND import DBManager
+
+if __name__ == "__main__":
+    
+    
+    # 日志配置
+    now_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).replace(":","_")
+    log_path = 'log/' + now_str
+    if not os.path.exists(log_path):
+        os.makedirs(log_path)
+    log = Log.Mylog(log_name='saftyCenter_offline', log_level = 'info')
+    log.set_file_hl(file_name='{}/info.log'.format(log_path), log_level='info', size=1024* 1024 * 100)
+    log.set_file_hl(file_name='{}/error.log'.format(log_path), log_level='error', size=1024* 1024 * 100)
+    logger = log.get_logger()
+
+    logger.info("pid is {}".format(os.getpid()))
+    try:
+        # 算法参数
+        host='172.16.121.236'
+        port=3306
+        db='fastfun'
+        user='readonly'
+        password='Fast1234'
+
+        db_iotp_engine = create_engine(
+            "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
+                user, parse.quote_plus(password), host, port, db
+            ))
+        host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
+        port=3306
+        db='qx_cas'
+        user='qx_algo_rw'
+        password='qx@123456'
+
+        db_qxcas_engine = create_engine(
+            "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
+                user, parse.quote_plus(password), host, port, db
+            ))
+
+        logger.info("pid-{}   START!".format(os.getpid()))
+        offline_alarm.offline_alarm(db_iotp_engine, db_qxcas_engine)
+        logger.info("pid-{} DONE!".format(os.getpid()))
+                    
+    except:
+        logger.error(traceback.format_exc)
+        logger.error("任务运行错误", exc_info=True)
+
+    db_iotp_engine.dispose()
+    db_qxcas_engine.dispose()
+    

+ 75 - 0
LIB/FRONTEND/SaftyCenter/Offline/deploy_sta.py

@@ -0,0 +1,75 @@
+
+__author__ = 'lmstack'
+#coding=utf-8
+import os
+import datetime
+import pandas as pd
+from LIB.BACKEND import DBManager, Log
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+import time, datetime
+import dateutil.relativedelta
+import traceback
+from LIB.MIDDLE.CellStateEstimation.Common import log
+from LIB.MIDDLE.SaftyCenter.Offline import offline_alarm_sta
+from urllib import parse
+import pymysql
+from LIB.BACKEND import DBManager
+
+if __name__ == "__main__":
+    
+    
+    # 日志配置
+    now_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).replace(":","_")
+    log_path = 'log_sta/' + now_str
+    if not os.path.exists(log_path):
+        os.makedirs(log_path)
+    log = Log.Mylog(log_name='saftyCenter_offlinesta', log_level = 'info')
+    log.set_file_hl(file_name='{}/info.log'.format(log_path), log_level='info', size=1024* 1024 * 100)
+    log.set_file_hl(file_name='{}/error.log'.format(log_path), log_level='error', size=1024* 1024 * 100)
+    logger = log.get_logger()
+
+    logger.info("pid is {}".format(os.getpid()))
+    try:
+        # 算法参数
+        host='172.16.121.236'
+        port=3306
+        db='fastfun'
+        user='readonly'
+        password='Fast1234'
+
+        db_iotp_engine = create_engine(
+            "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
+                user, parse.quote_plus(password), host, port, db
+            ))
+
+        host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
+        port=3306
+        db='qx_cas'
+        user='qx_algo_rw'
+        password='qx@123456'
+
+        db_qxcas_engine = create_engine(
+            "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
+                user, parse.quote_plus(password), host, port, db
+            ))
+
+        db = 'safety_platform'
+        conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
+        db_sp_engine = create_engine(
+            "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
+                user, parse.quote_plus(password), host, port, db
+            ))
+
+        logger.info("pid-{}   START!".format(os.getpid()))
+        offline_alarm_sta.offline_alarm_sta(db_iotp_engine, db_qxcas_engine, conn, db_sp_engine)
+        logger.info("pid-{} DONE!".format(os.getpid()))
+                    
+    except:
+        logger.error(traceback.format_exc)
+        logger.error("任务运行错误", exc_info=True)
+
+    db_iotp_engine.dispose()
+    db_qxcas_engine.dispose()
+    conn.close()
+    

+ 4 - 0
LIB/FRONTEND/SaftyCenter/Offline/run.bat

@@ -0,0 +1,4 @@
+cd /d D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\SaftyCenter\Offline
+title cal_saftyCenter_Offline
+D:\env\py_pro\python.exe D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\SaftyCenter\Offline\deploy.py
+pause

+ 4 - 0
LIB/FRONTEND/SaftyCenter/Offline/run_sta.bat

@@ -0,0 +1,4 @@
+cd /d D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\SaftyCenter\Offline
+title cal_saftyCenter_Offline
+D:\env\py_pro\python.exe D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\SaftyCenter\Offline\deploy_sta.py
+pause

+ 0 - 7
LIB/FRONTEND/SaftyCenter/status_sta/deploy.py

@@ -12,12 +12,8 @@ import dateutil.relativedelta
 import traceback
 from LIB.MIDDLE.CellStateEstimation.Common import log
 from LIB.MIDDLE.SaftyCenter.StatusSta.V1_0_0 import status_sta
-
-from LIB.MIDDLE.CellStateEstimation.Common import DBDownload
 from urllib import parse
 import pymysql
-
-import datacompy
 from LIB.BACKEND import DBManager
 
 if __name__ == "__main__":
@@ -77,9 +73,6 @@ if __name__ == "__main__":
         df_first_data_time = pd.read_sql("select * from bat_first_data_time", db_engine)
 
         
-
-        
-        
         # 算法参数
         host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
         port=3306