From 92d83038340093236c2e66a74c8bbb85db31d452 Mon Sep 17 00:00:00 2001 From: oguzhankoral Date: Wed, 13 Nov 2024 14:20:08 +0000 Subject: [PATCH] Remove business logic --- .../AutomateFunction.cs | 99 +++---------------- .../FunctionInputs.cs | 23 ++--- .../SpeckleTypeUtilities.cs | 50 ++++++++++ TestAutomateFunction/AutomationContextTest.cs | 5 +- 4 files changed, 74 insertions(+), 103 deletions(-) create mode 100644 SpeckleAutomateDotnetExample/SpeckleTypeUtilities.cs diff --git a/SpeckleAutomateDotnetExample/AutomateFunction.cs b/SpeckleAutomateDotnetExample/AutomateFunction.cs index 94eb66a..449cb70 100644 --- a/SpeckleAutomateDotnetExample/AutomateFunction.cs +++ b/SpeckleAutomateDotnetExample/AutomateFunction.cs @@ -21,46 +21,22 @@ public static async Task Run( FunctionInputs functionInputs ) { - var climateZone = GetClimateZone(functionInputs.ClimateZone); - Console.WriteLine("Starting execution"); _ = typeof(ObjectsKit).Assembly; // INFO: Force objects kit to initialize - Console.WriteLine("Receiving version"); - var rootObject = await automationContext.ReceiveVersion(); - - Console.WriteLine("Flatten the root object"); - var flatten = rootObject.Flatten().ToList(); - - Console.WriteLine("Traverse the objects by type"); - var walls = GetByType(flatten, SpeckleType.Wall); - var windows = GetByType(flatten, SpeckleType.Window); - var roofs = GetByType(flatten, SpeckleType.Roof); - - Console.WriteLine("Checking for compliance"); - var failedObjects = new List(); - var failedWalls = CheckCompliance(walls, climateZone, SpeckleType.Wall); - var failedWindows = CheckCompliance(windows, climateZone, SpeckleType.Window); - var failedRoofs = CheckCompliance(roofs, climateZone, SpeckleType.Roof); - - failedObjects.AddRange(failedWalls); - failedObjects.AddRange(failedWindows); - failedObjects.AddRange(failedRoofs); - - Console.WriteLine("Reporting compliance for failed objects"); - AttachReportToFailedObjects(automationContext, failedObjects); - - Console.WriteLine("Reporting the status of all automation"); - ReportStatus( - automationContext, - functionInputs, - walls.Count(), - failedWalls.Count(), - windows.Count(), - failedWindows.Count(), - roofs.Count(), - failedRoofs.Count() - ); + // 0- Get climate zone from function inputs + + // 1- Receive version from automation context + + // 2- Flatten the objects in received root object + + // 3- Get the objects we need + + // 4- Check the compliance for given object types + + // 5- Attach report to failed objects to be able to highlight them in viewer or Revit connector + + // 6- Report the automation result as SUCCESS/FAIL } private static void AttachReportToFailedObjects( @@ -106,7 +82,7 @@ int numberOfFailedRoofs if (numberOfFailedWalls + numberOfFailedWindows + numberOfFailedRoofs > 0) { var message = ""; - if (functionInputs.CheckWalls) + if (true) // TODO: Check the whether walls included or not from function inputs { message += "WALLS:\n"; if (numberOfWalls > 0) @@ -118,7 +94,7 @@ int numberOfFailedRoofs message += "There are no walls\n\n"; } } - if (functionInputs.CheckWindows) + if (true) // TODO: Check the whether windows included or not from function inputs { message += "WINDOWS:\n"; if (numberOfWindows > 0) @@ -131,7 +107,7 @@ int numberOfFailedRoofs } } - if (functionInputs.CheckWindows) + if (true) // TODO: Check the whether roofs included or not from function inputs { message += "ROOFS:\n"; if (numberOfRoofs > 0) @@ -196,47 +172,4 @@ private static ClimateZone GetClimateZone(string climateZoneString) // Handle the case where the ClimateZone string is not a valid ClimateZones value throw new ArgumentException($"Invalid ClimateZone: {climateZoneString}"); } - - private static IEnumerable GetByType( - IEnumerable objects, - SpeckleType speckleType - ) - { - return objects.Where(b => - b.speckle_type == SpeckleTypes[speckleType] - && (string)b["category"]! == SpeckleCategories[speckleType] - ); - } - - private static IEnumerable GetByType(Base root) - where T : Base - { - var traversal = new GraphTraversal(); - return traversal - .Traverse(root) - .Where(obj => obj.Current is T) - .Select(obj => obj.Current); - } - - private static readonly Dictionary SpeckleTypes = - new() - { - { - SpeckleType.Wall, - "Objects.BuiltElements.Wall:Objects.BuiltElements.Revit.RevitWall" - }, - { SpeckleType.Window, "Objects.BuiltElements.Revit.RevitElement" }, - { - SpeckleType.Roof, - "Objects.BuiltElements.Roof:Objects.BuiltElements.Revit.RevitRoof.RevitRoof:Objects.BuiltElements.Revit.RevitRoof.RevitExtrusionRoof" - }, - }; - - private static readonly Dictionary SpeckleCategories = - new() - { - { SpeckleType.Wall, "Walls" }, - { SpeckleType.Window, "Windows" }, - { SpeckleType.Roof, "Roofs" }, - }; } diff --git a/SpeckleAutomateDotnetExample/FunctionInputs.cs b/SpeckleAutomateDotnetExample/FunctionInputs.cs index d61138d..6a0af62 100644 --- a/SpeckleAutomateDotnetExample/FunctionInputs.cs +++ b/SpeckleAutomateDotnetExample/FunctionInputs.cs @@ -10,20 +10,11 @@ namespace TestAutomateFunction; /// are valid and match the required schema. public struct FunctionInputs { - [Required] - [EnumDataType(typeof(ClimateZone))] - [DefaultValue(TestAutomateFunction.ClimateZone.Csa_MediterraneanHotSummer)] - public string ClimateZone; - - [Required] - [DefaultValue(true)] - public bool CheckWalls; - - [Required] - [DefaultValue(true)] - public bool CheckWindows; - - [Required] - [DefaultValue(true)] - public bool CheckRoofs; + // 0- Create dropdown for available climate zones as "ClimateZones" + + // 1- Create toggle for whether including walls or not + + // 2- Create toggle for whether including windows or not + + // 3- Create toggle for whether including roofs or not } diff --git a/SpeckleAutomateDotnetExample/SpeckleTypeUtilities.cs b/SpeckleAutomateDotnetExample/SpeckleTypeUtilities.cs new file mode 100644 index 0000000..5ff65df --- /dev/null +++ b/SpeckleAutomateDotnetExample/SpeckleTypeUtilities.cs @@ -0,0 +1,50 @@ +using Speckle.Core.Models; +using Speckle.Core.Models.GraphTraversal; + +namespace TestAutomateFunction; + +public class SpeckleTypeUtilities +{ + public static IEnumerable GetByType( + IEnumerable objects, + SpeckleType speckleType + ) + { + return objects.Where(b => + b.speckle_type == SpeckleTypes[speckleType] + && (string)b["category"]! == SpeckleCategories[speckleType] + ); + } + + public static IEnumerable GetByType(Base root) + where T : Base + { + var traversal = new GraphTraversal(); + return traversal + .Traverse(root) + .Where(obj => obj.Current is T) + .Select(obj => obj.Current); + } + + private static readonly Dictionary SpeckleTypes = + new() + { + { + SpeckleType.Wall, + "Objects.BuiltElements.Wall:Objects.BuiltElements.Revit.RevitWall" + }, + { SpeckleType.Window, "Objects.BuiltElements.Revit.RevitElement" }, + { + SpeckleType.Roof, + "Objects.BuiltElements.Roof:Objects.BuiltElements.Revit.RevitRoof.RevitRoof:Objects.BuiltElements.Revit.RevitRoof.RevitExtrusionRoof" + }, + }; + + private static readonly Dictionary SpeckleCategories = + new() + { + { SpeckleType.Wall, "Walls" }, + { SpeckleType.Window, "Windows" }, + { SpeckleType.Roof, "Roofs" }, + }; +} diff --git a/TestAutomateFunction/AutomationContextTest.cs b/TestAutomateFunction/AutomationContextTest.cs index 62e0cdc..d5dd084 100644 --- a/TestAutomateFunction/AutomationContextTest.cs +++ b/TestAutomateFunction/AutomationContextTest.cs @@ -30,10 +30,7 @@ public async Task TestFunctionRun() { var inputs = new FunctionInputs { - ClimateZone = ClimateZone.Csa_MediterraneanHotSummer.ToString(), - CheckWindows = true, - CheckWalls = true, - CheckRoofs = true, + // TODO: Define test inputs }; var automationRunData = await TestAutomateUtils.CreateTestRun(client);