@hestia-earth/engine-models 0.65.9 → 0.65.11
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/config/Cycle.json +9 -9
- package/config/Site.json +18 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +23 -4
- package/dist/models.d.ts +1 -1
- package/dist/models.js +3 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/model-links.json +12 -0
- package/package.json +4 -4
- package/search-results.json +914 -914
- package/src/config.spec.ts +22 -1
- package/src/config.ts +27 -12
- package/src/models.spec.ts +3 -4
- package/src/models.ts +2 -1
- package/src/version.ts +1 -1
package/src/config.spec.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { describe, expect, test } from '@jest/globals';
|
|
2
2
|
import { NodeType } from '@hestia-earth/schema';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
loadConfig,
|
|
6
|
+
loadRunConfig,
|
|
7
|
+
loadTriggerConfig,
|
|
8
|
+
getMaxStage
|
|
9
|
+
} from './config';
|
|
5
10
|
|
|
6
11
|
describe('config', () => {
|
|
7
12
|
describe('loadConfig', () => {
|
|
@@ -64,4 +69,20 @@ describe('config', () => {
|
|
|
64
69
|
);
|
|
65
70
|
});
|
|
66
71
|
});
|
|
72
|
+
|
|
73
|
+
describe('getMaxStage', () => {
|
|
74
|
+
test('existing config', () => {
|
|
75
|
+
expect(getMaxStage(NodeType.Cycle)).toEqual(2);
|
|
76
|
+
expect(getMaxStage(NodeType.Site)).toEqual(2);
|
|
77
|
+
expect(getMaxStage(NodeType.ImpactAssessment)).toEqual(1);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('non-existing config', () => {
|
|
81
|
+
const t = () => getMaxStage('unknown' as any);
|
|
82
|
+
|
|
83
|
+
expect(t).toThrowError(
|
|
84
|
+
'Invalid type unknown. Allowed types: Cycle, Site, ImpactAssessment'
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
67
88
|
});
|
package/src/config.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { NodeType } from '@hestia-earth/schema';
|
|
2
|
+
import * as runConfig from '../config/run-calculations.json';
|
|
3
|
+
import * as triggerConfig from '../config/trigger-calculations.json';
|
|
4
|
+
import * as Cycle from '../config/Cycle.json';
|
|
5
|
+
import * as ImpactAssessment from '../config/ImpactAssessment.json';
|
|
6
|
+
import * as Site from '../config/Site.json';
|
|
2
7
|
|
|
3
8
|
export interface IOrchestratorModelConfig {
|
|
4
9
|
key: string;
|
|
@@ -29,14 +34,22 @@ const validateType = (nodeType: any) =>
|
|
|
29
34
|
);
|
|
30
35
|
})();
|
|
31
36
|
|
|
37
|
+
const typeToConfig: {
|
|
38
|
+
[type in NodeType]?: IOrchestratorConfig;
|
|
39
|
+
} = {
|
|
40
|
+
[NodeType.Cycle]: Cycle as IOrchestratorConfig,
|
|
41
|
+
[NodeType.ImpactAssessment]: ImpactAssessment as IOrchestratorConfig,
|
|
42
|
+
[NodeType.Site]: Site as IOrchestratorConfig
|
|
43
|
+
};
|
|
44
|
+
|
|
32
45
|
/**
|
|
33
46
|
* Load orchestrator configuration.
|
|
34
47
|
*
|
|
35
48
|
* @param nodeType NodeType associated with configuration.
|
|
36
49
|
* @returns
|
|
37
50
|
*/
|
|
38
|
-
export const loadConfig = (nodeType: allowedType)
|
|
39
|
-
validateType(nodeType) &&
|
|
51
|
+
export const loadConfig = (nodeType: allowedType) =>
|
|
52
|
+
validateType(nodeType) && typeToConfig[nodeType];
|
|
40
53
|
|
|
41
54
|
interface ICalculationConfigData {
|
|
42
55
|
key: 'related' | 'nested';
|
|
@@ -67,16 +80,18 @@ const validateStage = (
|
|
|
67
80
|
|
|
68
81
|
export const loadRunConfig = (nodeType: allowedType, stage: number) =>
|
|
69
82
|
validateType(nodeType) &&
|
|
70
|
-
validateStage(
|
|
71
|
-
require('../config/run-calculations.json') as calculationConfig,
|
|
72
|
-
nodeType,
|
|
73
|
-
stage
|
|
74
|
-
);
|
|
83
|
+
validateStage(runConfig as calculationConfig, nodeType, stage);
|
|
75
84
|
|
|
76
85
|
export const loadTriggerConfig = (nodeType: allowedType, stage: number) =>
|
|
77
86
|
validateType(nodeType) &&
|
|
78
|
-
validateStage(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
validateStage(triggerConfig as calculationConfig, nodeType, stage);
|
|
88
|
+
|
|
89
|
+
export const getMaxStage = (nodeType: allowedType) =>
|
|
90
|
+
validateType(nodeType)
|
|
91
|
+
? Math.max.apply(
|
|
92
|
+
Math.max,
|
|
93
|
+
Object.keys((runConfig as calculationConfig)[nodeType]).map((key) =>
|
|
94
|
+
Number(key.replace('stage-', ''))
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
: null;
|
package/src/models.spec.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { describe, expect, test } from '@jest/globals';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { models } from './models';
|
|
4
4
|
|
|
5
5
|
describe('models', () => {
|
|
6
6
|
describe('loadModels', () => {
|
|
7
|
-
test('
|
|
8
|
-
|
|
9
|
-
expect(links?.length > 0).toBeTruthy();
|
|
7
|
+
test('has links', () => {
|
|
8
|
+
expect(models.links?.length > 0).toBeTruthy();
|
|
10
9
|
});
|
|
11
10
|
});
|
|
12
11
|
});
|
package/src/models.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EmissionMethodTier } from '@hestia-earth/schema';
|
|
2
|
+
import * as data from '../model-links.json';
|
|
2
3
|
|
|
3
4
|
export interface IModel {
|
|
4
5
|
/**
|
|
@@ -33,4 +34,4 @@ export interface IModelLinks {
|
|
|
33
34
|
ecoinventV3AndEmberClimateLinks?: IModel[];
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
export const
|
|
37
|
+
export const models = data as IModelLinks;
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const ENGINE_VERSION = '0.65.
|
|
1
|
+
export const ENGINE_VERSION = '0.65.11';
|