4 Commits

Author SHA1 Message Date
oguzhankoral b148e50438 Mark template function as success 2024-11-13 20:59:49 +00:00
oguzhankoral 92d8303834 Remove business logic 2024-11-13 14:20:08 +00:00
oguzhankoral 1c8fe8927e Fix typo
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
2024-11-13 09:25:49 +00:00
oguzhankoral b2b8791d28 Replace window dict with wall
build and deploy Speckle functions / publish-automate-function-version (push) Has been cancelled
2024-11-13 09:17:33 +00:00
5 changed files with 173 additions and 208 deletions
@@ -21,45 +21,24 @@ public static class AutomateFunction
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();
// 0- Get climate zone from function inputs
Console.WriteLine("Flatten the root object");
var flatten = rootObject.Flatten().ToList();
// 1- Receive version from automation context
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);
// 2- Flatten the objects in received root object
Console.WriteLine("Checking for compliance");
var failedObjects = new List<ObjectToCheck>();
var failedWalls = CheckCompliance(walls, climateZone, SpeckleType.Wall);
var failedWindows = CheckCompliance(windows, climateZone, SpeckleType.Window);
var failedRoofs = CheckCompliance(roofs, climateZone, SpeckleType.Roof);
// 3- Get the objects we need
failedObjects.AddRange(failedWalls);
failedObjects.AddRange(failedWindows);
failedObjects.AddRange(failedRoofs);
// 4- Check the compliance for given object types
Console.WriteLine("Reporting compliance for failed objects");
AttachReportToFailedObjects(automationContext, failedObjects);
// 5- Attach report to failed objects to be able to highlight them in viewer or Revit connector
Console.WriteLine("Reporting the status of all automation");
ReportStatus(
automationContext,
functionInputs,
walls.Count(),
failedWalls.Count(),
windows.Count(),
failedWindows.Count(),
roofs.Count(),
failedRoofs.Count()
// 6- Report the automation result as SUCCESS/FAIL
automationContext.MarkRunSuccess(
"We are going to fail successfully in a bit, don't worry!"
);
}
@@ -75,12 +54,12 @@ public static class AutomateFunction
if (failedObject.UValue == 0)
{
message =
$"{speckleTypeString[..^1]} has no any material that have thermal properties.";
$"{speckleTypeString} has no any material that have thermal properties.";
}
else
{
message =
$"{speckleTypeString[..^1]} expected to have maximum {failedObject.ExpectedUValue} U-value but it is {failedObject.UValue}.";
$"{speckleTypeString} expected to have maximum {failedObject.ExpectedUValue} U-value but it is {failedObject.UValue}.";
}
automationContext.AttachResultToObjects(
@@ -106,7 +85,7 @@ public static class AutomateFunction
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 +97,7 @@ public static class AutomateFunction
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 +110,7 @@ public static class AutomateFunction
}
}
if (functionInputs.CheckWindows)
if (true) // TODO: Check the whether roofs included or not from function inputs
{
message += "ROOFS:\n";
if (numberOfRoofs > 0)
@@ -196,47 +175,4 @@ public static class AutomateFunction
// Handle the case where the ClimateZone string is not a valid ClimateZones value
throw new ArgumentException($"Invalid ClimateZone: {climateZoneString}");
}
private static IEnumerable<Base> GetByType(
IEnumerable<Base> objects,
SpeckleType speckleType
)
{
return objects.Where(b =>
b.speckle_type == SpeckleTypes[speckleType]
&& (string)b["category"]! == SpeckleCategories[speckleType]
);
}
private static IEnumerable<Base> GetByType<T>(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<SpeckleType, string> 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<SpeckleType, string> SpeckleCategories =
new()
{
{ SpeckleType.Wall, "Walls" },
{ SpeckleType.Window, "Windows" },
{ SpeckleType.Roof, "Roofs" },
};
}
+101 -110
View File
@@ -34,119 +34,110 @@ public enum ClimateZone
// Polar Climates
ET_Tundra,
EF_IceCap
EF_IceCap,
}
public static class UValues
{
public static Dictionary<ClimateZone, double> Wall => new ()
{
// Tropical Climates
{ ClimateZone.Af_TropicalRainforest, 0.9 },
{ ClimateZone.Am_TropicalMonsoon, 1.0 },
{ ClimateZone.Aw_TropicalSavanna, 1.1 },
{ ClimateZone.As_TropicalSavanna, 1.1 },
public static Dictionary<ClimateZone, double> Window =>
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 },
};
// Dry Climates
{ ClimateZone.BWh_HotDesert, 1.0 },
{ ClimateZone.BWk_ColdDesert, 1.2 },
{ ClimateZone.BSh_HotSemiArid, 1.2 },
{ ClimateZone.BSk_ColdSemiArid, 1.5 },
public static Dictionary<ClimateZone, double> Wall =>
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 },
};
// 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<ClimateZone, double> 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<ClimateZone, double> 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 }
};
}
public static Dictionary<ClimateZone, double> 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 },
};
}
+7 -16
View File
@@ -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
}
@@ -0,0 +1,50 @@
using Speckle.Core.Models;
using Speckle.Core.Models.GraphTraversal;
namespace TestAutomateFunction;
public class SpeckleTypeUtilities
{
public static IEnumerable<Base> GetByType(
IEnumerable<Base> objects,
SpeckleType speckleType
)
{
return objects.Where(b =>
b.speckle_type == SpeckleTypes[speckleType]
&& (string)b["category"]! == SpeckleCategories[speckleType]
);
}
public static IEnumerable<Base> GetByType<T>(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<SpeckleType, string> 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<SpeckleType, string> SpeckleCategories =
new()
{
{ SpeckleType.Wall, "Walls" },
{ SpeckleType.Window, "Windows" },
{ SpeckleType.Roof, "Roofs" },
};
}
@@ -30,10 +30,7 @@ public sealed class AutomationContextTest : IDisposable
{
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);