private void InitScoreTest(Test test, List<int> checkIds) { var db = SingletonDb.Instance(); TestTitle = test.TestTitle; CheckedUserIds = checkIds; var tags = test.Questions.SelectMany(k => k.TagInQuestions.Select(i => i.Tag)).ToList(); var lGroupTags = from tag in tags group tag by tag into GroupTags select GroupTags; var gTags = lGroupTags.Select(i => i.Key).ToList(); TotalScoreOfTest = test.Questions.TotalRealScore(); InTests = test.UserInTests.FilterInTestsOnAttempSetting(); ScoreUserList = new List<ScoreUserItem>(); InTests.ForEach(i => { if (i.User != null) { var item = new ScoreUserItem(gTags, i, TotalScoreOfTest); ScoreUserList.Add(item); } }); if (CheckedUserIds.Count != 0) { var names = ScoreUserList.Where(t => CheckedUserIds.Contains(t.UserID)).Select(k => k.UserLabel).Aggregate((i, o) => i + "," + o); if (names != null) { ScoreUsersNameLabel = names; } var groupTags = lGroupTags.Select(i => new ScoreTag(i.Key, test.TestID, checkIds)); AvailableTags = groupTags.ToList(); Overall = new ScoreStatistics(); Overall.Name = "Overall"; var totalScore = test.Questions.TotalRealScore(); var groupScoreList = InTests.Select(i => { return i.UserInTestDetails.Sum(k => k.RealNonChoiceScore() ?? 0 + k.RealScore() ?? 0); }); var stdevScore = groupScoreList.StandardDeviation(); var averageScore = groupScoreList.Average(); var userScoreList = InTests.Where(k => checkIds.Contains(k.UserID)).Select(i => { return i.UserInTestDetails.Sum(k => k.RealNonChoiceScore() ?? 0 + k.RealScore() ?? 0); }); var selectionAverageScore = userScoreList.Average(); Overall.SelectionAVGScore = new ScoreStatistic(selectionAverageScore, totalScore); Overall.GroupAVGScore = new ScoreStatistic(averageScore, totalScore); Overall.DifferenceScore = new ScoreStatistic(selectionAverageScore - averageScore, 1); Overall.GroupSTDEVScore = new ScoreStatistic(stdevScore, 1); Overall.ScoreList = userScoreList.ToList(); UsersScores = InTests.Where(k => checkIds.Contains(k.UserID)).Select(i => { var userScore = new ScoreOnUser(); userScore.Name = !string.IsNullOrEmpty(i.User.Name) ? i.User.Name : i.User.UserMail; decimal? percent = 0; if (totalScore != 0) { percent = (i.UserInTestDetails.Sum(k => k.RealNonChoiceScore() ?? 0 + k.RealScore() ?? 0) / totalScore).RoundTwo() * 100; } userScore.Percent = percent; userScore.UserId = i.UserID; return userScore; }).ToList(); } }
public ScoreTag(Tag tag, int testid, List<int> checkIds) { Tag = tag; if (tag != null) { var questions = tag.TagInQuestions.Where(i => i.Question.TestID == testid).Select(k => k.Question); statistic = new ScoreStatistics(); var totalScore = questions.TotalRealScore(); var inTests = questions.SelectMany(i => i.UserInTestDetails.Select(k => k.UserInTest)) .GroupBy(i=>i).Select(i=>i.Key); var filteredInTest = inTests.FilterInTestsOnAttempSetting().Select(i=>i.UserInTestID); var groupDetails = questions.SelectMany(i => i.UserInTestDetails).Where(i => filteredInTest.Contains(i.UserInTestID)); var groupCalculate = from g in groupDetails group g by g.UserInTestID into GroupDetails select new {Score = GroupDetails.Sum(k => k.RealNonChoiceScore() ?? 0 + k.RealScore() ?? 0) }; var userDetails = groupDetails.Where(i => checkIds.Contains(i.UserInTest.UserID)); var userCalculate = from g in userDetails group g by g.UserInTestID into UserDetails select new { Score = UserDetails.Sum(k => k.RealNonChoiceScore() ?? 0 + k.RealScore() ?? 0) }; var selectionAverageScore = userCalculate.Average(i => i.Score); var groupAverageScore = groupCalculate.Average(i => i.Score); var stdevScore = groupCalculate.Select(i => i.Score).StandardDeviation(); var userScoreList = userCalculate.Select(i => i.Score); statistic.Name = tag.TagName; statistic.SelectionAVGScore = new ScoreStatistic(selectionAverageScore, totalScore); statistic.GroupAVGScore = new ScoreStatistic(groupAverageScore, totalScore); statistic.DifferenceScore = new ScoreStatistic(selectionAverageScore - groupAverageScore, 1); statistic.GroupSTDEVScore = new ScoreStatistic(stdevScore, 1); statistic.ScoreList = userScoreList.ToList(); } }