From a62633974f701711f5c5b6ca3c9eadaaf4bff59b Mon Sep 17 00:00:00 2001 From: oguzhankoral Date: Tue, 12 Nov 2024 16:19:17 +0000 Subject: [PATCH] Clean up --- .../AutomateFunction.cs | 279 ++++++++++-------- SpeckleAutomateDotnetExample/ClimateZone.cs | 152 ++++++++++ .../FunctionInputs.cs | 156 +--------- SpeckleAutomateDotnetExample/ObjectToCheck.cs | 32 ++ SpeckleAutomateDotnetExample/Program.cs | 1 + TestAutomateFunction/AutomationContextTest.cs | 14 +- 6 files changed, 345 insertions(+), 289 deletions(-) create mode 100644 SpeckleAutomateDotnetExample/ClimateZone.cs create mode 100644 SpeckleAutomateDotnetExample/ObjectToCheck.cs diff --git a/SpeckleAutomateDotnetExample/AutomateFunction.cs b/SpeckleAutomateDotnetExample/AutomateFunction.cs index 8fb3671..8dae43a 100644 --- a/SpeckleAutomateDotnetExample/AutomateFunction.cs +++ b/SpeckleAutomateDotnetExample/AutomateFunction.cs @@ -3,12 +3,15 @@ using Speckle.Automate.Sdk.Schema; using Speckle.Core.Models; using Speckle.Core.Models.Extensions; +using Speckle.Core.Models.GraphTraversal; + +namespace TestAutomateFunction; public enum SpeckleType { Wall, Window, - Roof + Roof, } public static class AutomateFunction @@ -18,31 +21,85 @@ 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 commitObject = await automationContext.ReceiveVersion(); - - var flatten = commitObject.Flatten().ToList(); - var failedObjectIds = new List(); - var failedWallIds = CheckWalls(automationContext, functionInputs, flatten); - failedObjectIds.AddRange(failedWallIds); - var failedWindowIds = CheckWindows(automationContext, functionInputs, flatten); - failedObjectIds.AddRange(failedWindowIds); - var failedRoofIds = CheckRoofs(automationContext, functionInputs, flatten); - failedObjectIds.AddRange(failedRoofIds); - - if (failedObjectIds.Count > 0) + 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() + ); + } + + private static void AttachReportToFailedObjects( + AutomationContext automationContext, + IEnumerable failedObjects + ) + { + foreach (var failedObject in failedObjects) + { + var speckleTypeString = failedObject.SpeckleType.ToString(); + automationContext.AttachResultToObjects( + ObjectResultLevel.Error, + speckleTypeString, + new[] { failedObject.Id }, + $"{speckleTypeString[..^1]} expected to have maximum {failedObject.ExpectedUValue} U-value but it is {failedObject.UValue}." + ); + } + } + + private static void ReportStatus( + AutomationContext automationContext, + FunctionInputs functionInputs, + int numberOfWalls, + int numberOfFailedWalls, + int numberOfWindows, + int numberOfFailedWindows, + int numberOfRoofs, + int numberOfFailedRoofs + ) + { + if (numberOfFailedWalls + numberOfFailedWindows + numberOfFailedRoofs > 0) { var message = ""; if (functionInputs.CheckWalls) { - var wallCount = GetByType(flatten, SpeckleType.Wall).Count(); message += "WALLS:\n"; - if (wallCount > 0) + if (numberOfWalls > 0) { - message += $"{failedWallIds.Count}/{wallCount} wall(s) failed.\n"; + message += $"{numberOfFailedWalls}/{numberOfWalls} wall(s) failed.\n"; } else { @@ -51,25 +108,23 @@ FunctionInputs functionInputs } if (functionInputs.CheckWindows) { - var windowCount = GetByType(flatten, SpeckleType.Window).Count(); message += "WINDOWS:\n"; - if (windowCount > 0) + if (numberOfWindows > 0) { - message += $"{failedWindowIds.Count}/{windowCount} window(s) failed.\n"; + message += $"{numberOfFailedWindows}/{numberOfWindows} window(s) failed.\n"; } else { message += "There are no windows\n\n"; } } - + if (functionInputs.CheckWindows) { - var roofCount = GetByType(flatten, SpeckleType.Roof).Count(); message += "ROOFS:\n"; - if (roofCount > 0) + if (numberOfRoofs > 0) { - message += $"{failedRoofIds.Count}/{roofCount} roof(s) failed.\n"; + message += $"{numberOfFailedRoofs}/{numberOfRoofs} roof(s) failed.\n"; } else { @@ -80,132 +135,96 @@ FunctionInputs functionInputs } else { - automationContext.MarkRunSuccess($"Your building is compliant with selected climate zone!"); + automationContext.MarkRunSuccess( + $"Your building is compliant with selected climate zone!" + ); } } - private static List CheckWalls(AutomationContext automationContext, FunctionInputs functionInputs, IEnumerable flatten) + private static double GetExpectedValue( + ClimateZone climateZone, + SpeckleType speckleType + ) { - if (!functionInputs.CheckWalls) - { - return new List(); - } - - var walls = GetByType(flatten, SpeckleType.Wall); - var uValues = walls.Select(GetThermalResistance); - // Attempt to parse ClimateZone as a ClimateZones enum - if (Enum.TryParse(functionInputs.ClimateZone, out ClimateZones climateZoneEnum)) + switch (speckleType) { - var expectedValue = UValues.Wall[climateZoneEnum]; - var failedObjectIds = uValues.Where(val => val.value < expectedValue).Select(v => (v.id, v.value)).ToList(); - - foreach (var (id, value) in failedObjectIds) - { - automationContext.AttachResultToObjects( - ObjectResultLevel.Error, - "Walls", - new []{id}, - $"Wall expected to have maximum {expectedValue} U-value but it is {value}." - ); - } - return failedObjectIds.Select(i => i.id).ToList(); + case SpeckleType.Wall: + return UValues.Wall[climateZone]; + case SpeckleType.Window: + return UValues.Window[climateZone]; + case SpeckleType.Roof: + return UValues.Roof[climateZone]; + default: + return 0; } - - // Handle the case where the ClimateZone string is not a valid ClimateZones value - throw new ArgumentException($"Invalid ClimateZone: {functionInputs.ClimateZone}"); } - - private static List CheckWindows(AutomationContext automationContext, FunctionInputs functionInputs, IEnumerable flatten) - { - if (!functionInputs.CheckWindows) - { - return new List(); - } - - var walls = GetByType(flatten, SpeckleType.Window); - var uValues = walls.Select(GetThermalResistance); - if (Enum.TryParse(functionInputs.ClimateZone, out ClimateZones climateZoneEnum)) - { - var expectedValue = UValues.Window[climateZoneEnum]; - var failedObjectIds = uValues.Where(val => val.value < expectedValue).Select(v => (v.id, v.value)).ToList(); - foreach (var (id, value) in failedObjectIds) - { - automationContext.AttachResultToObjects( - ObjectResultLevel.Error, - "Windows", - new []{id}, - $"Window expected to have maximum {expectedValue} U-value but it is {value}." - ); - } - return failedObjectIds.Select(i => i.id).ToList(); - } - - // Handle the case where the ClimateZone string is not a valid ClimateZones value - throw new ArgumentException($"Invalid ClimateZone: {functionInputs.ClimateZone}"); + private static IEnumerable CheckCompliance( + IEnumerable objects, + ClimateZone climateZone, + SpeckleType speckleType + ) + { + var expectedValue = GetExpectedValue(climateZone, speckleType); + var objectsToCheck = objects.Select(o => new ObjectToCheck( + o, + expectedValue, + speckleType + )); + return objectsToCheck.Where(obj => obj.UValue < expectedValue); } - - private static List CheckRoofs(AutomationContext automationContext, FunctionInputs functionInputs, IEnumerable flatten) + + private static ClimateZone GetClimateZone(string climateZoneString) { - if (!functionInputs.CheckRoofs) + if (Enum.TryParse(climateZoneString, out ClimateZone climateZoneEnum)) { - return new List(); + return climateZoneEnum; } - - var walls = GetByType(flatten, SpeckleType.Roof); - var uValues = walls.Select(GetThermalResistance); - if (Enum.TryParse(functionInputs.ClimateZone, out ClimateZones climateZoneEnum)) - { - var expectedValue = UValues.Roof[climateZoneEnum]; - var failedObjectIds = uValues.Where(val => val.value < expectedValue).Select(v => (v.id, v.value)).ToList(); - foreach (var (id, value) in failedObjectIds) - { - automationContext.AttachResultToObjects( - ObjectResultLevel.Error, - "Roofs", - new []{id}, - $"Roof expected to have maximum {expectedValue} U-value but it is {value}." - ); - } - return failedObjectIds.Select(i => i.id).ToList(); - } - // Handle the case where the ClimateZone string is not a valid ClimateZones value - throw new ArgumentException($"Invalid ClimateZone: {functionInputs.ClimateZone}"); + throw new ArgumentException($"Invalid ClimateZone: {climateZoneString}"); } - private static IEnumerable GetByType(IEnumerable objects, SpeckleType speckleType) + private static IEnumerable GetByType( + IEnumerable objects, + SpeckleType speckleType + ) { - return objects.Where(b => b.speckle_type == SpeckleTypes[speckleType] && - (string)b["category"]! == SpeckleCategories[speckleType]); + return objects.Where(b => + b.speckle_type == SpeckleTypes[speckleType] + && (string)b["category"]! == SpeckleCategories[speckleType] + ); } - private static (string id, double value) GetThermalResistance(Base obj) + private static IEnumerable GetByType(Base root) + where T : Base { - 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 u = analyticalProperties!["Heat Transfer Coefficient (U)"] as Dictionary; - var value = u!["value"] is double ? (double)u!["value"] : 0; - return (obj.id, value); + var traversal = new GraphTraversal(); + return traversal + .Traverse(root) + .Where(obj => obj.Current is T) + .Select(obj => obj.Current); } - - private static readonly Dictionary SpeckleTypes = new Dictionary() - { - { 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 Dictionary() - { - { SpeckleType.Wall, "Walls"}, - { SpeckleType.Window, "Windows"}, - { SpeckleType.Roof, "Roofs"}, - }; + + 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/ClimateZone.cs b/SpeckleAutomateDotnetExample/ClimateZone.cs new file mode 100644 index 0000000..168b408 --- /dev/null +++ b/SpeckleAutomateDotnetExample/ClimateZone.cs @@ -0,0 +1,152 @@ +namespace TestAutomateFunction; + +public enum ClimateZone +{ + // Tropical Climates + Af_TropicalRainforest, + Am_TropicalMonsoon, + Aw_TropicalSavanna, + As_TropicalSavanna, + + // Dry Climates + BWh_HotDesert, + BWk_ColdDesert, + BSh_HotSemiArid, + BSk_ColdSemiArid, + + // Temperate Climates + Cfa_HumidSubtropical, + Cfb_Oceanic, + Cfc_SubpolarOceanic, + Csa_MediterraneanHotSummer, + Csb_MediterraneanWarmSummer, + Csc_MediterraneanCoolSummer, + + // Continental Climates + Dfa_HumidContinentalHotSummer, + Dfb_HumidContinentalMildSummer, + Dfc_Subarctic, + Dfd_SubarcticExtremeWinter, + Dsa_MediterraneanInfluenceSnowyWinter, + Dsb_MediterraneanInfluenceSnowyWinter, + Dsc_MediterraneanInfluenceSnowyWinter, + Dsd_MediterraneanInfluenceSnowyWinter, + + // Polar Climates + ET_Tundra, + EF_IceCap +} + +public static class UValues +{ + public static Dictionary Wall => new () + { + // Tropical Climates + { ClimateZone.Af_TropicalRainforest, 0.9 }, + { ClimateZone.Am_TropicalMonsoon, 1.0 }, + { ClimateZone.Aw_TropicalSavanna, 1.1 }, + { ClimateZone.As_TropicalSavanna, 1.1 }, + + // Dry Climates + { ClimateZone.BWh_HotDesert, 1.0 }, + { ClimateZone.BWk_ColdDesert, 1.2 }, + { ClimateZone.BSh_HotSemiArid, 1.2 }, + { ClimateZone.BSk_ColdSemiArid, 1.5 }, + + // Temperate Climates + { ClimateZone.Cfa_HumidSubtropical, 1.4 }, + { ClimateZone.Cfb_Oceanic, 1.3 }, + { ClimateZone.Cfc_SubpolarOceanic, 1.2 }, + { ClimateZone.Csa_MediterraneanHotSummer, 1.51 }, + { ClimateZone.Csb_MediterraneanWarmSummer, 1.4 }, + { ClimateZone.Csc_MediterraneanCoolSummer, 1.3 }, + + // Continental Climates + { ClimateZone.Dfa_HumidContinentalHotSummer, 1.3 }, + { ClimateZone.Dfb_HumidContinentalMildSummer, 1.2 }, + { ClimateZone.Dfc_Subarctic, 0.7 }, + { ClimateZone.Dfd_SubarcticExtremeWinter, 0.6 }, + { ClimateZone.Dsa_MediterraneanInfluenceSnowyWinter, 1.2 }, + { ClimateZone.Dsb_MediterraneanInfluenceSnowyWinter, 1.1 }, + { ClimateZone.Dsc_MediterraneanInfluenceSnowyWinter, 0.9 }, + { ClimateZone.Dsd_MediterraneanInfluenceSnowyWinter, 0.8 }, + + // Polar Climates + { ClimateZone.ET_Tundra, 0.5 }, + { ClimateZone.EF_IceCap, 0.4 } + }; + + public static Dictionary Window => new () + { + // Tropical Climates + { ClimateZone.Af_TropicalRainforest, 0.8 }, + { ClimateZone.Am_TropicalMonsoon, 0.8 }, + { ClimateZone.Aw_TropicalSavanna, 0.9 }, + { ClimateZone.As_TropicalSavanna, 0.9 }, + + // Dry Climates + { ClimateZone.BWh_HotDesert, 0.7 }, + { ClimateZone.BWk_ColdDesert, 0.9 }, + { ClimateZone.BSh_HotSemiArid, 0.8 }, + { ClimateZone.BSk_ColdSemiArid, 0.85 }, + + // Temperate Climates + { ClimateZone.Cfa_HumidSubtropical, 0.6 }, + { ClimateZone.Cfb_Oceanic, 0.7 }, + { ClimateZone.Cfc_SubpolarOceanic, 0.75 }, + { ClimateZone.Csa_MediterraneanHotSummer, 0.55 }, + { ClimateZone.Csb_MediterraneanWarmSummer, 0.65 }, + { ClimateZone.Csc_MediterraneanCoolSummer, 0.7 }, + + // Continental Climates + { ClimateZone.Dfa_HumidContinentalHotSummer, 0.75 }, + { ClimateZone.Dfb_HumidContinentalMildSummer, 0.8 }, + { ClimateZone.Dfc_Subarctic, 0.5 }, + { ClimateZone.Dfd_SubarcticExtremeWinter, 0.45 }, + { ClimateZone.Dsa_MediterraneanInfluenceSnowyWinter, 0.7 }, + { ClimateZone.Dsb_MediterraneanInfluenceSnowyWinter, 0.65 }, + { ClimateZone.Dsc_MediterraneanInfluenceSnowyWinter, 0.55 }, + { ClimateZone.Dsd_MediterraneanInfluenceSnowyWinter, 0.5 }, + + // Polar Climates + { ClimateZone.ET_Tundra, 0.3 }, + { ClimateZone.EF_IceCap, 0.25 } + }; + + public static Dictionary Roof => new () + { + // Tropical Climates + { ClimateZone.Af_TropicalRainforest, 1.2 }, + { ClimateZone.Am_TropicalMonsoon, 1.3 }, + { ClimateZone.Aw_TropicalSavanna, 1.4 }, + { ClimateZone.As_TropicalSavanna, 1.4 }, + + // Dry Climates + { ClimateZone.BWh_HotDesert, 1.1 }, + { ClimateZone.BWk_ColdDesert, 1.3 }, + { ClimateZone.BSh_HotSemiArid, 1.2 }, + { ClimateZone.BSk_ColdSemiArid, 1.3 }, + + // Temperate Climates + { ClimateZone.Cfa_HumidSubtropical, 1.1 }, + { ClimateZone.Cfb_Oceanic, 1.0 }, + { ClimateZone.Cfc_SubpolarOceanic, 0.9 }, + { ClimateZone.Csa_MediterraneanHotSummer, 1.2 }, + { ClimateZone.Csb_MediterraneanWarmSummer, 1.1 }, + { ClimateZone.Csc_MediterraneanCoolSummer, 1.0 }, + + // Continental Climates + { ClimateZone.Dfa_HumidContinentalHotSummer, 1.0 }, + { ClimateZone.Dfb_HumidContinentalMildSummer, 0.9 }, + { ClimateZone.Dfc_Subarctic, 0.6 }, + { ClimateZone.Dfd_SubarcticExtremeWinter, 0.5 }, + { ClimateZone.Dsa_MediterraneanInfluenceSnowyWinter, 0.9 }, + { ClimateZone.Dsb_MediterraneanInfluenceSnowyWinter, 0.8 }, + { ClimateZone.Dsc_MediterraneanInfluenceSnowyWinter, 0.7 }, + { ClimateZone.Dsd_MediterraneanInfluenceSnowyWinter, 0.6 }, + + // Polar Climates + { ClimateZone.ET_Tundra, 0.4 }, + { ClimateZone.EF_IceCap, 0.35 } + }; +} \ No newline at end of file diff --git a/SpeckleAutomateDotnetExample/FunctionInputs.cs b/SpeckleAutomateDotnetExample/FunctionInputs.cs index 66a2d5f..d61138d 100644 --- a/SpeckleAutomateDotnetExample/FunctionInputs.cs +++ b/SpeckleAutomateDotnetExample/FunctionInputs.cs @@ -1,157 +1,7 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; -public enum ClimateZones -{ - // Tropical Climates - Af_TropicalRainforest, - Am_TropicalMonsoon, - Aw_TropicalSavanna, - As_TropicalSavanna, - - // Dry Climates - BWh_HotDesert, - BWk_ColdDesert, - BSh_HotSemiArid, - BSk_ColdSemiArid, - - // Temperate Climates - Cfa_HumidSubtropical, - Cfb_Oceanic, - Cfc_SubpolarOceanic, - Csa_MediterraneanHotSummer, - Csb_MediterraneanWarmSummer, - Csc_MediterraneanCoolSummer, - - // Continental Climates - Dfa_HumidContinentalHotSummer, - Dfb_HumidContinentalMildSummer, - Dfc_Subarctic, - Dfd_SubarcticExtremeWinter, - Dsa_MediterraneanInfluenceSnowyWinter, - Dsb_MediterraneanInfluenceSnowyWinter, - Dsc_MediterraneanInfluenceSnowyWinter, - Dsd_MediterraneanInfluenceSnowyWinter, - - // Polar Climates - ET_Tundra, - EF_IceCap -} - -public static class UValues -{ - public static Dictionary Wall => new () - { - // Tropical Climates - { ClimateZones.Af_TropicalRainforest, 0.9 }, - { ClimateZones.Am_TropicalMonsoon, 1.0 }, - { ClimateZones.Aw_TropicalSavanna, 1.1 }, - { ClimateZones.As_TropicalSavanna, 1.1 }, - - // Dry Climates - { ClimateZones.BWh_HotDesert, 1.0 }, - { ClimateZones.BWk_ColdDesert, 1.2 }, - { ClimateZones.BSh_HotSemiArid, 1.2 }, - { ClimateZones.BSk_ColdSemiArid, 1.5 }, - - // Temperate Climates - { ClimateZones.Cfa_HumidSubtropical, 1.4 }, - { ClimateZones.Cfb_Oceanic, 1.3 }, - { ClimateZones.Cfc_SubpolarOceanic, 1.2 }, - { ClimateZones.Csa_MediterraneanHotSummer, 1.51 }, - { ClimateZones.Csb_MediterraneanWarmSummer, 1.4 }, - { ClimateZones.Csc_MediterraneanCoolSummer, 1.3 }, - - // Continental Climates - { ClimateZones.Dfa_HumidContinentalHotSummer, 1.3 }, - { ClimateZones.Dfb_HumidContinentalMildSummer, 1.2 }, - { ClimateZones.Dfc_Subarctic, 0.7 }, - { ClimateZones.Dfd_SubarcticExtremeWinter, 0.6 }, - { ClimateZones.Dsa_MediterraneanInfluenceSnowyWinter, 1.2 }, - { ClimateZones.Dsb_MediterraneanInfluenceSnowyWinter, 1.1 }, - { ClimateZones.Dsc_MediterraneanInfluenceSnowyWinter, 0.9 }, - { ClimateZones.Dsd_MediterraneanInfluenceSnowyWinter, 0.8 }, - - // Polar Climates - { ClimateZones.ET_Tundra, 0.5 }, - { ClimateZones.EF_IceCap, 0.4 } - }; - - public static Dictionary Window => new () - { - // Tropical Climates - { ClimateZones.Af_TropicalRainforest, 0.8 }, - { ClimateZones.Am_TropicalMonsoon, 0.8 }, - { ClimateZones.Aw_TropicalSavanna, 0.9 }, - { ClimateZones.As_TropicalSavanna, 0.9 }, - - // Dry Climates - { ClimateZones.BWh_HotDesert, 0.7 }, - { ClimateZones.BWk_ColdDesert, 0.9 }, - { ClimateZones.BSh_HotSemiArid, 0.8 }, - { ClimateZones.BSk_ColdSemiArid, 0.85 }, - - // Temperate Climates - { ClimateZones.Cfa_HumidSubtropical, 0.6 }, - { ClimateZones.Cfb_Oceanic, 0.7 }, - { ClimateZones.Cfc_SubpolarOceanic, 0.75 }, - { ClimateZones.Csa_MediterraneanHotSummer, 0.55 }, - { ClimateZones.Csb_MediterraneanWarmSummer, 0.65 }, - { ClimateZones.Csc_MediterraneanCoolSummer, 0.7 }, - - // Continental Climates - { ClimateZones.Dfa_HumidContinentalHotSummer, 0.75 }, - { ClimateZones.Dfb_HumidContinentalMildSummer, 0.8 }, - { ClimateZones.Dfc_Subarctic, 0.5 }, - { ClimateZones.Dfd_SubarcticExtremeWinter, 0.45 }, - { ClimateZones.Dsa_MediterraneanInfluenceSnowyWinter, 0.7 }, - { ClimateZones.Dsb_MediterraneanInfluenceSnowyWinter, 0.65 }, - { ClimateZones.Dsc_MediterraneanInfluenceSnowyWinter, 0.55 }, - { ClimateZones.Dsd_MediterraneanInfluenceSnowyWinter, 0.5 }, - - // Polar Climates - { ClimateZones.ET_Tundra, 0.3 }, - { ClimateZones.EF_IceCap, 0.25 } - }; - - public static Dictionary Roof => new () - { - // Tropical Climates - { ClimateZones.Af_TropicalRainforest, 1.2 }, - { ClimateZones.Am_TropicalMonsoon, 1.3 }, - { ClimateZones.Aw_TropicalSavanna, 1.4 }, - { ClimateZones.As_TropicalSavanna, 1.4 }, - - // Dry Climates - { ClimateZones.BWh_HotDesert, 1.1 }, - { ClimateZones.BWk_ColdDesert, 1.3 }, - { ClimateZones.BSh_HotSemiArid, 1.2 }, - { ClimateZones.BSk_ColdSemiArid, 1.3 }, - - // Temperate Climates - { ClimateZones.Cfa_HumidSubtropical, 1.1 }, - { ClimateZones.Cfb_Oceanic, 1.0 }, - { ClimateZones.Cfc_SubpolarOceanic, 0.9 }, - { ClimateZones.Csa_MediterraneanHotSummer, 1.2 }, - { ClimateZones.Csb_MediterraneanWarmSummer, 1.1 }, - { ClimateZones.Csc_MediterraneanCoolSummer, 1.0 }, - - // Continental Climates - { ClimateZones.Dfa_HumidContinentalHotSummer, 1.0 }, - { ClimateZones.Dfb_HumidContinentalMildSummer, 0.9 }, - { ClimateZones.Dfc_Subarctic, 0.6 }, - { ClimateZones.Dfd_SubarcticExtremeWinter, 0.5 }, - { ClimateZones.Dsa_MediterraneanInfluenceSnowyWinter, 0.9 }, - { ClimateZones.Dsb_MediterraneanInfluenceSnowyWinter, 0.8 }, - { ClimateZones.Dsc_MediterraneanInfluenceSnowyWinter, 0.7 }, - { ClimateZones.Dsd_MediterraneanInfluenceSnowyWinter, 0.6 }, - - // Polar Climates - { ClimateZones.ET_Tundra, 0.4 }, - { ClimateZones.EF_IceCap, 0.35 } - }; -} - +namespace TestAutomateFunction; /// /// This class describes the user specified variables that the function wants to work with. @@ -161,8 +11,8 @@ public static class UValues public struct FunctionInputs { [Required] - [EnumDataType(typeof(ClimateZones))] - [DefaultValue(ClimateZones.Csa_MediterraneanHotSummer)] + [EnumDataType(typeof(ClimateZone))] + [DefaultValue(TestAutomateFunction.ClimateZone.Csa_MediterraneanHotSummer)] public string ClimateZone; [Required] diff --git a/SpeckleAutomateDotnetExample/ObjectToCheck.cs b/SpeckleAutomateDotnetExample/ObjectToCheck.cs new file mode 100644 index 0000000..fe51bc0 --- /dev/null +++ b/SpeckleAutomateDotnetExample/ObjectToCheck.cs @@ -0,0 +1,32 @@ +using Speckle.Core.Models; + +namespace TestAutomateFunction; + +public class ObjectToCheck +{ + public string Id { get; } + public double UValue { get; } + public double ExpectedUValue { get; } + public SpeckleType SpeckleType { get; } + + public ObjectToCheck(Base obj, double expectedUValue, SpeckleType speckleType) + { + Id = obj.id; + ExpectedUValue = expectedUValue; + SpeckleType = speckleType; + var properties = obj["properties"] as Dictionary; + if (properties is null) + { + UValue = 0; + return; + } + var typeParameters = properties!["Type Parameters"] as Dictionary; + var analyticalProperties = + typeParameters!["Analytical Properties"] as Dictionary; + var u = + analyticalProperties!["Heat Transfer Coefficient (U)"] + as Dictionary; + var value = u!["value"] is double ? (double)u!["value"] : 0; + UValue = value; + } +} diff --git a/SpeckleAutomateDotnetExample/Program.cs b/SpeckleAutomateDotnetExample/Program.cs index 0bac59a..2d1085c 100644 --- a/SpeckleAutomateDotnetExample/Program.cs +++ b/SpeckleAutomateDotnetExample/Program.cs @@ -1,4 +1,5 @@ using Speckle.Automate.Sdk; +using TestAutomateFunction; // WARNING do not delete this call, this is the actual execution of your function return await AutomationRunner diff --git a/TestAutomateFunction/AutomationContextTest.cs b/TestAutomateFunction/AutomationContextTest.cs index acfe27a..62e0cdc 100644 --- a/TestAutomateFunction/AutomationContextTest.cs +++ b/TestAutomateFunction/AutomationContextTest.cs @@ -1,14 +1,13 @@ -namespace TestAutomateFunction; - using Speckle.Automate.Sdk; using Speckle.Automate.Sdk.Test; using Speckle.Core.Api; using Speckle.Core.Credentials; +namespace TestAutomateFunction; + [TestFixture] public sealed class AutomationContextTest : IDisposable { - private Client client; private Account account; @@ -18,7 +17,10 @@ public void Setup() account = new Account { token = TestAutomateEnvironment.GetSpeckleToken(), - serverInfo = new ServerInfo { url = TestAutomateEnvironment.GetSpeckleServerUrl().ToString() } + serverInfo = new ServerInfo + { + url = TestAutomateEnvironment.GetSpeckleServerUrl().ToString(), + }, }; client = new Client(account); } @@ -28,10 +30,10 @@ public async Task TestFunctionRun() { var inputs = new FunctionInputs { - ClimateZone = ClimateZones.Csa_MediterraneanHotSummer.ToString(), + ClimateZone = ClimateZone.Csa_MediterraneanHotSummer.ToString(), CheckWindows = true, CheckWalls = true, - CheckRoofs = true + CheckRoofs = true, }; var automationRunData = await TestAutomateUtils.CreateTestRun(client);