Skip to content

Commit

Permalink
7.3 Deployment (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-fisher authored Sep 19, 2024
2 parents 658da8f + af8c254 commit 6df1a6b
Show file tree
Hide file tree
Showing 37 changed files with 1,307 additions and 121 deletions.
6 changes: 2 additions & 4 deletions .ci/BHoMBot/Nuget/BHoM.Interop.LadybugTools.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
<file src="licence/licence.txt" target="" />
<file src="images/icon.png" target="" />
<file src="docs/readme.md" target="" />
<!--lib\**\* is a workaround for contentfiles not including dll files-->
<file src="lib\**\*" target="lib" />
<file src="C:\ProgramData\BHoM\Extensions\PythonCode\LadybugTools_Toolkit\src\ladybugtools_toolkit\bhom\wrapped\**\*.*" exclude="**\__pycache__\*;**\docs\**\*" target="contentFiles\any\any\PythonCode\LadybugTools_Toolkit\src\ladybugtools_toolkit\bhom\wrapped"/>
<file src="C:\ProgramData\BHoM\Extensions\PythonCode\LadybugTools_Toolkit\src\**\*.*" exclude="**\__pycache__\*;**\docs\**\*" target="contentFiles\any\any\PythonEnvironment\Lib\site-packages" />
<file src="C:\ProgramData\BHoM\Extensions\PythonCode\LadybugTools_Toolkit\src\ladybugtools_toolkit\bhom\wrapped\**\*.*" exclude="**\__pycache__\*;**\docs\**\*" target="contentFiles\any\any\PythonCode\LadybugTools_Toolkit\src\ladybugtools_toolkit\bhom\wrapped"/>
<file src="C:\ProgramData\BHoM\Extensions\PythonCode\LadybugTools_Toolkit\src\**\*.*" exclude="**\__pycache__\*;**\docs\**\*" target="contentFiles\any\any\PythonEnvironment\Lib\site-packages" />
</files>
</package>
102 changes: 81 additions & 21 deletions LadybugTools_Adapter/AdapterActions/Execute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
using BH.Engine.Base;
using System.Drawing;
using BH.Engine.Serialiser;
using BH.Engine.LadyBugTools;
using System.Reflection;

namespace BH.Adapter.LadybugTools
Expand Down Expand Up @@ -312,12 +311,25 @@ private List<object> RunCommand(HeatPlotCommand command, ActionConfig actionConf
if (colourMap.ColourMapValidity())
colourMap = colourMap.ToColourMap().FromColourMap();

string returnFile = Path.GetTempFileName();

// run the process
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -cmap \"{colourMap}\" -p \"{command.OutputLocation}\"";
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -cmap \"{colourMap}\" -r \"{returnFile.Replace('\\', '/')}\" -p \"{command.OutputLocation}\"";
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);

if (!File.Exists(result))
{
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
File.Delete(returnFile);
return new List<object>();
}

CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
File.Delete(returnFile);
PlotInformation info = Convert.ToPlotInformation(obj, new CollectionData());

m_executeSuccess = true;
return new List<object>() { result };
return new List<object>() { info };
}

/**************************************************/
Expand Down Expand Up @@ -351,12 +363,25 @@ private List<object> RunCommand(WindroseCommand command, ActionConfig actionConf
if (colourMap.ColourMapValidity())
colourMap = colourMap.ToColourMap().FromColourMap();

string returnFile = Path.GetTempFileName();

// run the process
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -ap \"{command.AnalysisPeriod.FromBHoM().Replace("\"", "\\\"")}\" -cmap \"{colourMap}\" -bins \"{command.NumberOfDirectionBins}\" -p \"{command.OutputLocation}\"";
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -ap \"{command.AnalysisPeriod.FromBHoM().Replace("\"", "\\\"")}\" -cmap \"{colourMap}\" -bins \"{command.NumberOfDirectionBins}\" -r \"{returnFile.Replace('\\', '/')}\" -p \"{command.OutputLocation}\"";
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);

if (!File.Exists(result))
{
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
File.Delete(returnFile);
return new List<object>();
}

CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
File.Delete(returnFile);
PlotInformation info = Convert.ToPlotInformation(obj, new WindroseData());

m_executeSuccess = true;
return new List<object> { result };
return new List<object> { info };
}

/**************************************************/
Expand Down Expand Up @@ -397,6 +422,7 @@ private List<object> RunCommand(UTCIHeatPlotCommand command, ActionConfig action
BH.Engine.Base.Compute.RecordError($"When overriding bin colours 10 colours must be provided, but {command.BinColours.Count} colours were provided instead.");
return null;
}

