dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo   B
last analyzed

Complexity

Total Complexity 52

Size/Duplication

Total Lines 184
Duplicated Lines 96.74 %

Importance

Changes 0
Metric Value
wmc 52
eloc 145
dl 178
loc 184
rs 7.44
c 0
b 0
f 0

30 Methods

Rating   Name   Duplication   Size   Complexity  
A GridParmInfo.__str__() 2 2 1
A GridParmInfo.__init__() 14 14 1
A GridParmInfo.setMaxValue() 2 2 1
A GridParmInfo.setRateParm() 2 2 1
A GridParmInfo.setDescriptiveName() 2 2 1
A GridParmInfo.setUnitString() 2 2 1
A GridParmInfo.getDescriptiveName() 2 2 1
A GridParmInfo.setGridType() 2 2 1
A GridParmInfo.setTimeIndependentParm() 2 2 1
A GridParmInfo.setMinValue() 2 2 1
A GridParmInfo.getTimeIndependentParm() 2 2 1
A GridParmInfo.getParmID() 2 2 1
A GridParmInfo.setGridLoc() 2 2 1
A GridParmInfo.setTimeConstraints() 2 2 1
A GridParmInfo.getUnitString() 2 2 1
A GridParmInfo.isValid() 3 3 1
A GridParmInfo.getMaxValue() 2 2 1
A GridParmInfo.__repr__() 14 14 2
A GridParmInfo.getPrecision() 2 2 1
A GridParmInfo.setParmID() 2 2 1
A GridParmInfo.__ne__() 2 2 1
A GridParmInfo.__setDefaultValues() 12 12 1
A GridParmInfo.getRateParm() 2 2 1
A GridParmInfo.getTimeConstraints() 2 2 1
D GridParmInfo.__eq__() 26 26 13
A GridParmInfo.setPrecision() 2 2 1
A GridParmInfo.getGridType() 2 2 1
A GridParmInfo.getMinValue() 2 2 1
C GridParmInfo.__validCheck() 24 24 10
A GridParmInfo.getGridLoc() 2 2 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complexity

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.db.objects import GridLocation
2
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.db.objects import ParmID
3
from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.db.objects import TimeConstraints
4
5
6 View Code Duplication
class GridParmInfo(object):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7
8
    def __init__(self, parmid=None, gridLoc=None, gridType="NONE", unit=None,
9
                 descriptiveName="", minValue=0.0, maxValue=0.0, precision=0,
10
                 timeIndependentParm=False, timeConstraints=None, rateParm=False):
11
        self.parmID = parmid
12
        self.gridLoc = gridLoc
13
        self.gridType = gridType
14
        self.descriptiveName = descriptiveName
15
        self.unitString = unit
16
        self.minValue = float(minValue)
17
        self.maxValue = float(maxValue)
18
        self.precision = int(precision)
19
        self.rateParm = rateParm
20
        self.timeConstraints = timeConstraints
21
        self.timeIndependentParm = timeIndependentParm
22
23
#        (valid, errors) = self.__validCheck()
24
#        if not valid:
25
#            errorMessage = "GridParmInfo is invalid: " + str(errors)
26
#            warnings.warn(errorMessage)
27
#            self.__setDefaultValues()
28
29
    def __str__(self):
30
        return self.__repr__()
31
32
    def __repr__(self):
33
        if self.isValid():
34
            out = "ParmID: " + str(self.parmID) + \
35
                  " TimeConstraints: " + str(self.timeConstraints) + \
36
                  " GridLoc: " + str(self.gridLoc) + \
37
                  " Units: " + self.unitString + \
38
                  " Name: " + self.descriptiveName + \
39
                  " Min/Max AllowedValues: " + str(self.minValue) + "," + \
40
                  str(self.maxValue) + " Precision: " + str(self.precision) + \
41
                  " TimeIndependent: " + str(self.timeIndependentParm) + \
42
                  " RateParm: " + str(self.rateParm) + \
43
                  " GridType: " + self.gridType
44
            return out
45
        return "<Invalid>"
46
47
    def __eq__(self, other):
48
        if not isinstance(other, GridParmInfo):
49
            return False
50
        if self.descriptiveName != other.descriptiveName:
51
            return False
