1 # Copyright (C) 2010-2011 Richard Lincoln
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to
5 # deal in the Software without restriction, including without limitation the
6 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 # sell copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 from CIM14
.IEC61970
.Meas
.Measurement
import Measurement
23 class Accumulator(Measurement
):
24 """Accumulator represents a accumulated (counted) Measurement, e.g. an energy value.
27 def __init__(self
, maxValue
=0, LimitSets
=None, AccumulatorValues
=None, *args
, **kw_args
):
28 """Initialises a new 'Accumulator' instance.
30 @param maxValue: Normal value range maximum for any of the MeasurementValue.values. Used for scaling, e.g. in bar graphs or of telemetered raw values.
31 @param LimitSets: A measurement may have zero or more limit ranges defined for it.
32 @param AccumulatorValues: The values connected to this measurement.
34 #: Normal value range maximum for any of the MeasurementValue.values. Used for scaling, e.g. in bar graphs or of telemetered raw values.
35 self
.maxValue
= maxValue
38 self
.LimitSets
= [] if LimitSets
is None else LimitSets
40 self
._AccumulatorValues
= []
41 self
.AccumulatorValues
= [] if AccumulatorValues
is None else AccumulatorValues
43 super(Accumulator
, self
).__init
__(*args
, **kw_args
)
46 _attr_types
= {"maxValue": int}
47 _defaults
= {"maxValue": 0}
49 _refs
= ["LimitSets", "AccumulatorValues"]
50 _many_refs
= ["LimitSets", "AccumulatorValues"]
52 def getLimitSets(self
):
53 """A measurement may have zero or more limit ranges defined for it.
55 return self
._LimitSets
57 def setLimitSets(self
, value
):
58 for p
in self
._LimitSets
:
59 filtered
= [q
for q
in p
.Measurements
if q
!= self
]
60 self
._LimitSets
._Measurements
= filtered
62 if self
not in r
._Measurements
:
63 r
._Measurements
.append(self
)
64 self
._LimitSets
= value
66 LimitSets
= property(getLimitSets
, setLimitSets
)
68 def addLimitSets(self
, *LimitSets
):
70 if self
not in obj
._Measurements
:
71 obj
._Measurements
.append(self
)
72 self
._LimitSets
.append(obj
)
74 def removeLimitSets(self
, *LimitSets
):
76 if self
in obj
._Measurements
:
77 obj
._Measurements
.remove(self
)
78 self
._LimitSets
.remove(obj
)
80 def getAccumulatorValues(self
):
81 """The values connected to this measurement.
83 return self
._AccumulatorValues
85 def setAccumulatorValues(self
, value
):
86 for x
in self
._AccumulatorValues
:
90 self
._AccumulatorValues
= value
92 AccumulatorValues
= property(getAccumulatorValues
, setAccumulatorValues
)
94 def addAccumulatorValues(self
, *AccumulatorValues
):
95 for obj
in AccumulatorValues
:
96 obj
.Accumulator
= self
98 def removeAccumulatorValues(self
, *AccumulatorValues
):
99 for obj
in AccumulatorValues
:
100 obj
.Accumulator
= None