-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #346 from Blueprints-org/add_nen_soil_types
feat(soil_type): Add SoilType class
- Loading branch information
Showing
3 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
"""Module containing definitions of soil types and soil materials.""" | ||
|
||
from dataclasses import dataclass | ||
from enum import Enum | ||
|
||
|
||
class SoilMainTypes(Enum): | ||
"""Soil types based on grain size, representing the main portion of the soil mix.""" | ||
|
||
GRAVEL = "Gravel" | ||
SAND = "Sand" | ||
SILT = "Silt" | ||
LOAM = "Loam" | ||
CLAY = "Clay" | ||
PEAT = "Peat" | ||
|
||
|
||
class SoilMinorCompositions(Enum): | ||
"""Soil minor compositions, representing the minor portion of the soil mix.""" | ||
|
||
CLEAN = "Clean" | ||
|
||
SLITGHTLY_SILTY = "Slightly silty" | ||
VERY_SILTY = "Very silty" | ||
|
||
SLIGHTLY_CLAYEY = "Slightly clayey" | ||
VERY_CLAYEY = "Very clayey" | ||
|
||
SLIGHTLY_SANDY = "Slightly sandy" | ||
VERY_SANDY = "Very sandy" | ||
|
||
ORGANIC = "Organic" | ||
|
||
|
||
class SoilConsolidationStates(Enum): | ||
"""Consolidation states of the soil.""" | ||
|
||
UNCONSOLIDATED = "Unconsolidated" | ||
NORMALLY_CONSOLIDATED = "Normally consolidated" | ||
SLIGHTLY_OVERCONSOLIDATED = "Slightly consolidated" | ||
MODERATELY_OVERCONSOLIDATED = "Moderately overconsolidated" | ||
HIGHLY_OVERCONSOLIDATED = "Highly consolidated" | ||
|
||
|
||
class SoilConsistencies(Enum): | ||
"""Consistencies of the soil.""" | ||
|
||
# Clay-like consistencies | ||
VERY_SOFT = "Very soft" | ||
SOFT = "Soft" | ||
MEDIUM_STIFF = "Medium stiff" | ||
STIFF = "Stiff" | ||
HARD = "Hard" | ||
|
||
# Sand-like consistencies | ||
VERY_LOOSE = "Very loose" | ||
LOOSE = "Loose" | ||
MEDIUM_DENSE = "Medium dense" | ||
DENSE = "Dense" | ||
VERY_DENSE = "Very dense" | ||
|
||
|
||
@dataclass | ||
class SoilType: | ||
"""Class representing a soil type. | ||
Parameters | ||
---------- | ||
main_type : SoilMainTypes | ||
The soil type of the main portion of the soil mix. | ||
minor_composition : SoilMinorCompositions, optional | ||
The composition of the minor portion of the soil mix, by default None. | ||
consolidation_state : SoilConsolidationStates, optional | ||
The consolidation state of the soil, by default None. | ||
consistency : SoilConsistencies, optional | ||
The consistency of the soil, by default None. | ||
description : str, optional | ||
The custom description of the soil, by default None. | ||
""" | ||
|
||
main_type: SoilMainTypes | ||
minor_composition: SoilMinorCompositions | None = None | ||
consolidation_state: SoilConsolidationStates | None = None | ||
consistency: SoilConsistencies | None = None | ||
description: str | None = None | ||
|
||
@property | ||
def default_description(self) -> str: | ||
"""The default description of the soil type based on the `main_type`, `minor_composition`, `consolidation_state`, and `consistency`.""" | ||
default_description = self.main_type.value | ||
|
||
for prop in [self.minor_composition, self.consolidation_state, self.consistency]: | ||
if prop is not None: | ||
assert isinstance(prop, Enum) | ||
default_description += ", " + prop.value | ||
return default_description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""Tests of the materials soil module.""" | ||
|
||
import pytest | ||
|
||
from blueprints.materials.soil import SoilConsistencies, SoilConsolidationStates, SoilMainTypes, SoilMinorCompositions, SoilType | ||
|
||
|
||
class TestSoilType: | ||
"""Tests for the SoilType class.""" | ||
|
||
@pytest.mark.parametrize( | ||
("main_type", "minor_composition", "consolidation_state", "consistency", "description"), | ||
[ | ||
(SoilMainTypes.SAND, SoilMinorCompositions.CLEAN, None, SoilConsistencies.LOOSE, None), | ||
(SoilMainTypes.LOAM, SoilMinorCompositions.VERY_SANDY, None, None, None), | ||
(SoilMainTypes.PEAT, None, SoilConsolidationStates.NORMALLY_CONSOLIDATED, None, None), | ||
(SoilMainTypes.PEAT, None, SoilConsolidationStates.NORMALLY_CONSOLIDATED, None, "Veen, nvt"), | ||
], | ||
) | ||
def test_soil_type_init_valid_input( | ||
self, | ||
main_type: SoilMainTypes, | ||
minor_composition: SoilMinorCompositions, | ||
consolidation_state: SoilConsolidationStates | None, | ||
consistency: SoilConsistencies | None, | ||
description: str | None, | ||
) -> None: | ||
"""Tests initialization of SoilType for valid input.""" | ||
# Giving None as input | ||
soil_type = SoilType( | ||
main_type=main_type, | ||
minor_composition=minor_composition, | ||
consolidation_state=consolidation_state, | ||
consistency=consistency, | ||
description=description, | ||
) | ||
|
||
assert soil_type | ||
|
||
@pytest.mark.parametrize( | ||
("main_type", "minor_composition", "consolidation_state", "consistency", "expected_default_description"), | ||
[ | ||
(SoilMainTypes.CLAY, None, None, None, "Clay"), | ||
(SoilMainTypes.LOAM, SoilMinorCompositions.VERY_SANDY, None, None, "Loam, Very sandy"), | ||
(SoilMainTypes.SAND, SoilMinorCompositions.CLEAN, None, SoilConsistencies.LOOSE, "Sand, Clean, Loose"), | ||
(SoilMainTypes.PEAT, None, SoilConsolidationStates.NORMALLY_CONSOLIDATED, None, "Peat, Normally consolidated"), | ||
], | ||
) | ||
def test_soil_type_default_description( | ||
self, | ||
main_type: SoilMainTypes, | ||
minor_composition: SoilMinorCompositions, | ||
consolidation_state: SoilConsolidationStates | None, | ||
consistency: SoilConsistencies | None, | ||
expected_default_description: str, | ||
) -> None: | ||
"""Tests the property method `default_description` of SoilType.""" | ||
soil_type = SoilType( | ||
main_type=main_type, | ||
minor_composition=minor_composition, | ||
consolidation_state=consolidation_state, | ||
consistency=consistency, | ||
) | ||
|
||
assert soil_type.default_description == expected_default_description |