1 Commits

Author SHA1 Message Date
oguzhankoral 4a2c22c287 POC works
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
2024-11-01 17:01:39 +03:00
@@ -1,5 +1,7 @@
using Objects;
using Speckle.Automate.Sdk;
using Speckle.Automate.Sdk.Schema;
using Speckle.Core.Models;
using Speckle.Core.Models.Extensions;
public static class AutomateFunction
@@ -11,23 +13,35 @@ public static class AutomateFunction
{
Console.WriteLine("Starting execution");
_ = typeof(ObjectsKit).Assembly; // INFO: Force objects kit to initialize
var threshold = 0.15;
Console.WriteLine("Receiving version");
var commitObject = await automationContext.ReceiveVersion();
Console.WriteLine("Received version: " + commitObject);
var count = commitObject
var values = commitObject
.Flatten()
.Count(b => b.speckle_type == functionInputs.SpeckleTypeToCount);
.Where(b => b.speckle_type == "Objects.BuiltElements.Revit.RevitElement" && (string)b["category"]! == "Windows")
.Select(GetThermalResistance);
Console.WriteLine($"Counted {count} objects");
var failedObjectIds = values.Where(val => val.value > threshold).Select(v => v.id).ToList();
if (count < functionInputs.SpeckleTypeTargetCount) {
automationContext.MarkRunFailed($"Counted {count} objects where {functionInputs.SpeckleTypeTargetCount} were expected");
return;
if (failedObjectIds.Count > 0)
{
automationContext.AttachResultToObjects(ObjectResultLevel.Error, "test", failedObjectIds);
automationContext.MarkRunFailed("FAILED");
}
else
{
automationContext.MarkRunSuccess($"SUCCESS");
}
}
automationContext.MarkRunSuccess($"Counted {count} objects");
private static (string id, double value) GetThermalResistance(Base obj)
{
var properties = obj["properties"] as Dictionary<string, object>;
var typeParameters = properties!["Type Parameters"] as Dictionary<string, object>;
var analyticalProperties = typeParameters!["Analytical Properties"] as Dictionary<string, object>;
var thermalResistance = analyticalProperties!["Thermal Resistance (R)"] as Dictionary<string, object>;
var value = thermalResistance!["value"] is double ? (double)thermalResistance!["value"] : 0;
return (obj.id, value);
}
}