1 # Copyright (C) 2010 Richard Lincoln
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA, USA
17 from CIM14
.Element
import Element
19 class TimeTariffInterval(Element
):
20 """One of a sequence of time intervals defined in terms of real time. It is typically used in association with TariffProfile to define the intervals in a time of use tariff structure, where startDateTime simultaneously determines the starting point of this interval and the ending point of the previous interval.
23 def __init__(self
, sequenceNumber
=0, startDateTime
='', TariffProfiles
=None, Charges
=None, *args
, **kw_args
):
24 """Initialises a new 'TimeTariffInterval' instance.
26 @param sequenceNumber: A sequential reference that defines the identity of this interval and its relative position with respect to other intervals in a sequence of intervals.
27 @param startDateTime: A real time marker that defines the starting time (typically it is the time of day) for this interval. The interval extends to the start of the next interval or until it is reset to the start of the first interval by TariffProfile.tariffCycle.
28 @param TariffProfiles: All tariff profiles defined by this time tariff interval.
29 @param Charges: All charges used to define this time tariff interval.
31 #: A sequential reference that defines the identity of this interval and its relative position with respect to other intervals in a sequence of intervals.
32 self
.sequenceNumber
= sequenceNumber
34 #: A real time marker that defines the starting time (typically it is the time of day) for this interval. The interval extends to the start of the next interval or until it is reset to the start of the first interval by TariffProfile.tariffCycle.
35 self
.startDateTime
= startDateTime
37 self
._TariffProfiles
= []
38 self
.TariffProfiles
= [] if TariffProfiles
is None else TariffProfiles
41 self
.Charges
= [] if Charges
is None else Charges
43 super(TimeTariffInterval
, self
).__init
__(*args
, **kw_args
)
45 _attrs
= ["sequenceNumber", "startDateTime"]
46 _attr_types
= {"sequenceNumber": int, "startDateTime": str}
47 _defaults
= {"sequenceNumber": 0, "startDateTime": ''}
49 _refs
= ["TariffProfiles", "Charges"]
50 _many_refs
= ["TariffProfiles", "Charges"]
52 def getTariffProfiles(self
):
53 """All tariff profiles defined by this time tariff interval.
55 return self
._TariffProfiles
57 def setTariffProfiles(self
, value
):
58 for p
in self
._TariffProfiles
:
59 filtered
= [q
for q
in p
.TimeTariffIntervals
if q
!= self
]
60 self
._TariffProfiles
._TimeTariffIntervals
= filtered
62 if self
not in r
._TimeTariffIntervals
:
63 r
._TimeTariffIntervals
.append(self
)
64 self
._TariffProfiles
= value
66 TariffProfiles
= property(getTariffProfiles
, setTariffProfiles
)
68 def addTariffProfiles(self
, *TariffProfiles
):
69 for obj
in TariffProfiles
:
70 if self
not in obj
._TimeTariffIntervals
:
71 obj
._TimeTariffIntervals
.append(self
)
72 self
._TariffProfiles
.append(obj
)
74 def removeTariffProfiles(self
, *TariffProfiles
):
75 for obj
in TariffProfiles
:
76 if self
in obj
._TimeTariffIntervals
:
77 obj
._TimeTariffIntervals
.remove(self
)
78 self
._TariffProfiles
.remove(obj
)
81 """All charges used to define this time tariff interval.
85 def setCharges(self
, value
):
86 for p
in self
._Charges
:
87 filtered
= [q
for q
in p
.TimeTariffIntervals
if q
!= self
]
88 self
._Charges
._TimeTariffIntervals
= filtered
90 if self
not in r
._TimeTariffIntervals
:
91 r
._TimeTariffIntervals
.append(self
)
94 Charges
= property(getCharges
, setCharges
)
96 def addCharges(self
, *Charges
):
98 if self
not in obj
._TimeTariffIntervals
:
99 obj
._TimeTariffIntervals
.append(self
)
100 self
._Charges
.append(obj
)
102 def removeCharges(self
, *Charges
):
104 if self
in obj
._TimeTariffIntervals
:
105 obj
._TimeTariffIntervals
.remove(self
)
106 self
._Charges
.remove(obj
)