DiagDataMerge.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import pandas as pd
  2. import datacompy
  3. class DiagDataMerge():
  4. def DetaMerge(df_Diag_Ram_sn,df_Diag_Batdiag_update,df_OprtnSta,df_Diag_Ram_sn_else):
  5. df_Diag_Ram_add = pd.DataFrame()
  6. df_Diag_Ram_Update_change = pd.DataFrame()
  7. df_Diag_Cal_finish = pd.DataFrame(columns=['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice','Batpos'])
  8. df_Diag_Cal_unfinish = pd.DataFrame(columns=['start_time', 'end_time', 'product_id', 'code', 'level', 'info','advice','Batpos'])
  9. print('处理前',df_Diag_Cal_unfinish)
  10. if not df_Diag_Batdiag_update.empty:
  11. #------------------------------合并两者故障,并将同一sn号下的车辆故障放一起----------------------------------------------
  12. df_Diag_Cal_finish = df_Diag_Batdiag_update[df_Diag_Batdiag_update['end_time'] != '0000-00-00 00:00:00']
  13. df_Diag_Cal_unfinish = df_Diag_Batdiag_update[df_Diag_Batdiag_update['end_time'] == '0000-00-00 00:00:00']
  14. df_Diag_Cal_finish['Batpos'] = [1]*len(df_Diag_Cal_finish)
  15. if len(df_OprtnSta):
  16. if df_OprtnSta.loc[0,'status'] !=1:#0禁用 1正常 2故障 3返修 4 损毁 5丢失已赔偿,6丢失未赔偿
  17. if df_Diag_Cal_unfinish['level'].max()>3:
  18. if df_OprtnSta.loc[0,'status'] ==3:
  19. df_Diag_Cal_unfinish['Batpos'] = [1]*len(df_Diag_Cal_unfinish)
  20. else:
  21. df_Diag_Cal_unfinish['Batpos'] = [0]*len(df_Diag_Cal_unfinish)
  22. else:
  23. df_Diag_Cal_unfinish['Batpos'] = [1]*len(df_Diag_Cal_unfinish)
  24. else:
  25. df_Diag_Cal_unfinish['Batpos'] = [0]*len(df_Diag_Cal_unfinish)
  26. print('处理后',df_Diag_Cal_unfinish)
  27. df_Diag_Cal_Update=pd.concat([df_Diag_Cal_finish,df_Diag_Cal_unfinish])
  28. df_Diag_Ram_add = pd.concat([df_Diag_Cal_Update,df_Diag_Ram_sn,df_Diag_Ram_sn]).drop_duplicates(subset=['start_time','code'],keep=False)#此次判断中新增故障
  29. df_Diag_Ram_Update_old = pd.concat([df_Diag_Cal_Update,df_Diag_Ram_add,df_Diag_Ram_add]).drop_duplicates(subset=['start_time','code'],keep=False)#此次判断中新增故障
  30. df_Diag_Ram_Update_change = pd.concat([df_Diag_Ram_Update_old,df_Diag_Ram_sn,df_Diag_Ram_sn]).drop_duplicates(subset=['start_time','code','Batpos'],keep=False)#此次判断中新增故障
  31. # df_Diag_Ram = pd.concat([df_Diag_Ram_sn_else,df_Diag_Cal_unfinish])
  32. return df_Diag_Ram_add,df_Diag_Ram_Update_change