프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / DTI_PID / HMBTable.py @ 3d990830

이력 | 보기 | 이력해설 | 다운로드 (4.97 KB)

1 0214673b humkyung
# coding: utf-8
2
3
import os
4
import sys
5
import sqlite3
6 1024ee16 humkyung
from SingletonInstance import SingletonInstance
7 0214673b humkyung
8 9168f672 humkyung
9 3b8a801a humkyung
class StreamData:
10 1780c139 esham21
    def __init__(self, name, unit='', value='', index=0, phase='', case=''):
11 3b8a801a humkyung
        self.name = name
12 2f121b7a esham21
        self.unit = unit
13 3b8a801a humkyung
        self.value = value
14 59a3b95b esham21
        self.index = index
15 929b28cc esham21
        self.phase = phase
16 1780c139 esham21
        self.case = case
17 3b8a801a humkyung
18
19 0214673b humkyung
class HMBData:
20 9168f672 humkyung
    """HMB data class"""
21 0214673b humkyung
    def __init__(self, uid=None):
22
        self._uid = uid
23
        self._stream_no = None
24 2f121b7a esham21
        self._from = None
25
        self._to = None
26 1780c139 esham21
        self._datas = []
27 2f121b7a esham21
28 3b8a801a humkyung
    @property
29 1780c139 esham21
    def datas(self):
30 2f121b7a esham21
        """return hmb data"""
31 1780c139 esham21
        return self._datas
32 3b8a801a humkyung
33 1780c139 esham21
    @datas.setter
34
    def datas(self, value):
35 2f121b7a esham21
        """hmb data"""
36 1780c139 esham21
        self._datas = value
37 929b28cc esham21
38
    @property
39 2f121b7a esham21
    def hfrom(self):
40
        """from"""
41
        return self._from
42
43
    @hfrom.setter
44
    def hfrom(self, value):
45
        """from"""
46
        self._from = value
47
48
    @property
49
    def hto(self):
50
        """to"""
51
        return self._to
52 3b8a801a humkyung
53 2f121b7a esham21
    @hto.setter
54
    def hto(self, value):
55
        """to"""
56
        self._to = value
57 0214673b humkyung
58
    @property
59
    def uid(self):
60 3b8a801a humkyung
        """uid"""
61 0214673b humkyung
        return self._uid
62
63
    @uid.setter
64
    def uid(self, value):
65 3b8a801a humkyung
        """uid"""
66 0214673b humkyung
        self._uid = value
67
    
68
    @property
69 9168f672 humkyung
    def stream_no(self):
70 3b8a801a humkyung
        """stream no"""
71 0214673b humkyung
        return self._stream_no
72
73 9168f672 humkyung
    @stream_no.setter
74
    def stream_no(self, value):
75 3b8a801a humkyung
        """stream no"""
76 0214673b humkyung
        self._stream_no = value
77
78
    @staticmethod
79 59a3b95b esham21
    def from_row(rows):
80 9168f672 humkyung
        """create hmb data from database record"""
81 59a3b95b esham21
        if rows:
82
            pre_no = rows[0]['Stream_No']
83 107d6245 esham21
        else:
84
            return []
85 59a3b95b esham21
86
        data_list = []
87
        datas = []
88
89
        for row in rows:
90
            if row['Stream_No'] == pre_no:
91
                datas.append(row)
92
            else:
93
                pre_no = row['Stream_No']
94
                data_list.append(datas)
95
                datas = [row]
96
97 e4717908 esham21
        data_list.append(datas)
98
99 59a3b95b esham21
        hmbs = []
100
        for datas in data_list:
101
            hmb = HMBData(datas[0]['UID'])
102
            hmb.stream_no = datas[0]['Stream_No']
103
            hmb.hfrom = datas[0]['From']
104
            hmb.hto = datas[0]['To']
105
106 1780c139 esham21
            cases = {}
107 59a3b95b esham21
            for _data in datas:
108 1780c139 esham21
                case = _data['Case']
109
                if case not in cases:
110
                    cases[case] = [_data]
111
                else:
112
                    cases[case].append(_data)
113
114
            hmb_datas = []
115 8a0907d0 esham21
            keys = sorted(list(cases.keys()))
116
            for key in keys:
117 1780c139 esham21
                hmb_data = []
118 8a0907d0 esham21
                _datas = cases[key]
119 1780c139 esham21
                for _data in _datas:
120
                    name = _data['Name']
121
                    unit = _data['Unit']
122
                    value = _data['Value']
123
                    index = _data['index']
124
                    phase = _data['Type']
125
                    case = _data['Case']
126
                    hmb_data.append(StreamData(name, unit, value, index, phase, case))
127
                hmb_datas.append(hmb_data)
128
129
            hmb.datas = hmb_datas
130 59a3b95b esham21
            hmbs.append(hmb)
131
132
        return hmbs
133 0214673b humkyung
134 9168f672 humkyung
135 1780c139 esham21
"""
136 0214673b humkyung
class HMBTable:
137 1780c139 esham21
    '''HMB table class'''
138 0214673b humkyung
    def __init__(self):
139
        self._hmbs = None
140

141 9168f672 humkyung
    def load_data(self):
142 1780c139 esham21
        '''load hmb data from database'''
143 0214673b humkyung
        from AppDocData import AppDocData
144

145
        try:
146
            if self._hmbs is None:
147
                self._hmbs = []
148

149 9f0676d9 esham21
                rows = AppDocData.instance().get_hmb_data(None)
150 3b8a801a humkyung
                for row in rows:
151
                    hmb = HMBData.from_row(row)
152
                    self._hmbs.append(hmb)
153 0214673b humkyung
        # Catch the exception
154
        except Exception as ex:
155 46c46d21 humkyung
            from App import App
156
            from AppDocData import MessageType
157

158
            message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
159
                      f"{sys.exc_info()[-1].tb_lineno}"
160
            App.mainWnd().addMessage.emit(MessageType.Error, message)
161 0214673b humkyung

162
        return self._hmbs
163
        
164 9168f672 humkyung
    @property
165
    def names(self):
166 1780c139 esham21
        '''return hmb attribute names'''
167 9168f672 humkyung
        return set([hmb.name for hmb in self._hmbs if not hmb.isDeleted]) if self._hmbs is not None else {}
168 0214673b humkyung

169
    def streamNos(self):
170 1780c139 esham21
        '''return stream no collection which are not duplicated'''
171 3b8a801a humkyung
        return set([hmb.stream_no for hmb in self._hmbs]) if self._hmbs is not None else {}
172 0214673b humkyung

173
    def dataOfStreamNo(self, streamNo):
174 1780c139 esham21
        '''return stream data'''
175 3b8a801a humkyung
        if self._hmbs is not None:
176
            matches = [hmb.data for hmb in self._hmbs if hmb.stream_no == streamNo]
177
            return matches[0] if matches else None
178
        else:
179
            return None
180 0214673b humkyung

181
    '''
182
        @brief      append hmb data
183
        @author     humkyung
184
        @date       2018.07.12
185
    '''
186
    def append(self, hmbData):
187
        if self._hmbs is None:
188
            self._hmbs = []
189

190
        self._hmbs.append(hmbData)
191

192
    '''
193
        @brief      reset
194
        @author     humkyung
195
        @date       2018.07.12
196
    '''
197
    def reset(self):
198
        if self._hmbs is not None:
199
            del self._hmbs
200

201 1780c139 esham21
        self._hmbs = None
202
"""
클립보드 이미지 추가 (최대 크기: 500 MB)