1.实现将Ta里程更新到S文件中。

This commit is contained in:
facat 2020-05-14 12:25:41 +08:00
parent a594030e5e
commit 9784bce362
1 changed files with 69 additions and 4 deletions

View File

@ -68,6 +68,22 @@ class SFileObject:
content = self._content
content[index][7] = new_height
# 更新档距
def update_all_mileage(self, new_mileage_dic):
content = list(self._content)
first_tower_number_in_s = self._content[2][0]
tower_mileage_of_first_tower_in_ta = new_mileage_dic[first_tower_number_in_s]
for index, s_entry in enumerate(self._content):
if s_entry[0] == "首端转角号" or s_entry[0] == "塔号":
continue
tower_number = s_entry[0]
if tower_number in new_mileage_dic:
new_mileage = (
new_mileage_dic[tower_number] - tower_mileage_of_first_tower_in_ta
)
content[index][1] = new_mileage
self._content = content
# 把所有S文件当做一个来操作
class SFileAsSingle:
@ -98,6 +114,16 @@ class SFileAsSingle:
s_file_obj.write(s_output_file_path)
print("update S file {Ss}".format(Ss=s_output_file_path))
# 写入一次S文件
def update_all_mileage(self, new_mileage_dic):
s_file = self._s_files
for s in s_file:
s_object = SFileObject(s)
s_object.update_all_mileage(new_mileage_dic)
s_output_file_path = s_object.file_path
s_object.write(s_output_file_path)
print("update mileage in S file {Ss}".format(Ss=s_output_file_path))
def content(self):
s_file = self._s_files
for s in s_file:
@ -114,6 +140,7 @@ class TaFileObject:
self._read(file_path)
self._old_tower_height_record = None
self._SFile = SFile
self._old_span_record = None # 档距
pass
def _read(self, file_path):
@ -128,7 +155,8 @@ class TaFileObject:
contents.append(sep)
return contents
def _make_tower_height_record(self, contents): # 将TA文件读入内存字典中
@staticmethod
def _make_tower_height_record(contents): # 将TA文件读入内存字典中
tower_height_record = {}
for content in contents:
sep = content
@ -138,10 +166,21 @@ class TaFileObject:
tower_height_record[tower_number] = tower_height
return tower_height_record
def sync_changed_tower_height_to_S(self, new_contents, old_tower_height_record):
# def _make_span_record(self, ta_content): # 将TA 文件档距读入字典中。
# tower_span_record = {}
# basic_mileage = 0
# for ta_entry in ta_content:
# if len(ta_entry) > 2:
# tower_number = ta_entry[0]
# tower_mileage = ta_entry[2]
# tower_span_record[tower_number] = tower_mileage - basic_mileage
# basic_mileage = tower_mileage
# return tower_span_record
def sync_changed_tower_height_to_S(self, ta_new_contents, old_tower_height_record):
updated = False
for content in new_contents:
sep = content
for ta_entry in ta_new_contents:
sep = ta_entry
if len(sep) > 9:
tower_number = sep[0]
old_tower_height = float(old_tower_height_record[tower_number])
@ -160,6 +199,32 @@ class TaFileObject:
updated = True
return updated
def sync_all_tower_mileage_to_s(self):
ta_new_contents = self._read(self._file_path)
new_mileage_dic = {}
for ta_entry in ta_new_contents:
if len(ta_entry)>2:
tower_number = ta_entry[0]
new_tower_mileage = float(ta_entry[2])
new_mileage_dic[tower_number] = new_tower_mileage
SFile = self._SFile
s_as_single = SFileAsSingle(SFile)
s_as_single.update_all_mileage(new_mileage_dic)
# # 同步Ta文件中修改过的档距。
# @staticmethod
# def sync_changed_tower_span_to_s(ta_new_contents, old_tower_span_record):
# for ta_entry in ta_new_contents:
# tower_number = ta_entry[0]
# old_tower_span = float(old_tower_span_record[tower_number])
# new_tower_span = float(ta_entry[2])
# if abs(old_tower_span - new_tower_span) > 1e-5:
# print(
# "{tower_number} span changes to {new_tower_span}".format(
# tower_number=tower_number, new_tower_span=new_tower_span
# )
# )
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":