lmstack 3 年之前
父节点
当前提交
4673f813d5

+ 28 - 25
LIB/FRONTEND/CellStateEstimation/BatSafetyAlarm/deploy.py

@@ -84,10 +84,11 @@ def diag_cal(df_sn, df_bms_ram, log_name):
             # print(df_bms)
 
             #电池诊断................................................................................................................................................................
-            if not df_bms.empty:
-                df_diag_ram_sn=df_diag_ram[df_diag_ram['product_id']==sn]
-                df_bms_ram_sn=df_bms_ram[df_bms_ram['sn']==sn]
-                if df_diag_ram_sn.empty:
+            
+            df_diag_ram_sn=df_diag_ram[df_diag_ram['product_id']==sn]
+            df_bms_ram_sn=df_bms_ram[df_bms_ram['sn']==sn]
+            if df_diag_ram_sn.empty:
+                if not df_bms.empty:
                     SafetyAlarm=CBMSSafetyAlarm.SafetyAlarm(sn,celltype,df_bms, df_bms_ram_sn)
                     df_diag_res, df_bms_res=SafetyAlarm.diag() 
 
@@ -106,27 +107,29 @@ def diag_cal(df_sn, df_bms_ram, log_name):
                         df_diag_res.columns = ['start_time', 'end_time', 'product_id', 'code', 'level', 'info', 'advice']
                         df_diag_res['add_time'] = datetime.datetime.now()
                         df_diag_res['factory'] = '骑享'
-                        df_diag_res.to_sql("all_fault_info",con=db_res_engine, if_exists="append",index=False)
-
-                    
-                #当前热失控已超过三天变为历史故障并写入数据库,并删除原有数据库中的当前故障和ram中的当前故障
-                else:
-                    fault_time=datetime.datetime.strptime(df_diag_ram_sn.iloc[-1]['start_time'], '%Y-%m-%d %H:%M:%S')
-                    if (now_time-fault_time).total_seconds()>24*3600:
-                        df_diag_ram_sn['end_time']=end_time
-                        df_diag_ram_sn['Batpos']=1
-                    
-                        try:
-
-                            cursor.execute('''
-                                        update all_fault_info set update_time='{}',end_time='{}', Batpos={} where product_id='{}' and end_time='0000-00-00 00:00:00' and code={} and factory='骑享'
-                                        '''.format(datetime.datetime.now(), end_time, 1,sn, 119))
-                            conn.commit()
-                            conn.close();
-                        except:
-                            logger.error(traceback.format_exc)
-                            logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)
-                            conn.close();
+                        df_diag_res.to_sql("all_fault_info",con=conn, if_exists="append",index=False)
+                        conn.commit()
+                        logger.info(u"{} 写入成功!!!\n".format(sn), exc_info=True)
+                
+            #当前热失控已超过三天变为历史故障并写入数据库,并删除原有数据库中的当前故障和ram中的当前故障
+            else:
+                fault_time=datetime.datetime.strptime(df_diag_ram_sn.iloc[-1]['start_time'], '%Y-%m-%d %H:%M:%S')
+                if (now_time-fault_time).total_seconds()>24*3600:
+                    df_diag_ram_sn['end_time']=end_time
+                    df_diag_ram_sn['Batpos']=1
+                
+                    try:
+
+                        cursor.execute('''
+                                    update all_fault_info set update_time='{}',end_time='{}', Batpos={} where product_id='{}' and end_time='0000-00-00 00:00:00' and code={} and factory='骑享'
+                                    '''.format(datetime.datetime.now(), end_time, 1,sn, 119))
+                        conn.commit()
+                        logger.info(u"{} 更新成功\n".format(sn), exc_info=True)
+
+                    except:
+                        logger.error(traceback.format_exc)
+                        logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)
+                  
         except:
             logger.error(traceback.format_exc)
             logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)

+ 28 - 32
LIB/FRONTEND/CellStateEstimation/BatSafetyWarning/deploy.py

@@ -12,15 +12,11 @@ import traceback
 from LIB.MIDDLE.CellStateEstimation.Common import log
 from LIB.MIDDLE.CellStateEstimation.BatSafetyWarning.V1_0_1 import CBMSSafetyWarning
 from LIB.MIDDLE.CellStateEstimation.BatSafetyWarning.V1_0_1 import CBMSBatInterShort
-
-from LIB.MIDDLE.CellStateEstimation.Common.V1_0_1 import DBDownload
 from urllib import parse
 import pymysql
-import pdb
+
 from apscheduler.schedulers.blocking import BlockingScheduler
-import datacompy
-import logging
-import multiprocessing
+
 #...................................电池包电芯安全诊断函数......................................................................................................................
 def saftywarning_cal():
     global df_sn
@@ -114,13 +110,12 @@ def saftywarning_cal():
                     df_lfp_ram_sn.reset_index(inplace=True,drop=True)     #重置索引
                 else:
                     df_lfp_ram_sn=pd.DataFrame()
