hestia-earth-utils 0.15.14__py3-none-any.whl → 0.15.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/emission.py +10 -2
- hestia_earth/utils/lookup_utils.py +68 -50
- hestia_earth/utils/version.py +1 -1
- {hestia_earth_utils-0.15.14.dist-info → hestia_earth_utils-0.15.16.dist-info}/METADATA +1 -1
- {hestia_earth_utils-0.15.14.dist-info → hestia_earth_utils-0.15.16.dist-info}/RECORD +9 -9
- {hestia_earth_utils-0.15.14.data → hestia_earth_utils-0.15.16.data}/scripts/hestia-format-upload +0 -0
- {hestia_earth_utils-0.15.14.data → hestia_earth_utils-0.15.16.data}/scripts/hestia-pivot-csv +0 -0
- {hestia_earth_utils-0.15.14.dist-info → hestia_earth_utils-0.15.16.dist-info}/WHEEL +0 -0
- {hestia_earth_utils-0.15.14.dist-info → hestia_earth_utils-0.15.16.dist-info}/top_level.txt +0 -0
hestia_earth/utils/emission.py
CHANGED
|
@@ -9,7 +9,11 @@ from .lookup_utils import (
|
|
|
9
9
|
is_product_termType_allowed,
|
|
10
10
|
is_product_id_allowed,
|
|
11
11
|
is_input_termType_allowed,
|
|
12
|
-
is_input_id_allowed
|
|
12
|
+
is_input_id_allowed,
|
|
13
|
+
is_practice_termType_allowed,
|
|
14
|
+
is_practice_id_allowed,
|
|
15
|
+
is_transformation_termType_allowed,
|
|
16
|
+
is_transformation_id_allowed,
|
|
13
17
|
)
|
|
14
18
|
|
|
15
19
|
|
|
@@ -35,7 +39,11 @@ def cycle_emission_is_in_system_boundary(cycle: dict):
|
|
|
35
39
|
is_product_termType_allowed,
|
|
36
40
|
is_product_id_allowed,
|
|
37
41
|
is_input_termType_allowed,
|
|
38
|
-
is_input_id_allowed
|
|
42
|
+
is_input_id_allowed,
|
|
43
|
+
is_practice_termType_allowed,
|
|
44
|
+
is_practice_id_allowed,
|
|
45
|
+
is_transformation_termType_allowed,
|
|
46
|
+
is_transformation_id_allowed,
|
|
39
47
|
]))
|
|
40
48
|
|
|
41
49
|
return filter_term
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from functools import lru_cache
|
|
2
2
|
import json
|
|
3
|
+
from hestia_earth.schema import SchemaType
|
|
3
4
|
|
|
4
5
|
from .lookup import _download_lookup_data, download_lookup, get_table_value, column_name
|
|
5
6
|
from .api import download_hestia
|
|
@@ -35,6 +36,10 @@ def _get_site_measurements(node: dict):
|
|
|
35
36
|
return flatten([non_empty_list(site.get('measurements', [])) for site in sites])
|
|
36
37
|
|
|
37
38
|
|
|
39
|
+
def _blank_node_term_values(blank_nodes: list, key: str = '@id'):
|
|
40
|
+
return non_empty_list([v.get('term', {}).get(key) for v in blank_nodes])
|
|
41
|
+
|
|
42
|
+
|
|
38
43
|
@lru_cache()
|
|
39
44
|
def _allowed_model_mapping(model: str, term_id: str, column: str):
|
|
40
45
|
mapping = _allowed_mapping_data()
|
|
@@ -45,22 +50,27 @@ def _allowed_model_mapping(model: str, term_id: str, column: str):
|
|
|
45
50
|
return (value or _ALLOW_ALL).split(';') if isinstance(value, str) else _ALLOW_ALL
|
|
46
51
|
|
|
47
52
|
|
|
53
|
+
def _is_model_value_allowed(model: str, term_id: str, values: list, lookup_column: str):
|
|
54
|
+
allowed_values = _allowed_model_mapping(model, term_id, lookup_column)
|
|
55
|
+
return any([
|
|
56
|
+
_ALLOW_ALL in allowed_values,
|
|
57
|
+
len(values) == 0
|
|
58
|
+
]) or any([value in allowed_values for value in values])
|
|
59
|
+
|
|
60
|
+
|
|
48
61
|
def is_model_siteType_allowed(model: str, term_id: str, data: dict):
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return True if _ALLOW_ALL in allowed_values or not site_types else any([
|
|
52
|
-
(site_type in allowed_values) for site_type in site_types
|
|
53
|
-
])
|
|
62
|
+
values = _get_site_types(data)
|
|
63
|
+
return _is_model_value_allowed(model, term_id, values, 'siteTypesAllowed')
|
|
54
64
|
|
|
55
65
|
|
|
56
66
|
def is_model_product_id_allowed(model: str, term_id: str, data: dict):
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
values = _blank_node_term_values(data.get('products', []))
|
|
68
|
+
return _is_model_value_allowed(model, term_id, values, 'productTermIdsAllowed')
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def is_model_measurement_id_allowed(model: str, term_id: str, data: dict):
|
|
72
|
+
values = _blank_node_term_values(data.get('measurements', []))
|
|
73
|
+
return _is_model_value_allowed(model, term_id, values, 'measurementIdsAllowed')
|
|
64
74
|
|
|
65
75
|
|
|
66
76
|
@lru_cache()
|
|
@@ -73,68 +83,76 @@ def _allowed_mapping(term_id: str, column: str):
|
|
|
73
83
|
return (value or _ALLOW_ALL).split(';') if isinstance(value, str) else _ALLOW_ALL
|
|
74
84
|
|
|
75
85
|
|
|
86
|
+
def _is_term_value_allowed(term_id: str, values: list, lookup_column: str):
|
|
87
|
+
allowed_values = _allowed_mapping(term_id, lookup_column)
|
|
88
|
+
return any([
|
|
89
|
+
_ALLOW_ALL in allowed_values,
|
|
90
|
+
len(values) == 0
|
|
91
|
+
]) or any([value in allowed_values for value in values])
|
|
92
|
+
|
|
93
|
+
|
|
76
94
|
def is_siteType_allowed(data: dict, term_id: str):
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return True if _ALLOW_ALL in allowed_values or not site_types else any([
|
|
80
|
-
(site_type in allowed_values) for site_type in site_types
|
|
81
|
-
])
|
|
95
|
+
values = _get_site_types(data)
|
|
96
|
+
return _is_term_value_allowed(term_id, values, 'siteTypesAllowed')
|
|
82
97
|
|
|
83
98
|
|
|
84
99
|
def is_site_measurement_id_allowed(data: dict, term_id: str):
|
|
85
100
|
measurements = _get_site_measurements(data)
|
|
86
|
-
values =
|
|
87
|
-
|
|
88
|
-
return True if any([
|
|
89
|
-
_ALLOW_ALL in allowed_values,
|
|
90
|
-
len(values) == 0
|
|
91
|
-
]) else any([value in allowed_values for value in values])
|
|
101
|
+
values = _blank_node_term_values(measurements, key='@id')
|
|
102
|
+
return _is_term_value_allowed(term_id, values, 'siteMeasurementIdsAllowed')
|
|
92
103
|
|
|
93
104
|
|
|
94
105
|
def is_product_termType_allowed(data: dict, term_id: str):
|
|
95
106
|
products = data.get('products', [])
|
|
96
|
-
values =
|
|
97
|
-
|
|
98
|
-
return True if any([
|
|
99
|
-
_ALLOW_ALL in allowed_values,
|
|
100
|
-
len(values) == 0
|
|
101
|
-
]) else any([value in allowed_values for value in values])
|
|
107
|
+
values = _blank_node_term_values(products, key='termType')
|
|
108
|
+
return _is_term_value_allowed(term_id, values, 'productTermTypesAllowed')
|
|
102
109
|
|
|
103
110
|
|
|
104
111
|
def is_product_id_allowed(data: dict, term_id: str):
|
|
105
112
|
products = data.get('products', [])
|
|
106
|
-
values =
|
|
107
|
-
|
|
108
|
-
return True if any([
|
|
109
|
-
_ALLOW_ALL in allowed_values,
|
|
110
|
-
len(values) == 0
|
|
111
|
-
]) else any([value in allowed_values for value in values])
|
|
113
|
+
values = _blank_node_term_values(products, key='@id')
|
|
114
|
+
return _is_term_value_allowed(term_id, values, 'productTermIdsAllowed')
|
|
112
115
|
|
|
113
116
|
|
|
114
117
|
def is_input_termType_allowed(data: dict, term_id: str):
|
|
115
118
|
inputs = data.get('inputs', [])
|
|
116
|
-
values =
|
|
117
|
-
|
|
118
|
-
return True if any([
|
|
119
|
-
_ALLOW_ALL in allowed_values,
|
|
120
|
-
len(values) == 0
|
|
121
|
-
]) else any([value in allowed_values for value in values])
|
|
119
|
+
values = _blank_node_term_values(inputs, key='termType')
|
|
120
|
+
return _is_term_value_allowed(term_id, values, 'inputTermTypesAllowed')
|
|
122
121
|
|
|
123
122
|
|
|
124
123
|
def is_input_id_allowed(data: dict, term_id: str):
|
|
125
124
|
inputs = data.get('inputs', [])
|
|
126
|
-
values =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
125
|
+
values = _blank_node_term_values(inputs, key='@id')
|
|
126
|
+
return _is_term_value_allowed(term_id, values, 'inputTermIdsAllowed')
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def is_practice_termType_allowed(data: dict, term_id: str):
|
|
130
|
+
practices = data.get('practices', [])
|
|
131
|
+
values = _blank_node_term_values(practices, key='termType')
|
|
132
|
+
return _is_term_value_allowed(term_id, values, 'practiceTermTypesAllowed')
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def is_practice_id_allowed(data: dict, term_id: str):
|
|
136
|
+
practices = data.get('practices', [])
|
|
137
|
+
values = _blank_node_term_values(practices, key='@id')
|
|
138
|
+
return _is_term_value_allowed(term_id, values, 'practiceTermIdsAllowed')
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def is_transformation_termType_allowed(data: dict, term_id: str):
|
|
142
|
+
is_transformation = data.get('@type', data.get('type')) == SchemaType.TRANSFORMATION.value
|
|
143
|
+
values = non_empty_list([data.get('term', {}).get('termType')])
|
|
144
|
+
return not is_transformation or _is_term_value_allowed(term_id, values, 'transformationTermTypesAllowed')
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def is_transformation_id_allowed(data: dict, term_id: str):
|
|
148
|
+
is_transformation = data.get('@type', data.get('type')) == SchemaType.TRANSFORMATION.value
|
|
149
|
+
values = non_empty_list([data.get('term', {}).get('@id')])
|
|
150
|
+
return not is_transformation or _is_term_value_allowed(term_id, values, 'transformationTermIdsAllowed')
|
|
132
151
|
|
|
133
152
|
|
|
134
153
|
def is_node_type_allowed(data: dict, term_id: str):
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return True if _ALLOW_ALL in allowed_types or not node_type else node_type in allowed_types
|
|
154
|
+
values = non_empty_list([data.get('@type', data.get('type'))])
|
|
155
|
+
return _is_term_value_allowed(term_id, values, 'typesAllowed')
|
|
138
156
|
|
|
139
157
|
|
|
140
158
|
@lru_cache()
|
hestia_earth/utils/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = '0.15.
|
|
1
|
+
VERSION = '0.15.16'
|
|
@@ -6,9 +6,9 @@ hestia_earth/utils/calculation_status.py,sha256=X7lbgVMD9luH1gj9lEcxd3_P2-u7e8ZP
|
|
|
6
6
|
hestia_earth/utils/cycle.py,sha256=rFLRL9X4KQ1UrE6fEPA_gV8KmwzrZpR3Ce56zg41lRk,1326
|
|
7
7
|
hestia_earth/utils/date.py,sha256=SPQ69uxHiv1o3BqIkBKkM5XX_CmS20CB7g6u2rhsdh8,1807
|
|
8
8
|
hestia_earth/utils/descriptive_stats.py,sha256=EMVwFvg2OnZgKRAfireAoWY2EbrSvqR0V0bK9B53p28,1583
|
|
9
|
-
hestia_earth/utils/emission.py,sha256=
|
|
9
|
+
hestia_earth/utils/emission.py,sha256=BhBitooLTxZSh82S982v2QfPxxTF1kmGClG_uHyWdz4,1981
|
|
10
10
|
hestia_earth/utils/lookup.py,sha256=0RLqy3HPzkbhkRaO7fYoHU0jKhAYzI6QHMptMEbqTlg,10344
|
|
11
|
-
hestia_earth/utils/lookup_utils.py,sha256=
|
|
11
|
+
hestia_earth/utils/lookup_utils.py,sha256=_k3RZ1pK-gw7jq8wn9HrPWfDl4FlEWRb8bXmgaARu0w,6716
|
|
12
12
|
hestia_earth/utils/model.py,sha256=uUcrF07XmBzqLni8VSaP0HoebJnQ57kk0EOmhwYMbfI,4637
|
|
13
13
|
hestia_earth/utils/pipeline.py,sha256=O-6DPtK0U1lJ51LFGa1gM6pjkBJUfxOjNjY8LxQPXV0,9588
|
|
14
14
|
hestia_earth/utils/request.py,sha256=bu7hkWKmFdXl2_Feawiam_x32whlclA9oP0asJyC69k,626
|
|
@@ -16,7 +16,7 @@ hestia_earth/utils/stats.py,sha256=4t3op10xDJbGxWJEY1Jtyl302PYWyMFwLpsSkMlzQn8,3
|
|
|
16
16
|
hestia_earth/utils/table.py,sha256=RrTt-KF_QzjKiCpaAueoG6La1FG-Iusxw5NMDpoRBpQ,2861
|
|
17
17
|
hestia_earth/utils/term.py,sha256=6LiUSc6KX3IOkfWF6fYkQ2tENCO8ENljcdDypxU6WtA,1060
|
|
18
18
|
hestia_earth/utils/tools.py,sha256=9GaUJwxL-CTzEOGnRFkUQDVFelPevQSxXrf25vssCVo,4990
|
|
19
|
-
hestia_earth/utils/version.py,sha256=
|
|
19
|
+
hestia_earth/utils/version.py,sha256=JDQ_516e1l28tU9cgTLDX-12-rAvR8X42sQ5QDTbtTU,20
|
|
20
20
|
hestia_earth/utils/pivot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
21
|
hestia_earth/utils/pivot/_shared.py,sha256=JnyIOzpans45DE2hSa9-4yvNhq8t08lx1IAWGJi6WPQ,1397
|
|
22
22
|
hestia_earth/utils/pivot/pivot_csv.py,sha256=zaiDcig4I5lVSHPZ-2bXKKBcIRrayA0GUaw0c8H3D-w,12371
|
|
@@ -26,12 +26,12 @@ hestia_earth/utils/storage/_azure_client.py,sha256=sevCZni04eknMql2DgUsWG23f7u0K
|
|
|
26
26
|
hestia_earth/utils/storage/_local_client.py,sha256=IbzziUKY0QS3ybHFfgEpELqvafa7hQnZ-DdGdjQuypE,515
|
|
27
27
|
hestia_earth/utils/storage/_s3_client.py,sha256=B2yTsf-VfHcRLCKTMes4S_nCXxrZad9umyZx3b5Pu_c,3181
|
|
28
28
|
hestia_earth/utils/storage/_sns_client.py,sha256=LowUatj78Egu6_Id6Rr7hZjfZx1WguS3lozB3yAwSps,347
|
|
29
|
-
hestia_earth_utils-0.15.
|
|
30
|
-
hestia_earth_utils-0.15.
|
|
29
|
+
hestia_earth_utils-0.15.16.data/scripts/hestia-format-upload,sha256=IhLAHHPJqRgUcht-M_EUEsRMbRbMfshig07o488zscM,703
|
|
30
|
+
hestia_earth_utils-0.15.16.data/scripts/hestia-pivot-csv,sha256=0YBuGuyPO8rytod6iwWEKiQdSlr9JLuD001k6U5t6no,1163
|
|
31
31
|
tests/pivot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
32
|
tests/pivot/test_pivot_csv.py,sha256=aYni7o3QDPSgtVxVCspEetotgpYHY7Lz5VHf-DR89gw,8131
|
|
33
33
|
tests/pivot/test_pivot_json.py,sha256=UYTAN4AZhzVicIYsU1A2VgJcctUXohjHppg6s-pqwcg,8287
|
|
34
|
-
hestia_earth_utils-0.15.
|
|
35
|
-
hestia_earth_utils-0.15.
|
|
36
|
-
hestia_earth_utils-0.15.
|
|
37
|
-
hestia_earth_utils-0.15.
|
|
34
|
+
hestia_earth_utils-0.15.16.dist-info/METADATA,sha256=nTJS2R1fi2c9Lz3R7zvRuf8HKG1n7K72KoDek_C9LpU,1758
|
|
35
|
+
hestia_earth_utils-0.15.16.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
36
|
+
hestia_earth_utils-0.15.16.dist-info/top_level.txt,sha256=1dqA9TqpOLTEgpqa-YBsmbCmmNU1y56AtfFGEceZ2A0,19
|
|
37
|
+
hestia_earth_utils-0.15.16.dist-info/RECORD,,
|
{hestia_earth_utils-0.15.14.data → hestia_earth_utils-0.15.16.data}/scripts/hestia-format-upload
RENAMED
|
File without changes
|
{hestia_earth_utils-0.15.14.data → hestia_earth_utils-0.15.16.data}/scripts/hestia-pivot-csv
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|