Skip to content

Commit a12cd35

Browse files
author
Fraser Greenroyd
authored
Re-implemented GetMaterial and GetTypology methods (#141)
2 parents e5b3083 + ef02c8a commit a12cd35

File tree

4 files changed

+135
-3
lines changed

4 files changed

+135
-3
lines changed

LadybugTools_Engine/Python/src/ladybugtools_toolkit/bhom/wrapped/get_typology.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Method to wrap for access to pre-defined materials."""
1+
"""Method to wrap for access to pre-defined typologies."""
22
# pylint: disable=C0415,E0401,W0703
33
import argparse
44
import traceback
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using BH.oM.Base.Attributes;
24+
using BH.oM.LadybugTools;
25+
using System.Linq;
26+
using System.Collections.Generic;
27+
using System.ComponentModel;
28+
using BH.oM.Python;
29+
using System.IO;
30+
using System;
31+
32+
namespace BH.Engine.LadybugTools
33+
{
34+
public static partial class Query
35+
{
36+
[Description("Returns a list of materials from the Python Materials list.")]
37+
[Input("filter", "Text to filter the resultant list by. Filter applies to the material identifier. Leave blank to return all materials.")]
38+
[Output("materials", "A list of materials.")]
39+
public static List<IEnergyMaterialOpaque> GetMaterial(string filter = "")
40+
{
41+
PythonEnvironment env = Compute.InstallPythonEnv_LBT(true);
42+
43+
string jsonFile = Path.Combine(Path.GetTempPath(), $"LBTBHoM_Materials_{DateTime.Now:yyyyMMdd}.json");
44+
45+
if (!File.Exists(jsonFile))
46+
{
47+
string script = Path.Combine(Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_material.py");
48+
49+
string command = $"{env.Executable} {script} -j \"{jsonFile}\"";
50+
51+
Python.Compute.RunCommandStdout(command: command, hideWindows: true);
52+
}
53+
54+
string jsonContent = File.ReadAllText(jsonFile);
55+
56+
List<object> materials = (List<object>)BH.Engine.Serialiser.Convert.FromJsonArray(jsonContent);
57+
58+
List<IEnergyMaterialOpaque> materialObjects = new List<IEnergyMaterialOpaque>();
59+
foreach (object materialObject in materials)
60+
{
61+
materialObjects.Add((IEnergyMaterialOpaque)materialObject);
62+
}
63+
64+
return materialObjects.Where(m => m.Identifier.Contains(filter)).ToList();
65+
}
66+
}
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2023, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using BH.oM.Base.Attributes;
24+
using BH.oM.LadybugTools;
25+
using System.Linq;
26+
using System.Collections.Generic;
27+
using System.ComponentModel;
28+
using BH.oM.Python;
29+
using System.IO;
30+
using System;
31+
32+
namespace BH.Engine.LadybugTools
33+
{
34+
public static partial class Query
35+
{
36+
[Description("Returns a list of Typology objects from the Python predefined Typologies list.")]
37+
[Input("filter", "Text to filter the resultant list by. Filter applies to the typology identifier. Leave blank to return all typologies.")]
38+
[Output("typologies", "A list of Typology objects.")]
39+
public static List<Typology> GetTypology(string filter = "")
40+
{
41+
PythonEnvironment env = Compute.InstallPythonEnv_LBT(true);
42+
43+
string jsonFile = Path.Combine(Path.GetTempPath(), $"LBTBHoM_Typologies_{DateTime.Now:yyyyMMdd}.json");
44+
45+
if (!File.Exists(jsonFile))
46+
{
47+
string script = Path.Combine(Python.Query.DirectoryCode(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_typology.py");
48+
49+
string command = $"{env.Executable} {script} -j \"{jsonFile}\"";
50+
51+
Python.Compute.RunCommandStdout(command: command, hideWindows: true);
52+
}
53+
54+
string jsonContent = File.ReadAllText(jsonFile);
55+
56+
List<object> typologies = (List<object>)BH.Engine.Serialiser.Convert.FromJsonArray(jsonContent);
57+
58+
List<Typology> typologyObjects = new List<Typology>();
59+
foreach (object typologyObject in typologies)
60+
{
61+
typologyObjects.Add((Typology)typologyObject);
62+
}
63+
64+
return typologyObjects.Where(m => m.Identifier.Contains(filter)).ToList();
65+
}
66+
}
67+
}

LadybugTools_Engine/Versioning_70.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
"BH.Engine.LadybugTools.Create.Typology(System.Collections.Generic.List<BH.oM.LadybugTools.Shelter>, 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.",
55
"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.",
66
"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.",
7-
"BH.Engine.LadybugTools.Query.GetMaterial(System.String)": "Due to a refactor of the underlying python libraries, this method was broken. To get materials for use within python scripts, get them within the scripts.",
8-
"BH.Engine.LadybugTools.Query.GetTypology(System.String)": "Due to a refactor of the underlying python libraries, this method was broken. To get typologies for use within python scripts, get them within the scripts.",
97
"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."
108
}
119
}

0 commit comments

Comments
 (0)