lmstack 3 years ago
parent
commit
99e2baa51d

+ 47 - 0
LIB/FRONTEND/CellStateEstimation/InterShort/create_table.py

@@ -0,0 +1,47 @@
+'''
+定义表的结构,并在数据库中创建对应的数据表
+'''
+__author__ = 'lmstack'
+
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy import Column, String, create_engine, Integer, DateTime, BigInteger, FLOAT, TIMESTAMP, func, Text
+from urllib import parse
+Base = declarative_base()
+
+
+class ConsistencyDeltaSoc(Base):
+    __tablename__ = "cellStateEstimation_interShort"
+    __table_args__ = ({'comment': '内短路电流'})  # 添加索引和表注释
+
+    id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
+    add_time = Column(TIMESTAMP(True), server_default=func.now(), comment='记录创建时间') # 创建时间
+    update_time = Column(TIMESTAMP(True), nullable=False, server_default=func.now(), onupdate=func.now(), comment='记录更新时间') # 更新时间
+    time_st = Column(TIMESTAMP(True), comment="开始时间")
+    time_sp = Column(TIMESTAMP(True), comment="结束时间")
+    sn = Column(String(64), comment="sn")
+
+    method = Column(Integer, comment="计算方法")
+    short_current = Column(Text, comment="内短路电流/mA")
+    baltime = Column(Text, comment="均衡时间/s")
+
+
+    # def __init__(self, sn, current, time_stamp, pack_state, line_state):
+    #     self.sn = sn
+    #     self.current = current
+    #     self.time_stamp = time_stamp
+    #     self.pack_state = pack_state
+    #     self.line_state = line_state
+
+# 执行该文件,创建表格到对应的数据库中
+if __name__ == "__main__":
+    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
+        ))
+    Base.metadata.create_all(db_engine)

+ 134 - 0
LIB/FRONTEND/CellStateEstimation/InterShort/deploy.py

@@ -0,0 +1,134 @@
+
+__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.InterShort.V1_0_0 import CBMSBatInterShort
+from LIB.MIDDLE.CellStateEstimation.Common import DBDownload
+from urllib import parse
+import pymysql
+import pdb
+dbManager = DBManager.DBManager()
+if __name__ == "__main__":
+    
+    # 时间设置
+    now_time = datetime.datetime.now()
+    pre_time = now_time + dateutil.relativedelta.relativedelta(days=-8)#上个月时间
+    end_time=datetime.datetime.strftime(now_time,"%Y-%m-%d 00:00:00")
+    start_time=datetime.datetime.strftime(pre_time,"%Y-%m-%d 12: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(":","_")
+    log_path = 'log/' + now_str
+    if not os.path.exists(log_path):
+        os.makedirs(log_path)
+    log = Log.Mylog(log_name='uniform', 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()))
+    
+
+
+    # 算法参数
+    host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
+    port=3306
+    db='qx_cas'
+    user='qx_read'
+    password='Qx@123456'
+    tablename='cellStateEstimation_soh'
+
+    for i in range(0, len(df_sn)):
+        try:
+            if df_sn.loc[i, 'imei'][5:9] == 'N640':
+                celltype=1 #6040三元电芯
+            elif df_sn.loc[i, 'imei'][5:9] == 'N440':
+                celltype=2 #4840三元电芯
+            elif df_sn.loc[i, 'imei'][5:9] == 'L660':
+                celltype=99 # 6060锂电芯
+            elif df_sn.loc[i, 'imei'][3:5] == 'LX' and df_sn.loc[i, 'imei'][5:9] == 'N750':    
+                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三元电芯
+            else:
+                logger.info("pid-{} celltype-{} SN: {} SKIP!".format(os.getpid(), "未知", sn))
+                continue
+            sn = df_sn.loc[i, 'sn']
+            
+            logger.info("pid-{} celltype-{} SN: {} START!".format(os.getpid(), celltype, sn))
+            
+            DBRead=DBDownload.DBDownload(host, port, db, user, password)
+            with DBRead as DBRead:
+                df_soh=DBRead.getdata('time_st','time_sp','sn','method','soh','cellsoh', tablename=tablename, sn=sn)
+            dbManager = DBManager.DBManager()
+            
+            # 处理运行历史数据
+            if (history_run_flag):
+                this_sn = df_first_data_time[df_first_data_time['sn']==sn]
+                if (len(this_sn) == 0):
+                    start_time = pd.to_datetime(str(df_sn.loc[df_sn[df_sn['sn']==sn].index, 'add_time'].values[0])).strftime("%Y-%m-%d 00:00:00")
+                else:
+                    first_data_time = df_first_data_time.loc[df_first_data_time[df_first_data_time['sn']==sn].index, 'first_data_time'].values[0]
+                    if pd.isnull(first_data_time):
+                        start_time = "2018-01-01 00:00:00"
+                    else:
+                        start_time = pd.to_datetime(str(df_first_data_time.loc[df_first_data_time[df_first_data_time['sn']==sn].index, 'first_data_time'].values[0])).strftime("%Y-%m-%d 00:00:00")
+
+            df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
+            df_bms = df_data['bms']
+
+            
+            BatInterShort=CBMSBatInterShort.BatInterShort(sn, celltype, df_bms, df_soh)
+            df_res=BatInterShort.intershort()
+
+            if not df_res.empty:
+                df_res.columns = ['time_st', 'time_sp', 'sn', 'method', 'short_current', 'baltime']
+                df_res.to_sql("cellStateEstimation_interShort",con=db_engine, if_exists="append",index=False)
+            logger.info("pid-{} celltype-{} SN: {} DONE!".format(os.getpid(), celltype, sn))
+        except:
+            logger.error(traceback.format_exc)
+            logger.error(u"{} :{},{} 任务运行错误\n".format(sn,start_time,end_time), exc_info=True)
+

