/// <summary> /// Get total score summary. /// </summary> /// <param name="summaryEvaluations">The summary information.</param> /// <returns></returns> private double GetTotalScore(IEnumerable <UserEvaluationViewModel> evaluations, string weigtingKey, int percentageId) { double result = 0; if (!string.Equals(weigtingKey, "A2", StringComparison.OrdinalIgnoreCase)) { var evaCount = evaluations.Where(x => x.EvaluationLogs.Count > 0); result = evaluations.Sum(x => x.TotalScore) / evaCount.Count(); } else { var percentageConfig = _unitOfWork.GetRepository <EvaluationPercentageConfig>().GetCache(x => x.Id == percentageId).FirstOrDefault(); var purEva = evaluations.FirstOrDefault(x => x.UserType == ConstantValue.UserTypePurchasing); var userEva = evaluations.Where(x => x.UserType == ConstantValue.UserTypeEvaluator); double userAverageScore = 0; int[] percentage = new int[] { percentageConfig.PurchasePercentage, percentageConfig.UserPercentage }; if (userEva.Count() == 0) { percentage[0] = 100; //purchase percentage calculate 100 percen when no user evaluation percentage[1] = 0; //user percentage } else { userAverageScore = UtilityService.AverageScore(userEva.Sum(x => x.TotalScore), userEva.Count()); } result = UtilityService.CalculateScore(purEva.TotalScore, userAverageScore, percentage[1], percentage[0], weigtingKey); } return(result); }
/// <summary> /// Initial Summary Evaluation Detail ViewModel. /// </summary> /// <param name="item">The summary evaluation detail viewmodel.</param> /// <param name="score">The score.</param> /// <returns></returns> private SummaryEvaluationDetailViewModel InitialModel(SummaryEvaluationDetailViewModel item, double score, EvaluationPercentageConfig percentageConfig, string weightingKey, int userCount, IEnumerable <SummaryEvaluationDetailViewModel> userResult = null, string fromUser = "") { double totalScore = 0; if (!string.Equals(weightingKey, "A2", StringComparison.OrdinalIgnoreCase)) { totalScore = Math.Round(UtilityService.AverageScore((item.Score + score), userCount)); } else { int[] percentage = new int[] { percentageConfig.PurchasePercentage, percentageConfig.UserPercentage }; if (userResult == null || userResult.Count() == 0) { percentage[0] = 100; //purchase percentage calculate 100 percen when no user evaluation percentage[1] = 0; //user percentage } totalScore = UtilityService.CalculateScore(item.Score, score, percentage[1], percentage[0], weightingKey); } return(new SummaryEvaluationDetailViewModel { KpiGroupId = item.KpiGroupId, KpiId = item.KpiId.HasValue ? item.KpiId : 0, Score = totalScore, Sequence = item.Sequence }); }
/// <summary> /// Sum score between purchasing and users. /// </summary> /// <param name="purResult">The purchasing score.</param> /// <param name="userResult">The users score.</param> /// <returns></returns> private IEnumerable <SummaryEvaluationDetailViewModel> SummaryScore(IEnumerable <SummaryEvaluationDetailViewModel> purResult, IEnumerable <SummaryEvaluationDetailViewModel> userResult, int percenConfigId, int userCount, string weightingKey) { var result = new List <SummaryEvaluationDetailViewModel>(); var percentageConfig = _unitOfWork.GetRepository <EvaluationPercentageConfig>().GetCache(x => x.Id == percenConfigId).FirstOrDefault(); if (userCount > 0 && purResult.Count() <= 0) { foreach (var item in userResult) { result.Add(this.InitialModel(new SummaryEvaluationDetailViewModel { KpiGroupId = item.KpiGroupId, KpiId = item.KpiId, Sequence = item.Sequence }, UtilityService.CalculateScore(0, UtilityService.AverageScore(item.Score, userCount), percentageConfig.UserPercentage, percentageConfig.PurchasePercentage, weightingKey), percentageConfig, weightingKey, userCount, userResult, "fromUser")); } } else { foreach (var item in purResult) { double uPoint = 0; var userPoint = userResult.FirstOrDefault(x => x.KpiGroupId == item.KpiGroupId && x.KpiId == item.KpiId); if (userPoint != null) { if (string.Equals(weightingKey, "A2", StringComparison.OrdinalIgnoreCase)) { uPoint = UtilityService.AverageScore(userPoint.Score, userCount - 1); } else { uPoint = userPoint.Score; } } result.Add(this.InitialModel(item, uPoint, percentageConfig, weightingKey, userCount, userResult)); } } return(result); }