IndexStaByPeriod.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. '''
  2. 基于某个周期(一天,一周...)的指标统计库
  3. '''
  4. __author__ = 'wlm'
  5. import CONFIGURE.PathSetting as PathSetting
  6. import sys
  7. sys.path.append(PathSetting.backend_path)
  8. sys.path.append(PathSetting.middle_path)
  9. import datetime
  10. import Tools
  11. import pandas as pd
  12. import numpy as np
  13. import IndexStaByOneCycle
  14. class IndexStaByPeriod():
  15. def __init__(self):
  16. self.indexStaByOneCycle = IndexStaByOneCycle.IndexStaByOneCycle()
  17. pass
  18. def drive_odo_sta(self, df_bms, df_gps):
  19. '''
  20. 计算周期内行车累积行驶里程
  21. ---------输入参数------------
  22. df_bms : 一段周期内的预处理后的bms数据
  23. df_gps : 一段周期内的预处理后的gps数据
  24. ---------输出参数------------
  25. sum_odo : 累积里程, 如果该周期内gps均无效,则返回None
  26. invalid_rate : 该周期内gps无效的bms数据行所占比例
  27. '''
  28. invalid_count = 0
  29. total_count = 0
  30. sum_odo = 0
  31. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_after_combine'])))
  32. if len(data_number_list) == 0:
  33. return {'sum_odo':0, 'invalid_rate':0}
  34. for data_number in data_number_list[:]:
  35. df_sel_bms = df_bms[df_bms['data_split_by_status_after_combine'] == data_number]
  36. df_sel_bms = df_sel_bms.reset_index(drop=True)
  37. total_count += len(df_sel_bms)
  38. if df_sel_bms.loc[0, 'gps_rely'] != 1:
  39. invalid_count += len(df_sel_bms)
  40. continue
  41. else:
  42. df_sel_gps = df_gps[(df_gps['时间戳']>df_sel_bms.loc[0,'时间戳']) & (df_gps['时间戳']<df_sel_bms.loc[len(df_sel_bms)-1,'时间戳'])]
  43. df_sel_gps = df_sel_gps.reset_index(drop=True)
  44. odo = self.indexStaByOneCycle.odo_sta(np.array(df_sel_gps['odo']))
  45. if not pd.isnull(odo):
  46. sum_odo += odo
  47. invalid_rate = invalid_count/total_count
  48. return {'sum_odo':sum_odo, 'invalid_rate':invalid_rate}
  49. #该函数未完成, TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  50. def _energy_consump_sta(self, cap, df_bms, df_gps):
  51. '''
  52. 计算周期内百公里能耗
  53. ---------输入参数------------
  54. df_bms : 本周期内的bms数据
  55. df_gps : 本周期内的gps数据
  56. ---------输出参数------------
  57. 本周期内的百公里能耗
  58. '''
  59. if not df_bms.empty and not df_gps.empty:
  60. # 计算能耗
  61. energy_sum = 0
  62. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  63. for data_number in data_number_list[:]:
  64. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  65. df_sel_bms = df_sel_bms.reset_index(drop=True)
  66. soc_array = np.array(df_sel_bms['SOC[%]'])
  67. soh_array = np.array(df_sel_bms['SOH[%]'])
  68. volt_array = np.array(df_sel_bms['总电压[V]'])
  69. energy = self.indexStaByOneCycle.energy_sta(cap, soc_array, soh_array, volt_array)
  70. if not pd.isnull(energy):
  71. energy_sum += energy
  72. # 计算里程
  73. pass # TODO!!!!!!!!!!!!!!!!!!!!!
  74. return 0
  75. else:
  76. return None
  77. def drive_soc_sta(self, df_bms):
  78. '''
  79. 计算周期内行车净累积soc
  80. ---------输入参数------------
  81. cap : 标称容量
  82. df_bms : 一段周期内的预处理后的bms数据
  83. df_gps : 一段周期内的预处理后的gps数据
  84. ---------输出参数------------
  85. sum_ah : 本周期的净累积soc
  86. '''
  87. sum_soc = 0
  88. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  89. if len(data_number_list) == 0:
  90. return sum_soc
  91. for data_number in data_number_list[:]:
  92. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  93. df_sel_bms = df_sel_bms.reset_index(drop=True)
  94. sum_soc += abs(df_sel_bms.loc[0, 'SOC[%]'] - df_sel_bms.loc[len(df_sel_bms)-1, 'SOC[%]'])
  95. return sum_soc
  96. def drive_time_sta(self, df_bms):
  97. '''
  98. 计算周期内累计行车时长/h
  99. ---------输入参数------------
  100. cap : 标称容量
  101. df_bms : 一段周期内的预处理后的bms数据
  102. df_gps : 一段周期内的预处理后的gps数据
  103. ---------输出参数------------
  104. sum_ah : 本周期的累计行车时长
  105. '''
  106. sum_time = 0
  107. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  108. if len(data_number_list) == 0:
  109. return sum_time
  110. for data_number in data_number_list[:]:
  111. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  112. df_sel_bms = df_sel_bms.reset_index(drop=True)
  113. sum_time += (df_sel_bms.loc[len(df_sel_bms)-1, '时间戳'] - df_sel_bms.loc[0, '时间戳']).total_seconds()
  114. return sum_time / 3600.0
  115. def drive_capacity_sta(self, cap, df_bms):
  116. '''
  117. 计算周期内行车净累积ah
  118. ---------输入参数------------
  119. cap : 标称容量
  120. df_bms : 一段周期内的预处理后的bms数据
  121. df_gps : 一段周期内的预处理后的gps数据
  122. ---------输出参数------------
  123. sum_ah : 本周期的净累积ah
  124. '''
  125. sum_ah = 0
  126. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  127. if len(data_number_list) == 0:
  128. return sum_ah
  129. for data_number in data_number_list[:]:
  130. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  131. df_sel_bms = df_sel_bms.reset_index(drop=True)
  132. soc_array = np.array(df_sel_bms['SOC[%]'])
  133. soh_array = np.array(df_sel_bms['SOH[%]'])
  134. sum_ah += self.indexStaByOneCycle.capacity_sta(cap, soc_array, soh_array)
  135. return sum_ah
  136. def drive_energy_sta(self, cap, df_bms):
  137. '''
  138. 计算周期内行车净累积能量
  139. ---------输入参数------------
  140. cap : 标称容量
  141. df_bms : 一段周期内的预处理后的bms数据
  142. df_gps : 一段周期内的预处理后的gps数据
  143. ---------输出参数------------
  144. sum_ah : 本周期的净累积能量
  145. '''
  146. sum_energy = 0
  147. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  148. if len(data_number_list) == 0:
  149. return sum_energy
  150. for data_number in data_number_list[:]:
  151. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  152. df_sel_bms = df_sel_bms.reset_index(drop=True)
  153. soc_array = np.array(df_sel_bms['SOC[%]'])
  154. soh_array = np.array(df_sel_bms['SOH[%]'])
  155. volt_array = np.array(df_sel_bms['总电压[V]'])
  156. sum_energy += self.indexStaByOneCycle.energy_sta(cap, soc_array, soh_array, volt_array)
  157. return sum_energy