def loading(self, load_total, sys_ticks, data_file='data/loads_model.xls', filter_col='BMS编号'): '''加载负载数据,并合并到load_pre 默认为load.xls ''' if self.obj == None: fp.output_msg( "The load's data has not loading because of the load model had not created!" ) #读取数据文件 self.load_data = fp.read_load_file(self.load_type, data_file) if data_file == 'data/loads_model.xls': data_d = False else: data_d = True #对数据进行预处理 self.load_data = dp.preprocess_data(self.load_data, self.sys_settings, data_d, col_sel=filter_col, row_sel='010101030613001F') self.loads_on(load_total, sys_ticks)
def sel_period(data, index_col='time', interval=10, d_clip=2): ''' 选择一个周期对数据切片, 时间间隔大于10分钟认为新对周期 ''' data = data.set_index([index_col]) #将time设为index index = data.index[0] index_pre = index try: t_obj = time.strptime(index, "%Y/%m/%d %H:%M") t_stamp_pre = time.mktime(t_obj) index_list = [index] time_interval = 60 * interval #将字符串转换为时间戳并计算得到按时间划分对index for index in data.index: t_obj = time.strptime(index, "%Y/%m/%d %H:%M") t_stamp = time.mktime(t_obj) if (t_stamp - t_stamp_pre) >= time_interval: index_list.append(index_pre) index_list.append(index) t_stamp_pre = t_stamp index_pre = index except: fp.output_msg("时间格式有误!") #选择第2个数据片 d_clip %= 2 data_clip = data[index_list[2 + d_clip]:index_list[3 + d_clip]] return data_clip
def calc_power(data, v1=None, v2=None, v3=None, c1=None, c2=None, c3=None): '''根据电压电流计算功率''' if v2 and v3 and c2 and c3: fp.output_msg('Nan') else: power = (data['volt'] * data['cur']) / 1000 return power
def loads_off(self, load_total, sys_ticks): """ 找到负载对应列,置为0 """ #更新state self.state = False #self.load_pre.update_settings(self.load_num, 'off') load_total.load_t = dp.data_del_col(sys_ticks, load_total.load_t, self.name) load_total.load_t_bk[self.name] = load_total.load_t[self.name] load_total.loads_link.delete(load_total.loads_link.index(self)) load_total.loads_state_update(self.load_num, self.state) fp.output_msg('sys_ticks = ' + str(sys_ticks) + " The load" + str(self.load_num) + " is off.")
def filter_data(data, sample_interval, sel_col): ''' 计算要压缩数据的次数 但是为了不必要的程序开销,压缩后数据均会比目标大,大的部分直接去掉 ''' num = int(math.log((len(data) / sample_interval), 2)) if num < 8: # 最多删减8次 data = delete_data(data, sel_col, num) if len(data) > sample_interval: #超出,删除超出的后面数据部分 data = data[0:sample_interval] else: fp.output_msg('the data is too small!') return data
def __init__(self, sys_settings, load_num, load_type=4): '''负载类型 ''' if load_num <= sys_settings.chargers_num: self.load_type = load_type #标准模型中的负载类型 self.state = False #负载还没有load_on, load_on为True self.load_num = load_num #负载编号 self.sys_settings = sys_settings self.regular = False self.regular_power = None self.obj = True else: self.obj = None fp.output_msg( "The number of loads is more than the system_setting! ")
def complete_data(data, sample_interval, sel_col): ''' 均匀补齐数据 ''' #计算要翻倍数据的次数 num = math.log((sample_interval / len(data)), 2) a = [1, 2, 3, 4, 5, 6, 7, 8] if num in a: num = int(num) else: num = int(num) + 1 if num < len(a): # 7200sample_interval data = insert_data(data, sel_col, num) if len(data) > sample_interval: #超出,删除超出的后面数据部分 data = data[0:sample_interval] else: fp.output_msg("Error, the data is too big!") return data
def loads_on(self, load_total, sys_ticks): """ 计算当前加载的负载,放入load_pre中并返回 sys_ticks为系统运行至当前采样数 col_list为当前负载有效状态列表 """ if self.state == False: #在当前时刻为新的负载,可以加载,并更新state self.state = True #按当前时刻重设data的index,使得合并dataframe时行能对应 self.load_data = dp.reset_index(self.load_data, sys_ticks) #按负载编号重命名数据calc_para列 data = dp.data_col_rename(self.load_data, self.sys_settings.calc_para, 'p' + str(self.load_num)) self.name = 'p' + str(self.load_num) self.min_power = max(data[self.name]) / 5 #调节功率的最小功率 self.end_tick = sys_ticks + len(data) #负载失效时刻 #与load_pre合并 load_cur = load_total.load_t[:] load_total.load_t = dp.data_merge(load_cur, data, col_name=self.name, col_list=load_total.col_list) load_total.load_t_bk[self.name] = load_total.load_t[self.name] load_total.loads_link.append(self) load_total.loads_state_update(self.load_num, self.state) fp.output_msg('sys_ticks = ' + str(sys_ticks) + ' The load' + str(self.load_num) + ' is on.') else: fp.output_msg( 'sys_ticks = ' + str(sys_ticks) + " The load's data has not loading because of the load already exists!" )