@powercalc/power-router 1.0.60 → 1.0.61
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/config/types.json +11 -2
- package/dist/services/LoadService.d.ts +8 -0
- package/dist/services/LoadService.js +6 -0
- package/dist/services/LoadService.js.map +1 -1
- package/dist/services/NaturalGasPrice.d.ts +13 -0
- package/dist/services/NaturalGasPrice.js +44 -0
- package/dist/services/NaturalGasPrice.js.map +1 -0
- package/package.json +1 -1
- package/src/router/config/types.json +11 -2
- package/src/router/services/LoadService.ts +8 -0
- package/src/router/services/NaturalGasPrice.ts +43 -0
package/dist/config/types.json
CHANGED
|
@@ -54,10 +54,19 @@
|
|
|
54
54
|
"yAxis": "price",
|
|
55
55
|
"abbr": "PR"
|
|
56
56
|
},
|
|
57
|
+
"naturalGasPrice": {
|
|
58
|
+
"name": "NatGas€",
|
|
59
|
+
"psrType": "X91",
|
|
60
|
+
"co2Footprint": 0,
|
|
61
|
+
"color": "purple",
|
|
62
|
+
"yAxis": "price",
|
|
63
|
+
"abbr": "NP"
|
|
64
|
+
},
|
|
65
|
+
|
|
57
66
|
"consumption": {
|
|
58
67
|
"name": "Consumption",
|
|
59
68
|
"psrType": "A05",
|
|
60
|
-
"co2Footprint":
|
|
69
|
+
"co2Footprint": 0,
|
|
61
70
|
"color": "#c3c3c3",
|
|
62
71
|
"abbr": "CO",
|
|
63
72
|
"stack": "stack2",
|
|
@@ -254,7 +263,7 @@
|
|
|
254
263
|
"ev": {
|
|
255
264
|
"name": "EV",
|
|
256
265
|
"psrType": "F16",
|
|
257
|
-
"co2Footprint":
|
|
266
|
+
"co2Footprint": 733,
|
|
258
267
|
"color": "gray",
|
|
259
268
|
"abbr": "EV",
|
|
260
269
|
"type": "fossil"
|
|
@@ -16,8 +16,16 @@ export declare class LoadService {
|
|
|
16
16
|
hydroFill: number[];
|
|
17
17
|
}>;
|
|
18
18
|
getFossil(country: string): Promise<any>;
|
|
19
|
+
getNaturalGasPrices(country: string): Promise<{
|
|
20
|
+
time: number[];
|
|
21
|
+
naturalGasPrice: number[];
|
|
22
|
+
}>;
|
|
19
23
|
getCountrydata(country: string, reload: boolean): Promise<{
|
|
20
24
|
fossil: any;
|
|
25
|
+
price: {
|
|
26
|
+
time: number[];
|
|
27
|
+
naturalGasPrice: number[];
|
|
28
|
+
};
|
|
21
29
|
installed: any;
|
|
22
30
|
hydrofill: {
|
|
23
31
|
time: number[];
|
|
@@ -9,6 +9,7 @@ const ParseInstalled_1 = require("./ParseInstalled");
|
|
|
9
9
|
const CommonTimestamps_1 = require("./CommonTimestamps");
|
|
10
10
|
const Eurostat_1 = require("./Eurostat");
|
|
11
11
|
const queryoptions_1 = require("../interfaces/queryoptions");
|
|
12
|
+
const NaturalGasPrice_1 = require("./NaturalGasPrice");
|
|
12
13
|
class LoadService {
|
|
13
14
|
constructor(loaderConfig) {
|
|
14
15
|
this.loaderConfig = loaderConfig;
|
|
@@ -70,10 +71,15 @@ class LoadService {
|
|
|
70
71
|
const eurostat = new Eurostat_1.EurostatAPI();
|
|
71
72
|
return await eurostat.load(country);
|
|
72
73
|
}
|
|
74
|
+
async getNaturalGasPrices(country) {
|
|
75
|
+
const eurostat = new NaturalGasPrice_1.NaturalGasPrices();
|
|
76
|
+
return await eurostat.load(country);
|
|
77
|
+
}
|
|
73
78
|
async getCountrydata(country, reload) {
|
|
74
79
|
console.log('reload', country, reload);
|
|
75
80
|
return {
|
|
76
81
|
fossil: await this.getFossil(country),
|
|
82
|
+
price: await this.getNaturalGasPrices(country),
|
|
77
83
|
installed: await this.getInstalled(country, reload),
|
|
78
84
|
hydrofill: await this.getHydrofill(country, reload)
|
|
79
85
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoadService.js","sourceRoot":"","sources":["../../src/router/services/LoadService.ts"],"names":[],"mappings":";;;AAAA,2BAAkC;AAClC,+BAA4B;AAC5B,qCAAsD;AACtD,iDAA0D;AAC1D,qDA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AAW,EAAE,CAAC;QACnC,OAAO,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,OAAe;QACrC,MAAM,QAAQ,GAAG,IAAI,kCAAgB,EAAE,CAAC;QACxC,OAAO,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;IAGD,KAAK,CAAC,cAAc,CAAC,OAAe,EAAE,MAAe;QACjD,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;QACtC,OAAO;YACH,MAAM,EAAE,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;YACrC,KAAK,EAAE,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC;YAC9C,SAAS,EAAE,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC;YACnD,SAAS,EAAE,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC;SACtD,CAAA;IACL,CAAC;CACJ;AApFD,kCAoFC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Country } from "./Loader";
|
|
2
|
+
export declare class NaturalGasPrices {
|
|
3
|
+
countries: Country[];
|
|
4
|
+
constructor();
|
|
5
|
+
load(countryCode: string): Promise<{
|
|
6
|
+
time: number[];
|
|
7
|
+
naturalGasPrice: number[];
|
|
8
|
+
}>;
|
|
9
|
+
convert(x: any): {
|
|
10
|
+
time: number[];
|
|
11
|
+
naturalGasPrice: number[];
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NaturalGasPrices = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
class NaturalGasPrices {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.countries = [];
|
|
9
|
+
const countryPath = (0, path_1.join)(__dirname, '..', 'config/countries.json');
|
|
10
|
+
const countriesString = (0, fs_1.readFileSync)(countryPath, 'utf-8');
|
|
11
|
+
this.countries = JSON.parse(countriesString);
|
|
12
|
+
}
|
|
13
|
+
async load(countryCode) {
|
|
14
|
+
var _a;
|
|
15
|
+
const countryShort = (_a = this.countries.find((item) => item.code === countryCode)) === null || _a === void 0 ? void 0 : _a.short;
|
|
16
|
+
const url = `https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/nrg_pc_203/S.4100.GJ10000-99999.KWH.X_TAX.EUR.${countryShort}/?format=JSON&lang=en&startPeriod=2014&endPeriod=2023`;
|
|
17
|
+
const response = await fetch(url);
|
|
18
|
+
const json = await response.json();
|
|
19
|
+
const r = this.convert(json);
|
|
20
|
+
return r;
|
|
21
|
+
}
|
|
22
|
+
convert(x) {
|
|
23
|
+
var _a, _b, _c;
|
|
24
|
+
const timeLabels = ((_c = (_b = (_a = x === null || x === void 0 ? void 0 : x.dimension) === null || _a === void 0 ? void 0 : _a.time) === null || _b === void 0 ? void 0 : _b.category) === null || _c === void 0 ? void 0 : _c.label) || [];
|
|
25
|
+
const value = (x === null || x === void 0 ? void 0 : x.value) || {};
|
|
26
|
+
const values = Object.values(value);
|
|
27
|
+
const time = Object.keys(timeLabels).map(item => {
|
|
28
|
+
const split = item.split('-');
|
|
29
|
+
const year = parseInt(split[0]);
|
|
30
|
+
let month = 3;
|
|
31
|
+
if (split[1] === 'S2') {
|
|
32
|
+
month = 9;
|
|
33
|
+
}
|
|
34
|
+
const date = new Date(year, month);
|
|
35
|
+
return date.getTime();
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
time: time,
|
|
39
|
+
naturalGasPrice: values.map(item => (item || 0) * 1000)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.NaturalGasPrices = NaturalGasPrices;
|
|
44
|
+
//# source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GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAa,CAAA;QAC/C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC9B,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAChC,IAAI,KAAK,GAAG,CAAC,CAAC;YACd,IAAI,KAAK,CAAC,CAAC,CAAC,KAAG,IAAI,EAAC;gBACpB,KAAK,GAAG,CAAC,CAAC;aACT;YACD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YAClC,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;QAC1B,CAAC,CAAC,CAAA;QACF,OAAO;YACH,IAAI,EAAC,IAAI;YACT,eAAe,EAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,IAAE,CAAC,CAAC,GAAC,IAAI,CAAC;SACrD,CAAA;IACH,CAAC;CACF;AAtCD,4CAsCC"}
|
package/package.json
CHANGED
|
@@ -54,10 +54,19 @@
|
|
|
54
54
|
"yAxis": "price",
|
|
55
55
|
"abbr": "PR"
|
|
56
56
|
},
|
|
57
|
+
"naturalGasPrice": {
|
|
58
|
+
"name": "NatGas€",
|
|
59
|
+
"psrType": "X91",
|
|
60
|
+
"co2Footprint": 0,
|
|
61
|
+
"color": "purple",
|
|
62
|
+
"yAxis": "price",
|
|
63
|
+
"abbr": "NP"
|
|
64
|
+
},
|
|
65
|
+
|
|
57
66
|
"consumption": {
|
|
58
67
|
"name": "Consumption",
|
|
59
68
|
"psrType": "A05",
|
|
60
|
-
"co2Footprint":
|
|
69
|
+
"co2Footprint": 0,
|
|
61
70
|
"color": "#c3c3c3",
|
|
62
71
|
"abbr": "CO",
|
|
63
72
|
"stack": "stack2",
|
|
@@ -254,7 +263,7 @@
|
|
|
254
263
|
"ev": {
|
|
255
264
|
"name": "EV",
|
|
256
265
|
"psrType": "F16",
|
|
257
|
-
"co2Footprint":
|
|
266
|
+
"co2Footprint": 733,
|
|
258
267
|
"color": "gray",
|
|
259
268
|
"abbr": "EV",
|
|
260
269
|
"type": "fossil"
|
|
@@ -7,6 +7,7 @@ import { CommonTimestamps } from "./CommonTimestamps";
|
|
|
7
7
|
import { EurostatAPI } from "./Eurostat";
|
|
8
8
|
import { Types } from "../interfaces/types";
|
|
9
9
|
import { Format, QueryOptions } from "../interfaces/queryoptions";
|
|
10
|
+
import { NaturalGasPrices } from "./NaturalGasPrice";
|
|
10
11
|
|
|
11
12
|
export class LoadService {
|
|
12
13
|
country = '';
|
|
@@ -77,10 +78,17 @@ export class LoadService {
|
|
|
77
78
|
return await eurostat.load(country)
|
|
78
79
|
}
|
|
79
80
|
|
|
81
|
+
async getNaturalGasPrices(country: string) {
|
|
82
|
+
const eurostat = new NaturalGasPrices();
|
|
83
|
+
return await eurostat.load(country)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
80
87
|
async getCountrydata(country: string, reload: boolean) {
|
|
81
88
|
console.log('reload', country, reload)
|
|
82
89
|
return {
|
|
83
90
|
fossil: await this.getFossil(country),
|
|
91
|
+
price: await this.getNaturalGasPrices(country),
|
|
84
92
|
installed: await this.getInstalled(country, reload),
|
|
85
93
|
hydrofill: await this.getHydrofill(country, reload)
|
|
86
94
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { readFileSync } from "fs"
|
|
2
|
+
import { join } from "path"
|
|
3
|
+
import { Country } from "./Loader"
|
|
4
|
+
|
|
5
|
+
export class NaturalGasPrices {
|
|
6
|
+
countries: Country[] = []
|
|
7
|
+
constructor() {
|
|
8
|
+
const countryPath = join(__dirname, '..', 'config/countries.json')
|
|
9
|
+
const countriesString = readFileSync(countryPath, 'utf-8')
|
|
10
|
+
this.countries = JSON.parse(countriesString)
|
|
11
|
+
}
|
|
12
|
+
async load(countryCode: string) {
|
|
13
|
+
const countryShort = this.countries.find(
|
|
14
|
+
(item) => item.code === countryCode
|
|
15
|
+
)?.short
|
|
16
|
+
|
|
17
|
+
const url = `https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/data/nrg_pc_203/S.4100.GJ10000-99999.KWH.X_TAX.EUR.${countryShort}/?format=JSON&lang=en&startPeriod=2014&endPeriod=2023`
|
|
18
|
+
const response = await fetch(url)
|
|
19
|
+
const json = await response.json()
|
|
20
|
+
const r = this.convert(json)
|
|
21
|
+
return r;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
convert(x:any){
|
|
25
|
+
const timeLabels = x?.dimension?.time?.category?.label || [];
|
|
26
|
+
const value = x?.value || {};
|
|
27
|
+
const values = Object.values(value) as number[]
|
|
28
|
+
const time = Object.keys(timeLabels).map(item => {
|
|
29
|
+
const split = item.split('-');
|
|
30
|
+
const year = parseInt(split[0]);
|
|
31
|
+
let month = 3;
|
|
32
|
+
if (split[1]==='S2'){
|
|
33
|
+
month = 9;
|
|
34
|
+
}
|
|
35
|
+
const date = new Date(year, month)
|
|
36
|
+
return date.getTime();
|
|
37
|
+
})
|
|
38
|
+
return {
|
|
39
|
+
time:time,
|
|
40
|
+
naturalGasPrice:values.map(item => (item||0)*1000)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|