1.重构了generate_ta_from_csv功能。

2.重新对过长的字符串排版。
This commit is contained in:
facat 2020-05-13 17:33:07 +08:00
parent 96b9137869
commit a594030e5e
1 changed files with 16 additions and 54 deletions

View File

@ -1,6 +1,14 @@
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_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"
TA_NC_STRING_LENGTH = 14
TA_NC_TOWER_NAME = "WNSJ"
@ -30,7 +38,7 @@ def prepare_TA_entry_without_altitude(SFiles):
if S_entry[0] == "首端转角号" or S_entry[0] == "塔号":
continue
tower_number = S_entry[0]
_entry["tower_number"]=tower_number
_entry["tower_number"] = tower_number
if tower_number not in visited_tower_number:
visited_tower_number[tower_number] = 0
else:
@ -121,56 +129,10 @@ def generate_ta_from_D(TA_file, SFiles, D_files_paths):
# SFiles中的文件必须是按顺序排列的
def generate_ta_from_csv(TA_file, SFiles, cordination_file_path):
visited_tower_number = {} # 记录访问过的塔号
ta_entry_without_altitude = prepare_TA_entry_without_altitude(SFiles)
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
ta_entry = list(ta_entry_without_altitude)
for entry in ta_entry:
pile_number = entry["tower_number"]
entry["altitude"] = cord_file_object.get_altitude(pile_number)
write_to_TA_file(TA_file, ta_entry)