List<string> colours = command.BinColours.Select(x => x.ToHexCode()).ToList();

string hexColours = $"[\"{string.Join("\",\"", colours)}\"]";
Expand All @@ -418,25 +444,29 @@ private List<object> RunCommand(UTCIHeatPlotCommand command, ActionConfig action

string script = Path.Combine(Engine.LadybugTools.Query.PythonCodeDirectory(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "utci_heatmap.py");

string returnFile = Path.GetTempFileName();

// run the process
string cmdCommand = $"{m_environment.Executable} \"{script}\" -e \"{epwFile}\" -in \"{argFile}\" -ws \"{command.WindSpeedMultiplier}\" -sp \"{command.OutputLocation}\"";
string result = "";
string cmdCommand = $"{m_environment.Executable} \"{script}\" -e \"{epwFile}\" -in \"{argFile}\" -ws \"{command.WindSpeedMultiplier}\" -r \"{returnFile.Replace('\\', '/')}\" -sp \"{command.OutputLocation}\"";
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);

try
{
result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);
}
catch (Exception ex)
{
BH.Engine.Base.Compute.RecordError(ex, "An error occurred while running some python.");
}
finally
string resultFile = result.Split('\n').Last();

if (!File.Exists(resultFile))
{
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
File.Delete(returnFile);
File.Delete(argFile);
return new List<object>();
}

CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
File.Delete(returnFile);
File.Delete(argFile);
PlotInformation info = Convert.ToPlotInformation(obj, new UTCIData());

m_executeSuccess = true;
return new List<object> { result.Split('\n').Last() };
return new List<object> { info };
}

/**************************************************/
Expand Down Expand Up @@ -473,12 +503,27 @@ private List<object> RunCommand(DiurnalPlotCommand command, ActionConfig actionC

string script = Path.Combine(Engine.LadybugTools.Query.PythonCodeDirectory(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "diurnal.py");

string returnFile = Path.GetTempFileName();

// run the process
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -dtk \"{command.EPWKey.ToText()}\" -c \"{command.Colour.ToHexCode()}\" -t \"{command.Title}\" -ap \"{command.Period.ToString().ToLower()}\" -p \"{command.OutputLocation}\"";
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}\"";
string result = Engine.Python.Compute.RunCommandStdout(command: cmdCommand, hideWindows: true);

string resultFile = result.Split('\n').Last();

if (!File.Exists(resultFile))
{
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
File.Delete(returnFile);
return new List<object>();
}

CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
File.Delete(returnFile);
PlotInformation info = Convert.ToPlotInformation(obj, new CollectionData());

m_executeSuccess = true;
return new List<object>() { result.Split('\n').Last() };
return new List<object>() { info };
}

/**************************************************/
Expand Down Expand Up @@ -513,12 +558,27 @@ private List<object> RunCommand(SunPathPlotCommand command, ActionConfig actionC

string script = Path.Combine(Engine.LadybugTools.Query.PythonCodeDirectory(), "LadybugTools_Toolkit\\src\\ladybugtools_toolkit\\bhom\\wrapped\\plot", "sunpath.py");

string returnFile = Path.GetTempFileName();

//run the process
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -s {command.SunSize} -ap \"{command.AnalysisPeriod.FromBHoM().Replace("\"", "\\\"")}\" -p \"{command.OutputLocation}\"";
string cmdCommand = $"{m_environment.Executable} {script} -e \"{epwFile}\" -s {command.SunSize} -ap \"{command.AnalysisPeriod.FromBHoM().Replace("\"", "\\\"")}\" -r \"{returnFile.Replace('\\', '/')}\" -p \"{command.OutputLocation}\"";
string result = Engine.Python.Compute.RunCommandStdout(cmdCommand, hideWindows: true);

string resultFile = result.Split('\n').Last();

if (!File.Exists(resultFile))
{
BH.Engine.Base.Compute.RecordError($"An error occurred while running the command: {result}");
File.Delete(returnFile);
return new List<object>();
}

CustomObject obj = (CustomObject)BH.Engine.Serialiser.Convert.FromJson(System.IO.File.ReadAllText(returnFile));
File.Delete(returnFile);
PlotInformation info = Convert.ToPlotInformation(obj, new SunPathData());

m_executeSuccess = true;
return new List<object>() { result.Split('\n').Last() };
return new List<object>() { info };
}

/**************************************************/
Expand Down
Loading

0 comments on commit 6df1a6b

Please sign in to comment.