@hestia-earth/engine-models 0.73.0 → 0.73.2

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 CHANGED
@@ -27,17 +27,9 @@
27
27
  "stage": 1
28
28
  },
29
29
  {
30
- "key": "practices",
31
- "model": "hestia",
32
- "value": "croppingIntensity",
33
- "runStrategy": "add_blank_node_if_missing",
34
- "mergeStrategy": "list",
35
- "stage": 1
36
- },
37
- {
38
- "key": "practices",
39
- "model": "geospatialDatabase",
40
- "value": "croppingIntensity",
30
+ "key": "inputs",
31
+ "model": "faostat2018",
32
+ "value": "seed",
41
33
  "runStrategy": "add_blank_node_if_missing",
42
34
  "mergeStrategy": "list",
43
35
  "stage": 1
@@ -100,6 +92,22 @@
100
92
  "stage": 1
101
93
  }
102
94
  ],
95
+ {
96
+ "key": "practices",
97
+ "model": "hestia",
98
+ "value": "croppingIntensity",
99
+ "runStrategy": "add_blank_node_if_missing",
100
+ "mergeStrategy": "list",
101
+ "stage": 1
102
+ },
103
+ {
104
+ "key": "practices",
105
+ "model": "geospatialDatabase",
106
+ "value": "croppingIntensity",
107
+ "runStrategy": "add_blank_node_if_missing",
108
+ "mergeStrategy": "list",
109
+ "stage": 1
110
+ },
103
111
  [
104
112
  {
105
113
  "key": "practices",
@@ -321,14 +329,6 @@
321
329
  "stage": 1
322
330
  },
323
331
  [
324
- {
325
- "key": "practices",
326
- "model": "hestia",
327
- "value": "longFallowRatio",
328
- "runStrategy": "add_blank_node_if_missing",
329
- "mergeStrategy": "list",
330
- "stage": 1
331
- },
332
332
  {
333
333
  "key": "practices",
334
334
  "model": "hestia",
@@ -467,24 +467,22 @@
467
467
  "stage": 1
468
468
  }
469
469
  ],
470
- [
471
- {
472
- "key": "inputs",
473
- "model": "faostat2018",
474
- "value": "seed",
475
- "runStrategy": "add_blank_node_if_missing",
476
- "mergeStrategy": "list",
477
- "stage": 1
478
- },
479
- {
480
- "key": "inputs",
481
- "model": "pooreNemecek2018",
482
- "value": "saplingsDepreciatedAmountPerCycle",
483
- "runStrategy": "add_blank_node_if_missing",
484
- "mergeStrategy": "list",
485
- "stage": 1
486
- }
487
- ],
470
+ {
471
+ "key": "practices",
472
+ "model": "hestia",
473
+ "value": "longFallowRatio",
474
+ "runStrategy": "add_blank_node_if_missing",
475
+ "mergeStrategy": "list",
476
+ "stage": 1
477
+ },
478
+ {
479
+ "key": "inputs",
480
+ "model": "pooreNemecek2018",
481
+ "value": "saplingsDepreciatedAmountPerCycle",
482
+ "runStrategy": "add_blank_node_if_missing",
483
+ "mergeStrategy": "list",
484
+ "stage": 1
485
+ },
488
486
  {
489
487
  "key": "completeness",
490
488
  "model": "cycle",
package/config/Site.json CHANGED
@@ -65,30 +65,6 @@
65
65
  "mergeStrategy": "list",
66
66
  "stage": 1
67
67
  },
68
- {
69
- "key": "measurements",
70
- "model": "hestia",
71
- "value": "brackishWater",
72
- "runStrategy": "add_blank_node_if_missing",
73
- "mergeStrategy": "list",
74
- "stage": 1
75
- },
76
- {
77
- "key": "measurements",
78
- "model": "hestia",
79
- "value": "freshWater",
80
- "runStrategy": "add_blank_node_if_missing",
81
- "mergeStrategy": "list",
82
- "stage": 1
83
- },
84
- {
85
- "key": "measurements",
86
- "model": "hestia",
87
- "value": "salineWater",
88
- "runStrategy": "add_blank_node_if_missing",
89
- "mergeStrategy": "list",
90
- "stage": 1
91
- },
92
68
  {
93
69
  "key": "measurements",
94
70
  "model": "hestia",
@@ -470,6 +446,32 @@
470
446
  "stage": 2
471
447
  }
472
448
  ],
