From 51ad4a8ff9ae9e9a384c9cf64ba7b2f4e87df5d9 Mon Sep 17 00:00:00 2001 From: oguzhankoral Date: Fri, 1 Nov 2024 18:07:15 +0300 Subject: [PATCH] Test enum function input --- .../AutomateFunction.cs | 14 +++++++++---- .../FunctionInputs.cs | 21 ++++++++++++------- TestAutomateFunction/AutomationContextTest.cs | 2 +- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/SpeckleAutomateDotnetExample/AutomateFunction.cs b/SpeckleAutomateDotnetExample/AutomateFunction.cs index 95a8cc5..c6c8cf5 100644 --- a/SpeckleAutomateDotnetExample/AutomateFunction.cs +++ b/SpeckleAutomateDotnetExample/AutomateFunction.cs @@ -13,14 +13,16 @@ FunctionInputs functionInputs { Console.WriteLine("Starting execution"); _ = typeof(ObjectsKit).Assembly; // INFO: Force objects kit to initialize - var threshold = 0.15; + var threshold = 0.02; Console.WriteLine("Receiving version"); var commitObject = await automationContext.ReceiveVersion(); - var values = commitObject + var objects = commitObject .Flatten() - .Where(b => b.speckle_type == "Objects.BuiltElements.Revit.RevitElement" && (string)b["category"]! == "Windows") - .Select(GetThermalResistance); + .Where(b => b.speckle_type == "Objects.BuiltElements.Wall:Objects.BuiltElements.Revit.RevitWall" && + (string)b["category"]! == "Walls"); + + var values = objects.Select(GetThermalResistance); var failedObjectIds = values.Where(val => val.value > threshold).Select(v => v.id).ToList(); @@ -38,6 +40,10 @@ FunctionInputs functionInputs private static (string id, double value) GetThermalResistance(Base obj) { var properties = obj["properties"] as Dictionary; + if (properties is null) + { + return (obj.id, 0); + } var typeParameters = properties!["Type Parameters"] as Dictionary; var analyticalProperties = typeParameters!["Analytical Properties"] as Dictionary; var thermalResistance = analyticalProperties!["Thermal Resistance (R)"] as Dictionary; diff --git a/SpeckleAutomateDotnetExample/FunctionInputs.cs b/SpeckleAutomateDotnetExample/FunctionInputs.cs index 29b7b88..5352470 100644 --- a/SpeckleAutomateDotnetExample/FunctionInputs.cs +++ b/SpeckleAutomateDotnetExample/FunctionInputs.cs @@ -2,6 +2,13 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; + +public enum ClimateZones +{ + ONEA, + TWOA +} + /// /// This class describes the user specified variables that the function wants to work with. /// @@ -9,11 +16,16 @@ /// are valid and match the required schema. public struct FunctionInputs { + [Required] + [EnumDataType(typeof(ClimateZones))] + [DefaultValue(ClimateZones.ONEA)] + public string ClimateZone; + /// /// The object type to count instances of in the given model version. /// [Required] - public string SpeckleTypeToCount; + public string SpeckleTypeToCheck; /// /// The total number of the specified type expected. @@ -22,11 +34,4 @@ public struct FunctionInputs [Range(1, 100)] [Required] public int SpeckleTypeTargetCount; - - /// - /// An arbitrary example of using a secret input value. - /// - [Required] - [Secret] - public string ExternalServiceKey; } diff --git a/TestAutomateFunction/AutomationContextTest.cs b/TestAutomateFunction/AutomationContextTest.cs index beea937..8370406 100644 --- a/TestAutomateFunction/AutomationContextTest.cs +++ b/TestAutomateFunction/AutomationContextTest.cs @@ -28,7 +28,7 @@ public async Task TestFunctionRun() { var inputs = new FunctionInputs { - SpeckleTypeToCount = "Base", + SpeckleTypeToCheck = "Base", SpeckleTypeTargetCount = 1 };