Repository navigation
Expand file tree
/
Copy pathtypes.go
More file actions
254 lines (222 loc) · 7.79 KB
/
Copy pathtypes.go
File metadata and controls
254 lines (222 loc) · 7.79 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
// SPDX-License-Identifier: MIT
package openadr
import "time"
// Metadata is assigned by the VTN when an object is created or modified. A
// VTN ignores these fields in create and update requests, so callers leave
// them zero when building an object to send.
type Metadata struct {
ID string
Created time.Time
Modified time.Time
}
// Program is a demand-response program or tariff.
type Program struct {
Metadata
// Name identifies the program and is unique within a VTN.
Name string
// IntervalPeriod is the temporal span of the program.
IntervalPeriod *IntervalPeriod
// Descriptions link to human or machine readable descriptions.
Descriptions []ProgramDescription
// PayloadDescriptors give context to the payloads of the program's
// events and reports. Each element is an EventPayloadDescriptor or a
// ReportPayloadDescriptor.
PayloadDescriptors []PayloadDescriptor
Attributes []ValuesMap
// Targets restrict which VENs may read the program. A VTN only shows a
// VEN the targets that VEN asked for.
Targets []string
}
// ProgramDescription links to a description of a program.
type ProgramDescription struct {
URL string
}
// Event communicates a demand-response request to VENs.
type Event struct {
Metadata
// ProgramID is the program the event belongs to.
ProgramID string
Name string
// Duration optionally bounds the event; it may be used to loop intervals.
Duration *Duration
// Priority orders events; a lower number is a higher priority.
Priority *int
Targets []string
ReportDescriptors []ReportDescriptor
PayloadDescriptors []EventPayloadDescriptor
// IntervalPeriod sets the default start and duration of Intervals.
IntervalPeriod *IntervalPeriod
Intervals []Interval
}
// Report carries data from a VEN in response to an event.
type Report struct {
Metadata
// ClientID is written by the VTN from the creating client's token.
ClientID string
// EventID is the event the report is associated with.
EventID string
// ClientName is chosen by the reporting client.
ClientName string
Name string
PayloadDescriptors []ReportPayloadDescriptor
Resources []ReportResource
}
// ReportResource is the report data of one resource. A ResourceName of
// AggregatedReport denotes data aggregated over several resources.
type ReportResource struct {
ResourceName string
IntervalPeriod *IntervalPeriod
Intervals []Interval
}
// AggregatedReport is the resource name of an aggregated report.
const AggregatedReport = "AGGREGATED_REPORT"
// VEN is a virtual end node known to the VTN.
type VEN struct {
Metadata
// ClientID ties the VEN to the client credentials it authenticates with.
// Business Logic supplies it; for a VEN-created object the VTN writes it
// from the token.
ClientID string
// Name is unique within a VTN.
Name string
Attributes []ValuesMap
// Targets are granted by Business Logic and decide which targeted
// programs and events the VEN may read. Only Business Logic may set them.
Targets []string
}
// Resource is a resource of a VEN, such as a device or a group of devices.
type Resource struct {
Metadata
ClientID string
// VENID is the VEN the resource belongs to.
VENID string
// Name is unique within its VEN.
Name string
Attributes []ValuesMap
// Targets are granted by Business Logic; see VEN.Targets.
Targets []string
}
// ResourceGroup is a named set of resources and of other resource groups,
// by which Business Logic arranges the resources of its VENs, for example
// by feeder or by building.
//
// Resource groups are not part of OpenADR 3.1.0. They are proposed for a
// later revision and implemented here as OpenLEADR implements them; expect
// them to change with the specification.
type ResourceGroup struct {
Metadata
Name string
Attributes []ValuesMap
Targets []string
// Children are the members of the group. A VEN is shown the resources
// that are its own, and the groups that lead to one.
Children []ResourceGroupChild
}
// ResourceGroupChildType says what a member of a resource group is.
type ResourceGroupChildType string
// The kinds of member a resource group has.
const (
// ChildResource is a resource of a VEN.
ChildResource ResourceGroupChildType = "ven_resource"
// ChildResourceGroup is another resource group.
ChildResourceGroup ResourceGroupChildType = "resource_group"
)
// ResourceGroupChild is a member of a resource group: the ID of a resource
// or of a resource group.
type ResourceGroupChild struct {
Type ResourceGroupChildType
ID string
}
// Interval is a temporal window with payloads. ID is chosen by the client
// that creates the interval and is not a sequence number.
type Interval struct {
ID int32
IntervalPeriod *IntervalPeriod
Payloads []ValuesMap
}
// IntervalPeriod defines the temporal aspects of one or more intervals.
//
// The specification gives two values a special meaning: a Start in year 1
// may mean "now", and a Duration of P9999Y may mean "indefinitely"; see
// Duration.IsInfinite.
type IntervalPeriod struct {
Start *time.Time
Duration *Duration
// RandomizeStart is the range of a client-applied offset to Start.
RandomizeStart *Duration
}
// ValuesMap is a list of values together with a type that says what they
// are, such as "PRICE". Type is one of the strings enumerated in the
// specification or a privately defined one; this package does not restrict it.
type ValuesMap struct {
Type string
Values []Value
}
// PayloadDescriptor is an EventPayloadDescriptor or a ReportPayloadDescriptor.
type PayloadDescriptor interface {
payloadDescriptor()
}
// EventPayloadDescriptor gives context, such as units and currency, to event
// payloads of one type.
type EventPayloadDescriptor struct {
PayloadType string
Units string
Currency string
}
// ReportPayloadDescriptor gives context, such as units and data quality, to
// report payloads of one type.
type ReportPayloadDescriptor struct {
PayloadType string
ReadingType string
Units string
Accuracy *float64
// Confidence is a percentage, 0 to 100.
Confidence *int
}
func (EventPayloadDescriptor) payloadDescriptor() {}
func (ReportPayloadDescriptor) payloadDescriptor() {}
// ReportIntervals says which intervals a requested report covers.
type ReportIntervals string
// Report interval options defined by OpenADR 3.1.0.
const (
ReportIntervalsIntervals ReportIntervals = "INTERVALS"
ReportIntervalsSubIntervals ReportIntervals = "SUB_INTERVALS"
ReportIntervalsOpen ReportIntervals = "OPEN_INTERVALS"
)
// ReportDescriptor requests a report from a VEN. NewReportDescriptor returns
// one holding the defaults of the specification; the zero value does not.
type ReportDescriptor struct {
PayloadType string
ReadingType string
Units string
Targets []string
// Aggregate asks for one result over all targeted resources.
Aggregate bool
// StartInterval is the interval on which to report; -1 is the end of
// the last interval.
StartInterval int32
// NumIntervals is the number of intervals to include; -1 is all.
NumIntervals int32
// Historical reports on the intervals before StartInterval, as opposed
// to those after it.
Historical bool
// Frequency is the number of intervals between reports; -1 is the same
// as NumIntervals.
Frequency int32
// Repeat is the number of reports to generate; -1 is indefinitely.
Repeat int32
ReportIntervals ReportIntervals
}
// NewReportDescriptor returns a descriptor for payloadType with every other
// field at the default the specification defines for it.
func NewReportDescriptor(payloadType string) ReportDescriptor {
return ReportDescriptor{
PayloadType: payloadType,
StartInterval: -1,
NumIntervals: -1,
Historical: true,
Frequency: -1,
Repeat: 1,
ReportIntervals: ReportIntervalsIntervals,
}
}