Skip to content

Commit

Permalink
Remove business logic
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhankoral committed Nov 13, 2024
1 parent 1c8fe89 commit 92d8303
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 103 deletions.
99 changes: 16 additions & 83 deletions SpeckleAutomateDotnetExample/AutomateFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObjectToCheck>();
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(
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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<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" },
};
}
23 changes: 7 additions & 16 deletions SpeckleAutomateDotnetExample/FunctionInputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
50 changes: 50 additions & 0 deletions SpeckleAutomateDotnetExample/SpeckleTypeUtilities.cs
Original file line number Diff line number Diff line change
@@ -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" },
};
}
5 changes: 1 addition & 4 deletions TestAutomateFunction/AutomationContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 92d8303

Please sign in to comment.