From 452c582590467b46137d133620d9ed2f0fcce4d8 Mon Sep 17 00:00:00 2001 From: facat Date: Sat, 14 Nov 2020 13:44:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=91=BD=E4=BB=A4=E8=A1=8C?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 6 +++++ cli.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ file_object.py | 16 ++++++++----- generate_ta.py | 2 +- main.py | 11 ++++++--- 5 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 .gitignore create mode 100644 cli.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3f82f --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# created by virtualenv automatically +__pycache__ +Scripts +.idea +Lib +pyvenv.cfg \ No newline at end of file diff --git a/cli.py b/cli.py new file mode 100644 index 0000000..e0d1f84 --- /dev/null +++ b/cli.py @@ -0,0 +1,61 @@ +import click +from generate_ta import generate_ta_from_D +from file_object import TaFileObject + + +@click.group() +def cli(): + pass + + +# 注意d_files和s_files中文件名的顺序 +@click.command() +@click.option("--s_files", help="s文件。以;分割") +@click.option("--d_files", help="d文件。以;分割") +@click.option("--ta_file", help="生成的Ta文件") +def generate_ta_file(s_files: str, d_files: str, ta_file: str): + s_files_list = s_files.split(",") + d_files_list = d_files.split(",") + generate_ta_from_D(ta_file, s_files_list, d_files_list) + print("生成Ta文件:{ta_file}".format(ta_file=ta_file)) + pass + + +# 将Ta文件里程同步到S文件中 +@click.command() +@click.option("--s_files", help="s文件。以;分割") +@click.option("--ta_file", help="Ta文件") +def sync_all_tower_mileage_to_s(s_files: str, ta_file: str): + s_files_list = s_files.split(",") + ta_object = TaFileObject(ta_file, s_files_list) + ta_object.sync_all_tower_mileage_to_s() + print('同步TA文件中里程到S文件') + + +# 将Ta文件塔高同步到S文件中 +@click.command() +@click.option("--s_files", help="s文件。以;分割") +@click.option("--ta_file", help="Ta文件") +def sync_all_tower_height_from_TA_to_S(s_files: str, ta_file: str): + s_files_list = s_files.split(",") + ta_object = TaFileObject(ta_file, s_files_list) + ta_object.sync_all_tower_height_from_TA_to_S(prompt=False) + print('同步TA文件中塔高到S文件') + + +# @click.command() +# @click.option('--count', default=1, help='Number of greetings.') +# @click.option('--name', prompt='Your name', +# help='The person to greet.') +# def hello(count, name): +# """Simple program that greets NAME for a total of COUNT times.""" +# for x in range(count): +# click.echo('Hello %s!' % name) + + +cli.add_command(generate_ta_file) +cli.add_command(sync_all_tower_mileage_to_s) +cli.add_command(sync_all_tower_height_from_TA_to_S) + +if __name__ == "__main__": + cli() diff --git a/file_object.py b/file_object.py index f56a35f..3ed52d8 100644 --- a/file_object.py +++ b/file_object.py @@ -41,6 +41,7 @@ class SFileObject: def _save_backup(self, back_file_path): shutil.copy(self.file_path, back_file_path) + # 将数据按行写入S数据文件 def write(self, target_file_path): (file_name, ext) = get_file_name_with_extention(self.file_path) src_file_dir = get_directory(self.file_path) @@ -91,7 +92,7 @@ class SFileAsSingle: self._s_files = s_files # 考虑不同位置处出现塔号的情况 - # 打开一次S文件 + # 这个函数需要打开一次S文件 def has(self, tower_number) -> [(SFileObject, int)]: s_file = self._s_files ret = [] @@ -203,7 +204,7 @@ class TaFileObject: ta_new_contents = self._read(self._file_path) new_mileage_dic = {} for ta_entry in ta_new_contents: - if len(ta_entry)>2: + 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 @@ -225,10 +226,13 @@ class TaFileObject: # ) # ) - 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 + def sync_all_tower_height_from_TA_to_S(self, prompt=True): + if prompt: + 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 diff --git a/generate_ta.py b/generate_ta.py index 51778e0..b668d6f 100644 --- a/generate_ta.py +++ b/generate_ta.py @@ -43,7 +43,7 @@ def prepare_TA_entry_without_altitude(SFiles): visited_tower_number[tower_number] = 0 else: continue - mileage = int(S_entry[1]) + last_S_mileage + mileage = int(float(S_entry[1])) + last_S_mileage _entry["mileage"] = mileage tower_height = float(S_entry[7]) _entry["tower_height"] = tower_height diff --git a/main.py b/main.py index d0d3561..ed71cb8 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import generate_ta from file_object import TaFileObject, DFileAsSingle from file_object import DFileObject +import gui if __name__ == "__main__1": SFile = [ @@ -21,9 +22,13 @@ if __name__ == "__main__1": if __name__ == "__main__": SFile = [r"d:\道亨排位\流程测试\S034.DAT"] DFile = [r"d:\道亨排位\流程测试\D034.TXT", r"d:\道亨排位\流程测试\D038.TXT"] - ta_object = TaFileObject(r"d:\道亨排位\流程测试\ 流程测试\ 流程测试.TA", SFile) - d_file_object = DFileObject(r"d:\道亨排位\流程测试\D034.TXT") + ta_object = TaFileObject(r"d:\道亨排位\流程测试\流程测试.TA", SFile) + # ta_object.start() + # d_file_object = DFileObject(r"d:\道亨排位\流程测试\D034.TXT") # d_as_single = DFileAsSingle(DFile) # print(d_as_single.get_altitude(1956+13)) - generate_ta.generate_ta_from_D(r"d:\道亨排位\流程测试\ 流程测试\ 流程测试.TA", SFile, DFile) + # generate_ta.generate_ta_from_D(r"d:\道亨排位\流程测试\流程测试.TA", SFile, DFile) + ta_object.sync_all_tower_mileage_to_s() + # app=gui.app() + # app.main_loop() print("Finished.")