-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheel_backend.py
331 lines (242 loc) · 8.55 KB
/
eel_backend.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
import copy
import collections
def setup_variables(w):
w.type = 'EEL'
w.title = None
w.aircraft_type = None
w.description = None
w.lopa = None
w.ohsc = None
w.locations = ['Cockpit']
w.layout = {'Cockpit': []}
w.summary = {}
w.summary_table = []
def update_variables(self, source):
self.title = source.title
self.aircraft_type = source.aircraft_type
self.description = source.description
self.lopa = source.lopa
self.ohsc = source.ohsc
self.locations = copy.deepcopy(source.locations)
self.layout = copy.deepcopy(source.layout)
self.layout = collections.OrderedDict(sorted(self.layout.items()))#sort by location
self.summary = copy.deepcopy(source.summary)
self.summary_table = copy.deepcopy(source.summary_table)
EEL_Backend.gen_summary_dict(self)
EEL_Backend.gen_summary_table(self)
if source.aircraft_type in ['A320']:
self.treeview_node = 'A320 EELs'
class EEL_Backend():
def __init__(self, parent_page, controller):
self.controller = controller #main append
self.parent_page = parent_page #this is the tkinter frame associated with this BE.
setup_variables(self)
self.setup_plot()
self.save_class = EEL_Saved_State
self.mainapp = self.parent_page.mainapp
def update_component(self, source, type, reset_redo = True):
#pass current joint through to state class (for undo redo)
if type != 'undo_redo':
self.controller.states.component_updated(type, self, EEL_Saved_State, reset_redo)
elif type == 'new':
self.controller.states.component_updated(type, self, EEL_Saved_State, reset_redo)
update_variables(self, source)
self.update_locations()
def gen_save_dict(self, comments_from_text_widget = True, comments = None):
if comments_from_text_widget:
comments = self.parent_page.comment_text.get("1.0","end")
else:
comments = comments
return {'Title': self.title,
'Description': self.description,
'Aircraft Type': self.aircraft_type,
'LOPA': self.lopa,
'OHSC': self.ohsc,
'Locations': self.locations,
'Layout': self.layout,
'Summary': self.summary,
'Summary Table': self.summary_table,
'Comments': comments}
def setup_plot(self):
self.lopa_figure = Figure(figsize=(5,5), dpi=100)
self.ax1 = self.lopa_figure.add_subplot(311, aspect='equal', adjustable='box')
def gen_summary_dict(self):
self.summary = {}
for loc in self.layout.keys():
for part in self.layout[loc]:
item_type = part[0]
part_no = part[1]
if item_type not in self.summary.keys():
self.summary[item_type] = {}
if part_no not in self.summary[item_type].keys():
self.summary[item_type][part_no] = int(part[3])
else:
self.summary[item_type][part_no] += int(part[3])
def gen_summary_table(self):
self.summary_table = []
summary_dict = {}
items = []
index = 0
for loc in self.layout:
for item in self.layout[loc]:
item_type = item[0]
pn = item[1]
qty = int(item[3])
if item_type not in summary_dict.keys():
summary_dict[item_type] = {}
summary_dict[item_type][pn] = qty
else:
if pn not in summary_dict[item_type].keys():
summary_dict[item_type][pn] = qty
else:
summary_dict[item_type][pn] += qty
for item_type in summary_dict.keys():
total_qty = 0
for pn in summary_dict[item_type]:
total_qty += summary_dict[item_type][pn]
self.summary_table.append([item_type, '', total_qty])
for pn in summary_dict[item_type]:
self.summary_table.append(['', pn, summary_dict[item_type][pn]])
def get_item_locations(self, item_to_find, part_no=None):
#get all locations where an item is found
# if part_no is None, will return all part numbers for that item type
locations = []
for loc in self.layout:
for item in self.layout[loc]:
item_type = item[0]
if item_type == item_to_find:
if not part_no:
locations.append(loc)
else:
if item[1] == part_no:
locations.append(loc)
return locations
def get_item_part_no_by_location(self, item_to_find):
# returns dict (locations are keys) showing all part numbers for a given item in that location
item_part_numbers = {}
for loc in self.layout:
for item in self.layout[loc]:
if item[0]==item_to_find:
part_no = item[1]
if loc in item_part_numbers.keys():
pass
else:
item_part_numbers[loc] = {}
item_part_numbers[loc][part_no] = int(item[3])
return item_part_numbers
def get_total_qty_item_per_location(self, item_to_find):
# returns dict (locations are keys) showing total qty for a given item in that location
# e.g. {'Cockpit': 1}
item_part_numbers = {}
for loc in self.layout:
for item in self.layout[loc]:
if item[0]==item_to_find:
part_no = item[1]
if loc in item_part_numbers.keys():
pass
else:
item_part_numbers[loc] = 0
item_part_numbers[loc] += int(item[3])
return item_part_numbers
def count_items(self):
'''
Counts the different item types e.g. {crash axe: 1, lifevest: 2, etc}
'''
item_count = {}
for loc in self.layout:
for part in self.layout[loc]:
item_type = part[0]
if item_type not in item_count.keys():
item_count[item_type] = int(part[3])
else:
item_count[item_type] += int(part[3])
return item_count
def count_part_nos(self):
'''
Counts the different part nos e.g. {pn1: 1, pn2: 2, etc}
'''
pn_count = {}
for loc in self.layout:
for part in self.layout[loc]:
part_no = part[1]
if part_no not in pn_count.keys():
pn_count[part_no] = int(part[3])
else:
pn_count[part_no] += int(part[3])
return pn_count
def compare_eels(self, current_eel):
# self should refer to the go to eel
# other eel should refer to the backend object
item_comparison = []
parts_comparison = []
# Item Type Comparison
item_count_go_to = self.count_items()
item_count_current = current_eel.count_items()
for item in item_count_go_to.keys():
goto_qty = item_count_go_to[item]
if item in item_count_current.keys():
current_qty = item_count_current[item]
delta = current_qty - goto_qty
else:
current_qty = 0
delta = goto_qty*-1
item_comparison.append([item, current_qty, goto_qty, delta])
# add any current items not in go to
for item in item_count_current.keys():
if item not in item_count_go_to.keys():
current_qty = item_count_current[item]
item_comparison.append([item, current_qty, '-', '-'])
# Part Number Comparison
item_count_go_to = self.count_part_nos()
item_count_current = current_eel.count_part_nos()
for item in item_count_go_to.keys():
goto_qty = item_count_go_to[item]
if item in item_count_current.keys():
current_qty = item_count_current[item]
delta = current_qty - goto_qty
else:
current_qty = 0
delta = goto_qty*-1
#get item type
type = self.mainapp.frames[item].backend.equipment_type
parts_comparison.append([item, type, current_qty, goto_qty, delta])
return item_comparison, parts_comparison
def compile_data_for_excel(self):
data = [['Location', 'Type', 'Part Number', 'Qty']]
for loc in self.layout:
for part in self.layout[loc]:
item_type = part[0]
part_no = part[1]
qty = int(part[3])
data.append([loc, item_type, part_no, qty])
return data
def update_locations(self):
locations = ['Cockpit', 'Each Seat']
if self.lopa != None:
lopa = self.mainapp.frames[self.lopa].backend
#check lavs
for l in lopa.lavs:
if l[1] == 'Yes':
if l[3] == 'Yes':
locations.append(f'{l[0]} CAS')
if l[4] == 'Yes':
locations.append(f'{l[0]} Doghouse')
locations.append(f'{l[0]} Bulkhead')
for g in lopa.galleys:
if g[1] == 'Yes':
locations.append(g[0])
if self.ohsc != None:
o = self.mainapp.frames[self.ohsc].backend
for side in ['LHS', 'RHS']:
for ohsc_bin in o.layout[side]:
locations.append(f'OHSC {side} {ohsc_bin[2]} - {ohsc_bin[3]}')
self.locations = sorted(locations)
class EEL_Saved_State():
def __init__(self, ohsc):
setup_variables(self)
update_variables(self, ohsc)