-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofptextprocess.py
153 lines (144 loc) · 4.54 KB
/
ofptextprocess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import re
import logging
# 正则表达式
reRoute = r'\b(ROUTE NO\.\s[0-9A-Z]+) +.+\b'
rePoint = r'\b\d{3} +\d{3}\/\d{4} (\w+) +.*\b'
reFL = r'\b(FL\s\d).+\b'
reFLend = r'.+ALL WEIGHTS IN KILOS'
reTurbTemp = r'\b([MP])(\d{2})\.+.* {7}(\d{2})? .*\b'
reAltn = r'\b(\w{4})\/\w{3}\/.*\b'
endFpl = r'----------------------\s{3}END OF FLIGHT PLAN\s{3}----------------------[\s\S]+$'
rmkEnd = ' ALTERNATE SUMMARY'
rmkBgn = 'DISP RMKS'
melBgnSign = '------------- -----------'
reEqpCd = r'^ACFT \S+ (\S+),'
reTargetFuel = r'^TARGET ARRIVAL FUEL( +)([0-9]+)KGS$'
def ofptextprocess(data, logger=logging.getLogger()):
eqpCd = ''
targetFuel = 0
ALTN = []
Min_temp = 999
Min_temp_sign = ''
Max_turb = 0
point = ''
tempPoint = []
turbPoint = []
FL = []
FL_start_flag = 0
FL_done_flag = 0
Rmk = []
MEL = []
RouteDef = []
Rmksign = 0
MELsign = 0
routeDef_start_flag = 0
routedef_end_flag = 0
lines = re.sub(endFpl, '', data).split('\n')
for line in lines:
#eqpCd
eqpCdResult = re.match(reEqpCd,line)
if eqpCdResult:
eqpCd = eqpCdResult.group(1)
reTargetFuelResult = re.match(reTargetFuel,line)
if reTargetFuelResult:
targetFuel = int(reTargetFuelResult.group(2))
# FL
if re.match(reFL, line):
FL_start_flag = 1
routedef_end_flag = 1
if re.match(reFLend,line):
FL_done_flag = 1
if FL_start_flag == 1 and FL_done_flag == 0:
if not re.match(r'^\s*$',line):
FL.append(line)
# 航路详情
if routeDef_start_flag == 1 and routedef_end_flag == 0:
RouteDef.append(line)
# 航路代号
if re.match(reRoute, line):
# tempo = re.match(reRoute, line)
# ROUTE = tempo.group(1)
routeDef_start_flag = 1
# RMK
if line == rmkEnd:
Rmksign = 0
MELsign = 0
if Rmksign != 0:
Rmk.append(line)
if line == rmkBgn:
Rmksign = 1
MELsign = 0
# 备降场列表
if re.match(reAltn, line):
tempo = re.match(reAltn, line)
ALTN.append(tempo.group(1))
# 航路点和颠簸
if re.match(rePoint, line):
tempo = re.match(rePoint, line)
point = tempo.group(1)
continue
if re.match(reTurbTemp, line):
tempo = re.match(reTurbTemp, line)
if tempo.group(3) is None:
turb = 0
else:
turb = int(tempo.group(3))
tempSign = tempo.group(1)
temp = int(tempo.group(2))
if tempSign == "M":
temp = -temp
if temp < Min_temp:
Min_temp = temp
Min_temp_sign = tempSign
tempPoint.clear()
tempPoint.append(point)
else:
if temp == Min_temp:
tempPoint.append(point)
if turb > Max_turb:
Max_turb = turb
turbPoint.clear()
turbPoint.append(point)
else:
if turb == Max_turb:
turbPoint.append(point)
# MEL
if MELsign != 0:
MEL.append(line)
if line == melBgnSign:
MELsign = 1
Max_turb = '%02d' % Max_turb
Min_temp = Min_temp_sign + '%02d' % abs(Min_temp)
detail = {}
detail['eqpCd'] = eqpCd
detail['targetFuel'] = targetFuel
if len(FL) == 0:
logger.warning('ofpProcess Warning : FL empty!')
detail['FL'] = "\n".join(FL)
if RouteDef == '':
logger.warning('ofpProcess Warning : routedefinition empty!')
detail['routeDef'] = "\n".join(RouteDef)
detail['Rmk'] = re.sub(r'([\'\"])',"\\\\\g<1>","\n".join(Rmk))
detail['Max_turb'] = Max_turb
# 颠簸点
if not turbPoint:
detail['turbPoint'] = ''
logger.warning('ofpProcess Warning : turbpoints empty')
else:
detail['turbPoint'] = ",".join(turbPoint)
detail['Min_temp'] = Min_temp
if not tempPoint:
logger.warning('ofpProcess Warning : temppoints empty!')
detail['tempPoint'] = ''
else:
detail['tempPoint'] = ",".join(tempPoint)
detail['MEL'] = re.sub(r'([\'\"])',"\\\\\g<1>","\n".join(MEL))
detail['altn0'] = ""
detail['altn1'] = ""
detail['altn2'] = ""
detail['altn3'] = ""
i = 0
for altn in ALTN:
detail['altn'+str(i)] = altn
i += 1
return detail