+ 80 - 0
LIB/FRONTEND/CellStateEstimation/InterShort/main.py

@@ -0,0 +1,80 @@
+import CBMSBatInterShort
+import log
+
+#coding=utf-8
+import sys
+import datetime
+import pandas as pd
+from LIB.BACKEND import DBManager, Log
+from sqlalchemy import create_engine
+import time, datetime
+
+host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
+port=3306
+db='qx_cas'
+user='qx_read'
+password='Qx@123456'
+tablename='soh_result'
+
+dbManager = DBManager.DBManager()
+if __name__ == "__main__":
+    excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\sn-20210903.xlsx'
+    SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
+    SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
+    SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
+    SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
+    SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
+    SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
+    SNnums_6060=SNdata_6060['SN号'].tolist()
+    SNnums_6040=SNdata_6040['SN号'].tolist()
+    SNnums_4840=SNdata_4840['SN号'].tolist()
+    SNnums_L7255=SNdata_L7255['SN号'].tolist()
+    SNnums_C7255=SNdata_C7255['SN号'].tolist()
+    SNnums_U7255=SNdata_U7255['SN号'].tolist()
+    SNnums= SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_6060 + SNnums_U7255
+    
+    now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+    now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
+    start_time=now_time-datetime.timedelta(days=30)
+    end_time=str(now_time)
+    start_time=str(start_time)
+
+    #log信息配置
+    mylog=log.Mylog('log.txt','error')
+    mylog.logcfg()
+
+    for sn in SNnums:
+        try:
+            if 'PK500' in sn:
+                celltype=1 #6040三元电芯
+            elif 'PK502' in sn:
+                celltype=2 #4840三元电芯
+            elif 'K504B' in sn:
+                celltype=99    #60ah林磷酸铁锂电芯
+            elif 'MGMLXN750' in sn:
+                celltype=3 #力信50ah三元电芯
+            elif 'MGMCLN750' or 'UD' in sn: 
+                celltype=4 #CATL 50ah三元电芯
+            else:
+                print('SN:{},未找到对应电池类型!!!'.format(sn))
+                continue
+                # sys.exit()
+            
+            # sn='MGMCLN750N215H001'
+            # celltype=2
+            start_time='2021-08-02 09:12:26'
+            end_time='2021-09-03 19:12:26'
+
+            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.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\99Result\\''BMS_'+sn+'.csv',encoding='GB18030')
+            
+            BatInterShort=CBMSBatInterShort.BatInterShort(sn,celltype,df_bms,host, port, db, user, password, tablename)
+            df_res=BatInterShort.intershort()
+            df_res.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\99Result\\'+'CBMS_Short_'+sn+'_1.csv',encoding='GB18030')
+        
+        except Exception as e:
+            print(repr(e))
+            mylog.logopt(sn,e)
+            pass

+ 3 - 0
LIB/FRONTEND/CellStateEstimation/InterShort/run.bat

@@ -0,0 +1,3 @@
+cd /d D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\CellStateEstimation\InterShort
+title cal_intershort
+D:\env\py_pro\python.exe D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\CellStateEstimation\InterShort\deploy.py

