Skip to content

Commit

Permalink
Merge pull request #346 from Blueprints-org/add_nen_soil_types
Browse files Browse the repository at this point in the history
feat(soil_type): Add SoilType class
  • Loading branch information
PabloVasconez authored Oct 16, 2024
2 parents f6c97e7 + 69899ab commit bf87664
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ instance/

# Sphinx documentation
docs/_build/
docs/source/gen/*

# PyBuilder
.pybuilder/
target/


# Jupyter Notebook
.ipynb_checkpoints

Expand Down
96 changes: 96 additions & 0 deletions blueprints/materials/soil.py
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
65 changes: 65 additions & 0 deletions tests/materials/test_soil.py
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

0 comments on commit bf87664

Please sign in to comment.