From 12faea9ef5acf3c8cff719c6051806b22cdeced9 Mon Sep 17 00:00:00 2001 From: "AMCBRIDGE\\ksloboda" Date: Thu, 12 Oct 2023 14:17:53 +0300 Subject: [PATCH] remove SpaceMetrics overrides --- .../dependencies/CoreArea.g.cs | 4 +- .../dependencies/SpaceBoundary.g.cs | 8 +- .../dependencies/SpaceMetricsOverride.g.cs | 104 ----------------- .../dependencies/WorkplaceMetricsInputs.g.cs | 109 +----------------- WorkplaceStrategy/WorkplaceMetrics/hypar.json | 25 ---- .../WorkplaceMetrics/src/WorkplaceMetrics.cs | 84 ++------------ 6 files changed, 17 insertions(+), 317 deletions(-) delete mode 100644 WorkplaceStrategy/WorkplaceMetrics/dependencies/SpaceMetricsOverride.g.cs diff --git a/WorkplaceStrategy/WorkplaceMetrics/dependencies/CoreArea.g.cs b/WorkplaceStrategy/WorkplaceMetrics/dependencies/CoreArea.g.cs index e45bf439..420be61a 100644 --- a/WorkplaceStrategy/WorkplaceMetrics/dependencies/CoreArea.g.cs +++ b/WorkplaceStrategy/WorkplaceMetrics/dependencies/CoreArea.g.cs @@ -27,8 +27,8 @@ namespace Elements public partial class CoreArea : SpaceBoundary { [JsonConstructor] - public CoreArea(System.Guid @core, Profile @boundary, IList @cells, double @area, double? @length, double? @depth, double @height, string @programGroup, string @programType, System.Guid? @level, System.Guid? @levelLayout, string @hyparSpaceType, Transform @transform, Material @material, Representation @representation, bool @isElementDefinition, System.Guid @id, string @name) - : base(boundary, cells, area, length, depth, height, programGroup, programType, level, levelLayout, hyparSpaceType, transform, material, representation, isElementDefinition, id, name) + public CoreArea(System.Guid @core, Profile @boundary, IList @cells, double @area, double? @length, double? @depth, double @height, string @programGroup, string @programType, System.Guid? @programRequirement, System.Guid? @level, System.Guid? @levelLayout, string @hyparSpaceType, Transform @transform, Material @material, Representation @representation, bool @isElementDefinition, System.Guid @id, string @name) + : base(boundary, cells, area, length, depth, height, programGroup, programType, programRequirement, level, levelLayout, hyparSpaceType, transform, material, representation, isElementDefinition, id, name) { this.Core = @core; } diff --git a/WorkplaceStrategy/WorkplaceMetrics/dependencies/SpaceBoundary.g.cs b/WorkplaceStrategy/WorkplaceMetrics/dependencies/SpaceBoundary.g.cs index 38a59481..acdfe657 100644 --- a/WorkplaceStrategy/WorkplaceMetrics/dependencies/SpaceBoundary.g.cs +++ b/WorkplaceStrategy/WorkplaceMetrics/dependencies/SpaceBoundary.g.cs @@ -27,7 +27,7 @@ namespace Elements public partial class SpaceBoundary : GeometricElement { [JsonConstructor] - public SpaceBoundary(Profile @boundary, IList @cells, double @area, double? @length, double? @depth, double @height, string @programGroup, string @programType, System.Guid? @level, System.Guid? @levelLayout, string @hyparSpaceType, Transform @transform = null, Material @material = null, Representation @representation = null, bool @isElementDefinition = false, System.Guid @id = default, string @name = null) + public SpaceBoundary(Profile @boundary, IList @cells, double @area, double? @length, double? @depth, double @height, string @programGroup, string @programType, System.Guid? @programRequirement, System.Guid? @level, System.Guid? @levelLayout, string @hyparSpaceType, Transform @transform = null, Material @material = null, Representation @representation = null, bool @isElementDefinition = false, System.Guid @id = default, string @name = null) : base(transform, material, representation, isElementDefinition, id, name) { this.Boundary = @boundary; @@ -38,6 +38,7 @@ public SpaceBoundary(Profile @boundary, IList @cells, double @area, dou this.Height = @height; this.ProgramGroup = @programGroup; this.ProgramType = @programType; + this.ProgramRequirement = @programRequirement; this.Level = @level; this.LevelLayout = @levelLayout; this.HyparSpaceType = @hyparSpaceType; @@ -78,9 +79,12 @@ public SpaceBoundary() public string ProgramGroup { get; set; } /// The name of the program type assigned to this space (like "Open Office" or "Meeting Room") - [JsonProperty("Program Type", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [JsonProperty("Program Type", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public string ProgramType { get; set; } + [JsonProperty("Program Requirement", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public System.Guid? ProgramRequirement { get; set; } + [JsonProperty("Level", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public System.Guid? Level { get; set; } diff --git a/WorkplaceStrategy/WorkplaceMetrics/dependencies/SpaceMetricsOverride.g.cs b/WorkplaceStrategy/WorkplaceMetrics/dependencies/SpaceMetricsOverride.g.cs deleted file mode 100644 index da1521da..00000000 --- a/WorkplaceStrategy/WorkplaceMetrics/dependencies/SpaceMetricsOverride.g.cs +++ /dev/null @@ -1,104 +0,0 @@ -using Elements; -using System.Collections.Generic; -using System; -using System.Linq; - -namespace WorkplaceMetrics -{ - /// - /// Override metadata for SpaceMetricsOverride - /// - public partial class SpaceMetricsOverride : IOverride - { - public static string Name = "Space Metrics"; - public static string Dependency = "Space Planning Zones"; - public static string Context = "[*discriminator=Elements.SpaceBoundary]"; - public static string Paradigm = "Edit"; - - /// - /// Get the override name for this override. - /// - public string GetName() { - return Name; - } - - public object GetIdentity() { - - return Identity; - } - - /// - /// Get context elements that are applicable to this override. - /// - /// Dictionary of input models, or any other kind of dictionary of models. - /// List of context elements that match what is defined on the override. - public static IEnumerable> ContextProxies(Dictionary models) { - return models.AllElementsOfType(Dependency).Proxies(Dependency); - } - } - public static class SpaceMetricsOverrideExtensions - { - /// - /// Apply Space Metrics edit overrides to a collection of existing elements - /// - /// The Space Metrics Overrides to apply - /// A collection of existing elements to which to apply the overrides. - /// A function returning a boolean which indicates whether an element is a match for an override's identity. - /// A function to modify a matched element, returning the modified element. - /// The element type this override applies to. Should match the type(s) in the override's context. - /// A collection of elements, including unmodified and modified elements from the supplied collection. - public static List Apply( - this IList overrideData, - IEnumerable existingElements, - Func identityMatch, - Func modifyElement) where T : Element - { - var resultElements = new List(existingElements); - if (overrideData != null) - { - foreach (var overrideValue in overrideData) - { - // Assuming there will only be one match per identity, find the first element that matches. - var matchingElement = existingElements.FirstOrDefault(e => identityMatch(e, overrideValue.Identity)); - // if we found a match, - if (matchingElement != null) - { - // remove the old matching element - resultElements.Remove(matchingElement); - // apply the modification function to it - var modifiedElement = modifyElement(matchingElement, overrideValue); - // set the identity - Identity.AddOverrideIdentity(modifiedElement, overrideValue); - //and re-add it to the collection - resultElements.Add(modifiedElement); - } - } - } - return resultElements; - } - - /// - /// Apply Space Metrics edit overrides to a collection of existing elements - /// - /// A collection of existing elements to which to apply the overrides. - /// The Space Metrics Overrides to apply — typically `input.Overrides.SpaceMetrics` - /// A function returning a boolean which indicates whether an element is a match for an override's identity. - /// A function to modify a matched element, returning the modified element. - /// The element type this override applies to. Should match the type(s) in the override's context. - /// A collection of elements, including unmodified and modified elements from the supplied collection. - public static void ApplyOverrides( - this List existingElements, - IList overrideData, - Func identityMatch, - Func modifyElement - ) where T : Element - { - var updatedElements = overrideData.Apply(existingElements, identityMatch, modifyElement); - existingElements.Clear(); - existingElements.AddRange(updatedElements); - } - - } - - -} \ No newline at end of file diff --git a/WorkplaceStrategy/WorkplaceMetrics/dependencies/WorkplaceMetricsInputs.g.cs b/WorkplaceStrategy/WorkplaceMetrics/dependencies/WorkplaceMetricsInputs.g.cs index 9430a2bf..4d66a50c 100644 --- a/WorkplaceStrategy/WorkplaceMetrics/dependencies/WorkplaceMetricsInputs.g.cs +++ b/WorkplaceStrategy/WorkplaceMetrics/dependencies/WorkplaceMetricsInputs.g.cs @@ -98,16 +98,15 @@ public partial class Overrides public Overrides() { } [Newtonsoft.Json.JsonConstructor] - public Overrides(IList @settings, IList @spaceMetrics) + public Overrides(IList @settings) { var validator = Validator.Instance.GetFirstValidatorForType(); if(validator != null) { - validator.PreConstruct(new object[]{ @settings, @spaceMetrics}); + validator.PreConstruct(new object[]{ @settings}); } this.Settings = @settings ?? this.Settings; - this.SpaceMetrics = @spaceMetrics ?? this.SpaceMetrics; if(validator != null) { @@ -118,9 +117,6 @@ public Overrides(IList @settings, IList [Newtonsoft.Json.JsonProperty("Settings", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public IList Settings { get; set; } = new List(); - [Newtonsoft.Json.JsonProperty("Space Metrics", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public IList SpaceMetrics { get; set; } = new List(); - } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.21.0 (Newtonsoft.Json v13.0.0.0)")] @@ -160,41 +156,6 @@ public SettingsOverride(string @id, SettingsIdentity @identity, SettingsValue @v [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.21.0 (Newtonsoft.Json v13.0.0.0)")] - public partial class SpaceMetricsOverride - - { - [Newtonsoft.Json.JsonConstructor] - public SpaceMetricsOverride(string @id, SpaceMetricsIdentity @identity, SpaceMetricsValue @value) - { - var validator = Validator.Instance.GetFirstValidatorForType(); - if(validator != null) - { - validator.PreConstruct(new object[]{ @id, @identity, @value}); - } - - this.Id = @id; - this.Identity = @identity; - this.Value = @value; - - if(validator != null) - { - validator.PostConstruct(this); - } - } - - [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string Id { get; set; } - - [Newtonsoft.Json.JsonProperty("Identity", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public SpaceMetricsIdentity Identity { get; set; } - - [Newtonsoft.Json.JsonProperty("Value", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public SpaceMetricsValue Value { get; set; } - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.21.0 (Newtonsoft.Json v13.0.0.0)")] - public partial class SettingsIdentity { @@ -247,70 +208,4 @@ public SettingsValue(double @usableArea) public double UsableArea { get; set; } } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.21.0 (Newtonsoft.Json v13.0.0.0)")] - - public partial class SpaceMetricsIdentity - - { - [Newtonsoft.Json.JsonConstructor] - public SpaceMetricsIdentity(Vector3 @parentCentroid) - { - var validator = Validator.Instance.GetFirstValidatorForType(); - if(validator != null) - { - validator.PreConstruct(new object[]{ @parentCentroid}); - } - - this.ParentCentroid = @parentCentroid; - - if(validator != null) - { - validator.PostConstruct(this); - } - } - - [Newtonsoft.Json.JsonProperty("ParentCentroid", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public Vector3 ParentCentroid { get; set; } - - } - - [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.21.0 (Newtonsoft.Json v13.0.0.0)")] - - public partial class SpaceMetricsValue - - { - [Newtonsoft.Json.JsonConstructor] - public SpaceMetricsValue(double @seats, double @headcount, double @desks, double @collaborationSeats) - { - var validator = Validator.Instance.GetFirstValidatorForType(); - if(validator != null) - { - validator.PreConstruct(new object[]{ @seats, @headcount, @desks, @collaborationSeats}); - } - - this.Seats = @seats; - this.Headcount = @headcount; - this.Desks = @desks; - this.CollaborationSeats = @collaborationSeats; - - if(validator != null) - { - validator.PostConstruct(this); - } - } - - [Newtonsoft.Json.JsonProperty("Seats", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public double Seats { get; set; } - - [Newtonsoft.Json.JsonProperty("Headcount", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public double Headcount { get; set; } - - [Newtonsoft.Json.JsonProperty("Desks", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public double Desks { get; set; } - - [Newtonsoft.Json.JsonProperty("Collaboration Seats", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public double CollaborationSeats { get; set; } - - } } \ No newline at end of file diff --git a/WorkplaceStrategy/WorkplaceMetrics/hypar.json b/WorkplaceStrategy/WorkplaceMetrics/hypar.json index ef2178c8..ddea9d7b 100644 --- a/WorkplaceStrategy/WorkplaceMetrics/hypar.json +++ b/WorkplaceStrategy/WorkplaceMetrics/hypar.json @@ -222,31 +222,6 @@ "$hyparUnitType": "area" } } - }, - "Space Metrics": { - "$hyparOrder": 1, - "dependency": "Space Planning Zones", - "context": "[*discriminator=Elements.SpaceBoundary]", - "identity": { - "ParentCentroid": { - "$ref": "https://hypar.io/Schemas/Geometry/Vector3.json" - } - }, - "paradigm": "edit", - "schema": { - "Seats": { - "type": "number" - }, - "Headcount": { - "type": "number" - }, - "Desks": { - "type": "number" - }, - "Collaboration Seats": { - "type": "number" - } - } } }, "outputs": [ diff --git a/WorkplaceStrategy/WorkplaceMetrics/src/WorkplaceMetrics.cs b/WorkplaceStrategy/WorkplaceMetrics/src/WorkplaceMetrics.cs index ef32358f..baa397c0 100644 --- a/WorkplaceStrategy/WorkplaceMetrics/src/WorkplaceMetrics.cs +++ b/WorkplaceStrategy/WorkplaceMetrics/src/WorkplaceMetrics.cs @@ -8,10 +8,6 @@ namespace WorkplaceMetrics { public static class WorkplaceMetrics { - private static readonly List> proxies = new List>(); - - private static readonly string SpaceMetricDependencyName = SpaceMetricsOverride.Dependency; - private const string _openOffice = "Open Office"; private const string _meetingRoom = "Meeting Room"; private const string _classroom = "Classroom"; @@ -30,7 +26,6 @@ public static class WorkplaceMetrics /// A WorkplaceMetricsOutputs instance containing computed results and the model with any new elements. public static WorkplaceMetricsOutputs Execute(Dictionary inputModels, WorkplaceMetricsInputs input) { - proxies.Clear(); var warnings = new List(); var outputModel = new Model(); var zonesModel = inputModels["Space Planning Zones"]; @@ -143,18 +138,17 @@ public static WorkplaceMetricsOutputs Execute(Dictionary inputMod metricByLayouts[layoutName] = CountWorkplaceTyped(inputModels, input, layoutName, allSpaceBoundaries, openOfficeBoundaries, openCollabSpaceMetrics); } - var otherSpacesMetric = allSpaceBoundaries.Where(sb => !layoutNames.Contains(sb.ProgramType) && sb.Name != "Circulation").Select(sb => GetSpaceMetricConfig(input, allSpaceBoundaries, sb).Value); var meetingRoomCount = allSpaceBoundaries.Count(sb => sb.Name == "Meeting Room"); - var desksMetric = metricByLayouts.Sum(m => m.Value.Desks) + otherSpacesMetric.Sum(m => m.Desks); - var collaborationSeatsMetric = metricByLayouts.Sum(m => m.Value.CollaborationSeats) + otherSpacesMetric.Sum(m => m.CollaborationSeats); + var desksMetric = metricByLayouts.Sum(m => m.Value.Desks); + var collaborationSeatsMetric = metricByLayouts.Sum(m => m.Value.CollaborationSeats); var headcount = -1; var deskSharingRatio = 1.0; if (input.CalculationMode == WorkplaceMetricsInputsCalculationMode.Headcount) { - headcount = (int)metricByLayouts.Sum(m => m.Value.Headcount) + (int)otherSpacesMetric.Sum(m => m.Headcount); + headcount = (int)metricByLayouts.Sum(m => m.Value.Headcount); deskSharingRatio = headcount / desksMetric; } else if (input.CalculationMode == WorkplaceMetricsInputsCalculationMode.Fixed_Headcount) @@ -213,8 +207,6 @@ public static WorkplaceMetricsOutputs Execute(Dictionary inputMod { output.Warnings = warnings; } - - output.Model.AddElements(proxies); return output; } @@ -247,23 +239,16 @@ private static SpaceMetric CountWorkplaceTyped( } } - var config = GetSpaceMetricConfig(input, boundaries, room, sm); - metric.Seats += (int)config.Value.Seats; - metric.Headcount += (int)config.Value.Headcount; - metric.Desks += (int)config.Value.Desks; - metric.CollaborationSeats += (int)config.Value.CollaborationSeats; + metric.Seats += sm.Seats; + metric.Headcount += sm.Headcount; + metric.Desks += sm.Desks; + metric.CollaborationSeats += sm.CollaborationSeats; } } } return metric; } - private static SpaceMetricsOverride GetSpaceMetricConfig(WorkplaceMetricsInputs input, List boundaries, SpaceBoundary room, SpaceMetric defaultMetric = null) - { - var proxy = GetElementProxy(room, boundaries.Proxies(SpaceMetricDependencyName)); - return MatchApplicableOverride(input.Overrides.SpaceMetrics.ToList(), proxy, defaultMetric); - } - private static Dictionary CalculateAreas(bool hasProgramRequirements, IEnumerable allSpaceBoundaries) { Dictionary areas = new Dictionary(); @@ -380,60 +365,5 @@ private static Dictionary CalculateAreas(bool hasProgramRequi return areas; } - - private static SpaceMetricsOverride MatchApplicableOverride( - List overridesById, - ElementProxy boundaryProxy, - SpaceMetric defaultMetric = null) - { - var overrideName = SpaceMetricsOverride.Name; - SpaceMetricsOverride config = null; - - // See if we already have matching override attached - var existingOverrideId = boundaryProxy.OverrideIds(overrideName).FirstOrDefault(); - if (existingOverrideId != null) - { - config = overridesById.Find(o => o.Id == existingOverrideId); - if (config != null) - { - return config; - } - } - - // Try to match from identity in configs - config ??= overridesById.Find(o => o.Identity.ParentCentroid.IsAlmostEqualTo(boundaryProxy.Element.ParentCentroid.Value)); - - // Use a default in case none found - if (config == null) - { - config = new SpaceMetricsOverride( - Guid.NewGuid().ToString(), - new SpaceMetricsIdentity(boundaryProxy.Element.ParentCentroid.Value), - new SpaceMetricsValue( - defaultMetric?.Seats ?? 0, - defaultMetric?.Headcount ?? 0, - defaultMetric?.Desks ?? 0, - defaultMetric?.CollaborationSeats ?? 0) - ); - overridesById.Add(config); - } - - // Attach the identity and values data to the proxy - boundaryProxy.AddOverrideIdentity(overrideName, config.Id, config.Identity); - boundaryProxy.AddOverrideValue(overrideName, config.Value); - - // Make sure proxies list has the proxy so that it will serialize in the model. - if (!proxies.Contains(boundaryProxy)) - { - proxies.Add(boundaryProxy); - } - - return config; - } - - private static ElementProxy GetElementProxy(SpaceBoundary spaceBoundary, IEnumerable> allSpaceBoundaries) - { - return allSpaceBoundaries.Proxy(spaceBoundary) ?? spaceBoundary.Proxy(SpaceMetricDependencyName); - } } } \ No newline at end of file