@smartdcc/duis-templates 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,6 +14,12 @@ the templates from `XML` into `JSON` is managed by the
14
14
  [Fuse.js][fusejs] library to easily search the templates, e.g. by *GBCS Use
15
15
  Case*, *Service Request Variant*, *Service Request Name*.
16
16
 
17
+ ## Tariff Builder
18
+
19
+ Tariff data within GB smart metering is complex and directly building a tariff
20
+ from a template is non-trivial. To help reduce the burden, a tariff builder is
21
+ provided within this library. See example below.
22
+
17
23
  ## Usage
18
24
 
19
25
  Developed and tested against `node 16`. Install from `npm`:
@@ -179,6 +185,130 @@ The structure of the result set is described in the Fuse.js documentation. Of
179
185
  interest, the `matches` item shows which key in the Template was matched and the
180
186
  position in the string too.
181
187
 
188
+ ## Lookup GBCS usecase details
189
+
190
+ It is possible to map a use case code to a textual names directly without the
191
+ service request. This is exposed as:
192
+
193
+ ```ts
194
+ import { lookupGBCS } from '@smartdcc/duis-templates'
195
+
196
+ console.log(lookupGBCS('ECS17b'))
197
+ ```
198
+
199
+ Which might return:
200
+
201
+ ```js
202
+ {
203
+ 'Use Case Name': 'Read Import Energy / Consumption Registers',
204
+ 'Use Case Title': 'ECS17b Read ESME Energy Registers (Import Energy)',
205
+ 'Message Type': 'SME.C.NC',
206
+ 'Use Case Description': 'This Use Case is for reading the ESME import energy registers / GSME consumption registers.',
207
+ 'Remote Party or HAN Message': 'Remote Party',
208
+ 'Service Reference': '4.1',
209
+ Code: 'ECS17b'
210
+ }
211
+ ```
212
+
213
+ ## Build ESME Tariff
214
+
215
+ The library includes utility functions to help build a service request `1.1.1` -
216
+ *Update Import Tariff (Primary Element)* for an ESME.
217
+
218
+ This consists of two parts, first a TypeScript [definition of a
219
+ tariff](./src/tariff.dto.ts) and then a [utility function](./src/tariff.ts) to
220
+ convert this into a DUIS request. They TypeScript definition of a tariff
221
+ attempts to be as close as possible to the underlying DUIS request, so an
222
+ understanding of service request `1.1.1` is required, which can be found in
223
+ [dugids][dugids].
224
+
225
+ A simple tariff which is £0.55/day standing charge and £0.20/kWh can be defined
226
+ as follows:
227
+
228
+ ```ts
229
+ import { Tariff } from '@smartdcc/duis-parser'
230
+
231
+ const tariff: Tariff = {
232
+ seasons: [
233
+ {
234
+ name: 'all',
235
+ weekProfile: 1
236
+ },
237
+ ],
238
+ weekProfiles: [[1, 1, 1, 1, 1, 1, 1]],
239
+ dayProfiles: [
240
+ [
241
+ {
242
+ mode: 'tou',
243
+ startTime: 0,
244
+ action: 1,
245
+ },
246
+ ],
247
+ ],
248
+ specialDays: [],
249
+ tous: [20],
250
+ blocks: [
251
+ {
252
+ prices: [0, 0],
253
+ thresholds: [ 0],
254
+ },
255
+ {
256
+ prices: [0, 0],
257
+ thresholds: [0],
258
+ },
259
+ {
260
+ prices: [0, 0],
261
+ thresholds: [0],
262
+ },
263
+ {
264
+ prices: [0, 0],
265
+ thresholds: [0],
266
+ },
267
+ {
268
+ prices: [0, 0],
269
+ thresholds: [0],
270
+ },
271
+ {
272
+ prices: [0, 0],
273
+ thresholds: [0],
274
+ },
275
+ {
276
+ prices: [0, 0],
277
+ thresholds: [0],
278
+ },
279
+ {
280
+ prices: [0, 0],
281
+ thresholds: [0],
282
+ },
283
+ ],
284
+ pricing: {
285
+ priceScale: -2,
286
+ standingCharge: 55,
287
+ standingChargeScale: -2,
288
+ },
289
+ }
290
+ ```
291
+
292
+ This would then be constructed into a DUIS request as follows:
293
+
294
+ ```ts
295
+ import {SimplifiedDuisOutputRequest, buildUpdateImportTariff_PrimaryElement} from '@smartdcc/duis-templates'
296
+
297
+ const req: SimplifiedDuisOutputRequest = buildUpdateImportTariff_PrimaryElement(
298
+ simpleToUTariff,
299
+ {
300
+ counter: BigInt(1006),
301
+ originatorId: '90-b3-d5-1f-30-01-00-00',
302
+ targetId: '00-db-12-34-56-78-90-a0',
303
+ },
304
+ )
305
+ ```
306
+
307
+ This can be used in the same way as the *templates* discussed
308
+ [above](#template-usage).
309
+
310
+ For more examples of tariffs, see the [test script](./test/tariff.test.ts).
311
+
182
312
  ## Contributing
183
313
 
184
314
  Contributions are welcome!
@@ -206,3 +336,4 @@ Copyright 2022, Smart DCC Limited, All rights reserved. Project is licensed unde
206
336
  [duis-parser]: https://github.com/SmartDCCInnovation/duis-parser "DUIS Parser"
207
337
  [boxed]: https://www.smartdcc.co.uk/our-smart-network/network-products-services/dcc-boxed/ "DCC Boxed"
208
338
  [fusejs]: https://fusejs.io/ "Fuse.js"
339
+ [dugids]: https://smartenergycodecompany.co.uk/document-download-centre/download-info/dugids-3-1a-operational-dugids-november-2019/ "DUGIDS"