-
                 BatShort=CBMSBatInterShort.BatInterShort(sn,celltype,df_bms,df_soh,df_warning_ram_sn,df_warning_ram_sn1,df_warning_ram_sn2,df_warning_ram_sn3,df_lfp_ram_sn)
                 df_short_res, df_ram_res, df_ram_res1, df_ram_res2, df_ram_res3, df_ram_res4=BatShort.intershort() 
 
                 if not df_short_res.empty:
-                    df_res.columns = ['time_st', 'time_sp', 'sn', 'method', 'short_current', 'baltime']
-                    df_res.to_sql("cellStateEstimation_interShort",con=db_qxcas_engine, if_exists="append",index=False)
+                    df_short_res.columns = ['time_st', 'time_sp', 'sn', 'method', 'short_current', 'baltime']
+                    df_short_res.to_sql("cellStateEstimation_interShort",con=db_qxcas_engine, if_exists="append",index=False)
 
                 #内短路ram处理.........................................................
                 df_warning_ram=df_warning_ram.drop(df_warning_ram[df_warning_ram.sn==sn].index)
@@ -140,35 +135,35 @@ def saftywarning_cal():
             #电池热安全预警..............................................................................................................................................................
             #读取内短路、析锂和一致性结果数据库数据
             df_short = pd.read_sql("select time_sp,sn,short_current from cellstateestimation_intershort where sn = '{}' and time_sp between '{}' and '{}'".format(sn,start_time1,end_time), db_qxcas_engine)
-            df_liplated = pd.read_sql("select time,sn,liplated,liplated_amount as lipltd_amount from mechanism_liplated where sn = '{}' and time between '{}' and '{}'".format(sn,start_time2,end_time), db_qxcas_engine)
+            df_liplated = pd.read_sql("select time,sn,liplated,liplated_amount from mechanism_liplated where sn = '{}' and time between '{}' and '{}'".format(sn,start_time2,end_time), db_qxcas_engine)
             df_uniform = pd.read_sql("select time,sn,cellsoc_diff,cellmin_num from cellstateestimation_uniform_socvoltdiff where sn = '{}' and time between '{}' and '{}'".format(sn,start_time1,end_time), db_qxcas_engine)
             
             #获取sn的故障RAM
             df_fault_ram_sn=df_fault_ram[df_fault_ram['product_id']==sn]
             
             #热安全预警
-            BatWarning=CBMSSafetyWarning.SafetyWarning(sn,celltype,df_short,df_liplated,df_uniform,df_fault_ram_sn)
-            df_warning_res=BatWarning.diag()
-
-            df_warning_end=df_warning_res[df_warning_res['end_time'] != '0000-00-00 00:00:00']
-            df_warning_end = df_warning_end.reset_index(drop=True)
-            if not df_warning_end.empty:    #df_warning_end历史故障筛选并更改数据库故障结束时间
-                try:
-                    cursor.execute('''
-                                update all_fault_info set update_time='{}',end_time='{}', Batpos={} where product_id='{}' and code={} and end_time='0000-00-00 00:00:00' and factory='骑享'
-                                '''.format(datetime.datetime.now(), df_warning_end.loc[0,'end_time'], df_warning_end.loc[0,'Batpos'],sn, 110))
+            if df_fault_ram_sn.empty:
+                BatWarning=CBMSSafetyWarning.SafetyWarning(sn,celltype,df_short,df_liplated,df_uniform)
+                df_warning_res=BatWarning.diag()
+                #当前热失控故障写入数据库
+                if not df_warning_res.empty:
+                    df_warning_res['add_time'] = datetime.datetime.now()
+                    df_warning_res['factory'] = '骑享'
+                    df_warning_res.to_sql("all_fault_info",con=conn, if_exists="append",index=False)
                     conn.commit()
-                    conn.close();
-                except:
-                    logger.error(traceback.format_exc)
-                    logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)
-    
-            elif df_fault_ram_sn.empty and (not df_warning_res.empty):
-                df_warning_res['add_time'] = datetime.datetime.now()
-                df_warning_res['factory'] = '骑享'
-                df_warning_res.to_sql("all_fault_info",con=db_qxcas_engine, if_exists="append",index=False)
             else:
-                pass
+                fault_time=datetime.datetime.strptime(df_fault_ram_sn.iloc[-1]['start_time'], '%Y-%m-%d %H:%M:%S')
+                if (now_time-fault_time).total_seconds()>24*3600:   #df_warning_end历史故障筛选并更改数据库故障结束时间
+                    df_fault_ram_sn['end_time']=end_time
+                    df_fault_ram_sn['Batpos']=1
+                    try:
+                        cursor.execute('''
+                                update all_fault_info set update_time='{}',end_time='{}', Batpos={} where product_id='{}' and code={} and end_time='0000-00-00 00:00:00' and factory='骑享'
+                                '''.format(datetime.datetime.now(), df_fault_ram_sn.loc[0,'end_time'], df_fault_ram_sn.loc[0,'Batpos'],sn, 110))
+                        conn.commit()
+                    except:
+                        logger.error(traceback.format_exc)
+                        logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)
         except:
             logger.error(traceback.format_exc)
             logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)