449
+ [
450
+ {
451
+ "key": "measurements",
452
+ "model": "hestia",
453
+ "value": "brackishWater",
454
+ "runStrategy": "add_blank_node_if_missing",
455
+ "mergeStrategy": "list",
456
+ "stage": 1
457
+ },
458
+ {
459
+ "key": "measurements",
460
+ "model": "hestia",
461
+ "value": "freshWater",
462
+ "runStrategy": "add_blank_node_if_missing",
463
+ "mergeStrategy": "list",
464
+ "stage": 1
465
+ },
466
+ {
467
+ "key": "measurements",
468
+ "model": "hestia",
469
+ "value": "salineWater",
470
+ "runStrategy": "add_blank_node_if_missing",
471
+ "mergeStrategy": "list",
472
+ "stage": 1
473
+ }
474
+ ],
473
475
  [
474
476
  {
475
477
  "key": "defaultMethodClassification",
package/dist/config.d.ts CHANGED
@@ -12,6 +12,7 @@ export interface IOrchestratorConfig {
12
12
  models: (IOrchestratorModelConfig | IOrchestratorModelConfig[])[];
13
13
  }
14
14
  export type allowedType = NodeType.Cycle | NodeType.Site | NodeType.ImpactAssessment;
15
+ export declare const allowedTypes: allowedType[];
15
16
  /**
16
17
  * Load orchestrator configuration.
17
18
  *
package/dist/config.js CHANGED
@@ -1,18 +1,22 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getMaxStage = exports.loadTriggerConfig = exports.loadRunConfig = exports.loadConfig = void 0;
4
+ exports.getMaxStage = exports.loadTriggerConfig = exports.loadRunConfig = exports.loadConfig = exports.allowedTypes = void 0;
5
5
  var schema_1 = require("@hestia-earth/schema");
6
6
  var runConfig = require("../config/run-calculations.json");
7
7
  var triggerConfig = require("../config/trigger-calculations.json");
8
8
  var Cycle = require("../config/Cycle.json");
9
9
  var ImpactAssessment = require("../config/ImpactAssessment.json");
10
10
  var Site = require("../config/Site.json");
11
- var allowedTypes = [schema_1.NodeType.Cycle, schema_1.NodeType.Site, schema_1.NodeType.ImpactAssessment];
11
+ exports.allowedTypes = [
12
+ schema_1.NodeType.Cycle,
13
+ schema_1.NodeType.Site,
14
+ schema_1.NodeType.ImpactAssessment
15
+ ];
12
16
  var validateType = function (nodeType) {
13
- return allowedTypes.includes(nodeType) ||
17
+ return exports.allowedTypes.includes(nodeType) ||
14
18
  (function () {
15
- throw new Error("Invalid type ".concat(nodeType, ". Allowed types: ").concat(allowedTypes.join(', ')));
19
+ throw new Error("Invalid type ".concat(nodeType, ". Allowed types: ").concat(exports.allowedTypes.join(', ')));
16
20
  })();
17
21
  };
18
22
  var typeToConfig = (_a = {},
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from './config';
2
2
  export * from './models';
3
+ export * from './utils';
4
+ export * from './validate-config';
3
5
  export * from './version';
package/dist/index.js CHANGED
@@ -16,4 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./config"), exports);
18
18
  __exportStar(require("./models"), exports);
19
+ __exportStar(require("./utils"), exports);
20
+ __exportStar(require("./validate-config"), exports);
19
21
  __exportStar(require("./version"), exports);
package/dist/models.d.ts CHANGED
@@ -24,6 +24,10 @@ export interface IModel {
24
24
  * A key in the model if term does not exist.
25
25
  */
26
26
  modelKey?: string;
27
+ /**
28
+ * List of other models this model needs to run.
29
+ */
30
+ dependencies?: string[];
27
31
  }
28
32
  export type modelLookup = Record<string, Pick<IModel, 'model' | 'term' | 'modelKey'>[]>;
29
33
  export interface IModelLinks {
@@ -0,0 +1,6 @@
1
+ import { IOrchestratorModelConfig } from './config';
2
+ import { IModel } from './models';
3
+ export declare const findMatchingModel: (model: Partial<IModel>, config?: {
4
+ useDotValues?: boolean;
5
+ }) => IModel;
6
+ export declare const findMatchingModelFromConfig: (model: Pick<IOrchestratorModelConfig, "model" | "value">) => IModel;
package/dist/utils.js ADDED
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.findMatchingModelFromConfig = exports.findMatchingModel = void 0;
20
+ var models_1 = require("./models");
21
+ var matchWithDot = function (model, key, value) {
22
+ return typeof value === 'string' && value.split('.').pop() === model[key];
23
+ };
24
+ var matchPath = function (model, key, value) {
25
+ return key === 'path' && typeof value === 'string' && model[key].startsWith(value);
26
+ };
27
+ var findMatchingModel = function (model, config) {
28
+ if (config === void 0) { config = {
29
+ useDotValues: false
30
+ }; }
31
+ return Object.keys(model).length > 0
32
+ ? models_1.models.links.find(function (m) {
33
+ return Object.entries(model).every(function (_a) {
34
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
35
+ return value === m[key] ||
36
+ (config.useDotValues && matchWithDot(m, key, value)) ||
37
+ matchPath(m, key, value);
38
+ });
39
+ })
40
+ : null;
41
+ };
42
+ exports.findMatchingModel = findMatchingModel;
43
+ var modelMatchOrder = function (_a) {
44
+ var model = _a.model, value = _a.value;
45
+ return [
46
+ { model: model, term: value },
47
+ { model: model, modelKey: value },
48
+ {
49
+ model: model,
50
+ modelKey: value.split('.').pop()
51
+ },
52
+ {
53
+ model: model,
54
+ term: value.split('.').pop()
55
+ },
56
+ {
57
+ model: model,
58
+ path: ['hestia_earth', 'models', model, value].join('/')
59
+ },
60
+ !value || value === 'all' ? { model: model } : null
61
+ ].filter(Boolean);
62
+ };
63
+ var findMatchingModelFromConfig = function (model) {
64
+ var _a, _b;
65
+ return (_b = (_a = modelMatchOrder(model)
66
+ .map(function (params) {
67
+ return (0, exports.findMatchingModel)(params) ||
68
+ (0, exports.findMatchingModel)(params, { useDotValues: true });
69
+ })) === null || _a === void 0 ? void 0 : _a.filter(Boolean)) === null || _b === void 0 ? void 0 : _b.shift();
70
+ };
71
+ exports.findMatchingModelFromConfig = findMatchingModelFromConfig;
@@ -0,0 +1,6 @@
1
+ import { allowedType, IOrchestratorModelConfig } from './config';
2
+ export declare const validateConfig: (nodeType: allowedType) => {
3
+ model: IOrchestratorModelConfig;
4
+ existing: string[];
5
+ missing: string[];
6
+ }[];
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateConfig = void 0;
4
+ var config_1 = require("./config");
5
+ var utils_1 = require("./utils");
6
+ // models not included in the links
7
+ var skipModels = ['emissions.deleted', 'transformations'];
8
+ var isHestiaResidueCyclicModel = function (_a) {
9
+ var model = _a.model, value = _a.value;
10
+ return model === 'hestia' && (value === null || value === void 0 ? void 0 : value.startsWith('residue'));
11
+ };
12
+ var isOrganicCarbonCyclicModel = function (_a) {
13
+ var model = _a.model, value = _a.value;
14
+ return model === 'hestia' && (value === null || value === void 0 ? void 0 : value.startsWith('organicCarbonPer'));
15
+ };
16
+ var includeModel = function (model) {
17
+ return [
18
+ !skipModels.includes(model.model),
19
+ // cyclic dependencies
20
+ !isHestiaResidueCyclicModel(model),
21
+ !isOrganicCarbonCyclicModel(model)
22
+ ].every(Boolean);
23
+ };
24
+ // dependencies that cannot be validated
25
+ var skipDependencies = [
26
+ // completeness gap-fills after other models run
27
+ 'completeness'
28
+ ];
29
+ var matchDependencies = function (models) { return function (model) {
30
+ var _a, _b, _c;
31
+ var dependencies = (0, utils_1.findMatchingModelFromConfig)(model).dependencies;
32
+ var previousModels = models.slice(0, models.indexOf(model));
33
+ var existing = (_a = dependencies === null || dependencies === void 0 ? void 0 : dependencies.filter(function (value) {
34
+ return previousModels.some(function (config) { var _a; return ((_a = config.value) === null || _a === void 0 ? void 0 : _a.split('.').pop()) === value; });
35
+ })) !== null && _a !== void 0 ? _a : [];
36
+ return {
37
+ model: model,
38
+ existing: existing,
39
+ missing: (_c = (_b = dependencies === null || dependencies === void 0 ? void 0 : dependencies
40
+ // skip dependencies that dont exist at all
41
+ .filter(function (value) { return models.some(function (config) { return config.value === value; }); })) === null || _b === void 0 ? void 0 : _b.filter(function (v) {
42
+ return !existing.includes(v) &&
43
+ !skipDependencies.includes(v) &&
44
+ v !== model.value;
45
+ })) !== null && _c !== void 0 ? _c : []
46
+ };
47
+ }; };
48
+ var validateConfig = function (nodeType) {
49
+ var config = (0, config_1.loadConfig)(nodeType);
50
+ // flatten all models to process one by one, starting with the last one
51
+ var models = config.models.flat();
52
+ var results = models.filter(includeModel).map(matchDependencies(models));
53
+ return results.filter(function (r) { return r.missing.length > 0; });
54
+ };
55
+ exports.validateConfig = validateConfig;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const ENGINE_VERSION = "0.73.0";
1
+ export declare const ENGINE_VERSION = "0.73.2";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ENGINE_VERSION = void 0;
4
- exports.ENGINE_VERSION = '0.73.0';
4
+ exports.ENGINE_VERSION = '0.73.2';