+ 1 - 1
LIB/FRONTEND/CellStateEstimation/SOH/create_table.py

@@ -10,7 +10,7 @@ Base = declarative_base()
 
 
 class ConsistencyDeltaSoc(Base):
-    __tablename__ = "soh_result"
+    __tablename__ = "cellStateEstimation_soh"
     __table_args__ = ({'comment': 'soh 计算结果'})  # 添加索引和表注释
 
     id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")

+ 30 - 7
LIB/FRONTEND/CellStateEstimation/SOH/deploy.py

@@ -11,6 +11,7 @@ import time, datetime
 import dateutil.relativedelta
 import traceback
 from LIB.MIDDLE.CellStateEstimation.SOH.V1_0_0 import CBMSBatSoh
+from LIB.MIDDLE.CellStateEstimation.Common import DBDownload
 from urllib import parse
 import pymysql
 import pdb
@@ -19,13 +20,12 @@ if __name__ == "__main__":
     
     # 时间设置
     now_time = datetime.datetime.now()
-    pre_time = now_time + dateutil.relativedelta.relativedelta(years=-3)#上个月时间
+    pre_time = now_time + dateutil.relativedelta.relativedelta(months=-1, days=-1)#上个月-1天时间
     end_time=datetime.datetime.strftime(now_time,"%Y-%m-%d 00:00:00")
     start_time=datetime.datetime.strftime(pre_time,"%Y-%m-%d 00:00:00")
     
-    # end_time="2021-08-02 01:00:00"
-    # start_time="2019-01-01 00:00:00"
-    
+    history_run_flag = False # 历史数据运行标志
+    # end_time = "2021-09-01 00:00:00"
 
     # 更新sn列表
     host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'
@@ -54,6 +54,11 @@ if __name__ == "__main__":
         ))
     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(":","_")
     log_path = 'log/' + now_str
@@ -74,7 +79,7 @@ if __name__ == "__main__":
     db='qx_cas'
     user='qx_read'
     password='Qx@123456'
-    tablename='soh_result'
+    tablename='cellStateEstimation_soh'
 
     for i in range(0, len(df_sn)):
         try:
@@ -95,16 +100,34 @@ if __name__ == "__main__":
             
             logger.info("pid-{} celltype-{} SN: {} START!".format(os.getpid(), celltype, sn))
             dbManager = DBManager.DBManager()
+            
+            
+            # 处理运行历史数据
+            if (history_run_flag):
+                this_sn = df_first_data_time[df_first_data_time['sn']==sn]
+                if (len(this_sn) == 0):
+                    start_time = pd.to_datetime(str(df_sn.loc[df_sn[df_sn['sn']==sn].index, 'add_time'].values[0])).strftime("%Y-%m-%d 00:00:00")
+                else:
+                    first_data_time = df_first_data_time.loc[df_first_data_time[df_first_data_time['sn']==sn].index, 'first_data_time'].values[0]
+                    if pd.isnull(first_data_time):
+                        start_time = "2018-01-01 00:00:00"
+                    else:
+                        start_time = pd.to_datetime(str(df_first_data_time.loc[df_first_data_time[df_first_data_time['sn']==sn].index, 'first_data_time'].values[0])).strftime("%Y-%m-%d 00:00:00")
+            
+            DBRead=DBDownload.DBDownload(host, port, db, user, password)
+            with DBRead as DBRead:
+                df_soh=DBRead.getdata('time_st','time_sp','sn','method','soh','cellsoh', tablename=tablename, sn=sn)
+                
             df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms','accum'])
             df_bms = df_data['bms']
             df_accum=df_data['accum']
 
-            BatSoh=CBMSBatSoh.BatSoh(sn,celltype,df_bms,df_accum,host, port, db, user, password, tablename)
+            BatSoh=CBMSBatSoh.BatSoh(sn, celltype, df_bms, df_accum, df_soh)
             df_res=BatSoh.batsoh()
 
             if not df_res.empty:
                 df_res.columns = ['time_st', 'time_sp', 'sn', 'method', 'soh', 'cellsoh']
-                df_res.to_sql("soh_result",con=db_engine, if_exists="append",index=False)
+                df_res.to_sql("cellStateEstimation_soh",con=db_engine, if_exists="append",index=False)
             logger.info("pid-{} celltype-{} SN: {} DONE!".format(os.getpid(), celltype, sn))
         except:
             logger.error(traceback.format_exc)

