@powercalc/power-router 1.0.68 → 1.0.70
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/dist/controllers/LoadAndParse.js +1 -1
- package/dist/controllers/LoadAndParse.js.map +1 -1
- package/dist/services/EnergyCharts.d.ts +5 -2
- package/dist/services/EnergyCharts.js +48 -21
- package/dist/services/EnergyCharts.js.map +1 -1
- package/dist/services/LoadService.d.ts +1 -1
- package/dist/services/LoadService.js +2 -2
- package/dist/services/LoadService.js.map +1 -1
- package/package.json +1 -1
- package/src/router/controllers/LoadAndParse.ts +1 -1
- package/src/router/services/EnergyCharts.ts +47 -15
- package/src/router/services/LoadService.ts +63 -57
|
@@ -44,7 +44,7 @@ class LoadAndParse {
|
|
|
44
44
|
}
|
|
45
45
|
if (chartType === 'power') {
|
|
46
46
|
if (this.config.source === 'energycharts') {
|
|
47
|
-
return await this.loadService.getPowerEnergyCharts(countryCode, year, month);
|
|
47
|
+
return await this.loadService.getPowerEnergyCharts(countryCode, year, month, queryOptions);
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
50
|
return await this.loadService.getPower(countryCode, year, month, queryOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoadAndParse.js","sourceRoot":"","sources":["../../src/router/controllers/LoadAndParse.ts"],"names":[],"mappings":";;;AAEA,+BAA4B;AAC5B,2BAAkC;AAClC,yDAAsD;AAEtD,6DAA0E;AAE1E,MAAa,YAAY;IAMvB,YAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QALlC,YAAO,GAAG,EAAE,CAAC;QAMX,MAAM,aAAa,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,0BAA0B,CAAC,CAAC,CAAC,mCAAmC;QACtG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,iBAAY,EAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,iCAAiC;QACnG,IA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AAA;YAClB,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;SACvE;QACD,IAAI,SAAS,KAAK,OAAO,EAAE;YACzB,IAAG,IAAI,CAAC,MAAM,CAAC,MAAM,KAAG,cAAc,EAAC;gBACrC,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,CAAE,CAAC;aAC7F;iBAAI;gBACH,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;aAChF;SACF;QACD,IAAI,SAAS,KAAK,WAAW,EAAE;YAC7B,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;SACvE;QACD,IAAI,SAAS,KAAK,QAAQ,EAAE;YAC1B,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;SACpE;QACD,IAAI,SAAS,KAAK,aAAa,EAAE;YAC/B,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;SACzE;IACH,CAAC;CACF;AA1DD,oCA0DC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { QueryOptions } from '../interfaces/queryoptions';
|
|
1
2
|
export declare class EnergyCharts {
|
|
2
3
|
pumpUp: string;
|
|
3
4
|
trans: ({
|
|
@@ -9,8 +10,10 @@ export declare class EnergyCharts {
|
|
|
9
10
|
})[];
|
|
10
11
|
countries: any;
|
|
11
12
|
constructor();
|
|
12
|
-
load(country: string, startIso: string, endIso: string): Promise<any>;
|
|
13
|
-
|
|
13
|
+
load(country: string, startIso: string, endIso: string, queryOptions: QueryOptions): Promise<any>;
|
|
14
|
+
getPower(url: string): Promise<any>;
|
|
15
|
+
makeUrls(country: string, startIso: string, endIso: string): string[];
|
|
16
|
+
getPrices(url: string): Promise<any>;
|
|
14
17
|
translate(json: any): any;
|
|
15
18
|
rebase(data: any, newTime: number[]): any;
|
|
16
19
|
private findTime;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EnergyCharts = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
+
const queryoptions_1 = require("../interfaces/queryoptions");
|
|
6
7
|
class EnergyCharts {
|
|
7
8
|
constructor() {
|
|
8
9
|
this.pumpUp = 'Hydro pumped storage consumption';
|
|
@@ -84,48 +85,74 @@ class EnergyCharts {
|
|
|
84
85
|
const countriesString = (0, fs_1.readFileSync)(countryPath, 'utf-8');
|
|
85
86
|
this.countries = JSON.parse(countriesString);
|
|
86
87
|
}
|
|
87
|
-
async load(country, startIso, endIso) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const
|
|
88
|
+
async load(country, startIso, endIso, queryOptions) {
|
|
89
|
+
const urls = this.makeUrls(country, startIso, endIso);
|
|
90
|
+
if ((queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.format) === queryoptions_1.Format.SOURCES) {
|
|
91
|
+
return urls;
|
|
92
|
+
}
|
|
93
|
+
const data = await this.getPower(urls[0]);
|
|
94
|
+
const priceTime = await this.getPrices(urls[1]);
|
|
95
|
+
if (priceTime) {
|
|
96
|
+
const rebasedPrice = this.rebase(priceTime, data.time);
|
|
97
|
+
data.price = rebasedPrice.price;
|
|
98
|
+
}
|
|
99
|
+
return data;
|
|
100
|
+
}
|
|
101
|
+
async getPower(url) {
|
|
93
102
|
try {
|
|
94
|
-
const url = `https://api.energy-charts.info/public_power?country=${countryShort}&start=${start}&end=${end}`;
|
|
95
103
|
const response = await fetch(url);
|
|
96
104
|
const text = await response.text();
|
|
97
105
|
if (!text)
|
|
98
106
|
return;
|
|
99
107
|
const json = JSON.parse(text);
|
|
100
108
|
const t = this.translate(json);
|
|
109
|
+
/*
|
|
101
110
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
console.error(e);
|
|
111
|
+
const priceTime = await this.getPrices(countryShort, startIso, endIso);
|
|
112
|
+
if (priceTime) {
|
|
113
|
+
const rebasedPrice = this.rebase(priceTime, t.time);
|
|
114
|
+
t.price = rebasedPrice.price;
|
|
115
|
+
}
|
|
116
|
+
} catch (e) {
|
|
117
|
+
console.error(e);
|
|
110
118
|
}
|
|
119
|
+
*/
|
|
111
120
|
return t;
|
|
112
121
|
}
|
|
113
122
|
catch (e) {
|
|
114
123
|
console.error(e);
|
|
115
124
|
}
|
|
116
125
|
}
|
|
117
|
-
|
|
118
|
-
|
|
126
|
+
makeUrls(country, startIso, endIso) {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
const countryShort = (_b = (_a = this.countries
|
|
129
|
+
.find((item) => item.code === country)) === null || _a === void 0 ? void 0 : _a.short) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
130
|
+
const start = encodeURIComponent(startIso);
|
|
131
|
+
const end = encodeURIComponent(endIso);
|
|
132
|
+
const powerUrl = `https://api.energy-charts.info/public_power?country=${countryShort}&start=${start}&end=${end}`;
|
|
133
|
+
let zone = countryShort.toUpperCase();
|
|
119
134
|
if (zone === 'DE') {
|
|
120
135
|
zone = 'DE-LU';
|
|
121
136
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
137
|
+
if (zone === 'DK') {
|
|
138
|
+
zone = 'DK1';
|
|
139
|
+
}
|
|
140
|
+
if (zone === 'IT') {
|
|
141
|
+
zone = 'IT-North';
|
|
142
|
+
}
|
|
143
|
+
if (zone === 'NO') {
|
|
144
|
+
zone = 'NO1';
|
|
145
|
+
}
|
|
146
|
+
if (zone === 'SE') {
|
|
147
|
+
zone = 'SE1';
|
|
148
|
+
}
|
|
149
|
+
const priceUrl = `https://api.energy-charts.info/price?bzn=${zone}&start=${start}&end=${end}`;
|
|
150
|
+
return [powerUrl, priceUrl];
|
|
151
|
+
}
|
|
152
|
+
async getPrices(url) {
|
|
125
153
|
console.log(url);
|
|
126
154
|
const response = await fetch(url);
|
|
127
155
|
const text = await response.text();
|
|
128
|
-
//console.log(text);
|
|
129
156
|
if (!text)
|
|
130
157
|
return;
|
|
131
158
|
const json = JSON.parse(text);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnergyCharts.js","sourceRoot":"","sources":["../../src/router/services/EnergyCharts.ts"],"names":[],"mappings":";;;AAAA,2BAAkC;AAClC,+BAA4B;
|
|
1
|
+
{"version":3,"file":"EnergyCharts.js","sourceRoot":"","sources":["../../src/router/services/EnergyCharts.ts"],"names":[],"mappings":";;;AAAA,2BAAkC;AAClC,+BAA4B;AAC5B,6DAAkE;AAElE,MAAa,YAAY;IA8EvB;QA7EA,WAAM,GAAG,kCAAkC,CAAC;QAC5C,UAAK,GAAG;YACN;gBACE,YAAY,EAAE,kCAAkC;gBAChD,WAAW,EAAE,IAAI;aAClB;YACD;gBACE,YAAY,EAAE,kCAAkC;gBAChD,WAAW,EAAE,OAAO;aACrB;YACD;gBACE,YAAY,EAAE,SAAS;gBACvB,WAAW,EAAE,SAAS;aACvB;YACD;gBACE,YAAY,EAAE,oBAAoB;gBAClC,WAAW,EAAE,4BAA4B;aAC1C;YACD;gBACE,YAAY,EAAE,SAAS;gBACvB,WAAW,EAAE,SAAS;aACvB;YACD;gBACE,YAAY,EAAE,6BAA6B;gBAC3C,WAAW,EAAE,wBAAwB;aACtC;YACD;gBACE,YAAY,EAAE,kBAAkB;gBAChC,WAAW,EAAE,gBAAgB;aAC9B;YACD;gBACE,YAAY,EAAE,YAAY;gBAC1B,WAAW,EAAE,WAAW;aACzB;YACD;gBACE,YAAY,EAAE,YAAY;gBAC1B,WAAW,EAAE,WAAW;aAC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YAC3B,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACf;QACD,IAAI,UAAU,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE;YACzB,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;SACrB;QACD,IAAI,UAAU,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE;YACzB,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;SACrB;QACD,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE;YAClB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;YACtC,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE;gBAC1B,EAAE,GAAG,GAAG,CAAC;aACV;iBAAM;gBACL,EAAE,GAAG,GAAG,CAAC;aACV;SACF;QACD,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAClB,CAAC;CACF;AA/OD,oCA+OC"}
|
|
@@ -9,7 +9,7 @@ export declare class LoadService {
|
|
|
9
9
|
parser: EdifactParser;
|
|
10
10
|
parseInstalled: ParseInstalled;
|
|
11
11
|
constructor(loaderConfig: LoaderConfig);
|
|
12
|
-
getPowerEnergyCharts(countryCode: string, year: number, month: number): Promise<any>;
|
|
12
|
+
getPowerEnergyCharts(countryCode: string, year: number, month: number, queryOptions: QueryOptions): Promise<any>;
|
|
13
13
|
getPower(countryCode: string, year: number, month: number, queryOptions?: QueryOptions): Promise<any>;
|
|
14
14
|
getInstalled(countryCode: string, queryOptions: QueryOptions): Promise<any>;
|
|
15
15
|
getHydrofill(countryCode: string, queryOptions: QueryOptions): Promise<any[] | {
|
|
@@ -21,11 +21,11 @@ class LoadService {
|
|
|
21
21
|
this.parser = new ParseEdifact_1.EdifactParser(types);
|
|
22
22
|
this.parseInstalled = new ParseInstalled_1.ParseInstalled(types);
|
|
23
23
|
}
|
|
24
|
-
async getPowerEnergyCharts(countryCode, year, month) {
|
|
24
|
+
async getPowerEnergyCharts(countryCode, year, month, queryOptions) {
|
|
25
25
|
const startMonth = new Date(Date.UTC(year, month - 1)).toISOString();
|
|
26
26
|
const endMonth = new Date(Date.UTC(year, month)).toISOString();
|
|
27
27
|
const energyCharts = new EnergyCharts_1.EnergyCharts();
|
|
28
|
-
const power = await energyCharts.load(countryCode, startMonth, endMonth);
|
|
28
|
+
const power = await energyCharts.load(countryCode, startMonth, endMonth, queryOptions);
|
|
29
29
|
return power;
|
|
30
30
|
}
|
|
31
31
|
async getPower(countryCode, year, month, queryOptions) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoadService.js","sourceRoot":"","sources":["../../src/router/services/LoadService.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"LoadService.js","sourceRoot":"","sources":["../../src/router/services/LoadService.ts"],"names":[],"mappings":";;;AAAA,2BAAkC;AAClC,+BAA4B;AAC5B,qCAAsD;AACtD,iDAA0D;AAC1D,qDAAkD;AAClD,yDAAsD;AACtD,yCAAyC;AAEzC,6DAAkE;AAClE,uDAAqD;AAErD,iDAA8C;AAE9C,MAAa,WAAW;IAMtB,YAAoB,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;QAL9C,YAAO,GAAG,EAAE,CAAC;QAMX,MAAM,SAAS,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC,CAAC,mCAAmC;QAC9F,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,iBAAY,EAAC,SAAS,EAAE,MAAM,CAAC,CAAU,CAAC,CAAC,iCAAiC;QAErG,IAAI,CAAC,MAAM,GAAG,IAAI,qBAAY,CAAC,YAAY,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM,GAAG,IAAI,4BAAa,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,CAAC,cAAc,GAAG,IAAI,+BAAc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CAAC;QACnC,OAAO,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,OAAe,EAAE,YAA0B;QACnE,MAAM,QAAQ,GAAG,IAAI,kCAAgB,EAAE,CAAC;QACxC,OAAO,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAe,EAAE,YAA0B;QAC9D,OAAO;YACL,MAAM,EAAE,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC;YACnD,KAAK,EAAE,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC;YAC5D,SAAS,EAAE,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC;YACzD,SAAS,EAAE,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC;SAC1D,CAAC;IACJ,CAAC;CACF;AAvID,kCAuIC"}
|
package/package.json
CHANGED
|
@@ -49,7 +49,7 @@ export class LoadAndParse {
|
|
|
49
49
|
}
|
|
50
50
|
if (chartType === 'power') {
|
|
51
51
|
if(this.config.source==='energycharts'){
|
|
52
|
-
return await this.loadService.getPowerEnergyCharts(countryCode, year, month );
|
|
52
|
+
return await this.loadService.getPowerEnergyCharts(countryCode, year, month, queryOptions );
|
|
53
53
|
}else{
|
|
54
54
|
return await this.loadService.getPower(countryCode, year, month, queryOptions);
|
|
55
55
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
|
-
import {
|
|
3
|
+
import { Format, QueryOptions } from '../interfaces/queryoptions';
|
|
4
4
|
|
|
5
5
|
export class EnergyCharts {
|
|
6
6
|
pumpUp = 'Hydro pumped storage consumption';
|
|
@@ -85,20 +85,32 @@ export class EnergyCharts {
|
|
|
85
85
|
const countriesString = readFileSync(countryPath, 'utf-8');
|
|
86
86
|
this.countries = JSON.parse(countriesString);
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
88
|
+
async load(
|
|
89
|
+
country: string,
|
|
90
|
+
startIso: string,
|
|
91
|
+
endIso: string,
|
|
92
|
+
queryOptions: QueryOptions
|
|
93
|
+
) {
|
|
94
|
+
const urls = this.makeUrls(country, startIso, endIso);
|
|
95
|
+
if (queryOptions?.format === Format.SOURCES) {
|
|
96
|
+
return urls;
|
|
97
|
+
}
|
|
98
|
+
const data = await this.getPower(urls[0]);
|
|
99
|
+
const priceTime = await this.getPrices(urls[1]);
|
|
100
|
+
if (priceTime) {
|
|
101
|
+
const rebasedPrice = this.rebase(priceTime, data.time);
|
|
102
|
+
data.price = rebasedPrice.price;
|
|
103
|
+
}
|
|
104
|
+
return data;
|
|
105
|
+
}
|
|
106
|
+
async getPower(url: string) {
|
|
95
107
|
try {
|
|
96
|
-
const url = `https://api.energy-charts.info/public_power?country=${countryShort}&start=${start}&end=${end}`;
|
|
97
108
|
const response = await fetch(url);
|
|
98
109
|
const text = await response.text();
|
|
99
110
|
if (!text) return;
|
|
100
111
|
const json = JSON.parse(text);
|
|
101
112
|
const t = this.translate(json);
|
|
113
|
+
/*
|
|
102
114
|
try {
|
|
103
115
|
const priceTime = await this.getPrices(countryShort, startIso, endIso);
|
|
104
116
|
if (priceTime) {
|
|
@@ -108,25 +120,45 @@ export class EnergyCharts {
|
|
|
108
120
|
} catch (e) {
|
|
109
121
|
console.error(e);
|
|
110
122
|
}
|
|
123
|
+
*/
|
|
111
124
|
return t;
|
|
112
125
|
} catch (e) {
|
|
113
126
|
console.error(e);
|
|
114
127
|
}
|
|
115
128
|
}
|
|
129
|
+
makeUrls(country: string, startIso: string, endIso: string) {
|
|
130
|
+
const countryShort = this.countries
|
|
131
|
+
.find((item: any) => item.code === country)
|
|
132
|
+
?.short?.toLowerCase();
|
|
133
|
+
const start = encodeURIComponent(startIso);
|
|
134
|
+
const end = encodeURIComponent(endIso);
|
|
135
|
+
const powerUrl = `https://api.energy-charts.info/public_power?country=${countryShort}&start=${start}&end=${end}`;
|
|
116
136
|
|
|
117
|
-
|
|
118
|
-
let zone = country.toUpperCase();
|
|
137
|
+
let zone = countryShort.toUpperCase();
|
|
119
138
|
if (zone === 'DE') {
|
|
120
139
|
zone = 'DE-LU';
|
|
121
140
|
}
|
|
141
|
+
if (zone === 'DK') {
|
|
142
|
+
zone = 'DK1';
|
|
143
|
+
}
|
|
144
|
+
if (zone === 'IT') {
|
|
145
|
+
zone = 'IT-North';
|
|
146
|
+
}
|
|
147
|
+
if (zone === 'NO') {
|
|
148
|
+
zone = 'NO1';
|
|
149
|
+
}
|
|
150
|
+
if (zone === 'SE') {
|
|
151
|
+
zone = 'SE1';
|
|
152
|
+
}
|
|
122
153
|
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
154
|
+
const priceUrl = `https://api.energy-charts.info/price?bzn=${zone}&start=${start}&end=${end}`;
|
|
155
|
+
return [powerUrl, priceUrl];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async getPrices(url: string) {
|
|
126
159
|
console.log(url);
|
|
127
160
|
const response = await fetch(url);
|
|
128
161
|
const text = await response.text();
|
|
129
|
-
//console.log(text);
|
|
130
162
|
if (!text) return;
|
|
131
163
|
const json = JSON.parse(text);
|
|
132
164
|
if (json?.unix_seconds && json?.price) {
|
|
@@ -1,40 +1,46 @@
|
|
|
1
|
-
import { readFileSync } from 'fs'
|
|
2
|
-
import { join } from 'path'
|
|
3
|
-
import { EntsoeLoader, LoaderConfig } from './Loader'
|
|
4
|
-
import { DataPoint, EdifactParser } from './ParseEdifact'
|
|
5
|
-
import { ParseInstalled } from './ParseInstalled'
|
|
6
|
-
import { CommonTimestamps } from './CommonTimestamps'
|
|
7
|
-
import { EurostatAPI } from './Eurostat'
|
|
8
|
-
import { Types } from '../interfaces/types'
|
|
9
|
-
import { Format, QueryOptions } from '../interfaces/queryoptions'
|
|
10
|
-
import { NaturalGasPrices } from './NaturalGasPrice'
|
|
11
|
-
import { Entsoe } from '../interfaces/entsoe'
|
|
12
|
-
import { EnergyCharts } from './EnergyCharts'
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { EntsoeLoader, LoaderConfig } from './Loader';
|
|
4
|
+
import { DataPoint, EdifactParser } from './ParseEdifact';
|
|
5
|
+
import { ParseInstalled } from './ParseInstalled';
|
|
6
|
+
import { CommonTimestamps } from './CommonTimestamps';
|
|
7
|
+
import { EurostatAPI } from './Eurostat';
|
|
8
|
+
import { Types } from '../interfaces/types';
|
|
9
|
+
import { Format, QueryOptions } from '../interfaces/queryoptions';
|
|
10
|
+
import { NaturalGasPrices } from './NaturalGasPrice';
|
|
11
|
+
import { Entsoe } from '../interfaces/entsoe';
|
|
12
|
+
import { EnergyCharts } from './EnergyCharts';
|
|
13
13
|
|
|
14
14
|
export class LoadService {
|
|
15
|
-
country = ''
|
|
16
|
-
loader: EntsoeLoader
|
|
17
|
-
parser: EdifactParser
|
|
18
|
-
parseInstalled: ParseInstalled
|
|
15
|
+
country = '';
|
|
16
|
+
loader: EntsoeLoader;
|
|
17
|
+
parser: EdifactParser;
|
|
18
|
+
parseInstalled: ParseInstalled;
|
|
19
19
|
|
|
20
20
|
constructor(private loaderConfig: LoaderConfig) {
|
|
21
|
-
const typesPath = join(__dirname, '../config/types.json') // Set the path to your config file
|
|
22
|
-
const types = JSON.parse(readFileSync(typesPath, 'utf8')) as Types // Read the config file from disk
|
|
21
|
+
const typesPath = join(__dirname, '../config/types.json'); // Set the path to your config file
|
|
22
|
+
const types = JSON.parse(readFileSync(typesPath, 'utf8')) as Types; // Read the config file from disk
|
|
23
23
|
|
|
24
|
-
this.loader = new EntsoeLoader(loaderConfig)
|
|
25
|
-
this.parser = new EdifactParser(types)
|
|
26
|
-
this.parseInstalled = new ParseInstalled(types)
|
|
24
|
+
this.loader = new EntsoeLoader(loaderConfig);
|
|
25
|
+
this.parser = new EdifactParser(types);
|
|
26
|
+
this.parseInstalled = new ParseInstalled(types);
|
|
27
27
|
}
|
|
28
28
|
async getPowerEnergyCharts(
|
|
29
29
|
countryCode: string,
|
|
30
30
|
year: number,
|
|
31
31
|
month: number,
|
|
32
|
+
queryOptions: QueryOptions
|
|
32
33
|
): Promise<any> {
|
|
33
|
-
const startMonth = new Date(Date.UTC(year, month - 1)).toISOString()
|
|
34
|
-
const endMonth = new Date(Date.UTC(year, month)).toISOString()
|
|
35
|
-
const energyCharts = new EnergyCharts()
|
|
36
|
-
const power = await energyCharts.load(
|
|
37
|
-
|
|
34
|
+
const startMonth = new Date(Date.UTC(year, month - 1)).toISOString();
|
|
35
|
+
const endMonth = new Date(Date.UTC(year, month)).toISOString();
|
|
36
|
+
const energyCharts = new EnergyCharts();
|
|
37
|
+
const power = await energyCharts.load(
|
|
38
|
+
countryCode,
|
|
39
|
+
startMonth,
|
|
40
|
+
endMonth,
|
|
41
|
+
queryOptions
|
|
42
|
+
);
|
|
43
|
+
return power;
|
|
38
44
|
}
|
|
39
45
|
async getPower(
|
|
40
46
|
countryCode: string,
|
|
@@ -42,11 +48,11 @@ export class LoadService {
|
|
|
42
48
|
month: number,
|
|
43
49
|
queryOptions?: QueryOptions
|
|
44
50
|
): Promise<any> {
|
|
45
|
-
const startMonth = new Date(Date.UTC(year, month - 1)).toISOString()
|
|
46
|
-
const endMonth = new Date(Date.UTC(year, month)).toISOString()
|
|
47
|
-
const wanted = ['generation', 'price', 'consumption']
|
|
51
|
+
const startMonth = new Date(Date.UTC(year, month - 1)).toISOString();
|
|
52
|
+
const endMonth = new Date(Date.UTC(year, month)).toISOString();
|
|
53
|
+
const wanted = ['generation', 'price', 'consumption'];
|
|
48
54
|
if (queryOptions?.format === Format.SOURCES) {
|
|
49
|
-
return this.loader.makeUrls(wanted, countryCode, year, month)
|
|
55
|
+
return this.loader.makeUrls(wanted, countryCode, year, month);
|
|
50
56
|
}
|
|
51
57
|
const edifactAsJson = await this.loader.load(
|
|
52
58
|
wanted,
|
|
@@ -54,22 +60,22 @@ export class LoadService {
|
|
|
54
60
|
year,
|
|
55
61
|
month,
|
|
56
62
|
queryOptions
|
|
57
|
-
)
|
|
63
|
+
);
|
|
58
64
|
if (queryOptions?.format === Format.EDIJSON) {
|
|
59
|
-
return edifactAsJson
|
|
65
|
+
return edifactAsJson;
|
|
60
66
|
}
|
|
61
|
-
const parsed = await this.parser.parseAll(edifactAsJson)
|
|
67
|
+
const parsed = await this.parser.parseAll(edifactAsJson);
|
|
62
68
|
if (queryOptions?.format === Format.KEYVALUE) {
|
|
63
|
-
return parsed
|
|
69
|
+
return parsed;
|
|
64
70
|
}
|
|
65
|
-
const ready: any = CommonTimestamps.transform(parsed, startMonth, endMonth)
|
|
71
|
+
const ready: any = CommonTimestamps.transform(parsed, startMonth, endMonth);
|
|
66
72
|
//console.log('e.price',e.price)
|
|
67
73
|
/*
|
|
68
74
|
if (!e.price) {
|
|
69
75
|
e.price = ready.price
|
|
70
76
|
}
|
|
71
77
|
*/
|
|
72
|
-
return ready
|
|
78
|
+
return ready;
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
async getInstalled(countryCode: string, queryOptions: QueryOptions) {
|
|
@@ -81,55 +87,55 @@ export class LoadService {
|
|
|
81
87
|
const edifactAsJson = await this.loader.loadInstalled(
|
|
82
88
|
countryCode,
|
|
83
89
|
queryOptions
|
|
84
|
-
)
|
|
90
|
+
);
|
|
85
91
|
if (queryOptions.format === Format.SOURCES) {
|
|
86
|
-
return edifactAsJson
|
|
92
|
+
return edifactAsJson;
|
|
87
93
|
}
|
|
88
|
-
const ready = await this.parseInstalled.parse(edifactAsJson as Entsoe[])
|
|
89
|
-
return ready
|
|
94
|
+
const ready = await this.parseInstalled.parse(edifactAsJson as Entsoe[]);
|
|
95
|
+
return ready;
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
async getHydrofill(countryCode: string, queryOptions: QueryOptions) {
|
|
93
|
-
const wanted = ['hydroFill']
|
|
94
|
-
const endYear = new Date().getFullYear() + 1
|
|
95
|
-
let all: DataPoint[] = []
|
|
99
|
+
const wanted = ['hydroFill'];
|
|
100
|
+
const endYear = new Date().getFullYear() + 1;
|
|
101
|
+
let all: DataPoint[] = [];
|
|
96
102
|
for (let year = 2015; year < endYear; year++) {
|
|
97
|
-
const month = 1
|
|
103
|
+
const month = 1;
|
|
98
104
|
const edifactAsJson = await this.loader.load(
|
|
99
105
|
wanted,
|
|
100
106
|
countryCode,
|
|
101
107
|
year,
|
|
102
108
|
month,
|
|
103
109
|
queryOptions
|
|
104
|
-
)
|
|
110
|
+
);
|
|
105
111
|
if (queryOptions.format === Format.SOURCES) {
|
|
106
|
-
return [edifactAsJson.hydroFill]
|
|
112
|
+
return [edifactAsJson.hydroFill];
|
|
107
113
|
}
|
|
108
|
-
const parsed = await this.parser.parseAll(edifactAsJson)
|
|
114
|
+
const parsed = await this.parser.parseAll(edifactAsJson);
|
|
109
115
|
if (parsed?.hydroFill) {
|
|
110
|
-
const yearArr = Object.values(parsed?.hydroFill)?.[0]
|
|
116
|
+
const yearArr = Object.values(parsed?.hydroFill)?.[0];
|
|
111
117
|
if (yearArr) {
|
|
112
|
-
all = all.concat(yearArr)
|
|
118
|
+
all = all.concat(yearArr);
|
|
113
119
|
}
|
|
114
120
|
}
|
|
115
121
|
}
|
|
116
122
|
const keyValue = all.filter((obj, index, self) => {
|
|
117
|
-
return index === self.findIndex((o) => o.time === obj.time)
|
|
118
|
-
})
|
|
123
|
+
return index === self.findIndex((o) => o.time === obj.time);
|
|
124
|
+
});
|
|
119
125
|
return {
|
|
120
126
|
time: keyValue.map((item) => item.time),
|
|
121
127
|
hydroFill: keyValue.map((item) => item.value),
|
|
122
|
-
}
|
|
128
|
+
};
|
|
123
129
|
}
|
|
124
130
|
|
|
125
131
|
async getFossil(country: string, queryOptions: QueryOptions) {
|
|
126
|
-
const eurostat = new EurostatAPI()
|
|
127
|
-
return await eurostat.load(country, queryOptions)
|
|
132
|
+
const eurostat = new EurostatAPI();
|
|
133
|
+
return await eurostat.load(country, queryOptions);
|
|
128
134
|
}
|
|
129
135
|
|
|
130
136
|
async getNaturalGasPrices(country: string, queryOptions: QueryOptions) {
|
|
131
|
-
const eurostat = new NaturalGasPrices()
|
|
132
|
-
return await eurostat.load(country, queryOptions)
|
|
137
|
+
const eurostat = new NaturalGasPrices();
|
|
138
|
+
return await eurostat.load(country, queryOptions);
|
|
133
139
|
}
|
|
134
140
|
|
|
135
141
|
async getCountrydata(country: string, queryOptions: QueryOptions) {
|
|
@@ -138,6 +144,6 @@ export class LoadService {
|
|
|
138
144
|
price: await this.getNaturalGasPrices(country, queryOptions),
|
|
139
145
|
installed: await this.getInstalled(country, queryOptions),
|
|
140
146
|
hydrofill: await this.getHydrofill(country, queryOptions),
|
|
141
|
-
}
|
|
147
|
+
};
|
|
142
148
|
}
|
|
143
149
|
}
|