User_persona.py 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # 读取数据
  2. import numpy as np
  3. import pandas as pd
  4. import preprocess.preprocess
  5. import importlib
  6. import ana.parameters
  7. import datetime
  8. import os
  9. import matplotlib
  10. import openpyxl
  11. file_path = r'D:\Work\Interior\Cloud_BMS\data_ana\7250.csv'
  12. sn_list = pd.read_csv(file_path,encoding='gbk')
  13. sn_list = sn_list.values.tolist()
  14. # print(sn_list)
  15. sn_list = [['PK504B10100004301']]
  16. df_res = pd.DataFrame(columns=['sn', 'date', 'odo', 'capacity', 'energy', 'energy_rate', 'acc_time_drive',
  17. 'acc_time_stand', 'acc_time_charge', 'avr_stand_tem', 'avr_stand_tem_rate',
  18. 'max_pwr', 'regen_flag', 'regen_rate', 'avr_speed', 'max_speed', 'avr_drive_tem',
  19. 'avr_drive_tem_rate', 'center_long', 'center_lat', 'rad'])
  20. df_soh_res = pd.DataFrame(columns=['sn', 'time', 'accum_ah', 'soh_cell01', 'soh_cell02', 'soh_cell03',
  21. 'soh_cell04', 'soh_cell05', 'soh_cell06', 'soh_cell07',
  22. 'soh_cell08', 'soh_cell09', 'soh_cell10', 'soh_cell11',
  23. 'soh_cell12', 'soh_cell13', 'soh_cell14', 'soh_cell15',
  24. 'soh_cell16', 'soh_cell17', 'soh_cell18', 'soh_cell19',
  25. 'soh_cell20'])
  26. df_cell_res = pd.DataFrame(columns=['sn', 'time', 'status', 'volt_cell01', 'volt_cell02', 'volt_cell03',
  27. 'volt_cell04', 'volt_cell05', 'volt_cell06', 'volt_cell07',
  28. 'volt_cell08', 'volt_cell09', 'volt_cell10', 'volt_cell11',
  29. 'volt_cell12', 'volt_cell13', 'volt_cell14', 'volt_cell15',
  30. 'volt_cell16', 'volt_cell17', 'volt_cell18', 'volt_cell19',
  31. 'volt_cell20', 'volt_max', 'volt_min', 'volt_avr', 'soc_diff',
  32. 'soc_diff_div', 'over_discharge'])
  33. for sn in sn_list:
  34. # 数据读取
  35. base_path = r'D:\Work\Interior\Cloud_BMS\data_ana\Data_Files'
  36. time = '_from_2020-04-27_to_2021-04-27.csv'
  37. bms_file = base_path + r'\\' + sn[0] + '\BMS_' + sn[0] + time
  38. gps_file = base_path + r'\\' + sn[0] + '\GPS_' + sn[0] + time
  39. # print(bms_file)
  40. if not os.path.exists(bms_file):
  41. print('{} bms file does not exist!!!!!!'.format(sn[0]))
  42. continue
  43. if not os.path.exists(gps_file):
  44. print('{} gps file does not exist!!!!!!'.format(sn[0]))
  45. continue
  46. df_bms = pd.read_csv(bms_file, encoding='GB2312')
  47. df_gps = pd.read_csv(gps_file, encoding='GB2312')
  48. df_bms = df_bms.drop_duplicates(['时间戳'])
  49. df_gps = df_gps.drop_duplicates(['时间戳'])
  50. df_bms = df_bms.reset_index(drop=True)
  51. df_gps = df_gps.reset_index(drop=True)
  52. df_bms['时间戳'] = pd.to_datetime(df_bms['时间戳'])
  53. df_gps['时间戳'] = pd.to_datetime(df_gps['时间戳'])
  54. print('{} data read Well Done!'.format(sn[0]))
  55. df_bms.to_csv('result2.csv', index=False, encoding='GB2312')
  56. # 数据预处理
  57. # 1、数据分段
  58. # 2、GPS数据可靠与否的判断(根据GPS计算出的平均车速<2认为可靠)
  59. importlib.reload(preprocess.preprocess)
  60. df_bms = preprocess.preprocess.data_split(df_bms)
  61. df_bms.to_csv('result.csv',encoding='GB2312')
  62. df_bms, df_gps, prepro_record = preprocess.preprocess.data_gps_judge(df_bms, df_gps, 2)
  63. print('{} data preprocess Well Done!'.format(sn[0]))
  64. df_bms.to_csv('result.csv', index=False, encoding='GB2312')
  65. df_gps.to_csv('result1.csv', index=False, encoding='GB2312')
  66. importlib.reload(ana.parameters)
  67. # test = ana.parameters.sta_one_drive_cycle(df_bms, df_gps, prepro_record, time_window=3600*24, step=3600*24, start_time="00:00:00")
  68. # print(test)
  69. # 计算Daily数据
  70. start_time = df_bms.loc[0, '时间戳']
  71. # print(start_time)
  72. cur_time = start_time
  73. index = 0
  74. while cur_time < df_bms.loc[len(df_bms) - 1, '时间戳']:
  75. if cur_time.day != start_time.day:
  76. break
  77. else:
  78. index = index + 1
  79. cur_time = df_bms.loc[index, '时间戳']
  80. start = '00:00:00'
  81. start_time = datetime.datetime.strptime(str(df_bms.loc[index, '时间戳'])[0:10] + ' ' + start, '%Y-%m-%d %H:%M:%S')
  82. # print(index, start_time)
  83. timeDelta = datetime.timedelta(days=1)
  84. end_time = start_time + timeDelta
  85. # print(start_time, end_time)
  86. while end_time < df_bms.loc[len(df_bms) - 1, '时间戳']:
  87. # while end_time < df_bms.loc[8500, '时间戳']:
  88. df_sel_bms = df_bms[(df_bms['时间戳'] >= start_time) & (df_bms['时间戳'] <= end_time)]
  89. df_sel_bms = df_sel_bms.reset_index(drop=True)
  90. df_sel_gps = df_gps[(df_gps['时间戳'] >= start_time) & (df_gps['时间戳'] <= end_time)]
  91. df_sel_gps = df_sel_gps.reset_index(drop=True)
  92. if len(df_sel_bms) == 0:
  93. continue
  94. date = ana.parameters.get_date(df_sel_bms)
  95. odo_total, odo_sum, odo_plus = ana.parameters.get_daily_odo(df_sel_bms, df_sel_gps)
  96. print('total={},odo={},plus={}'.format(odo_total, odo_sum, odo_plus))
  97. # 计算单日里程,单日平均车速,单日最高车速
  98. # print(start_time)
  99. odo, avr_speed, max_speed = ana.parameters.get_daily_odo_and_speed(df_sel_bms, df_sel_gps)
  100. # 计算单日使用容量,单日使用能量
  101. capacity, energy = ana.parameters.get_daily_capacity_and_energy(df_sel_bms, 55)
  102. # 计算单日平均电耗:kwh/100km
  103. if odo > 10:
  104. energy_rate = energy / odo * 100
  105. else:
  106. energy_rate = 0
  107. # 计算单日累积时间(行驶、静置、充电)
  108. acc_time_drive = ana.parameters.get_daily_accum_time(df_sel_bms, 'drive')
  109. acc_time_stand = ana.parameters.get_daily_accum_time(df_sel_bms, 'stand')
  110. acc_time_charge = ana.parameters.get_daily_accum_time(df_sel_bms, 'charge')
  111. # 计算过程平均温度,平均温升(静置、行驶)
  112. avr_stand_tem, avr_stand_tem_rate = ana.parameters.get_daily_stand_temp(df_sel_bms, 'stand')
  113. avr_drive_tem, avr_drive_tem_rate = ana.parameters.get_daily_stand_temp(df_sel_bms, 'drive')
  114. # 计算车辆功率
  115. max_pwr = ana.parameters.get_daily_max_pwr(df_sel_bms, 'drive')
  116. # 计算regen数据,是否有regen以及regen比例
  117. regen_flag, regen_rate = ana.parameters.get_daily_regen(df_sel_bms, 'drive')
  118. # 计算活动范围,圆心和半径
  119. center_long, center_lat, rad = ana.parameters.get_working_scope(df_sel_bms, df_sel_gps, 'drive')
  120. df_res = df_res.append({'sn': sn[0],
  121. 'date': date,
  122. 'odo': odo,
  123. 'capacity': capacity,
  124. 'energy': energy,
  125. 'energy_rate': energy_rate,
  126. 'acc_time_drive': acc_time_drive,
  127. 'acc_time_stand': acc_time_stand,
  128. 'acc_time_charge': acc_time_charge,
  129. 'avr_stand_tem': avr_stand_tem,
  130. 'avr_stand_tem_rate': avr_stand_tem_rate,
  131. 'max_pwr': max_pwr,
  132. 'regen_flag': regen_flag,
  133. 'regen_rate': regen_rate,
  134. 'avr_speed': avr_speed,
  135. 'max_speed': max_speed,
  136. 'avr_drive_tem': avr_drive_tem,
  137. 'avr_drive_tem_rate': avr_drive_tem_rate,
  138. 'center_long': center_long,
  139. 'center_lat': center_lat,
  140. 'rad': rad}, ignore_index=True)
  141. start_time = end_time
  142. end_time = start_time + timeDelta
  143. # print(end_time,df_bms.loc[len(df_bms) - 1, '时间戳'])
  144. print('{} daily data process Well Done!'.format(sn[0]))
  145. # 计算电池周期性数据
  146. df_soh_res_single, df_cell_res_single = ana.parameters.get_soh(df_bms, sn)
  147. df_soh_res = pd.concat([df_soh_res, df_soh_res_single], ignore_index=True)
  148. df_cell_res = pd.concat([df_cell_res, df_cell_res_single], ignore_index=True)
  149. print('{} period data process Well Done!'.format(sn[0]))
  150. path = r'D:\Work\Interior\Cloud_BMS\data_ana\report\daily_data_analysis.csv'
  151. df_res.to_csv(path, index=False, encoding='GB2312')
  152. path = r'D:\Work\Interior\Cloud_BMS\data_ana\report\period_data_analysis.xlsx'
  153. writer = pd.ExcelWriter(path)
  154. df_soh_res.to_excel(writer, "SOH数据")
  155. df_cell_res.to_excel(writer, "一致性数据")
  156. writer.save()