hestia-earth-utils 0.16.14__py3-none-any.whl → 0.16.16__py3-none-any.whl
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/blank_node.py +34 -16
- hestia_earth/utils/cycle.py +24 -5
- hestia_earth/utils/pivot/_shared.py +0 -1
- hestia_earth/utils/version.py +1 -1
- {hestia_earth_utils-0.16.14.dist-info → hestia_earth_utils-0.16.16.dist-info}/METADATA +2 -2
- {hestia_earth_utils-0.16.14.dist-info → hestia_earth_utils-0.16.16.dist-info}/RECORD +10 -10
- {hestia_earth_utils-0.16.14.dist-info → hestia_earth_utils-0.16.16.dist-info}/WHEEL +1 -1
- {hestia_earth_utils-0.16.14.data → hestia_earth_utils-0.16.16.data}/scripts/hestia-format-upload +0 -0
- {hestia_earth_utils-0.16.14.data → hestia_earth_utils-0.16.16.data}/scripts/hestia-pivot-csv +0 -0
- {hestia_earth_utils-0.16.14.dist-info → hestia_earth_utils-0.16.16.dist-info}/top_level.txt +0 -0
hestia_earth/utils/blank_node.py
CHANGED
|
@@ -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
|
|
hestia_earth/utils/cycle.py
CHANGED
|
@@ -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
|
}
|
hestia_earth/utils/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = "0.16.
|
|
1
|
+
VERSION = "0.16.16"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hestia_earth_utils
|
|
3
|
-
Version: 0.16.
|
|
3
|
+
Version: 0.16.16
|
|
4
4
|
Summary: HESTIA's utils library
|
|
5
5
|
Home-page: https://gitlab.com/hestia-earth/hestia-utils
|
|
6
6
|
Author: HESTIA Team
|
|
@@ -13,7 +13,7 @@ Requires-Dist: hestia-earth-schema>=35.0.1
|
|
|
13
13
|
Requires-Dist: requests>=2.24.0
|
|
14
14
|
Requires-Dist: urllib3~=1.26.0
|
|
15
15
|
Requires-Dist: python-dateutil>=2.8.1
|
|
16
|
-
Requires-Dist: pandas
|
|
16
|
+
Requires-Dist: pandas<3,>=2
|
|
17
17
|
Requires-Dist: flatten_json
|
|
18
18
|
Dynamic: author
|
|
19
19
|
Dynamic: author-email
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
hestia_earth/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
hestia_earth/utils/api.py,sha256=b6g87ylAgdWvwPlDeZDv74UGfXVe1KFXap5-Rv5daSE,9929
|
|
3
|
-
hestia_earth/utils/blank_node.py,sha256
|
|
3
|
+
hestia_earth/utils/blank_node.py,sha256=-ABKV9eiDIxzGWma1tTWxaupF_yQ1SvE6wfItR8OZCs,8368
|
|
4
4
|
hestia_earth/utils/calculation_status.py,sha256=f5b05cEFXMfFI1clirIt7v3Y9H2Nja66GYv1NCyZjf0,2381
|
|
5
|
-
hestia_earth/utils/cycle.py,sha256=
|
|
5
|
+
hestia_earth/utils/cycle.py,sha256=MbIK4qOMceAb9mV_Un8UsxmmmAtvGwSE9saYHROIPjQ,1788
|
|
6
6
|
hestia_earth/utils/date.py,sha256=cwcGtYVh2K5rH7k5uO1Olovy-hzIDrvsfaiR94ZlyO0,16165
|
|
7
7
|
hestia_earth/utils/descriptive_stats.py,sha256=YvDI6EWCcZWw8yCxYhqyzMCDqCu2X8DjvygmMK_AVvc,1633
|
|
8
8
|
hestia_earth/utils/emission.py,sha256=rHHf5vwe-RxTOaOJ9N0MuyJOLpDnPjjxv6MHYSpPgcU,2165
|
|
@@ -15,9 +15,9 @@ hestia_earth/utils/stats.py,sha256=vTNyKcMKmX0DoodM9QEG7HF8qm2Wf-4ckMWQFWZ1VgE,3
|
|
|
15
15
|
hestia_earth/utils/table.py,sha256=MOJDo5fQPRDogAty_UXbO9-EXFwz97m0f7--mOM17lQ,2363
|
|
16
16
|
hestia_earth/utils/term.py,sha256=aBVYuYv55nPqJPyt5mN4Fz652s_1hwUPckNUZX0pMP8,1064
|
|
17
17
|
hestia_earth/utils/tools.py,sha256=WMx05cBtBR8mYQnLLBA2cgF1x2tI41514diFDeX4gLQ,7533
|
|
18
|
-
hestia_earth/utils/version.py,sha256=
|
|
18
|
+
hestia_earth/utils/version.py,sha256=SGKvksJDyfirCQnk3wbuotlbC2CvazXTR8lJe6kBC6U,20
|
|
19
19
|
hestia_earth/utils/pivot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
-
hestia_earth/utils/pivot/_shared.py,sha256=
|
|
20
|
+
hestia_earth/utils/pivot/_shared.py,sha256=ZBmZRLbDN2JHODvQAh9jH_61Koh7Ts0C52xmiw_Bhpo,2827
|
|
21
21
|
hestia_earth/utils/pivot/pivot_csv.py,sha256=1zGYuC_xlrLoX5FYSG3mt5HSc03CO-0p8J0oAmyI1VI,11778
|
|
22
22
|
hestia_earth/utils/pivot/pivot_json.py,sha256=yWbsuFeTQJPk4H2b7ibVALGJa3qfKGyNuPeqM8yrcsI,11030
|
|
23
23
|
hestia_earth/utils/storage/__init__.py,sha256=uNX6_EHWWnNUIm4Ng7L43-cQmuc6NGFAxXye85saIXQ,922
|
|
@@ -25,9 +25,9 @@ hestia_earth/utils/storage/_azure_client.py,sha256=mseexhzjteRDzzoFe2fEXe9MYLmvj
|
|
|
25
25
|
hestia_earth/utils/storage/_local_client.py,sha256=KbYqTfniIU5R5J1m_unCQip9kOz9EGIGI0OH0QvD8eo,551
|
|
26
26
|
hestia_earth/utils/storage/_s3_client.py,sha256=8TCxiHfxE7G8kdp3CnEFrxgmPwfPyci3-blsowE2T7o,3146
|
|
27
27
|
hestia_earth/utils/storage/_sns_client.py,sha256=pvtXYw-sQ8ns3mlDz7ld9iZp3FYSm0xSXSXMJ5IPnBc,380
|
|
28
|
-
hestia_earth_utils-0.16.
|
|
29
|
-
hestia_earth_utils-0.16.
|
|
30
|
-
hestia_earth_utils-0.16.
|
|
31
|
-
hestia_earth_utils-0.16.
|
|
32
|
-
hestia_earth_utils-0.16.
|
|
33
|
-
hestia_earth_utils-0.16.
|
|
28
|
+
hestia_earth_utils-0.16.16.data/scripts/hestia-format-upload,sha256=IhLAHHPJqRgUcht-M_EUEsRMbRbMfshig07o488zscM,703
|
|
29
|
+
hestia_earth_utils-0.16.16.data/scripts/hestia-pivot-csv,sha256=0YBuGuyPO8rytod6iwWEKiQdSlr9JLuD001k6U5t6no,1163
|
|
30
|
+
hestia_earth_utils-0.16.16.dist-info/METADATA,sha256=iOf4uwvgxtoZgFdSjW3uElhZfRf9vRQFJL_LC9ojvlM,1873
|
|
31
|
+
hestia_earth_utils-0.16.16.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
32
|
+
hestia_earth_utils-0.16.16.dist-info/top_level.txt,sha256=q0QxKEYx9uLpAD5ZtC7Ypq29smEPfOzEAn7Xv8XHGOQ,13
|
|
33
|
+
hestia_earth_utils-0.16.16.dist-info/RECORD,,
|
{hestia_earth_utils-0.16.14.data → hestia_earth_utils-0.16.16.data}/scripts/hestia-format-upload
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.14.data → hestia_earth_utils-0.16.16.data}/scripts/hestia-pivot-csv
RENAMED
|
File without changes
|
|
File without changes
|