Skip to content

Commit e07b89f

Browse files
authored
8.1 Deployment (#304)
2 parents d409675 + 4a4519f commit e07b89f

132 files changed

Lines changed: 4527 additions & 1457 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

LadybugTools_Adapter/AdapterActions/Execute.cs

Lines changed: 3 additions & 568 deletions
Large diffs are not rendered by default.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2025, 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.Engine.Adapter;
24+
using BH.Engine.Base;
25+
using BH.Engine.LadybugTools;
26+
using BH.oM.Adapter;
27+
using BH.oM.Base;
28+
using BH.oM.LadybugTools;
29+
using System;
30+
using System.Collections.Generic;
31+
using System.IO;
32+
using System.Linq;
33+
using System.Text;
34+
35+
namespace BH.Adapter.LadybugTools
36+
{
37+
public partial class LadybugToolsAdapter : BHoMAdapter
38+
{
39+
private List<object> RunCommand(DiurnalPlotCommand command, ActionConfig actionConfig)
40+
{
41+
if (command.EPWFile == null)
42+
{
43+
BH.Engine.Base.Compute.RecordError($"{nameof(command.EPWFile)} input cannot be null.");
44+
return null;
45+
}
46+
47+
if (!System.IO.File.Exists(command.EPWFile.GetFullFileName()))
48+
{
49+
BH.Engine.Base.Compute.RecordError($"File '{command.EPWFile}' does not exist.");
50+
return null;
51+
}
52+
53+
if (command.Period == DiurnalPeriod.Undefined)
54+
{
55+
BH.Engine.Base.Compute.RecordError("Please provide a valid diurnal period.");
56+
return null;
57+
}
58+
59+
if (command.EPWKey == EPWKey.Undefined)
60+
{
61+
BH.Engine.Base.Compute.RecordError("Please provide a valid EPW key.");
62+
return null;
63+
}
64+
65+
command.Title = command.Title.SanitiseString();
66+
67+
string epwFile = System.IO.Path.GetFullPath(command.EPWFile.GetFullFileName());
68+
69+
string script = Path.Combine(Engine.LadybugTools.Query.PythonCodeDirectory(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "diurnal.py");
70+
71+
string returnFile = Path.GetTempFileName();
72+
73+
// run the process
74+
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -c \"{command.Colour.ToHexCode()}\" -t \"{command.Title}\" -ap \"{command.Period.ToString().ToLower()}\" -r \"{returnFile.Replace('\\', '/')}\" -p \"{command.OutputLocation}\"";
75+
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
76+
77+
string resultFile = result.Split('\n').Last();
78+
79+
if (!File.Exists(resultFile))
80+
{
81+
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
82+
File.Delete(returnFile);
83+
return new List<object>();
84+
}
85+
86+
CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
87+
File.Delete(returnFile);
88+
PlotInformation info = Convert.ToPlotInformation(obj, new CollectionData());
89+
90+
m_executeSuccess = true;
91+
return new List<object>() { info };
92+
}
93+
}
94+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2025, 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.Engine.Adapter;
24+
using BH.oM.Adapter;
25+
using BH.oM.Data.Requests;
26+
using BH.oM.LadybugTools;
27+
using System;
28+
using System.Collections.Generic;
29+
using System.IO;
30+
using System.Linq;
31+
using System.Text;
32+
33+
namespace BH.Adapter.LadybugTools
34+
{
35+
public partial class LadybugToolsAdapter : BHoMAdapter
36+
{
37+
private List<object> RunCommand(GetMaterialCommand command, ActionConfig actionConfig)
38+
{
39+
LadybugConfig config;
40+
41+
if (actionConfig?.GetType() == typeof(LadybugConfig))
42+
{
43+
config = (LadybugConfig)actionConfig;
44+
config.JsonFile = new FileSettings()
45+
{
46+
FileName = $"LBTBHoM_Materials.json",
47+
Directory = Path.GetTempPath()
48+
};
49+
}
50+
else
51+
{
52+
config = new LadybugConfig()
53+
{
54+
JsonFile = new FileSettings()
55+
{
56+
FileName = $"LBTBHoM_Materials.json",
57+
Directory = Path.GetTempPath()
58+
}
59+
};
60+
}
61+
62+
TimeSpan timeSinceLastUpdate = DateTime.Now - File.GetCreationTime(config.JsonFile.GetFullFileName());
63+
if (timeSinceLastUpdate.Days > config.CacheFileMaximumAge)
64+
File.Delete(config.JsonFile.GetFullFileName());
65+
66+
if (!File.Exists(config.JsonFile.GetFullFileName()))
67+
{
68+
string script = Path.Combine(Engine.LadybugTools.Query.PythonCodeDirectory(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_material.py");
69+
70+
string cmdCommand = $"{m_environment.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
71+
72+
Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
73+
}
74+
75+
List<object> materialObjects = Pull(new FilterRequest(), actionConfig: config).ToList();
76+
77+
m_executeSuccess = true;
78+
return materialObjects.Where(m => (m as IEnergyMaterialOpaque).Name.Contains(command.Filter)).ToList();
79+
}
80+
}
81+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2025, 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.Engine.Adapter;
24+
using BH.oM.Adapter;
25+
using BH.oM.Data.Requests;
26+
using BH.oM.LadybugTools;
27+
using System;
28+
using System.Collections.Generic;
29+
using System.IO;
30+
using System.Linq;
31+
using System.Text;
32+
33+
namespace BH.Adapter.LadybugTools
34+
{
35+
public partial class LadybugToolsAdapter : BHoMAdapter
36+
{
37+
private List<object> RunCommand(GetTypologyCommand command, ActionConfig actionConfig)
38+
{
39+
LadybugConfig config;
40+
41+
if (actionConfig?.GetType() == typeof(LadybugConfig))
42+
{
43+
config = (LadybugConfig)actionConfig;
44+
config.JsonFile = new FileSettings()
45+
{
46+
FileName = $"LBTBHoM_Typologies.json",
47+
Directory = Path.GetTempPath()
48+
};
49+
}
50+
else
51+
{
52+
config = new LadybugConfig()
53+
{
54+
JsonFile = new FileSettings()
55+
{
56+
FileName = $"LBTBHoM_Typologies.json",
57+
Directory = Path.GetTempPath()
58+
}
59+
};
60+
}
61+
62+
TimeSpan timeSinceLastUpdate = DateTime.Now - File.GetCreationTime(config.JsonFile.GetFullFileName());
63+
if (timeSinceLastUpdate.Days > config.CacheFileMaximumAge)
64+
File.Delete(config.JsonFile.GetFullFileName());
65+
66+
if (!File.Exists(config.JsonFile.GetFullFileName()))
67+
{
68+
string script = Path.Combine(Engine.LadybugTools.Query.PythonCodeDirectory(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped", "get_typology.py");
69+
70+
string cmdCommand = $"{m_environment.Executable} {script} -j \"{config.JsonFile.GetFullFileName()}\"";
71+
72+
Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
73+
}
74+
75+
List<object> typologyObjects = Pull(new FilterRequest(), actionConfig: config).ToList();
76+
77+
m_executeSuccess = true;
78+
return typologyObjects.Where(m => (m as Typology).Name.Contains(command.Filter)).ToList();
79+
}
80+
}
81+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2025, 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.Engine.Adapter;
24+
using BH.Engine.Base;
25+
using BH.oM.Adapter;
26+
using BH.oM.Base;
27+
using BH.oM.LadybugTools;
28+
using System;
29+
using System.Collections.Generic;
30+
using System.IO;
31+
using System.Text;
32+
33+
namespace BH.Adapter.LadybugTools
34+
{
35+
public partial class LadybugToolsAdapter : BHoMAdapter
36+
{
37+
private List<object> RunCommand(HeatPlotCommand command, ActionConfig actionConfig)
38+
{
39+
if (command.EPWFile == null)
40+
{
41+
BH.Engine.Base.Compute.RecordError($"{nameof(command.EPWFile)} input cannot be null.");
42+
return null;
43+
}
44+
45+
if (!System.IO.File.Exists(command.EPWFile.GetFullFileName()))
46+
{
47+
BH.Engine.Base.Compute.RecordError($"File '{command.EPWFile}' does not exist.");
48+
return null;
49+
}
50+
51+
string epwFile = System.IO.Path.GetFullPath(command.EPWFile.GetFullFileName());
52+
53+
string script = Path.Combine(Engine.LadybugTools.Query.PythonCodeDirectory(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "heatmap.py");
54+
55+
//check if the colourmap is valid for user warning, but run with input anyway as the map could be defined separately.
56+
string colourMap = command.ColourMap;
57+
if (colourMap.ColourMapValidity())
58+
colourMap = colourMap.ToColourMap().FromColourMap();
59+
60+
string returnFile = Path.GetTempFileName();
61+
62+
// run the process
63+
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -cmap \"{colourMap}\" -r \"{returnFile.Replace('\\', '/')}\" -p \"{command.OutputLocation}\"";
64+
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
65+
66+
if (!File.Exists(result))
67+
{
68+
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
69+
File.Delete(returnFile);
70+
return new List<object>();
71+
}
72+
73+
CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
74+
File.Delete(returnFile);
75+
PlotInformation info = Convert.ToPlotInformation(obj, new CollectionData());
76+
77+
m_executeSuccess = true;
78+
return new List<object>() { info };
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)