zhuxi 2 anos atrás
pai
commit
f5e9b82c20
1 arquivos alterados com 4 adições e 1 exclusões
  1. 4 1
      LIB/MIDDLE/InfoChrgDrive/Charge/main_V0.py

+ 4 - 1
LIB/MIDDLE/InfoChrgDrive/Charge/main_V0.py

@@ -72,7 +72,10 @@ def diag_cal():
                     df_diag_ram_sn=df_diag_ram[df_diag_ram['sn']==sn]
                     if not df_diag_ram_sn.empty:   #该sn相关结果非空
                         df_diag_ram_sn.reset_index(inplace=True,drop=True)
+                        df_diag_ram_sn['time_end']=list(map(lambda x: datetime.datetime.strptime(x,'%Y-%m-%d %H:%M:%S'),list(df_diag_ram_sn['time_end'])))
+                        df_diag_ram_sn = df_diag_ram_sn.sort_values(by = 'time_end')
                         df_diag_ram_sn=df_diag_ram_sn.iloc[-1]
+                        time_end =df_diag_ram_sn['time_end']
                         df_diag_ram_sn.reset_index(inplace=True,drop=True)
                 df_diag_new,df_diag_change=pro_output(df_merge,sn,gpscity,df_diag_ram_sn)
                 kmeans1 = joblib.load('kmeans1.pkl')
@@ -81,7 +84,7 @@ def diag_cal():
                 df_diag_new=prediction(df_diag_new,kmeans1,kmeans2,kmeans3)
                 df_diag_change=prediction(df_diag_change,kmeans1,kmeans2,kmeans3)
                 if not df_diag_change.empty:   #需变更的结果非空
-                    cursor.execute("DELETE FROM algo_charge_info WHERE time_end = '0000-00-00 00:00:00' and sn='{}'".format(sn))
+                    cursor.execute("DELETE FROM algo_charge_info WHERE time_end = '{}' and sn='{}'".format(time_end,sn))
                     mysql.commit()
                     df_diag_change.to_sql("algo_charge_info",con=db_res_engine, if_exists="append",index=False)