su-lmstack 3 years ago
parent
commit
e136828aa2
2 changed files with 8 additions and 5 deletions
  1. 2 2
      LIB/FRONTEND/SignalMonitor/create_table.py
  2. 6 3
      LIB/FRONTEND/SignalMonitor/main.py

+ 2 - 2
LIB/FRONTEND/SignalMonitor/create_table.py

@@ -5,7 +5,7 @@ __author__ = 'Wang Liming'
 
 from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy import Column, String, create_engine, Integer, DateTime, BigInteger, FLOAT
-
+from urllib import parse
 Base = declarative_base()
 
 
@@ -92,7 +92,7 @@ if __name__ == "__main__":
     host = 'rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
     port = 3306
     user = 'qx_cas'
-    password = 'Qx@123456'
+    password = parse.quote_plus('Qx@123456')
     database = 'qx_cas'
 
     db_engine = create_engine(

+ 6 - 3
LIB/FRONTEND/SignalMonitor/main.py

@@ -53,7 +53,12 @@ if __name__ == "__main__":
                 continue
             st = df_sn.loc[i, 'StartTime']
             if df_sn.loc[i, 'Service'] == 0:
-                et = df_sn.loc[i, 'ExitTime']
+                if pd.isnull(df_sn.loc[i, 'EndTime']) and pd.isnull(df_sn.loc[i, 'ExitTime']):
+                    continue
+                elif pd.isnull(df_sn.loc[i, 'ExitTime']):
+                    et = df_sn.loc[i, 'EndTime']
+                else:
+                    et = df_sn.loc[i, 'ExitTime']
             elif pd.isnull(df_sn.loc[i, 'EndTime']):
                 otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
                 et = pd.to_datetime(otherStyleTime)
@@ -87,12 +92,10 @@ if __name__ == "__main__":
                 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)
-                print(df_tosql)
 
                 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)
-                print(df_tosql)
 
             logger.info("{} {} Success!".format(sn, str(st)))
     except Exception as e: