@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.
Files changed (53) hide show
  1. package/README.md +6 -0
  2. package/dist/app.d.ts +1 -1
  3. package/dist/app.js +26 -26
  4. package/dist/config/countrydata.json +265 -265
  5. package/dist/converter.d.ts +8 -8
  6. package/dist/converter.js +56 -59
  7. package/dist/converter.js.map +1 -1
  8. package/dist/genTypes.d.ts +4 -4
  9. package/dist/genTypes.js +53 -53
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.js +5 -5
  12. package/dist/load.d.ts +7 -7
  13. package/dist/load.js +31 -31
  14. package/dist/router/config/countries.json +194 -0
  15. package/dist/router/config/countrydata.json +266 -0
  16. package/dist/router/config/types.json +333 -0
  17. package/dist/router/controllers/LoadAndParse.d.ts +10 -10
  18. package/dist/router/controllers/LoadAndParse.js +57 -57
  19. package/dist/router/controllers/Router.d.ts +7 -7
  20. package/dist/router/controllers/Router.js +105 -105
  21. package/dist/router/index.d.ts +2 -2
  22. package/dist/router/index.js +5 -5
  23. package/dist/router/interfaces/config.d.ts +5 -5
  24. package/dist/router/interfaces/config.js +2 -2
  25. package/dist/router/interfaces/entsoe.d.ts +50 -50
  26. package/dist/router/interfaces/entsoe.js +2 -2
  27. package/dist/router/interfaces/queryoptions.d.ts +15 -15
  28. package/dist/router/interfaces/queryoptions.js +15 -15
  29. package/dist/router/interfaces/types.d.ts +12 -12
  30. package/dist/router/interfaces/types.js +2 -2
  31. package/dist/router/services/CommonTimestamps.d.ts +15 -15
  32. package/dist/router/services/CommonTimestamps.js +185 -173
  33. package/dist/router/services/CommonTimestamps.js.map +1 -1
  34. package/dist/router/services/Eurostat.d.ts +10 -10
  35. package/dist/router/services/Eurostat.js +72 -72
  36. package/dist/router/services/Eurostat.js.map +1 -1
  37. package/dist/router/services/LoadService.d.ts +27 -27
  38. package/dist/router/services/LoadService.js +82 -82
  39. package/dist/router/services/Loader.d.ts +38 -38
  40. package/dist/router/services/Loader.js +119 -121
  41. package/dist/router/services/Loader.js.map +1 -1
  42. package/dist/router/services/ParseEdifact.d.ts +28 -28
  43. package/dist/router/services/ParseEdifact.js +159 -159
  44. package/dist/router/services/ParseInstalled.d.ts +9 -9
  45. package/dist/router/services/ParseInstalled.js +45 -45
  46. package/dist/router/services/batch/maxHydrofill.d.ts +10 -10
  47. package/dist/router/services/batch/maxHydrofill.js +65 -65
  48. package/package.json +53 -53
  49. package/src/converter.ts +61 -64
  50. package/src/router/config/countrydata.json +265 -265
  51. package/src/router/services/CommonTimestamps.ts +90 -54
  52. package/src/router/services/Eurostat.ts +3 -3
  53. package/src/router/services/Loader.ts +2 -5
@@ -1,160 +1,160 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EdifactParser = void 0;
4
- const luxon_1 = require("luxon");
5
- class EdifactParser {
6
- constructor(types) {
7
- this.types = types;
8
- this.psrName = {};
9
- for (const [key, value] of Object.entries(types)) {
10
- this.psrName[value.psrType] = key;
11
- }
12
- }
13
- parseAll(all) {
14
- const flat = {};
15
- Object.keys(all).forEach(key => {
16
- const parsed = this.parse(all[key], key);
17
- if (parsed) {
18
- Object.keys(parsed).forEach(type => {
19
- flat[type] = parsed[type];
20
- });
21
- }
22
- });
23
- return flat;
24
- }
25
- parse(json, key) {
26
- var _a, _b;
27
- const timeSeries = ((_a = json.GL_MarketDocument) === null || _a === void 0 ? void 0 : _a.TimeSeries) || ((_b = json.Publication_MarketDocument) === null || _b === void 0 ? void 0 : _b.TimeSeries);
28
- if (!timeSeries) {
29
- return;
30
- }
31
- let name = 'what';
32
- const all = {};
33
- timeSeries.forEach((timeSerie, i) => {
34
- var _a, _b;
35
- const psrType = ((_b = (_a = timeSerie === null || timeSerie === void 0 ? void 0 : timeSerie.MktPSRType) === null || _a === void 0 ? void 0 : _a[0].psrType) === null || _b === void 0 ? void 0 : _b[0]) || 'unknow';
36
- name = this.psrName[psrType] || key;
37
- const parsed = this.parseTimeSeries(timeSerie, name);
38
- const resolution = parsed[0];
39
- if (!all[name]) {
40
- all[name] = {};
41
- }
42
- if (!all[name][resolution]) {
43
- all[name][resolution] = [];
44
- }
45
- all[name][resolution] = all[name][resolution].concat(parsed[1]);
46
- });
47
- const result = {};
48
- Object.keys(all).forEach(type => {
49
- Object.keys(all[type]).forEach(res => {
50
- all[type][res] = this.mergeEqualTimeStamps(all[type][res]);
51
- all[type][res] = all[type][res].sort((a, b) => a.time - b.time);
52
- });
53
- result[type] = all[type];
54
- });
55
- return result;
56
- }
57
- parseTimeSeries(timeSerie, name) {
58
- if (timeSerie.Period.length > 1) {
59
- throw new Error('There is more than one Period in timeSeries');
60
- }
61
- const startEndResolution = this.getStartEndResolution(timeSerie);
62
- const timeArray = this.makeTimeArray(startEndResolution.startIsoString, startEndResolution.endIsoString, startEndResolution.resolution, timeSerie);
63
- const points = timeSerie.Period[0].Point;
64
- if (timeArray.length !== points.length) {
65
- throw new Error(`time array length: ${timeArray.length}, points length: ${points.length}`);
66
- }
67
- let sign = 1;
68
- if (timeSerie['outBiddingZone_Domain.mRID']) {
69
- sign = -1;
70
- }
71
- if (name === 'consumption') {
72
- sign = 1;
73
- }
74
- const result = [];
75
- points.forEach((point, i) => {
76
- var _a, _b;
77
- const pos = parseInt(point.position[0]) - 1;
78
- const val = parseFloat(((_a = point.quantity) === null || _a === void 0 ? void 0 : _a[0]) || ((_b = point['price.amount']) === null || _b === void 0 ? void 0 : _b[0]) || '0') || 0;
79
- result.push({
80
- time: timeArray[pos],
81
- value: val * sign
82
- });
83
- });
84
- return [startEndResolution.resolution, result];
85
- }
86
- makeTimeArray(startIsoString, endIsoString, resolution, timeSerie) {
87
- const duration = luxon_1.Duration.fromISO(resolution).toMillis();
88
- const localStartTime = luxon_1.DateTime.fromISO(startIsoString);
89
- const localEndTime = luxon_1.DateTime.fromISO(endIsoString);
90
- // Convert start and end time to UTC time using Luxon
91
- const utcStartTime = localStartTime.toUTC();
92
- const utcEndTime = localEndTime.toUTC();
93
- // Calculate time distance in milliseconds
94
- const timeDistance = utcEndTime.toMillis() - utcStartTime.toMillis();
95
- if (timeDistance < duration && timeSerie.Period.length !== 1) {
96
- console.log('timeDistance', timeDistance, duration, startIsoString, endIsoString);
97
- console.log(JSON.stringify(timeSerie.Period.length, null, 2));
98
- }
99
- if (timeDistance > duration) {
100
- //console.log('timeDistance2', timeDistance, duration, startIsoString, endIsoString)
101
- }
102
- // Create an array with time distance duration in UTC time using Luxon
103
- const timeSteps = [];
104
- for (let i = 0; i <= timeDistance; i += duration) {
105
- const dur = utcStartTime.plus({ milliseconds: i });
106
- timeSteps.push(dur.toUnixInteger() * 1000);
107
- }
108
- if (timeSteps.length > 1) {
109
- timeSteps.pop();
110
- }
111
- return timeSteps;
112
- }
113
- getStartEndResolution(timeSeries) {
114
- let startIsoString = null;
115
- let endIsoString = null;
116
- let resolution = '';
117
- if (!Array.isArray(timeSeries)) {
118
- timeSeries = [timeSeries];
119
- }
120
- timeSeries === null || timeSeries === void 0 ? void 0 : timeSeries.forEach(series => {
121
- var _a;
122
- (_a = series.Period) === null || _a === void 0 ? void 0 : _a.forEach(period => {
123
- resolution = period.resolution[0];
124
- if (resolution && resolution !== period.resolution[0]) {
125
- console.log('big problem', resolution, period.resolution[0]);
126
- }
127
- const timeInterval = period.timeInterval[0];
128
- if (!startIsoString || startIsoString > timeInterval.start[0]) {
129
- startIsoString = timeInterval.start[0];
130
- }
131
- if (!endIsoString || endIsoString < timeInterval.end[0]) {
132
- endIsoString = timeInterval.end[0];
133
- }
134
- });
135
- });
136
- //console.log(startIsoString, endIsoString, resolution)
137
- return ({
138
- startIsoString,
139
- endIsoString,
140
- resolution
141
- });
142
- }
143
- mergeEqualTimeStamps(data) {
144
- const timeStamps = data.map(item => item.time);
145
- const uniqueTimeStamps = [...new Set(timeStamps)];
146
- const result = uniqueTimeStamps.map(time => {
147
- return {
148
- time: time,
149
- value: 0
150
- };
151
- });
152
- data.forEach(item => {
153
- const pos = uniqueTimeStamps.indexOf(item.time);
154
- result[pos].value += item.value;
155
- });
156
- return result;
157
- }
158
- }
159
- exports.EdifactParser = EdifactParser;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EdifactParser = void 0;
4
+ const luxon_1 = require("luxon");
5
+ class EdifactParser {
6
+ constructor(types) {
7
+ this.types = types;
8
+ this.psrName = {};
9
+ for (const [key, value] of Object.entries(types)) {
10
+ this.psrName[value.psrType] = key;
11
+ }
12
+ }
13
+ parseAll(all) {
14
+ const flat = {};
15
+ Object.keys(all).forEach(key => {
16
+ const parsed = this.parse(all[key], key);
17
+ if (parsed) {
18
+ Object.keys(parsed).forEach(type => {
19
+ flat[type] = parsed[type];
20
+ });
21
+ }
22
+ });
23
+ return flat;
24
+ }
25
+ parse(json, key) {
26
+ var _a, _b;
27
+ const timeSeries = ((_a = json.GL_MarketDocument) === null || _a === void 0 ? void 0 : _a.TimeSeries) || ((_b = json.Publication_MarketDocument) === null || _b === void 0 ? void 0 : _b.TimeSeries);
28
+ if (!timeSeries) {
29
+ return;
30
+ }
31
+ let name = 'what';
32
+ const all = {};
33
+ timeSeries.forEach((timeSerie, i) => {
34
+ var _a, _b;
35
+ const psrType = ((_b = (_a = timeSerie === null || timeSerie === void 0 ? void 0 : timeSerie.MktPSRType) === null || _a === void 0 ? void 0 : _a[0].psrType) === null || _b === void 0 ? void 0 : _b[0]) || 'unknow';
36
+ name = this.psrName[psrType] || key;
37
+ const parsed = this.parseTimeSeries(timeSerie, name);
38
+ const resolution = parsed[0];
39
+ if (!all[name]) {
40
+ all[name] = {};
41
+ }
42
+ if (!all[name][resolution]) {
43
+ all[name][resolution] = [];
44
+ }
45
+ all[name][resolution] = all[name][resolution].concat(parsed[1]);
46
+ });
47
+ const result = {};
48
+ Object.keys(all).forEach(type => {
49
+ Object.keys(all[type]).forEach(res => {
50
+ all[type][res] = this.mergeEqualTimeStamps(all[type][res]);
51
+ all[type][res] = all[type][res].sort((a, b) => a.time - b.time);
52
+ });
53
+ result[type] = all[type];
54
+ });
55
+ return result;
56
+ }
57
+ parseTimeSeries(timeSerie, name) {
58
+ if (timeSerie.Period.length > 1) {
59
+ throw new Error('There is more than one Period in timeSeries');
60
+ }
61
+ const startEndResolution = this.getStartEndResolution(timeSerie);
62
+ const timeArray = this.makeTimeArray(startEndResolution.startIsoString, startEndResolution.endIsoString, startEndResolution.resolution, timeSerie);
63
+ const points = timeSerie.Period[0].Point;
64
+ if (timeArray.length !== points.length) {
65
+ throw new Error(`time array length: ${timeArray.length}, points length: ${points.length}`);
66
+ }
67
+ let sign = 1;
68
+ if (timeSerie['outBiddingZone_Domain.mRID']) {
69
+ sign = -1;
70
+ }
71
+ if (name === 'consumption') {
72
+ sign = 1;
73
+ }
74
+ const result = [];
75
+ points.forEach((point, i) => {
76
+ var _a, _b;
77
+ const pos = parseInt(point.position[0]) - 1;
78
+ const val = parseFloat(((_a = point.quantity) === null || _a === void 0 ? void 0 : _a[0]) || ((_b = point['price.amount']) === null || _b === void 0 ? void 0 : _b[0]) || '0') || 0;
79
+ result.push({
80
+ time: timeArray[pos],
81
+ value: val * sign
82
+ });
83
+ });
84
+ return [startEndResolution.resolution, result];
85
+ }
86
+ makeTimeArray(startIsoString, endIsoString, resolution, timeSerie) {
87
+ const duration = luxon_1.Duration.fromISO(resolution).toMillis();
88
+ const localStartTime = luxon_1.DateTime.fromISO(startIsoString);
89
+ const localEndTime = luxon_1.DateTime.fromISO(endIsoString);
90
+ // Convert start and end time to UTC time using Luxon
91
+ const utcStartTime = localStartTime.toUTC();
92
+ const utcEndTime = localEndTime.toUTC();
93
+ // Calculate time distance in milliseconds
94
+ const timeDistance = utcEndTime.toMillis() - utcStartTime.toMillis();
95
+ if (timeDistance < duration && timeSerie.Period.length !== 1) {
96
+ console.log('timeDistance', timeDistance, duration, startIsoString, endIsoString);
97
+ console.log(JSON.stringify(timeSerie.Period.length, null, 2));
98
+ }
99
+ if (timeDistance > duration) {
100
+ //console.log('timeDistance2', timeDistance, duration, startIsoString, endIsoString)
101
+ }
102
+ // Create an array with time distance duration in UTC time using Luxon
103
+ const timeSteps = [];
104
+ for (let i = 0; i <= timeDistance; i += duration) {
105
+ const dur = utcStartTime.plus({ milliseconds: i });
106
+ timeSteps.push(dur.toUnixInteger() * 1000);
107
+ }
108
+ if (timeSteps.length > 1) {
109
+ timeSteps.pop();
110
+ }
111
+ return timeSteps;
112
+ }
113
+ getStartEndResolution(timeSeries) {
114
+ let startIsoString = null;
115
+ let endIsoString = null;
116
+ let resolution = '';
117
+ if (!Array.isArray(timeSeries)) {
118
+ timeSeries = [timeSeries];
119
+ }
120
+ timeSeries === null || timeSeries === void 0 ? void 0 : timeSeries.forEach(series => {
121
+ var _a;
122
+ (_a = series.Period) === null || _a === void 0 ? void 0 : _a.forEach(period => {
123
+ resolution = period.resolution[0];
124
+ if (resolution && resolution !== period.resolution[0]) {
125
+ console.log('big problem', resolution, period.resolution[0]);
126
+ }
127
+ const timeInterval = period.timeInterval[0];
128
+ if (!startIsoString || startIsoString > timeInterval.start[0]) {
129
+ startIsoString = timeInterval.start[0];
130
+ }
131
+ if (!endIsoString || endIsoString < timeInterval.end[0]) {
132
+ endIsoString = timeInterval.end[0];
133
+ }
134
+ });
135
+ });
136
+ //console.log(startIsoString, endIsoString, resolution)
137
+ return ({
138
+ startIsoString,
139
+ endIsoString,
140
+ resolution
141
+ });
142
+ }
143
+ mergeEqualTimeStamps(data) {
144
+ const timeStamps = data.map(item => item.time);
145
+ const uniqueTimeStamps = [...new Set(timeStamps)];
146
+ const result = uniqueTimeStamps.map(time => {
147
+ return {
148
+ time: time,
149
+ value: 0
150
+ };
151
+ });
152
+ data.forEach(item => {
153
+ const pos = uniqueTimeStamps.indexOf(item.time);
154
+ result[pos].value += item.value;
155
+ });
156
+ return result;
157
+ }
158
+ }
159
+ exports.EdifactParser = EdifactParser;
160
160
  //# sourceMappingURL=ParseEdifact.js.map
@@ -1,9 +1,9 @@
1
- import { Entsoe, TimeSeries } from "../interfaces/entsoe";
2
- import { Types } from "../interfaces/types";
3
- export declare class ParseInstalled {
4
- private types;
5
- private psrName;
6
- constructor(types: Types);
7
- parse(json: Entsoe[]): any;
8
- getPsrType(timeSeries: TimeSeries): string[] | undefined;
9
- }
1
+ import { Entsoe, TimeSeries } from "../interfaces/entsoe";
2
+ import { Types } from "../interfaces/types";
3
+ export declare class ParseInstalled {
4
+ private types;
5
+ private psrName;
6
+ constructor(types: Types);
7
+ parse(json: Entsoe[]): any;
8
+ getPsrType(timeSeries: TimeSeries): string[] | undefined;
9
+ }
@@ -1,46 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParseInstalled = void 0;
4
- class ParseInstalled {
5
- constructor(types) {
6
- this.types = types;
7
- this.psrName = {};
8
- for (const [key, value] of Object.entries(types)) {
9
- this.psrName[value.psrType] = key;
10
- }
11
- }
12
- parse(json) {
13
- const all = {
14
- time: []
15
- };
16
- json.forEach((year, i) => {
17
- var _a, _b;
18
- const time = (_a = year.GL_MarketDocument) === null || _a === void 0 ? void 0 : _a.TimeSeries[0].Period[0].timeInterval[0].start[0];
19
- const timeStamp = new Date(time || 0).getTime();
20
- all.time.push(timeStamp);
21
- (_b = year.GL_MarketDocument) === null || _b === void 0 ? void 0 : _b.TimeSeries.forEach(timeSeries => {
22
- var _a;
23
- const psrType = (_a = this.getPsrType(timeSeries)) === null || _a === void 0 ? void 0 : _a[0];
24
- if (!psrType) {
25
- return; //continue
26
- }
27
- const name = this.psrName[psrType];
28
- if (!all[name]) {
29
- all[name] = [];
30
- }
31
- timeSeries.Period.forEach(period => {
32
- var _a;
33
- const value = (_a = period.Point[0].quantity) === null || _a === void 0 ? void 0 : _a[0];
34
- all[name][i] = parseFloat(value + '');
35
- });
36
- });
37
- });
38
- return all;
39
- }
40
- getPsrType(timeSeries) {
41
- var _a;
42
- return (_a = timeSeries === null || timeSeries === void 0 ? void 0 : timeSeries.MktPSRType) === null || _a === void 0 ? void 0 : _a[0].psrType;
43
- }
44
- }
45
- exports.ParseInstalled = ParseInstalled;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParseInstalled = void 0;
4
+ class ParseInstalled {
5
+ constructor(types) {
6
+ this.types = types;
7
+ this.psrName = {};
8
+ for (const [key, value] of Object.entries(types)) {
9
+ this.psrName[value.psrType] = key;
10
+ }
11
+ }
12
+ parse(json) {
13
+ const all = {
14
+ time: []
15
+ };
16
+ json.forEach((year, i) => {
17
+ var _a, _b;
18
+ const time = (_a = year.GL_MarketDocument) === null || _a === void 0 ? void 0 : _a.TimeSeries[0].Period[0].timeInterval[0].start[0];
19
+ const timeStamp = new Date(time || 0).getTime();
20
+ all.time.push(timeStamp);
21
+ (_b = year.GL_MarketDocument) === null || _b === void 0 ? void 0 : _b.TimeSeries.forEach(timeSeries => {
22
+ var _a;
23
+ const psrType = (_a = this.getPsrType(timeSeries)) === null || _a === void 0 ? void 0 : _a[0];
24
+ if (!psrType) {
25
+ return; //continue
26
+ }
27
+ const name = this.psrName[psrType];
28
+ if (!all[name]) {
29
+ all[name] = [];
30
+ }
31
+ timeSeries.Period.forEach(period => {
32
+ var _a;
33
+ const value = (_a = period.Point[0].quantity) === null || _a === void 0 ? void 0 : _a[0];
34
+ all[name][i] = parseFloat(value + '');
35
+ });
36
+ });
37
+ });
38
+ return all;
39
+ }
40
+ getPsrType(timeSeries) {
41
+ var _a;
42
+ return (_a = timeSeries === null || timeSeries === void 0 ? void 0 : timeSeries.MktPSRType) === null || _a === void 0 ? void 0 : _a[0].psrType;
43
+ }
44
+ }
45
+ exports.ParseInstalled = ParseInstalled;
46
46
  //# sourceMappingURL=ParseInstalled.js.map
@@ -1,10 +1,10 @@
1
- export declare class Hydrofill {
2
- static start(): Promise<void>;
3
- static getMaxHydrofill(country: string): Promise<{
4
- country: string;
5
- min: number | undefined;
6
- max: number | undefined;
7
- }>;
8
- static getHydrofill(countryCode: string, year: number): Promise<any>;
9
- static getCountries(): Promise<any>;
10
- }
1
+ export declare class Hydrofill {
2
+ static start(): Promise<void>;
3
+ static getMaxHydrofill(country: string): Promise<{
4
+ country: string;
5
+ min: number | undefined;
6
+ max: number | undefined;
7
+ }>;
8
+ static getHydrofill(countryCode: string, year: number): Promise<any>;
9
+ static getCountries(): Promise<any>;
10
+ }
@@ -1,66 +1,66 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Hydrofill = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
6
- const process_1 = require("process");
7
- //import { EntsoeLoader } from "../Loader";
8
- process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = '0';
9
- class Hydrofill {
10
- static async start() {
11
- const countries = await this.getCountries();
12
- for (const country of countries) {
13
- const h = await this.getMaxHydrofill(country.code);
14
- if (h.max) {
15
- const GW = Math.round(h.max / 1000) + ' GW';
16
- console.log(country.name, GW);
17
- country.hydrofill = {
18
- min: h.min,
19
- max: h.max
20
- };
21
- }
22
- }
23
- const countryFile = (0, path_1.join)(__dirname, '../../config', 'countrydata.json');
24
- console.log(countryFile);
25
- const countryDataFile = (0, path_1.join)((0, process_1.cwd)(), 'data/countrydata.json');
26
- (0, fs_1.writeFileSync)(countryFile, JSON.stringify(countries, null, 2));
27
- }
28
- static async getMaxHydrofill(country) {
29
- const minYear = 2015;
30
- const maxYear = 2023;
31
- let min;
32
- let max;
33
- for (let year = minYear; year <= maxYear; year++) {
34
- const hydro = await this.getHydrofill(country, year);
35
- if (hydro.dataset) {
36
- hydro.dataset[0].data.forEach((item) => {
37
- max = Math.max(...[max, item.y].filter(x => x));
38
- min = Math.min(...[min, item.y].filter(x => x));
39
- });
40
- }
41
- }
42
- return {
43
- country,
44
- min,
45
- max
46
- };
47
- }
48
- static async getHydrofill(countryCode, year) {
49
- const url = `https://powercalculator.eu/entsoe/${countryCode}/hydrofill?year=${year}`;
50
- const response = await fetch(url);
51
- return await response.json();
52
- }
53
- static async getCountries() {
54
- const configFile = (0, path_1.join)(__dirname, '../../config', 'countries.json');
55
- const countriesString = (0, fs_1.readFileSync)(configFile, 'utf-8');
56
- return JSON.parse(countriesString);
57
- /*
58
- const url = 'https://powercalculator.eu/entsoe/datalists/countries';
59
- const response = await fetch(url);
60
- return await response.json()
61
- */
62
- }
63
- }
64
- exports.Hydrofill = Hydrofill;
65
- Hydrofill.start();
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Hydrofill = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const process_1 = require("process");
7
+ //import { EntsoeLoader } from "../Loader";
8
+ process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = '0';
9
+ class Hydrofill {
10
+ static async start() {
11
+ const countries = await this.getCountries();
12
+ for (const country of countries) {
13
+ const h = await this.getMaxHydrofill(country.code);
14
+ if (h.max) {
15
+ const GW = Math.round(h.max / 1000) + ' GW';
16
+ console.log(country.name, GW);
17
+ country.hydrofill = {
18
+ min: h.min,
19
+ max: h.max
20
+ };
21
+ }
22
+ }
23
+ const countryFile = (0, path_1.join)(__dirname, '../../config', 'countrydata.json');
24
+ console.log(countryFile);
25
+ const countryDataFile = (0, path_1.join)((0, process_1.cwd)(), 'data/countrydata.json');
26
+ (0, fs_1.writeFileSync)(countryFile, JSON.stringify(countries, null, 2));
27
+ }
28
+ static async getMaxHydrofill(country) {
29
+ const minYear = 2015;
30
+ const maxYear = 2023;
31
+ let min;
32
+ let max;
33
+ for (let year = minYear; year <= maxYear; year++) {
34
+ const hydro = await this.getHydrofill(country, year);
35
+ if (hydro.dataset) {
36
+ hydro.dataset[0].data.forEach((item) => {
37
+ max = Math.max(...[max, item.y].filter(x => x));
38
+ min = Math.min(...[min, item.y].filter(x => x));
39
+ });
40
+ }
41
+ }
42
+ return {
43
+ country,
44
+ min,
45
+ max
46
+ };
47
+ }
48
+ static async getHydrofill(countryCode, year) {
49
+ const url = `https://powercalculator.eu/entsoe/${countryCode}/hydrofill?year=${year}`;
50
+ const response = await fetch(url);
51
+ return await response.json();
52
+ }
53
+ static async getCountries() {
54
+ const configFile = (0, path_1.join)(__dirname, '../../config', 'countries.json');
55
+ const countriesString = (0, fs_1.readFileSync)(configFile, 'utf-8');
56
+ return JSON.parse(countriesString);
57
+ /*
58
+ const url = 'https://powercalculator.eu/entsoe/datalists/countries';
59
+ const response = await fetch(url);
60
+ return await response.json()
61
+ */
62
+ }
63
+ }
64
+ exports.Hydrofill = Hydrofill;
65
+ Hydrofill.start();
66
66
  //# sourceMappingURL=maxHydrofill.js.map