Example #1
0
 def _get_plot_data(self) -> Dict[str, Union[dict, int, list]]:
     return {
         "titles": get_titles(self.json_data),
         "num_stages": get_num_stages(self.json_data),
         "stage_names": get_stage_names(self.json_data),
         "node_levels": self.get_node_levels(),
         "wall_results": self.get_results(),
         "envelopes": self.get_envelopes(),
     }
Example #2
0
    def get(self, request: str) -> Union[dict, str, int, list]:
        """ Method to get information about the model.

        Parameters
        ----------
        request : str
            Options for request are: 'titles', 'file history', 'file version',
            'frew version', 'num stages', 'stage names', 'num nodes'.

        Returns
        -------
        return_value : Union[dict, str, int, list]
            The information requested about the model.

        Raises
        ------
        FrewError
            If `request` input is not a string or is not one of the options.

        """
        if not isinstance(request, str):
            raise FrewError("Request must be a string.")
        while request == "titles":
            return get_titles(self.json_data)
        while request == "file history":
            return get_file_history(self.json_data)
        while request == "file version":
            return get_file_version(self.json_data)
        while request == "frew version":
            return get_frew_version(self.json_data)
        while request == "num stages":
            return get_num_stages(self.json_data)
        while request == "stage names":
            return get_stage_names(self.json_data)
        while request == "num nodes":
            return get_num_nodes(self.json_data)
        raise FrewError("Please input a valid option.")
Example #3
0
def test_titles_initials(json_data):
    assert get_titles(json_data)["Initials"] == "FW"
Example #4
0
def test_titles_job_title(json_data):
    assert get_titles(json_data)["JobTitle"] == "Elizabeth House "
Example #5
0
def test_titles_job_number(json_data):
    assert get_titles(json_data)["JobNumber"] == "261026"
Example #6
0
def test_titles_index_error():
    with pytest.raises(FrewError):
        get_titles({"OasysHeader": []})
Example #7
0
def test_titles_key_error():
    with pytest.raises(FrewError):
        get_titles({"None": 1})
Example #8
0
    def results_to_excel(self, out_folder: str) -> None:
        """ Method to exports the wall results to an excel file where each
        sheet in the spreadsheet is a design case. The spreadsheet also
        a title sheet and the envelopes.

        Parameters
        ----------
        out_folder : str
            The folder path to save the results at.

        Returns
        -------
        None

        """
        if not os.path.exists(out_folder):
            raise FrewError(f"Path {out_folder} does not exist.")

        num_nodes: int = get_num_nodes(self.json_data)
        num_stages: int = get_num_stages(self.json_data)
        node_levels: List[float] = self.get_node_levels()
        wall_results: Dict[int, dict] = self.get_results()
        design_cases: List[str] = get_design_case_names(self.json_data)
        envelopes: Dict[str, dict] = self.get_envelopes()
        export_envelopes = pd.DataFrame(
            self._format_envelope_data(
                num_nodes, node_levels, envelopes, design_cases
            )
        )
        titles: Dict[str, str] = get_titles(self.json_data)
        export_titles = pd.DataFrame(self._format_titles_data(titles))

        job_title: str = titles["JobTitle"]
        uuid_str: str = str(uuid4()).split("-")[0]
        file_name: str = f"{job_title}_{uuid_str}_results.xlsx"

        export_data: Dict[str, dict] = {}
        for design_case in design_cases:
            export_data[design_case] = {
                "Node #": [],
                "Node levels (m)": [],
                "Stage": [],
                "Bending (kNm/m)": [],
                "Shear (kN/m)": [],
                "Displacement (mm)": [],
            }
            for stage in range(num_stages):
                node_array = list(range(1, num_nodes + 1))
                stage_array = [stage] * num_nodes
                bending_results = wall_results[stage][design_case]["bending"]
                shear_results = wall_results[stage][design_case]["shear"]
                displacement_results = wall_results[stage][design_case][
                    "displacement"
                ]

                export_data[design_case]["Node #"].extend(node_array)
                export_data[design_case]["Node levels (m)"].extend(node_levels)
                export_data[design_case]["Stage"].extend(stage_array)
                export_data[design_case]["Bending (kNm/m)"].extend(
                    bending_results
                )
                export_data[design_case]["Shear (kN/m)"].extend(shear_results)
                export_data[design_case]["Displacement (mm)"].extend(
                    displacement_results
                )
        try:
            with pd.ExcelWriter(os.path.join(out_folder, file_name)) as writer:
                export_titles.to_excel(
                    writer, sheet_name="Titles", index=False, header=False
                )
                export_envelopes.to_excel(
                    writer, sheet_name="Envelopes", index=False,
                )
                for design_case in design_cases:
                    export_data_df = pd.DataFrame(export_data[design_case])
                    export_data_df.to_excel(
                        writer, sheet_name=design_case, index=False,
                    )
        except PermissionError:
            raise FrewError(
                """
                Please make sure you have closed the results spreadsheet.
            """
            )