Skip to content

Commit

Permalink
Test enum function input
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhankoral committed Nov 1, 2024
1 parent 4a2c22c commit 51ad4a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
14 changes: 10 additions & 4 deletions SpeckleAutomateDotnetExample/AutomateFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -38,6 +40,10 @@ FunctionInputs functionInputs
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>;
Expand Down
21 changes: 13 additions & 8 deletions SpeckleAutomateDotnetExample/FunctionInputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@
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>
/// This class is used to generate a JSON Schema to ensure that the user provided values
/// 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.
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion TestAutomateFunction/AutomationContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task TestFunctionRun()
{
var inputs = new FunctionInputs
{
SpeckleTypeToCount = "Base",
SpeckleTypeToCheck = "Base",
SpeckleTypeTargetCount = 1
};

Expand Down

0 comments on commit 51ad4a8

Please sign in to comment.