Beispiel #1
0
        public async Task <WorkplaceMetricsOutputs> Handler(WorkplaceMetricsInputs args, ILambdaContext context)
        {
            // Preload dependencies (if they exist),
            // so that they are available during model deserialization.

            var sw          = System.Diagnostics.Stopwatch.StartNew();
            var asmLocation = this.GetType().Assembly.Location;
            var asmDir      = Path.GetDirectoryName(asmLocation);

            // Explicitly load the dependencies project, it might have types
            // that aren't used in the function but are necessary for correct
            // deserialization.
            var asmName = Path.GetFileNameWithoutExtension(asmLocation);
            var depPath = Path.Combine(asmDir, $"{asmName}.Dependencies.dll");

            if (File.Exists(depPath))
            {
                Console.WriteLine($"Loading dependencies assembly from: {depPath}...");
                Assembly.LoadFrom(depPath);
                Console.WriteLine("Dependencies assembly loaded.");
            }

            // Load all reference assemblies.
            Console.WriteLine($"Loading all referenced assemblies.");
            foreach (var asm in this.GetType().Assembly.GetReferencedAssemblies())
            {
                try
                {
                    Assembly.Load(asm);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Failed to load {asm.FullName}");
                    Console.WriteLine(e.Message);
                }
            }
            sw.Stop();
            Console.WriteLine($"Time to load assemblies: {sw.Elapsed.TotalSeconds})");

            if (this.store == null)
            {
                this.store = new S3ModelStore <WorkplaceMetricsInputs>(RegionEndpoint.USWest1);
            }

            var l      = new InvocationWrapper <WorkplaceMetricsInputs, WorkplaceMetricsOutputs>(store, WorkplaceMetrics.Execute);
            var output = await l.InvokeAsync(args);

            return(output);
        }
Beispiel #2
0
        /// <summary>
        /// The WorkplaceMetrics function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A WorkplaceMetricsOutputs instance containing computed results and the model with any new elements.</returns>
        public static WorkplaceMetricsOutputs Execute(Dictionary <string, Model> inputModels, WorkplaceMetricsInputs input)
        {
            var floorsModel    = inputModels["Floors"];
            var zonesModel     = inputModels["Space Planning Zones"];
            var allFloors      = floorsModel.AllElementsOfType <Floor>();
            var totalFloorArea = 0.0;

            foreach (var floor in allFloors)
            {
                var difference = Profile.Difference(new[] { floor.Profile }, input.USFExclusions.Select(s => new Profile(s)));
                totalFloorArea += difference.Sum(d => d.Area());
            }

            var deskCount = 0;

            if (inputModels.TryGetValue("Open Office Layout", out var openOfficeModel))
            {
                deskCount += openOfficeModel.AllElementsOfType <WorkpointCount>().Sum(wc => wc.Count);
            }

            var meetingRoomCount = zonesModel.AllElementsOfType <SpaceBoundary>().Count(sb => sb.Name == "Meeting Room");

            var headcount        = -1;
            var deskSharingRatio = 1.0;

            if (input.CalculationMode == WorkplaceMetricsInputsCalculationMode.Fixed_Headcount)
            {
                headcount        = input.TotalHeadcount;
                deskSharingRatio = headcount / (double)deskCount;
            }
            else // fixed sharing ratio
            {
                deskSharingRatio = input.DeskSharingRatio;
                headcount        = (int)Math.Round(deskCount * deskSharingRatio);
            }
            var areaPerPerson    = totalFloorArea / headcount;
            var totalDeskCount   = deskCount;
            var areaPerDesk      = totalFloorArea / deskCount;
            var meetingRoomRatio = meetingRoomCount == 0 ? 0 : (int)Math.Round(headcount / (double)meetingRoomCount);
            var output           = new WorkplaceMetricsOutputs(totalFloorArea, areaPerPerson, totalDeskCount, headcount, areaPerDesk, deskSharingRatio, meetingRoomRatio);

            return(output);
        }