@@ -251,9 +246,10 @@ if __name__ == "__main__":
     df_warning_ram=pd.DataFrame(columns=['sn','time','deltsoc','cellsoc'])
     df_warning_ram1=pd.DataFrame(columns=['sn','time1','deltsoc1'])
     df_warning_ram2=pd.DataFrame(columns=['sn','time2','deltAs2'])
-    df_warning_ram3=pd.DataFrame(columns=['sn','standingtime','standingtime1'])
+    df_warning_ram3=pd.DataFrame(columns=['sn','time3','standingtime','standingtime1'])
     df_lfp_ram=pd.DataFrame()
-    
+    # now_time='2021-10-15 00:00:00'
+    # now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
     saftywarning_cal()
     #定时任务.......................................................................................................................................................................
     scheduler = BlockingScheduler()

+ 58 - 53
LIB/FRONTEND/SaftyCenter/status_sta/deploy.py

@@ -22,47 +22,6 @@ from LIB.BACKEND import DBManager
 
 if __name__ == "__main__":
     
-    # 时间设置
-
-    now_time = datetime.datetime.now()
-    pre_time = now_time + dateutil.relativedelta.relativedelta(hours=-1)#上小时时间
-    end_time=datetime.datetime.strftime(now_time,"%Y-%m-%d %H:00:00")
-    start_time=datetime.datetime.strftime(pre_time,"%Y-%m-%d %H:00:00")
-    
-    history_run_flag = False # 历史数据运行标志
-    
-
-    # 更新sn列表
-    host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
-    port=3306
-    db='qixiang_oss'
-    user='qixiang_oss'
-    password='Qixiang2021'
-    conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
-    cursor = conn.cursor()
-    cursor.execute("select sn, imei, add_time from app_device")
-    res = cursor.fetchall()
-    df_sn = pd.DataFrame(res, columns=['sn', 'imei', 'add_time'])
-    df_sn = df_sn.reset_index(drop=True)
-    conn.close();
-    
-    # 数据库配置
-    host = 'rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
-    port = 3306
-    user = 'qx_cas'
-    password = parse.quote_plus('Qx@123456')
-    database = 'qx_cas'
-
-    db_engine = create_engine(
-        "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
-            user, password, host, port, database
-        ))
-    DbSession = sessionmaker(bind=db_engine)
-    
-    # 运行历史数据配置
-    
-    df_first_data_time = pd.read_sql("select * from bat_first_data_time", db_engine)
-
     
     # 日志配置
     now_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).replace(":","_")
@@ -75,18 +34,64 @@ if __name__ == "__main__":
     logger = log.get_logger()
 
     logger.info("pid is {}".format(os.getpid()))
-    
-    
-    # 算法参数
-    host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
-    port=3306
-    db='safety_platform'
-    user='qx_read'
-    password=parse.quote_plus('Qx@123456')
-    db_res_engine = create_engine(
-        "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
-            user, password, host, port, db
-        ))
+    try:
+        # 时间设置
+
+        now_time = datetime.datetime.now()
+        pre_time = now_time + dateutil.relativedelta.relativedelta(hours=-1)#上小时时间
+        end_time=datetime.datetime.strftime(now_time,"%Y-%m-%d %H:00:00")
+        start_time=datetime.datetime.strftime(pre_time,"%Y-%m-%d %H:00:00")
+        
+        history_run_flag = False # 历史数据运行标志
+        
+
+        # 更新sn列表
+        host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
+        port=3306
+        db='qixiang_oss'
+        user='qixiang_oss'
+        password='Qixiang2021'
+        conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
+        cursor = conn.cursor()
+        cursor.execute("select sn, imei, add_time from app_device")
+        res = cursor.fetchall()
+        df_sn = pd.DataFrame(res, columns=['sn', 'imei', 'add_time'])
+        df_sn = df_sn.reset_index(drop=True)
+        conn.close();
+        
+        # 数据库配置
+        host = 'rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
+        port = 3306
+        user = 'qx_cas'
+        password = parse.quote_plus('Qx@123456')
+        database = 'qx_cas'
+
+        db_engine = create_engine(
+            "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
+                user, password, host, port, database
+            ))
+        DbSession = sessionmaker(bind=db_engine)
+        
+        # 运行历史数据配置
+        
+        df_first_data_time = pd.read_sql("select * from bat_first_data_time", db_engine)
+
+        
+
+        
+        
+        # 算法参数
+        host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
+        port=3306
+        db='safety_platform'
+        user='qx_read'
+        password=parse.quote_plus('Qx@123456')
+        db_res_engine = create_engine(
+            "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
+                user, password, host, port, db
+            ))
+    except Exception as e:
+        logger.error("任务初始出错" + str(e), exc_info=True)
     
     dbManager = DBManager.DBManager()
     charge_count = 0