Skip to content

Commit

Permalink
Lima v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Eyderoe committed Oct 24, 2023
1 parent c7ac931 commit 43b8070
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 41 deletions.
52 changes: 45 additions & 7 deletions Terminal Procedure/terminalFunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
RNP数值计算 √
重构pandas读取 有点问题又把第一行当表头读取了 √
CF(航向到航点)检查一下
有时间再把程序重新写写
进近最后不会显示锚定点 ??? 没有一点头猪
Cpp见证虔诚的信徒,Python诞生虚伪的屎山。 √
"""
Expand All @@ -33,6 +34,18 @@ def printf(string: str, exiting: bool):
print("<进程> " + string)


logPath = ""


def log_record(anything, enter=0):
global logPath
log = open(logPath, 'a+', encoding='utf-8')
for i in range(enter):
log.write('\n')
log.write(str(anything))
log.close()


class Info:
# 仅结构体,仅存放需要二次处理的数据
# 由于结构混乱,有些东西来不及printf就在这里报错了。应该?
Expand All @@ -50,7 +63,7 @@ def set(self, header: list, content: list):
self.runway = [].copy()
self.alfa = [].copy()
if not os.path.isdir(header[1]):
printf("不存在该路径", True)
printf("不存在该路径{}".format(header[1]), True)
if header[0].count(',') != 6:
printf("程序头第一行错误", True)
self.runway = header[0].split(',')[4]
Expand All @@ -77,6 +90,7 @@ def set(self, header: list, content: list):
# printf("procedure name error", True)
self.transAltitude = header[0].split(',')[5]
self.rfFull = bool(int(header[0].split(',')[6]))
log_record("结构体检查通过",1)


namelist = []
Expand Down Expand Up @@ -104,11 +118,13 @@ def rank(a):
excelGlobal = ExcelFile(xlsx)
db = read_excel(excelGlobal, sheet_name=None)
temp = list(db.keys())
log_record("所有工作表: " + str(temp) + "\n")
global namelist
for i in temp:
if ("appr" in i.lower()) or ("sid" in i.lower()) or ("star" in i.lower()):
namelist.append(i)
namelist = sorted(namelist, key=rank)
log_record("有效工作表: " + str(namelist))
return namelist


Expand Down Expand Up @@ -173,17 +189,24 @@ def spawn_proc(file_path):
建立工作表名称列表
工作表写入临时文件
"""
base_path, base_name = os.path.split(file_path)
path_log = os.path.join(base_path, "log.md")
path_all = file_path[:file_path.index('.')] + ".proc"
path_temp = file_path[:file_path.index('.')] + ".temp"
file_all = open(path_all, 'w', encoding="utf-8")
file_all.close()
path_all = open(path_temp, 'w', encoding="utf-8")
path_all.close()
global logPath
logPath = path_log
path_all = open(path_log, 'w', encoding="utf-8")
path_all.close()

sheet_list = est_name(file_path)

for i in sheet_list:
trans_table(file_path, i)
log_record("\n读取到{}个程序".format(procCount))
printf("加载程序数量: " + str(procCount), False)


Expand All @@ -205,6 +228,12 @@ def get_proc(vnv):
temp_file.close()
if not combine:
return -1, -1
log_record("获取程序", 2)
log_record("程序头部" + str(combine[:2]), 1)
log_record("程序内容" + str(combine[2:]), 1)
for i in combine[2:]:
if os.path.isdir(i):
printf("_QED存在缺失",True)
return combine[:2].copy(), combine[2:].copy()


Expand Down Expand Up @@ -237,7 +266,13 @@ def info_check(multi_info: str, path: str):
pass # 假如直接从little navmap里面导出就可能导致没有后面那几个
earth_fix.close()
# 检查跑道是否正确
airport_data = open(os.path.join(path, "GNS430/navdata/Airports.txt"), 'r')
# * 有些环境下可能出现路径错误的情况 所以这样改
path_list = ["GNS430", "navdata", "Airports.txt"]
for i in path_list:
path = os.path.join(path, i)
if not os.path.exists(path):
printf("路径{}不存在".format(path), True)
airport_data = open(path, 'r')
bottom = False
runways = [] # 所有跑道
for i_line in airport_data:
Expand All @@ -256,7 +291,7 @@ def info_check(multi_info: str, path: str):
runway = refer.runway # 程序跑道
for i in runway:
if i not in runways:
printf("机场跑道错误,可能是: ".format(airport) + (lambda x: ','.join(x))(runways), True)
printf("机场{}跑道错误,可能是: ".format(airport) + (lambda x: ','.join(x))(runways), True)