+ 43 - 29
LIB/FRONTEND/CellStateEstimation/SOH/main.py

@@ -1,38 +1,30 @@
 import CBMSBatSoh
 import log
 #coding=utf-8
-import os
-import sys
 import datetime
 import pandas as pd
 from LIB.BACKEND import DBManager, Log
-# from LIB.MIDDLE import SignalMonitor
 from sqlalchemy import create_engine
-from sqlalchemy.orm import sessionmaker
 import time, datetime
-from LIB.MIDDLE.soh import NCMSoh_20210716 as NCMSoh
-from LIB.MIDDLE.soh import LFPSoh_20210711 as LFPSoh
-from urllib import parse
-
-host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
-port=3306
-db='qx_cas'
-user='qx_read'
-password='Qx@123456'
-tablename='soh_result'
+from LIB.MIDDLE.CellStateEstimation.Common import DBDownload
 
 dbManager = DBManager.DBManager()
 if __name__ == "__main__":
-    SNdata_6040 = pd.read_excel('骑享资产梳理-20210621.xlsx', sheet_name='6040骑享')
-    SNdata_6060 = pd.read_excel('骑享资产梳理-20210621.xlsx', sheet_name='6060')
-    SNdata_4840 = pd.read_excel('骑享资产梳理-20210621.xlsx', sheet_name='4840骑享')
-    SNdata_7250 = pd.read_excel('骑享资产梳理-20210621.xlsx', sheet_name='7250')
-    SNnums_6060=SNdata_6060['SN号']
-    SNnums_6040=SNdata_6040['SN号']
-    SNnums_4840=SNdata_4840['SN号']
-    SNnums_7250=SNdata_7250['SN号']
+    excelpath=r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\sn-20210903.xlsx'
+    SNdata_6060 = pd.read_excel(excelpath, sheet_name='科易6060')
+    SNdata_6040 = pd.read_excel(excelpath, sheet_name='科易6040')
+    SNdata_4840 = pd.read_excel(excelpath, sheet_name='科易4840')
+    SNdata_L7255 = pd.read_excel(excelpath, sheet_name='格林美-力信7255')
+    SNdata_C7255 = pd.read_excel(excelpath, sheet_name='格林美-CATL7255')
+    SNdata_U7255 = pd.read_excel(excelpath, sheet_name='优旦7255')
+    SNnums_6060=SNdata_6060['SN号'].tolist()
+    SNnums_6040=SNdata_6040['SN号'].tolist()
+    SNnums_4840=SNdata_4840['SN号'].tolist()
+    SNnums_L7255=SNdata_L7255['SN号'].tolist()
+    SNnums_C7255=SNdata_C7255['SN号'].tolist()
+    SNnums_U7255=SNdata_U7255['SN号'].tolist()
+    SNnums= SNnums_6060 + SNnums_L7255 + SNnums_C7255 + SNnums_6040 + SNnums_4840 + SNnums_U7255
 
-    SNnums=SNnums_6040.tolist()+SNnums_6060.tolist()+SNnums_4840.tolist()
     now_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
     now_time=datetime.datetime.strptime(now_time,'%Y-%m-%d %H:%M:%S')
     start_time=now_time-datetime.timedelta(days=30)
@@ -56,18 +48,40 @@ if __name__ == "__main__":
             elif 'MGMCLN750' in sn: 
                 celltype=4 #CATL 50ah三元电芯
             else:
-                print('未找到对应电池编号!!!')
-                sys.exit()
+                print('未找到对应电池编号!!!\n',sn)
+                # sys.exit()
+            
+            sn='PK504B10100004353'
+            celltype=99
+            start_time='2021-04-01 19:12:26'
+            end_time='2021-06-02 19:12:26'
+            # df_bms= pd.read_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\98Download\\'+'BMS_'+sn+'.csv',encoding='GB18030')
+            # df_accum= pd.read_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\98Download\\'+'BMS_accum_'+sn+'.csv',encoding='GB18030')
+            
+            #..........................................................................读取原始数据库数据...........................................................................
             dbManager = DBManager.DBManager()
             df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms','accum'])
             df_bms = df_data['bms']
             df_accum=df_data['accum']
