IndexStaByPeriod.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <<<<<<< HEAD
  2. '''
  3. 基于某个周期(一天,一周...)的指标统计库
  4. '''
  5. __author__ = 'lmstack'
  6. import CONFIGURE.PathSetting as PathSetting
  7. import sys
  8. sys.path.append(PathSetting.backend_path)
  9. sys.path.append(PathSetting.middle_path)
  10. import datetime
  11. import Tools
  12. import pandas as pd
  13. import numpy as np
  14. import IndexStaByOneCycle
  15. class IndexStaByPeriod():
  16. def __init__(self):
  17. self.indexStaByOneCycle = IndexStaByOneCycle.IndexStaByOneCycle()
  18. pass
  19. def drive_odo_sta(self, df_bms, df_gps):
  20. '''
  21. 计算周期内行车累积行驶里程
  22. ---------输入参数------------
  23. df_bms : 一段周期内的预处理后的bms数据
  24. df_gps : 一段周期内的预处理后的gps数据
  25. ---------输出参数------------
  26. sum_odo : 累积里程, 如果该周期内gps均无效,则返回None
  27. invalid_rate : 该周期内gps无效的bms数据行所占比例
  28. '''
  29. invalid_count = 0
  30. total_count = 0
  31. sum_odo = 0
  32. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_after_combine'])))
  33. if len(data_number_list) == 0:
  34. return {'sum_odo':0, 'invalid_rate':0}
  35. for data_number in data_number_list[:]:
  36. df_sel_bms = df_bms[df_bms['data_split_by_status_after_combine'] == data_number]
  37. df_sel_bms = df_sel_bms.reset_index(drop=True)
  38. total_count += len(df_sel_bms)
  39. if df_sel_bms.loc[0, 'gps_rely'] != 1:
  40. invalid_count += len(df_sel_bms)
  41. continue
  42. else:
  43. df_sel_gps = df_gps[(df_gps['时间戳']>df_sel_bms.loc[0,'时间戳']) & (df_gps['时间戳']<df_sel_bms.loc[len(df_sel_bms)-1,'时间戳'])]
  44. df_sel_gps = df_sel_gps.reset_index(drop=True)
  45. odo = self.indexStaByOneCycle.odo_sta(np.array(df_sel_gps['odo']))
  46. if not pd.isnull(odo):
  47. sum_odo += odo
  48. invalid_rate = invalid_count/total_count
  49. return {'sum_odo':sum_odo, 'invalid_rate':invalid_rate}
  50. #该函数未完成, TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  51. def _energy_consump_sta(self, cap, df_bms, df_gps):
  52. '''
  53. 计算周期内百公里能耗
  54. ---------输入参数------------
  55. df_bms : 本周期内的bms数据
  56. df_gps : 本周期内的gps数据
  57. ---------输出参数------------
  58. 本周期内的百公里能耗
  59. '''
  60. if not df_bms.empty and not df_gps.empty:
  61. # 计算能耗
  62. energy_sum = 0
  63. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  64. for data_number in data_number_list[:]:
  65. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  66. df_sel_bms = df_sel_bms.reset_index(drop=True)
  67. soc_array = np.array(df_sel_bms['SOC[%]'])
  68. soh_array = np.array(df_sel_bms['SOH[%]'])
  69. volt_array = np.array(df_sel_bms['总电压[V]'])
  70. energy = self.indexStaByOneCycle.energy_sta(cap, soc_array, soh_array, volt_array)
  71. if not pd.isnull(energy):
  72. energy_sum += energy
  73. # 计算里程
  74. pass # TODO!!!!!!!!!!!!!!!!!!!!!
  75. return 0
  76. else:
  77. return None
  78. def drive_soc_sta(self, df_bms):
  79. '''
  80. 计算周期内行车净累积soc
  81. ---------输入参数------------
  82. cap : 标称容量
  83. df_bms : 一段周期内的预处理后的bms数据
  84. df_gps : 一段周期内的预处理后的gps数据
  85. ---------输出参数------------
  86. sum_ah : 本周期的净累积soc
  87. '''
  88. sum_soc = 0
  89. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  90. if len(data_number_list) == 0:
  91. return sum_soc
  92. for data_number in data_number_list[:]:
  93. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  94. df_sel_bms = df_sel_bms.reset_index(drop=True)
  95. sum_soc += abs(df_sel_bms.loc[0, 'SOC[%]'] - df_sel_bms.loc[len(df_sel_bms)-1, 'SOC[%]'])
  96. return sum_soc
  97. def drive_time_sta(self, df_bms):
  98. '''
  99. 计算周期内累计行车时长/h
  100. ---------输入参数------------
  101. cap : 标称容量
  102. df_bms : 一段周期内的预处理后的bms数据
  103. df_gps : 一段周期内的预处理后的gps数据
  104. ---------输出参数------------
  105. sum_ah : 本周期的累计行车时长
  106. '''
  107. sum_time = 0
  108. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  109. if len(data_number_list) == 0:
  110. return sum_time
  111. for data_number in data_number_list[:]:
  112. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  113. df_sel_bms = df_sel_bms.reset_index(drop=True)
  114. sum_time += (df_sel_bms.loc[len(df_sel_bms)-1, '时间戳'] - df_sel_bms.loc[0, '时间戳']).total_seconds()
  115. return sum_time / 3600.0
  116. def drive_capacity_sta(self, cap, df_bms):
  117. '''
  118. 计算周期内行车净累积ah
  119. ---------输入参数------------
  120. cap : 标称容量
  121. df_bms : 一段周期内的预处理后的bms数据
  122. df_gps : 一段周期内的预处理后的gps数据
  123. ---------输出参数------------
  124. sum_ah : 本周期的净累积ah
  125. '''
  126. sum_ah = 0
  127. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  128. if len(data_number_list) == 0:
  129. return sum_ah
  130. for data_number in data_number_list[:]:
  131. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  132. df_sel_bms = df_sel_bms.reset_index(drop=True)
  133. soc_array = np.array(df_sel_bms['SOC[%]'])
  134. soh_array = np.array(df_sel_bms['SOH[%]'])
  135. sum_ah += self.indexStaByOneCycle.capacity_sta(cap, soc_array, soh_array)
  136. return sum_ah
  137. def drive_energy_sta(self, cap, df_bms):
  138. '''
  139. 计算周期内行车净累积能量
  140. ---------输入参数------------
  141. cap : 标称容量
  142. df_bms : 一段周期内的预处理后的bms数据
  143. df_gps : 一段周期内的预处理后的gps数据
  144. ---------输出参数------------
  145. sum_ah : 本周期的净累积能量
  146. '''
  147. sum_energy = 0
  148. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  149. if len(data_number_list) == 0:
  150. return sum_energy
  151. for data_number in data_number_list[:]:
  152. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  153. df_sel_bms = df_sel_bms.reset_index(drop=True)
  154. soc_array = np.array(df_sel_bms['SOC[%]'])
  155. soh_array = np.array(df_sel_bms['SOH[%]'])
  156. volt_array = np.array(df_sel_bms['总电压[V]'])
  157. sum_energy += self.indexStaByOneCycle.energy_sta(cap, soc_array, soh_array, volt_array)
  158. =======
  159. '''
  160. 基于某个周期(一天,一周...)的指标统计库
  161. '''
  162. __author__ = 'lmstack'
  163. # import CONFIGURE.PathSetting as PathSetting
  164. # import sys
  165. # sys.path.append(PathSetting.backend_path)
  166. # sys.path.append(PathSetting.middle_path)
  167. import datetime
  168. import Tools
  169. import pandas as pd
  170. import numpy as np
  171. from LIB.MIDDLE import IndexStaByOneCycle
  172. class IndexStaByPeriod():
  173. def __init__(self):
  174. self.indexStaByOneCycle = IndexStaByOneCycle.IndexStaByOneCycle()
  175. pass
  176. def drive_odo_sta(self, df_bms, df_gps):
  177. '''
  178. 计算周期内行车累积行驶里程
  179. ---------输入参数------------
  180. df_bms : 一段周期内的预处理后的bms数据
  181. df_gps : 一段周期内的预处理后的gps数据
  182. ---------输出参数------------
  183. sum_odo : 累积里程, 如果该周期内gps均无效,则返回None
  184. invalid_rate : 该周期内gps无效的bms数据行所占比例
  185. '''
  186. invalid_count = 0
  187. total_count = 0
  188. sum_odo = 0
  189. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_after_combine'])))
  190. if len(data_number_list) == 0:
  191. return {'sum_odo':0, 'invalid_rate':0}
  192. for data_number in data_number_list[:]:
  193. df_sel_bms = df_bms[df_bms['data_split_by_status_after_combine'] == data_number]
  194. df_sel_bms = df_sel_bms.reset_index(drop=True)
  195. total_count += len(df_sel_bms)
  196. if df_sel_bms.loc[0, 'gps_rely'] != 1:
  197. invalid_count += len(df_sel_bms)
  198. continue
  199. else:
  200. df_sel_gps = df_gps[(df_gps['时间戳']>df_sel_bms.loc[0,'时间戳']) & (df_gps['时间戳']<df_sel_bms.loc[len(df_sel_bms)-1,'时间戳'])]
  201. df_sel_gps = df_sel_gps.reset_index(drop=True)
  202. odo = self.indexStaByOneCycle.odo_sta(np.array(df_sel_gps['odo']))
  203. if not pd.isnull(odo):
  204. sum_odo += odo
  205. invalid_rate = invalid_count/total_count
  206. return {'sum_odo':sum_odo, 'invalid_rate':invalid_rate}
  207. #该函数未完成, TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  208. def _energy_consump_sta(self, cap, df_bms, df_gps):
  209. '''
  210. 计算周期内百公里能耗
  211. ---------输入参数------------
  212. df_bms : 本周期内的bms数据
  213. df_gps : 本周期内的gps数据
  214. ---------输出参数------------
  215. 本周期内的百公里能耗
  216. '''
  217. if not df_bms.empty and not df_gps.empty:
  218. # 计算能耗
  219. energy_sum = 0
  220. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  221. for data_number in data_number_list[:]:
  222. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  223. df_sel_bms = df_sel_bms.reset_index(drop=True)
  224. soc_array = np.array(df_sel_bms['SOC[%]'])
  225. soh_array = np.array(df_sel_bms['SOH[%]'])
  226. volt_array = np.array(df_sel_bms['总电压[V]'])
  227. energy = self.indexStaByOneCycle.energy_sta(cap, soc_array, soh_array, volt_array)
  228. if not pd.isnull(energy):
  229. energy_sum += energy
  230. # 计算里程
  231. pass # TODO!!!!!!!!!!!!!!!!!!!!!
  232. return 0
  233. else:
  234. return None
  235. def drive_soc_sta(self, df_bms):
  236. '''
  237. 计算周期内行车净累积soc
  238. ---------输入参数------------
  239. cap : 标称容量
  240. df_bms : 一段周期内的预处理后的bms数据
  241. df_gps : 一段周期内的预处理后的gps数据
  242. ---------输出参数------------
  243. sum_ah : 本周期的净累积soc
  244. '''
  245. sum_soc = 0
  246. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  247. if len(data_number_list) == 0:
  248. return sum_soc
  249. for data_number in data_number_list[:]:
  250. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  251. df_sel_bms = df_sel_bms.reset_index(drop=True)
  252. sum_soc += abs(df_sel_bms.loc[0, 'SOC[%]'] - df_sel_bms.loc[len(df_sel_bms)-1, 'SOC[%]'])
  253. return sum_soc
  254. def drive_time_sta(self, df_bms):
  255. '''
  256. 计算周期内累计行车时长/h
  257. ---------输入参数------------
  258. cap : 标称容量
  259. df_bms : 一段周期内的预处理后的bms数据
  260. df_gps : 一段周期内的预处理后的gps数据
  261. ---------输出参数------------
  262. sum_ah : 本周期的累计行车时长
  263. '''
  264. sum_time = 0
  265. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  266. if len(data_number_list) == 0:
  267. return sum_time
  268. for data_number in data_number_list[:]:
  269. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  270. df_sel_bms = df_sel_bms.reset_index(drop=True)
  271. sum_time += (df_sel_bms.loc[len(df_sel_bms)-1, '时间戳'] - df_sel_bms.loc[0, '时间戳']).total_seconds()
  272. return sum_time / 3600.0
  273. def drive_capacity_sta(self, cap, df_bms):
  274. '''
  275. 计算周期内行车净累积ah
  276. ---------输入参数------------
  277. cap : 标称容量
  278. df_bms : 一段周期内的预处理后的bms数据
  279. df_gps : 一段周期内的预处理后的gps数据
  280. ---------输出参数------------
  281. sum_ah : 本周期的净累积ah
  282. '''
  283. sum_ah = 0
  284. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  285. if len(data_number_list) == 0:
  286. return sum_ah
  287. for data_number in data_number_list[:]:
  288. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  289. df_sel_bms = df_sel_bms.reset_index(drop=True)
  290. soc_array = np.array(df_sel_bms['SOC[%]'])
  291. soh_array = np.array(df_sel_bms['SOH[%]'])
  292. sum_ah += self.indexStaByOneCycle.capacity_sta(cap, soc_array, soh_array)
  293. return sum_ah
  294. def drive_energy_sta(self, cap, df_bms):
  295. '''
  296. 计算周期内行车净累积能量
  297. ---------输入参数------------
  298. cap : 标称容量
  299. df_bms : 一段周期内的预处理后的bms数据
  300. df_gps : 一段周期内的预处理后的gps数据
  301. ---------输出参数------------
  302. sum_ah : 本周期的净累积能量
  303. '''
  304. sum_energy = 0
  305. data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
  306. if len(data_number_list) == 0:
  307. return sum_energy
  308. for data_number in data_number_list[:]:
  309. df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
  310. df_sel_bms = df_sel_bms.reset_index(drop=True)
  311. soc_array = np.array(df_sel_bms['SOC[%]'])
  312. soh_array = np.array(df_sel_bms['SOH[%]'])
  313. volt_array = np.array(df_sel_bms['总电压[V]'])
  314. sum_energy += self.indexStaByOneCycle.energy_sta(cap, soc_array, soh_array, volt_array)
  315. >>>>>>> 65a87ae16013552e359df047df19f46fc4e6eb08
  316. return sum_energy