hestia-earth-aggregation 0.21.13__tar.gz → 0.21.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.
Files changed (43) hide show
  1. {hestia_earth_aggregation-0.21.13/hestia_earth_aggregation.egg-info → hestia_earth_aggregation-0.21.15}/PKG-INFO +1 -1
  2. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/aggregate_country_nodes.py +45 -3
  3. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/aggregate_weighted.py +8 -1
  4. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/completeness.py +0 -1
  5. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/emission.py +15 -0
  6. hestia_earth_aggregation-0.21.15/hestia_earth/aggregation/version.py +1 -0
  7. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15/hestia_earth_aggregation.egg-info}/PKG-INFO +1 -1
  8. hestia_earth_aggregation-0.21.13/hestia_earth/aggregation/version.py +0 -1
  9. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/LICENSE +0 -0
  10. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/MANIFEST.in +0 -0
  11. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/README.md +0 -0
  12. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/__init__.py +0 -0
  13. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/aggregate_cycles.py +0 -0
  14. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/config/Cycle/processedFood.json +0 -0
  15. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/log.py +0 -0
  16. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/recalculate_cycles.py +0 -0
  17. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/__init__.py +0 -0
  18. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/blank_node.py +0 -0
  19. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/combine.py +0 -0
  20. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/covariance.py +0 -0
  21. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/cycle.py +0 -0
  22. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/distribution.py +0 -0
  23. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/group.py +0 -0
  24. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/input.py +0 -0
  25. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/lookup.py +0 -0
  26. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/management.py +0 -0
  27. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/measurement.py +0 -0
  28. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/practice.py +0 -0
  29. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/product.py +0 -0
  30. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/property.py +0 -0
  31. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/quality_score.py +0 -0
  32. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/queries.py +0 -0
  33. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/site.py +0 -0
  34. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/source.py +0 -0
  35. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/term.py +0 -0
  36. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth/aggregation/utils/weights.py +0 -0
  37. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth_aggregation.egg-info/SOURCES.txt +0 -0
  38. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth_aggregation.egg-info/dependency_links.txt +0 -0
  39. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth_aggregation.egg-info/requires.txt +0 -0
  40. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/hestia_earth_aggregation.egg-info/top_level.txt +0 -0
  41. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/setup.cfg +0 -0
  42. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/setup.py +0 -0
  43. {hestia_earth_aggregation-0.21.13 → hestia_earth_aggregation-0.21.15}/tests/test_aggregation.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hestia_earth_aggregation
3
- Version: 0.21.13
3
+ Version: 0.21.15
4
4
  Summary: HESTIA's aggregation engine.
5
5
  Home-page: https://gitlab.com/hestia-earth/hestia-aggregation-engine
6
6
  Author: HESTIA Team
@@ -10,6 +10,7 @@ from hestia_earth.utils.tools import (
10
10
  flatten,
11
11
  is_number,
12
12
  is_boolean,
13
+ current_time_ms,
13
14
  )
14
15
  from hestia_earth.utils.blank_node import (
15
16
  ArrayTreatment,
@@ -60,7 +61,11 @@ from .site import (
60
61
  format_site_description,
61
62
  site_parent_region_id,
62
63
  )
63
- from .emission import get_method_tier, get_method_model
64
+ from .emission import (
65
+ get_method_tier,
66
+ get_method_model,
67
+ has_value_without_transformation,
68
+ )
64
69
  from .property import aggregate_properties
65
70
  from .distribution import generate_blank_node_distribution
66
71
  from .covariance import add_covariance_cycles, generate_covariance_cycles
@@ -109,6 +114,8 @@ class BlankNodeFormatted(TypedDict, total=False):
109
114
  completeness_key: Optional[str]
110
115
  start_date: Optional[str]
111
116
  end_date: str
117
+ inputs: List[dict]
118
+ transformation: List[dict]
112
119
 
113
120
 
114
121
  # --- Cycle
@@ -242,6 +249,8 @@ def _group_cycle_blank_node(cycle: dict, product: dict, product_value: float):
242
249
  "economicValueShare": non_empty_list([_blank_node_evs(blank_nodes)]),
243
250
  # needed for background emissions
244
251
  "inputs": _map_values(blank_nodes, "inputs"),
252
+ # needed to exclude emissions with only transformation value
253
+ "transformation": _map_values(blank_nodes, "transformation"),
245
254
  "properties": _map_values(blank_nodes, "properties"),
246
255
  "methodTier": _map_values(blank_nodes, "methodTier"),
247
256
  "methodModel": _map_values(blank_nodes, "methodModel"),
@@ -292,14 +301,22 @@ def _group_cycle_blank_nodes(
292
301
  end_year: int = None,
293
302
  ):
294
303
  def grouper(group: dict, list_key: str) -> Dict[str, Dict[str, BlankNodeFormatted]]:
304
+ now = current_time_ms()
295
305
  blank_nodes = _filter_blank_nodes(cycle, list_key, start_year, end_year)
296
306
  values = reduce(
297
307
  _group_cycle_blank_node(cycle, product, product_value), blank_nodes, {}
298
308
  )
299
309
  # after combining all values, need to compute the final statistical values
300
310
  group[list_key] = {
301
- k: v | _compute_blank_node_stats(v) for k, v in values.items()
311
+ k: v | _compute_blank_node_stats(v)
312
+ for k, v in values.items()
313
+ if list_key != "emissions" or has_value_without_transformation(v)
302
314
  }
315
+ logger.debug(
316
+ "function=_group_cycle_blank_nodes, list_key=%s, time=%s",
317
+ list_key,
318
+ current_time_ms() - now,
319
+ )
303
320
  return group
304
321
 
305
322
  return grouper
@@ -405,6 +422,7 @@ def _combine_cycle_blank_nodes(
405
422
  cycles: List[CycleFormatted], completeness: Dict[str, int], cycle_count: int
406
423
  ):
407
424
  def combine(group: dict, list_key: str):
425
+ now = current_time_ms()
408
426
  # get all possible keys first, then group each key values into a single blank node
409
427
  keys = set(flatten([list(cycle.get(list_key, {}).keys()) for cycle in cycles]))
410
428
  group[list_key] = reduce(
@@ -412,6 +430,11 @@ def _combine_cycle_blank_nodes(
412
430
  keys,
413
431
  {},
414
432
  )
433
+ logger.debug(
434
+ "function=_combine_cycle_blank_nodes, list_key=%s, time=%s",
435
+ list_key,
436
+ current_time_ms() - now,
437
+ )
415
438
  return group
416
439
 
417
440
  return combine
@@ -511,8 +534,14 @@ def _group_site_blank_nodes(
511
534
  site: SiteJSONLD, start_year: int = None, end_year: int = None
512
535
  ):
513
536
  def grouper(group: dict, list_key: str) -> Dict[str, BlankNodeFormatted]:
537
+ now = current_time_ms()
514
538
  blank_nodes = _filter_blank_nodes(site, list_key, start_year, end_year)
515
539
  group[list_key] = reduce(_group_site_blank_node(), blank_nodes, {})
540
+ logger.debug(
541
+ "function=_group_site_blank_nodes, list_key=%s, time=%s",
542
+ list_key,
543
+ current_time_ms() - now,
544
+ )
516
545
  return group
517
546
 
518
547
  return grouper
@@ -559,9 +588,15 @@ def _combine_site_blank_node(sites: List[SiteFormatted], list_key: str):
559
588
 
560
589
  def _combine_site_blank_nodes(sites: List[SiteFormatted]):
561
590
  def combine(group: dict, list_key: str):
591
+ now = current_time_ms()
562
592
  # get all possible keys first, then group each key values into a single blank node
563
593
  keys = set(flatten([list(site.get(list_key, {}).keys()) for site in sites]))
564
594
  group[list_key] = reduce(_combine_site_blank_node(sites, list_key), keys, {})
595
+ logger.debug(
596
+ "function=_combine_site_blank_nodes, list_key=%s, time=%s",
597
+ list_key,
598
+ current_time_ms() - now,
599
+ )
565
600
  return group
566
601
 
567
602
  return combine
@@ -647,9 +682,16 @@ def _aggregate_formatted(
647
682
  data: Union[CycleFormatted, SiteFormatted], aggregated_keys: List[str]
648
683
  ):
649
684
  def aggregate(key: str):
685
+ now = current_time_ms()
650
686
  values = data.get(key, {}).values()
651
687
  logger.debug(f"Aggregating {len(values)} {key}...")
652
- return list(map(_aggregate_blank_node, values))
688
+ values = list(map(_aggregate_blank_node, values))
689
+ logger.debug(
690
+ "function=_aggregate_formatted, key=%s, time=%s",
691
+ key,
692
+ current_time_ms() - now,
693
+ )
694
+ return values
653
695
 
654
696
  return reduce(lambda group, key: group | {key: aggregate(key)}, aggregated_keys, {})
655
697
 
@@ -6,9 +6,11 @@ from hestia_earth.utils.tools import (
6
6
  list_sum,
7
7
  list_average,
8
8
  is_boolean,
9
+ current_time_ms,
9
10
  )
10
11
  from hestia_earth.utils.blank_node import get_node_value
11
12
 
13
+ from hestia_earth.aggregation.log import logger
12
14
  from . import weighted_average, _min, _max, _sd, format_evs, pick
13
15
  from .emission import get_method_tier, get_method_model
14
16
  from .property import aggregate_properties
@@ -188,14 +190,19 @@ def _aggregate_nodes(
188
190
  aggregate_keys: List[str], data: dict, weights: dict, missing_weights_node_id_func
189
191
  ):
190
192
  def aggregate_single(key: str):
193
+ now = current_time_ms()
191
194
  aggregates_map: dict = data.get(key)
192
195
  terms = aggregates_map.keys()
193
- return non_empty_list(
196
+ values = non_empty_list(
194
197
  map(
195
198
  _aggregate_term(aggregates_map, weights, missing_weights_node_id_func),
196
199
  terms,
197
200
  )
198
201
  )
202
+ logger.debug(
203
+ "function=_aggregate_nodes, key=%s, time=%s", key, current_time_ms() - now
204
+ )
205
+ return values
199
206
 
200
207
  return reduce(
201
208
  lambda prev, curr: prev | {curr: aggregate_single(curr)}, aggregate_keys, {}
@@ -9,7 +9,6 @@ from hestia_earth.schema import (
9
9
  )
10
10
  from hestia_earth.utils.tools import non_empty_list
11
11
 
12
-
13
12
  _ANIMAL_FEED_INPUT_MAPPING = {
14
13
  SchemaType.INPUT.value: {
15
14
  TermTermType.ANIMALPRODUCT.value: CompletenessField.ANIMALFEED.value,
@@ -69,3 +69,18 @@ def get_method_model(emissions: list):
69
69
  values = non_empty_list(flatten([e.get("methodModel", []) for e in emissions]))
70
70
  values = list({v["@id"]: v for v in values}.values())
71
71
  return values[0] if len(values) == 1 else None
72
+
73
+
74
+ def has_value_without_transformation(blank_node: dict):
75
+ values = blank_node.get("value", [])
76
+ transformations = blank_node.get("transformation", [])
77
+ return (
78
+ not transformations
79
+ or len(transformations) != len(values)
80
+ or any(
81
+ [
82
+ value is not None and transformations[index] is None
83
+ for index, value in enumerate(values)
84
+ ]
85
+ )
86
+ )
@@ -0,0 +1 @@
1
+ VERSION = "0.21.15"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hestia_earth_aggregation
3
- Version: 0.21.13
3
+ Version: 0.21.15
4
4
  Summary: HESTIA's aggregation engine.
5
5
  Home-page: https://gitlab.com/hestia-earth/hestia-aggregation-engine
6
6
  Author: HESTIA Team
@@ -1 +0,0 @@
1
- VERSION = "0.21.13"