-            # df_bms.to_csv('BMS_'+sn+'.csv')
-            # df_accum.to_csv('BMS_accum_'+sn+'.csv')
+            # df_bms.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\98Download\\'+'BMS_'+sn+'.csv',encoding='GB18030')
+            # df_accum.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\98Download\\'+'BMS_accum_'+sn+'.csv',encoding='GB18030')
+
+            #..........................................................................读取结果数据库数据.........................................................................
+            host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
+            port=3306
+            db='qx_cas'
+            user='qx_read'
+            password='Qx@123456'
+            tablename='cellstateestimation_soh'
+            DBRead=DBDownload.DBDownload(host, port, db, user, password)
+            with DBRead as DBRead:
+                df_soh=DBRead.getdata('time_st','time_sp','sn','method','soh','cellsoh', tablename=tablename, sn=sn)
 
-            BatSoh=CBMSBatSoh.BatSoh(sn,celltype,df_bms,df_accum,host, port, db, user, password, tablename)
+            #..............................................................................计算soh...................................................................................
+            BatSoh=CBMSBatSoh.BatSoh(sn,celltype,df_bms,df_accum,df_soh)
             df_res=BatSoh.batsoh()
-            df_res.to_csv('BMS_SOH_'+sn+'.csv',encoding='GB18030')
+            df_res.to_csv(r'D:\Platform\platform_python\data_analyze_platform\USER\01qixiang\99Result\\'+'CBMS_SOH'+sn+'_1.csv',encoding='GB18030')
+            # print('done!!!')
              
         except IndexError as e:
             print(repr(e))

+ 1 - 2
LIB/FRONTEND/CellStateEstimation/SOH/run.bat

@@ -1,4 +1,3 @@
 cd /d D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\CellStateEstimation\SOH
 title cal_soh
-D:\env\py_pro\python.exe D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\CellStateEstimation\SOH\deploy.py
-pause
+D:\env\py_pro\python.exe D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\CellStateEstimation\SOH\deploy.py

+ 2 - 2
LIB/FRONTEND/CellStateEstimation/Uniform/create_table.py

@@ -10,8 +10,8 @@ Base = declarative_base()
 
 
 class ConsistencyDeltaSoc(Base):
-    __tablename__ = "consistency_delta_soc"
-    __table_args__ = ({'comment': 'delta_soc 计算结果'})  # 添加索引和表注释
+    __tablename__ = "cellStateEstimation_uniform_socVoltDiff"
+    __table_args__ = ({'comment': '一致性 计算结果'})  # 添加索引和表注释
 
     id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
     add_time = Column(TIMESTAMP(True), server_default=func.now(), comment='记录创建时间') # 创建时间

+ 23 - 6
LIB/FRONTEND/CellStateEstimation/Uniform/deploy.py

@@ -13,17 +13,17 @@ import traceback
 from LIB.MIDDLE.CellStateEstimation.Uniform.V1_0_0 import CBMSBatUniform
 from urllib import parse
 import pymysql
+import pdb
 dbManager = DBManager.DBManager()
 if __name__ == "__main__":
     
     # 时间设置
     now_time = datetime.datetime.now()
-    pre_time = now_time + dateutil.relativedelta.relativedelta(days=-4)#上个月时间
+    pre_time = now_time + dateutil.relativedelta.relativedelta(days=-6)#6天前时间
     end_time=datetime.datetime.strftime(now_time,"%Y-%m-%d 00:00:00")
     start_time=datetime.datetime.strftime(pre_time,"%Y-%m-%d 12:00:00")
     
-    # end_time="2021-08-02 01:00:00"
-    # start_time="2019-01-01 00:00:00"
+    history_run_flag = False # 历史数据运行标志
     
 
     # 更新sn列表
@@ -34,9 +34,9 @@ if __name__ == "__main__":
     password='Qixiang2021'
     conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
     cursor = conn.cursor()
-    cursor.execute("select sn, imei from app_device")
+    cursor.execute("select sn, imei, add_time from app_device")
     res = cursor.fetchall()
-    df_sn = pd.DataFrame(res, columns=['sn', 'imei'])
+    df_sn = pd.DataFrame(res, columns=['sn', 'imei', 'add_time'])
     df_sn = df_sn.reset_index(drop=True)
     conn.close();
     
@@ -52,6 +52,10 @@ if __name__ == "__main__":
             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)
 
     
     # 日志配置
@@ -96,6 +100,19 @@ if __name__ == "__main__":
             logger.info("pid-{} celltype-{} SN: {} START!".format(os.getpid(), celltype, sn))
             
             dbManager = DBManager.DBManager()
