Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 51ad4a8ff9 | |||
| 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,41 @@ public static class AutomateFunction
|
||||
{
|
||||
Console.WriteLine("Starting execution");
|
||||
_ = typeof(ObjectsKit).Assembly; // INFO: Force objects kit to initialize
|
||||
|
||||
var threshold = 0.02;
|
||||
Console.WriteLine("Receiving version");
|
||||
var commitObject = await automationContext.ReceiveVersion();
|
||||
|
||||
Console.WriteLine("Received version: " + commitObject);
|
||||
|
||||
var count = commitObject
|
||||
var objects = commitObject
|
||||
.Flatten()
|
||||
.Count(b => b.speckle_type == functionInputs.SpeckleTypeToCount);
|
||||
.Where(b => b.speckle_type == "Objects.BuiltElements.Wall:Objects.BuiltElements.Revit.RevitWall" &&
|
||||
(string)b["category"]! == "Walls");
|
||||
|
||||
Console.WriteLine($"Counted {count} objects");
|
||||
var values = objects.Select(GetThermalResistance);
|
||||
|
||||
if (count < functionInputs.SpeckleTypeTargetCount) {
|
||||
automationContext.MarkRunFailed($"Counted {count} objects where {functionInputs.SpeckleTypeTargetCount} were expected");
|
||||
return;
|
||||
var failedObjectIds = values.Where(val => val.value > threshold).Select(v => v.id).ToList();
|
||||
|
||||
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>;
|
||||
if (properties is null)
|
||||
{
|
||||
return (obj.id, 0);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,13 @@ using Speckle.Automate.Sdk.DataAnnotations;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
|
||||
public enum ClimateZones
|
||||
{
|
||||
ONEA,
|
||||
TWOA
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class describes the user specified variables that the function wants to work with.
|
||||
/// </summary>
|
||||
@@ -9,11 +16,16 @@ using System.ComponentModel.DataAnnotations;
|
||||
/// are valid and match the required schema.
|
||||
public struct FunctionInputs
|
||||
{
|
||||
[Required]
|
||||
[EnumDataType(typeof(ClimateZones))]
|
||||
[DefaultValue(ClimateZones.ONEA)]
|
||||
public string ClimateZone;
|
||||
|
||||
/// <summary>
|
||||
/// The object type to count instances of in the given model version.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string SpeckleTypeToCount;
|
||||
public string SpeckleTypeToCheck;
|
||||
|
||||
/// <summary>
|
||||
/// The total number of the specified type expected.
|
||||
@@ -22,11 +34,4 @@ public struct FunctionInputs
|
||||
[Range(1, 100)]
|
||||
[Required]
|
||||
public int SpeckleTypeTargetCount;
|
||||
|
||||
/// <summary>
|
||||
/// An arbitrary example of using a secret input value.
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Secret]
|
||||
public string ExternalServiceKey;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public sealed class AutomationContextTest : IDisposable
|
||||
{
|
||||
var inputs = new FunctionInputs
|
||||
{
|
||||
SpeckleTypeToCount = "Base",
|
||||
SpeckleTypeToCheck = "Base",
|
||||
SpeckleTypeTargetCount = 1
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user