hestia-earth-models 0.62.5__py3-none-any.whl → 0.62.6__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.
Potentially problematic release.
This version of hestia-earth-models might be problematic. Click here for more details.
- hestia_earth/models/cycle/croppingIntensity.py +57 -0
- hestia_earth/models/cycle/longFallowRatio.py +52 -0
- hestia_earth/models/cycle/siteDuration.py +23 -3
- hestia_earth/models/cycle/siteUnusedDuration.py +64 -0
- hestia_earth/models/geospatialDatabase/croppingIntensity.py +32 -22
- hestia_earth/models/geospatialDatabase/longFallowRatio.py +34 -23
- hestia_earth/models/mocking/mock_search.py +14 -8
- hestia_earth/models/mocking/search-results.json +27 -27
- hestia_earth/models/pooreNemecek2018/longFallowPeriod.py +1 -2
- hestia_earth/models/pooreNemecek2018/nurseryDensity.py +1 -2
- hestia_earth/models/pooreNemecek2018/nurseryDuration.py +1 -2
- hestia_earth/models/pooreNemecek2018/plantationDensity.py +1 -2
- hestia_earth/models/pooreNemecek2018/plantationLifespan.py +1 -2
- hestia_earth/models/pooreNemecek2018/plantationProductiveLifespan.py +1 -2
- hestia_earth/models/preload_requests.py +14 -7
- hestia_earth/models/utils/__init__.py +0 -9
- hestia_earth/models/utils/cycle.py +10 -2
- hestia_earth/models/utils/product.py +2 -2
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.62.5.dist-info → hestia_earth_models-0.62.6.dist-info}/METADATA +2 -2
- {hestia_earth_models-0.62.5.dist-info → hestia_earth_models-0.62.6.dist-info}/RECORD +30 -24
- tests/models/cycle/test_croppingIntensity.py +53 -0
- tests/models/cycle/test_longFallowRatio.py +49 -0
- tests/models/cycle/test_siteDuration.py +41 -14
- tests/models/cycle/test_siteUnusedDuration.py +55 -0
- tests/models/geospatialDatabase/test_croppingIntensity.py +5 -3
- tests/models/geospatialDatabase/test_longFallowRatio.py +5 -3
- {hestia_earth_models-0.62.5.dist-info → hestia_earth_models-0.62.6.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.62.5.dist-info → hestia_earth_models-0.62.6.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.62.5.dist-info → hestia_earth_models-0.62.6.dist-info}/top_level.txt +0 -0
|
@@ -7,8 +7,7 @@ from . import MODEL
|
|
|
7
7
|
|
|
8
8
|
REQUIREMENTS = {
|
|
9
9
|
"Cycle": {
|
|
10
|
-
"products": [{"@type": "Product", "value": "", "term.termType": "crop"}]
|
|
11
|
-
"site": {"@type": "Site", "siteType": "cropland"}
|
|
10
|
+
"products": [{"@type": "Product", "value": "", "term.termType": "crop"}]
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
13
|
LOOKUPS = {
|
|
@@ -9,8 +9,7 @@ from . import MODEL
|
|
|
9
9
|
|
|
10
10
|
REQUIREMENTS = {
|
|
11
11
|
"Cycle": {
|
|
12
|
-
"products": [{"@type": "Product", "value": "", "term.termType": "crop"}]
|
|
13
|
-
"site": {"@type": "Site", "siteType": "cropland"}
|
|
12
|
+
"products": [{"@type": "Product", "value": "", "term.termType": "crop"}]
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
15
|
LOOKUPS = {
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Preload all search requests to avoid making the same searches many times while running models.
|
|
3
3
|
"""
|
|
4
4
|
import json
|
|
5
|
+
import os
|
|
5
6
|
|
|
6
7
|
from .log import logger
|
|
7
8
|
from .mocking.mock_search import create_search_results
|
|
8
9
|
from .mocking import RESULTS_PATH, enable_mock as _mock
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
def enable_preload(filepath: str = RESULTS_PATH, node: dict = None):
|
|
12
|
+
def enable_preload(filepath: str = RESULTS_PATH, node: dict = None, overwrite_existing: bool = True):
|
|
12
13
|
"""
|
|
13
14
|
Prefetch calls to HESTIA API in a local file.
|
|
14
15
|
|
|
@@ -18,15 +19,21 @@ def enable_preload(filepath: str = RESULTS_PATH, node: dict = None):
|
|
|
18
19
|
The path of the file containing the search results. Defaults to current library folder.
|
|
19
20
|
node : dict
|
|
20
21
|
Optional - The node used to run calculations. This is especially useful when running calculations on a Site.
|
|
22
|
+
overwrite_existing : bool
|
|
23
|
+
Optional - If the file already exists, the file can be used instead of generating it again.
|
|
24
|
+
Will overwrite by default.
|
|
21
25
|
"""
|
|
22
|
-
|
|
26
|
+
should_generate = overwrite_existing or not os.path.exists(filepath)
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
if should_generate:
|
|
29
|
+
logger.debug('Preloading search results and storing in %s', filepath)
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
# build the search results
|
|
32
|
+
data = create_search_results()
|
|
33
|
+
|
|
34
|
+
# store in file
|
|
35
|
+
with open(filepath, 'w') as f:
|
|
36
|
+
f.write(json.dumps(data, indent=2, ensure_ascii=False))
|
|
30
37
|
|
|
31
38
|
# enable mock search results from file
|
|
32
39
|
_mock(filepath=filepath, node=node)
|
|
@@ -122,15 +122,6 @@ def get_kg_term_units(term_id: str, units: str):
|
|
|
122
122
|
}.get(units, lambda x: None)(term_id)
|
|
123
123
|
|
|
124
124
|
|
|
125
|
-
def _get_by_key(x, y):
|
|
126
|
-
return x if x is None else (
|
|
127
|
-
x.get(y) if isinstance(x, dict) else list(map(lambda v: get_dict_key(v, y), x))
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
def get_dict_key(value: dict, key: str): return reduce(lambda x, y: _get_by_key(x, y), key.split('.'), value)
|
|
132
|
-
|
|
133
|
-
|
|
134
125
|
def first_day_of_month(year: int, month: int):
|
|
135
126
|
return datetime.date(int(year), int(month), 1)
|
|
136
127
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
from hestia_earth.schema import CycleFunctionalUnit, SiteSiteType, TermTermType, AnimalReferencePeriod
|
|
2
2
|
from hestia_earth.utils.model import filter_list_term_type, find_term_match, find_primary_product
|
|
3
|
-
from hestia_earth.utils.tools import list_sum, safe_parse_float, safe_parse_date
|
|
3
|
+
from hestia_earth.utils.tools import list_sum, safe_parse_float, safe_parse_date, non_empty_list
|
|
4
4
|
|
|
5
5
|
from ..log import logRequirements, debugValues
|
|
6
|
-
from .lookup import factor_value
|
|
6
|
+
from .lookup import factor_value, is_siteType_allowed
|
|
7
7
|
from .term import get_lookup_value
|
|
8
8
|
from .property import get_node_property
|
|
9
9
|
from .completeness import _is_term_type_complete
|
|
@@ -464,3 +464,11 @@ def get_animals_by_period(cycle: dict, period: AnimalReferencePeriod = AnimalRef
|
|
|
464
464
|
a.get('referencePeriod') == period.value
|
|
465
465
|
])
|
|
466
466
|
]
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
def get_allowed_sites(model: str, term_id: str, termType: TermTermType, cycle: dict):
|
|
470
|
+
sites = non_empty_list([cycle.get('site', None)]) + cycle.get('otherSites', [])
|
|
471
|
+
allowed_sites = [s for s in sites if is_siteType_allowed(s, {'@id': term_id, 'termType': termType.value})]
|
|
472
|
+
debugValues(cycle, model=model, term=term_id,
|
|
473
|
+
allowed_sites=';'.join([s.get('@id', s.get('id')) for s in allowed_sites]))
|
|
474
|
+
return allowed_sites
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
from hestia_earth.schema import SchemaType, TermTermType, UNIQUENESS_FIELDS
|
|
2
2
|
from hestia_earth.utils.api import download_hestia
|
|
3
3
|
from hestia_earth.utils.model import filter_list_term_type, find_term_match, linked_node
|
|
4
|
-
from hestia_earth.utils.tools import flatten, list_sum, non_empty_list
|
|
4
|
+
from hestia_earth.utils.tools import flatten, list_sum, non_empty_list, get_dict_key
|
|
5
5
|
|
|
6
|
-
from . import _term_id, _include_model
|
|
6
|
+
from . import _term_id, _include_model
|
|
7
7
|
from .blank_node import get_total_value, get_total_value_converted
|
|
8
8
|
from .constant import Units
|
|
9
9
|
from .currency import DEFAULT_CURRENCY
|
hestia_earth/models/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = '0.62.
|
|
1
|
+
VERSION = '0.62.6'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: hestia-earth-models
|
|
3
|
-
Version: 0.62.
|
|
3
|
+
Version: 0.62.6
|
|
4
4
|
Summary: HESTIA's set of modules for filling gaps in the activity data using external datasets (e.g. populating soil properties with a geospatial dataset using provided coordinates) and internal lookups (e.g. populating machinery use from fuel use). Includes rules for when gaps should be filled versus not (e.g. never gap fill yield, gap fill crop residue if yield provided etc.).
|
|
5
5
|
Home-page: https://gitlab.com/hestia-earth/hestia-engine-models
|
|
6
6
|
Author: HESTIA Team
|
|
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3.6
|
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: hestia-earth.schema==29.*
|
|
15
|
-
Requires-Dist: hestia-earth.utils>=0.13.
|
|
15
|
+
Requires-Dist: hestia-earth.utils>=0.13.3
|
|
16
16
|
Requires-Dist: python-dateutil>=2.8.1
|
|
17
17
|
Requires-Dist: CurrencyConverter==0.16.8
|
|
18
18
|
Requires-Dist: haversine>=2.7.0
|
|
@@ -2,9 +2,9 @@ hestia_earth/__init__.py,sha256=G-d438vPx7m_ks5e9XTtM3u7LDRO5dSSukibukWmyPM,56
|
|
|
2
2
|
hestia_earth/models/__init__.py,sha256=qEFeq3yuf3lQKVseALmL8aPM8fpCS54B_5pry00M3hk,76
|
|
3
3
|
hestia_earth/models/cache_sites.py,sha256=KQp9cUKE-aIcYJoMWEtKFYS8gBFfsx5LKQhqoWpUSoM,6065
|
|
4
4
|
hestia_earth/models/log.py,sha256=DbfNcGzaC5hzkuMDxQqW6XYoNBI4Uxw4SIoOYoZA6og,3474
|
|
5
|
-
hestia_earth/models/preload_requests.py,sha256=
|
|
5
|
+
hestia_earth/models/preload_requests.py,sha256=Ibx-YOhR_1yuyFBxsLUbvJHVK7PLyMLoPu5l9jDN_Qk,1342
|
|
6
6
|
hestia_earth/models/requirements.py,sha256=eU4yT443fx7BnaokhrLB_PCizJI7Y6m4auyo8vQauNg,17363
|
|
7
|
-
hestia_earth/models/version.py,sha256=
|
|
7
|
+
hestia_earth/models/version.py,sha256=bq12SSfdPusguwOVPL82zbxOkhoEi6X6goWBn-b5HwE,19
|
|
8
8
|
hestia_earth/models/agribalyse2016/__init__.py,sha256=WvK0qCQbnYtg9oZxrACd1wGormZyXibPtpCnIQeDqbw,415
|
|
9
9
|
hestia_earth/models/agribalyse2016/fuelElectricity.py,sha256=tnGxBmJdPfPFfehLUQcefEqy1lHvzsSpx_s7O8nf3Zs,4412
|
|
10
10
|
hestia_earth/models/agribalyse2016/machineryInfrastructureDepreciatedAmountPerCycle.py,sha256=_Rbngu0DzHKa62JwBl58ZC_ui1zLF2que_nB7ukhOQc,3392
|
|
@@ -39,6 +39,7 @@ hestia_earth/models/cycle/coldCarcassWeightPerHead.py,sha256=fQ7huuxyS5PQkRmR_tR
|
|
|
39
39
|
hestia_earth/models/cycle/coldDressedCarcassWeightPerHead.py,sha256=k0xg5SIfJGwEKteFr2Fh-lh8yDC_sqQw_lBnnfwl9zU,3069
|
|
40
40
|
hestia_earth/models/cycle/concentrateFeed.py,sha256=wiq9KLRuipHz_2_CVfXDuUek0JN1ZPSyKSimtJntG9E,5636
|
|
41
41
|
hestia_earth/models/cycle/cropResidueManagement.py,sha256=QTRCCFu9VvD_a3_8aAj216vsuhAJEhlAwTJH7ifMkDo,2237
|
|
42
|
+
hestia_earth/models/cycle/croppingIntensity.py,sha256=44CgDqXg9CBRfTPYTyOleQT-M4_tsQgPba-0vjjk_C4,1770
|
|
42
43
|
hestia_earth/models/cycle/cycleDuration.py,sha256=SuTFqCP3Zr3nOV9HuvvvIVcaHtOlTAdSaaswvRLSEwc,3242
|
|
43
44
|
hestia_earth/models/cycle/energyContentLowerHeatingValue.py,sha256=AyVKCQbb3Pto3Ca__F0KJ_wlwTxbPd7mUyehZW7AJPM,2212
|
|
44
45
|
hestia_earth/models/cycle/excretaKgMass.py,sha256=iA8Kfl3WvyxbQpx1QOGPQZ9O_Pc5rj7xhucYx3rB8Co,3949
|
|
@@ -47,6 +48,7 @@ hestia_earth/models/cycle/excretaKgVs.py,sha256=ed-DcQoQXZgWF8UZDs2N-G6EBIOPmpXu
|
|
|
47
48
|
hestia_earth/models/cycle/inorganicFertiliser.py,sha256=Yt5NcP9FQEzWwlritrPGbhh2W9wR378OM3lDPBzDiL4,6967
|
|
48
49
|
hestia_earth/models/cycle/irrigatedTypeUnspecified.py,sha256=KlIa5eDvT47Twz6Q1kpw0rMlRjCK25CExaW58DEvc9w,2125
|
|
49
50
|
hestia_earth/models/cycle/liveAnimal.py,sha256=LWAMnNKRoLDdChrGApVIN-Ns7em0Lspz5UtLbf7PPLY,3988
|
|
51
|
+
hestia_earth/models/cycle/longFallowRatio.py,sha256=RmUAUrTmSi8YG3A43R60N_7iy66vN_aY3d4uSJoJcDc,1661
|
|
50
52
|
hestia_earth/models/cycle/milkYield.py,sha256=RhzePjkvEAGicTzRA4eatc0K_4NSGHhyEhYF0EbbGXw,5820
|
|
51
53
|
hestia_earth/models/cycle/pastureGrass.py,sha256=7PrmDMJPtsbKGa8WIOh_4NXNtbH3Pxb23pmjawQuY9o,1226
|
|
52
54
|
hestia_earth/models/cycle/pastureSystem.py,sha256=uksVgl_3bp_t2niwZ5BvS3VT-Kndx26Se6GpzqG0bX8,2709
|
|
@@ -55,7 +57,8 @@ hestia_earth/models/cycle/residueBurnt.py,sha256=HwU1D9ibiIul-FlXDUcEMDEc_KxpB8u
|
|
|
55
57
|
hestia_earth/models/cycle/residueIncorporated.py,sha256=9_s2RMOy5D20eq9ziDBEA_Y7RiFFMeK0bDJ65CW4qlE,2763
|
|
56
58
|
hestia_earth/models/cycle/residueLeftOnField.py,sha256=qYxKGAdUORN7Vjqj7AZC2VGV_rM3MN0-padDGhgjiNU,2175
|
|
57
59
|
hestia_earth/models/cycle/residueRemoved.py,sha256=jxDu_Jfcyd-rm-qo8ZuRIf-GGxtFBMpmGy1zHOavwy0,2135
|
|
58
|
-
hestia_earth/models/cycle/siteDuration.py,sha256=
|
|
60
|
+
hestia_earth/models/cycle/siteDuration.py,sha256=793ez4IDOHxsbDIREZQ5rUgS6FQare2jL6SZ8qemxKs,2014
|
|
61
|
+
hestia_earth/models/cycle/siteUnusedDuration.py,sha256=HvVyok1HPt0_WsTPZq2PklsFT9WKPF9frncS07nqzGA,2105
|
|
59
62
|
hestia_earth/models/cycle/startDate.py,sha256=OnuMf4TkDb0WwCntjXNy3ipLS-b4drMWSkXWeXU142Q,1507
|
|
60
63
|
hestia_earth/models/cycle/startDateDefinition.py,sha256=nCFeKjZjC3MoYNFH0N66WNW4HJUzKD_UkznvTMl_KfM,2244
|
|
61
64
|
hestia_earth/models/cycle/transformation.py,sha256=06KTfVubh2I47dfnG9Iv6AbuUBbURM8BAVOkRu7XmHw,1255
|
|
@@ -143,14 +146,14 @@ hestia_earth/models/faostat2018/product/price.py,sha256=X7Zxa-rXthzYdgw2lzybbHc-
|
|
|
143
146
|
hestia_earth/models/geospatialDatabase/__init__.py,sha256=TH-FW3aoL7r1GquRChr7rde7uQonKQRDR00udG8tDrQ,957
|
|
144
147
|
hestia_earth/models/geospatialDatabase/aware.py,sha256=cbxFnShXW8QUCIjU4uuO1DdK9KhYiLf41ZVjS9hSppI,1358
|
|
145
148
|
hestia_earth/models/geospatialDatabase/clayContent.py,sha256=HWaswqkf1FZXcRHw8DrMvvpH2Uo3nbjX4C0D1tqyTBw,2710
|
|
146
|
-
hestia_earth/models/geospatialDatabase/croppingIntensity.py,sha256=
|
|
149
|
+
hestia_earth/models/geospatialDatabase/croppingIntensity.py,sha256=4HVrl7Hayg6IpdCrz19Xq_clKdcS_0Sw9uiA4kjKJ40,2509
|
|
147
150
|
hestia_earth/models/geospatialDatabase/drainageClass.py,sha256=CVagB2wxLnHgQQauDyYCJCfJw21OPB7Ry8BVyt2uPak,1883
|
|
148
151
|
hestia_earth/models/geospatialDatabase/ecoClimateZone.py,sha256=hzK9Je_4NvbLtgAM48G7yf-6jrcMpsDzqSlLkVP3oYg,3625
|
|
149
152
|
hestia_earth/models/geospatialDatabase/ecoregion.py,sha256=awvHn0YEVu-YaW0ZDgBo_zbjSJU2EvydM_qAT_CL78A,1462
|
|
150
153
|
hestia_earth/models/geospatialDatabase/erodibility.py,sha256=M62CetEcHuExeXl7P7DVKZWWbk9tenjaDFvjMsWbga4,1843
|
|
151
154
|
hestia_earth/models/geospatialDatabase/heavyWinterPrecipitation.py,sha256=54pvHOfcfEUNNhTIWIPGRzqO_t59ACh-zhnLidO2xro,1956
|
|
152
155
|
hestia_earth/models/geospatialDatabase/histosol.py,sha256=5zwKdF1t9aOjTzBoear62T0Kzpjco-IJXu4oRYrUFQ8,2387
|
|
153
|
-
hestia_earth/models/geospatialDatabase/longFallowRatio.py,sha256=
|
|
156
|
+
hestia_earth/models/geospatialDatabase/longFallowRatio.py,sha256=OXInoU4uYlgLwpAF3PetIDQ2ck4rOdf9_EyjXEtzD4Q,2505
|
|
154
157
|
hestia_earth/models/geospatialDatabase/nutrientLossToAquaticEnvironment.py,sha256=uEsoYJ1mzgUo6fQhUrcJ-ATcFw1j9oEgqMXKbQuFRxQ,1973
|
|
155
158
|
hestia_earth/models/geospatialDatabase/organicCarbonPerKgSoil.py,sha256=gt3-crrUN0HPtIKY7Hf9dUteCXkegSICVjO-jufDqas,2196
|
|
156
159
|
hestia_earth/models/geospatialDatabase/potentialEvapotranspirationAnnual.py,sha256=UlCBvAD-6H-4sdryfPuX1YDlOsGPOI8T9y0q4O0Tau8,2544
|
|
@@ -369,8 +372,8 @@ hestia_earth/models/linkedImpactAssessment/landTransformationFromPermanentPastur
|
|
|
369
372
|
hestia_earth/models/linkedImpactAssessment/landTransformationFromPermanentPasture20YearAverageInputsProduction.py,sha256=pdluhfRQuJK0EHq-L0s0TOf37tvOQYB-M-wZiuSbarw,1050
|
|
370
373
|
hestia_earth/models/linkedImpactAssessment/utils.py,sha256=dGwGc2d-8_WQElTpfyPmz5vQtL-LHQRmiZnCTuPXMDs,1876
|
|
371
374
|
hestia_earth/models/mocking/__init__.py,sha256=n3Fkkrvh8zHNWiJZmnfQ7WZ91JRzAO9P6pSG1JpwtXo,687
|
|
372
|
-
hestia_earth/models/mocking/mock_search.py,sha256=
|
|
373
|
-
hestia_earth/models/mocking/search-results.json,sha256=
|
|
375
|
+
hestia_earth/models/mocking/mock_search.py,sha256=qgABw-sZK37XtsALKt8AHF2VJPUrZSnHv5Qj1Dn93oA,2405
|
|
376
|
+
hestia_earth/models/mocking/search-results.json,sha256=Ej8oiIFaddQ5-eOjMO_X7TxO7yVdsd0IASgWWRPfvWg,46413
|
|
374
377
|
hestia_earth/models/pooreNemecek2018/__init__.py,sha256=nPboL7ULJzL5nJD5q7q9VOZt_fxbKVm8fmn1Az5YkVY,417
|
|
375
378
|
hestia_earth/models/pooreNemecek2018/aboveGroundCropResidueTotal.py,sha256=Qt-mel4dkhK6N5uUOutNOinCTFjbjtGzITaaI0LvYc4,2396
|
|
376
379
|
hestia_earth/models/pooreNemecek2018/belowGroundCropResidue.py,sha256=JT0RybbvWVlo01FO8K0Yj41HrEaJT3Kj1xfayr2X-xw,2315
|
|
@@ -379,7 +382,7 @@ hestia_earth/models/pooreNemecek2018/excretaKgN.py,sha256=kLWtv49c1sD3YrporqRcmw
|
|
|
379
382
|
hestia_earth/models/pooreNemecek2018/excretaKgVs.py,sha256=nlnZSDx-bIvtukL79Syhon0cSQ8o4OC1YKtAG6haGhI,8500
|
|
380
383
|
hestia_earth/models/pooreNemecek2018/freshwaterWithdrawalsDuringCycle.py,sha256=HB_9q5eE6al2Te3v29hC5wqxsYe4P46ZAPwdWNzx3v0,3939
|
|
381
384
|
hestia_earth/models/pooreNemecek2018/landOccupationDuringCycle.py,sha256=jE110XgPMgfnBMUXyKIL5SL9yZWYhdGr5NrfHcqn2h0,2785
|
|
382
|
-
hestia_earth/models/pooreNemecek2018/longFallowPeriod.py,sha256=
|
|
385
|
+
hestia_earth/models/pooreNemecek2018/longFallowPeriod.py,sha256=jXm6SeoA0kW0rpcWLcGEDxWwiLsIJRllM4md6jSAqgc,1507
|
|
383
386
|
hestia_earth/models/pooreNemecek2018/n2OToAirAquacultureSystemsDirect.py,sha256=HJ7IstImGyasIKosK2lQZ-v6Lqt3_aEfZhoiC4CY0rM,2586
|
|
384
387
|
hestia_earth/models/pooreNemecek2018/n2ToAirAquacultureSystems.py,sha256=SoZlogDd7_4kq5S9gc8KmVeIXacWWhaUkWlKTuho_OA,2431
|
|
385
388
|
hestia_earth/models/pooreNemecek2018/nh3ToAirAquacultureSystems.py,sha256=4TDILoagYMVBSBbVXEecIOv-pzQ-W2Hg6rpL58t1-J4,4001
|
|
@@ -389,11 +392,11 @@ hestia_earth/models/pooreNemecek2018/no3ToGroundwaterInorganicFertiliser.py,sha2
|
|
|
389
392
|
hestia_earth/models/pooreNemecek2018/no3ToGroundwaterOrganicFertiliser.py,sha256=ussLIjMsJT0_GmikEBpGqHzDZ5KqJYH8T-B2qN4LRzE,2298
|
|
390
393
|
hestia_earth/models/pooreNemecek2018/no3ToGroundwaterSoilFlux.py,sha256=G0D_YBCP29Yl_hmQ7jpZP6i0I708PiiaaVRoNrI01MI,6058
|
|
391
394
|
hestia_earth/models/pooreNemecek2018/noxToAirAquacultureSystems.py,sha256=NfuCdx-rt5mhUxGSsJSudSMp9YkiHRMAiWVyR6m8faM,2733
|
|
392
|
-
hestia_earth/models/pooreNemecek2018/nurseryDensity.py,sha256=
|
|
393
|
-
hestia_earth/models/pooreNemecek2018/nurseryDuration.py,sha256=
|
|
394
|
-
hestia_earth/models/pooreNemecek2018/plantationDensity.py,sha256
|
|
395
|
-
hestia_earth/models/pooreNemecek2018/plantationLifespan.py,sha256=
|
|
396
|
-
hestia_earth/models/pooreNemecek2018/plantationProductiveLifespan.py,sha256=
|
|
395
|
+
hestia_earth/models/pooreNemecek2018/nurseryDensity.py,sha256=ZY4w4q6uvKls-Tj4hz770MRIwJeHxA4DZ10JUJYeBss,951
|
|
396
|
+
hestia_earth/models/pooreNemecek2018/nurseryDuration.py,sha256=_k8OCZxCiT5hrWGLx4HF0CHi21eYtbkFMxMNYKctzCc,953
|
|
397
|
+
hestia_earth/models/pooreNemecek2018/plantationDensity.py,sha256=-y-zXHFPet0LdIgSG-o2hV_sdIOLeuWoRikW2DPi3kk,957
|
|
398
|
+
hestia_earth/models/pooreNemecek2018/plantationLifespan.py,sha256=FudC-csC1IkiFOJ_uD0s6_rwsgqVrUN6Ej7A03JXDsM,959
|
|
399
|
+
hestia_earth/models/pooreNemecek2018/plantationProductiveLifespan.py,sha256=Q54woX67eUab0qEEAuW2naFGhnVPJHrMas3bG92KNeg,1740
|
|
397
400
|
hestia_earth/models/pooreNemecek2018/rotationDuration.py,sha256=F3zDjhEzxZJ_1y_9LG3_DRkyNuaGiJX5i4XqiXOoP_0,1509
|
|
398
401
|
hestia_earth/models/pooreNemecek2018/saplings.py,sha256=LS0zepV51-LlVmPBAjj5nlfgaJFnQF6wo40sgoFCr3Y,2258
|
|
399
402
|
hestia_earth/models/pooreNemecek2018/utils.py,sha256=to2vtONKCbuG1gVSDvsUcG7EnlahELfG_57gzIAHlv0,1710
|
|
@@ -527,7 +530,7 @@ hestia_earth/models/transformation/product/__init__.py,sha256=47DEQpj8HBSa-_TImW
|
|
|
527
530
|
hestia_earth/models/transformation/product/excreta.py,sha256=Yj9wMF5if-zivb6qbN3vy1X51ZNYxvoyG9f4KPp3Y18,5700
|
|
528
531
|
hestia_earth/models/usetoxV2/__init__.py,sha256=pK37V3H-KvYcvRKw4Mv8CWrB2N0LFLzmv0jKLdhGGqs,409
|
|
529
532
|
hestia_earth/models/usetoxV2/freshwaterEcotoxicityPotentialCtue.py,sha256=oYNwThnMXjZymif5buyHiczFiOq_61jOdDMOAyy8vwQ,1018
|
|
530
|
-
hestia_earth/models/utils/__init__.py,sha256=
|
|
533
|
+
hestia_earth/models/utils/__init__.py,sha256=xC04_nMK9YSVW8Eq8BOcvi2AFjKxlVG5uAwfdZ-_cak,4964
|
|
531
534
|
hestia_earth/models/utils/aggregated.py,sha256=sz6usleZmo_tC_hIvmGgYsX8-H0dulXmmhHK4EkA5Kg,4946
|
|
532
535
|
hestia_earth/models/utils/animalProduct.py,sha256=M5IunAKGY6oZv3j1Ascl34ywyeLWApqOIlBzbtlA2FE,721
|
|
533
536
|
hestia_earth/models/utils/aquacultureManagement.py,sha256=dxrbC1Xf140cohxTbSw6TxLAnAASWTdNZwBBam4yQnw,171
|
|
@@ -539,7 +542,7 @@ hestia_earth/models/utils/crop.py,sha256=kG054fryqPSBpmzvJFBy_CLiOdjrt7RMk5uTItO
|
|
|
539
542
|
hestia_earth/models/utils/cropResidue.py,sha256=_0Q35CrliJeo31xGHsPWe8A2oHxijdIsOrf3gBEqhlA,612
|
|
540
543
|
hestia_earth/models/utils/cropResidueManagement.py,sha256=nIDFjf39rDD10UHSVudfDyu-EiL261g8jyrgS-2aDKw,347
|
|
541
544
|
hestia_earth/models/utils/currency.py,sha256=f_ArJANb--pZq4LL49SXQ1AMX_oKroqwBXKRRQqZwsM,578
|
|
542
|
-
hestia_earth/models/utils/cycle.py,sha256=
|
|
545
|
+
hestia_earth/models/utils/cycle.py,sha256=JeYxIJOwdgZltkVQqFmEdzyGIpjWLa4oBt_H65OaRxU,16706
|
|
543
546
|
hestia_earth/models/utils/descriptive_stats.py,sha256=qOyG8_TpWYmaxZ0h99n9L71gDLLiVMrMf0ChtxnZLjw,8559
|
|
544
547
|
hestia_earth/models/utils/ecoClimateZone.py,sha256=NHFt-A9EiWXC6tUNIxkgOWUZOjj4I4uwJIP9ddDZegw,1112
|
|
545
548
|
hestia_earth/models/utils/emission.py,sha256=5Dz8Z4P6QXbYSvOzVcqJy3R_oZMrp77_Iwj5xZsxsKc,3769
|
|
@@ -557,7 +560,7 @@ hestia_earth/models/utils/measurement.py,sha256=rxrrOVdkDm-J0QVjCEapa4z4KY3hUw-b
|
|
|
557
560
|
hestia_earth/models/utils/organicFertiliser.py,sha256=2HY-a0EBzUw4DkEAXClLMXVCEZTKYf0BwFHBo7lQ5Tg,363
|
|
558
561
|
hestia_earth/models/utils/pesticideAI.py,sha256=6f8b-dFm3qr-eY049_eOvj_iDk4XBam61csozdDAvyA,2361
|
|
559
562
|
hestia_earth/models/utils/practice.py,sha256=tNadOzsrNlCEt801B815XaruJXzZ5yPASam7B3sWpXE,1091
|
|
560
|
-
hestia_earth/models/utils/product.py,sha256=
|
|
563
|
+
hestia_earth/models/utils/product.py,sha256=DhDgiReR8k9n9aaRM2xk3PIY3nfoE1ISKg9pKsBVzVQ,10143
|
|
561
564
|
hestia_earth/models/utils/productivity.py,sha256=bUBVCZInGqHuHZvHDSYPQkjWXQxOtTjEk-1-f_BsFOo,594
|
|
562
565
|
hestia_earth/models/utils/property.py,sha256=_9Wy0oZIBLsa-jOiGLokKehYLNdz-_7LfLaE4fb6SWM,5085
|
|
563
566
|
hestia_earth/models/utils/site.py,sha256=zEj2PtIghk-L_vVJidlXM6_ed7HTc2-ogP0sQSh49vw,3874
|
|
@@ -606,6 +609,7 @@ tests/models/cycle/test_coldDressedCarcassWeightPerHead.py,sha256=DrdI1TUmggeeQv
|
|
|
606
609
|
tests/models/cycle/test_completeness.py,sha256=Ku1ZSApGaACkXe3ae14yP01C4GssHMwlPG_UPrSytPo,1625
|
|
607
610
|
tests/models/cycle/test_concentrateFeed.py,sha256=tgkThL4g293CexLvb89ftO9UqUbHhNOxiP6QMmsqCCo,2013
|
|
608
611
|
tests/models/cycle/test_cropResidueManagement.py,sha256=vQWl7rDYLJjiKyBQlCiOA76LpzM4dI2t7JJ30uF8H9M,2020
|
|
612
|
+
tests/models/cycle/test_croppingIntensity.py,sha256=o5nA5tGbnk1IFdOhlN_Dh9oKcSq_yzSwkbBJzYfmYMg,1565
|
|
609
613
|
tests/models/cycle/test_cycleDuration.py,sha256=2KExiliuOa7_j88rJuPObJKZqq0xsRnFAb0ZEqc5KEM,846
|
|
610
614
|
tests/models/cycle/test_energyContentLowerHeatingValue.py,sha256=ZvHigQrtneKrRc8qr7rN8aj6tuA0ds0V6Brh0UzN_T8,1204
|
|
611
615
|
tests/models/cycle/test_excretaKgMass.py,sha256=xpuq0k5HKvnGmWdJy0GmIv6A4xYk2VDFB4BMb8J2Z0g,2925
|
|
@@ -615,6 +619,7 @@ tests/models/cycle/test_feedConversionRatio.py,sha256=V6zpZvUmBN0LciJW5YbHHaRQX6
|
|
|
615
619
|
tests/models/cycle/test_inorganicFertiliser.py,sha256=c-JDYC0qDK4JWlYDaGX53AcKfetz_YifSfdhy-v-WMo,642
|
|
616
620
|
tests/models/cycle/test_irrigatedTypeUnspecified.py,sha256=9YGwpDO_RHMaldvjJZ0xdrdfUzYDnLPt6nMJ2eRXSTI,2151
|
|
617
621
|
tests/models/cycle/test_liveAnimal.py,sha256=7fRPgEnIwcir-tYwUNnr6gc2e5_vnZi-t8EuuiPioeM,2139
|
|
622
|
+
tests/models/cycle/test_longFallowRatio.py,sha256=Aspp7l_L4gBVDmd9cj8doma6NX-509iWmzvkDpKhFf8,1502
|
|
618
623
|
tests/models/cycle/test_milkYield.py,sha256=7e5JJzLkc47OnQf3xni1Nkyq7N4xi1RglnE8caE9TfY,1778
|
|
619
624
|
tests/models/cycle/test_pastureGrass.py,sha256=hNRjBLYXGybzHPMfBOCgcRjGkDBmW0k_G6tn9TLrycY,1025
|
|
620
625
|
tests/models/cycle/test_pastureSystem.py,sha256=VlPn4mlaNimiu3liV5EMELJueUCqSSJ1l82yMV0UK90,1590
|
|
@@ -625,7 +630,8 @@ tests/models/cycle/test_residueBurnt.py,sha256=eBAzGR1210cBYH_s6oI1yCG6tVKUj9gGs
|
|
|
625
630
|
tests/models/cycle/test_residueIncorporated.py,sha256=esB_wnpf6W0PB24HW0YUgtfD9mxLDIY22eNVD4WAYFA,1719
|
|
626
631
|
tests/models/cycle/test_residueLeftOnField.py,sha256=_8CoSp-7z3BBLGN5Hv067FRYz8yDFw5fi_Cu5n6Rl3g,1290
|
|
627
632
|
tests/models/cycle/test_residueRemoved.py,sha256=R5v8lwGyz_4a9_X_LnugBEmgVgcisS5LTM5GFCtKIco,1278
|
|
628
|
-
tests/models/cycle/test_siteDuration.py,sha256=
|
|
633
|
+
tests/models/cycle/test_siteDuration.py,sha256=43Hjb0f2lXCRGqj-UmfLVmk7OGJswawtcA2q5wlffXk,1712
|
|
634
|
+
tests/models/cycle/test_siteUnusedDuration.py,sha256=5h9R3guw6ErU_sE5omoiK9Fpke74SmQWsJYWYURE9Fo,1532
|
|
629
635
|
tests/models/cycle/test_startDate.py,sha256=cGhqeZWkJdp6PNxmT0rJ5ZVsTAKm_8CyZKivAzRwSeI,592
|
|
630
636
|
tests/models/cycle/test_startDateDefinition.py,sha256=42BmsT1I7Jq_YMVN-VNU7a0fIZ2w3i5jgwy4H_r4dNM,920
|
|
631
637
|
tests/models/cycle/test_transformations.py,sha256=Ws_8KhNqeHogGFXTQ4qZXQ5Ph2I3ZUaY0yO1itFUHLk,464
|
|
@@ -697,14 +703,14 @@ tests/models/faostat2018/product/test_price.py,sha256=vUTT-FZVbXnDrwQVOgq8PWTDuF
|
|
|
697
703
|
tests/models/geospatialDatabase/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
698
704
|
tests/models/geospatialDatabase/test_aware.py,sha256=tbBBvXrOqdO0cMPJTa02UfhlwfosH8iNoJLzZNFs1NU,857
|
|
699
705
|
tests/models/geospatialDatabase/test_clayContent.py,sha256=KdkmsJMB1FsJXZCggcGWh3LlDKDDlwvcmSLEhZpdM_g,1177
|
|
700
|
-
tests/models/geospatialDatabase/test_croppingIntensity.py,sha256=
|
|
706
|
+
tests/models/geospatialDatabase/test_croppingIntensity.py,sha256=p7OQZOKuxcEhokFqIE4jj6GU3YwR9GtQqNwlhOGy7uI,1006
|
|
701
707
|
tests/models/geospatialDatabase/test_drainageClass.py,sha256=X75v6f8N5i40grULUNMvNOu_UC27VoahuW6BaQb19LY,1015
|
|
702
708
|
tests/models/geospatialDatabase/test_ecoClimateZone.py,sha256=ad0BBOhjl6uMUP_-QhAHEG3kTo7x3EaXuEahbbnx10E,1119
|
|
703
709
|
tests/models/geospatialDatabase/test_ecoregion.py,sha256=xPEXQKXpF4ghpVwuyZWC-4mmN9qywF-s_QKkmU40H70,868
|
|
704
710
|
tests/models/geospatialDatabase/test_erodibility.py,sha256=UW6SZS1nY3rzr2TqRcFDoq6a5KJ6ox-8L0k-im23R0s,1013
|
|
705
711
|
tests/models/geospatialDatabase/test_heavyWinterPrecipitation.py,sha256=1xv7L_b3ochbcu6y6TQrTUL0ZLr6aR44kAPsEN_1kAE,1026
|
|
706
712
|
tests/models/geospatialDatabase/test_histosol.py,sha256=Jc4N7Qt2zx09L8lj9Kjmr1q36T96MBNlasxGB0jD4EQ,1102
|
|
707
|
-
tests/models/geospatialDatabase/test_longFallowRatio.py,sha256=
|
|
713
|
+
tests/models/geospatialDatabase/test_longFallowRatio.py,sha256=VoYURFuOnlC8ozxcMLTzv99MGlymlVXd596T5MKVvOU,1004
|
|
708
714
|
tests/models/geospatialDatabase/test_nutrientLossToAquaticEnvironment.py,sha256=ZtoNdI_dB3Nk79Ts9JJrlda7z6HRE2cwCQHC2DiWCsY,1034
|
|
709
715
|
tests/models/geospatialDatabase/test_organicCarbonPerKgSoil.py,sha256=WomlRdVl4f6ooJz2YctPf0YGiNs-9To6XFwTdtpm0SQ,1024
|
|
710
716
|
tests/models/geospatialDatabase/test_potentialEvapotranspirationAnnual.py,sha256=6s4XDmKi__njKE_3tFMIAHr0a1w7X4t8uFRtihN_cm4,706
|
|
@@ -1094,8 +1100,8 @@ tests/models/utils/test_source.py,sha256=mv3vHZV5cjpoLA2I1109-YUkuzAiuhbRSnv_76_
|
|
|
1094
1100
|
tests/models/utils/test_term.py,sha256=M5Sa26v2gzQYbZ4H_fo7DspnaCx__-WtL-MULGapCWk,3509
|
|
1095
1101
|
tests/models/webbEtAl2012AndSintermannEtAl2012/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
1096
1102
|
tests/models/webbEtAl2012AndSintermannEtAl2012/test_nh3ToAirOrganicFertiliser.py,sha256=qi2FNXS5Af2WDtm7nq_FsprH3BfCF0XxnE0XHmC4aIY,2244
|
|
1097
|
-
hestia_earth_models-0.62.
|
|
1098
|
-
hestia_earth_models-0.62.
|
|
1099
|
-
hestia_earth_models-0.62.
|
|
1100
|
-
hestia_earth_models-0.62.
|
|
1101
|
-
hestia_earth_models-0.62.
|
|
1103
|
+
hestia_earth_models-0.62.6.dist-info/LICENSE,sha256=AC7h7GAgCZGJK_Tzh6LUCrML9gQEfowWwecEw2w54QM,1154
|
|
1104
|
+
hestia_earth_models-0.62.6.dist-info/METADATA,sha256=vTHt2mh8iCpLEmF569y6GKPZrhm2xg91Fjq3bnKFc1E,3343
|
|
1105
|
+
hestia_earth_models-0.62.6.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
|
1106
|
+
hestia_earth_models-0.62.6.dist-info/top_level.txt,sha256=1dqA9TqpOLTEgpqa-YBsmbCmmNU1y56AtfFGEceZ2A0,19
|
|
1107
|
+
hestia_earth_models-0.62.6.dist-info/RECORD,,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
import pytest
|
|
3
|
+
import json
|
|
4
|
+
from tests.utils import fixtures_path, fake_new_practice
|
|
5
|
+
|
|
6
|
+
from hestia_earth.models.cycle.croppingIntensity import MODEL, TERM_ID, run, _should_run
|
|
7
|
+
|
|
8
|
+
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
|
9
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.mark.parametrize(
|
|
13
|
+
'test_name,cycle,expected_should_run',
|
|
14
|
+
[
|
|
15
|
+
(
|
|
16
|
+
'no cycleDuration => no run',
|
|
17
|
+
{},
|
|
18
|
+
False
|
|
19
|
+
),
|
|
20
|
+
(
|
|
21
|
+
'with cycleDuration and wrong startDateDefinition => no run',
|
|
22
|
+
{
|
|
23
|
+
'cycleDuration': 100,
|
|
24
|
+
'startDateDefinition': 'random definition'
|
|
25
|
+
},
|
|
26
|
+
False
|
|
27
|
+
),
|
|
28
|
+
(
|
|
29
|
+
'with cycleDuration and correct startDateDefinition => run',
|
|
30
|
+
{
|
|
31
|
+
'cycleDuration': 100,
|
|
32
|
+
'startDateDefinition': 'harvest of previous crop'
|
|
33
|
+
},
|
|
34
|
+
True
|
|
35
|
+
)
|
|
36
|
+
]
|
|
37
|
+
)
|
|
38
|
+
@patch(f"{class_path}.is_plantation", return_value=False)
|
|
39
|
+
def test_should_run(mock_is_plantation, test_name, cycle, expected_should_run):
|
|
40
|
+
should_run = _should_run(cycle)
|
|
41
|
+
assert should_run == expected_should_run, test_name
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@patch(f"{class_path}._new_practice", side_effect=fake_new_practice)
|
|
45
|
+
def test_run(*args):
|
|
46
|
+
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
|
47
|
+
cycle = json.load(f)
|
|
48
|
+
|
|
49
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
|
50
|
+
expected = json.load(f)
|
|
51
|
+
|
|
52
|
+
result = run(cycle)
|
|
53
|
+
assert result == expected
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from unittest.mock import patch
|
|
2
|
+
import pytest
|
|
3
|
+
import json
|
|
4
|
+
from tests.utils import fixtures_path, fake_new_practice
|
|
5
|
+
|
|
6
|
+
from hestia_earth.models.cycle.longFallowRatio import MODEL, TERM_ID, run, _should_run
|
|
7
|
+
|
|
8
|
+
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
|
9
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.mark.parametrize(
|
|
13
|
+
'test_name,cycle,expected_should_run',
|
|
14
|
+
[
|
|
15
|
+
(
|
|
16
|
+
'no longFallowPeriod => no run',
|
|
17
|
+
{'practices': []},
|
|
18
|
+
False
|
|
19
|
+
),
|
|
20
|
+
(
|
|
21
|
+
'with longFallowPeriod no rotationDuration => no run',
|
|
22
|
+
{'practices': [{'term': {'@id': 'longFallowPeriod'}, 'value': [10]}]},
|
|
23
|
+
False
|
|
24
|
+
),
|
|
25
|
+
(
|
|
26
|
+
'with longFallowPeriod and rotationDuration => run',
|
|
27
|
+
{'practices': [
|
|
28
|
+
{'term': {'@id': 'longFallowPeriod'}, 'value': [10]},
|
|
29
|
+
{'term': {'@id': 'rotationDuration'}, 'value': [10]}
|
|
30
|
+
]},
|
|
31
|
+
True
|
|
32
|
+
)
|
|
33
|
+
]
|
|
34
|
+
)
|
|
35
|
+
def test_should_run(test_name, cycle, expected_should_run):
|
|
36
|
+
should_run, *args = _should_run(cycle)
|
|
37
|
+
assert should_run == expected_should_run, test_name
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@patch(f"{class_path}._new_practice", side_effect=fake_new_practice)
|
|
41
|
+
def test_run(*args):
|
|
42
|
+
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
|
43
|
+
cycle = json.load(f)
|
|
44
|
+
|
|
45
|
+
with open(f"{fixtures_folder}/result.jsonld", encoding='utf-8') as f:
|
|
46
|
+
expected = json.load(f)
|
|
47
|
+
|
|
48
|
+
result = run(cycle)
|
|
49
|
+
assert result == expected
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import pytest
|
|
2
3
|
from tests.utils import fixtures_path
|
|
3
4
|
|
|
4
5
|
from hestia_earth.models.cycle.siteDuration import MODEL, MODEL_KEY, _should_run, run
|
|
@@ -6,21 +7,47 @@ from hestia_earth.models.cycle.siteDuration import MODEL, MODEL_KEY, _should_run
|
|
|
6
7
|
fixtures_folder = f"{fixtures_path}/{MODEL}/{MODEL_KEY}"
|
|
7
8
|
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
@pytest.mark.parametrize(
|
|
11
|
+
'test_name,cycle,expected_should_run',
|
|
12
|
+
[
|
|
13
|
+
(
|
|
14
|
+
'no cycleDuration => no run',
|
|
15
|
+
{},
|
|
16
|
+
False
|
|
17
|
+
),
|
|
18
|
+
(
|
|
19
|
+
'with otherSites => no run',
|
|
20
|
+
{'otherSites': []},
|
|
21
|
+
False
|
|
22
|
+
),
|
|
23
|
+
(
|
|
24
|
+
'with cycleDuration => run',
|
|
25
|
+
{'cycleDuration': 100},
|
|
26
|
+
True
|
|
27
|
+
),
|
|
28
|
+
(
|
|
29
|
+
'with a crop product and wrong startDateDefinition => no run',
|
|
30
|
+
{
|
|
31
|
+
'cycleDuration': 100,
|
|
32
|
+
'products': [{'term': {'termType': 'crop'}, 'primary': True}],
|
|
33
|
+
'startDateDefinition': 'random definition'
|
|
34
|
+
},
|
|
35
|
+
False
|
|
36
|
+
),
|
|
37
|
+
(
|
|
38
|
+
'with a crop product and correct startDateDefinition => run',
|
|
39
|
+
{
|
|
40
|
+
'cycleDuration': 100,
|
|
41
|
+
'products': [{'term': {'termType': 'crop'}, 'primary': True}],
|
|
42
|
+
'startDateDefinition': 'harvest of previous crop'
|
|
43
|
+
},
|
|
44
|
+
True
|
|
45
|
+
)
|
|
46
|
+
]
|
|
47
|
+
)
|
|
48
|
+
def test_should_run_animal(test_name, cycle, expected_should_run):
|
|
12
49
|
should_run = _should_run(cycle)
|
|
13
|
-
assert
|
|
14
|
-
|
|
15
|
-
# with cycleDuration => run
|
|
16
|
-
cycle['cycleDuration'] = 100
|
|
17
|
-
should_run = _should_run(cycle)
|
|
18
|
-
assert should_run is True
|
|
19
|
-
|
|
20
|
-
# with otherSites => no run
|
|
21
|
-
cycle['otherSites'] = [{}]
|
|
22
|
-
should_run = _should_run(cycle)
|
|
23
|
-
assert not should_run
|
|
50
|
+
assert should_run == expected_should_run, test_name
|
|
24
51
|
|
|
25
52
|
|
|
26
53
|
def test_run():
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import pytest
|
|
3
|
+
from tests.utils import fixtures_path
|
|
4
|
+
|
|
5
|
+
from hestia_earth.models.cycle.siteUnusedDuration import MODEL, MODEL_KEY, _should_run, run
|
|
6
|
+
|
|
7
|
+
fixtures_folder = f"{fixtures_path}/{MODEL}/{MODEL_KEY}"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@pytest.mark.parametrize(
|
|
11
|
+
'test_name,cycle,expected_should_run',
|
|
12
|
+
[
|
|
13
|
+
(
|
|
14
|
+
'no siteDuration => no run',
|
|
15
|
+
{},
|
|
16
|
+
False
|
|
17
|
+
),
|
|
18
|
+
(
|
|
19
|
+
'with siteDuration => no run',
|
|
20
|
+
{'siteDuration': 100},
|
|
21
|
+
False
|
|
22
|
+
),
|
|
23
|
+
(
|
|
24
|
+
'with siteDuration and longFallowRatio => no run',
|
|
25
|
+
{
|
|
26
|
+
'siteDuration': 100,
|
|
27
|
+
'practices': [{'term': {'@id': 'longFallowRatio'}, 'value': [10]}]
|
|
28
|
+
},
|
|
29
|
+
False
|
|
30
|
+
),
|
|
31
|
+
(
|
|
32
|
+
'with siteDuration and longFallowRatio and cropland => run',
|
|
33
|
+
{
|
|
34
|
+
'siteDuration': 100,
|
|
35
|
+
'practices': [{'term': {'@id': 'longFallowRatio'}, 'value': [10]}],
|
|
36
|
+
'site': {'siteType': 'cropland'}
|
|
37
|
+
},
|
|
38
|
+
True
|
|
39
|
+
)
|
|
40
|
+
]
|
|
41
|
+
)
|
|
42
|
+
def test_should_run_animal(test_name, cycle, expected_should_run):
|
|
43
|
+
should_run, *args = _should_run(cycle)
|
|
44
|
+
assert should_run == expected_should_run, test_name
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_run():
|
|
48
|
+
with open(f"{fixtures_folder}/cycle.jsonld", encoding='utf-8') as f:
|
|
49
|
+
data = json.load(f)
|
|
50
|
+
|
|
51
|
+
with open(f"{fixtures_folder}/result.txt", encoding='utf-8') as f:
|
|
52
|
+
expected = f.read().strip()
|
|
53
|
+
|
|
54
|
+
value = run(data)
|
|
55
|
+
assert float(value) == float(expected)
|
|
@@ -9,14 +9,16 @@ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
@patch(f"{class_path}.is_plantation")
|
|
12
|
-
def test_should_run(mock_is_plantation):
|
|
12
|
+
def test_should_run(mock_is_plantation, *args):
|
|
13
13
|
cycle = {'@type': 'Cycle'}
|
|
14
14
|
|
|
15
15
|
mock_is_plantation.return_value = False
|
|
16
|
-
|
|
16
|
+
should_run = _should_run(cycle)
|
|
17
|
+
assert should_run is True
|
|
17
18
|
|
|
18
19
|
mock_is_plantation.return_value = True
|
|
19
|
-
|
|
20
|
+
should_run = _should_run(cycle)
|
|
21
|
+
assert not should_run
|
|
20
22
|
|
|
21
23
|
|
|
22
24
|
@patch(f"{class_path}._new_practice", side_effect=fake_new_practice)
|
|
@@ -9,14 +9,16 @@ fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
@patch(f"{class_path}.is_plantation")
|
|
12
|
-
def test_should_run(mock_is_plantation):
|
|
12
|
+
def test_should_run(mock_is_plantation, *args):
|
|
13
13
|
cycle = {'@type': 'Cycle'}
|
|
14
14
|
|
|
15
15
|
mock_is_plantation.return_value = False
|
|
16
|
-
|
|
16
|
+
should_run = _should_run(cycle)
|
|
17
|
+
assert should_run is True
|
|
17
18
|
|
|
18
19
|
mock_is_plantation.return_value = True
|
|
19
|
-
|
|
20
|
+
should_run = _should_run(cycle)
|
|
21
|
+
assert not should_run
|
|
20
22
|
|
|
21
23
|
|
|
22
24
|
@patch(f"{class_path}._new_practice", side_effect=fake_new_practice)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|