classDikeProfile(DikeProfileProtocol):characteristic_points:List[Point]def__init__(self)->None:self.characteristic_points=[]@propertydefheight(self)->float:""" The greatest `y coordinate` in the `characteristic_points` (`List[Point]`). Returns: float: Highest y coordinate of the dike. """ifnotself.characteristic_points:returnmath.nanreturnmax([p.yforpinself.characteristic_points])@propertydefwidth(self)->float:""" The greatest `x coordinate` in the `characteristic_points` (`List[Point]`). Returns: float: Highest x coordinate of the dike. """ifnotself.characteristic_points:returnmath.nanreturnself.characteristic_points[-1].x@classmethoddeffrom_tuple_list(cls,tuple_list:List[Tuple[float,float]])->DikeProfile:""" Initializes a `DikeProfile` with the given `tuple_list` mapped into a `List[Point]` representing the `characteristic_points` property. Args: tuple_list (List[Tuple[float, float]]): List of float tuples representing the characteristic points. Raises: ValueError: When no `tuple_list` is given. Returns: DikeProfile: Instance with valid `characteristic points`. """ifnottuple_list:raiseValueError("tuple_list argument required.")_dike=cls()_dike.characteristic_points=list(map(Point,tuple_list))return_dike
Source code in dikesfordummies/dike/dike_profile.py
42434445464748495051525354555657585960
@classmethoddeffrom_tuple_list(cls,tuple_list:List[Tuple[float,float]])->DikeProfile:""" Initializes a `DikeProfile` with the given `tuple_list` mapped into a `List[Point]` representing the `characteristic_points` property. Args: tuple_list (List[Tuple[float, float]]): List of float tuples representing the characteristic points. Raises: ValueError: When no `tuple_list` is given. Returns: DikeProfile: Instance with valid `characteristic points`. """ifnottuple_list:raiseValueError("tuple_list argument required.")_dike=cls()_dike.characteristic_points=list(map(Point,tuple_list))return_dike
The greatest y coordinate in the characteristic_points (List[Point]).
Returns:
Name
Type
Description
float
float
Highest y coordinate of the dike.
Source code in dikesfordummies/dike/dike_profile.py
1819202122232425262728
@propertydefheight(self)->float:""" The greatest `y coordinate` in the `characteristic_points` (`List[Point]`). Returns: float: Highest y coordinate of the dike. """ifnotself.characteristic_points:returnmath.nanreturnmax([p.yforpinself.characteristic_points])
The greatest x coordinate in the characteristic_points (List[Point]).
Returns:
Name
Type
Description
float
float
Highest x coordinate of the dike.
Source code in dikesfordummies/dike/dike_profile.py
3031323334353637383940
@propertydefwidth(self)->float:""" The greatest `x coordinate` in the `characteristic_points` (`List[Point]`). Returns: float: Highest x coordinate of the dike. """ifnotself.characteristic_points:returnmath.nanreturnself.characteristic_points[-1].x
classDikeProfileBuilder:""" Class responsible of building a valid concrete `DikeProfileProtocol` with a given `DikeInput`. Raises: ValueError: When trying to `build` without a valid `DikeInput`. """dike_input:DikeInputdike_type:Type[DikeProfileProtocol]def__init__(self)->None:self.dike_input=Noneself.dike_type=Nonedef_build_waterside(self)->List[Point]:_p4=Point(0,self.dike_input.kruin_hoogte)_p3_x=_p4.x-((self.dike_input.kruin_hoogte-self.dike_input.buiten_berm_hoogte)*self.dike_input.buiten_talud)_p3=Point(_p3_x,self.dike_input.buiten_berm_hoogte)_p2_x=_p3.x-self.dike_input.buiten_berm_breedte_p2=Point(_p2_x,self.dike_input.buiten_berm_hoogte)_p1_x=_p2.x-((self.dike_input.buiten_berm_hoogte-self.dike_input.buiten_maaiveld)*self.dike_input.buiten_talud)_p1=Point(_p1_x,self.dike_input.buiten_maaiveld)return[_p1,_p2,_p3,_p4]def_build_polderside(self)->List[Point]:_x_p5=self.dike_input.kruin_breedte_p5=Point(_x_p5,self.dike_input.kruin_hoogte)_x_p6=_p5.x+((self.dike_input.kruin_hoogte-self.dike_input.binnen_berm_hoogte)*self.dike_input.binnen_talud)_p6=Point(_x_p6,self.dike_input.binnen_berm_hoogte)_x_p7=_p6.x+self.dike_input.binnen_berm_breedte_p7=Point(_x_p7,self.dike_input.binnen_berm_hoogte)_x_p8=_p7.x+((self.dike_input.binnen_berm_hoogte-self.dike_input.binnen_maaiveld)*self.dike_input.binnen_talud)_p8=Point(_x_p8,self.dike_input.binnen_maaiveld)return[_p5,_p6,_p7,_p8]defbuild(self)->DikeProfileProtocol:""" Builds a `DikeProfileProtocol` based on the given `DikeInput` and concrete type of `DikeProfileProtocol` Raises: ValueError: When the `dike_input` or `dike_type` are not provided. Returns: DikeProfileProtocol: Valid concrete instanced of DikeProfileProtocol. """ifnotself.dike_input:raiseValueError("Input Profile should be provided.")ifnotself.dike_type:raiseValueError(f"Dike type from {DikeProfileProtocol} should be provided.")_dike_points:List[Point]=[]_waterside=self._build_waterside()_polderside=self._build_polderside()_dike_points.extend(_waterside)_dike_points.extend(_polderside)_dike=self.dike_type()_dike.characteristic_points=_dike_pointsreturn_dike@classmethoddeffrom_input(cls,dike_input:DikeInput,dike_type:Optional[Type[DikeProfileProtocol]]=DikeProfile,)->DikeProfileBuilder:""" Initializes a `DikeProfileBuilder' with a valid `DikeInput` as `dike_input` parameter and a concrete type of `DikeProfileProtocol` as `dike_type`. Args: dike_input (DikeInput): Dike input to be set to the instance of the builder. dike_type (Optional[Type[DikeProfileProtocol]], optional): _description_. Defaults to DikeProfile. Returns: DikeProfileBuilder: Valid instance of a DikeProfileBuilder instance. """_builder=cls()_builder.dike_input=dike_input_builder.dike_type=dike_typereturn_builder
defbuild(self)->DikeProfileProtocol:""" Builds a `DikeProfileProtocol` based on the given `DikeInput` and concrete type of `DikeProfileProtocol` Raises: ValueError: When the `dike_input` or `dike_type` are not provided. Returns: DikeProfileProtocol: Valid concrete instanced of DikeProfileProtocol. """ifnotself.dike_input:raiseValueError("Input Profile should be provided.")ifnotself.dike_type:raiseValueError(f"Dike type from {DikeProfileProtocol} should be provided.")_dike_points:List[Point]=[]_waterside=self._build_waterside()_polderside=self._build_polderside()_dike_points.extend(_waterside)_dike_points.extend(_polderside)_dike=self.dike_type()_dike.characteristic_points=_dike_pointsreturn_dike
@classmethoddeffrom_input(cls,dike_input:DikeInput,dike_type:Optional[Type[DikeProfileProtocol]]=DikeProfile,)->DikeProfileBuilder:""" Initializes a `DikeProfileBuilder' with a valid `DikeInput` as `dike_input` parameter and a concrete type of `DikeProfileProtocol` as `dike_type`. Args: dike_input (DikeInput): Dike input to be set to the instance of the builder. dike_type (Optional[Type[DikeProfileProtocol]], optional): _description_. Defaults to DikeProfile. Returns: DikeProfileBuilder: Valid instance of a DikeProfileBuilder instance. """_builder=cls()_builder.dike_input=dike_input_builder.dike_type=dike_typereturn_builder
classDikeInput:""" Data structure containing the necessary data to generate Characteristic Points. """def__init__(self)->None:self.buiten_maaiveld=math.nanself.buiten_talud=math.nanself.buiten_berm_hoogte=math.nanself.buiten_berm_breedte=math.nanself.kruin_hoogte=math.nanself.kruin_breedte=math.nanself.binnen_talud=math.nanself.binnen_berm_hoogte=math.nanself.binnen_berm_breedte=math.nanself.binnen_maaiveld=math.nan@classmethoddeffrom_list(cls,values:List[float])->DikeInput:""" Initializes a `DikeInput` with the given values mapped to the class' parameters. Args: values (List[float]): Values representing a Dike's profile data. Raises: ValueError: When the values given do not match the amount expected. Returns: DikeInput: Instanciated object with set data. """_input=cls()_dike_keys=_input.__dict__.keys()ifnotvaluesorlen(values)!=len(_dike_keys):ifnotvalues:values=[]raiseValueError("Expected {} values, {} provided".format(len(_dike_keys),len(values)))foridx,keyinenumerate(_dike_keys):_input.__dict__[key]=values[idx]return_input
@classmethoddeffrom_list(cls,values:List[float])->DikeInput:""" Initializes a `DikeInput` with the given values mapped to the class' parameters. Args: values (List[float]): Values representing a Dike's profile data. Raises: ValueError: When the values given do not match the amount expected. Returns: DikeInput: Instanciated object with set data. """_input=cls()_dike_keys=_input.__dict__.keys()ifnotvaluesorlen(values)!=len(_dike_keys):ifnotvalues:values=[]raiseValueError("Expected {} values, {} provided".format(len(_dike_keys),len(values)))foridx,keyinenumerate(_dike_keys):_input.__dict__[key]=values[idx]return_input