def locate(listy: list) -> dict:
Expand Down Expand Up @@ -453,6 +488,7 @@ def del_words(string: str, words: list): # 重写代码的乐趣 有病是吧
if _type == 'A' and False:
for i in proc:
print(i)
log_record("程序复杂处理" + str(proc), 1)
return proc


Expand Down Expand Up @@ -500,6 +536,7 @@ def digit_process(x: str, front: int, back: int) -> str:

location = locate(content)
now = content[timer].split(',')
log_record("当前航点: " + str(now), 1)
key_word = [' '] * 38
# 1.程序类型+编号
if refer.typist == 'A': # APPR
Expand Down Expand Up @@ -545,11 +582,11 @@ def digit_process(x: str, front: int, back: int) -> str:
na = now[0] # now alfa
key_word[3] = "RW" + _nr if na == 'M' else content[location[na][0] + location[na][1] - 1].split(',')[1]
# 5.航路点 Fix Identifie
key_word[4] = now[1] if 'V' not in now else "RW" + now[1]
if 'V' in now and now[1] in refer.runway:
key_word[4] = now[1]
if ('V' in now) and (now[1] in refer.runway):
key_word[4] = "RW" + now[1]
else:
key_word[4] = now[1]
if ('V' in now) and (now[1] not in refer.runway) and (len(now[1]) <= 3):
print("<警戒!> 考虑进近跑道错误")
if refer.typist == 'S' and timer == 0: # 打的第一个补丁
key_word[4] = "RW" + now[1]
# 6.7.8.ICAO Code
Expand Down Expand Up @@ -735,4 +772,5 @@ def digit_process(x: str, front: int, back: int) -> str:
if ('V' in now) and ("RW" not in key_word[4]):
key_word[7] = 'C'
key_word[8] = "EY M"
log_record("当前航点编码"+'['+','.join(key_word)+']',1)
return ','.join(key_word) # 怎么是620 不是 520 艹
53 changes: 31 additions & 22 deletions Terminal Procedure/terminalMain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import traceback

import terminalFunc as func

# 1. 将xlsx文件转换为文本
Expand All @@ -8,25 +10,32 @@

# 读取并处理xlsx文件
xlsxPath = r"D:\Python项目\Terminal\存档\zhny.xlsx"
func.spawn_proc(xlsxPath)
while True:
# 从.temp文件拿一个程序
header, _content = func.get_proc(xlsxPath)
if header == -1:
break
try:
func.printf("{} / {}".format(func.clock - 1, func.procCount), False)
except TypeError: # 忘了 反正可能会报
pass
# 程序校验
func.refer.set(header, _content)
func.info_check(header[0], header[1])
# 程序修改
content = func.complex_process(header[0], _content)
# 程序写入
for i in range(len(content)):
output = func.encode(content, i)
func.write2file(xlsxPath, output)
if False:
func.write2file(xlsxPath, '')
os.remove(xlsxPath[:-4] + "temp")
try:
func.spawn_proc(xlsxPath)
while True:
# 从.temp文件拿一个程序
header, _content = func.get_proc(xlsxPath)
if header == -1:
break
try:
func.printf("{} / {}".format(func.clock - 1, func.procCount), False)
except TypeError: # 忘了 反正可能会报
pass
# 程序校验
func.refer.set(header, _content)
func.info_check(header[0], header[1])
# 程序修改
content = func.complex_process(header[0], _content)

# 程序写入
for i in range(len(content)):
output = func.encode(content, i)
func.write2file(xlsxPath, output)
if False:
func.write2file(xlsxPath, '')
os.remove(xlsxPath[:-4] + "temp")
os.remove(func.logPath)
except Exception as error:
func.log_record(traceback.format_exc(),2)
print("错误源:", error)
func.printf("程序出现未知错误 检查log.md", True)
7 changes: 7 additions & 0 deletions tools/fixTransform/fixSample3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
NY404 N30 30.333 E100 30.333
NY405 N30 30.444 E 100 30.444
NY406 N 30 30.553 E100 30.553
NY406 N 30 30.553 E 100 30.553

