Created
December 23, 2022 08:48
-
-
Save afshawnlotfi/628c717dfed52649888809cabb6ac7a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class FastenerPredicter: | |
| @staticmethod | |
| def get_nominal_size( | |
| target_diameter: float, | |
| nominal_size_range: List[str], | |
| ): | |
| for nominal_size in nominal_size_range: | |
| nominal_diameter = float(nominal_size.split("-")[0].replace("M", "")) | |
| if target_diameter <= nominal_diameter: | |
| return nominal_size | |
| raise ValueError(f"nominal size for target diameter {target_diameter} could not be found") | |
| @staticmethod | |
| def get_nominal_length( | |
| target_length: float, | |
| nominal_length_range: List[float], | |
| ): | |
| for nominal_length in nominal_length_range: | |
| if target_length <= nominal_length: | |
| return nominal_length | |
| raise ValueError(f"nominal length for target length {target_length} could not be found") | |
| @staticmethod | |
| def predict_heatset(target_diameter: float, max_nut_thickness: float, type: str = "Hilitchi"): | |
| nominal_size_range = HeatSetNut.sizes(type) | |
| predicted_size = FastenerPredicter.get_nominal_size(target_diameter, nominal_size_range) | |
| heatset = HeatSetNut( | |
| size=predicted_size, | |
| fastener_type=type, | |
| simple=True, | |
| ) | |
| assert heatset.nut_thickness <= max_nut_thickness, f"heatset nut thickness {heatset.nut_thickness} is greater than max nut thickness {max_nut_thickness}" | |
| return heatset | |
| @staticmethod | |
| def predict_screw(target_diameter: float, target_length: float, type: str = "iso4762"): | |
| nominal_length_range = SocketHeadCapScrew.nominal_length_range[type] | |
| predicted_length = FastenerPredicter.get_nominal_length(target_length, nominal_length_range) | |
| nominal_size_range = SocketHeadCapScrew.sizes(type) | |
| predicted_size = FastenerPredicter.get_nominal_size(target_diameter, nominal_size_range) | |
| return SocketHeadCapScrew(predicted_size, predicted_length, type) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment