From 66bba301c95a937b400d80d365add5882e8c6043 Mon Sep 17 00:00:00 2001 From: Chris McComb Date: Tue, 2 Jan 2024 15:03:41 -0500 Subject: [PATCH] Cleanup --- trussme/report.py | 4 ++-- trussme/truss.py | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/trussme/report.py b/trussme/report.py index a5f247f..36cfb37 100644 --- a/trussme/report.py +++ b/trussme/report.py @@ -6,7 +6,7 @@ import trussme.visualize -from .truss import Truss, Goals +from trussme.truss import Truss, Goals def report_to_str(truss: Truss, goals: Goals, with_figures: bool = True) -> str: @@ -20,7 +20,7 @@ def report_to_str(truss: Truss, goals: Goals, with_figures: bool = True) -> str: goals: Goals The goals against which to evaluate the truss with_figures: bool, default=True - Whether or not to include figures in the report + Whether to include figures in the report Returns ------- diff --git a/trussme/truss.py b/trussme/truss.py index b06d2b7..9d26d2c 100644 --- a/trussme/truss.py +++ b/trussme/truss.py @@ -326,10 +326,6 @@ def analyze(self): """ Analyze the truss - Parameters - ---------- - None - Returns ------- None @@ -623,7 +619,7 @@ def read_json(file_name: str) -> Truss: json_truss = json.load(file) truss = Truss() - material_library: list[Material] = json_truss["materials"] + current_material_library: list[Material] = json_truss["materials"] for joint in json_truss["joints"]: truss.add_free_joint(joint["coordinates"]) @@ -632,7 +628,9 @@ def read_json(file_name: str) -> Truss: for member in json_truss["members"]: material: Material = next( - item for item in material_library if item["name"] == member["material"] + item + for item in current_material_library + if item["name"] == member["material"] ) shape_params = member["shape"]["parameters"] if member["shape"]["name"] == "pipe": @@ -643,6 +641,12 @@ def read_json(file_name: str) -> Truss: shape = Square(**dict(shape_params)) elif member["shape"]["name"] == "box": shape = Box(**dict(shape_params)) + else: + raise ValueError( + "Shape type '" + + member["shape"]["name"] + + "' is a custom type and not supported." + ) truss.add_member( member["begin_joint"], member["end_joint"], material=material, shape=shape )