hestia-earth-aggregation 0.21.17__py3-none-any.whl → 0.21.18__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.
@@ -1,6 +1,7 @@
1
1
  from hestia_earth.schema import ManagementJSONLD
2
2
  from hestia_earth.utils.model import linked_node
3
- from hestia_earth.utils.tools import safe_parse_date
3
+ from hestia_earth.utils.tools import safe_parse_date, flatten
4
+ from hestia_earth.utils.date import gapfill_datestr
4
5
 
5
6
  from . import match_dates, _set_dict_single
6
7
  from .queries import TIME_PERIOD, _get_time_ranges, _current_date
@@ -45,6 +46,34 @@ def aggregated_dates(blank_node: dict):
45
46
  )
46
47
 
47
48
 
49
+ def split_by_dates(blank_nodes: list, start_year: int):
50
+ # if the blank_node overlaps with the start period of the aggregation, we need to split it in 2 parts
51
+ def split_data(blank_node: dict):
52
+ start_date = safe_parse_date(blank_node.get("startDate"), default=None)
53
+ end_date = safe_parse_date(blank_node.get("endDate"), default=None)
54
+ is_overlapping = all([start_date is not None, end_date is not None]) and all(
55
+ [start_date.year < start_year, start_year < end_date.year]
56
+ )
57
+ return (
58
+ [
59
+ blank_node
60
+ | {
61
+ "startDate": blank_node.get("startDate"),
62
+ "endDate": gapfill_datestr(start_year - 1, "end"),
63
+ },
64
+ blank_node
65
+ | {
66
+ "startDate": gapfill_datestr(start_year, "start"),
67
+ "endDate": blank_node.get("endDate"),
68
+ },
69
+ ]
70
+ if is_overlapping
71
+ else blank_node
72
+ )
73
+
74
+ return flatten(map(split_data, blank_nodes))
75
+
76
+
48
77
  def filter_management(blank_nodes: list, start_year: int = None, end_year: int = None):
49
78
  def update_dates(blank_node: dict):
50
79
  start_date = safe_parse_date(blank_node.get("startDate"), default=None)
@@ -72,7 +101,9 @@ def filter_management(blank_nodes: list, start_year: int = None, end_year: int =
72
101
  """
73
102
  return [
74
103
  update_dates(v)
75
- for v in blank_nodes
104
+ for v in (
105
+ split_by_dates(blank_nodes, start_year) if start_year else blank_nodes
106
+ )
76
107
  if not start_year
77
108
  or not end_year
78
109
  or match_dates(v, start_year - TIME_PERIOD, end_year)
@@ -15,7 +15,7 @@ from hestia_earth.aggregation.log import logger
15
15
  from . import HestiaError, _save_json, pick
16
16
  from .term import DEFAULT_COUNTRY_NAME, _fetch_countries, is_global as is_global_country
17
17
 
18
- SEARCH_LIMIT = 10000
18
+ SEARCH_LIMIT = int(os.getenv("SEARCH_LIMIT", "10000"))
19
19
  _MATCH_AGGREGATED_QUERY = {"match": {"aggregated": "true"}}
20
20
  _MATCH_AGGREGATED_VALIDATED_QUERY = {"match": {"aggregatedDataValidated": "true"}}
21
21
  # enable matching any product
@@ -1 +1 @@
1
- VERSION = "0.21.17"
1
+ VERSION = "0.21.18"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hestia_earth_aggregation
3
- Version: 0.21.17
3
+ Version: 0.21.18
4
4
  Summary: HESTIA's aggregation engine.
5
5
  Home-page: https://gitlab.com/hestia-earth/hestia-aggregation-engine
6
6
  Author: HESTIA Team
@@ -2,7 +2,7 @@ hestia_earth/aggregation/__init__.py,sha256=kSK6RYcK0YnRGx6TknaukhuhbnxRHofLI_8P
2
2
  hestia_earth/aggregation/aggregate_cycles.py,sha256=MR-SseQRMGFUOKiBJcLVysjdjw5J-QfJ258VxGhasFw,7868
3
3
  hestia_earth/aggregation/log.py,sha256=0CibXDtKqFfE-R86qziM2uH7ATUZ6I9p_bVpRSn_e_o,2351
4
4
  hestia_earth/aggregation/recalculate_cycles.py,sha256=igMxKd7_K0MFlAt3Q_OynvHxDo3ldTixWbXjaC4M71c,510
5
- hestia_earth/aggregation/version.py,sha256=hcVLcttb0pemu91UT65kphAN_tKjRCwH4PaeO6euVl8,20
5
+ hestia_earth/aggregation/version.py,sha256=l0WM7ge0CXaUMWDGZjVN-Bv5P4kpSeFzwkayyG9kADw,20
6
6
  hestia_earth/aggregation/config/Cycle/crop.json,sha256=OBYXxleifxg9EJfZsqR1dgCxlEe2lIrCBqMe_Jo5XE4,1387
7
7
  hestia_earth/aggregation/config/Cycle/processedFood.json,sha256=OBYXxleifxg9EJfZsqR1dgCxlEe2lIrCBqMe_Jo5XE4,1387
8
8
  hestia_earth/aggregation/utils/__init__.py,sha256=nVVLgVFZ4415CgQAqgv4jDamA7gDmzOWk5SY4vshAQs,6583
@@ -18,19 +18,19 @@ hestia_earth/aggregation/utils/emission.py,sha256=fmzi2GHhG1E5Ioi00D1vVIPZwqaDB7
18
18
  hestia_earth/aggregation/utils/group.py,sha256=qU9sAuJu0RG80yLs90nsyoOcU57Pb6M1WKwT1TlJEkM,4765
19
19
  hestia_earth/aggregation/utils/input.py,sha256=pZ1bcdHR3y4S-3b0JZllbEUWdEyVZbltxv-07j7SucI,1092
20
20
  hestia_earth/aggregation/utils/lookup.py,sha256=osJiXTRns5KeBMz3mRsanmFQTATrwcMVBzB07xrb71M,2046
21
- hestia_earth/aggregation/utils/management.py,sha256=wrgNHhWuDTWmpRdKNi9BKg7GQRL8CJVAjcW1aeRaiyM,2891
21
+ hestia_earth/aggregation/utils/management.py,sha256=tr46zD8HrmRjEQnhMJ5s9eYapd8CKs4Gr99aZGLo1kY,4117
22
22
  hestia_earth/aggregation/utils/measurement.py,sha256=tdQwjo1hPb3iAaboBQiua832q27xZb_a9KqIp3iQkuE,1463
23
23
  hestia_earth/aggregation/utils/practice.py,sha256=MXZsQoeSXxe2vmdjvyS58HZN9jejPZNbVnczTc3HxxU,2252
24
24
  hestia_earth/aggregation/utils/product.py,sha256=dEUCy0eakyKyD2vu1RRnF4bdAI-jpS-qePNF8ZGhHFE,886
25
25
  hestia_earth/aggregation/utils/property.py,sha256=n_aHZ4qASv_wcDJ_HrA1T2kFX8R2zUEo91LCPL5xWkw,917
26
26
  hestia_earth/aggregation/utils/quality_score.py,sha256=PPNRW1wEkVqP7QExyu5dcr8R_Z_DWkmT3zmQG9u470Y,8914
27
- hestia_earth/aggregation/utils/queries.py,sha256=kzob6CHL1a60CRJdGICiWS98LKJRyq3uaToyuQyl9RI,17564
27
+ hestia_earth/aggregation/utils/queries.py,sha256=S9JZ3km_7EkbPDV0piQxfXMDF0qa2eXKdN0mz7oIkf8,17598
28
28
  hestia_earth/aggregation/utils/site.py,sha256=nc1N4IRiTki69IbCX4G6lagQ5U7IpsOsqiPuHwbl1HM,5455
29
29
  hestia_earth/aggregation/utils/source.py,sha256=SOiE-jB5WNtbRxreUWQ8c04ywzrwICy1aGyRL3-L0RY,686
30
30
  hestia_earth/aggregation/utils/term.py,sha256=uVAfBYnxNkcTNfzuwwHur6JGBahNrPwR2pN-__sj9zk,2758
31
31
  hestia_earth/aggregation/utils/weights.py,sha256=Qk5hCr_K24DzkeE4Sa241pGb6m00iaWHIXFQAJ-cDGc,7518
32
- hestia_earth_aggregation-0.21.17.dist-info/licenses/LICENSE,sha256=TD25LoiRJsA5CPUNrcyt1PXlGcbUGFMAeZoBcfCrCNE,1154
33
- hestia_earth_aggregation-0.21.17.dist-info/METADATA,sha256=fgZq8hdf22iumAqR_xOGtVJcOoKfSKnaexEakj6H7YA,2481
34
- hestia_earth_aggregation-0.21.17.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
35
- hestia_earth_aggregation-0.21.17.dist-info/top_level.txt,sha256=q0QxKEYx9uLpAD5ZtC7Ypq29smEPfOzEAn7Xv8XHGOQ,13
36
- hestia_earth_aggregation-0.21.17.dist-info/RECORD,,
32
+ hestia_earth_aggregation-0.21.18.dist-info/licenses/LICENSE,sha256=TD25LoiRJsA5CPUNrcyt1PXlGcbUGFMAeZoBcfCrCNE,1154
33
+ hestia_earth_aggregation-0.21.18.dist-info/METADATA,sha256=1WmgTNGYc4EQFS6ltVH_UQkThgZAm1gM2z84cuCiDLk,2481
34
+ hestia_earth_aggregation-0.21.18.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
35
+ hestia_earth_aggregation-0.21.18.dist-info/top_level.txt,sha256=q0QxKEYx9uLpAD5ZtC7Ypq29smEPfOzEAn7Xv8XHGOQ,13
36
+ hestia_earth_aggregation-0.21.18.dist-info/RECORD,,