52
        if self.gridLoc != other.gridLoc:
53
            return False
54
        if self.gridType != other.gridType:
55
            return False
56
        if self.minValue != other.minValue:
57
            return False
58
        if self.maxValue != other.maxValue:
59
            return False
60
        if self.parmID != other.parmID:
61
            return False
62
        if self.precision != other.precision:
63
            return False
64
        if self.rateParm != other.rateParm:
65
            return False
66
        if self.timeConstraints != other.timeConstraints:
67
            return False
68
        if self.timeIndependentParm != other.timeIndependentParm:
69
            return False
70
        if self.unitString != other.unitString:
71
            return False
72
        return True
73
74
    def __ne__(self, other):
75
        return not self.__eq__(other)
76
77
    def __validCheck(self):
78
        status = []
79
80
        if not self.parmID.isValid():
81
            status.append("GridParmInfo.ParmID is not valid [" + str(self.parmID) + "]")
82
        if not self.timeConstraints.isValid():
83
            status.append("GridParmInfo.TimeConstraints are not valid [" +
84
                          str(self.timeConstraints) + "]")
85
        if not self.gridLoc.isValid():
86
            status.append("GridParmInfo.GridLocation is not valid")
87
        if self.timeIndependentParm and self.timeConstraints.anyConstraints():
88
            status.append("GridParmInfo is invalid. There are time constraints" +
89
                          " for a time independent parm. Constraints: " +
90
                          str(self.timeConstraints))
91
        if not self.unitString:
92
            status.append("GridParmInfo.Units are not defined.")
93
        if self.precision < -2 or self.precision > 5:
94
            status.append("GridParmInfo is invalid. Precision out of limits." +
95
                          " Precision is: " + str(self.precision) + ". Must be between -2 and 5.")
96
97
        retVal = True
98
        if status:
99
            retVal = False
100
        return retVal, status
101
102
    def isValid(self):
103
        (valid, errors) = self.__validCheck()
104
        return valid
105
106
    def __setDefaultValues(self):
107
        self.parmID = ParmID()
108
        self.gridLoc = GridLocation()
109
        self.gridType = "NONE"
110
        self.descriptiveName = ""
111
        self.unitString = ""
112
        self.minValue = 0.0
113
        self.maxValue = 0.0
114
        self.precision = 0
115
        self.rateParm = False
116
        self.timeConstraints = TimeConstraints()
117
        self.timeIndependentParm = False
118
119
    def getParmID(self):
120
        return self.parmID
121
122
    def setParmID(self, parmID):
123
        self.parmID = parmID
124
125
    def getGridLoc(self):
126
        return self.gridLoc
127
128
    def setGridLoc(self, gridLoc):
129
        self.gridLoc = gridLoc
130
131
    def getGridType(self):
132
        return self.gridType
133
134
    def setGridType(self, gridType):
135
        self.gridType = gridType
136
137
    def getDescriptiveName(self):
138
        return self.descriptiveName
139
140
    def setDescriptiveName(self, descriptiveName):
141
        self.descriptiveName = descriptiveName
142
143
    def getUnitString(self):
144
        return self.unitString
145
146
    def setUnitString(self, unitString):
147
        self.unitString = unitString
148
149
    def getMinValue(self):
150
        return self.minValue
151
152
    def setMinValue(self, minValue):
153
        self.minValue = minValue
154
155
    def getMaxValue(self):
156
        return self.maxValue
157
158
    def setMaxValue(self, maxValue):
159
        self.maxValue = maxValue
160
161
    def getPrecision(self):
162
        return self.precision
163
164
    def setPrecision(self, precision):
165
        self.precision = precision
166
167
    def getRateParm(self):
168
        return self.rateParm
169
170
    def setRateParm(self, rateParm):
171
        self.rateParm = rateParm
172
173
    def getTimeConstraints(self):
174
        return self.timeConstraints
175
176
    def setTimeConstraints(self, timeConstraints):
177
        self.timeConstraints = timeConstraints
178
179
    def getTimeIndependentParm(self):
180
        return self.timeIndependentParm
181
182
    def setTimeIndependentParm(self, timeIndependentParm):
183
        self.timeIndependentParm = timeIndependentParm
184