Kaynağa Gözat

更新 信号监控

su-lmstack 3 yıl önce
ebeveyn
işleme
59be5c1ce8

+ 1 - 0
.gitignore

@@ -16,3 +16,4 @@
 # *.*
 /CONFIGURE/PathSetting.py
 *.log
+/demo.ipynb

+ 3 - 1
LIB/BACKEND/DBManager.py

@@ -221,9 +221,11 @@ class DBManager():
                 try:
                     data_blocks = np.concatenate((data_blocks,data_block),axis=0)
                 except Exception as e: 
-                    if 'all the input array dimensions except for the concatenation axis must match exactly' in str(e):
+                    if 'all the input array dimensions for the concatenation axis must match exactly' in str(e) or \
+                    'all the input array dimensions except for the concatenation axis must match exactly'  in str(e):
                         pass
                     else:
+                        pdb.set_trace()
                         raise e
   
                 # print('\r'+str(i),end=" ")

+ 12 - 4
LIB/FRONTEND/SignalMonitor/create_table.py

@@ -4,7 +4,7 @@
 __author__ = 'Wang Liming'
 
 from sqlalchemy.ext.declarative import declarative_base
-from sqlalchemy import Column, String, create_engine, Integer, DateTime, BigInteger, FLOAT
+from sqlalchemy import Column, String, create_engine, Integer, DateTime, BigInteger, FLOAT, TIMESTAMP, func
 from urllib import parse
 Base = declarative_base()
 
@@ -14,6 +14,8 @@ class BmsLastDataDay(Base):
     __table_args__ = ({'comment': '电池信号监控---每天最后一条bms数据'})  # 添加索引和表注释
 
     id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
+    add_time = Column(TIMESTAMP(True), server_default=func.now()) # 创建时间
+    update_time = Column(TIMESTAMP(True), nullable=False, server_default=func.now(), onupdate=func.now()) # 更新时间
     sn = Column(String(64), comment="sn")
     current = Column(FLOAT, comment="电流")
     time_stamp = Column(DateTime, comment="时间戳")
@@ -33,6 +35,8 @@ class GpsLastDataDay(Base):
     __table_args__ = ({'comment': '电池信号监控---每天最后一条gps数据'})  # 添加索引和表注释
 
     id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
+    add_time = Column(TIMESTAMP(True), server_default=func.now()) # 创建时间
+    update_time = Column(TIMESTAMP(True), nullable=False, server_default=func.now(), onupdate=func.now()) # 更新时间
     sn = Column(String(64), comment="sn")
     time_stamp = Column(DateTime, comment="时间戳")
     pack_state = Column(Integer, comment="电池状态")
@@ -50,10 +54,12 @@ class GpsSignalMonitor(Base):
     __table_args__ = ({'comment': 'gps信号监控'})  # 添加索引和表注释
 
     id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
+    add_time = Column(TIMESTAMP(True), server_default=func.now()) # 创建时间
+    update_time = Column(TIMESTAMP(True), nullable=False, server_default=func.now(), onupdate=func.now()) # 更新时间
     sn = Column(String(64), comment="sn")
     start_time = Column(DateTime, comment="开始时间")
     end_time = Column(DateTime, comment="结束时间")
-    offline_time = Column(DateTime, comment="离线时间")
+    offline_time = Column(Integer, comment="离线时间")
     pack_state = Column(Integer, comment="电池状态")
     line_state = Column(Integer, comment="信号状态")
 
@@ -71,10 +77,12 @@ class BmsSignalMonitor(Base):
     __table_args__ = ({'comment': 'bms信号监控'})  # 添加索引和表注释
 
     id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
+    add_time = Column(TIMESTAMP(True), server_default=func.now()) # 创建时间
+    update_time = Column(TIMESTAMP(True), nullable=False, server_default=func.now(), onupdate=func.now()) # 更新时间
     sn = Column(String(64), comment="sn")
     start_time = Column(DateTime, comment="开始时间")
     end_time = Column(DateTime, comment="结束时间")
-    offline_time = Column(DateTime, comment="离线时间")
+    offline_time = Column(Integer, comment="离线时间")
     pack_state = Column(Integer, comment="电池状态")
     line_state = Column(Integer, comment="信号状态")
 
@@ -94,7 +102,7 @@ if __name__ == "__main__":
     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

+ 8 - 8
LIB/FRONTEND/SignalMonitor/main.py

@@ -36,7 +36,7 @@ if __name__ == "__main__":
         log.set_file_hl(file_name='error.log', log_level='error')
         logger = log.get_logger()
 
-        logger.info("pid is + {}".format(os.getpid))
+        logger.info("pid is + {}".format(os.getpid()))
 
         # 读取sn列表
         df_sn = pd.read_csv('sn_list.csv')
@@ -88,14 +88,14 @@ if __name__ == "__main__":
                 df_tosql.loc[df_res.index[-1:]].to_sql("bms_signal_monitor",con=db_engine, if_exists="append",index=False)
                 st = st + datetime.timedelta(hours=cal_period)
 
-            # 数据入库
-                df_tosql = df_last_state.copy()
-                df_tosql.columns = ['sn', 'current', 'time_stamp', 'pack_state', 'line_state']
-                df_tosql.to_sql("bms_last_data_day",con=db_engine, if_exists="append",index=False)
+        # 数据入库
+            df_tosql = df_last_state.copy()
+            df_tosql.columns = ['sn', 'current', 'time_stamp', 'pack_state', 'line_state']
+            df_tosql.to_sql("bms_last_data_day",con=db_engine, if_exists="append",index=False)
 
-                df_tosql = df_last_state_gps.copy()
-                df_tosql.columns = ['sn', 'time_stamp', 'pack_state', 'line_state']
-                df_tosql.to_sql("gps_last_data_day",con=db_engine, if_exists="append",index=False)
+            df_tosql = df_last_state_gps.copy()
+            df_tosql.columns = ['sn', 'time_stamp', 'pack_state', 'line_state']
+            df_tosql.to_sql("gps_last_data_day",con=db_engine, if_exists="append",index=False)
 
             logger.info("{} {} Success!".format(sn, str(st)))
     except Exception as e: