diff --git a/LadybugTools_Adapter/AdapterActions/Execute.cs b/LadybugTools_Adapter/AdapterActions/Execute.cs new file mode 100644 index 00000000..f3299eba --- /dev/null +++ b/LadybugTools_Adapter/AdapterActions/Execute.cs @@ -0,0 +1,263 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.Engine.Adapter; +using BH.Engine.LadybugTools; +using BH.oM.Adapter; +using BH.oM.Adapter.Commands; +using BH.oM.Base; +using BH.oM.Data.Requests; +using BH.oM.LadybugTools; +using BH.oM.Python; +using BH.Engine.Python; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace BH.Adapter.LadybugTools +{ + public partial class LadybugToolsAdapter : BHoMAdapter + { + bool m_executeSuccess = false; + public override Output, bool> Execute(IExecuteCommand command, ActionConfig actionConfig = null) + { + m_executeSuccess = false; + Output, bool> output = new Output, bool>() { Item1 = new List(), Item2 = false }; + + List temp = IRunCommand(command); + + output.Item1 = temp; + output.Item2 = m_executeSuccess; + + return output; + } + + /**************************************************/ + /* Public methods - Interface */ + /**************************************************/ + + public List IRunCommand(IExecuteCommand command) + { + if (command == null) + { + BH.Engine.Base.Compute.RecordError("Please input a valid Ladybug Command to execute."); + return new List(); + } + + return RunCommand(command as dynamic); + } + + /**************************************************/ + /* Private methods - Run Ladybug Command */ + /**************************************************/ + + private List RunCommand(GetMaterialCommand command) + { + PythonEnvironment env = Engine.LadybugTools.Compute.InstallPythonEnv_LBT(true); + LadybugConfig config = new LadybugConfig() + { + JsonFile = new FileSettings() + { + FileName = $"LBTBHoM_Materials_{DateTime.Now:yyyyMMdd}.json", + Directory = Path.GetTempPath() + } + }; + + if (!File.Exists(config.JsonFile.GetFullFileName())) + { + string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_material.py"); + + string cmdCommand = $"{env.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\""; + + Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true); + } + + List materialObjects = Pull(new FilterRequest(), actionConfig: config).ToList(); + + m_executeSuccess = true; + return materialObjects.Where(m => (m as IEnergyMaterialOpaque).Name.Contains(command.Filter)).ToList(); + } + + /**************************************************/ + + private List RunCommand(GetTypologyCommand command) + { + PythonEnvironment env = Engine.LadybugTools.Compute.InstallPythonEnv_LBT(true); + LadybugConfig config = new LadybugConfig() + { + JsonFile = new FileSettings() + { + FileName = $"LBTBHoM_Typologies_{DateTime.Now:yyyyMMdd}.json", + Directory = Path.GetTempPath() + } + }; + + if (!File.Exists(config.JsonFile.GetFullFileName())) + { + string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_typology.py"); + + string cmdCommand = $"{env.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\""; + + Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true); + } + + List typologyObjects = Pull(new FilterRequest(), actionConfig: config).ToList(); + + m_executeSuccess = true; + return typologyObjects.Where(m => (m as Typology).Name.Contains(command.Filter)).ToList(); + } + + /**************************************************/ + + private List RunCommand(RunSimulationCommand command) + { + // validation prior to passing to Python + if (command.EpwFile == null) + { + BH.Engine.Base.Compute.RecordError($"{nameof(command.EpwFile)} input cannot be null."); + return null; + } + + if (!File.Exists(command.EpwFile.GetFullFileName())) + { + BH.Engine.Base.Compute.RecordError($"{command.EpwFile.GetFullFileName()} does not exist."); + return null; + } + + if (command.GroundMaterial == null) + { + BH.Engine.Base.Compute.RecordError($"{nameof(command.GroundMaterial)} input cannot be null."); + return null; + } + + if (command.ShadeMaterial == null) + { + BH.Engine.Base.Compute.RecordError($"{nameof(command.ShadeMaterial)} input cannot be null."); + return null; + } + + // construct adapter and config + LadybugConfig config = new LadybugConfig() + { + JsonFile = new FileSettings() + { + FileName = $"LBTBHoM_{Guid.NewGuid()}.json", + Directory = Path.GetTempPath() + } + }; + + // construct the base object and file to be passed to Python for simulation + SimulationResult simulationResult = new SimulationResult() + { + EpwFile = Path.GetFullPath(command.EpwFile.GetFullFileName()).Replace(@"\", "/"), + GroundMaterial = command.GroundMaterial, + ShadeMaterial = command.ShadeMaterial, + Name = Engine.LadybugTools.Compute.SimulationID(command.EpwFile.GetFullFileName(), command.GroundMaterial, command.ShadeMaterial) + }; + + // push object to json file + Push(new List() { simulationResult }, actionConfig: config); + + // locate the Python executable and file containing the simulation code + PythonEnvironment env = Engine.LadybugTools.Compute.InstallPythonEnv_LBT(true); + string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "simulation_result.py"); + + // run the simulation + string cmdCommand = $"{env.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\""; + Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true); + + // reload from Python results + List simulationResultPopulated = Pull(new FilterRequest(), actionConfig: config).ToList(); + + // remove temporary file + File.Delete(config.JsonFile.GetFullFileName()); + + m_executeSuccess = true; + return simulationResultPopulated; + } + + /**************************************************/ + + private List RunCommand(RunExternalComfortCommand command) + { + if (command.SimulationResult == null) + { + BH.Engine.Base.Compute.RecordError($"{nameof(command.SimulationResult)} input cannot be null."); + return null; + } + + if (command.Typology == null) + { + BH.Engine.Base.Compute.RecordError($"{nameof(command.Typology)} input cannot be null."); + return null; + } + + LadybugConfig config = new LadybugConfig() + { + JsonFile = new FileSettings() + { + FileName = $"LBTBHoM_{Guid.NewGuid()}.json", + Directory = Path.GetTempPath() + } + }; + + // construct the base object + ExternalComfort externalComfort = new ExternalComfort() + { + SimulationResult = command.SimulationResult, + Typology = command.Typology, + }; + + // push objects to json file + Push(new List() { externalComfort }, actionConfig: config); + + // locate the Python executable and file containing the simulation code + PythonEnvironment env = Engine.LadybugTools.Compute.InstallPythonEnv_LBT(true); + string script = Path.Combine(Engine.Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "external_comfort.py"); + + // run the calculation + string cmdCommand = $"{env.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\""; + Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true); + + // reload from Python results + List externalComfortPopulated = Pull(new FilterRequest(), actionConfig: config).ToList(); + + // remove temporary file + File.Delete(config.JsonFile.GetFullFileName()); + + m_executeSuccess = true; + return externalComfortPopulated; + } + + /**************************************************/ + /* Private methods - Fallback */ + /**************************************************/ + + private List RunCommand(IExecuteCommand command) + { + BH.Engine.Base.Compute.RecordError($"The command {command.GetType().FullName} is not valid for the LadybugTools Adapter. Please use a LadybugCommand, or use the correct adapter for the input command."); + return new List(); + } + } +} diff --git a/LadybugTools_Adapter/LadybugTools_Adapter.csproj b/LadybugTools_Adapter/LadybugTools_Adapter.csproj index 305a414a..329c1cf5 100644 --- a/LadybugTools_Adapter/LadybugTools_Adapter.csproj +++ b/LadybugTools_Adapter/LadybugTools_Adapter.csproj @@ -67,6 +67,16 @@ False False + + $(ProgramData)\BHoM\Assemblies\Python_Engine.dll + False + False + + + $(ProgramData)\BHoM\Assemblies\Python_oM.dll + False + False + $(ProgramData)\BHoM\Assemblies\Serialiser_Engine.dll False diff --git a/LadybugTools_Engine/Compute/ExternalComfort.cs b/LadybugTools_Engine/Compute/ExternalComfort.cs deleted file mode 100644 index 47263dc0..00000000 --- a/LadybugTools_Engine/Compute/ExternalComfort.cs +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using System.ComponentModel; -using System.IO; -using System; - -using BH.Engine.Serialiser; -using BH.oM.Base.Attributes; -using BH.oM.LadybugTools; -using BH.oM.Python; - -namespace BH.Engine.LadybugTools -{ - public static partial class Compute - { - [Description("Run an External Comfort simulation and return results.")] - [Input("simulationResult", "A simulation result object.")] - [Input("typology", "An ExternalComfortTypology.")] - [Output("externalComfort", "An external comfort result object containing simulation results.")] - public static ExternalComfort ExternalComfort(SimulationResult simulationResult, Typology typology) - { - if (simulationResult == null) - { - BH.Engine.Base.Compute.RecordError($"{nameof(simulationResult)} input cannot be null."); - return null; - } - - if (typology == null) - { - BH.Engine.Base.Compute.RecordError($"{nameof(typology)} input cannot be null."); - return null; - } - - // construct the base object - ExternalComfort externalComfort = new ExternalComfort() - { - SimulationResult = simulationResult, - Typology = typology, - }; - string jsonPreSimulation = externalComfort.ToJson(); - string jsonFile = Path.Combine(Path.GetTempPath(), $"LBTBHoM_{Guid.NewGuid()}.json"); - File.WriteAllText(jsonFile, jsonPreSimulation); - - // locate the Python executable and file containing the simulation code - PythonEnvironment env = InstallPythonEnv_LBT(true); - string script = Path.Combine(Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "external_comfort.py"); - - // run the calculation - string command = $"{env.Executable} {script} -j \"{jsonFile}\""; - Python.Compute.RunCommandStdout(command: command, hideWindows: true); - - // reload from Python results - string jsonPostSimulation = File.ReadAllText(jsonFile); - BH.oM.LadybugTools.ExternalComfort externalComfortPopulated = (BH.oM.LadybugTools.ExternalComfort)BH.Engine.Serialiser.Convert.FromJson(jsonPostSimulation); - - // remove temporary file - File.Delete(jsonFile); - - return externalComfortPopulated; - } - } -} diff --git a/LadybugTools_Engine/Compute/SimulationResult.cs b/LadybugTools_Engine/Compute/SimulationResult.cs deleted file mode 100644 index e2bed8f6..00000000 --- a/LadybugTools_Engine/Compute/SimulationResult.cs +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - - -using BH.oM.Python; -using BH.oM.Base.Attributes; -using System.ComponentModel; -using System.IO; -using BH.oM.LadybugTools; -using System; -using BH.Engine.Serialiser; - -namespace BH.Engine.LadybugTools -{ - public static partial class Compute - { - [Description("Run a simulation and return results.")] - [Input("epwFile", "An EPW file.")] - [Input("groundMaterial", "A ground material.")] - [Input("shadeMaterial", "A shade material.")] - [Output("simulationResult", "An simulation result object containing simulation results.")] - [PreviousVersion("7.0", "BH.Engine.LadybugTools.Compute.SimulationResult(System.String, BH.oM.LadybugTools.ILadybugToolsMaterial, BH.oM.LadybugTools.ILadybugToolsMaterial)")] - public static SimulationResult SimulationResult(string epwFile, IEnergyMaterialOpaque groundMaterial, IEnergyMaterialOpaque shadeMaterial) - { - // validation prior to passing to Python - if (epwFile == null) - { - BH.Engine.Base.Compute.RecordError($"{nameof(epwFile)} input cannot be null."); - return null; - } - if (!File.Exists(epwFile)) - { - BH.Engine.Base.Compute.RecordError($"{epwFile} does not exist."); - return null; - } - - if (groundMaterial == null) - { - BH.Engine.Base.Compute.RecordError($"{nameof(groundMaterial)} input cannot be null."); - return null; - } - - if (shadeMaterial == null) - { - BH.Engine.Base.Compute.RecordError($"{nameof(shadeMaterial)} input cannot be null."); - return null; - } - - // construct the base object and file to be passed to Python for simulation - SimulationResult simulationResult = new SimulationResult() - { - EpwFile = Path.GetFullPath(epwFile).Replace(@"\", "/"), - GroundMaterial = groundMaterial, - ShadeMaterial = shadeMaterial, - Name = Compute.SimulationID(epwFile, groundMaterial, shadeMaterial) - }; - string jsonPreSimulation = simulationResult.ToJson(); - string jsonFile = Path.Combine(Path.GetTempPath(), $"LBTBHoM_{Guid.NewGuid()}.json"); - File.WriteAllText(jsonFile, jsonPreSimulation); - - // locate the Python executable and file containing the simulation code - PythonEnvironment env = InstallPythonEnv_LBT(true); - string script = Path.Combine(Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "simulation_result.py"); - - // run the simulation - string command = $"{env.Executable} {script} -j \"{jsonFile}\""; - Python.Compute.RunCommandStdout(command: command, hideWindows: true); - - // reload from Python results - string jsonPostSimulation = File.ReadAllText(jsonFile); - SimulationResult simulationResultPopulated = (SimulationResult)BH.Engine.Serialiser.Convert.FromJson(jsonPostSimulation); - - // remove temporary file - File.Delete(jsonFile); - - return simulationResultPopulated; - } - } -} diff --git a/LadybugTools_Engine/Convert/ToPython.cs b/LadybugTools_Engine/Convert/ToPython.cs deleted file mode 100644 index e39a2e13..00000000 --- a/LadybugTools_Engine/Convert/ToPython.cs +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base.Attributes; -using System.ComponentModel; -using System.Collections.Generic; -using BH.oM.Geometry; -using BH.Engine.Serialiser; -using BH.oM.LadybugTools; -using System.Web.Script.Serialization; - -namespace BH.Engine.LadybugTools -{ - public static partial class Convert - { - [Description("Convert this object to its Ladybug JSON string.")] - [Input("point", "A Point object.")] - [Output("str", "The JSON string representation of this BHoM object, ready for deserialistion in Python using Ladybug.")] - public static string ToPythonString(this Point point) - { - JavaScriptSerializer serializer = new JavaScriptSerializer(); - var dict = serializer.Deserialize>(point.ToJson()); - dict["Type"] = "Point3D"; - var dictConverted = ToSnakeCase(dict); - string json = serializer.Serialize(dictConverted); - return json; - } - - [Description("Convert this object to its Ladybug JSON string.")] - [Input("collection", "A HourlyContinuousCollection object.")] - [Output("str", "The JSON string representation of this BHoM object, ready for deserialistion in Python using Ladybug.")] - public static string ToPythonString(this HourlyContinuousCollection collection) - { - JavaScriptSerializer serializer = new JavaScriptSerializer(); - var dict = serializer.Deserialize>(collection.ToJson()); - var dictConverted = ToSnakeCase(dict); - string json = serializer.Serialize(dictConverted); - return json.Replace("data__type", "data_type"); - } - } -} diff --git a/LadybugTools_Engine/LadybugTools_Engine.csproj b/LadybugTools_Engine/LadybugTools_Engine.csproj index 3ab642cb..53d6c13b 100644 --- a/LadybugTools_Engine/LadybugTools_Engine.csproj +++ b/LadybugTools_Engine/LadybugTools_Engine.csproj @@ -17,6 +17,11 @@ + + $(ProgramData)\BHoM\Assemblies\Adapter_Engine.dll + False + False + $(ProgramData)\BHoM\Assemblies\Analytical_oM.dll False @@ -77,11 +82,6 @@ False False - - ..\libs\System.Web.Extensions.dll - False - False - diff --git a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/bhom/wrapped/get_material.py b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/bhom/wrapped/get_material.py index a6de8bc0..720c0798 100644 --- a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/bhom/wrapped/get_material.py +++ b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/bhom/wrapped/get_material.py @@ -9,10 +9,9 @@ def main(json_file: str) -> None: """Create a file containing all default materials.""" try: from ladybugtools_toolkit.external_comfort.material import Materials - from ladybugtools_toolkit.bhom.to_bhom import material_to_bhom with open(json_file, "w") as f: - json.dump([material_to_bhom(material.value) for material in Materials], f) + json.dump([material.value.to_dict() for material in Materials], f) except Exception as e: print(e) diff --git a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_externalcomfortbase.py b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_externalcomfortbase.py index d6c1bac8..399f1e60 100644 --- a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_externalcomfortbase.py +++ b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_externalcomfortbase.py @@ -123,19 +123,16 @@ def __repr__(self) -> str: def to_dict(self) -> str: """Convert this object to a dictionary.""" - attr_dict = {} for attr in _ATTRIBUTES: if getattr(self, attr): - attr_dict[pascalcase(attr)] = hourlycontinuouscollection_to_bhom( - getattr(self, attr) - ) + attr_dict[attr] = getattr(self, attr).to_dict() d = { **{ - "_t": "BH.oM.LadybugTools.ExternalComfort", - "SimulationResult": self.simulation_result.to_dict(), - "Typology": self.typology.to_dict(), + "type": "ExternalComfort", + "simulation_result": self.simulation_result.to_dict(), + "typology": self.typology.to_dict(), }, **attr_dict, } @@ -143,10 +140,7 @@ def to_dict(self) -> str: @classmethod def from_dict(cls, d: dict) -> "ExternalComfort": - """_""" - - d = convert_keys_to_snake_case(d) - + """Create a dictionary from this object.""" if isinstance(d["simulation_result"], dict): d["simulation_result"] = SimulationResult.from_dict(d["simulation_result"]) @@ -157,6 +151,10 @@ def from_dict(cls, d: dict) -> "ExternalComfort": if d.get(attr, None): if isinstance(d[attr], dict): d[attr] = HourlyContinuousCollection.from_dict(d[attr]) + else: + d[attr] = None + else: + d[attr] = None return cls( simulation_result=d["simulation_result"], diff --git a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_shelterbase.py b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_shelterbase.py index f94c3737..c046a449 100644 --- a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_shelterbase.py +++ b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_shelterbase.py @@ -101,28 +101,26 @@ def to_dict(self) -> str: """Convert this object to a dictionary.""" point_dicts = [] for point in self.vertices: - point_dicts.append(point3d_to_bhom(point)) + point_dict = point.to_dict() + point_dict["type"] = "Point3D" + point_dicts.append(point_dict) d = { - "_t": "BH.oM.LadybugTools.Shelter", - "Vertices": point_dicts, - "WindPorosity": self.wind_porosity, - "RadiationPorosity": self.radiation_porosity, + "type": "Shelter", + "vertices": point_dicts, + "wind_porosity": self.wind_porosity, + "radiation_porosity": self.radiation_porosity, } return d @classmethod def from_dict(cls, d: dict) -> "Shelter": """Create this object from a dictionary.""" - - d = convert_keys_to_snake_case(d) - - new_verts = [] - for vert in d["vertices"]: - if isinstance(vert, dict): - vert["Type"] = "Point3D" - new_verts.append(Point3D.from_dict(vert)) - d["vertices"] = new_verts + new_vertices = [] + for vertex in d["vertices"]: + if isinstance(vertex, dict): + new_vertices.append(Point3D.from_dict(vertex)) + d["vertices"] = new_vertices return cls( vertices=d["vertices"], diff --git a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_simulatebase.py b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_simulatebase.py index 079a03f2..b032ee80 100644 --- a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_simulatebase.py +++ b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_simulatebase.py @@ -439,24 +439,21 @@ def __post_init__(self): def to_dict(self) -> dict[str, Any]: """Convert this object to a dictionary.""" - - ground_material_dict = material_to_bhom(self.ground_material) - shade_material_dict = material_to_bhom(self.shade_material) + ground_material_dict = self.ground_material.to_dict() + shade_material_dict = self.shade_material.to_dict() attr_dict = {} for attr in _ATTRIBUTES: if getattr(self, attr): - attr_dict[pascalcase(attr)] = hourlycontinuouscollection_to_bhom( - getattr(self, attr) - ) + attr_dict[attr] = getattr(self, attr).to_dict() d = { **{ - "_t": "BH.oM.LadybugTools.SimulationResult", - "EpwFile": self.epw_file.as_posix(), - "GroundMaterial": ground_material_dict, - "ShadeMaterial": shade_material_dict, - "Identifier": self.identifier, + "type": "SimulationResult", + "epw_file": self.epw_file.as_posix(), + "ground_material": ground_material_dict, + "shade_material": shade_material_dict, + "identifier": self.identifier, }, **attr_dict, } @@ -466,9 +463,6 @@ def to_dict(self) -> dict[str, Any]: @classmethod def from_dict(cls, d: dict[str, Any]) -> "SimulationResult": """Create this object from a dictionary.""" - - d = convert_keys_to_snake_case(d) - if isinstance(d["ground_material"], dict): d["ground_material"] = dict_to_material(d["ground_material"]) @@ -479,6 +473,8 @@ def from_dict(cls, d: dict[str, Any]) -> "SimulationResult": if d.get(attr, None): if isinstance(d[attr], dict): d[attr] = HourlyContinuousCollection.from_dict(d[attr]) + else: + d[attr] = None return cls( epw_file=d["epw_file"], diff --git a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_typologybase.py b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_typologybase.py index 1fd98a6a..57907014 100644 --- a/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_typologybase.py +++ b/LadybugTools_Engine/Python/src/ladybugtools_toolkit/external_comfort/_typologybase.py @@ -89,20 +89,18 @@ def to_dict(self) -> str: shelter_dicts.append(shelter.to_dict()) d = { - "_t": "BH.oM.LadybugTools.Typology", - "Identifier": self.identifier, - "Shelters": shelter_dicts, - "EvaporativeCoolingEffect": self.evaporative_cooling_effect, - "TargetWindSpeed": self.target_wind_speed, - "RadiantTemperatureAdjustment": self.radiant_temperature_adjustment, + "type": "Typology", + "identifier": self.identifier, + "shelters": shelter_dicts, + "evaporative_cooling_effect": self.evaporative_cooling_effect, + "target_wind_speed": self.target_wind_speed, + "radiant_temperature_adjustment": self.radiant_temperature_adjustment, } return d @classmethod def from_dict(cls, d: dict) -> "Shelter": """Create this object from a dictionary.""" - d = convert_keys_to_snake_case(d) - new_shelters = [] for shelter in d["shelters"]: if isinstance(shelter, dict): diff --git a/LadybugTools_Engine/Query/GetMaterial.cs b/LadybugTools_Engine/Query/GetMaterial.cs deleted file mode 100644 index 083aa634..00000000 --- a/LadybugTools_Engine/Query/GetMaterial.cs +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base.Attributes; -using BH.oM.LadybugTools; -using System.Linq; -using System.Collections.Generic; -using System.ComponentModel; -using BH.oM.Python; -using System.IO; -using System; - -namespace BH.Engine.LadybugTools -{ - public static partial class Query - { - [Description("Returns a list of materials from the Python Materials list.")] - [Input("filter", "Text to filter the resultant list by. Filter applies to the material identifier. Leave blank to return all materials.")] - [Output("materials", "A list of materials.")] - public static List GetMaterial(string filter = "") - { - PythonEnvironment env = Compute.InstallPythonEnv_LBT(true); - - string jsonFile = Path.Combine(Path.GetTempPath(), $"LBTBHoM_Materials_{DateTime.Now:yyyyMMdd}.json"); - - if (!File.Exists(jsonFile)) - { - string script = Path.Combine(Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_material.py"); - - string command = $"{env.Executable} {script} -j \"{jsonFile}\""; - - Python.Compute.RunCommandStdout(command: command, hideWindows: true); - } - - string jsonContent = File.ReadAllText(jsonFile); - - List materials = (List)BH.Engine.Serialiser.Convert.FromJsonArray(jsonContent); - - List materialObjects = new List(); - foreach (object materialObject in materials) - { - materialObjects.Add((IEnergyMaterialOpaque)materialObject); - } - - return materialObjects.Where(m => m.Name.Contains(filter)).ToList(); - } - } -} diff --git a/LadybugTools_Engine/Query/GetTypology.cs b/LadybugTools_Engine/Query/GetTypology.cs deleted file mode 100644 index f2505bc5..00000000 --- a/LadybugTools_Engine/Query/GetTypology.cs +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. - * - * Each contributor holds copyright over their respective contributions. - * The project versioning (Git) records all such contribution source information. - * - * - * The BHoM is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3.0 of the License, or - * (at your option) any later version. - * - * The BHoM is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this code. If not, see . - */ - -using BH.oM.Base.Attributes; -using BH.oM.LadybugTools; -using System.Linq; -using System.Collections.Generic; -using System.ComponentModel; -using BH.oM.Python; -using System.IO; -using System; - -namespace BH.Engine.LadybugTools -{ - public static partial class Query - { - [Description("Returns a list of Typology objects from the Python predefined Typologies list.")] - [Input("filter", "Text to filter the resultant list by. Filter applies to the typology identifier. Leave blank to return all typologies.")] - [Output("typologies", "A list of Typology objects.")] - public static List GetTypology(string filter = "") - { - PythonEnvironment env = Compute.InstallPythonEnv_LBT(true); - - string jsonFile = Path.Combine(Path.GetTempPath(), $"LBTBHoM_Typologies_{DateTime.Now:yyyyMMdd}.json"); - - if (!File.Exists(jsonFile)) - { - string script = Path.Combine(Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_typology.py"); - - string command = $"{env.Executable} {script} -j \"{jsonFile}\""; - - Python.Compute.RunCommandStdout(command: command, hideWindows: true); - } - - string jsonContent = File.ReadAllText(jsonFile); - - List typologies = (List)BH.Engine.Serialiser.Convert.FromJsonArray(jsonContent); - - List typologyObjects = new List(); - foreach (object typologyObject in typologies) - { - typologyObjects.Add((Typology)typologyObject); - } - - return typologyObjects.Where(m => m.Name.Contains(filter)).ToList(); - } - } -} diff --git a/LadybugTools_Engine/Versioning_70.json b/LadybugTools_Engine/Versioning_70.json index 106743df..09257534 100644 --- a/LadybugTools_Engine/Versioning_70.json +++ b/LadybugTools_Engine/Versioning_70.json @@ -1,9 +1,13 @@ { - "MessageForDeleted": { - "BH.Engine.LadybugTools.Convert.FromHoneybeeSurface(System.Object)": "This method has been removed as part of the removal of the dependency from Rhino in the LadybugTools_Toolkit.", - "BH.Engine.LadybugTools.Create.Typology(System.Collections.Generic.List, System.String, System.Double, System.Double, System.Double)": "This method only did validation for creating the object, which has been moved to methods that take a Typology as an input.", - "BH.Engine.LadybugTools.Convert.SnakeCaseToPascalCase(System.String)": "This method and other case conversion methods in the LBT Toolkit have been replaced by a single method that can do case conversions when given a case type.", - "BH.Engine.LadybugTools.Convert.PascalCaseToSnakeCase(System.String)": "This method and other case conversion methods in the LBT Toolkit have been replaced by a single method that can do case conversions when given a case type.", - "BH.Engine.LadybugTools.Compute.EPWtoCustomObject(System.String)": "Due to inclusion of EPW as an object, this method is no longer required and has been removed." - } + "MessageForDeleted": { + "BH.Engine.LadybugTools.Convert.FromHoneybeeSurface(System.Object)": "This method has been removed as part of the removal of the dependency from Rhino in the LadybugTools_Toolkit.", + "BH.Engine.LadybugTools.Create.Typology(System.Collections.Generic.List, System.String, System.Double, System.Double, System.Double)": "This method only did validation for creating the object, which has been moved to methods that take a Typology as an input.", + "BH.Engine.LadybugTools.Convert.SnakeCaseToPascalCase(System.String)": "This method and other case conversion methods in the LBT Toolkit have been replaced by a single method that can do case conversions when given a case type.", + "BH.Engine.LadybugTools.Convert.PascalCaseToSnakeCase(System.String)": "This method and other case conversion methods in the LBT Toolkit have been replaced by a single method that can do case conversions when given a case type.", + "BH.Engine.LadybugTools.Compute.EPWtoCustomObject(System.String)": "Due to inclusion of EPW as an object, this method is no longer required and has been removed.", + "BH.Engine.LadybugTools.Query.GetMaterial(System.String)": "All methods that involve serialisation of Ladybug Python objects have been converted into adapter Execute Commands, to access, use a LadybugToolsAdapter with the Execute method.", + "BH.Engine.LadybugTools.Query.GetTypology(System.String)": "All methods that involve serialisation of Ladybug Python objects have been converted into adapter Execute Commands, to access, use a LadybugToolsAdapter with the Execute method.", + "BH.Engine.LadybugTools.Compute.ExternalComfort(BH.oM.LadybugTools.SimulationResult, BH.oM.LadybugTools.Typology)": "All methods that involve serialisation of Ladybug Python objects have been converted into adapter Execute Commands, to access, use a LadybugToolsAdapter with the Execute method.", + "BH.Engine.LadybugTools.Compute.SimulationResult(System.String, BH.oM.LadybugTools.ILadybugToolsMaterial, BH.oM.LadybugTools.ILadybugToolsMaterial)": "All methods that involve serialisation of Ladybug Python objects have been converted into adapter Execute Commands, to access, use a LadybugToolsAdapter with the Execute method." + } } \ No newline at end of file diff --git a/LadybugTools_oM/ExecuteCommands/GetMaterialCommand.cs b/LadybugTools_oM/ExecuteCommands/GetMaterialCommand.cs new file mode 100644 index 00000000..f50b2004 --- /dev/null +++ b/LadybugTools_oM/ExecuteCommands/GetMaterialCommand.cs @@ -0,0 +1,38 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Adapter; +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; + +namespace BH.oM.LadybugTools +{ + [Description("Command that when executed with the LadybugTools Adapter, returns a list of materials from the Python Materials list.")] + public class GetMaterialCommand : IExecuteCommand, IObject + { + [Description("Text to filter the resultant list by. Filter applies to the Material Name. Leave blank to return all Materials.")] + public virtual string Filter { get; set; } = ""; + } +} diff --git a/LadybugTools_oM/ExecuteCommands/GetTypologyCommand.cs b/LadybugTools_oM/ExecuteCommands/GetTypologyCommand.cs new file mode 100644 index 00000000..9f2f091a --- /dev/null +++ b/LadybugTools_oM/ExecuteCommands/GetTypologyCommand.cs @@ -0,0 +1,38 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Adapter; +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; + +namespace BH.oM.LadybugTools +{ + [Description("Command that when executed with the LadybugTools Adapter, returns a list of Typology objects from the Python predefined Typologies list.")] + public class GetTypologyCommand : IExecuteCommand, IObject + { + [Description("Text to filter the resultant list by. Filter applies to the Typology Name. Leave blank to return all Typologies.")] + public virtual string Filter { get; set; } = ""; + } +} diff --git a/LadybugTools_oM/ExecuteCommands/RunExternalComfortCommand.cs b/LadybugTools_oM/ExecuteCommands/RunExternalComfortCommand.cs new file mode 100644 index 00000000..38c52b37 --- /dev/null +++ b/LadybugTools_oM/ExecuteCommands/RunExternalComfortCommand.cs @@ -0,0 +1,41 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Adapter; +using BH.oM.Base; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; + +namespace BH.oM.LadybugTools +{ + [Description("Command that when executed with the LadybugTools Adapter, runs an External Comfort simulation and returns an ExternalComfort object containing results.")] + public class RunExternalComfortCommand : IExecuteCommand, IObject + { + [Description("A SimulationResult object generated by the RunSimulation Execute command.")] + public virtual SimulationResult SimulationResult { get; set; } = null; + + [Description("A Typology object.")] + public virtual Typology Typology { get; set; } = null; + } +} \ No newline at end of file diff --git a/LadybugTools_oM/ExecuteCommands/RunSimulationCommand.cs b/LadybugTools_oM/ExecuteCommands/RunSimulationCommand.cs new file mode 100644 index 00000000..b8d16e47 --- /dev/null +++ b/LadybugTools_oM/ExecuteCommands/RunSimulationCommand.cs @@ -0,0 +1,45 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2023, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Adapter; +using BH.oM.Base; +using BH.oM.LadybugTools; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; + +namespace BH.oM.LadybugTools +{ + [Description("Command that when executed with the LadybugTools Adapter, runs a simulation and return a SimulationResult containing hourly data.")] + public class RunSimulationCommand : IExecuteCommand, IObject + { + [Description("FileSettings for an EPW file to run the simulation with.")] + public virtual FileSettings EpwFile { get; set; } = new FileSettings(); + + [Description("The ground material for the simulation to use.")] + public virtual IEnergyMaterialOpaque GroundMaterial { get; set; } = null; + + [Description("The shade material for the simulation to use.")] + public virtual IEnergyMaterialOpaque ShadeMaterial { get; set; } = null; + } +} \ No newline at end of file diff --git a/libs/System.Web.Extensions.dll b/libs/System.Web.Extensions.dll deleted file mode 100644 index daecd7b6..00000000 Binary files a/libs/System.Web.Extensions.dll and /dev/null differ