Ejemplo n.º 1
0
        private BuildingSearchingResult GetBuildingSearchingResult(Building building)
        {
            BuildingSearchingResult buildingSearchingResult = new BuildingSearchingResult();

            buildingSearchingResult.Building = building;

            IEnumerable <Workplace> buildingWorkplaces = _workplaceDB.GetWorkplacesByBuildingId(building.Id);

            foreach (var buildingWorkplace in buildingWorkplaces)
            {
                WorkplaceSearchingResult workplaceSearchingResult = new WorkplaceSearchingResult();
                workplaceSearchingResult.WorkplaceId = buildingWorkplace.Id;

                IEnumerable <WorkplaceEquipment> currentWorkplaceEquipments =
                    _workplaceEquipmentDB.GetWorkplaceEquipmentByWorkplace(buildingWorkplace.Id);


                double equipmentAppropriation = 0;

                foreach (var workplaceParameter in _workplaceParameters)
                {
                    WorkplaceEquipment currentWorkplaceEquipment =
                        currentWorkplaceEquipments.FirstOrDefault(x => x.EquipmentId == workplaceParameter.EquipmentId);

                    if (currentWorkplaceEquipment != null && workplaceParameter.Priority != 0)
                    {
                        if (workplaceParameter.Count == 0)
                        {
                            equipmentAppropriation += workplaceParameter.Priority;
                        }
                        else
                        {
                            double workplaceSatisfactionCoefficient =
                                (double)currentWorkplaceEquipment.Count / (double)workplaceParameter.Count;
                            workplaceSatisfactionCoefficient = (workplaceSatisfactionCoefficient > 1) ? 1 : workplaceSatisfactionCoefficient;

                            equipmentAppropriation += (workplaceSatisfactionCoefficient * workplaceParameter.Priority);
                        }
                    }
                }

                if (!_workplaceParameters.Any() || _idealMark == 0)
                {
                    workplaceSearchingResult.EquipmentAppropriation = 100;
                }
                else
                {
                    workplaceSearchingResult.EquipmentAppropriation = equipmentAppropriation / _idealMark * 100;
                }

                if (buildingWorkplace.Cost == 0)
                {
                    workplaceSearchingResult.CostAppropriation = 100;
                }
                else
                {
                    double costStisfactionCoefficient =
                        (double)_searchSetting.WantedCost / (double)buildingWorkplace.Cost;
                    costStisfactionCoefficient = (costStisfactionCoefficient > 1) ? 1 : costStisfactionCoefficient;

                    workplaceSearchingResult.CostAppropriation = costStisfactionCoefficient * 100;
                }

                buildingSearchingResult.WorkplaceSearchingResults.Add(workplaceSearchingResult);
            }

            return(buildingSearchingResult);
        }
Ejemplo n.º 2
0
 public IEnumerable <WorkplaceEquipment> GetWorkplaceEquipmentByWorkplace(int workplaceId)
 {
     return(WorkplaceEquipmentDB.GetWorkplaceEquipmentByWorkplace(workplaceId));
 }