private IEnumerable<AggregationResult> GetAggregationResult(Project project, AggregationType aggregationType, decimal? lambda = null) { var aggregationResult = new AggregationResult(); aggregationResult.Items = new List<AggregationResultItem>(); aggregationResult.Project = project; IAggregation aggregation = null; switch (aggregationType) { case AggregationType.MIN: case AggregationType.MAX: case AggregationType.AVERAGE: aggregation = AggregationFactory.CreateSimpleAggregation(aggregationType); foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation, }); } break; case AggregationType.OWA: case AggregationType.OWG: foreach (var weight in project.WeightGenerationResults) { aggregationResult = new AggregationResult(); aggregationResult.Items = new List<AggregationResultItem>(); aggregationResult.Project = project; aggregationResult.Weight = weight; foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); List<decimal> weights = weight.GetWeights(alternative); aggregation = AggregationFactory.CreateWeightAggregation(aggregationType, weights.ToList()); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation }); } yield return aggregationResult; } break; case AggregationType.IOWA: case AggregationType.IOWG: foreach (var weight in project.WeightGenerationResults) { aggregationResult = new AggregationResult(); aggregationResult.Items = new List<AggregationResultItem>(); aggregationResult.Project = project; aggregationResult.Weight = weight; foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); List<decimal> weights = weight.GetWeights(alternative); List<decimal> ratings = weight.GetRatings(alternative); aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), ratings); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation }); } yield return aggregationResult; } break; case AggregationType.IGOWA: foreach (var weight in project.WeightGenerationResults) { aggregationResult = new AggregationResult(); aggregationResult.Items = new List<AggregationResultItem>(); aggregationResult.Project = project; aggregationResult.Weight = weight; foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); List<decimal> weights = weight.GetWeights(alternative); List<decimal> ratings = weight.GetRatings(alternative); aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), ratings, lambda.Value); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation }); } yield return aggregationResult; } break; case AggregationType.GOWA: foreach (var weight in project.WeightGenerationResults) { aggregationResult = new AggregationResult(); aggregationResult.Items = new List<AggregationResultItem>(); aggregationResult.Project = project; aggregationResult.Weight = weight; aggregationResult.Lambda = lambda; foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); List<decimal> weights = weight.GetWeights(alternative); aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), lambda.Value); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation }); } yield return aggregationResult; } break; case AggregationType.POWA: foreach (var weight in project.WeightGenerationResults) { aggregationResult = new AggregationResult(); aggregationResult.Items = new List<AggregationResultItem>(); aggregationResult.Project = project; aggregationResult.Weight = weight; aggregationResult.Lambda = lambda; foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); List<decimal> weights = weight.GetWeights(alternative); List<decimal> probabilities = weight.GetProbabilities(alternative); aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), probabilities, lambda); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation }); } yield return aggregationResult; } break; case AggregationType.ASPOWA_MIN: case AggregationType.ASPOWA_MAX: case AggregationType.ASPOWA_MEAN: foreach (var weight in project.WeightGenerationResults) { aggregationResult = new AggregationResult(); aggregationResult.Items = new List<AggregationResultItem>(); aggregationResult.Project = project; aggregationResult.Weight = weight; aggregationResult.Lambda = lambda; foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId)) { var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId) .OrderBy(x => x.FactorId).ToList(); var points = row.Select(x => x.Points).ToList(); List<decimal> weights = weight.GetWeights(alternative); List<decimal> possibilities = weight.GetPossibilities(alternative); aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), possibilities, lambda); var calculatedAggregation = aggregation.Calc(points); aggregationResult.Items.Add(new AggregationResultItem() { Alternative = alternative, Aggregation = calculatedAggregation }); } yield return aggregationResult; } break; } yield return aggregationResult; }
private static FillRatingsViewModel GetFillRatingsViewModel(Project project, FillRatingsViewModel existing = null) { existing = existing ?? new FillRatingsViewModel(); var firstAlternative = project.Alternatives.First(); existing.Ratings = project.WeightGenerationResults.Select(x => new FillRatingsItemModel() { WeightId = x.WeightGenerationResultId, Method = x.GenerationMethod, FactorNames = x.GetFirstAlternativeFactors().Select(factor => factor.Factor.FactorName).ToList(), }).ToList(); return existing; }