|
| 1 | +from decimal import Decimal |
| 2 | +from typing import Literal, Any |
| 3 | + |
| 4 | +from pydantic import Field, model_validator, computed_field, AliasChoices |
| 5 | + |
| 6 | +from sgf_parser.models import MethodData, Method, MethodType |
| 7 | +from sgf_parser.models.types import DPType |
| 8 | + |
| 9 | + |
| 10 | +class MethodDPData(MethodData): |
| 11 | + """ |
| 12 | + Dynamic Probing Data |
| 13 | + """ |
| 14 | + |
| 15 | + def __init__(self, **kwargs): |
| 16 | + super().__init__(**kwargs) |
| 17 | + |
| 18 | + depth: Decimal = Field(..., alias="D", description="Depth (m)") |
| 19 | + |
| 20 | + penetration_force: Decimal | None = Field(None, alias="A", description="Penetration force (kN)") |
| 21 | + penetration_rate: Decimal | None = Field( |
| 22 | + None, |
| 23 | + validation_alias=AliasChoices( |
| 24 | + "B", # mm/s |
| 25 | + "C", # s/0.2m |
| 26 | + ), |
| 27 | + description="Penetration rate (mm/s)", |
| 28 | + ) |
| 29 | + torque: Decimal | None = Field( |
| 30 | + None, |
| 31 | + validation_alias=AliasChoices( |
| 32 | + "V", # kNm |
| 33 | + "AB", # Nm |
| 34 | + ), |
| 35 | + description="Torque (kNm)", |
| 36 | + ) |
| 37 | + ramming: Decimal = Field(None, validation_alias=AliasChoices("S", "SA"), description="Ramming (Blow/0.2 m)") |
| 38 | + rotation_rate: Decimal | None = Field(None, alias="R", description="Rotation rate (rpm)") |
| 39 | + increased_rotation_rate: bool | None = Field(None, alias="AQ") |
| 40 | + |
| 41 | + |
| 42 | +class MethodDP(Method): |
| 43 | + """ |
| 44 | + Dynamic Probing (Swedish Hejarsondering) |
| 45 | + """ |
| 46 | + |
| 47 | + def __init__(self, **kwargs): |
| 48 | + super().__init__(**kwargs) |
| 49 | + |
| 50 | + name: str = "DP" |
| 51 | + method_type: Literal[MethodType.DP] = MethodType.DP |
| 52 | + method_data_type: type[MethodDPData] = MethodDPData |
| 53 | + |
| 54 | + type: DPType |
| 55 | + |
| 56 | + predrilling_depth: Decimal = Field(Decimal("0"), alias="HO") |
| 57 | + |
| 58 | + cone_type: str | None = Field( |
| 59 | + None, validation_alias=AliasChoices("KonTyp", "HN", "HC"), description="Type of cone used." |
| 60 | + ) |
| 61 | + cushion_type: str | None = Field(None, alias="DynTyp", description="Type of impact cushion used.") |
| 62 | + use_damper: bool | None = Field(None, alias="Gummi", description="Use of damper.") |
| 63 | + |
| 64 | + method_data: list[MethodDPData] = [] |
| 65 | + |
| 66 | + @computed_field |
| 67 | + def depth_top(self) -> Decimal | None: |
| 68 | + if not self.method_data: |
| 69 | + return None |
| 70 | + |
| 71 | + return min(method_data.depth for method_data in self.method_data) |
| 72 | + |
| 73 | + @computed_field |
| 74 | + def depth_base(self) -> Decimal | None: |
| 75 | + if not self.method_data: |
| 76 | + return None |
| 77 | + |
| 78 | + return max(method_data.depth for method_data in self.method_data) |
| 79 | + |
| 80 | + @model_validator(mode="before") |
| 81 | + @classmethod |
| 82 | + def set_operation(cls, data: Any) -> Any: |
| 83 | + if isinstance(data, dict): |
| 84 | + if "HM" in data and data["HM"] is not None: |
| 85 | + data["type"] = { |
| 86 | + "8": DPType.DPSH_A, |
| 87 | + "108A": DPType.DPSH_A, |
| 88 | + "108B": DPType.DPL, |
| 89 | + "108C": DPType.DPM, |
| 90 | + "108D": DPType.DPH, |
| 91 | + "108E": DPType.DPSH_B, |
| 92 | + }[data["HM"]] |
| 93 | + |
| 94 | + return data |
| 95 | + |
| 96 | + @computed_field |
| 97 | + def stopcode(self) -> int | None: |
| 98 | + if not self.method_data: |
| 99 | + return None |
| 100 | + |
| 101 | + return self.method_data[-1].comment_code |
0 commit comments