|
| 1 | +from decimal import Decimal |
| 2 | +from typing import Literal, Any |
| 3 | + |
| 4 | +from pydantic import Field, model_validator, computed_field |
| 5 | + |
| 6 | +from sgf_parser.models import MethodData, Method, MethodType |
| 7 | +from sgf_parser.models.types import Operation |
| 8 | + |
| 9 | + |
| 10 | +class MethodWSTData(MethodData): |
| 11 | + """ |
| 12 | + Weight Sounding Test (Swedish Viktsondering) Data |
| 13 | + """ |
| 14 | + |
| 15 | + def __init__(self, **kwargs): |
| 16 | + super().__init__(**kwargs) |
| 17 | + |
| 18 | + depth: Decimal = Field(..., alias="D", description="Depth (m)") |
| 19 | + turning: Decimal = Field(..., alias="H", description="Turning (half revolution/0.2 m)") |
| 20 | + load: Decimal = Field(..., alias="W", description="Load (kN)") |
| 21 | + penetration_rate: Decimal | None = Field(None, alias="B", description="Penetration rate (mm/s)") |
| 22 | + |
| 23 | + hammering: bool | None = Field(None, alias="AP") |
| 24 | + rotation_rate: Decimal | None = Field(None, alias="R", description="Rotation rate (rpm)") |
| 25 | + |
| 26 | + |
| 27 | +class MethodWST(Method): |
| 28 | + """ |
| 29 | + Weight Sounding Test (Swedish Viktsondering) |
| 30 | + """ |
| 31 | + |
| 32 | + def __init__(self, **kwargs): |
| 33 | + super().__init__(**kwargs) |
| 34 | + |
| 35 | + name: str = "WST" |
| 36 | + method_type: Literal[MethodType.WST] = MethodType.WST |
| 37 | + method_data_type: type[MethodWSTData] = MethodWSTData |
| 38 | + |
| 39 | + operation: Operation = Operation.MECHANICAL |
| 40 | + |
| 41 | + method_data: list[MethodWSTData] = [] |
| 42 | + |
| 43 | + @computed_field |
| 44 | + def depth_top(self) -> Decimal | None: |
| 45 | + if not self.method_data: |
| 46 | + return None |
| 47 | + |
| 48 | + return min(method_data.depth for method_data in self.method_data) |
| 49 | + |
| 50 | + @computed_field |
| 51 | + def depth_base(self) -> Decimal | None: |
| 52 | + if not self.method_data: |
| 53 | + return None |
| 54 | + |
| 55 | + return max(method_data.depth for method_data in self.method_data) |
| 56 | + |
| 57 | + @model_validator(mode="before") |
| 58 | + @classmethod |
| 59 | + def set_operation(cls, data: Any) -> Any: |
| 60 | + if isinstance(data, dict): |
| 61 | + if "HM" in data and data["HM"] is not None: |
| 62 | + data["operation"] = { |
| 63 | + "101": Operation.MANUAL, |
| 64 | + "102": Operation.MECHANICAL, |
| 65 | + }[data["HM"]] |
| 66 | + |
| 67 | + return data |
0 commit comments