+            
+            # 处理运行历史数据
+            if (history_run_flag):
+                this_sn = df_first_data_time[df_first_data_time['sn']==sn]
+                if (len(this_sn) == 0):
+                    start_time = pd.to_datetime(str(df_sn.loc[df_sn[df_sn['sn']==sn].index, 'add_time'].values[0])).strftime("%Y-%m-%d 00:00:00")
+                else:
+                    first_data_time = df_first_data_time.loc[df_first_data_time[df_first_data_time['sn']==sn].index, 'first_data_time'].values[0]
+                    if pd.isnull(first_data_time):
+                        start_time = "2018-01-01 00:00:00"
+                    else:
+                        start_time = pd.to_datetime(str(df_first_data_time.loc[df_first_data_time[df_first_data_time['sn']==sn].index, 'first_data_time'].values[0])).strftime("%Y-%m-%d 00:00:00")
+
             df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms'])
             df_bms = df_data['bms']
 
@@ -104,7 +121,7 @@ if __name__ == "__main__":
 
             if not df_res.empty:
                 df_res.columns = ['time', 'sn', 'cellsoc_diff', 'cellvolt_diff', 'cellmin_num', 'cellmax_num']
-                df_res.to_sql("consistency_delta_soc",con=db_engine, if_exists="append",index=False)
+                df_res.to_sql("cellStateEstimation_uniform_socVoltDiff",con=db_engine, if_exists="append",index=False)
             logger.info("pid-{} celltype-{} SN: {} DONE!".format(os.getpid(), celltype, sn))
         except:
             logger.error(traceback.format_exc)

+ 2 - 3
LIB/FRONTEND/CellStateEstimation/Uniform/run.bat

@@ -1,4 +1,3 @@
-cd /d D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\CellStateEstimation\Uniform
-CHCP 65001
-title 一致性计算
+cd /d D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\CellStateEstimation\Uniform
+title cal_uniform
 D:\env\py_pro\python.exe D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\CellStateEstimation\Uniform\deploy.py

+ 68 - 0
LIB/FRONTEND/other/oss_to_iotp/deploy.py

@@ -0,0 +1,68 @@
+#coding=utf-8
+import pymysql
+import pandas as pd
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+import time, datetime
+import dateutil.relativedelta
+import os
+import traceback
+from LIB.BACKEND import Log
+
+if __name__ == "__main__":
+    
+    # 时间设置
+    now_time = datetime.datetime.now()
+    pre_time = now_time + dateutil.relativedelta.relativedelta(days=-1)
+    end_time=datetime.datetime.strftime(now_time,"%Y-%m-%d 00:00:00")
+    start_time=datetime.datetime.strftime(pre_time,"%Y-%m-%d 00:00:00")
+     
+    # 结果数据库配置
+    host = '172.16.121.236'
+    port = 3306
+    user = 'root'
+    password = 'FastFun1234,'
+    database = 'fastfun'
+
+    db_engine = create_engine(
+        "mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8".format(
+            user, password, host, port, database
+        ))
+    DbSession = sessionmaker(bind=db_engine)
+
+    # 日志配置
+    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='oss_to_iotp', 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:
+        logger.info("pid-{} --{} START!".format(os.getpid(), str(start_time)))
+        host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
+        port=3306
+        db='qixiang_oss'
+        user='qx_read'
+        password='Qx@123456'
+        conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
+        cursor = conn.cursor()
+        cursor.execute("select * from (select distinct(t.sn) from (select * from app_device where status = 3)t inner join (select * from app_device_log where type=3 and out_type=1) t2 on t.sn=t2.sn)t3")
+        res = cursor.fetchall()
+        df_res = pd.DataFrame(res, columns=['sn'])
+        df_res = df_res.reset_index(drop=True)
+    
+        df_res.to_sql("operation_sn",con=db_engine, if_exists="replace",index=False)
+        logger.info("{}DONE!".format(str(start_time)))
+
+    except Exception as e:
+        logger.error(traceback.format_exc)
+        logger.error(u" 任务运行错误", exc_info=True)
+
+
+    

+ 1 - 0
LIB/FRONTEND/other/oss_to_iotp/readme.md

@@ -0,0 +1 @@
+从oss拉取投入运营的sn列表,写入iotp数据库

+ 2 - 0
LIB/FRONTEND/other/oss_to_iotp/run.bat

@@ -0,0 +1,2 @@
+cd /d D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\other\oss_to_iotp
+D:\env\py_pro\python.exe D:\deploy\python_platform\data_analyze_platform\LIB\FRONTEND\other\oss_to_iotp\deploy.py