@powercalc/power-router 1.0.12 → 1.0.14

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/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@powercalc/power-router",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
8
  "v": "node -v",
@@ -46,6 +46,7 @@
46
46
  },
47
47
  "files": [
48
48
  "dist/**/*",
49
+ "src/**/*",
49
50
  "!**/*.test.js"
50
51
  ]
51
52
  }
package/src/app.ts ADDED
@@ -0,0 +1,25 @@
1
+ import 'reflect-metadata';
2
+ process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = '0';
3
+
4
+ import express, { Request } from 'express';
5
+ import cors from 'cors'
6
+ import { join } from 'path';
7
+ import { cwd } from 'process';
8
+ import { Config } from './router/interfaces/config';
9
+ import { PowerRouter } from './router/controllers/Router';
10
+
11
+ const app = express();
12
+ const port = 30000;
13
+ const config: Config = {
14
+ securityToken: '1c608639-afff-4d73-bfe1-a960fe7ea8da',
15
+ cacheDir: join(cwd(), 'data'),
16
+ entsoeDomain: "https://web-api.tp.entsoe.eu"
17
+ }
18
+ app.use(cors<Request>());
19
+ app.use('/entsoe', PowerRouter.init(config));
20
+ app.use('/public', express.static('public'));
21
+ // app.use('/config', express.static('dist/config', { maxAge: 100000 }));
22
+
23
+ app.listen(port, () => {
24
+ console.log(`Server listening on port ${port}`);
25
+ });
@@ -0,0 +1,50 @@
1
+ import { gzip } from "node:zlib";
2
+ import { Load } from "./load";
3
+ import { writeFile } from 'node:fs/promises';
4
+
5
+
6
+ export class GenTypes {
7
+ static async getTypes(country: string) {
8
+ let types: any[] = []
9
+ const minYear = 2015;
10
+ const maxYear = 2023;
11
+ let min: number | undefined;
12
+ let max: number | undefined;
13
+ for (let year = minYear; year <= maxYear; year++) {
14
+ for (let month = 1; month <= 12; month++) {
15
+ const gen = await Load.getGeneration(country, year, month);
16
+ const price = await Load.getPrice(country, year, month);
17
+ const load = await Load.getLoad(country, year, month);
18
+ const all = this.makeGen(gen, load, price);
19
+ const gzipfilename = `data/gzip/${country}-${year}-${month}.json.gzip`
20
+ const filename = `data/generation/${country}-${year}-${month}.json`
21
+ const buf = Buffer.from(JSON.stringify(all), 'utf-8');
22
+ gzip(buf, async (_, result) => {
23
+ await writeFile(gzipfilename, result, 'utf-8')
24
+ // console.log(gen.dataset.map((item:any) => item.label))
25
+ types = types.concat(gen.dataset?.map((item: any) => item.psrType) || []);
26
+ })
27
+ await writeFile(filename, JSON.stringify(all, null, 2), 'utf-8')
28
+ }
29
+ }
30
+ return [...new Set(types)].sort();
31
+
32
+ }
33
+ static makeGen(gen: any, load: any, price: any): any {
34
+ const all: any = {}
35
+ if (gen.dataset?.[0]) {
36
+ all.time = gen.dataset?.[0]?.data?.map((item: any) => item.x);
37
+ gen.dataset.forEach((dataset: any) => {
38
+ all[dataset.psrType] = dataset.data.map((item: any) => item.y)
39
+ })
40
+ }
41
+ if (load?.dataset?.[0]?.data) {
42
+ all.A05 = load.dataset[0].data.map((item:any)=>item.y)
43
+ }
44
+ if (price?.dataset?.[0]) {
45
+ all.price = price.dataset[0].data.map((item:any)=>item.y)
46
+ }
47
+ console.log(all.time?.length, all.A05?.length, all.price?.length)
48
+ return all;
49
+ }
50
+ }
package/src/index.ts ADDED
@@ -0,0 +1,64 @@
1
+ import { GenTypes } from "./genTypes";
2
+ import { Hydrofill } from "./router/services/batch/maxHydrofill";
3
+ import { writeFile } from 'node:fs/promises';
4
+
5
+
6
+ export class Convert {
7
+ static async start() {
8
+ const countries = await this.getCountries()
9
+ console.log(countries)
10
+ for (const country of countries) {
11
+ const types = await GenTypes.getTypes(country.code);
12
+ country.types = types;
13
+ console.log(country.name, types.join(', '))
14
+ const h = await Hydrofill.getMaxHydrofill(country.code)
15
+ if (h.max) {
16
+ const GW = Math.round(h.max / 1000) + ' GW'
17
+ console.log(country.name, GW)
18
+ country.hydrofill = {
19
+ min: h.min,
20
+ max: h.max
21
+ }
22
+ }
23
+ const gen = await this.getGeneration(country.code)
24
+ const load = await this.getLoad(country.code)
25
+ const price = await this.getPrice(country.code)
26
+ const hydrofill = await this.getHydrofill(country.code)
27
+ }
28
+ console.log(countries);
29
+ writeFile('data/countrydata.json', JSON.stringify(countries, null, 2), 'utf-8')
30
+ }
31
+
32
+ static async getCountries() {
33
+ const url = 'https://powercalculator.eu/entsoe/datalists/countries';
34
+ const response = await fetch(url);
35
+ return await response.json()
36
+ }
37
+
38
+ static async getGeneration(countryCode: string) {
39
+ const url = `https://powercalculator.eu/entsoe/${countryCode}/generation?year=2021&month=9`;
40
+ const response = await fetch(url);
41
+ return await response.json()
42
+ }
43
+
44
+ static async getLoad(countryCode: string) {
45
+ const url = `https://powercalculator.eu/entsoe/${countryCode}/load?year=2021&month=9`;
46
+ const response = await fetch(url);
47
+ return await response.json()
48
+ }
49
+
50
+ static async getPrice(countryCode: string) {
51
+ const url = `https://powercalculator.eu/entsoe/${countryCode}/prices?year=2021&month=9`;
52
+ const response = await fetch(url);
53
+ return await response.json()
54
+ }
55
+
56
+ static async getHydrofill(countryCode: string) {
57
+ const url = `https://powercalculator.eu/entsoe/${countryCode}/hydrofill?year=2021`
58
+ const response = await fetch(url);
59
+ return await response.json()
60
+ }
61
+
62
+ }
63
+
64
+ Convert.start();
package/src/load.ts ADDED
@@ -0,0 +1,34 @@
1
+ export class Load {
2
+
3
+
4
+ static async getCountries() {
5
+ const url = 'https://powercalculator.eu/entsoe/datalists/countries';
6
+ const response = await fetch(url);
7
+ return await response.json()
8
+ }
9
+
10
+ static async getGeneration(countryCode: string, year: number, month: number) {
11
+ const url = `https://powercalculator.eu/entsoe/${countryCode}/generation?year=${year}&month=${month}`;
12
+ const response = await fetch(url);
13
+ return await response.json()
14
+ }
15
+
16
+ static async getLoad(countryCode: string, year: number, month: number) {
17
+ const url = `https://powercalculator.eu/entsoe/${countryCode}/load?year=${year}&month=${month}`;
18
+ const response = await fetch(url);
19
+ return await response.json()
20
+ }
21
+
22
+ static async getPrice(countryCode: string, year: number, month: number) {
23
+ const url = `https://powercalculator.eu/entsoe/${countryCode}/prices?year=${year}&month=${month}`;
24
+ const response = await fetch(url);
25
+ return await response.json()
26
+ }
27
+
28
+ static async getHydrofill(countryCode: string, year: number) {
29
+ const url = `https://powercalculator.eu/entsoe/${countryCode}/hydrofill?year=${year}`
30
+ const response = await fetch(url);
31
+ return await response.json()
32
+ }
33
+
34
+ }
@@ -0,0 +1,194 @@
1
+ [
2
+ {
3
+ "code": "10YAT-APG------L",
4
+ "name": "Austria",
5
+ "population": 8955102,
6
+ "short": "AT"
7
+ },
8
+ {
9
+ "code": "10YBE----------2",
10
+ "name": "Belgium",
11
+ "population": 11524454,
12
+ "short": "BE"
13
+ },
14
+ {
15
+ "code": "10YBA-JPCC-----D",
16
+ "name": "Bosnia and Herzegovina",
17
+ "population": 3280819,
18
+ "short": "BA"
19
+ },
20
+ {
21
+ "code": "10YCA-BULGARIA-R",
22
+ "name": "Bulgaria",
23
+ "population": 6951482,
24
+ "short": "BG"
25
+ },
26
+ {
27
+ "code": "10YCY-1001A0003J",
28
+ "name": "Cyprus",
29
+ "population": 1207359,
30
+ "short": "CY"
31
+ },
32
+ {
33
+ "code": "10YCZ-CEPS-----N",
34
+ "name": "Czech Republic",
35
+ "population": 10708981,
36
+ "short": "CZ"
37
+ },
38
+ {
39
+ "code": "10Y1001A1001A65H",
40
+ "name": "Denmark",
41
+ "population": 5793636,
42
+ "short": "DK"
43
+ },
44
+ {
45
+ "code": "10Y1001A1001A39I",
46
+ "name": "Estonia",
47
+ "population": 1328976,
48
+ "short": "EE"
49
+ },
50
+ {
51
+ "code": "10YFI-1--------U",
52
+ "name": "Finland",
53
+ "population": 5540720,
54
+ "short": "FI"
55
+ },
56
+ {
57
+ "code": "10YMK-MEPSO----8",
58
+ "name": "North Macedonia",
59
+ "population": 2084367,
60
+ "short": "MK"
61
+ },
62
+ {
63
+ "code": "10YFR-RTE------C",
64
+ "name": "France",
65
+ "population": 67146000,
66
+ "short": "FR"
67
+ },
68
+ {
69
+ "code": "10Y1001A1001A83F",
70
+ "name": "Germany",
71
+ "population": 83190556,
72
+ "short": "DE"
73
+ },
74
+ {
75
+ "code": "10YGR-HTSO-----Y",
76
+ "name": "Greece",
77
+ "population": 10724599,
78
+ "short": "GR"
79
+ },
80
+ {
81
+ "code": "10YHU-MAVIR----U",
82
+ "name": "Hungary",
83
+ "population": 9769526,
84
+ "short": "HU"
85
+ },
86
+ {
87
+ "code": "10Y1001A1001A59C",
88
+ "name": "Ireland",
89
+ "population": 4982900,
90
+ "short": "IE"
91
+ },
92
+ {
93
+ "code": "10YIT-GRTN-----B",
94
+ "name": "Italy",
95
+ "population": 60390560,
96
+ "short": "IT"
97
+ },
98
+ {
99
+ "code": "10YLV-1001A00074",
100
+ "name": "Latvia",
101
+ "population": 1901548,
102
+ "short": "LV"
103
+ },
104
+ {
105
+ "code": "10YLT-1001A0008Q",
106
+ "name": "Lithuania",
107
+ "population": 2793471,
108
+ "short": "LT"
109
+ },
110
+ {
111
+ "code": "10YLU-CEGEDEL-NQ",
112
+ "name": "Luxembourg",
113
+ "population": 626108,
114
+ "short": "LU"
115
+ },
116
+ {
117
+ "code": "10YCS-CG-TSO---S",
118
+ "name": "Montenegro",
119
+ "population": 622359,
120
+ "short": "ME"
121
+ },
122
+ {
123
+ "code": "10YGB----------A",
124
+ "name": "United Kingdom",
125
+ "population": 68133400,
126
+ "short": "GB"
127
+ },
128
+ {
129
+ "code": "10YNL----------L",
130
+ "name": "Nederlands",
131
+ "population": 17446640,
132
+ "short": "NL"
133
+ },
134
+ {
135
+ "code": "10YNO-0--------C",
136
+ "name": "Norway",
137
+ "population": 5330800,
138
+ "short": "NO"
139
+ },
140
+ {
141
+ "code": "10YPL-AREA-----S",
142
+ "name": "Poland",
143
+ "population": 38386000,
144
+ "short": "PL"
145
+ },
146
+ {
147
+ "code": "10YPT-REN------W",
148
+ "name": "Portugal",
149
+ "population": 10276617,
150
+ "short": "PT"
151
+ },
152
+ {
153
+ "code": "10YRO-TEL------P",
154
+ "name": "Romania",
155
+ "population": 19238250,
156
+ "short": "RO"
157
+ },
158
+ {
159
+ "code": "10YCS-SERBIATSOV",
160
+ "name": "Serbia",
161
+ "population": 6963764,
162
+ "short": "RS"
163
+ },
164
+ {
165
+ "code": "10YSK-SEPS-----K",
166
+ "name": "Slovakia",
167
+ "population": 5459642,
168
+ "short": "SK"
169
+ },
170
+ {
171
+ "code": "10YSI-ELES-----O",
172
+ "name": "Slovenia",
173
+ "population": 2094060,
174
+ "short": "SI"
175
+ },
176
+ {
177
+ "code": "10YES-REE------0",
178
+ "name": "Spain",
179
+ "population": 46723749,
180
+ "short": "ES"
181
+ },
182
+ {
183
+ "code": "10YSE-1--------K",
184
+ "name": "Sweden",
185
+ "population": 10383676,
186
+ "short": "SE"
187
+ },
188
+ {
189
+ "code": "10YCH-SWISSGRIDZ",
190
+ "name": "Switzerland",
191
+ "population": 8718853,
192
+ "short": "CH"
193
+ }
194
+ ]
@@ -0,0 +1,266 @@
1
+ [
2
+ {
3
+ "code": "10YAT-APG------L",
4
+ "name": "Austria",
5
+ "population": 8955102,
6
+ "short": "AT",
7
+ "hydrofill": {
8
+ "min": 269440,
9
+ "max": 2001005
10
+ }
11
+ },
12
+ {
13
+ "code": "10YBE----------2",
14
+ "name": "Belgium",
15
+ "population": 11524454,
16
+ "short": "BE"
17
+ },
18
+ {
19
+ "code": "10YBA-JPCC-----D",
20
+ "name": "Bosnia and Herzegovina",
21
+ "population": 3280819,
22
+ "short": "BA"
23
+ },
24
+ {
25
+ "code": "10YCA-BULGARIA-R",
26
+ "name": "Bulgaria",
27
+ "population": 6951482,
28
+ "short": "BG",
29
+ "hydrofill": {
30
+ "min": 987839,
31
+ "max": 2240914
32
+ }
33
+ },
34
+ {
35
+ "code": "10YCY-1001A0003J",
36
+ "name": "Cyprus",
37
+ "population": 1207359,
38
+ "short": "CY"
39
+ },
40
+ {
41
+ "code": "10YCZ-CEPS-----N",
42
+ "name": "Czech Republic",
43
+ "population": 10708981,
44
+ "short": "CZ"
45
+ },
46
+ {
47
+ "code": "10Y1001A1001A65H",
48
+ "name": "Denmark",
49
+ "population": 5793636,
50
+ "short": "DK"
51
+ },
52
+ {
53
+ "code": "10Y1001A1001A39I",
54
+ "name": "Estonia",
55
+ "population": 1328976,
56
+ "short": "EE"
57
+ },
58
+ {
59
+ "code": "10YFI-1--------U",
60
+ "name": "Finland",
61
+ "population": 5540720,
62
+ "short": "FI",
63
+ "hydrofill": {
64
+ "min": 1560000,
65
+ "max": 4512000
66
+ }
67
+ },
68
+ {
69
+ "code": "10YMK-MEPSO----8",
70
+ "name": "North Macedonia",
71
+ "population": 2084367,
72
+ "short": "MK",
73
+ "hydrofill": {
74
+ "min": 81108,
75
+ "max": 162524
76
+ }
77
+ },
78
+ {
79
+ "code": "10YFR-RTE------C",
80
+ "name": "France",
81
+ "population": 67146000,
82
+ "short": "FR",
83
+ "hydrofill": {
84
+ "min": 586044,
85
+ "max": 3100546
86
+ }
87
+ },
88
+ {
89
+ "code": "10Y1001A1001A83F",
90
+ "name": "Germany",
91
+ "population": 83190556,
92
+ "short": "DE"
93
+ },
94
+ {
95
+ "code": "10YGR-HTSO-----Y",
96
+ "name": "Greece",
97
+ "population": 10724599,
98
+ "short": "GR",
99
+ "hydrofill": {
100
+ "min": 1099043,
101
+ "max": 3060004
102
+ }
103
+ },
104
+ {
105
+ "code": "10YHU-MAVIR----U",
106
+ "name": "Hungary",
107
+ "population": 9769526,
108
+ "short": "HU"
109
+ },
110
+ {
111
+ "code": "10Y1001A1001A59C",
112
+ "name": "Ireland",
113
+ "population": 4982900,
114
+ "short": "IE"
115
+ },
116
+ {
117
+ "code": "10YIT-GRTN-----B",
118
+ "name": "Italy",
119
+ "population": 60390560,
120
+ "short": "IT",
121
+ "hydrofill": {
122
+ "min": 1837814,
123
+ "max": 4408894
124
+ }
125
+ },
126
+ {
127
+ "code": "10YLV-1001A00074",
128
+ "name": "Latvia",
129
+ "population": 1901548,
130
+ "short": "LV",
131
+ "hydrofill": {
132
+ "min": 1775,
133
+ "max": 11167
134
+ }
135
+ },
136
+ {
137
+ "code": "10YLT-1001A0008Q",
138
+ "name": "Lithuania",
139
+ "population": 2793471,
140
+ "short": "LT",
141
+ "hydrofill": {
142
+ "min": 395,
143
+ "max": 12217
144
+ }
145
+ },
146
+ {
147
+ "code": "10YLU-CEGEDEL-NQ",
148
+ "name": "Luxembourg",
149
+ "population": 626108,
150
+ "short": "LU"
151
+ },
152
+ {
153
+ "code": "10YCS-CG-TSO---S",
154
+ "name": "Montenegro",
155
+ "population": 622359,
156
+ "short": "ME",
157
+ "hydrofill": {
158
+ "min": 555,
159
+ "max": 505322
160
+ }
161
+ },
162
+ {
163
+ "code": "10YGB----------A",
164
+ "name": "United Kingdom",
165
+ "population": 68133400,
166
+ "short": "GB"
167
+ },
168
+ {
169
+ "code": "10YNL----------L",
170
+ "name": "Nederlands",
171
+ "population": 17446640,
172
+ "short": "NL"
173
+ },
174
+ {
175
+ "code": "10YNO-0--------C",
176
+ "name": "Norway",
177
+ "population": 5330800,
178
+ "short": "NO",
179
+ "hydrofill": {
180
+ "min": 18328177,
181
+ "max": 83251000
182
+ }
183
+ },
184
+ {
185
+ "code": "10YPL-AREA-----S",
186
+ "name": "Poland",
187
+ "population": 38386000,
188
+ "short": "PL"
189
+ },
190
+ {
191
+ "code": "10YPT-REN------W",
192
+ "name": "Portugal",
193
+ "population": 10276617,
194
+ "short": "PT",
195
+ "hydrofill": {
196
+ "min": 974314,
197
+ "max": 2897771
198
+ }
199
+ },
200
+ {
201
+ "code": "10YRO-TEL------P",
202
+ "name": "Romania",
203
+ "population": 19238250,
204
+ "short": "RO",
205
+ "hydrofill": {
206
+ "min": 885300,
207
+ "max": 2849800
208
+ }
209
+ },
210
+ {
211
+ "code": "10YCS-SERBIATSOV",
212
+ "name": "Serbia",
213
+ "population": 6963764,
214
+ "short": "RS",
215
+ "hydrofill": {
216
+ "min": 159000,
217
+ "max": 608000
218
+ }
219
+ },
220
+ {
221
+ "code": "10YSK-SEPS-----K",
222
+ "name": "Slovakia",
223
+ "population": 5459642,
224
+ "short": "SK"
225
+ },
226
+ {
227
+ "code": "10YSI-ELES-----O",
228
+ "name": "Slovenia",
229
+ "population": 2094060,
230
+ "short": "SI",
231
+ "hydrofill": {
232
+ "min": 2600,
233
+ "max": 2600
234
+ }
235
+ },
236
+ {
237
+ "code": "10YES-REE------0",
238
+ "name": "Spain",
239
+ "population": 46723749,
240
+ "short": "ES",
241
+ "hydrofill": {
242
+ "min": 4308428,
243
+ "max": 13674197
244
+ }
245
+ },
246
+ {
247
+ "code": "10YSE-1--------K",
248
+ "name": "Sweden",
249
+ "population": 10383676,
250
+ "short": "SE",
251
+ "hydrofill": {
252
+ "min": 5672000,
253
+ "max": 30694000
254
+ }
255
+ },
256
+ {
257
+ "code": "10YCH-SWISSGRIDZ",
258
+ "name": "Switzerland",
259
+ "population": 8718853,
260
+ "short": "CH",
261
+ "hydrofill": {
262
+ "min": 377710,
263
+ "max": 6572889
264
+ }
265
+ }
266
+ ]