hestia-earth-utils 0.16.14__tar.gz → 0.16.15__tar.gz
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.
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/PKG-INFO +1 -1
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/blank_node.py +34 -16
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/cycle.py +24 -5
- hestia_earth_utils-0.16.15/hestia_earth/utils/version.py +1 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth_utils.egg-info/PKG-INFO +1 -1
- hestia_earth_utils-0.16.15/tests/test_calculation_status.py +40 -0
- hestia_earth_utils-0.16.15/tests/test_cycle.py +33 -0
- hestia_earth_utils-0.16.14/hestia_earth/utils/version.py +0 -1
- hestia_earth_utils-0.16.14/tests/test_calculation_status.py +0 -40
- hestia_earth_utils-0.16.14/tests/test_cycle.py +0 -18
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/MANIFEST.in +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/README.md +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/bin/hestia-format-upload +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/bin/hestia-pivot-csv +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/__init__.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/api.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/calculation_status.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/date.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/descriptive_stats.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/emission.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/lookup.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/lookup_utils.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/model.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/pipeline.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/pivot/__init__.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/pivot/_shared.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/pivot/pivot_csv.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/pivot/pivot_json.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/request.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/stats.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/storage/__init__.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/storage/_azure_client.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/storage/_local_client.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/storage/_s3_client.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/storage/_sns_client.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/table.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/term.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/tools.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth_utils.egg-info/SOURCES.txt +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth_utils.egg-info/dependency_links.txt +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth_utils.egg-info/requires.txt +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth_utils.egg-info/top_level.txt +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/setup.cfg +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/setup.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_api.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_blank_node.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_date.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_descriptive_stats.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_emission.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_lookup.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_lookup_utils.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_model.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_pipeline.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_request.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_stats.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_table.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_term.py +0 -0
- {hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/tests/test_tools.py +0 -0
|
@@ -186,6 +186,38 @@ def get_node_value(
|
|
|
186
186
|
_BLANK_NODE_GROUPING_KEYS = {TermTermType.EMISSION: ["methodModel"]}
|
|
187
187
|
|
|
188
188
|
|
|
189
|
+
def _pluralize_key(key: str):
|
|
190
|
+
return key + ("" if key.endswith("s") else "s")
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _blank_node_ids(values: list):
|
|
194
|
+
return sorted(list(set(list(map(lambda v: v.get("@id"), values)))))
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _blank_node_sub_values(blank_nodes: list, key: str):
|
|
198
|
+
values = flatten(map(lambda v: v.get(key, []), blank_nodes))
|
|
199
|
+
return {_pluralize_key(key): _blank_node_ids(values)} if values else {}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _blank_node_data(blank_nodes: list):
|
|
203
|
+
value = get_node_value(
|
|
204
|
+
{
|
|
205
|
+
"term": blank_nodes[0].get("term"),
|
|
206
|
+
"value": list(map(get_node_value, blank_nodes)),
|
|
207
|
+
}
|
|
208
|
+
)
|
|
209
|
+
sub_values = ["inputs", "operation", "transformation"]
|
|
210
|
+
has_cycle_value = any(
|
|
211
|
+
[
|
|
212
|
+
all([get_node_value(v) is not None, not v.get("transformation")])
|
|
213
|
+
for v in blank_nodes
|
|
214
|
+
]
|
|
215
|
+
)
|
|
216
|
+
return {"value": value, "hasCycleValue": has_cycle_value} | reduce(
|
|
217
|
+
lambda p, c: p | _blank_node_sub_values(blank_nodes, c), sub_values, {}
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
|
|
189
221
|
def get_blank_nodes_calculation_status(
|
|
190
222
|
node: dict, list_key: str, termType: TermTermType
|
|
191
223
|
):
|
|
@@ -214,20 +246,6 @@ def get_blank_nodes_calculation_status(
|
|
|
214
246
|
blank_nodes_by_term = group_by_keys(blank_nodes, ["term"])
|
|
215
247
|
blank_nodes_grouping_keys = _BLANK_NODE_GROUPING_KEYS.get(termType) or []
|
|
216
248
|
|
|
217
|
-
def blank_node_data(blank_nodes: list):
|
|
218
|
-
value = get_node_value(
|
|
219
|
-
{
|
|
220
|
-
"term": blank_nodes[0].get("term"),
|
|
221
|
-
"value": list(map(get_node_value, blank_nodes)),
|
|
222
|
-
}
|
|
223
|
-
)
|
|
224
|
-
inputs = flatten(map(lambda v: v.get("inputs", []), blank_nodes))
|
|
225
|
-
return {"value": value} | (
|
|
226
|
-
{"inputs": sorted(list(map(lambda v: v.get("@id"), inputs)))}
|
|
227
|
-
if inputs
|
|
228
|
-
else {}
|
|
229
|
-
)
|
|
230
|
-
|
|
231
249
|
def map_blank_node(term_id: str):
|
|
232
250
|
values = blank_nodes_by_term.get(term_id, [])
|
|
233
251
|
grouped_blank_nodes = (
|
|
@@ -239,9 +257,9 @@ def get_blank_nodes_calculation_status(
|
|
|
239
257
|
{}
|
|
240
258
|
if not values
|
|
241
259
|
else (
|
|
242
|
-
{k:
|
|
260
|
+
{k: _blank_node_data(v) for k, v in grouped_blank_nodes.items()}
|
|
243
261
|
if grouped_blank_nodes
|
|
244
|
-
else
|
|
262
|
+
else _blank_node_data([values[0]])
|
|
245
263
|
)
|
|
246
264
|
)
|
|
247
265
|
|
|
@@ -4,10 +4,16 @@ from .tools import flatten
|
|
|
4
4
|
from .blank_node import get_blank_nodes_calculation_status
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
def _extend_missing_values(
|
|
8
|
+
value: dict, all_values: set, key: str, must_have_key: bool = False
|
|
9
|
+
):
|
|
10
|
+
included_values = set(flatten([v.get(key, []) for v in value.values()]))
|
|
11
|
+
missing_values = all_values - included_values
|
|
12
|
+
return (
|
|
13
|
+
{"missing" + key.capitalize(): sorted(list(missing_values))}
|
|
14
|
+
if all([missing_values, not must_have_key or included_values])
|
|
15
|
+
else {}
|
|
16
|
+
)
|
|
11
17
|
|
|
12
18
|
|
|
13
19
|
def get_cycle_emissions_calculation_status(cycle: dict):
|
|
@@ -30,7 +36,20 @@ def get_cycle_emissions_calculation_status(cycle: dict):
|
|
|
30
36
|
cycle, "emissions", TermTermType.EMISSION
|
|
31
37
|
)
|
|
32
38
|
input_ids = set([v.get("term", {}).get("@id") for v in cycle.get("inputs", [])])
|
|
39
|
+
transformation_ids = set(
|
|
40
|
+
[v.get("term", {}).get("@id") for v in cycle.get("transformations", [])]
|
|
41
|
+
)
|
|
33
42
|
return {
|
|
34
|
-
k: v
|
|
43
|
+
k: v
|
|
44
|
+
| (
|
|
45
|
+
_extend_missing_values(v, input_ids, "inputs")
|
|
46
|
+
if "InputsProduction" in k
|
|
47
|
+
else {}
|
|
48
|
+
)
|
|
49
|
+
| (
|
|
50
|
+
_extend_missing_values(
|
|
51
|
+
v, transformation_ids, "transformations", must_have_key=True
|
|
52
|
+
)
|
|
53
|
+
)
|
|
35
54
|
for k, v in status.items()
|
|
36
55
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = "0.16.15"
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
from tests.utils import fixtures_path
|
|
5
|
+
from hestia_earth.utils.calculation_status import _emissions_with_status
|
|
6
|
+
|
|
7
|
+
fixtures_folder = os.path.join(fixtures_path, "calculation_status")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_emissions_with_status():
|
|
11
|
+
with open(os.path.join(fixtures_folder, "nodes.json")) as f:
|
|
12
|
+
nodes = json.load(f)
|
|
13
|
+
|
|
14
|
+
result = _emissions_with_status(nodes[0])
|
|
15
|
+
assert result == {
|
|
16
|
+
"emissions-total": 195,
|
|
17
|
+
"emissions-complete": 55,
|
|
18
|
+
"emissions-incomplete": 0,
|
|
19
|
+
"emissions-missing": 140,
|
|
20
|
+
"emissions": result["emissions"], # ignore
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
result = _emissions_with_status(nodes[1])
|
|
24
|
+
assert result == {
|
|
25
|
+
"emissions-total": 195,
|
|
26
|
+
"emissions-complete": 0,
|
|
27
|
+
"emissions-incomplete": 13,
|
|
28
|
+
"emissions-missing": 182,
|
|
29
|
+
"emissions": result["emissions"], # ignore
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# def test_get_nodes_calculations_status_dataframe():
|
|
34
|
+
# with open(os.path.join(fixtures_folder, 'nodes.json')) as f:
|
|
35
|
+
# nodes = json.load(f)
|
|
36
|
+
|
|
37
|
+
# expected = open(os.path.join(fixtures_folder, 'result.csv'), 'r').read()
|
|
38
|
+
|
|
39
|
+
# df = get_nodes_calculations_status_dataframe(nodes, file_format='csv')
|
|
40
|
+
# assert df.to_csv(None, index=None) == expected
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import json
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from tests.utils import fixtures_path
|
|
6
|
+
from hestia_earth.utils.cycle import get_cycle_emissions_calculation_status
|
|
7
|
+
|
|
8
|
+
fixtures_folder = os.path.join(fixtures_path, "blank_node", "calculation_status")
|
|
9
|
+
_folders = [
|
|
10
|
+
d
|
|
11
|
+
for d in os.listdir(fixtures_folder)
|
|
12
|
+
if os.path.isdir(os.path.join(fixtures_folder, d))
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.mark.parametrize("folder", _folders)
|
|
17
|
+
def test_get_cycle_emissions_calculation_status(folder: str):
|
|
18
|
+
with open(
|
|
19
|
+
os.path.join(fixtures_folder, folder, "node.jsonld"), encoding="utf-8"
|
|
20
|
+
) as f:
|
|
21
|
+
cycle = json.load(f)
|
|
22
|
+
|
|
23
|
+
with open(
|
|
24
|
+
os.path.join(
|
|
25
|
+
fixtures_folder, folder, "emissions-emission-with-missing-inputs.json"
|
|
26
|
+
),
|
|
27
|
+
encoding="utf-8",
|
|
28
|
+
) as f:
|
|
29
|
+
expected = json.load(f)
|
|
30
|
+
|
|
31
|
+
result = get_cycle_emissions_calculation_status(cycle)
|
|
32
|
+
print(json.dumps(result, indent=2))
|
|
33
|
+
assert result == expected
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
VERSION = "0.16.14"
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# import os
|
|
2
|
-
# import json
|
|
3
|
-
|
|
4
|
-
# from tests.utils import fixtures_path
|
|
5
|
-
# from hestia_earth.utils.calculation_status import _emissions_with_status, get_nodes_calculations_status_dataframe
|
|
6
|
-
|
|
7
|
-
# fixtures_folder = os.path.join(fixtures_path, 'calculation_status')
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
# def test_emissions_with_status():
|
|
11
|
-
# with open(os.path.join(fixtures_folder, 'nodes.json')) as f:
|
|
12
|
-
# nodes = json.load(f)
|
|
13
|
-
|
|
14
|
-
# result = _emissions_with_status(nodes[0])
|
|
15
|
-
# assert result == {
|
|
16
|
-
# 'emissions-total': 193,
|
|
17
|
-
# 'emissions-complete': 56,
|
|
18
|
-
# 'emissions-incomplete': 1,
|
|
19
|
-
# 'emissions-missing': 136,
|
|
20
|
-
# 'emissions': result['emissions'] # ignore
|
|
21
|
-
# }
|
|
22
|
-
|
|
23
|
-
# result = _emissions_with_status(nodes[1])
|
|
24
|
-
# assert result == {
|
|
25
|
-
# 'emissions-total': 193,
|
|
26
|
-
# 'emissions-complete': 0,
|
|
27
|
-
# 'emissions-incomplete': 13,
|
|
28
|
-
# 'emissions-missing': 180,
|
|
29
|
-
# 'emissions': result['emissions'] # ignore
|
|
30
|
-
# }
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
# def test_get_nodes_calculations_status_dataframe():
|
|
34
|
-
# with open(os.path.join(fixtures_folder, 'nodes.json')) as f:
|
|
35
|
-
# nodes = json.load(f)
|
|
36
|
-
|
|
37
|
-
# expected = open(os.path.join(fixtures_folder, 'result.csv'), 'r').read()
|
|
38
|
-
|
|
39
|
-
# df = get_nodes_calculations_status_dataframe(nodes, file_format='csv')
|
|
40
|
-
# assert df.to_csv(None, index=None) == expected
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# import os
|
|
2
|
-
# import json
|
|
3
|
-
|
|
4
|
-
# from tests.utils import fixtures_path
|
|
5
|
-
# from hestia_earth.utils.cycle import get_cycle_emissions_calculation_status
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
# def test_get_cycle_emissions_calculation_status():
|
|
9
|
-
# folder = os.path.join(fixtures_path, 'blank_node', 'calculation_status', 'cycle')
|
|
10
|
-
|
|
11
|
-
# with open(f"{folder}/node.jsonld", encoding='utf-8') as f:
|
|
12
|
-
# cycle = json.load(f)
|
|
13
|
-
|
|
14
|
-
# with open(f"{folder}/emissions-emission-with-missing-inputs.json", encoding='utf-8') as f:
|
|
15
|
-
# expected = json.load(f)
|
|
16
|
-
|
|
17
|
-
# result = get_cycle_emissions_calculation_status(cycle)
|
|
18
|
-
# assert result == expected
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/calculation_status.py
RENAMED
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/descriptive_stats.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/lookup_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/pivot/__init__.py
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/pivot/_shared.py
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/pivot/pivot_csv.py
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/pivot/pivot_json.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/storage/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/storage/_s3_client.py
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth/utils/storage/_sns_client.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth_utils.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth_utils.egg-info/requires.txt
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.14 → hestia_earth_utils-0.16.15}/hestia_earth_utils.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|