123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520 |
- <<<<<<< HEAD
- <<<<<<< HEAD
- '''
- 基于某个周期(一天,一周...)的指标统计库
- '''
- __author__ = 'lmstack'
- import CONFIGURE.PathSetting as PathSetting
- import sys
- sys.path.append(PathSetting.backend_path)
- sys.path.append(PathSetting.middle_path)
- import datetime
- import Tools
- import pandas as pd
- import numpy as np
- import IndexStaByOneCycle
- class IndexStaByPeriod():
- def __init__(self):
- self.indexStaByOneCycle = IndexStaByOneCycle.IndexStaByOneCycle()
- pass
- def drive_odo_sta(self, df_bms, df_gps):
- '''
- 计算周期内行车累积行驶里程
- ---------输入参数------------
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_odo : 累积里程, 如果该周期内gps均无效,则返回None
- invalid_rate : 该周期内gps无效的bms数据行所占比例
- '''
- invalid_count = 0
- total_count = 0
- sum_odo = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_after_combine'])))
- if len(data_number_list) == 0:
- return {'sum_odo':0, 'invalid_rate':0}
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_after_combine'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- total_count += len(df_sel_bms)
- if df_sel_bms.loc[0, 'gps_rely'] != 1:
- invalid_count += len(df_sel_bms)
- continue
- else:
- df_sel_gps = df_gps[(df_gps['时间戳']>df_sel_bms.loc[0,'时间戳']) & (df_gps['时间戳']<df_sel_bms.loc[len(df_sel_bms)-1,'时间戳'])]
- df_sel_gps = df_sel_gps.reset_index(drop=True)
- odo = self.indexStaByOneCycle.odo_sta(np.array(df_sel_gps['odo']))
- if not pd.isnull(odo):
- sum_odo += odo
- invalid_rate = invalid_count/total_count
- return {'sum_odo':sum_odo, 'invalid_rate':invalid_rate}
-
-
- #该函数未完成, TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- def _energy_consump_sta(self, cap, df_bms, df_gps):
- '''
- 计算周期内百公里能耗
- ---------输入参数------------
- df_bms : 本周期内的bms数据
- df_gps : 本周期内的gps数据
- ---------输出参数------------
- 本周期内的百公里能耗
- '''
- if not df_bms.empty and not df_gps.empty:
- # 计算能耗
- energy_sum = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- soc_array = np.array(df_sel_bms['SOC[%]'])
- soh_array = np.array(df_sel_bms['SOH[%]'])
- volt_array = np.array(df_sel_bms['总电压[V]'])
- energy = self.indexStaByOneCycle.energy_sta(cap, soc_array, soh_array, volt_array)
- if not pd.isnull(energy):
- energy_sum += energy
- # 计算里程
- pass # TODO!!!!!!!!!!!!!!!!!!!!!
- return 0
- else:
- return None
- def drive_soc_sta(self, df_bms):
- '''
- 计算周期内行车净累积soc
- ---------输入参数------------
- cap : 标称容量
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_ah : 本周期的净累积soc
- '''
- sum_soc = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- if len(data_number_list) == 0:
- return sum_soc
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- sum_soc += abs(df_sel_bms.loc[0, 'SOC[%]'] - df_sel_bms.loc[len(df_sel_bms)-1, 'SOC[%]'])
- return sum_soc
- def drive_time_sta(self, df_bms):
- '''
- 计算周期内累计行车时长/h
- ---------输入参数------------
- cap : 标称容量
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_ah : 本周期的累计行车时长
- '''
- sum_time = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- if len(data_number_list) == 0:
- return sum_time
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- sum_time += (df_sel_bms.loc[len(df_sel_bms)-1, '时间戳'] - df_sel_bms.loc[0, '时间戳']).total_seconds()
- return sum_time / 3600.0
- def drive_capacity_sta(self, cap, df_bms):
- '''
- 计算周期内行车净累积ah
- ---------输入参数------------
- cap : 标称容量
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_ah : 本周期的净累积ah
- '''
- sum_ah = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- if len(data_number_list) == 0:
- return sum_ah
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- soc_array = np.array(df_sel_bms['SOC[%]'])
- soh_array = np.array(df_sel_bms['SOH[%]'])
- sum_ah += self.indexStaByOneCycle.capacity_sta(cap, soc_array, soh_array)
- return sum_ah
- def drive_energy_sta(self, cap, df_bms):
- '''
- 计算周期内行车净累积能量
- ---------输入参数------------
- cap : 标称容量
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_ah : 本周期的净累积能量
- '''
- sum_energy = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- if len(data_number_list) == 0:
- return sum_energy
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- soc_array = np.array(df_sel_bms['SOC[%]'])
- soh_array = np.array(df_sel_bms['SOH[%]'])
- volt_array = np.array(df_sel_bms['总电压[V]'])
- sum_energy += self.indexStaByOneCycle.energy_sta(cap, soc_array, soh_array, volt_array)
- =======
- '''
- 基于某个周期(一天,一周...)的指标统计库
- '''
- __author__ = 'lmstack'
- import CONFIGURE.PathSetting as PathSetting
- import sys
- sys.path.append(PathSetting.backend_path)
- sys.path.append(PathSetting.middle_path)
- import datetime
- import Tools
- import pandas as pd
- import numpy as np
- import IndexStaByOneCycle
- class IndexStaByPeriod():
- def __init__(self):
- self.indexStaByOneCycle = IndexStaByOneCycle.IndexStaByOneCycle()
- pass
- def drive_odo_sta(self, df_bms, df_gps):
- '''
- 计算周期内行车累积行驶里程
- ---------输入参数------------
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_odo : 累积里程, 如果该周期内gps均无效,则返回None
- invalid_rate : 该周期内gps无效的bms数据行所占比例
- '''
- invalid_count = 0
- total_count = 0
- sum_odo = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_after_combine'])))
- if len(data_number_list) == 0:
- return {'sum_odo':0, 'invalid_rate':0}
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_after_combine'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- total_count += len(df_sel_bms)
- if df_sel_bms.loc[0, 'gps_rely'] != 1:
- invalid_count += len(df_sel_bms)
- continue
- else:
- df_sel_gps = df_gps[(df_gps['时间戳']>df_sel_bms.loc[0,'时间戳']) & (df_gps['时间戳']<df_sel_bms.loc[len(df_sel_bms)-1,'时间戳'])]
- df_sel_gps = df_sel_gps.reset_index(drop=True)
- odo = self.indexStaByOneCycle.odo_sta(np.array(df_sel_gps['odo']))
- if not pd.isnull(odo):
- sum_odo += odo
- invalid_rate = invalid_count/total_count
- return {'sum_odo':sum_odo, 'invalid_rate':invalid_rate}
-
-
- #该函数未完成, TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- def _energy_consump_sta(self, cap, df_bms, df_gps):
- '''
- 计算周期内百公里能耗
- ---------输入参数------------
- df_bms : 本周期内的bms数据
- df_gps : 本周期内的gps数据
- ---------输出参数------------
- 本周期内的百公里能耗
- '''
- if not df_bms.empty and not df_gps.empty:
- # 计算能耗
- energy_sum = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- soc_array = np.array(df_sel_bms['SOC[%]'])
- soh_array = np.array(df_sel_bms['SOH[%]'])
- volt_array = np.array(df_sel_bms['总电压[V]'])
- energy = self.indexStaByOneCycle.energy_sta(cap, soc_array, soh_array, volt_array)
- if not pd.isnull(energy):
- energy_sum += energy
- # 计算里程
- pass # TODO!!!!!!!!!!!!!!!!!!!!!
- return 0
- else:
- return None
- def drive_soc_sta(self, df_bms):
- '''
- 计算周期内行车净累积soc
- ---------输入参数------------
- cap : 标称容量
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_ah : 本周期的净累积soc
- '''
- sum_soc = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- if len(data_number_list) == 0:
- return sum_soc
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- sum_soc += abs(df_sel_bms.loc[0, 'SOC[%]'] - df_sel_bms.loc[len(df_sel_bms)-1, 'SOC[%]'])
- return sum_soc
- def drive_time_sta(self, df_bms):
- '''
- 计算周期内累计行车时长/h
- ---------输入参数------------
- cap : 标称容量
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_ah : 本周期的累计行车时长
- '''
- sum_time = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- if len(data_number_list) == 0:
- return sum_time
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- sum_time += (df_sel_bms.loc[len(df_sel_bms)-1, '时间戳'] - df_sel_bms.loc[0, '时间戳']).total_seconds()
- return sum_time / 3600.0
- def drive_capacity_sta(self, cap, df_bms):
- '''
- 计算周期内行车净累积ah
- ---------输入参数------------
- cap : 标称容量
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_ah : 本周期的净累积ah
- '''
- sum_ah = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- if len(data_number_list) == 0:
- return sum_ah
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- soc_array = np.array(df_sel_bms['SOC[%]'])
- soh_array = np.array(df_sel_bms['SOH[%]'])
- sum_ah += self.indexStaByOneCycle.capacity_sta(cap, soc_array, soh_array)
- return sum_ah
- def drive_energy_sta(self, cap, df_bms):
- '''
- 计算周期内行车净累积能量
- ---------输入参数------------
- cap : 标称容量
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_ah : 本周期的净累积能量
- '''
- sum_energy = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- if len(data_number_list) == 0:
- return sum_energy
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- soc_array = np.array(df_sel_bms['SOC[%]'])
- soh_array = np.array(df_sel_bms['SOH[%]'])
- volt_array = np.array(df_sel_bms['总电压[V]'])
- sum_energy += self.indexStaByOneCycle.energy_sta(cap, soc_array, soh_array, volt_array)
- >>>>>>> master
- =======
- '''
- 基于某个周期(一天,一周...)的指标统计库
- '''
- __author__ = 'lmstack'
- # import CONFIGURE.PathSetting as PathSetting
- # import sys
- # sys.path.append(PathSetting.backend_path)
- # sys.path.append(PathSetting.middle_path)
- import datetime
- import Tools
- import pandas as pd
- import numpy as np
- from LIB.MIDDLE import IndexStaByOneCycle
- class IndexStaByPeriod():
- def __init__(self):
- self.indexStaByOneCycle = IndexStaByOneCycle.IndexStaByOneCycle()
- pass
- def drive_odo_sta(self, df_bms, df_gps):
- '''
- 计算周期内行车累积行驶里程
- ---------输入参数------------
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_odo : 累积里程, 如果该周期内gps均无效,则返回None
- invalid_rate : 该周期内gps无效的bms数据行所占比例
- '''
- invalid_count = 0
- total_count = 0
- sum_odo = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_after_combine'])))
- if len(data_number_list) == 0:
- return {'sum_odo':0, 'invalid_rate':0}
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_after_combine'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- total_count += len(df_sel_bms)
- if df_sel_bms.loc[0, 'gps_rely'] != 1:
- invalid_count += len(df_sel_bms)
- continue
- else:
- df_sel_gps = df_gps[(df_gps['时间戳']>df_sel_bms.loc[0,'时间戳']) & (df_gps['时间戳']<df_sel_bms.loc[len(df_sel_bms)-1,'时间戳'])]
- df_sel_gps = df_sel_gps.reset_index(drop=True)
- odo = self.indexStaByOneCycle.odo_sta(np.array(df_sel_gps['odo']))
- if not pd.isnull(odo):
- sum_odo += odo
- invalid_rate = invalid_count/total_count
- return {'sum_odo':sum_odo, 'invalid_rate':invalid_rate}
-
-
- #该函数未完成, TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- def _energy_consump_sta(self, cap, df_bms, df_gps):
- '''
- 计算周期内百公里能耗
- ---------输入参数------------
- df_bms : 本周期内的bms数据
- df_gps : 本周期内的gps数据
- ---------输出参数------------
- 本周期内的百公里能耗
- '''
- if not df_bms.empty and not df_gps.empty:
- # 计算能耗
- energy_sum = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- soc_array = np.array(df_sel_bms['SOC[%]'])
- soh_array = np.array(df_sel_bms['SOH[%]'])
- volt_array = np.array(df_sel_bms['总电压[V]'])
- energy = self.indexStaByOneCycle.energy_sta(cap, soc_array, soh_array, volt_array)
- if not pd.isnull(energy):
- energy_sum += energy
- # 计算里程
- pass # TODO!!!!!!!!!!!!!!!!!!!!!
- return 0
- else:
- return None
- def drive_soc_sta(self, df_bms):
- '''
- 计算周期内行车净累积soc
- ---------输入参数------------
- cap : 标称容量
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_ah : 本周期的净累积soc
- '''
- sum_soc = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- if len(data_number_list) == 0:
- return sum_soc
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- sum_soc += abs(df_sel_bms.loc[0, 'SOC[%]'] - df_sel_bms.loc[len(df_sel_bms)-1, 'SOC[%]'])
- return sum_soc
- def drive_time_sta(self, df_bms):
- '''
- 计算周期内累计行车时长/h
- ---------输入参数------------
- cap : 标称容量
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_ah : 本周期的累计行车时长
- '''
- sum_time = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- if len(data_number_list) == 0:
- return sum_time
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- sum_time += (df_sel_bms.loc[len(df_sel_bms)-1, '时间戳'] - df_sel_bms.loc[0, '时间戳']).total_seconds()
- return sum_time / 3600.0
- def drive_capacity_sta(self, cap, df_bms):
- '''
- 计算周期内行车净累积ah
- ---------输入参数------------
- cap : 标称容量
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_ah : 本周期的净累积ah
- '''
- sum_ah = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- if len(data_number_list) == 0:
- return sum_ah
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- soc_array = np.array(df_sel_bms['SOC[%]'])
- soh_array = np.array(df_sel_bms['SOH[%]'])
- sum_ah += self.indexStaByOneCycle.capacity_sta(cap, soc_array, soh_array)
- return sum_ah
- def drive_energy_sta(self, cap, df_bms):
- '''
- 计算周期内行车净累积能量
- ---------输入参数------------
- cap : 标称容量
- df_bms : 一段周期内的预处理后的bms数据
- df_gps : 一段周期内的预处理后的gps数据
- ---------输出参数------------
- sum_ah : 本周期的净累积能量
- '''
- sum_energy = 0
- data_number_list = sorted(list(set(df_bms[(df_bms['data_status'].isin(['drive']))]['data_split_by_status_time'])))
- if len(data_number_list) == 0:
- return sum_energy
- for data_number in data_number_list[:]:
- df_sel_bms = df_bms[df_bms['data_split_by_status_time'] == data_number]
- df_sel_bms = df_sel_bms.reset_index(drop=True)
- soc_array = np.array(df_sel_bms['SOC[%]'])
- soh_array = np.array(df_sel_bms['SOH[%]'])
- volt_array = np.array(df_sel_bms['总电压[V]'])
- sum_energy += self.indexStaByOneCycle.energy_sta(cap, soc_array, soh_array, volt_array)
- >>>>>>> 65a87ae16013552e359df047df19f46fc4e6eb08
- return sum_energy
|