@smartdcc/duis-templates 0.3.0 → 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 +106 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/tariff.d.ts +18 -0
- package/dist/tariff.d.ts.map +1 -0
- package/dist/tariff.dto.d.ts +124 -0
- package/dist/tariff.dto.d.ts.map +1 -0
- package/dist/tariff.dto.js +35 -0
- package/dist/tariff.dto.js.map +1 -0
- package/dist/tariff.is.d.ts +27 -0
- package/dist/tariff.is.d.ts.map +1 -0
- package/dist/tariff.is.js +228 -0
- package/dist/tariff.is.js.map +1 -0
- package/dist/tariff.js +178 -0
- package/dist/tariff.js.map +1 -0
- package/package.json +10 -7
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`:
|
|
@@ -204,6 +210,105 @@ Which might return:
|
|
|
204
210
|
}
|
|
205
211
|
```
|
|
206
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
|
+
|
|
207
312
|
## Contributing
|
|
208
313
|
|
|
209
314
|
Contributions are welcome!
|
|
@@ -231,3 +336,4 @@ Copyright 2022, Smart DCC Limited, All rights reserved. Project is licensed unde
|
|
|
231
336
|
[duis-parser]: https://github.com/SmartDCCInnovation/duis-parser "DUIS Parser"
|
|
232
337
|
[boxed]: https://www.smartdcc.co.uk/our-smart-network/network-products-services/dcc-boxed/ "DCC Boxed"
|
|
233
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"
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { loadTemplates, lookupGBCS, GBCSRecord, Template, TemplateDirectory, } from './load';
|
|
2
2
|
export { search, searchGBCS } from './search';
|
|
3
|
+
export { buildUpdateImportTariff_PrimaryElement } from './tariff';
|
|
4
|
+
export type * from './tariff.dto';
|
|
5
|
+
export { isTariff } from './tariff.is';
|
|
3
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,aAAa,EACb,UAAU,EACV,UAAU,EACV,QAAQ,EACR,iBAAiB,GAClB,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,aAAa,EACb,UAAU,EACV,UAAU,EACV,QAAQ,EACR,iBAAiB,GAClB,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,sCAAsC,EAAE,MAAM,UAAU,CAAA;AACjE,mBAAmB,cAAc,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -18,11 +18,15 @@
|
|
|
18
18
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.searchGBCS = exports.search = exports.lookupGBCS = exports.loadTemplates = void 0;
|
|
21
|
+
exports.isTariff = exports.buildUpdateImportTariff_PrimaryElement = exports.searchGBCS = exports.search = exports.lookupGBCS = exports.loadTemplates = void 0;
|
|
22
22
|
var load_1 = require("./load");
|
|
23
23
|
Object.defineProperty(exports, "loadTemplates", { enumerable: true, get: function () { return load_1.loadTemplates; } });
|
|
24
24
|
Object.defineProperty(exports, "lookupGBCS", { enumerable: true, get: function () { return load_1.lookupGBCS; } });
|
|
25
25
|
var search_1 = require("./search");
|
|
26
26
|
Object.defineProperty(exports, "search", { enumerable: true, get: function () { return search_1.search; } });
|
|
27
27
|
Object.defineProperty(exports, "searchGBCS", { enumerable: true, get: function () { return search_1.searchGBCS; } });
|
|
28
|
+
var tariff_1 = require("./tariff");
|
|
29
|
+
Object.defineProperty(exports, "buildUpdateImportTariff_PrimaryElement", { enumerable: true, get: function () { return tariff_1.buildUpdateImportTariff_PrimaryElement; } });
|
|
30
|
+
var tariff_is_1 = require("./tariff.is");
|
|
31
|
+
Object.defineProperty(exports, "isTariff", { enumerable: true, get: function () { return tariff_is_1.isTariff; } });
|
|
28
32
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAEH,+BAMe;AALb,qGAAA,aAAa,OAAA;AACb,kGAAA,UAAU,OAAA;AAKZ,mCAA6C;AAApC,gGAAA,MAAM,OAAA;AAAE,oGAAA,UAAU,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAEH,+BAMe;AALb,qGAAA,aAAa,OAAA;AACb,kGAAA,UAAU,OAAA;AAKZ,mCAA6C;AAApC,gGAAA,MAAM,OAAA;AAAE,oGAAA,UAAU,OAAA;AAC3B,mCAAiE;AAAxD,gIAAA,sCAAsC,OAAA;AAE/C,yCAAsC;AAA7B,qGAAA,QAAQ,OAAA"}
|
package/dist/tariff.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RequestId, SimplifiedDuisOutputRequest, XMLData } from '@smartdcc/duis-parser';
|
|
2
|
+
import { Tariff } from './tariff.dto';
|
|
3
|
+
export declare function singlify(d: XMLData[]): XMLData[] | XMLData;
|
|
4
|
+
export declare function buildDate(d: {
|
|
5
|
+
year?: number;
|
|
6
|
+
month?: number;
|
|
7
|
+
dayOfMonth?: number;
|
|
8
|
+
dayOfWeek?: number;
|
|
9
|
+
}): XMLData;
|
|
10
|
+
/**
|
|
11
|
+
* Builds SRV 1.1.1 from a Tariff object
|
|
12
|
+
*
|
|
13
|
+
* @param t Tariff object
|
|
14
|
+
* @param requestId
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildUpdateImportTariff_PrimaryElement(t: Tariff, requestId: RequestId<bigint>): SimplifiedDuisOutputRequest;
|
|
18
|
+
//# sourceMappingURL=tariff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tariff.d.ts","sourceRoot":"","sources":["../src/tariff.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,SAAS,EACT,2BAA2B,EAC3B,OAAO,EAGR,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,OAAO,CAK1D;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,GAAG,OAAO,CAuBV;AAED;;;;;;GAMG;AACH,wBAAgB,sCAAsC,CACpD,CAAC,EAAE,MAAM,EACT,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,GAC3B,2BAA2B,CAsL7B"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export type Tuple<T, N extends number, Q extends T[] = []> = N extends Q['length'] ? Q : Tuple<T, N, [...Q, T]>;
|
|
2
|
+
export type TupleMinMax<T, Min extends number, Max extends number, Q extends T[] = Tuple<T, Min>> = Max extends Q['length'] ? Q : Q | TupleMinMax<T, Min, Max, [...Q, T]>;
|
|
3
|
+
export interface Season {
|
|
4
|
+
name: string;
|
|
5
|
+
/**
|
|
6
|
+
* 4 digit year, or undefined for wildcard
|
|
7
|
+
*/
|
|
8
|
+
year?: number;
|
|
9
|
+
/**
|
|
10
|
+
* 1 = jan ... 12 = dec, or undefined for wildcard
|
|
11
|
+
*/
|
|
12
|
+
month?: number;
|
|
13
|
+
/**
|
|
14
|
+
* 1..31, or undefined for wildcard
|
|
15
|
+
*/
|
|
16
|
+
dayOfMonth?: number;
|
|
17
|
+
/**
|
|
18
|
+
* 1..7, or undefined for wildcard
|
|
19
|
+
*/
|
|
20
|
+
dayOfWeek?: number;
|
|
21
|
+
/**
|
|
22
|
+
* 1..4, index week profile
|
|
23
|
+
*/
|
|
24
|
+
weekProfile: number;
|
|
25
|
+
}
|
|
26
|
+
export type Seasons = TupleMinMax<Season, 1, 4>;
|
|
27
|
+
export type NumberRange<N extends number, Q extends number[] = [1]> = N extends Q['length'] ? Q['length'] : NumberRange<N, [...Q, 1]> | Q['length'];
|
|
28
|
+
export type ProfileSchedule = {
|
|
29
|
+
/**
|
|
30
|
+
* seconds from 00:00:00 UTC
|
|
31
|
+
*/
|
|
32
|
+
startTime: number;
|
|
33
|
+
} & ({
|
|
34
|
+
mode: 'tou';
|
|
35
|
+
action: NumberRange<48>;
|
|
36
|
+
} | {
|
|
37
|
+
mode: 'block';
|
|
38
|
+
action: NumberRange<8>;
|
|
39
|
+
});
|
|
40
|
+
export type DayProfile = TupleMinMax<ProfileSchedule, 1, 48>;
|
|
41
|
+
export type DayProfiles = TupleMinMax<DayProfile, 1, 16>;
|
|
42
|
+
export type DayProfileName = NumberRange<16>;
|
|
43
|
+
export type WeekProfile = [
|
|
44
|
+
DayProfileName,
|
|
45
|
+
DayProfileName,
|
|
46
|
+
DayProfileName,
|
|
47
|
+
DayProfileName,
|
|
48
|
+
DayProfileName,
|
|
49
|
+
DayProfileName,
|
|
50
|
+
DayProfileName
|
|
51
|
+
];
|
|
52
|
+
export type WeekProfiles = TupleMinMax<WeekProfile, 1, 4>;
|
|
53
|
+
export type BlockAction = {
|
|
54
|
+
thresholds: [number];
|
|
55
|
+
prices: [number, number];
|
|
56
|
+
} | {
|
|
57
|
+
thresholds: [number, number];
|
|
58
|
+
prices: [number, number, number];
|
|
59
|
+
} | {
|
|
60
|
+
thresholds: [number, number, number];
|
|
61
|
+
prices: [number, number, number, number];
|
|
62
|
+
};
|
|
63
|
+
export type Blocks = Tuple<BlockAction, 8>;
|
|
64
|
+
export type TOUAction = number;
|
|
65
|
+
export type TOUs = TupleMinMax<TOUAction, 1, 48> | [];
|
|
66
|
+
export declare function scheduleSize(dp: DayProfile, ps: ProfileSchedule): number;
|
|
67
|
+
export interface Pricing {
|
|
68
|
+
/**
|
|
69
|
+
* positive integer
|
|
70
|
+
* */
|
|
71
|
+
standingCharge: number;
|
|
72
|
+
/**
|
|
73
|
+
* positive integer
|
|
74
|
+
*
|
|
75
|
+
* scale applied to standingCharge, e.g. 0 sets standingCharge to pounds and
|
|
76
|
+
* -2 sets standingCharge to pence.
|
|
77
|
+
*
|
|
78
|
+
* standingCharge * 10^standingChargeScale
|
|
79
|
+
*/
|
|
80
|
+
standingChargeScale: number;
|
|
81
|
+
/**
|
|
82
|
+
* positive integer
|
|
83
|
+
*
|
|
84
|
+
* scale applied to tou and block tariff elements, e.g. 0 sets to pounds and
|
|
85
|
+
* -2 sets to pence.
|
|
86
|
+
*/
|
|
87
|
+
priceScale: number;
|
|
88
|
+
}
|
|
89
|
+
export interface SpecialDay {
|
|
90
|
+
/**
|
|
91
|
+
* 4 digit year, or undefined for wildcard
|
|
92
|
+
*/
|
|
93
|
+
year?: number;
|
|
94
|
+
/**
|
|
95
|
+
* 1 = jan ... 12 = dec, or undefined for wildcard
|
|
96
|
+
*/
|
|
97
|
+
month?: number;
|
|
98
|
+
/**
|
|
99
|
+
* 1..31, or undefined for wildcard
|
|
100
|
+
*/
|
|
101
|
+
dayOfMonth?: number;
|
|
102
|
+
/**
|
|
103
|
+
* 1..7, or undefined for wildcard
|
|
104
|
+
*/
|
|
105
|
+
dayOfWeek?: number;
|
|
106
|
+
/**
|
|
107
|
+
* 1..16, index day profile
|
|
108
|
+
*/
|
|
109
|
+
dayProfile: number;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 0 to 50 SpecialDays
|
|
113
|
+
*/
|
|
114
|
+
export type SpecialDays = SpecialDay[];
|
|
115
|
+
export interface Tariff {
|
|
116
|
+
seasons: Seasons;
|
|
117
|
+
weekProfiles: WeekProfiles;
|
|
118
|
+
dayProfiles: DayProfiles;
|
|
119
|
+
specialDays: SpecialDays;
|
|
120
|
+
blocks: Blocks;
|
|
121
|
+
tous: TOUs;
|
|
122
|
+
pricing: Pricing;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=tariff.dto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tariff.dto.d.ts","sourceRoot":"","sources":["../src/tariff.dto.ts"],"names":[],"mappings":"AAmBA,MAAM,MAAM,KAAK,CACf,CAAC,EACD,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,IAChB,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAItD,MAAM,MAAM,WAAW,CACrB,CAAC,EACD,GAAG,SAAS,MAAM,EAClB,GAAG,SAAS,MAAM,EAClB,CAAC,SAAS,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,IAC3B,GAAG,SAAS,CAAC,CAAC,QAAQ,CAAC,GAAG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IAEb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,UAAU,EAAE,CAAA;AAEtC,MAAM,WAAW,MAAM;IACrB,OAAO,EAAE,OAAO,CAAA;IAChB,YAAY,EAAE,YAAY,CAAA;IAC1B,WAAW,EAAE,WAAW,CAAA;IACxB,WAAW,EAAE,WAAW,CAAA;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,IAAI,CAAA;IACV,OAAO,EAAE,OAAO,CAAA;CACjB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Created on Thu Jul 20 2023
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2023 Smart DCC Limited
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU General Public License
|
|
18
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.scheduleSize = void 0;
|
|
22
|
+
function scheduleSize(dp, ps) {
|
|
23
|
+
const start = Math.floor(ps.startTime / 1800);
|
|
24
|
+
let end = 48;
|
|
25
|
+
const i = dp.indexOf(ps);
|
|
26
|
+
if (i < 0) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
if (dp.length > i + 1) {
|
|
30
|
+
end = Math.floor(dp[i + 1].startTime / 1800);
|
|
31
|
+
}
|
|
32
|
+
return end - start;
|
|
33
|
+
}
|
|
34
|
+
exports.scheduleSize = scheduleSize;
|
|
35
|
+
//# sourceMappingURL=tariff.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tariff.dto.js","sourceRoot":"","sources":["../src/tariff.dto.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAuGH,SAAgB,YAAY,CAAC,EAAc,EAAE,EAAmB;IAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,GAAG,IAAI,CAAC,CAAA;IAC7C,IAAI,GAAG,GAAG,EAAE,CAAA;IAEZ,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IACxB,IAAI,CAAC,GAAG,CAAC,EAAE;QACT,OAAO,CAAC,CAAA;KACT;IAED,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,EAAE;QACrB,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,CAAA;KAC7C;IACD,OAAO,GAAG,GAAG,KAAK,CAAA;AACpB,CAAC;AAbD,oCAaC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BlockAction, DayProfiles, NumberRange, Pricing, ProfileSchedule, Season, SpecialDay, SpecialDays, TOUs, Tariff, Tuple, TupleMinMax, WeekProfile, WeekProfiles } from './tariff.dto';
|
|
2
|
+
export declare function isTuple<T, N extends number, Q extends T[] = []>(x: unknown, n: N, isT: (x: unknown) => x is T): x is Tuple<T, N, Q>;
|
|
3
|
+
export declare function isTupleMinMax<T, Min extends number, Max extends number, Q extends T[] = Tuple<T, Min>>(x: unknown, min: Min, max: Max, isT: (x: unknown) => x is T): x is TupleMinMax<T, Min, Max, Q>;
|
|
4
|
+
export declare function isSeason(x: unknown): x is Season;
|
|
5
|
+
export declare const isSeasons: (x: unknown) => x is [Season] | [Season, Season] | [Season, Season, Season] | [Season, Season, Season, Season];
|
|
6
|
+
export declare function isNumberRange<N extends number>(x: unknown, n: N): x is NumberRange<N>;
|
|
7
|
+
export declare function isProfileSchedule(x: unknown): x is ProfileSchedule;
|
|
8
|
+
export declare const isDayProfile: (x: unknown) => x is [ProfileSchedule] | [ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule] | [ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule, ProfileSchedule];
|
|
9
|
+
export declare const isDayProfiles: (x: unknown) => x is DayProfiles;
|
|
10
|
+
export declare const isDayProfileName: (x: unknown) => x is 2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16;
|
|
11
|
+
export declare const isWeekProfile: (x: unknown) => x is WeekProfile;
|
|
12
|
+
export declare const isWeekProfiles: (x: unknown) => x is WeekProfiles;
|
|
13
|
+
export declare function isBlockAction(x: unknown): x is BlockAction;
|
|
14
|
+
export declare const isBlocks: (x: unknown) => x is [BlockAction, BlockAction, BlockAction, BlockAction, BlockAction, BlockAction, BlockAction, BlockAction];
|
|
15
|
+
export declare const isTOUs: (x: unknown) => x is TOUs;
|
|
16
|
+
export declare function isPricing(x: unknown): x is Pricing;
|
|
17
|
+
export declare function isSpecialDay(x: unknown): x is SpecialDay;
|
|
18
|
+
export declare const isSpecialDays: (x: unknown) => x is SpecialDays;
|
|
19
|
+
export declare function isTariff(x: unknown): x is Tariff;
|
|
20
|
+
/**
|
|
21
|
+
* Determine if parameter is a valid tariff. This is a restriction on isTariff
|
|
22
|
+
* by also checking items which are not enforced by the type system.
|
|
23
|
+
*
|
|
24
|
+
* @param x a Tariff object
|
|
25
|
+
*/
|
|
26
|
+
export declare function isValidTariff(x: unknown): x is Tariff;
|
|
27
|
+
//# sourceMappingURL=tariff.is.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tariff.is.d.ts","sourceRoot":"","sources":["../src/tariff.is.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EACV,WAAW,EAIX,WAAW,EACX,WAAW,EACX,OAAO,EACP,eAAe,EACf,MAAM,EAEN,UAAU,EACV,WAAW,EACX,IAAI,EACJ,MAAM,EACN,KAAK,EACL,WAAW,EACX,WAAW,EACX,YAAY,EACb,MAAM,cAAc,CAAA;AAErB,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,EAC7D,CAAC,EAAE,OAAO,EACV,CAAC,EAAE,CAAC,EACJ,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,GAC1B,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAMrB;AAID,wBAAgB,aAAa,CAC3B,CAAC,EACD,GAAG,SAAS,MAAM,EAClB,GAAG,SAAS,MAAM,EAClB,CAAC,SAAS,C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AAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,UAAU,CAYxD;AAED,eAAO,MAAM,aAAa,MAAO,OAAO,qBACG,CAAA;AAE3C,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAchD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAwGrD"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Created on Fri Aug 11 2023
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2023 Smart DCC Limited
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU General Public License
|
|
18
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.isValidTariff = exports.isTariff = exports.isSpecialDays = exports.isSpecialDay = exports.isPricing = exports.isTOUs = exports.isBlocks = exports.isBlockAction = exports.isWeekProfiles = exports.isWeekProfile = exports.isDayProfileName = exports.isDayProfiles = exports.isDayProfile = exports.isProfileSchedule = exports.isNumberRange = exports.isSeasons = exports.isSeason = exports.isTupleMinMax = exports.isTuple = void 0;
|
|
22
|
+
function isTuple(x, n, isT) {
|
|
23
|
+
const y = x;
|
|
24
|
+
if (y === null || y === undefined || !Array.isArray(y) || y.length !== n) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return y.every(isT);
|
|
28
|
+
}
|
|
29
|
+
exports.isTuple = isTuple;
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
function isTupleMinMax(x, min, max, isT) {
|
|
33
|
+
const y = x;
|
|
34
|
+
if (y === null ||
|
|
35
|
+
y === undefined ||
|
|
36
|
+
!Array.isArray(y) ||
|
|
37
|
+
y.length < min ||
|
|
38
|
+
y.length > max) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return y.every(isT);
|
|
42
|
+
}
|
|
43
|
+
exports.isTupleMinMax = isTupleMinMax;
|
|
44
|
+
function isSeason(x) {
|
|
45
|
+
const y = x;
|
|
46
|
+
return (y !== null &&
|
|
47
|
+
y !== undefined &&
|
|
48
|
+
typeof y === 'object' &&
|
|
49
|
+
typeof y.name === 'string' &&
|
|
50
|
+
typeof y.weekProfile === 'number' &&
|
|
51
|
+
['undefined', 'number'].includes(typeof y.year) &&
|
|
52
|
+
['undefined', 'number'].includes(typeof y.month) &&
|
|
53
|
+
['undefined', 'number'].includes(typeof y.dayOfMonth) &&
|
|
54
|
+
['undefined', 'number'].includes(typeof y.dayOfWeek));
|
|
55
|
+
}
|
|
56
|
+
exports.isSeason = isSeason;
|
|
57
|
+
const isSeasons = (x) => isTupleMinMax(x, 1, 4, isSeason);
|
|
58
|
+
exports.isSeasons = isSeasons;
|
|
59
|
+
function isNumberRange(x, n) {
|
|
60
|
+
return typeof x === 'number' && Number.isInteger(x) && x > 0 && x <= n;
|
|
61
|
+
}
|
|
62
|
+
exports.isNumberRange = isNumberRange;
|
|
63
|
+
function isProfileSchedule(x) {
|
|
64
|
+
const y = x;
|
|
65
|
+
if (y === null ||
|
|
66
|
+
y === undefined ||
|
|
67
|
+
typeof y !== 'object' ||
|
|
68
|
+
!['tou', 'block'].includes(y.mode) ||
|
|
69
|
+
typeof y.startTime !== 'number') {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return ((y.mode === 'tou' && isNumberRange(y.action, 48)) ||
|
|
73
|
+
(y.mode === 'block' && isNumberRange(y.action, 8)));
|
|
74
|
+
}
|
|
75
|
+
exports.isProfileSchedule = isProfileSchedule;
|
|
76
|
+
const isDayProfile = (x) => isTupleMinMax(x, 1, 48, isProfileSchedule);
|
|
77
|
+
exports.isDayProfile = isDayProfile;
|
|
78
|
+
const isDayProfiles = (x) => isTupleMinMax(x, 1, 16, exports.isDayProfile);
|
|
79
|
+
exports.isDayProfiles = isDayProfiles;
|
|
80
|
+
const isDayProfileName = (x) => isNumberRange(x, 16);
|
|
81
|
+
exports.isDayProfileName = isDayProfileName;
|
|
82
|
+
const isWeekProfile = (x) => isTuple(x, 7, exports.isDayProfileName);
|
|
83
|
+
exports.isWeekProfile = isWeekProfile;
|
|
84
|
+
const isWeekProfiles = (x) => isTupleMinMax(x, 1, 4, exports.isWeekProfile);
|
|
85
|
+
exports.isWeekProfiles = isWeekProfiles;
|
|
86
|
+
function isBlockAction(x) {
|
|
87
|
+
const y = x;
|
|
88
|
+
return (y !== null &&
|
|
89
|
+
y !== undefined &&
|
|
90
|
+
typeof y === 'object' &&
|
|
91
|
+
Array.isArray(y.prices) &&
|
|
92
|
+
Array.isArray(y.thresholds) &&
|
|
93
|
+
y.prices.every((p) => typeof p === 'number') &&
|
|
94
|
+
y.thresholds.every((t) => typeof t === 'number') &&
|
|
95
|
+
((y.thresholds.length === 1 && y.prices.length === 2) ||
|
|
96
|
+
(y.thresholds.length === 2 && y.prices.length === 3) ||
|
|
97
|
+
(y.thresholds.length === 3 && y.prices.length === 4)));
|
|
98
|
+
}
|
|
99
|
+
exports.isBlockAction = isBlockAction;
|
|
100
|
+
const isBlocks = (x) => isTuple(x, 8, isBlockAction);
|
|
101
|
+
exports.isBlocks = isBlocks;
|
|
102
|
+
const isTOUs = (x) => isTupleMinMax(x, 0, 48, (n) => typeof n === 'number');
|
|
103
|
+
exports.isTOUs = isTOUs;
|
|
104
|
+
function isPricing(x) {
|
|
105
|
+
const y = x;
|
|
106
|
+
return (y !== null &&
|
|
107
|
+
y !== undefined &&
|
|
108
|
+
typeof y === 'object' &&
|
|
109
|
+
typeof y.priceScale === 'number' &&
|
|
110
|
+
typeof y.standingCharge === 'number' &&
|
|
111
|
+
typeof y.standingChargeScale === 'number');
|
|
112
|
+
}
|
|
113
|
+
exports.isPricing = isPricing;
|
|
114
|
+
function isSpecialDay(x) {
|
|
115
|
+
const y = x;
|
|
116
|
+
return (y !== null &&
|
|
117
|
+
y !== undefined &&
|
|
118
|
+
typeof y === 'object' &&
|
|
119
|
+
typeof y.dayProfile === 'number' &&
|
|
120
|
+
['undefined', 'number'].includes(typeof y.year) &&
|
|
121
|
+
['undefined', 'number'].includes(typeof y.month) &&
|
|
122
|
+
['undefined', 'number'].includes(typeof y.dayOfMonth) &&
|
|
123
|
+
['undefined', 'number'].includes(typeof y.dayOfWeek));
|
|
124
|
+
}
|
|
125
|
+
exports.isSpecialDay = isSpecialDay;
|
|
126
|
+
const isSpecialDays = (x) => Array.isArray(x) && x.every(isSpecialDay);
|
|
127
|
+
exports.isSpecialDays = isSpecialDays;
|
|
128
|
+
function isTariff(x) {
|
|
129
|
+
const y = x;
|
|
130
|
+
return (y !== null &&
|
|
131
|
+
y !== undefined &&
|
|
132
|
+
typeof y === 'object' &&
|
|
133
|
+
(0, exports.isSeasons)(y.seasons) &&
|
|
134
|
+
(0, exports.isWeekProfiles)(y.weekProfiles) &&
|
|
135
|
+
(0, exports.isDayProfiles)(y.dayProfiles) &&
|
|
136
|
+
(0, exports.isSpecialDays)(y.specialDays) &&
|
|
137
|
+
(0, exports.isBlocks)(y.blocks) &&
|
|
138
|
+
(0, exports.isTOUs)(y.tous) &&
|
|
139
|
+
isPricing(y.pricing));
|
|
140
|
+
}
|
|
141
|
+
exports.isTariff = isTariff;
|
|
142
|
+
/**
|
|
143
|
+
* Determine if parameter is a valid tariff. This is a restriction on isTariff
|
|
144
|
+
* by also checking items which are not enforced by the type system.
|
|
145
|
+
*
|
|
146
|
+
* @param x a Tariff object
|
|
147
|
+
*/
|
|
148
|
+
function isValidTariff(x) {
|
|
149
|
+
if (isTariff(x)) {
|
|
150
|
+
/*
|
|
151
|
+
well-formedness check on day profiles:
|
|
152
|
+
each day profile starts at 0
|
|
153
|
+
each day profile start time is monotonic
|
|
154
|
+
largest profile schedule is < full day
|
|
155
|
+
*/
|
|
156
|
+
if (!x.dayProfiles.every((dp) => dp[0].startTime === 0 &&
|
|
157
|
+
dp.reduce((acc, x) => [
|
|
158
|
+
acc[0] && x.startTime > acc[1] && Number.isInteger(x.startTime),
|
|
159
|
+
x.startTime,
|
|
160
|
+
], [true, -1])[0] &&
|
|
161
|
+
dp[dp.length - 1].startTime < 60 * 60 * 24)) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
/*
|
|
165
|
+
well-formedness check on week profiles:
|
|
166
|
+
each week profile only references defined day profiles
|
|
167
|
+
*/
|
|
168
|
+
if (!x.weekProfiles.every((wp) => wp.every((dpname) => dpname - 1 < x.dayProfiles.length))) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
/*
|
|
172
|
+
well-formdness check on seasons:
|
|
173
|
+
each season only references defined week profiles
|
|
174
|
+
each year (if not wildcard) is >= 2014
|
|
175
|
+
each month (if not wildcard) is 1..12
|
|
176
|
+
each day of month (if not wildcard) is 1..31
|
|
177
|
+
each day of week (if not wildcard) is 1..7
|
|
178
|
+
*/
|
|
179
|
+
if (!x.seasons.every((s) => s.weekProfile - 1 < x.weekProfiles.length &&
|
|
180
|
+
Number.isInteger(s.year ?? 2014) &&
|
|
181
|
+
(s.year ?? 2014) >= 2014 &&
|
|
182
|
+
Number.isInteger(s.month ?? 1) &&
|
|
183
|
+
(s.month ?? 1) >= 1 &&
|
|
184
|
+
(s.month ?? 1) <= 12 &&
|
|
185
|
+
Number.isInteger(s.dayOfMonth ?? 1) &&
|
|
186
|
+
(s.dayOfMonth ?? 1) >= 1 &&
|
|
187
|
+
(s.dayOfMonth ?? 1) <= 31 &&
|
|
188
|
+
Number.isInteger(s.dayOfWeek ?? 1) &&
|
|
189
|
+
(s.dayOfWeek ?? 1) >= 1 &&
|
|
190
|
+
(s.dayOfWeek ?? 1) <= 7 &&
|
|
191
|
+
(s.year === undefined ||
|
|
192
|
+
s.month === undefined ||
|
|
193
|
+
s.dayOfMonth === undefined ||
|
|
194
|
+
s.dayOfWeek === undefined))) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
/*
|
|
198
|
+
well-formdness check on special days:
|
|
199
|
+
each special day only references defined day profiles
|
|
200
|
+
each year (if not wildcard) is >= 2014
|
|
201
|
+
each month (if not wildcard) is 1..12
|
|
202
|
+
each day of month (if not wildcard) is 1..31
|
|
203
|
+
each day of week (if not wildcard) is 1..7
|
|
204
|
+
*/
|
|
205
|
+
if (!x.specialDays.every((sd) => sd.dayProfile - 1 < x.dayProfiles.length &&
|
|
206
|
+
Number.isInteger(sd.year ?? 2014) &&
|
|
207
|
+
(sd.year ?? 2014) >= 2014 &&
|
|
208
|
+
Number.isInteger(sd.month ?? 1) &&
|
|
209
|
+
(sd.month ?? 1) >= 1 &&
|
|
210
|
+
(sd.month ?? 1) <= 12 &&
|
|
211
|
+
Number.isInteger(sd.dayOfMonth ?? 1) &&
|
|
212
|
+
(sd.dayOfMonth ?? 1) >= 1 &&
|
|
213
|
+
(sd.dayOfMonth ?? 1) <= 31 &&
|
|
214
|
+
Number.isInteger(sd.dayOfWeek ?? 1) &&
|
|
215
|
+
(sd.dayOfWeek ?? 1) >= 1 &&
|
|
216
|
+
(sd.dayOfWeek ?? 1) <= 7 &&
|
|
217
|
+
(sd.year === undefined ||
|
|
218
|
+
sd.month === undefined ||
|
|
219
|
+
sd.dayOfMonth === undefined ||
|
|
220
|
+
sd.dayOfWeek === undefined))) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
exports.isValidTariff = isValidTariff;
|
|
228
|
+
//# sourceMappingURL=tariff.is.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tariff.is.js","sourceRoot":"","sources":["../src/tariff.is.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAuBH,SAAgB,OAAO,CACrB,CAAU,EACV,CAAI,EACJ,GAA2B;IAE3B,MAAM,CAAC,GAAG,CAAa,CAAA;IACvB,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;QACxE,OAAO,KAAK,CAAA;KACb;IACD,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AACrB,CAAC;AAVD,0BAUC;AAED,6DAA6D;AAC7D,aAAa;AACb,SAAgB,aAAa,CAM3B,CAAU,EACV,GAAQ,EACR,GAAQ,EACR,GAA2B;IAE3B,MAAM,CAAC,GAAG,CAAa,CAAA;IACvB,IACE,CAAC,KAAK,IAAI;QACV,CAAC,KAAK,SAAS;QACf,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QACjB,CAAC,CAAC,MAAM,GAAG,GAAG;QACd,CAAC,CAAC,MAAM,GAAG,GAAG,EACd;QACA,OAAO,KAAK,CAAA;KACb;IACD,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AACrB,CAAC;AAtBD,sCAsBC;AAED,SAAgB,QAAQ,CAAC,CAAU;IACjC,MAAM,CAAC,GAAG,CAAW,CAAA;IACrB,OAAO,CACL,CAAC,KAAK,IAAI;QACV,CAAC,KAAK,SAAS;QACf,OAAO,CAAC,KAAK,QAAQ;QACrB,OAAO,CAAC,CAAC,IAAI,KA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YACpC,CAAC,EAAE,CAAC,UAAU,IAAI,CAAC,CAAC,IAAI,CAAC;YACzB,CAAC,EAAE,CAAC,UAAU,IAAI,CAAC,CAAC,IAAI,EAAE;YAC1B,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,IAAI,CAAC,CAAC;YACnC,CAAC,EAAE,CAAC,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC;YACxB,CAAC,EAAE,CAAC,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC;YACxB,CAAC,EAAE,CAAC,IAAI,KAAK,SAAS;gBACpB,EAAE,CAAC,KAAK,KAAK,SAAS;gBACtB,EAAE,CAAC,UAAU,KAAK,SAAS;gBAC3B,EAAE,CAAC,SAAS,KAAK,SAAS,CAAC,CAChC,EACD;YACA,OAAO,KAAK,CAAA;SACb;QAED,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAxGD,sCAwGC"}
|
package/dist/tariff.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Created on Thu Jul 20 2023
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2023 Smart DCC Limited
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU General Public License
|
|
18
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.buildUpdateImportTariff_PrimaryElement = exports.buildDate = exports.singlify = void 0;
|
|
22
|
+
const duis_parser_1 = require("@smartdcc/duis-parser");
|
|
23
|
+
function singlify(d) {
|
|
24
|
+
if (d.length === 1) {
|
|
25
|
+
return d[0];
|
|
26
|
+
}
|
|
27
|
+
return d;
|
|
28
|
+
}
|
|
29
|
+
exports.singlify = singlify;
|
|
30
|
+
function buildDate(d) {
|
|
31
|
+
return {
|
|
32
|
+
Year: d.year === undefined
|
|
33
|
+
? { NonSpecifiedYear: '' }
|
|
34
|
+
: { SpecifiedYear: `${d.year}` },
|
|
35
|
+
Month: d.month === undefined
|
|
36
|
+
? { NonSpecifiedMonth: '' }
|
|
37
|
+
: d.month === 0xfd
|
|
38
|
+
? { SecondLastDayOfMonth: '' }
|
|
39
|
+
: d.month === 0xfe
|
|
40
|
+
? { LastDayOfMonth: '' }
|
|
41
|
+
: { SpecifiedMonth: `${d.month}` },
|
|
42
|
+
DayOfMonth: d.dayOfMonth === undefined
|
|
43
|
+
? { NonSpecifiedDayOfMonth: '' }
|
|
44
|
+
: { SpecifiedDayOfMonth: `${d.dayOfMonth}` },
|
|
45
|
+
DayOfWeek: d.dayOfWeek === undefined
|
|
46
|
+
? { NonSpecifiedDayOfWeek: '' }
|
|
47
|
+
: { SpecifiedDayOfWeek: `${d.dayOfWeek}` },
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
exports.buildDate = buildDate;
|
|
51
|
+
/**
|
|
52
|
+
* Builds SRV 1.1.1 from a Tariff object
|
|
53
|
+
*
|
|
54
|
+
* @param t Tariff object
|
|
55
|
+
* @param requestId
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
function buildUpdateImportTariff_PrimaryElement(t, requestId) {
|
|
59
|
+
const serviceReferenceVariant = (0, duis_parser_1.lookupSRV)('1.1.1');
|
|
60
|
+
if (serviceReferenceVariant === undefined) {
|
|
61
|
+
throw new Error('unable to lookup srv 1.1.1');
|
|
62
|
+
}
|
|
63
|
+
const Seasons = {
|
|
64
|
+
Season: singlify(t.seasons.map((season) => ({
|
|
65
|
+
SeasonName: season.name,
|
|
66
|
+
SeasonStartDate: buildDate(season),
|
|
67
|
+
ReferencedWeekName: `${season.weekProfile}`,
|
|
68
|
+
}))),
|
|
69
|
+
};
|
|
70
|
+
const WeekProfiles = {
|
|
71
|
+
WeekProfile: singlify(t.weekProfiles.map((weekProfile, i) => ({
|
|
72
|
+
WeekName: `${i + 1}`,
|
|
73
|
+
ReferencedDayName: singlify(weekProfile.map((dayName, i) => ({
|
|
74
|
+
'#text': `${dayName}`,
|
|
75
|
+
'@_index': `${i + 1}`,
|
|
76
|
+
}))),
|
|
77
|
+
}))),
|
|
78
|
+
};
|
|
79
|
+
const DayProfiles = {
|
|
80
|
+
DayProfile: singlify(t.dayProfiles.map((dayProfile, i) => ({
|
|
81
|
+
DayName: `${i + 1}`,
|
|
82
|
+
ProfileSchedule: singlify(dayProfile.map((action) => {
|
|
83
|
+
const d = new Date(action.startTime * 1000);
|
|
84
|
+
return {
|
|
85
|
+
StartTime: `${`00${d.getUTCHours()}`.slice(-2)}:${`00${d.getUTCMinutes()}`.slice(-2)}:${`00${d.getUTCSeconds()}`.slice(-2)}.00Z`,
|
|
86
|
+
[action.mode === 'block'
|
|
87
|
+
? 'BlockTariffAction'
|
|
88
|
+
: 'TOUTariffAction']: `${action.action}`,
|
|
89
|
+
};
|
|
90
|
+
})),
|
|
91
|
+
}))),
|
|
92
|
+
};
|
|
93
|
+
const SpecialDay = t.specialDays.map((specialDay) => ({
|
|
94
|
+
Date: buildDate(specialDay),
|
|
95
|
+
ReferencedDayName: `${specialDay.dayProfile}`,
|
|
96
|
+
}));
|
|
97
|
+
let SpecialDays = '';
|
|
98
|
+
if (SpecialDay.length >= 1) {
|
|
99
|
+
SpecialDays = { SpecialDay: singlify(SpecialDay) };
|
|
100
|
+
}
|
|
101
|
+
const ThresholdMatrix = {
|
|
102
|
+
Thresholds: t.blocks.map((block, i) => ({
|
|
103
|
+
BlockThreshold: singlify(block.thresholds.map((threshold, i) => ({
|
|
104
|
+
'#text': `${threshold}`,
|
|
105
|
+
'@_index': `${i + 1}`,
|
|
106
|
+
}))),
|
|
107
|
+
'@_index': `${i + 1}`,
|
|
108
|
+
})),
|
|
109
|
+
};
|
|
110
|
+
const TOUTariff = {
|
|
111
|
+
TOUPrice: singlify(t.tous
|
|
112
|
+
.map((price, i) => ({
|
|
113
|
+
'#text': `${price}`,
|
|
114
|
+
'@_index': `${i + 1}`,
|
|
115
|
+
}))
|
|
116
|
+
.filter((x) => x['#text'] !== '0')),
|
|
117
|
+
};
|
|
118
|
+
const BlockPrices = t.blocks
|
|
119
|
+
.map((block, i) => ({
|
|
120
|
+
BlockPrice: singlify(block.prices
|
|
121
|
+
.map((price, i) => ({
|
|
122
|
+
'#text': `${price}`,
|
|
123
|
+
'@_index': `${i + 1}`,
|
|
124
|
+
}))
|
|
125
|
+
.filter((x) => x['#text'] !== '0')),
|
|
126
|
+
'@_index': `${i + 1}`,
|
|
127
|
+
}))
|
|
128
|
+
.filter((block) => t.dayProfiles.some((dayProfile) => dayProfile.some((profileSchedule) => profileSchedule.mode === 'block' &&
|
|
129
|
+
profileSchedule.action === Number(block['@_index']))));
|
|
130
|
+
const BlockTariff = {
|
|
131
|
+
BlockPrices: BlockPrices.length === 1 ? BlockPrices[0] : BlockPrices,
|
|
132
|
+
};
|
|
133
|
+
const isTOU = t.dayProfiles.some((dayProfile) => dayProfile.some((profileSchedule) => profileSchedule.mode === 'tou'));
|
|
134
|
+
const isBlock = t.dayProfiles.some((dayProfile) => dayProfile.some((profileSchedule) => profileSchedule.mode === 'block'));
|
|
135
|
+
let pricing;
|
|
136
|
+
if (isTOU && isBlock) {
|
|
137
|
+
pricing = { HybridTariff: { ...BlockTariff, ...TOUTariff } };
|
|
138
|
+
}
|
|
139
|
+
else if (isTOU) {
|
|
140
|
+
pricing = { TOUTariff };
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
pricing = { BlockTariff };
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
header: {
|
|
147
|
+
type: 'request',
|
|
148
|
+
commandVariant: (0, duis_parser_1.lookupCV)(4),
|
|
149
|
+
serviceReference: '1.1',
|
|
150
|
+
serviceReferenceVariant,
|
|
151
|
+
requestId,
|
|
152
|
+
},
|
|
153
|
+
body: {
|
|
154
|
+
UpdateImportTariffPrimaryElement: {
|
|
155
|
+
ElecTariffElements: {
|
|
156
|
+
CurrencyUnits: 'GBP',
|
|
157
|
+
SwitchingTable: {
|
|
158
|
+
DayProfiles,
|
|
159
|
+
WeekProfiles,
|
|
160
|
+
Seasons,
|
|
161
|
+
},
|
|
162
|
+
SpecialDays,
|
|
163
|
+
ThresholdMatrix,
|
|
164
|
+
},
|
|
165
|
+
PriceElements: {
|
|
166
|
+
ElectricityPriceElements: {
|
|
167
|
+
StandingCharge: `${t.pricing.standingCharge}`,
|
|
168
|
+
StandingChargeScale: `${t.pricing.standingChargeScale}`,
|
|
169
|
+
PriceScale: `${t.pricing.priceScale}`,
|
|
170
|
+
...pricing,
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
exports.buildUpdateImportTariff_PrimaryElement = buildUpdateImportTariff_PrimaryElement;
|
|
178
|
+
//# sourceMappingURL=tariff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tariff.js","sourceRoot":"","sources":["../src/tariff.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAEH,uDAM8B;AAG9B,SAAgB,QAAQ,CAAC,CAAY;IACnC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;QAClB,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;KACZ;IACD,OAAO,CAAC,CAAA;AACV,CAAC;AALD,4BAKC;AAED,SAAgB,SAAS,CAAC,CAKz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2
2
|
"name": "@smartdcc/duis-templates",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Collection of DUIS templates from RTDS along with utility functions",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -38,16 +38,19 @@
|
|
|
38
38
|
},
|
|
39
39
|
"license": "GPL-3.0-or-later",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@
|
|
41
|
+
"@smartdcc/duis-sign-wrap": "^0.1.2",
|
|
42
|
+
"@tsconfig/node16": "^16.1.1",
|
|
42
43
|
"@types/glob": "^8.0.0",
|
|
43
44
|
"@types/jest": "^29.0.0",
|
|
44
|
-
"@types/node": "^
|
|
45
|
-
"@
|
|
46
|
-
"@typescript-eslint/
|
|
45
|
+
"@types/node": "^20.1.0",
|
|
46
|
+
"@types/ungap__structured-clone": "^0.3.0",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^6.1.0",
|
|
48
|
+
"@typescript-eslint/parser": "^6.1.0",
|
|
49
|
+
"@ungap/structured-clone": "^1.2.0",
|
|
47
50
|
"del-cli": "^5.0.0",
|
|
48
51
|
"eslint": "^8.23.0",
|
|
49
|
-
"eslint-config-prettier": "^
|
|
50
|
-
"prettier": "^
|
|
52
|
+
"eslint-config-prettier": "^9.0.0",
|
|
53
|
+
"prettier": "^3.0.0",
|
|
51
54
|
"ts-jest": "^29.0.0",
|
|
52
55
|
"typescript": "^5.0.2"
|
|
53
56
|
},
|