개정판 e41d63f8
issue #000: hmb saving test
Change-Id: I0b4974337d913a7f20bed5d40989535b35255156
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
36 | 36 |
@author humkyung |
37 | 37 |
@date 2018.04.24 |
38 | 38 |
''' |
39 |
|
|
40 | 39 |
def sizeValue(self): |
41 | 40 |
return self.inchStr if 'Inch' == self.sizeUnit else self.metricStr |
42 | 41 |
|
... | ... | |
82 | 81 |
self._activeDrawing = None |
83 | 82 |
#self._hmbTable = None |
84 | 83 |
self._hmbColors = {} |
84 |
self._hmbData = None |
|
85 | 85 |
self._streamLineListModelDatas = [] |
86 | 86 |
self._titleBlockProperties = None |
87 | 87 |
self.needReOpening = None |
... | ... | |
167 | 167 |
self._activeDrawing = None |
168 | 168 |
#self._hmbTable = None |
169 | 169 |
self._hmbColors = {} |
170 |
self._hmbData = None |
|
170 | 171 |
self._streamLineListModelDatas = [] |
171 | 172 |
self._titleBlockProperties = None |
172 | 173 |
|
... | ... | |
2483 | 2484 |
self._attributeByType = {} |
2484 | 2485 |
CodeTable.clearTables() |
2485 | 2486 |
|
2486 |
@staticmethod |
|
2487 | 2487 |
def save_hmb_data(hmb_list: list): |
2488 | 2488 |
import uuid |
2489 | 2489 |
|
... | ... | |
2522 | 2522 |
params = (str(uuid.uuid4()), list_uids[index], hmb.uid, data.value, data.value_min, data.value_max) |
2523 | 2523 |
cursor.execute(sql, params) |
2524 | 2524 |
index = index + 1 |
2525 |
|
|
2526 |
self._hmbData = None |
|
2525 | 2527 |
|
2526 | 2528 |
except Exception as ex: |
2527 | 2529 |
# Roll back any change if something goes wrong |
... | ... | |
2532 | 2534 |
f"{sys.exc_info()[-1].tb_lineno}" |
2533 | 2535 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
2534 | 2536 |
|
2535 |
@staticmethod |
|
2536 |
def get_hmb_data(file_path: str): |
|
2537 |
def get_hmb_data(self, file_path: str): |
|
2537 | 2538 |
"""get hmb data from pap database if file_path is given otherwise get hmb data from id2 database""" |
2538 | 2539 |
|
2539 | 2540 |
from HMBTable import HMBData |
2540 | 2541 |
|
2541 | 2542 |
if not file_path: |
2542 |
app_doc_data = AppDocData.instance() |
|
2543 |
with app_doc_data.project.database.connect() as conn: |
|
2544 |
try: |
|
2545 |
cursor = conn.cursor() |
|
2546 |
sql = f"SELECT v.Value, v.Value_Min, v.Value_Max, r.Name, r.Unit, r.[index], r.[Type], s.Stream_No, s.[From], s.[To], s.UID, s.[Type] as Phase FROM " \ |
|
2547 |
f"HMB_VALUE v " \ |
|
2548 |
f"INNER JOIN HMB_LIST r ON v.HMB_LIST_UID=r.UID " \ |
|
2549 |
f"INNER JOIN Stream_No s ON v.Stream_No_UID=s.UID " \ |
|
2550 |
f"ORDER BY s.stream_no" |
|
2551 |
cursor.execute(sql) |
|
2552 |
rows = cursor.fetchall() |
|
2553 |
|
|
2554 |
hmbs = HMBData.from_row(rows) |
|
2555 |
return hmbs |
|
2556 |
except Exception as ex: |
|
2557 |
# Roll back any change if something goes wrong |
|
2558 |
conn.rollback() |
|
2559 |
|
|
2560 |
from App import App |
|
2561 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
|
2562 |
f"{sys.exc_info()[-1].tb_lineno}" |
|
2563 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
2543 |
if self._hmbData is None: |
|
2544 |
app_doc_data = AppDocData.instance() |
|
2545 |
with app_doc_data.project.database.connect() as conn: |
|
2546 |
try: |
|
2547 |
cursor = conn.cursor() |
|
2548 |
sql = f"SELECT v.Value, v.Value_Min, v.Value_Max, r.Name, r.Unit, r.[index], r.[Type], s.Stream_No, s.[From], s.[To], s.UID, s.[Type] as Phase FROM " \ |
|
2549 |
f"HMB_VALUE v " \ |
|
2550 |
f"INNER JOIN HMB_LIST r ON v.HMB_LIST_UID=r.UID " \ |
|
2551 |
f"INNER JOIN Stream_No s ON v.Stream_No_UID=s.UID " \ |
|
2552 |
f"ORDER BY s.stream_no" |
|
2553 |
cursor.execute(sql) |
|
2554 |
rows = cursor.fetchall() |
|
2555 |
|
|
2556 |
hmbs = HMBData.from_row(rows) |
|
2557 |
return hmbs |
|
2558 |
except Exception as ex: |
|
2559 |
# Roll back any change if something goes wrong |
|
2560 |
conn.rollback() |
|
2561 |
|
|
2562 |
from App import App |
|
2563 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
|
2564 |
f"{sys.exc_info()[-1].tb_lineno}" |
|
2565 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
2566 |
else: |
|
2567 |
return self._hmbData |
|
2564 | 2568 |
else: |
2565 | 2569 |
with sqlite3.connect(file_path) as conn: |
2566 | 2570 |
try: |
DTI_PID/DTI_PID/ItemDataExportDialog.py | ||
---|---|---|
506 | 506 |
|
507 | 507 |
return header_list |
508 | 508 |
|
509 |
@staticmethod |
|
510 |
def make_hmb_data(data, hmb_data, names): |
|
511 |
"""make min, max data""" |
|
512 |
try: |
|
513 |
phase = hmb_data.phase |
|
514 |
|
|
515 |
if phase and phase == 'Two': |
|
516 |
phase = 'LIQUID' |
|
517 |
elif not phase: |
|
518 |
return False |
|
519 |
|
|
520 |
data['PHASE'] = phase |
|
521 |
|
|
522 |
datas = hmb_data.data |
|
523 |
|
|
524 |
for name in names: |
|
525 |
matches = [data for data in datas if data.name == name and data.phase == phase] |
|
526 |
if matches: |
|
527 |
value = matches[0].value |
|
528 |
value_max = matches[0].value_max |
|
529 |
value_min = matches[0].value_min |
|
530 |
|
|
531 |
data[name] = value |
|
532 |
data[name + '_min'] = value_min |
|
533 |
data[name + '_max'] = value_max |
|
534 |
|
|
535 |
data[name + '_' + matches[0].phase] = value |
|
536 |
data[name + '_' + matches[0].phase + '_min'] = value_min |
|
537 |
data[name + '_' + matches[0].phase + '_max'] = value_max |
|
538 |
|
|
539 |
matches = [data for data in datas if data.name == name and data.phase and data.phase != phase] |
|
540 |
if matches: |
|
541 |
for match in matches: |
|
542 |
data[name + '_' + match.phase] = match.value |
|
543 |
data[name + '_' + match.phase + '_min'] = match.value_min |
|
544 |
data[name + '_' + match.phase + '_max'] = match.value_max |
|
545 |
|
|
546 |
else: |
|
547 |
matches = [data for data in datas if data.name == name] |
|
548 |
if matches: |
|
549 |
value = matches[0].value |
|
550 |
value_max = matches[0].value_max |
|
551 |
value_min = matches[0].value_min |
|
552 |
|
|
553 |
data[name] = value |
|
554 |
data[name + '_min'] = value_min |
|
555 |
data[name + '_max'] = value_max |
|
556 |
|
|
557 |
return data |
|
558 |
except Exception as ex: |
|
559 |
from App import App |
|
560 |
from AppDocData import MessageType |
|
561 |
|
|
562 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
563 |
sys.exc_info()[-1].tb_lineno) |
|
564 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
565 |
|
|
566 |
return None |
|
567 |
|
|
509 | 568 |
def add_hmb_data(self, hmb_datas, dataList): |
510 | 569 |
''' add hmb data dependon stream no ''' |
511 | 570 |
dataList_backup = dataList.copy() |
... | ... | |
526 | 585 |
matches = [hmb_data for hmb_data in hmb_datas if hmb_data.stream_no == stream_no] |
527 | 586 |
if matches: |
528 | 587 |
hmb_data = matches[0] |
529 |
phase = hmb_data.phase |
|
530 |
|
|
531 |
if phase and phase == 'Two': |
|
532 |
phase = 'LIQUID' |
|
533 |
elif not phase: |
|
588 |
data = QItemDataExportDialog.make_hmb_data(data, hmb_data, names) |
|
589 |
if data is None: |
|
590 |
return dataList_backup |
|
591 |
if data is False: |
|
534 | 592 |
continue |
535 | 593 |
|
536 |
data['PHASE'] = phase |
|
537 |
|
|
538 |
datas = hmb_data.data |
|
539 |
|
|
540 |
for name in names: |
|
541 |
matches = [data for data in datas if data.name == name and data.phase == phase] |
|
542 |
if matches: |
|
543 |
value = matches[0].value |
|
544 |
value_max = matches[0].value_max |
|
545 |
value_min = matches[0].value_min |
|
546 |
|
|
547 |
data[name] = value |
|
548 |
data[name + '_min'] = value_min |
|
549 |
data[name + '_max'] = value_max |
|
550 |
|
|
551 |
data[name + '_' + matches[0].phase] = value |
|
552 |
data[name + '_' + matches[0].phase + '_min'] = value_min |
|
553 |
data[name + '_' + matches[0].phase + '_max'] = value_max |
|
554 |
|
|
555 |
matches = [data for data in datas if data.name == name and data.phase and data.phase != phase] |
|
556 |
if matches: |
|
557 |
for match in matches: |
|
558 |
data[name + '_' + match.phase] = match.value |
|
559 |
data[name + '_' + match.phase + '_min'] = match.value_min |
|
560 |
data[name + '_' + match.phase + '_max'] = match.value_max |
|
561 |
|
|
562 |
else: |
|
563 |
matches = [data for data in datas if data.name == name] |
|
564 |
if matches: |
|
565 |
value = matches[0].value |
|
566 |
value_max = matches[0].value_max |
|
567 |
value_min = matches[0].value_min |
|
568 |
|
|
569 |
data[name] = value |
|
570 |
data[name + '_min'] = value_min |
|
571 |
data[name + '_max'] = value_max |
|
572 |
|
|
573 | 594 |
return dataList |
574 | 595 |
|
575 | 596 |
except Exception as ex: |
DTI_PID/DTI_PID/Shapes/EngineeringAbstractItem.py | ||
---|---|---|
625 | 625 |
_attrs[attr] = self.try_eval(None, attr.Expression) if attr.Expression else _attrs[attr] |
626 | 626 |
|
627 | 627 |
"""calculate attribute value for HMB type""" |
628 |
for attr in [_attr for _attr in targetAttrs if _attr.AttributeType == 'HMB']: |
|
629 |
value, pos = '', 0 |
|
630 |
|
|
631 |
matches = p.finditer(attr.Expression) |
|
632 |
for match in matches: |
|
633 |
attr_name = attr.Expression[(match.start() + 1):(match.end() - 1)] |
|
634 |
values = [value for key, value in _attrs.items() if key.Attribute == attr_name] |
|
635 |
if not values: |
|
636 |
values = [] |
|
637 |
value += attr.Expression[pos:match.start()] + '\'' + values[0] + '\'' |
|
638 |
pos = match.end() |
|
639 |
|
|
640 |
value += attr.Expression[pos:len(attr.Expression)] |
|
641 |
_attrs[attr] = self.try_eval(None, value) if attr.Expression else '' |
|
628 |
matches = [_attr for _attr in _attrs if _attr.Attribute.upper() == 'STREAM NO'] |
|
629 |
hmb_attrs = [_attr for _attr in targetAttrs if _attr.AttributeType == 'HMB'] |
|
630 |
hmb_datas = app_doc_data.get_hmb_data(None) |
|
631 |
if hmb_datas and hmb_attrs and matches and _attrs[matches[0]] and _attrs[matches[0]] != 'None': |
|
632 |
stream_no = _attrs[matches[0]] |
|
633 |
names = [] |
|
634 |
for data in hmb_datas[0].data: |
|
635 |
if data.name not in names: |
|
636 |
names.append(data.name) |
|
637 |
|
|
638 |
matches = [hmb_data for hmb_data in hmb_datas if hmb_data.stream_no == stream_no] |
|
639 |
if matches: |
|
640 |
data = {} |
|
641 |
hmb_data = matches[0] |
|
642 |
data = QItemDataExportDialog.make_hmb_data(data, hmb_data, names) |
|
643 |
for _attr in hmb_attrs: |
|
644 |
if _attr.Attribute in data: |
|
645 |
_attrs[_attr] = data[_attr.Attribute] |
|
646 |
else: |
|
647 |
_attrs[_attr] = '' |
|
642 | 648 |
"""up to here""" |
643 | 649 |
|
644 | 650 |
"""calculate attribute value for combined type""" |
DTI_PID/DTI_PID/SymbolAttrEditorDialog.py | ||
---|---|---|
251 | 251 |
QItemDataExportDialog.add_hmb_header(names) |
252 | 252 |
hmb.addItems(names) |
253 | 253 |
self.ui.tableWidgetAttr.setCellWidget(row, 1, hmb) |
254 |
result = attrTypeComboBox.findText(attr.AttributeType)
|
|
254 |
result = hmb.findText(attr.Attribute)
|
|
255 | 255 |
if result: |
256 | 256 |
hmb.setCurrentIndex(result) |
257 | 257 |
|
내보내기 Unified diff