@powercalc/power-router 1.0.39 → 1.0.42
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 +6 -0
- package/dist/app.d.ts +1 -1
- package/dist/app.js +26 -26
- package/dist/config/countrydata.json +265 -265
- package/dist/converter.d.ts +8 -8
- package/dist/converter.js +56 -59
- package/dist/converter.js.map +1 -1
- package/dist/genTypes.d.ts +4 -4
- package/dist/genTypes.js +53 -53
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -5
- package/dist/load.d.ts +7 -7
- package/dist/load.js +31 -31
- package/dist/router/config/countries.json +194 -0
- package/dist/router/config/countrydata.json +266 -0
- package/dist/router/config/types.json +333 -0
- package/dist/router/controllers/LoadAndParse.d.ts +10 -10
- package/dist/router/controllers/LoadAndParse.js +57 -57
- package/dist/router/controllers/Router.d.ts +7 -7
- package/dist/router/controllers/Router.js +105 -105
- package/dist/router/index.d.ts +2 -2
- package/dist/router/index.js +5 -5
- package/dist/router/interfaces/config.d.ts +5 -5
- package/dist/router/interfaces/config.js +2 -2
- package/dist/router/interfaces/entsoe.d.ts +50 -50
- package/dist/router/interfaces/entsoe.js +2 -2
- package/dist/router/interfaces/queryoptions.d.ts +15 -15
- package/dist/router/interfaces/queryoptions.js +15 -15
- package/dist/router/interfaces/types.d.ts +12 -12
- package/dist/router/interfaces/types.js +2 -2
- package/dist/router/services/CommonTimestamps.d.ts +15 -15
- package/dist/router/services/CommonTimestamps.js +185 -173
- package/dist/router/services/CommonTimestamps.js.map +1 -1
- package/dist/router/services/Eurostat.d.ts +10 -10
- package/dist/router/services/Eurostat.js +72 -72
- package/dist/router/services/Eurostat.js.map +1 -1
- package/dist/router/services/LoadService.d.ts +27 -27
- package/dist/router/services/LoadService.js +82 -82
- package/dist/router/services/Loader.d.ts +38 -38
- package/dist/router/services/Loader.js +119 -121
- package/dist/router/services/Loader.js.map +1 -1
- package/dist/router/services/ParseEdifact.d.ts +28 -28
- package/dist/router/services/ParseEdifact.js +159 -159
- package/dist/router/services/ParseInstalled.d.ts +9 -9
- package/dist/router/services/ParseInstalled.js +45 -45
- package/dist/router/services/batch/maxHydrofill.d.ts +10 -10
- package/dist/router/services/batch/maxHydrofill.js +65 -65
- package/package.json +53 -53
- package/src/converter.ts +61 -64
- package/src/router/config/countrydata.json +265 -265
- package/src/router/services/CommonTimestamps.ts +90 -54
- package/src/router/services/Eurostat.ts +3 -3
- package/src/router/services/Loader.ts +2 -5
|
@@ -1,68 +1,94 @@
|
|
|
1
1
|
import { DateTime, Duration } from "luxon";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AllInResulotions,
|
|
4
|
+
DataPoint,
|
|
5
|
+
DataPointResolutions,
|
|
6
|
+
} from "./ParseEdifact";
|
|
3
7
|
|
|
4
8
|
export interface Result {
|
|
5
|
-
[key: string]: (number | null)[]
|
|
9
|
+
[key: string]: (number | null)[];
|
|
6
10
|
}
|
|
7
11
|
|
|
8
12
|
export class CommonTimestamps {
|
|
9
|
-
static transform(
|
|
13
|
+
static transform(
|
|
14
|
+
all: AllInResulotions,
|
|
15
|
+
startMonth: string,
|
|
16
|
+
endMonth: string
|
|
17
|
+
): Result {
|
|
10
18
|
const best = this.bestResolution(all);
|
|
11
|
-
const time = this.makeTimeArray(startMonth, endMonth, best)
|
|
19
|
+
const time = this.makeTimeArray(startMonth, endMonth, best);
|
|
12
20
|
const result: Result = {
|
|
13
|
-
time: time
|
|
14
|
-
}
|
|
15
|
-
Object.keys(all).forEach(key => {
|
|
21
|
+
time: time,
|
|
22
|
+
};
|
|
23
|
+
Object.keys(all).forEach((key) => {
|
|
16
24
|
const item = all[key];
|
|
17
25
|
const interpolated = this.makeCommonTimeBase(item, time, best);
|
|
18
26
|
if (interpolated) {
|
|
19
|
-
result[key] = interpolated
|
|
27
|
+
result[key] = interpolated;
|
|
28
|
+
}
|
|
29
|
+
if (key === "price") {
|
|
30
|
+
if (item["PT15M"] && item["PT60M"]) {
|
|
31
|
+
result["price15m"] = result['price'];
|
|
32
|
+
delete item['PT15M'];
|
|
33
|
+
const price60 = this.makeCommonTimeBase(item, time, best);
|
|
34
|
+
if (price60) {
|
|
35
|
+
result['price'] = price60;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
20
38
|
}
|
|
21
|
-
})
|
|
39
|
+
});
|
|
40
|
+
// console.log(Object.keys(result))
|
|
22
41
|
return result;
|
|
23
42
|
}
|
|
24
|
-
static makeCommonTimeBase(
|
|
43
|
+
static makeCommonTimeBase(
|
|
44
|
+
all: DataPointResolutions,
|
|
45
|
+
newTimes: number[],
|
|
46
|
+
best: string
|
|
47
|
+
): (number | null)[] | undefined {
|
|
25
48
|
const haveToMerge = this.shouldMerge(all);
|
|
26
49
|
if (haveToMerge) {
|
|
27
|
-
const all2: DataPointResolutions = {}
|
|
28
|
-
all2[best] = []
|
|
50
|
+
const all2: DataPointResolutions = {};
|
|
51
|
+
all2[best] = [];
|
|
29
52
|
const keys = Object.keys(all);
|
|
30
|
-
keys.forEach(key => {
|
|
31
|
-
all2[best] = all2[best].concat(all[key])
|
|
32
|
-
})
|
|
33
|
-
all2[best] = all2[best].sort((a, b) => a.time - b.time)
|
|
34
|
-
return this.interpolate(all2, newTimes)
|
|
53
|
+
keys.forEach((key) => {
|
|
54
|
+
all2[best] = all2[best].concat(all[key]);
|
|
55
|
+
});
|
|
56
|
+
all2[best] = all2[best].sort((a, b) => a.time - b.time);
|
|
57
|
+
return this.interpolate(all2, newTimes);
|
|
35
58
|
}
|
|
36
|
-
const data = all[best]
|
|
59
|
+
const data = all[best];
|
|
37
60
|
if (data) {
|
|
38
|
-
return this.makeNumbers(data, newTimes)
|
|
61
|
+
return this.makeNumbers(data, newTimes);
|
|
39
62
|
} else {
|
|
40
|
-
return this.interpolate(all, newTimes)
|
|
63
|
+
return this.interpolate(all, newTimes);
|
|
41
64
|
}
|
|
42
65
|
}
|
|
43
66
|
static shouldMerge(all: DataPointResolutions): boolean {
|
|
44
67
|
let start = 0;
|
|
45
68
|
let end = 0;
|
|
46
|
-
const keys = Object.keys(all)
|
|
69
|
+
const keys = Object.keys(all);
|
|
47
70
|
if (keys.length < 2) {
|
|
48
71
|
return false;
|
|
49
72
|
}
|
|
50
73
|
let shouldMerge = true;
|
|
51
|
-
keys.forEach(key => {
|
|
52
|
-
const times = all[key].map(item => item.time);
|
|
74
|
+
keys.forEach((key) => {
|
|
75
|
+
const times = all[key].map((item) => item.time);
|
|
53
76
|
if (start && end && start > times[0] && end < times[times.length - 1]) {
|
|
54
77
|
shouldMerge = false;
|
|
55
78
|
}
|
|
56
|
-
start = times[0]
|
|
57
|
-
end = times[times.length - 1]
|
|
58
|
-
})
|
|
79
|
+
start = times[0];
|
|
80
|
+
end = times[times.length - 1];
|
|
81
|
+
});
|
|
59
82
|
return shouldMerge;
|
|
60
83
|
}
|
|
61
|
-
static interpolate(
|
|
84
|
+
static interpolate(
|
|
85
|
+
all: DataPointResolutions,
|
|
86
|
+
newTimes: number[]
|
|
87
|
+
): (number | null)[] | undefined {
|
|
62
88
|
const best = this.best(all);
|
|
63
|
-
const dur = Duration.fromISO(best).as(
|
|
89
|
+
const dur = Duration.fromISO(best).as("milliseconds");
|
|
64
90
|
const data: DataPoint[] = all[best];
|
|
65
|
-
const sourceTimes = data.map(item => item.time);
|
|
91
|
+
const sourceTimes = data.map((item) => item.time);
|
|
66
92
|
/*
|
|
67
93
|
console.log('all', new Date(all[best][0].time))
|
|
68
94
|
console.log('data', new Date(data[0].time), new Date(data[data.length -1].time))
|
|
@@ -81,12 +107,13 @@ export class CommonTimestamps {
|
|
|
81
107
|
const delta = hi.value - lo.value;
|
|
82
108
|
const timeDelta = hi.time - lo.time;
|
|
83
109
|
const timeFactor = (time - lo.time) / timeDelta;
|
|
84
|
-
if (timeDelta > 3600000 && dur * 1.5 < timeDelta) {
|
|
110
|
+
if (timeDelta > 3600000 && dur * 1.5 < timeDelta) {
|
|
111
|
+
// interpolate everything that's smaller than 61 minutes
|
|
85
112
|
result[i] = null;
|
|
86
113
|
} else {
|
|
87
|
-
result[i] = lo.value + delta * timeFactor
|
|
114
|
+
result[i] = lo.value + delta * timeFactor;
|
|
88
115
|
}
|
|
89
|
-
})
|
|
116
|
+
});
|
|
90
117
|
return result;
|
|
91
118
|
}
|
|
92
119
|
|
|
@@ -94,13 +121,13 @@ export class CommonTimestamps {
|
|
|
94
121
|
let lo = 0;
|
|
95
122
|
let hi = arr.length - 1;
|
|
96
123
|
if (arr.length === 1) {
|
|
97
|
-
return [0, 0]
|
|
124
|
+
return [0, 0];
|
|
98
125
|
}
|
|
99
126
|
if (arr[lo] > num) {
|
|
100
|
-
return [lo, lo + 1]
|
|
127
|
+
return [lo, lo + 1];
|
|
101
128
|
}
|
|
102
129
|
if (arr[hi] < num) {
|
|
103
|
-
return [hi - 1, hi]
|
|
130
|
+
return [hi - 1, hi];
|
|
104
131
|
}
|
|
105
132
|
while (hi - lo > 1) {
|
|
106
133
|
const mid = Math.trunc((lo + hi) / 2);
|
|
@@ -109,19 +136,22 @@ export class CommonTimestamps {
|
|
|
109
136
|
} else {
|
|
110
137
|
hi = mid;
|
|
111
138
|
}
|
|
112
|
-
|
|
113
139
|
}
|
|
114
|
-
return [lo, hi]
|
|
140
|
+
return [lo, hi];
|
|
115
141
|
}
|
|
116
142
|
static makeNumbers(all: DataPoint[], newTimes: number[]): (number | null)[] {
|
|
117
143
|
const result: (number | null)[] = [];
|
|
118
|
-
newTimes.forEach(time => {
|
|
119
|
-
const num = all.find(item => item.time === time)?.value || null;
|
|
120
|
-
result.push(num)
|
|
121
|
-
})
|
|
144
|
+
newTimes.forEach((time) => {
|
|
145
|
+
const num = all.find((item) => item.time === time)?.value || null;
|
|
146
|
+
result.push(num);
|
|
147
|
+
});
|
|
122
148
|
return result;
|
|
123
149
|
}
|
|
124
|
-
static makeTimeArray(
|
|
150
|
+
static makeTimeArray(
|
|
151
|
+
startIsoString: string,
|
|
152
|
+
endIsoString: string,
|
|
153
|
+
resolution: string
|
|
154
|
+
): number[] {
|
|
125
155
|
const duration = Duration.fromISO(resolution).toMillis();
|
|
126
156
|
const localStartTime = DateTime.fromISO(startIsoString);
|
|
127
157
|
const localEndTime = DateTime.fromISO(endIsoString);
|
|
@@ -133,7 +163,13 @@ export class CommonTimestamps {
|
|
|
133
163
|
// Calculate time distance in milliseconds
|
|
134
164
|
const timeDistance = utcEndTime.toMillis() - utcStartTime.toMillis();
|
|
135
165
|
if (timeDistance < duration) {
|
|
136
|
-
console.log(
|
|
166
|
+
console.log(
|
|
167
|
+
"timeDistance",
|
|
168
|
+
timeDistance,
|
|
169
|
+
duration,
|
|
170
|
+
startIsoString,
|
|
171
|
+
endIsoString
|
|
172
|
+
);
|
|
137
173
|
}
|
|
138
174
|
// Create an array with time distance duration in UTC time using Luxon
|
|
139
175
|
const timeSteps: number[] = [];
|
|
@@ -149,12 +185,12 @@ export class CommonTimestamps {
|
|
|
149
185
|
|
|
150
186
|
static best(all: any): string {
|
|
151
187
|
let min = Infinity;
|
|
152
|
-
let minPeriod =
|
|
188
|
+
let minPeriod = "";
|
|
153
189
|
const keys = Object.keys(all);
|
|
154
|
-
keys.forEach(period => {
|
|
190
|
+
keys.forEach((period) => {
|
|
155
191
|
const dur = Duration.fromISO(period);
|
|
156
|
-
if (dur.as(
|
|
157
|
-
min = dur.as(
|
|
192
|
+
if (dur.as("minutes") < min) {
|
|
193
|
+
min = dur.as("minutes");
|
|
158
194
|
minPeriod = period;
|
|
159
195
|
}
|
|
160
196
|
});
|
|
@@ -162,16 +198,16 @@ export class CommonTimestamps {
|
|
|
162
198
|
}
|
|
163
199
|
static bestResolution(all: any): string {
|
|
164
200
|
let min = Infinity;
|
|
165
|
-
let minPeriod =
|
|
201
|
+
let minPeriod = "";
|
|
166
202
|
Object.keys(all).forEach((key: string) => {
|
|
167
|
-
Object.keys(all[key]).forEach(period => {
|
|
203
|
+
Object.keys(all[key]).forEach((period) => {
|
|
168
204
|
const dur = Duration.fromISO(period);
|
|
169
|
-
if (dur.as(
|
|
170
|
-
min = dur.as(
|
|
205
|
+
if (dur.as("minutes") < min) {
|
|
206
|
+
min = dur.as("minutes");
|
|
171
207
|
minPeriod = period;
|
|
172
208
|
}
|
|
173
|
-
})
|
|
174
|
-
})
|
|
209
|
+
});
|
|
210
|
+
});
|
|
175
211
|
return minPeriod;
|
|
176
212
|
}
|
|
177
|
-
}
|
|
213
|
+
}
|
|
@@ -72,16 +72,16 @@ export class EurostatAPI {
|
|
|
72
72
|
const select = `${chartType}/${freq}.${nrg_bal}.${siec}.${unit}`;
|
|
73
73
|
const rest = `?format=JSON&lang=en&startPeriod=2015-01&endPeriod=2050-12`;
|
|
74
74
|
const url = `${baseUrl}${select}${geo}${rest}`;
|
|
75
|
-
console.log(url)
|
|
75
|
+
// console.log(url)
|
|
76
76
|
promises.push(this.fetchData(url, type, unit))
|
|
77
77
|
}
|
|
78
78
|
const res = await Promise.all(promises)
|
|
79
|
-
console.log('---res---', res)
|
|
79
|
+
// console.log('---res---', res)
|
|
80
80
|
let merged: any = {};
|
|
81
81
|
res.forEach(item => {
|
|
82
82
|
merged = { ...merged, ...item };
|
|
83
83
|
})
|
|
84
|
-
console.log('---merged----', merged)
|
|
84
|
+
// console.log('---merged----', merged)
|
|
85
85
|
return merged; // this.removeElGas(merged);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -78,15 +78,13 @@ export class EntsoeLoader {
|
|
|
78
78
|
const price = `${this.config.entsoeDomain}/api?documentType=A44&in_Domain=${priceCountryCode}&out_Domain=${priceCountryCode}&periodStart=${periodStart}&periodEnd=${periodEnd}`
|
|
79
79
|
const consumption = `${this.config.entsoeDomain}/api?documentType=A65&processType=A16&in_Domain=${countryCode}&outBiddingZone_Domain=${countryCode}&periodStart=${periodStart}&periodEnd=${periodEnd}`
|
|
80
80
|
const hydroFill = `${this.config.entsoeDomain}/api?documentType=A72&processType=A16&in_Domain=${countryCode}&periodStart=${hydroPeriodStart}&periodEnd=${hydroPeriodEnd}`
|
|
81
|
-
|
|
82
|
-
console.log(hydroFill);
|
|
81
|
+
//const crossBorder = `${this.config.entsoeDomain}/api?documentType=A88&acquiring_Domain=10YCZ-CEPS-----N&connecting_Domain=10YSK-SEPS-----K&periodStart=${periodStart}&periodEnd=${periodEnd}`
|
|
83
82
|
const urls = {
|
|
84
83
|
generation,
|
|
85
84
|
price,
|
|
86
85
|
consumption,
|
|
87
|
-
hydroFill
|
|
86
|
+
hydroFill
|
|
88
87
|
}
|
|
89
|
-
|
|
90
88
|
const filteredUrls = this.filterURLs(urls, wanted);
|
|
91
89
|
return filteredUrls;
|
|
92
90
|
}
|
|
@@ -100,7 +98,6 @@ export class EntsoeLoader {
|
|
|
100
98
|
const installed = `${this.config.entsoeDomain}/api?documentType=A68&processType=A33&in_Domain=${countryCode}&periodStart=${periodStart}&periodEnd=${periodEnd}`;
|
|
101
99
|
urls.push(installed)
|
|
102
100
|
}
|
|
103
|
-
console.log(urls);
|
|
104
101
|
const allJsons = await this.fetchAndMakeJson(Object.values(urls), reload);
|
|
105
102
|
return allJsons;
|
|
106
103
|
}
|