hestia-earth-utils 0.16.9__py3-none-any.whl → 0.16.10__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/api.py +78 -36
- hestia_earth/utils/blank_node.py +101 -60
- hestia_earth/utils/calculation_status.py +45 -35
- hestia_earth/utils/cycle.py +7 -7
- hestia_earth/utils/date.py +7 -2
- hestia_earth/utils/descriptive_stats.py +10 -6
- hestia_earth/utils/emission.py +26 -15
- hestia_earth/utils/lookup.py +62 -28
- hestia_earth/utils/lookup_utils.py +89 -63
- hestia_earth/utils/model.py +45 -40
- hestia_earth/utils/pipeline.py +179 -90
- hestia_earth/utils/pivot/_shared.py +16 -12
- hestia_earth/utils/pivot/pivot_csv.py +35 -18
- hestia_earth/utils/pivot/pivot_json.py +34 -18
- hestia_earth/utils/request.py +17 -6
- hestia_earth/utils/stats.py +89 -68
- hestia_earth/utils/storage/_azure_client.py +17 -6
- hestia_earth/utils/storage/_local_client.py +8 -3
- hestia_earth/utils/storage/_s3_client.py +27 -22
- hestia_earth/utils/storage/_sns_client.py +7 -2
- hestia_earth/utils/term.py +5 -5
- hestia_earth/utils/tools.py +50 -21
- hestia_earth/utils/version.py +1 -1
- {hestia_earth_utils-0.16.9.dist-info → hestia_earth_utils-0.16.10.dist-info}/METADATA +1 -1
- hestia_earth_utils-0.16.10.dist-info/RECORD +33 -0
- hestia_earth_utils-0.16.9.dist-info/RECORD +0 -33
- {hestia_earth_utils-0.16.9.data → hestia_earth_utils-0.16.10.data}/scripts/hestia-format-upload +0 -0
- {hestia_earth_utils-0.16.9.data → hestia_earth_utils-0.16.10.data}/scripts/hestia-pivot-csv +0 -0
- {hestia_earth_utils-0.16.9.dist-info → hestia_earth_utils-0.16.10.dist-info}/WHEEL +0 -0
- {hestia_earth_utils-0.16.9.dist-info → hestia_earth_utils-0.16.10.dist-info}/top_level.txt +0 -0
hestia_earth/utils/tools.py
CHANGED
|
@@ -8,7 +8,9 @@ from hestia_earth.schema import NodeType
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def to_precision(number: float, digits: int = 3) -> float:
|
|
11
|
-
return
|
|
11
|
+
return (
|
|
12
|
+
0 if not number else round(number, digits - int(floor(log10(abs(number)))) - 1)
|
|
13
|
+
)
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
def non_empty_value(value) -> bool:
|
|
@@ -25,12 +27,14 @@ def non_empty_value(value) -> bool:
|
|
|
25
27
|
bool
|
|
26
28
|
True if the value is not en empty string or an empty list.
|
|
27
29
|
"""
|
|
28
|
-
return all(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
return all(
|
|
31
|
+
[
|
|
32
|
+
value != "",
|
|
33
|
+
value is not None,
|
|
34
|
+
not isinstance(value, list) or value != [],
|
|
35
|
+
not isinstance(value, dict) or value != {},
|
|
36
|
+
]
|
|
37
|
+
)
|
|
34
38
|
|
|
35
39
|
|
|
36
40
|
def non_empty_list(values: list) -> list:
|
|
@@ -66,7 +70,10 @@ def is_node_of(node_type) -> bool:
|
|
|
66
70
|
bool
|
|
67
71
|
True if matches type.
|
|
68
72
|
"""
|
|
69
|
-
return
|
|
73
|
+
return (
|
|
74
|
+
lambda node: isinstance(node, dict)
|
|
75
|
+
and node.get("type", node.get("@type")) == node_type.value
|
|
76
|
+
)
|
|
70
77
|
|
|
71
78
|
|
|
72
79
|
def is_term(node: dict) -> bool:
|
|
@@ -147,10 +154,12 @@ def is_number(value):
|
|
|
147
154
|
"""
|
|
148
155
|
Return `True` if the value is either an `int` or a `float`.
|
|
149
156
|
"""
|
|
150
|
-
return all(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
157
|
+
return all(
|
|
158
|
+
[
|
|
159
|
+
not isinstance(value, bool), # True is apparently considered an `int`
|
|
160
|
+
any([isinstance(value, int), isinstance(value, float)]),
|
|
161
|
+
]
|
|
162
|
+
)
|
|
154
163
|
|
|
155
164
|
|
|
156
165
|
def is_boolean(v):
|
|
@@ -176,7 +185,11 @@ def list_average(value: list, default=0):
|
|
|
176
185
|
float
|
|
177
186
|
The average of the values.
|
|
178
187
|
"""
|
|
179
|
-
values =
|
|
188
|
+
values = (
|
|
189
|
+
non_empty_list(value)
|
|
190
|
+
if value and isinstance(value, list) and all(map(is_number, value))
|
|
191
|
+
else []
|
|
192
|
+
)
|
|
180
193
|
return mean(values) if values else default
|
|
181
194
|
|
|
182
195
|
|
|
@@ -196,7 +209,11 @@ def list_sum(value: list, default=0):
|
|
|
196
209
|
float
|
|
197
210
|
The sum of the values.
|
|
198
211
|
"""
|
|
199
|
-
values =
|
|
212
|
+
values = (
|
|
213
|
+
non_empty_list(value)
|
|
214
|
+
if value and isinstance(value, list) and all(map(is_number, value))
|
|
215
|
+
else []
|
|
216
|
+
)
|
|
200
217
|
return sum(values) if values else default
|
|
201
218
|
|
|
202
219
|
|
|
@@ -214,22 +231,34 @@ def flatten(values: list):
|
|
|
214
231
|
list
|
|
215
232
|
A list of single values.
|
|
216
233
|
"""
|
|
217
|
-
return list(
|
|
234
|
+
return list(
|
|
235
|
+
reduce(lambda x, y: x + (y if isinstance(y, list) else [y]), values, [])
|
|
236
|
+
)
|
|
218
237
|
|
|
219
238
|
|
|
220
239
|
def _get_by_key(x, y):
|
|
221
|
-
return
|
|
222
|
-
x
|
|
240
|
+
return (
|
|
241
|
+
x
|
|
242
|
+
if x is None
|
|
243
|
+
else (
|
|
244
|
+
x.get(y)
|
|
245
|
+
if isinstance(x, dict)
|
|
246
|
+
else list(map(lambda v: get_dict_key(v, y), x))
|
|
247
|
+
)
|
|
223
248
|
)
|
|
224
249
|
|
|
225
250
|
|
|
226
|
-
def get_dict_key(value: dict, key: str):
|
|
251
|
+
def get_dict_key(value: dict, key: str):
|
|
252
|
+
return reduce(lambda x, y: _get_by_key(x, y), key.split("."), value)
|
|
227
253
|
|
|
228
254
|
|
|
229
|
-
def omit(values: dict, keys: list) -> dict:
|
|
255
|
+
def omit(values: dict, keys: list) -> dict:
|
|
256
|
+
return {k: v for k, v in values.items() if k not in keys}
|
|
230
257
|
|
|
231
258
|
|
|
232
|
-
def pick(value: dict, keys: list) -> dict:
|
|
259
|
+
def pick(value: dict, keys: list) -> dict:
|
|
260
|
+
return {k: v for k, v in value.items() if k in keys}
|
|
233
261
|
|
|
234
262
|
|
|
235
|
-
def unique_values(values: list, key: str =
|
|
263
|
+
def unique_values(values: list, key: str = "@id"):
|
|
264
|
+
return list({v[key]: v for v in values}.values())
|
hestia_earth/utils/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION =
|
|
1
|
+
VERSION = "0.16.10"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
hestia_earth/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
hestia_earth/utils/api.py,sha256=b6g87ylAgdWvwPlDeZDv74UGfXVe1KFXap5-Rv5daSE,9929
|
|
3
|
+
hestia_earth/utils/blank_node.py,sha256=de-Vu0wEsm5xl6XjJREsNTRRuPSHTsXRkg2KSBVa66o,7889
|
|
4
|
+
hestia_earth/utils/calculation_status.py,sha256=f5b05cEFXMfFI1clirIt7v3Y9H2Nja66GYv1NCyZjf0,2381
|
|
5
|
+
hestia_earth/utils/cycle.py,sha256=oo0CesLMblL8ewI4s7eXdyNjr9R9df4Vyr0iRXCYFu4,1326
|
|
6
|
+
hestia_earth/utils/date.py,sha256=IVqZjIJda8lUbDZkEbaNN5FBQoTHdNudgKXpngm-2a4,1847
|
|
7
|
+
hestia_earth/utils/descriptive_stats.py,sha256=YvDI6EWCcZWw8yCxYhqyzMCDqCu2X8DjvygmMK_AVvc,1633
|
|
8
|
+
hestia_earth/utils/emission.py,sha256=rHHf5vwe-RxTOaOJ9N0MuyJOLpDnPjjxv6MHYSpPgcU,2165
|
|
9
|
+
hestia_earth/utils/lookup.py,sha256=SArKqjqs_Yt5cC6TIk12WVQNToun2spZ_iNUm4fX9FA,8274
|
|
10
|
+
hestia_earth/utils/lookup_utils.py,sha256=cjYIFSQpcdSCoHqCoz3f5Odkpv_2j5aGn0COOIdz3hg,6948
|
|
11
|
+
hestia_earth/utils/model.py,sha256=YzQ4Cs3HBlhLGNDvrfv2pM_FrNZhZkg9h7JKIH3CHFE,4626
|
|
12
|
+
hestia_earth/utils/pipeline.py,sha256=LYxPXhuSWTwmsLRz_nl_JscFgGYhUAbNQx4Zla5_REM,10292
|
|
13
|
+
hestia_earth/utils/request.py,sha256=EfitmS13abPxfl5gSAOyHRUYhk4R2Rfv94fF9lvOT00,723
|
|
14
|
+
hestia_earth/utils/stats.py,sha256=vTNyKcMKmX0DoodM9QEG7HF8qm2Wf-4ckMWQFWZ1VgE,34729
|
|
15
|
+
hestia_earth/utils/table.py,sha256=MOJDo5fQPRDogAty_UXbO9-EXFwz97m0f7--mOM17lQ,2363
|
|
16
|
+
hestia_earth/utils/term.py,sha256=aBVYuYv55nPqJPyt5mN4Fz652s_1hwUPckNUZX0pMP8,1064
|
|
17
|
+
hestia_earth/utils/tools.py,sha256=FPzevMJQPBEOWS68em4CuDqJNjmRkTeyF_h2wf-r39U,5271
|
|
18
|
+
hestia_earth/utils/version.py,sha256=m9xLiUwc2sMV2VdfuWN3MgvHe4zrkjcBJgwtBc1YC-E,20
|
|
19
|
+
hestia_earth/utils/pivot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
+
hestia_earth/utils/pivot/_shared.py,sha256=8-AZAAitXU53BYpOFFGnuCy5VBSphyClgIqGU-kg6CM,1436
|
|
21
|
+
hestia_earth/utils/pivot/pivot_csv.py,sha256=TtePpo9L_GKISpQMW9dwjBv2tHHE822rb-j6_bflVOA,12251
|
|
22
|
+
hestia_earth/utils/pivot/pivot_json.py,sha256=CrFwIxRXuUemdr5-k7weloB5rHeTLX5yB9K-I3xDVmk,9977
|
|
23
|
+
hestia_earth/utils/storage/__init__.py,sha256=uNX6_EHWWnNUIm4Ng7L43-cQmuc6NGFAxXye85saIXQ,922
|
|
24
|
+
hestia_earth/utils/storage/_azure_client.py,sha256=mseexhzjteRDzzoFe2fEXe9MYLmvjG3sfl9-eha4ZW0,1353
|
|
25
|
+
hestia_earth/utils/storage/_local_client.py,sha256=KbYqTfniIU5R5J1m_unCQip9kOz9EGIGI0OH0QvD8eo,551
|
|
26
|
+
hestia_earth/utils/storage/_s3_client.py,sha256=8TCxiHfxE7G8kdp3CnEFrxgmPwfPyci3-blsowE2T7o,3146
|
|
27
|
+
hestia_earth/utils/storage/_sns_client.py,sha256=pvtXYw-sQ8ns3mlDz7ld9iZp3FYSm0xSXSXMJ5IPnBc,380
|
|
28
|
+
hestia_earth_utils-0.16.10.data/scripts/hestia-format-upload,sha256=IhLAHHPJqRgUcht-M_EUEsRMbRbMfshig07o488zscM,703
|
|
29
|
+
hestia_earth_utils-0.16.10.data/scripts/hestia-pivot-csv,sha256=0YBuGuyPO8rytod6iwWEKiQdSlr9JLuD001k6U5t6no,1163
|
|
30
|
+
hestia_earth_utils-0.16.10.dist-info/METADATA,sha256=IElWducWXMK-2YdsM_s5OJ_BD82nLtgTna1R4aQ0gBU,1870
|
|
31
|
+
hestia_earth_utils-0.16.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
32
|
+
hestia_earth_utils-0.16.10.dist-info/top_level.txt,sha256=q0QxKEYx9uLpAD5ZtC7Ypq29smEPfOzEAn7Xv8XHGOQ,13
|
|
33
|
+
hestia_earth_utils-0.16.10.dist-info/RECORD,,
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
hestia_earth/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
hestia_earth/utils/api.py,sha256=y0gw5pCCHNnFIhM62Hok_5eDtH3QDAZdkye_1mANMNs,9654
|
|
3
|
-
hestia_earth/utils/blank_node.py,sha256=kLjq8U0PYyq_SQ-VHGMll_3XxKdYEnHEwtCCglNT3vg,7350
|
|
4
|
-
hestia_earth/utils/calculation_status.py,sha256=X7lbgVMD9luH1gj9lEcxd3_P2-u7e8ZPGCvX1czPZUo,2238
|
|
5
|
-
hestia_earth/utils/cycle.py,sha256=rFLRL9X4KQ1UrE6fEPA_gV8KmwzrZpR3Ce56zg41lRk,1326
|
|
6
|
-
hestia_earth/utils/date.py,sha256=SPQ69uxHiv1o3BqIkBKkM5XX_CmS20CB7g6u2rhsdh8,1807
|
|
7
|
-
hestia_earth/utils/descriptive_stats.py,sha256=EMVwFvg2OnZgKRAfireAoWY2EbrSvqR0V0bK9B53p28,1583
|
|
8
|
-
hestia_earth/utils/emission.py,sha256=BhBitooLTxZSh82S982v2QfPxxTF1kmGClG_uHyWdz4,1981
|
|
9
|
-
hestia_earth/utils/lookup.py,sha256=0PdI7F_i_-Q0Tbb1ys0tL-pyt8_gigVkpNyXPSrYrug,7994
|
|
10
|
-
hestia_earth/utils/lookup_utils.py,sha256=P3Ae2MqZWvk3f9AObNwk6Fq9AyyX279K4kR9qHX8rKQ,6667
|
|
11
|
-
hestia_earth/utils/model.py,sha256=uUcrF07XmBzqLni8VSaP0HoebJnQ57kk0EOmhwYMbfI,4637
|
|
12
|
-
hestia_earth/utils/pipeline.py,sha256=O-6DPtK0U1lJ51LFGa1gM6pjkBJUfxOjNjY8LxQPXV0,9588
|
|
13
|
-
hestia_earth/utils/request.py,sha256=bu7hkWKmFdXl2_Feawiam_x32whlclA9oP0asJyC69k,626
|
|
14
|
-
hestia_earth/utils/stats.py,sha256=4t3op10xDJbGxWJEY1Jtyl302PYWyMFwLpsSkMlzQn8,34667
|
|
15
|
-
hestia_earth/utils/table.py,sha256=MOJDo5fQPRDogAty_UXbO9-EXFwz97m0f7--mOM17lQ,2363
|
|
16
|
-
hestia_earth/utils/term.py,sha256=6LiUSc6KX3IOkfWF6fYkQ2tENCO8ENljcdDypxU6WtA,1060
|
|
17
|
-
hestia_earth/utils/tools.py,sha256=9GaUJwxL-CTzEOGnRFkUQDVFelPevQSxXrf25vssCVo,4990
|
|
18
|
-
hestia_earth/utils/version.py,sha256=dYYPNRy7pxZ1PXeIozqamp1Gdu0z8aKNUgvQ1ew7zYA,19
|
|
19
|
-
hestia_earth/utils/pivot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
-
hestia_earth/utils/pivot/_shared.py,sha256=JnyIOzpans45DE2hSa9-4yvNhq8t08lx1IAWGJi6WPQ,1397
|
|
21
|
-
hestia_earth/utils/pivot/pivot_csv.py,sha256=7f6kMqeb1b3RKANLGeDgVu8G5WC-vXIijHnsJhO-CjI,12022
|
|
22
|
-
hestia_earth/utils/pivot/pivot_json.py,sha256=GBu5CFgCNdFjAuKGNsk2Phgds-xp4iREa5YIrplpFwA,9801
|
|
23
|
-
hestia_earth/utils/storage/__init__.py,sha256=uNX6_EHWWnNUIm4Ng7L43-cQmuc6NGFAxXye85saIXQ,922
|
|
24
|
-
hestia_earth/utils/storage/_azure_client.py,sha256=sevCZni04eknMql2DgUsWG23f7u0KvsXP7me1ZUBy00,1274
|
|
25
|
-
hestia_earth/utils/storage/_local_client.py,sha256=IbzziUKY0QS3ybHFfgEpELqvafa7hQnZ-DdGdjQuypE,515
|
|
26
|
-
hestia_earth/utils/storage/_s3_client.py,sha256=B2yTsf-VfHcRLCKTMes4S_nCXxrZad9umyZx3b5Pu_c,3181
|
|
27
|
-
hestia_earth/utils/storage/_sns_client.py,sha256=LowUatj78Egu6_Id6Rr7hZjfZx1WguS3lozB3yAwSps,347
|
|
28
|
-
hestia_earth_utils-0.16.9.data/scripts/hestia-format-upload,sha256=IhLAHHPJqRgUcht-M_EUEsRMbRbMfshig07o488zscM,703
|
|
29
|
-
hestia_earth_utils-0.16.9.data/scripts/hestia-pivot-csv,sha256=0YBuGuyPO8rytod6iwWEKiQdSlr9JLuD001k6U5t6no,1163
|
|
30
|
-
hestia_earth_utils-0.16.9.dist-info/METADATA,sha256=x2e0dU-hhvQp3qRFlGGuJ-pCDwi72rnMERPofFzCpa0,1869
|
|
31
|
-
hestia_earth_utils-0.16.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
32
|
-
hestia_earth_utils-0.16.9.dist-info/top_level.txt,sha256=q0QxKEYx9uLpAD5ZtC7Ypq29smEPfOzEAn7Xv8XHGOQ,13
|
|
33
|
-
hestia_earth_utils-0.16.9.dist-info/RECORD,,
|
{hestia_earth_utils-0.16.9.data → hestia_earth_utils-0.16.10.data}/scripts/hestia-format-upload
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|