1.增加同步全部TA中的呼高到S文件中的功能。
This commit is contained in:
parent
b1e993dbf5
commit
610d196009
|
|
@ -18,7 +18,7 @@ def get_file_name_with_extention(file_path):
|
|||
dir_part = get_directory(file_path)
|
||||
file_name = file_path.replace(dir_part, "").replace("\\", "").replace(r"/", "")
|
||||
(name, ext) = file_name.split(".")
|
||||
return (name, ext)
|
||||
return name, ext
|
||||
|
||||
|
||||
class SFileObject:
|
||||
|
|
@ -55,7 +55,7 @@ class SFileObject:
|
|||
file.write("{content}\n".format(content=" ".join(_content)))
|
||||
|
||||
def has(self, tower_number): # 塔位号是否存在S文件中。可能存在多行的情况。
|
||||
indexes=[]
|
||||
indexes = []
|
||||
for index, content in enumerate(self._content):
|
||||
if content[0] == tower_number:
|
||||
indexes.append(index)
|
||||
|
|
@ -75,6 +75,7 @@ class SFileAsSingle:
|
|||
self._s_files = s_files
|
||||
|
||||
# 考虑不同位置处出现塔号的情况
|
||||
# 打开一次S文件
|
||||
def has(self, tower_number) -> [(SFileObject, int)]:
|
||||
s_file = self._s_files
|
||||
ret = []
|
||||
|
|
@ -85,6 +86,7 @@ class SFileAsSingle:
|
|||
ret.append((d_file_obj, index))
|
||||
return ret
|
||||
|
||||
# 写入一次S文件
|
||||
def update_height(self, result: [(SFileObject, int)], new_height):
|
||||
s_changed_record = {}
|
||||
for s_file_obj, index in result:
|
||||
|
|
@ -135,7 +137,7 @@ class TaFileObject:
|
|||
tower_height_record[tower_number] = tower_height
|
||||
return tower_height_record
|
||||
|
||||
def sync_tower_height_to_S(self, new_contents, old_tower_height_record):
|
||||
def sync_changed_tower_height_to_S(self, new_contents, old_tower_height_record):
|
||||
updated = False
|
||||
for content in new_contents:
|
||||
sep = content
|
||||
|
|
@ -157,6 +159,22 @@ class TaFileObject:
|
|||
updated = True
|
||||
return updated
|
||||
|
||||
def sync_all_tower_height_from_TA_to_S(self):
|
||||
enter_string = input("Will synchronize all height from TA to S. Enter AH2S:\n")
|
||||
if enter_string.lower() != "ah2s":
|
||||
return
|
||||
ta_content = self._read(self._file_path)
|
||||
for entry in ta_content:
|
||||
sep = entry
|
||||
if len(sep) > 9:
|
||||
tower_number = sep[0]
|
||||
new_tower_height = float(sep[9])
|
||||
s_files = self._SFile
|
||||
s_as_single = SFileAsSingle(s_files)
|
||||
result = s_as_single.has(tower_number)
|
||||
if len(result) > 0:
|
||||
s_as_single.update_height(result, new_tower_height)
|
||||
|
||||
# 将S文件中的塔高同步到TA文件中。
|
||||
def sync_tower_height_from_S(self):
|
||||
enter_string = input(
|
||||
|
|
@ -224,7 +242,9 @@ class TaFileObject:
|
|||
self._old_tower_height_record = self._make_tower_height_record(
|
||||
new_contents
|
||||
)
|
||||
if self.sync_tower_height_to_S(new_contents, self._old_tower_height_record):
|
||||
if self.sync_changed_tower_height_to_S(
|
||||
new_contents, self._old_tower_height_record
|
||||
):
|
||||
self._old_tower_height_record = self._make_tower_height_record(
|
||||
new_contents
|
||||
)
|
||||
|
|
|
|||
11
main.py
11
main.py
|
|
@ -4,13 +4,14 @@ from file_object import TaFileObject
|
|||
if __name__ == "__main__":
|
||||
SFile = [
|
||||
r"d:\工程\灵州-青山\排位\0-21\S000.DAT",
|
||||
r"d:\工程\灵州-青山\排位\21-52\S021.DAT",
|
||||
r"d:\工程\灵州-青山\排位\52-68\S052.DAT",
|
||||
r"d:\工程\灵州-青山\排位\68-72\S068.DAT",
|
||||
r"d:\工程\灵州-青山\排位\72-169\S072.DAT",
|
||||
# r"d:\工程\灵州-青山\排位\21-52\S021.DAT",
|
||||
# r"d:\工程\灵州-青山\排位\52-68\S052.DAT",
|
||||
# r"d:\工程\灵州-青山\排位\68-72\S068.DAT",
|
||||
# r"d:\工程\灵州-青山\排位\72-169\S072.DAT",
|
||||
]
|
||||
ta_object = TaFileObject(r"d:\工程\灵州-青山\排位\道亨\最终排位\最终排位.TA", SFile)
|
||||
# ta_object.sync_tower_height_from_S()
|
||||
ta_object.start()
|
||||
# ta_object.start()
|
||||
ta_object.sync_all_tower_height_from_TA_to_S()
|
||||
# generate_ta_from_csv.generate_ta(r"d:\工程\灵州-青山\排位\道亨\最终排位\最终排位.TA",SFile,r'd:\工程\灵州-青山\排位\道亨\成果表.csv')
|
||||
print("Finished.")
|
||||
|
|
|
|||
Loading…
Reference in New Issue