hestia-earth-utils 0.16.13__tar.gz → 0.16.14__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.13/hestia_earth_utils.egg-info → hestia_earth_utils-0.16.14}/PKG-INFO +1 -1
- hestia_earth_utils-0.16.14/hestia_earth/utils/pivot/_shared.py +110 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/pivot/pivot_csv.py +3 -22
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/pivot/pivot_json.py +55 -21
- hestia_earth_utils-0.16.14/hestia_earth/utils/version.py +1 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14/hestia_earth_utils.egg-info}/PKG-INFO +1 -1
- hestia_earth_utils-0.16.13/hestia_earth/utils/pivot/_shared.py +0 -55
- hestia_earth_utils-0.16.13/hestia_earth/utils/version.py +0 -1
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/MANIFEST.in +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/README.md +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/bin/hestia-format-upload +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/bin/hestia-pivot-csv +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/__init__.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/api.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/blank_node.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/calculation_status.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/cycle.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/date.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/descriptive_stats.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/emission.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/lookup.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/lookup_utils.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/model.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/pipeline.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/pivot/__init__.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/request.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/stats.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/storage/__init__.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/storage/_azure_client.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/storage/_local_client.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/storage/_s3_client.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/storage/_sns_client.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/table.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/term.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/tools.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth_utils.egg-info/SOURCES.txt +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth_utils.egg-info/dependency_links.txt +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth_utils.egg-info/requires.txt +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth_utils.egg-info/top_level.txt +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/setup.cfg +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/setup.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_api.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_blank_node.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_calculation_status.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_cycle.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_date.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_descriptive_stats.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_emission.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_lookup.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_lookup_utils.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_model.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_pipeline.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_request.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_stats.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_table.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_term.py +0 -0
- {hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/tests/test_tools.py +0 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import numpy as np
|
|
3
|
+
import pandas as pd
|
|
4
|
+
from hestia_earth.schema import SCHEMA_TYPES, NODE_TYPES, EmissionMethodTier
|
|
5
|
+
from flatten_json import flatten as flatten_json
|
|
6
|
+
|
|
7
|
+
from ..tools import list_sum
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
EXCLUDE_FIELDS = ["@type", "type", "@context"]
|
|
11
|
+
EXCLUDE_PRIVATE_FIELDS = [
|
|
12
|
+
"added",
|
|
13
|
+
"addedVersion",
|
|
14
|
+
"updated",
|
|
15
|
+
"updatedVersion",
|
|
16
|
+
"aggregatedVersion",
|
|
17
|
+
"_cache",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# assuming column labels always camelCase
|
|
22
|
+
def _get_node_type_label(node_type):
|
|
23
|
+
return node_type[0].lower() + node_type[1:]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _get_node_type_from_label(node_type):
|
|
27
|
+
return node_type[0].upper() + node_type[1:]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _is_blank_node(data: dict):
|
|
31
|
+
node_type = data.get("@type") or data.get("type")
|
|
32
|
+
return node_type in SCHEMA_TYPES and node_type not in NODE_TYPES
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _with_csv_formatting(dct):
|
|
36
|
+
"""
|
|
37
|
+
Use as object_hook when parsing a JSON node: json.loads(node, object_hook=_with_csv_formatting).
|
|
38
|
+
Ensures parsed JSON has field values formatted according to hestia csv conventions.
|
|
39
|
+
"""
|
|
40
|
+
if "boundary" in dct:
|
|
41
|
+
dct["boundary"] = json.dumps(dct["boundary"])
|
|
42
|
+
for key, value in dct.items():
|
|
43
|
+
if _is_scalar_list(value):
|
|
44
|
+
dct[key] = ";".join([str(el) for el in value])
|
|
45
|
+
return dct
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _is_scalar_list(value):
|
|
49
|
+
if not isinstance(value, list):
|
|
50
|
+
return False
|
|
51
|
+
all_scalar = True
|
|
52
|
+
for element in value:
|
|
53
|
+
if not np.isscalar(element):
|
|
54
|
+
all_scalar = False
|
|
55
|
+
break
|
|
56
|
+
return all_scalar
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _filter_not_relevant(blank_node: dict):
|
|
60
|
+
return blank_node.get("methodTier") != EmissionMethodTier.NOT_RELEVANT.value
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _filter_emissions_not_relevant(node: dict):
|
|
64
|
+
"""
|
|
65
|
+
Ignore all emissions where `methodTier=not relevant` to save space.
|
|
66
|
+
"""
|
|
67
|
+
return node | (
|
|
68
|
+
{
|
|
69
|
+
key: list(filter(_filter_not_relevant, node[key]))
|
|
70
|
+
for key in ["emissions", "emissionsResourceUse"]
|
|
71
|
+
if key in node
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _filter_zero_value(blank_node: dict):
|
|
77
|
+
value = blank_node.get("value")
|
|
78
|
+
value = (
|
|
79
|
+
list_sum(blank_node.get("value"), default=-1)
|
|
80
|
+
if isinstance(value, list)
|
|
81
|
+
else value
|
|
82
|
+
)
|
|
83
|
+
return value != 0
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _filter_zero_values(node: dict):
|
|
87
|
+
"""
|
|
88
|
+
Ignore all blank nodes where `value=0` to save space.
|
|
89
|
+
"""
|
|
90
|
+
return node | (
|
|
91
|
+
{
|
|
92
|
+
key: list(filter(_filter_zero_value, value))
|
|
93
|
+
for key, value in node.items()
|
|
94
|
+
if isinstance(value, list)
|
|
95
|
+
and isinstance(value[0], dict)
|
|
96
|
+
and _is_blank_node(value[0])
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def nodes_to_df(nodes: list[dict]):
|
|
102
|
+
nodes_flattened = [
|
|
103
|
+
flatten_json(
|
|
104
|
+
dict([(_get_node_type_label(node.get("@type", node.get("type"))), node)]),
|
|
105
|
+
".",
|
|
106
|
+
)
|
|
107
|
+
for node in nodes
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
return pd.json_normalize(nodes_flattened)
|
{hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/pivot/pivot_csv.py
RENAMED
|
@@ -5,7 +5,6 @@ import numpy as np
|
|
|
5
5
|
import pandas as pd
|
|
6
6
|
from hestia_earth.schema import UNIQUENESS_FIELDS, Term, NODE_TYPES
|
|
7
7
|
from hestia_earth.schema.utils.sort import get_sort_key, SORT_CONFIG
|
|
8
|
-
from flatten_json import flatten as flatten_json
|
|
9
8
|
|
|
10
9
|
# __package__ = "hestia_earth.utils" # required to run interactively in vscode
|
|
11
10
|
from ..api import find_term_ids_by_names
|
|
@@ -14,6 +13,9 @@ from ._shared import (
|
|
|
14
13
|
EXCLUDE_PRIVATE_FIELDS,
|
|
15
14
|
_with_csv_formatting,
|
|
16
15
|
_filter_emissions_not_relevant,
|
|
16
|
+
_get_node_type_label,
|
|
17
|
+
_get_node_type_from_label,
|
|
18
|
+
nodes_to_df,
|
|
17
19
|
)
|
|
18
20
|
|
|
19
21
|
|
|
@@ -36,15 +38,6 @@ def _get_blank_node_uniqueness_fields():
|
|
|
36
38
|
BLANK_NODE_UNIQUENESS_FIELDS = _get_blank_node_uniqueness_fields()
|
|
37
39
|
|
|
38
40
|
|
|
39
|
-
# assuming column labels always camelCase
|
|
40
|
-
def _get_node_type_label(node_type):
|
|
41
|
-
return node_type[0].lower() + node_type[1:]
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def _get_node_type_from_label(node_type):
|
|
45
|
-
return node_type[0].upper() + node_type[1:]
|
|
46
|
-
|
|
47
|
-
|
|
48
41
|
def _get_names(df):
|
|
49
42
|
names = []
|
|
50
43
|
for node_type, array_fields in BLANK_NODE_UNIQUENESS_FIELDS.items():
|
|
@@ -283,18 +276,6 @@ def _format_and_pivot(df_in):
|
|
|
283
276
|
return df_out
|
|
284
277
|
|
|
285
278
|
|
|
286
|
-
def nodes_to_df(nodes: list[dict]):
|
|
287
|
-
nodes_flattened = [
|
|
288
|
-
flatten_json(
|
|
289
|
-
dict([(_get_node_type_label(node.get("@type", node.get("type"))), node)]),
|
|
290
|
-
".",
|
|
291
|
-
)
|
|
292
|
-
for node in nodes
|
|
293
|
-
]
|
|
294
|
-
|
|
295
|
-
return pd.json_normalize(nodes_flattened)
|
|
296
|
-
|
|
297
|
-
|
|
298
279
|
def pivot_nodes(nodes: list[dict]):
|
|
299
280
|
"""
|
|
300
281
|
Pivot array of nodes in dict format (e.g under the 'nodes' key of a .hestia file)
|
{hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/pivot/pivot_json.py
RENAMED
|
@@ -11,6 +11,7 @@ from ._shared import (
|
|
|
11
11
|
EXCLUDE_PRIVATE_FIELDS,
|
|
12
12
|
_with_csv_formatting,
|
|
13
13
|
_filter_emissions_not_relevant,
|
|
14
|
+
_filter_zero_values,
|
|
14
15
|
)
|
|
15
16
|
|
|
16
17
|
pivot_exclude_fields = Term().fields
|
|
@@ -22,6 +23,8 @@ term_exclude_fields = Term().fields
|
|
|
22
23
|
del term_exclude_fields["name"]
|
|
23
24
|
term_exclude_fields.update({k: "" for k in EXCLUDE_PRIVATE_FIELDS})
|
|
24
25
|
|
|
26
|
+
include_all_unique_keys = ["emissions", "emissionsResourceUse"]
|
|
27
|
+
|
|
25
28
|
# Treat properties uniqueness fields as special case for now
|
|
26
29
|
PROPERTIES_VIRTUAL_UNIQUENESS_FIELD = "propertyValues"
|
|
27
30
|
ADAPTED_UNIQUENESS_FIELDS = deepcopy(UNIQUENESS_FIELDS)
|
|
@@ -90,6 +93,7 @@ def _do_pivot(node, parent_node_type=None, parent_field=None, level=0): # noqa:
|
|
|
90
93
|
|
|
91
94
|
# print('\n', level, 'fields_to_pivot', fields_to_pivot)
|
|
92
95
|
for field, uniqueness_fields in fields_to_pivot:
|
|
96
|
+
include_all_unique_fields = field in include_all_unique_keys
|
|
93
97
|
# print('\nbefore processing node field', level, field, node[field], '\n')
|
|
94
98
|
# Compress lists of 'Node' nodes to dict with single @id key.
|
|
95
99
|
# The compressed field matches uniqueness fields like cycle.emissions.inputs.@id.
|
|
@@ -155,14 +159,13 @@ def _do_pivot(node, parent_node_type=None, parent_field=None, level=0): # noqa:
|
|
|
155
159
|
del term_data["combined_fields"][id_key]
|
|
156
160
|
# print('combined_fields', field, term_id, term_data['combined_fields'], '\n')
|
|
157
161
|
fields_to_include = {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
for idx in indexes
|
|
162
|
+
k: include_all_unique_fields
|
|
163
|
+
or any(
|
|
164
|
+
by_idx[idx].get(k) != by_idx[indexes[0]].get(k) for idx in indexes
|
|
161
165
|
)
|
|
162
|
-
for
|
|
163
|
-
if
|
|
164
|
-
or
|
|
165
|
-
and field.split(".")[-1] not in pivot_exclude_fields
|
|
166
|
+
for k in term_data["combined_fields"].keys()
|
|
167
|
+
if k in uniqueness_fields
|
|
168
|
+
or (k != "value" and k.split(".")[-1] not in pivot_exclude_fields)
|
|
166
169
|
}
|
|
167
170
|
# print('fields_to_include', level, field, term_id, fields_to_include, '\n')
|
|
168
171
|
for idx in indexes:
|
|
@@ -179,19 +182,23 @@ def _do_pivot(node, parent_node_type=None, parent_field=None, level=0): # noqa:
|
|
|
179
182
|
)
|
|
180
183
|
]
|
|
181
184
|
# print('distingishing_field_fields', level, field, term_id, distingishing_field_fields, '\n')
|
|
182
|
-
unanimous_fields = {
|
|
183
|
-
field: term_data["combined_fields"][field]
|
|
184
|
-
for field, not_unanimous in fields_to_include.items()
|
|
185
|
-
if field not in distingishing_field_fields
|
|
186
|
-
and not not_unanimous
|
|
187
|
-
and field is not PROPERTIES_VIRTUAL_UNIQUENESS_FIELD
|
|
188
|
-
}
|
|
189
185
|
# print('unanimous_fields', level, field, term_id, unanimous_fields, '\n')
|
|
186
|
+
unanimous_fields = (
|
|
187
|
+
{}
|
|
188
|
+
if include_all_unique_fields
|
|
189
|
+
else {
|
|
190
|
+
field: term_data["combined_fields"][field]
|
|
191
|
+
for field, not_unanimous in fields_to_include.items()
|
|
192
|
+
if field not in distingishing_field_fields
|
|
193
|
+
and not not_unanimous
|
|
194
|
+
and field is not PROPERTIES_VIRTUAL_UNIQUENESS_FIELD
|
|
195
|
+
}
|
|
196
|
+
)
|
|
190
197
|
differentiated_fields = {
|
|
191
198
|
field: term[field]
|
|
192
199
|
for field, not_unanimous in fields_to_include.items()
|
|
193
200
|
if field not in distingishing_field_fields
|
|
194
|
-
and not_unanimous
|
|
201
|
+
and (include_all_unique_fields or not_unanimous)
|
|
195
202
|
and field in term
|
|
196
203
|
}
|
|
197
204
|
# print('differentiated_fields', level, field, term_id, differentiated_fields, '\n')
|
|
@@ -223,19 +230,35 @@ def _do_pivot(node, parent_node_type=None, parent_field=None, level=0): # noqa:
|
|
|
223
230
|
return pivoted_node
|
|
224
231
|
|
|
225
232
|
|
|
226
|
-
def pivot_node(
|
|
233
|
+
def pivot_node(
|
|
234
|
+
node: dict,
|
|
235
|
+
include_emissions_not_relevant: bool = False,
|
|
236
|
+
include_zero_values: bool = True,
|
|
237
|
+
):
|
|
227
238
|
"""
|
|
228
239
|
Pivot single node in dict format parsed with object_hook=_with_csv_formatting
|
|
229
240
|
"""
|
|
230
|
-
|
|
241
|
+
node = (
|
|
242
|
+
node if include_emissions_not_relevant else _filter_emissions_not_relevant(node)
|
|
243
|
+
)
|
|
244
|
+
node = node if include_zero_values else _filter_zero_values(node)
|
|
245
|
+
return _do_pivot(node)
|
|
231
246
|
|
|
232
247
|
|
|
233
|
-
def pivot_json_node(
|
|
248
|
+
def pivot_json_node(
|
|
249
|
+
json_node: str,
|
|
250
|
+
include_emissions_not_relevant: bool = False,
|
|
251
|
+
include_zero_values: bool = True,
|
|
252
|
+
):
|
|
234
253
|
"""
|
|
235
254
|
Pivot single schema-compliant unparsed json string node
|
|
236
255
|
"""
|
|
237
256
|
node = json.loads(json_node, object_hook=_with_csv_formatting)
|
|
238
|
-
return pivot_node(
|
|
257
|
+
return pivot_node(
|
|
258
|
+
node,
|
|
259
|
+
include_emissions_not_relevant=include_emissions_not_relevant,
|
|
260
|
+
include_zero_values=include_zero_values,
|
|
261
|
+
)
|
|
239
262
|
|
|
240
263
|
|
|
241
264
|
def pivot_hestia_file(hestia_file: str):
|
|
@@ -246,8 +269,19 @@ def pivot_hestia_file(hestia_file: str):
|
|
|
246
269
|
return pivot_nodes(parsed.get("nodes", []))
|
|
247
270
|
|
|
248
271
|
|
|
249
|
-
def pivot_nodes(
|
|
272
|
+
def pivot_nodes(
|
|
273
|
+
nodes: list[dict],
|
|
274
|
+
include_emissions_not_relevant: bool = False,
|
|
275
|
+
include_zero_values: bool = True,
|
|
276
|
+
):
|
|
250
277
|
"""
|
|
251
278
|
Pivot multiple nodes in dict format parsed with object_hook=_with_csv_formatting
|
|
252
279
|
"""
|
|
253
|
-
return [
|
|
280
|
+
return [
|
|
281
|
+
pivot_node(
|
|
282
|
+
node,
|
|
283
|
+
include_emissions_not_relevant=include_emissions_not_relevant,
|
|
284
|
+
include_zero_values=include_zero_values,
|
|
285
|
+
)
|
|
286
|
+
for node in nodes
|
|
287
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = "0.16.14"
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import numpy as np
|
|
3
|
-
from hestia_earth.schema import EmissionMethodTier
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
EXCLUDE_FIELDS = ["@type", "type", "@context"]
|
|
7
|
-
EXCLUDE_PRIVATE_FIELDS = [
|
|
8
|
-
"added",
|
|
9
|
-
"addedVersion",
|
|
10
|
-
"updated",
|
|
11
|
-
"updatedVersion",
|
|
12
|
-
"aggregatedVersion",
|
|
13
|
-
"_cache",
|
|
14
|
-
]
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def _with_csv_formatting(dct):
|
|
18
|
-
"""
|
|
19
|
-
Use as object_hook when parsing a JSON node: json.loads(node, object_hook=_with_csv_formatting).
|
|
20
|
-
Ensures parsed JSON has field values formatted according to hestia csv conventions.
|
|
21
|
-
"""
|
|
22
|
-
if "boundary" in dct:
|
|
23
|
-
dct["boundary"] = json.dumps(dct["boundary"])
|
|
24
|
-
for key, value in dct.items():
|
|
25
|
-
if _is_scalar_list(value):
|
|
26
|
-
dct[key] = ";".join([str(el) for el in value])
|
|
27
|
-
return dct
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def _is_scalar_list(value):
|
|
31
|
-
if not isinstance(value, list):
|
|
32
|
-
return False
|
|
33
|
-
all_scalar = True
|
|
34
|
-
for element in value:
|
|
35
|
-
if not np.isscalar(element):
|
|
36
|
-
all_scalar = False
|
|
37
|
-
break
|
|
38
|
-
return all_scalar
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def _filter_not_relevant(blank_node: dict):
|
|
42
|
-
return blank_node.get("methodTier") != EmissionMethodTier.NOT_RELEVANT.value
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def _filter_emissions_not_relevant(node: dict):
|
|
46
|
-
"""
|
|
47
|
-
Ignore all emissions where `methodTier=not relevant` so save space.
|
|
48
|
-
"""
|
|
49
|
-
return node | (
|
|
50
|
-
{
|
|
51
|
-
key: list(filter(_filter_not_relevant, node[key]))
|
|
52
|
-
for key in ["emissions", "emissionsResourceUse"]
|
|
53
|
-
if key in node
|
|
54
|
-
}
|
|
55
|
-
)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
VERSION = "0.16.13"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/calculation_status.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/descriptive_stats.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/lookup_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/pivot/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/storage/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth/utils/storage/_s3_client.py
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/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.13 → hestia_earth_utils-0.16.14}/hestia_earth_utils.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/hestia_earth_utils.egg-info/requires.txt
RENAMED
|
File without changes
|
{hestia_earth_utils-0.16.13 → hestia_earth_utils-0.16.14}/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
|
|
File without changes
|
|
File without changes
|