特点:
航点 纬度 纬分 经度 经分
8 changes: 4 additions & 4 deletions tools/fixTransform/fixTransform.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fixTransformFunc as fTF

# 程序只针对国区进行优化
filePath = "t1.txt"
airport = "ZUMY"
fixList, locList = fTF.rough_process(filePath)
filePath = "test.txt"
airport = "zumy"
fixList, locList = fTF.rough_process(filePath, 3)
locList = fTF.location_process(locList)
fTF.encoding(airport,filePath,fixList,locList)
fTF.encoding(airport, filePath, fixList, locList)
44 changes: 36 additions & 8 deletions tools/fixTransform/fixTransformFunc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
def rough_process(txt: str):
def rough_process(txt: str, cat: int) -> tuple:
"""
:param cat: 1.fixSample1那种 2.fixSample2那种 ...
"""

def not_empty(a):
for i in a:
if i != '\n' and i != ' ':
Expand All @@ -16,29 +20,43 @@ def clean_head_tail(a: str):
_txt = open(txt, 'r', encoding="utf-8")
fix_list = []
location_list = []
cat = 1 # 0整齐 1杂乱
txt = _txt.read()
for i in txt:
if '°' in i:
cat = 0
break
_txt.close()
if cat == 0:
if cat == 1:
txt = txt.split('\n')
txt = [i for i in txt if not_empty(i)]
for i in range(len(txt)):
if i < len(txt) / 2:
fix_list.append(clean_head_tail(txt[i]))
else:
location_list.append(clean_head_tail(txt[i]))
else:
elif cat == 2:
txt = txt.replace('\n', ' ').split(' ')
txt = [i for i in txt if i != '']
for i in range(len(txt)):
if i % 2 == 0:
fix_list.append(txt[i])
else:
location_list.append(txt[i])
elif cat == 3:
txt = txt.split('\n')
txt = [i for i in txt if i != '']
for i in txt:
if not not_empty(i):
continue
i = i.split()
for j in range(1, len(i)):
i[j] = i[j].replace('N', '')
i[j] = i[j].replace('E', '')
i = [j for j in i if j != '']
fix_list.append(i[0])
location_list.append('T'.join(i[1:]))
else:
print("文本类型错误")
return fix_list, location_list


Expand All @@ -60,10 +78,13 @@ def cut(string: str, sep: list) -> list:
for i in loc_list:
if '°' in i: # N29°18'45.1"E092°19'45.4" 度分秒
mode = 0
elif 'T' in i:
mode = 2
elif '.' in i: # N3226.0E10456.0 度分?
mode = 1
else: # N312047E1044856 度分秒?
mode = 2
mode = -1

if mode == 0: # 感觉有点像脱了裤子放屁 算了
i = cut(i, ['N', 'E', '°', '\'', '\"'])
for j in range(6):
Expand All @@ -81,15 +102,22 @@ def cut(string: str, sep: list) -> list:
for k in range(2): # j[k]:32.0
add += j[k] / (60 ** k)
back.append(add) # 怎么感觉上面的写法好奇怪
else:
elif mode == 2:
for i in loc_list:
i = i.split('T')
i = list(map(float, i))
la = i[0] + i[1] / 60
long = i[2] + i[3] / 60
back.append(la)
back.append(long)
elif mode == -1:
i = cut(i, ['N', 'E'])
i = [str(int(j)) for j in i]
i = [[float(j[:-4]), float(j[-4:-2]), float(j[-2:])] for j in i]
print(i)
for j in i: # j:[31.0, 30.0, 6.0]
add = 0
for k in range(3): # j[k]:32.0 艹复制下来忘改成3了
add += j[k] / (60 ** k)
add += j[k] / (60 ** k)
back.append(add) # 怎么感觉上面的写法好奇怪
back = [str(round(i, 9)) for i in back]
return back
Expand Down

0 comments on commit 43b8070

Please sign in to comment.