예제 #1
0
def main():
    """
    c_id = pd.DataFrame(np.random.randint(low=20, high=50, size=(5, 1)),
                         columns=['vin_code'])
    df = create_bat_id(c_id['vin_code'])
    df = df.join(c_id)
    """
    config = {
        's': '192.168.1.105',
        'u': 'data',
        'p': 'For2019&tomorrow',
        'db': 'bsa',
        'port': 3306
    }
    df = ioo.read_sql_data(config, 'vehicle_info')
    df = df[['vin']]
    df1 = create_bat_id(df['vin'])
    df = df.join(df1)
    config['db'] = 'bat_config'
    save_bat_id(df, config)
    config['db'] = 'evb_batterybase'
    df = df = ioo.read_sql_data(config, 'bat_info')
    df = df[['sys_id', 'vin_code']]
    df = df.rename(columns={'vin_code': 'vin'})
    config['db'] = 'bat_config'
    save_bat_id(df, config)
예제 #2
0
def get_cell_rate_para(config, cell_info, fuzzy=False):
    """
    #通过电池基础信息表获得电池基础参数
    """
    bat_config = {'C_RATE': 210, 'V_RATE': 3.2, 'T_REFER': 20}

    df = ioo.read_sql_data(config, '电池信息表')
    cell_info_list = set(df['电池型号'].tolist())
    if not fuzzy:
        if cell_info in cell_info_list:  #暂时先按每个电芯做匹配
            bat_config['C_RATE'] = df[df['电池型号'] == cell_info]['额定容量'].iloc[0]
            bat_config['V_RATE'] = df[df['电池型号'] == cell_info]['额定电压'].iloc[0]
            bat_config['bat_type'] = df[df['电池型号'] ==
                                        cell_info]['bat_type'].iloc[0]
            bat_config['parallel'] = df[df['电池型号'] == cell_info]['并联数'].iloc[0]
            bat_config['series'] = df[df['电池型号'] == cell_info]['串联数'].iloc[0]
    else:
        for cell_reg in cell_info_list:
            if re.match(cell_reg, cell_info):
                bat_config['C_RATE'] = df[df['电池型号'] ==
                                          cell_reg]['额定容量'].iloc[0]
                bat_config['V_RATE'] = df[df['电池型号'] ==
                                          cell_reg]['额定电压'].iloc[0]
                bat_config['bat_type'] = df[df['电池型号'] ==
                                            cell_reg]['bat_type'].iloc[0]
                bat_config['parallel'] = df[df['电池型号'] ==
                                            cell_reg]['并联数'].iloc[0]
                bat_config['series'] = df[df['电池型号'] ==
                                          cell_reg]['串联数'].iloc[0]
                break
    return bat_config
예제 #3
0
def read_bat_data(para_dict, mode, bat_name, **kwg):
    config = para_dict['config'][mode]
    kwds = {}
    if 'limit' in kwg:
        kwds['limit'] = kwg['limit']
    if 'start_time' in kwg and 'end_time' in kwg:
        kwds['start_time'] = kwg['start_time']
        kwds['end_time'] = kwg['end_time']
    raw_data = ioo.read_sql_data(config, bat_name, **kwds)
    return raw_data
예제 #4
0
def scale_data(ser, config, cell_no, score_key, start_kwd, end_kwd, nclip=10, no_scale=False):
    score, start_time, end_time = get_info(ser, score_key, start_kwd, end_kwd)
    cell_info = str(ser[cell_no])
    data_dict = ioo.read_sql_data(config, cell_info, start_time=start_time, end_time=end_time, no_scale=no_scale, nclip=nclip)
    return data_dict, score, cell_info
예제 #5
0
def get_vin_list(para_dict, mode):
    config = para_dict['config'][mode]
    vin_info = ioo.read_sql_data(config, para_dict['info_table_name'])
    print(vin_info)
    return vin_info
예제 #6
0
def find_sequence(table_name, showbar=None, total=100, t_keywords='stime', cur_keywords='current', 
                  time_gap=300, charge_time=100, discharge_time=100, valid_cnt=100,
                  start_index=0, **kwg):
    """
    #找到给定对数据中所有满足条件对充电1、静置0或放电2过程对应的数据起始与终止字段信息
    #通用的处理是根据电流值来进行判断
    #放电2:电流值<-1;充电1:>1:
    #充电charge_time和放电discharge_time过程小于设定值则认为过程无效,直接丢弃,并且不影响前后过程的判断,默认值300秒
    #充放电过程数据valid_cnt<100,无效,静置数据默认10
    #两个数据间格time_gap大于设定值,也认为是新的一个过程,默认值300秒
    #默认时间字段stime
    #start_index代表pro的起始编号
    """
    dis_current = -1
    cha_current = 1
    mode = kwg['run_mode']
    config = kwg['config'][mode]
    df = ioo.read_sql_data(config, table_name, limit=kwg['data_limit'][mode])
    print(df.shape.__str__())
    #filt samples on rows, if a row has too few none-nan value, drop it
    DROPNA_THRESH = df.shape[1]//5
    df = df.dropna(thresh=DROPNA_THRESH)
    df = df.rename(columns={t_keywords: 'stime'})
    df['stime'] = df['stime'].apply(str)
    df['stime'] = df['stime'].apply(lambda x: parser.parse(x))
    df = df.sort_values('stime')
    #增加每条数据的充放电状态,并将不符合条件的数据丢弃
    df['state'] = np.nan
    df['state'][df['current'] > cha_current] = 1
    df['state'][df['current'] < dis_current] = 2
    df['state'] = df['state'].fillna(0)
    #开始划分
    pro_df = []
    j_last = 0
    start_index = start_index
    df_len = len(df)
    per = df_len // total + 1
    if showbar != None:
        next(showbar)
    for j in range(1, df_len):
        state_cur = df['state'].iloc[j]
        state_last = df['state'].iloc[j - 1]
        if j >= (df_len - 1) or (df.iloc[j]['stime'] - df.iloc[j - 1]['stime']).seconds > time_gap or state_last != state_cur:
            cur_df = df.iloc[j_last:j]
            valid_flag = True
            cur_mean = cur_df[cur_keywords].mean(skipna=True)
            if cur_mean < dis_current: #放电
                cad_time = discharge_time
                state = 2 #'discharge'
            elif cur_mean > cha_current: #充电
                cad_time = charge_time
                state = 1 #'charge'
            else:
                valid_cnt = 1 #改写有效计数要求
                cad_time = valid_cnt
                state = 0 #'rest'
            if state_last != state_cur and (j - cad_time) < j_last:#电流状态改变持续时间不够条件
                valid_flag = False
            if valid_flag:
                tmp = get_process_info(cur_df, start_index, state, cad_time/10)
                if tmp is not None:
                    pro_df.append(tmp)
                start_index += 1   #只有满足条件了才改变     
                j_last = j
        valid_flag = False
        if showbar != None:
            r = showbar.send(j//per)
    pro_df = pd.concat(tuple(pro_df), axis=0)
    return pro_df