Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b148e50438 | |||
| 92d8303834 | |||
| 1c8fe8927e | |||
| b2b8791d28 | |||
| cbfdd67306 | |||
| a62633974f | |||
| c04328bfa4 |
@@ -3,12 +3,15 @@ using Speckle.Automate.Sdk;
|
||||
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
|
||||
@@ -21,55 +24,98 @@ public static class AutomateFunction
|
||||
Console.WriteLine("Starting execution");
|
||||
_ = typeof(ObjectsKit).Assembly; // INFO: Force objects kit to initialize
|
||||
|
||||
Console.WriteLine("Receiving version");
|
||||
var commitObject = await automationContext.ReceiveVersion();
|
||||
// 0- Get climate zone from function inputs
|
||||
|
||||
var flatten = commitObject.Flatten().ToList();
|
||||
var failedObjectIds = new List<string>();
|
||||
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)
|
||||
// 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
|
||||
automationContext.MarkRunSuccess(
|
||||
"We are going to fail successfully in a bit, don't worry!"
|
||||
);
|
||||
}
|
||||
|
||||
private static void AttachReportToFailedObjects(
|
||||
AutomationContext automationContext,
|
||||
IEnumerable<ObjectToCheck> failedObjects
|
||||
)
|
||||
{
|
||||
foreach (var failedObject in failedObjects)
|
||||
{
|
||||
var speckleTypeString = failedObject.SpeckleType.ToString();
|
||||
string message = "";
|
||||
if (failedObject.UValue == 0)
|
||||
{
|
||||
message =
|
||||
$"{speckleTypeString} has no any material that have thermal properties.";
|
||||
}
|
||||
else
|
||||
{
|
||||
message =
|
||||
$"{speckleTypeString} expected to have maximum {failedObject.ExpectedUValue} U-value but it is {failedObject.UValue}.";
|
||||
}
|
||||
|
||||
automationContext.AttachResultToObjects(
|
||||
ObjectResultLevel.Error,
|
||||
speckleTypeString,
|
||||
new[] { failedObject.Id },
|
||||
message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
if (true) // TODO: Check the whether walls included or not from function inputs
|
||||
{
|
||||
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
|
||||
{
|
||||
message += "There are no walls\n\n";
|
||||
}
|
||||
}
|
||||
if (functionInputs.CheckWindows)
|
||||
if (true) // TODO: Check the whether windows included or not from function inputs
|
||||
{
|
||||
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)
|
||||
|
||||
if (true) // TODO: Check the whether roofs included or not from function inputs
|
||||
{
|
||||
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,113 +126,53 @@ public static class AutomateFunction
|
||||
}
|
||||
else
|
||||
{
|
||||
automationContext.MarkRunSuccess($"Your building is compliant with selected climate zone!");
|
||||
}
|
||||
}
|
||||
|
||||
private static List<string> CheckWalls(AutomationContext automationContext, FunctionInputs functionInputs, IEnumerable<Base> flatten)
|
||||
{
|
||||
if (!functionInputs.CheckWalls)
|
||||
{
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
var walls = GetByType(flatten, SpeckleType.Wall);
|
||||
var uValues = walls.Select(GetThermalResistance);
|
||||
var expectedValue = UValues.Wall[functionInputs.ClimateZone];
|
||||
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}."
|
||||
automationContext.MarkRunSuccess(
|
||||
$"Your building is compliant with selected climate zone!"
|
||||
);
|
||||
}
|
||||
return failedObjectIds.Select(i => i.id).ToList();
|
||||
}
|
||||
|
||||
private static List<string> CheckWindows(AutomationContext automationContext, FunctionInputs functionInputs, IEnumerable<Base> flatten)
|
||||
{
|
||||
if (!functionInputs.CheckWindows)
|
||||
{
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
var walls = GetByType(flatten, SpeckleType.Window);
|
||||
var uValues = walls.Select(GetThermalResistance);
|
||||
var expectedValue = UValues.Window[functionInputs.ClimateZone];
|
||||
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();
|
||||
}
|
||||
|
||||
private static List<string> CheckRoofs(AutomationContext automationContext, FunctionInputs functionInputs, IEnumerable<Base> flatten)
|
||||
{
|
||||
if (!functionInputs.CheckRoofs)
|
||||
{
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
var walls = GetByType(flatten, SpeckleType.Roof);
|
||||
var uValues = walls.Select(GetThermalResistance);
|
||||
var expectedValue = UValues.Roof[functionInputs.ClimateZone];
|
||||
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();
|
||||
}
|
||||
|
||||
private static IEnumerable<Base> GetByType(IEnumerable<Base> objects, SpeckleType speckleType)
|
||||
private static double GetExpectedValue(
|
||||
ClimateZone climateZone,
|
||||
SpeckleType speckleType
|
||||
)
|
||||
{
|
||||
return objects.Where(b => b.speckle_type == SpeckleTypes[speckleType] &&
|
||||
(string)b["category"]! == SpeckleCategories[speckleType]);
|
||||
switch (speckleType)
|
||||
{
|
||||
case SpeckleType.Wall:
|
||||
return UValues.Wall[climateZone];
|
||||
case SpeckleType.Window:
|
||||
return UValues.Window[climateZone];
|
||||
case SpeckleType.Roof:
|
||||
return UValues.Roof[climateZone];
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static (string id, double value) GetThermalResistance(Base obj)
|
||||
private static IEnumerable<ObjectToCheck> CheckCompliance(
|
||||
IEnumerable<Base> objects,
|
||||
ClimateZone climateZone,
|
||||
SpeckleType speckleType
|
||||
)
|
||||
{
|
||||
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 u = analyticalProperties!["Heat Transfer Coefficient (U)"] as Dictionary<string, object>;
|
||||
var value = u!["value"] is double ? (double)u!["value"] : 0;
|
||||
return (obj.id, value);
|
||||
var expectedValue = GetExpectedValue(climateZone, speckleType);
|
||||
var objectsToCheck = objects.Select(o => new ObjectToCheck(
|
||||
o,
|
||||
expectedValue,
|
||||
speckleType
|
||||
));
|
||||
return objectsToCheck.Where(obj => obj.UValue > expectedValue || obj.UValue == 0);
|
||||
}
|
||||
|
||||
private static readonly Dictionary<SpeckleType, string> SpeckleTypes = new Dictionary<SpeckleType, string>()
|
||||
|
||||
private static ClimateZone GetClimateZone(string climateZoneString)
|
||||
{
|
||||
{ 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 Dictionary<SpeckleType, string>()
|
||||
{
|
||||
{ SpeckleType.Wall, "Walls"},
|
||||
{ SpeckleType.Window, "Windows"},
|
||||
{ SpeckleType.Roof, "Roofs"},
|
||||
};
|
||||
if (Enum.TryParse(climateZoneString, out ClimateZone climateZoneEnum))
|
||||
{
|
||||
return climateZoneEnum;
|
||||
}
|
||||
|
||||
// Handle the case where the ClimateZone string is not a valid ClimateZones value
|
||||
throw new ArgumentException($"Invalid ClimateZone: {climateZoneString}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
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<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 },
|
||||
};
|
||||
|
||||
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 },
|
||||
};
|
||||
|
||||
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 },
|
||||
};
|
||||
}
|
||||
@@ -1,159 +1,7 @@
|
||||
using Speckle.Automate.Sdk.DataAnnotations;
|
||||
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<ClimateZones, double> 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<ClimateZones, double> 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<ClimateZones, double> 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;
|
||||
|
||||
/// <summary>
|
||||
/// This class describes the user specified variables that the function wants to work with.
|
||||
@@ -162,23 +10,11 @@ public static class UValues
|
||||
/// are valid and match the required schema.
|
||||
public struct FunctionInputs
|
||||
{
|
||||
[Required]
|
||||
[EnumDataType(typeof(ClimateZones))]
|
||||
[DefaultValue(ClimateZones.Csa_MediterraneanHotSummer)]
|
||||
public ClimateZones ClimateZone;
|
||||
|
||||
[Required]
|
||||
[DefaultValue(true)]
|
||||
[Description("Include Walls")]
|
||||
public bool CheckWalls;
|
||||
|
||||
[Required]
|
||||
[DefaultValue(true)]
|
||||
[Description("Include Windows")]
|
||||
public bool CheckWindows;
|
||||
|
||||
[Required]
|
||||
[DefaultValue(true)]
|
||||
[Description("Include Roofs")]
|
||||
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,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<string, object>;
|
||||
if (properties is null)
|
||||
{
|
||||
UValue = 0;
|
||||
return;
|
||||
}
|
||||
var typeParameters = properties!["Type Parameters"] as Dictionary<string, object>;
|
||||
var analyticalProperties =
|
||||
typeParameters!["Analytical Properties"] as Dictionary<string, object>;
|
||||
var u =
|
||||
analyticalProperties!["Heat Transfer Coefficient (U)"]
|
||||
as Dictionary<string, object>;
|
||||
var value = u!["value"] is double ? (double)u!["value"] : 0;
|
||||
UValue = value;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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" },
|
||||
};
|
||||
}
|
||||
@@ -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 sealed class AutomationContextTest : IDisposable
|
||||
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,7 @@ public sealed class AutomationContextTest : IDisposable
|
||||
{
|
||||
var inputs = new FunctionInputs
|
||||
{
|
||||
ClimateZone = ClimateZones.Csa_MediterraneanHotSummer,
|
||||
CheckWindows = true,
|
||||
CheckWalls = true,
|
||||
CheckRoofs = true
|
||||
// TODO: Define test inputs
|
||||
};
|
||||
|
||||
var automationRunData = await TestAutomateUtils.CreateTestRun(client);
|
||||
|
||||
Reference in New Issue
Block a user