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
|
'''
Created on Dec 20, 2012
@author: steger, jozsef
@organization: ELTE
@contact: steger@complex.elte.hu
'''
from DataProcessing.Dimension import DimensionManager
from DataProcessing.DataError import DataError
from DataProcessing.Unit import UnitManager
class Cell(object):
'''
@author: steger, jozsef
@summary:
This class represents meta information of a single table column.
It stores the following information:
- the name of the cell,
- the feature associated to the underlying data,
- the dimension of the underlying data,
- the unit of the underlying data,
'''
def __init__(self):
self._name = None
self._dimension = None
self._unit = None
self._feature = None
def _get_name(self):
if self._name is None:
raise DataError("name property is not set")
return self._name
def _set_name(self, name):
if not isinstance(name, basestring):
raise DataError("name is not a string")
if name.count('.'):
raise DataError("name must not contain any periods (%s)" % name)
if self._name is not None and self._name != name:
raise DataError("name property cannot be modified")
self._name = name
def _get_dimension(self):
if not self._dimension:
raise DataError("dimension property is not set")
return self._dimension
def _set_dimension(self, dimension):
if not isinstance(dimension, DimensionManager.Dimension):
raise DataError("dimension is invalid")
if self._unit is not None:
if not dimension.containsUnit(self._unit):
raise DataError("unit %s is not in the basin of dimension %s" % (self.unit, dimension))
self._dimension = dimension
def _get_unit(self):
if self._unit is None:
return self.dimension.unit
else:
return self._unit
def _set_unit(self, unit):
if not isinstance(unit, UnitManager.Unit):
raise DataError("unit is invalid")
if self._dimension is not None:
if not self.dimension.containsUnit(unit):
raise DataError("unit %s is not in the basin of dimension %s" % (unit, self.dimension))
self._unit = unit
def _get_feature(self):
if self._feature is None:
raise DataError("feature property is not set")
return self._feature
def _set_feature(self, feature):
if self._feature is not None and self._feature != feature:
raise DataError("feature property cannot be modified")
self._feature = feature
def __eq__(self, cell):
if not isinstance(cell, Cell):
raise DataError("type error expecting Cell for comparison")
return self._name == cell._name and self._feature == cell._feature and self._unit == cell._unit and self._dimension == cell._dimension
def __ne__(self, cell):
'''
@summary: comparison operator of column types.
@return: True if column names or their units differ
@rtype: boolean
'''
return not self.__eq__(cell)
feature = property(_get_feature,_set_feature,None)
name = property(_get_name,_set_name,None)
unit = property(_get_unit,_set_unit,None)
dimension = property(_get_dimension,_set_dimension,None)
class DataHeaderCell(Cell):
def __init__(self, name, dimension, feature = None, unit = None):
Cell.__init__(self)
self.name = name
self.dimension = dimension
if unit is not None:
self.unit = unit
if feature is not None:
self.feature = feature
class CellRequest(Cell): pass
class CellRequestByName(CellRequest):
'''
@author: steger, jozsef
@summary:
This class represents the user request for a data column matching the name of the column.
One can specify the requested unit.
'''
def __init__(self, name, unit = None):
'''
@summary: Constructor
@param name: the name of the requested column
@type name: string
@param unit: the requested unit, default is None, which means no conversion request
@type unit: string or None
'''
Cell.__init__(self)
self.name = name
if unit is not None:
self.unit = unit
def __eq__(self, cell):
return self.name == cell.name
class CellRequestByFeature(CellRequest):
'''
@author: steger, jozsef
@summary:
This class represents the user request for a data column(s) matching the feature of the column.
One can specify the requested unit.
'''
def __init__(self, feature, unit = None):
'''
@summary: Constructor
@param feature: the feature of the requested column
@type feature: string
@param unit: the requested unit, default is None, which means no conversion request
@type unit: string or None
'''
Cell.__init__(self)
self.feature = feature
if unit is not None:
self.unit = unit
def __eq__(self, cell):
return self.feature == cell.feature
|