Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a2c22c287 |
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user