Skip to content

Commit 1128669

Browse files
committed
修复了一些bug
1 parent a59cbc2 commit 1128669

File tree

1 file changed

+52
-27
lines changed

1 file changed

+52
-27
lines changed

main.py

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import pandas as pd
55
import random
66
import os
7+
import numpy as np
8+
from collections import Counter
79
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
810
QHBoxLayout, QLabel, QLineEdit, QPushButton,
911
QTextEdit, QSpinBox, QComboBox, QMessageBox,
@@ -352,8 +354,7 @@ def initUI(self):
352354
flight_layout.addWidget(self.tower_rfl_input, 2, 1)
353355

354356
flight_layout.addWidget(QLabel("机场标高高度:"), 3, 0)
355-
self.tower_alti_input = QComboBox()
356-
self.tower_alti_input.addItems(list(self.ALTI.keys()))
357+
self.tower_alti_input= QLineEdit()
357358
flight_layout.addWidget(self.tower_alti_input, 3, 1)
358359

359360
flight_layout.addWidget(QLabel("机型:"), 4, 0)
@@ -641,7 +642,7 @@ def write_pos_and_hdg_into_json(self, pos, hdg):
641642
data[adep] = {gate: gate_data}
642643

643644
# 写回文件
644-
with open("Gate.json", "w", encoding="utf-8") as f:
645+
with open(self.gate_path, "w", encoding="utf-8") as f:
645646
json.dump(data, f, indent=4, ensure_ascii=False)
646647

647648
print(f"成功写入数据: {adep}/{gate} - 位置: {pos}, 航向: {hdg}")
@@ -753,8 +754,7 @@ def generate_tower_flights(self):
753754
adep = self.tower_dep_input.currentText()
754755
dest = self.tower_arr_input.currentText()
755756
rfl = self.tower_rfl_input.currentText()
756-
alti_key = self.tower_alti_input.currentText()
757-
alt = self.ALTI[alti_key]
757+
alt = self.tower_alti_input.text()
758758
typ = self.tower_typ_input.text()
759759
gate = self.gate_input.text()
760760
result = self.find_pos_and_hdg_by_gate(adep, gate)
@@ -799,31 +799,36 @@ def generate_tower_flights(self):
799799
rte = self.tower_rte_input.text() or route
800800

801801
# 生成输出
802-
output = f"PSEUDOPILOT:ALL\n"
803-
output += f"@N:{callsign}:2000:1:{pos}:{alt}:0:{hdg}:0\n"
804-
output += f"$FP{callsign}:*A:I:{typ}:420:{adep}:0000:0000:{rfl}:{dest}:00:00:0:0::/v/{remark}:{route}\n"
805-
output += f"$ROUTE:{rte}\n"
806-
output += f"DELAY:1:8\n"
807-
output += f"REQALT::{alt}\n"
808-
output += f"INITIALPSEUDOPILOT:{self.tower_ini_input.text()}\n"
809-
output += f"\n"
810-
811-
self.tower_output.setPlainText(output)
802+
tower_output = f"PSEUDOPILOT:ALL\n"
803+
tower_output += f"@N:{callsign}:2000:1:{pos}:{alt}:0:{hdg}:0\n"
804+
tower_output += f"$FP{callsign}:*A:I:{typ}:420:{adep}:0000:0000:{rfl}:{dest}:00:00:0:0::/v/{remark}:{route}\n"
805+
tower_output += f"$ROUTE:{rte}\n"
806+
tower_output += f"DELAY:1:8\n"
807+
tower_output += f"REQALT::{alt}\n"
808+
tower_output += f"INITIALPSEUDOPILOT:{self.tower_ini_input.text()}\n"
809+
tower_output += f"\n"
810+
811+
self.tower_output.setPlainText(tower_output)
812+
self.output_text.setPlainText(tower_output)
812813
self.statusBar().showMessage("塔台航班计划生成完成")
813814

814815

815816
def get_rte_options(self, pro_input: str) -> str:
817+
"""
818+
根据PRO输入从CSV文件中获取所有包含该PRO的行对应的RTE选项的重合部分
819+
使用最简单的版本,手动处理CSV格式问题
820+
"""
816821
try:
817-
rte_values = set()
818-
822+
rte_values = []
823+
819824
with open(self.sid_path, 'r', encoding='utf-8') as file:
820825
for i, line in enumerate(file):
821826
line = line.strip()
822827
if not line:
823828
continue
824-
829+
825830
fields = line.split(',')
826-
831+
827832
# 第一行是表头
828833
if i == 0:
829834
if 'PRO' in fields and 'RTE' in fields:
@@ -837,17 +842,37 @@ def get_rte_options(self, pro_input: str) -> str:
837842
if len(fields) >= 5:
838843
pro_value = fields[pro_index] if pro_index < len(fields) else ""
839844
rte_value = fields[rte_index] if rte_index < len(fields) else ""
840-
841-
if pro_input in pro_value and rte_value:
842-
rte_values.add(rte_value)
843-
844-
return ','.join(rte_values) if rte_values else ""
845-
845+
846+
# 检查PRO是否包含输入值且RTE不为空
847+
if pro_input in pro_value and rte_value and rte_value.strip():
848+
rte_values.append(rte_value.strip())
849+
850+
if not rte_values:
851+
return ""
852+
853+
# 计算所有RTE值的交集(共同部分)
854+
# 这里我们找出所有匹配行中都出现的RTE值
855+
from collections import Counter
856+
rte_counter = Counter(rte_values)
857+
858+
# 获取出现次数等于总匹配行数的RTE值(即所有行都有的共同值)
859+
total_matches = len(rte_values)
860+
common_rte = [rte for rte, count in rte_counter.items() if count == total_matches]
861+
862+
# 如果没有完全相同的共同值,返回所有去重后的值
863+
if not common_rte:
864+
# 或者可以返回出现次数最多的值
865+
# common_rte = [rte_counter.most_common(1)[0][0]] if rte_counter else []
866+
867+
# 或者返回所有去重值
868+
common_rte = list(set(rte_values))
869+
870+
return ','.join(common_rte) if common_rte else ""
871+
846872
except Exception as e:
847873
print(f"读取文件出错: {e}")
848874
return ""
849875

850-
851876
def generate_app_flights(self):
852877
airline = random.choice(self.airlines)
853878
numbers = str(random.randint(100,9999))
@@ -959,7 +984,7 @@ def toggle_topmost(self, checked):
959984
background-color: #7f8c8d;
960985
}
961986
""")
962-
987+
963988
# 重新显示窗口以使设置生效
964989
self.show()
965990

0 commit comments

Comments
 (0)