Example #1
0
def search_aei_suffix(ss_path, odb_folder_name):
    """
    在ss_path路径下搜索文件后缀,如果存在.AEI和.txt文件则对该文件进行读取
    :param ss_path: 需要搜索AEI文件的路径文件夹
    :param odb_folder_name:
    :return:
    """
    sfx_set = {}
    sfx_list = []
    aei_txt = None
    all_set = {'.AEI', '.txt'}
    file_list = listdir(ss_path)
    if len(file_list) != 0:
        for file in file_list:
            sfx = path.splitext(file)
            sfx_list.append(sfx[1])
            sfx_set = set(sfx_list)
            if sfx[1] == '.AEI':
                aei_dir = ss_path + '/' + file
                aei_txt = read_txt(aei_dir)  # 读取AEI文件
        diff = all_set.difference(sfx_set)
        if len(diff) != 0:
            for s in diff:
                if s not in sfx_list:
                    print('找不到%s文件,请重新检查数据!' % s)
                    info('找不到%s文件,请重新检查数据!' % s)
    else:
        print('%s文件夹中无可用文件,请重新传入文件!' % odb_folder_name)
        info('%s文件夹中无可用文件,请重新传入文件!' % odb_folder_name)
    return aei_txt
Example #2
0
def hex2decimal(hd_path):
    hex_list = []
    dec_list = []
    hex_txt = read_txt(hd_path)
    if len(hex_txt) == 1:
        hex_str = hex_txt[0]
        hex_count = len(hex_str) // 6
        hex_s = hex_str[:hex_count * 6]
        for c in range(hex_count):
            hex_single = hex_s[c * 6:(c + 1) * 6].split()
            hex_single = hex_single[1] + hex_single[0]
            dec_single = int(hex_single, 16)
            hex_list.append(hex_single)
            dec_list.append(dec_single)
    return hex_list, dec_list
Example #3
0
def txt_to_list(ttp_path):
    txt_set = []
    txt_name = listdir(ttp_path)
    for txt_signal_name in txt_name:
        xy_list = []
        txt_path = ttp_path + '\\' + txt_signal_name
        if path.exists(txt_path):
            x_list = []
            y_list = []
            txt = read_txt(txt_path)
            for t in txt:
                xy_t = t.strip().split()
                x_t = float(xy_t[0])
                y_t = float(xy_t[1])
                x_list.append(x_t)
                y_list.append(y_t)
            xy_list.append(x_list)
            xy_list.append(y_list)
        txt_set.append(xy_list)
    return txt_set
Example #4
0
    plt.grid()
    plt.subplot(234)
    plt.plot(new_wave[1])
    plt.grid()
    plt.subplot(235)
    plt.plot(new_wave[3])
    plt.grid()
    plt.subplot(236)
    plt.plot(new_wave[5])
    plt.grid()
    plt.show()


if __name__ == '__main__':
    # p = 'D:\\jaysk\\Desktop\\TP\\optical_fiber_data\\2020-07-01\\Available\\Data_20200701_160241.txt'
    p = 'D:\\jaysk\\Desktop\\TP\\optical_fiber_data\\2020-07-01\\Available\\Data_20200701_171736.txt'
    data = read_txt(p)
    d_a = read_fiber_data_simple(data)
    ttw_date_list, ttw_temp_list, ttw_wave_list = time_temp_wave(d_a)
    wave_all = wave_collection(ttw_wave_list)

    start_time = str(ttw_date_list[0])[:-7]
    # tw_txt = time_wave(ttw_date_list, wave_all)
    tw_txt = data_integration(start_time, wave_all)

    # 将6个传感器的数据保存成txt
    # save_path = 'D:\\jaysk\\Desktop\\TP\\optical_fiber_data\\2020-07-01\\Available\\Data_20200701_160241'
    save_path = 'D:\\jaysk\\Desktop\\TP\\optical_fiber_data\\2020-07-01\\Available\\Data_20200701_171736'
    for i in range(len(tw_txt)):
        writelines_txt(save_path + '\\%s.txt' % str(i + 1), tw_txt[i])
Example #5
0
def format_conversion(fc_path):
    """
    # TODO 读文件夹,存在文件则读取并进行格式转换,不存在则退出
    :param fc_path:该路径为主程序的相对路径
    :return:
    """
    fc_path = 'D:'
    # 加载配置文件
    original_db = conf.get_original_db_name()  # 获取Original_DB文件夹名称
    original_temp_db = conf.get_original_temp_db_name(
    )  # 获取Original_temp_DB文件夹名称
    config_frequency = int(conf.get_optical_fiber_frequency())
    decimal_places = len(str(1 / config_frequency)) - 2

    # 创建所需文件夹
    fc_original_db_path = folder_creation(fc_path, original_db)
    fc_original_temp_db_path = folder_creation(fc_path, original_temp_db)

    # 从Original_temp_DB下读取文件进行处理
    txt_output = []
    txt_content = listdir(fc_original_temp_db_path)
    if len(txt_content) != 0:
        for txt_file_name in txt_content:
            if txt_file_name[-4:] == '.txt':
                txt_ = read_txt(fc_original_temp_db_path + '\\' +
                                txt_file_name)  # txt文档读取
                _txt = txt_[1:]  # 数据截取

                # 时间格式获取
                date_time = txt_[0].strip()
                datetime_ = datetime.fromisoformat(date_time)
                time_delay = timedelta(microseconds=(10**6 / config_frequency))

                for i in range(len(_txt)):
                    time_ = str(datetime_ + time_delay * i)
                    if len(_txt[i]) > 1:
                        format_time = ''
                        if len(time_) == 26:
                            format_time = time_[:20 + decimal_places].replace(
                                '.', ':')
                        elif len(time_) == 19:
                            format_time = time_ + ':' + '0' * decimal_places
                        txt_data = _txt[i].strip()
                        if len(txt_data) == 7:
                            txt_new_ = txt_data[:4] + '.' + txt_data[4:] + '0\n'
                            format_single_data = format_time + ',' + txt_new_
                            txt_output.append(format_single_data)
                        else:
                            # format_single_data = format_time + ',' + _txt[i].strip() + '\n'
                            format_single_data = format_time + ',' + _txt[i]
                            txt_output.append(format_single_data)
                if txt_file_name == '4.txt':
                    txt_file_name = '3.txt'
                elif txt_file_name == '5.txt':
                    txt_file_name = '4.txt'
                elif txt_file_name == '6.txt':
                    txt_file_name = '5.txt'
                elif txt_file_name == '3.txt':
                    txt_file_name = '6.txt'
                elif txt_file_name == '12.txt':
                    txt_file_name = '7.txt'
                elif txt_file_name == '11.txt':
                    txt_file_name = '8.txt'
                elif txt_file_name == '10.txt':
                    txt_file_name = '9.txt'
                elif txt_file_name == '8.txt':
                    txt_file_name = '10.txt'
                elif txt_file_name == '7.txt':
                    txt_file_name = '11.txt'
                elif txt_file_name == '9.txt':
                    txt_file_name = '12.txt'
                if len(txt_file_name) == 5:
                    txt_file_name = '0' + txt_file_name  # 统一文件名称:01.txt~12.txt
                writelines_txt(fc_original_db_path + '\\' + txt_file_name,
                               txt_output)
                txt_output = []
            elif txt_file_name[-4:] == '.AEI':
                move(fc_original_temp_db_path + '\\' + txt_file_name,
                     fc_original_db_path + '\\' + txt_file_name)