From 96b91378691b50b057dfcca957abbd8587ab4f91 Mon Sep 17 00:00:00 2001 From: facat Date: Wed, 13 May 2020 17:24:49 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=86=99=E5=85=A5?= =?UTF-8?q?Ta=E6=96=87=E4=BB=B6=E6=97=B6=E6=B2=A1=E6=9C=89=E5=86=99?= =?UTF-8?q?=E5=85=A5=E7=9B=B4=E7=BA=BF=E5=A1=94=E7=9A=84bug=E3=80=82=202.?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=B2=A1=E6=9C=89=E5=AD=98=E5=8F=96?= =?UTF-8?q?=E7=9B=B4=E7=BA=BF=E5=A1=94=E4=B8=B2=E9=95=BF=E7=9A=84bug?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file_object.py | 1 + generate_ta.py | 160 +++++++++++++++++++++++++++++++------------------ main.py | 5 +- 3 files changed, 107 insertions(+), 59 deletions(-) diff --git a/file_object.py b/file_object.py index c049cab..b9e3e7a 100644 --- a/file_object.py +++ b/file_object.py @@ -92,6 +92,7 @@ class SFileAsSingle: for s_file_obj, index in result: s_file_obj.update_height(index, new_height) s_changed_record[s_file_obj] = 1 + # 输出变化的文件名 for s_file_obj in s_changed_record: s_output_file_path = s_file_obj.file_path s_file_obj.write(s_output_file_path) diff --git a/generate_ta.py b/generate_ta.py index 9897913..2b4b781 100644 --- a/generate_ta.py +++ b/generate_ta.py @@ -1,4 +1,4 @@ -from file_object import SFileObject, CordinationObject +from file_object import SFileObject, CordinationObject, DFileAsSingle TA_ENTRY_TEMPLATE = "{tower_number},{suspend_or_tension},{mileage}, {conductor_suspension_poit},0.3212,0.000,{altitude},{pile_number},{tower_name}_{tower_height},{tower_height},{string_name},{string_length}, 0.000,0.1142,0.000000,0.000000,,15,15.500000,,{angel},2.5,15.5,2.500,3.000,1,610.4,2.000,0,2,0,2,{conductor_type},GJ-50,0,0,0,0.000,,0,0.000,9,750,1.000,,0,0.000,0,750,1.000,ZHCH_1,28,1.000,9.5,750,1.000,9.5,750,1.000,{string_name},1,{string_length},{string_name},1,{string_length},,0,0.000,,0,0.000,0,0,0.000, 0.000,0,0,0.000,0,0,4.000,0,1,1.000,,0,0.000,,0,0.000,,0,0.000,1,1,0.000,0,0,0.000, 0.000,0,0, 0.000,1.000,1.000,0.000,0.000,0.000,,0,\n" TA_NC_STRING_NAME = "750-NC" @@ -17,63 +17,109 @@ def is_tension_tower_by_string(string_name): return 2 return 1 -# SFiles中的文件必须是按顺序排列的` -def generate_ta_from_D(TA_file, SFiles, D_file_path): - visited_tower_number = {} # 记录访问过的塔号 - cord_file_object = CordinationObject(cordination_file_path) - with open(TA_file, "w") as file: - # 生成所有需要用到的数据 - last_S_mileage = 0 - for S in SFiles: - SObj = SFileObject(S) - S_content = SObj.content() - for S_entry in S_content: - if S_entry[0] == "首端转角号" or S_entry[0] == "塔号": - continue - tower_number = S_entry[0] - if tower_number not in visited_tower_number: - visited_tower_number[tower_number] = 0 - else: - continue - mileage = int(S_entry[1]) + last_S_mileage - tower_height = float(S_entry[7]) - angel = S_entry[5] - string_name = S_entry[8] - suspend_or_tension = is_tension_tower_by_string(string_name) - conductor_type = TA_CONDUCTOR_TYPE - # 1是悬垂 2是耐张 - if suspend_or_tension == 1: - string_length = TA_XC_STRING_LENGTH - conductor_suspension_poit = tower_height - string_length - pile_number = tower_number - ta_string_name = TA_XC_STRING_NAME - tower_name = TA_XC_TOWER_NAME - else: - string_length = TA_NC_STRING_LENGTH - conductor_suspension_poit = tower_height - pile_number = tower_number - ta_string_name = TA_NC_STRING_NAME - tower_name = TA_NC_TOWER_NAME - altitude = cord_file_object.get_altitude(pile_number) - file.write( - TA_ENTRY_TEMPLATE.format( - tower_number=tower_number, - suspend_or_tension=suspend_or_tension, - mileage=mileage, - conductor_suspension_poit=conductor_suspension_poit, - altitude=altitude, - pile_number=pile_number, - tower_name=tower_name, - tower_height=tower_height, - string_name=ta_string_name, - string_length=string_length, - angel=angel, - conductor_type=conductor_type, - ) - ) - last_S_mileage = float(S_content[-1][1]) + last_S_mileage -# SFiles中的文件必须是按顺序排列的` +def prepare_TA_entry_without_altitude(SFiles): + visited_tower_number = {} # 记录访问过的塔号 + last_S_mileage = 0 + ta_entry = [] + for S in SFiles: + SObj = SFileObject(S) + S_content = SObj.content() + for S_entry in S_content: + _entry = {} + if S_entry[0] == "首端转角号" or S_entry[0] == "塔号": + continue + tower_number = S_entry[0] + _entry["tower_number"]=tower_number + if tower_number not in visited_tower_number: + visited_tower_number[tower_number] = 0 + else: + continue + mileage = int(S_entry[1]) + last_S_mileage + _entry["mileage"] = mileage + tower_height = float(S_entry[7]) + _entry["tower_height"] = tower_height + angel = S_entry[5] + _entry["angel"] = angel + string_name = S_entry[8] + suspend_or_tension = is_tension_tower_by_string(string_name) + _entry["suspend_or_tension"] = suspend_or_tension + conductor_type = TA_CONDUCTOR_TYPE + _entry["conductor_type"] = conductor_type + # 1是悬垂 2是耐张 + if suspend_or_tension == 1: + string_length = TA_XC_STRING_LENGTH + _entry["string_length"] = string_length + conductor_suspension_point = tower_height - string_length + _entry["conductor_suspension_point"] = conductor_suspension_point + pile_number = tower_number + _entry["pile_number"] = pile_number + ta_string_name = TA_XC_STRING_NAME + _entry["ta_string_name"] = ta_string_name + tower_name = TA_XC_TOWER_NAME + _entry["tower_name"] = tower_name + else: + string_length = TA_NC_STRING_LENGTH + _entry["string_length"] = string_length + conductor_suspension_point = tower_height + _entry["conductor_suspension_point"] = conductor_suspension_point + pile_number = tower_number + _entry["pile_number"] = pile_number + ta_string_name = TA_NC_STRING_NAME + _entry["ta_string_name"] = ta_string_name + tower_name = TA_NC_TOWER_NAME + _entry["tower_name"] = tower_name + ta_entry.append(_entry) + last_S_mileage = float(S_content[-1][1]) + last_S_mileage + return ta_entry + + +def write_to_TA_file(TA_file, ta_entry): + with open(TA_file, "w") as file: + for entry in ta_entry: + tower_number = entry["tower_number"] + suspend_or_tension = entry["suspend_or_tension"] + mileage = entry["mileage"] + conductor_suspension_point = entry["conductor_suspension_point"] + altitude = entry["altitude"] + pile_number = entry["pile_number"] + tower_name = entry["tower_name"] + tower_height = entry["tower_height"] + ta_string_name = entry["ta_string_name"] + string_length = entry["string_length"] + angel = entry["angel"] + conductor_type = entry["conductor_type"] + file.write( + TA_ENTRY_TEMPLATE.format( + tower_number=tower_number, + suspend_or_tension=suspend_or_tension, + mileage=mileage, + conductor_suspension_poit=conductor_suspension_point, + altitude=altitude, + pile_number=pile_number, + tower_name=tower_name, + tower_height=tower_height, + string_name=ta_string_name, + string_length=string_length, + angel=angel, + conductor_type=conductor_type, + ) + ) + + +# SFiles中的文件必须是按顺序排列的 +def generate_ta_from_D(TA_file, SFiles, D_files_paths): + # 准备要写入的文件 + ta_entry_without_altitude = prepare_TA_entry_without_altitude(SFiles) + d_file_object = DFileAsSingle(D_files_paths) + ta_entry = list(ta_entry_without_altitude) + for entry in ta_entry: + mileage = entry["mileage"] + entry["altitude"] = d_file_object.get_altitude(mileage) + write_to_TA_file(TA_file, ta_entry) + + +# SFiles中的文件必须是按顺序排列的 def generate_ta_from_csv(TA_file, SFiles, cordination_file_path): visited_tower_number = {} # 记录访问过的塔号 cord_file_object = CordinationObject(cordination_file_path) diff --git a/main.py b/main.py index 848e4d2..d0d3561 100644 --- a/main.py +++ b/main.py @@ -23,6 +23,7 @@ if __name__ == "__main__": DFile = [r"d:\道亨排位\流程测试\D034.TXT", r"d:\道亨排位\流程测试\D038.TXT"] ta_object = TaFileObject(r"d:\道亨排位\流程测试\ 流程测试\ 流程测试.TA", SFile) d_file_object = DFileObject(r"d:\道亨排位\流程测试\D034.TXT") - d_as_single = DFileAsSingle(DFile) - print(d_as_single.get_altitude(1956+13)) + # d_as_single = DFileAsSingle(DFile) + # print(d_as_single.get_altitude(1956+13)) + generate_ta.generate_ta_from_D(r"d:\道亨排位\流程测试\ 流程测试\ 流程测试.TA", SFile, DFile) print("Finished.")