public ScoreUserItemStatistic(Tag tag, UserInTest inTest, decimal? totalScore) { Name = tag.TagName; var details = inTest.UserInTestDetails.Where(i => { var tagIds = i.Question.TagInQuestions.Select(k => k.Tag.TagID); return tagIds.Contains(tag.TagID); }); var score = details.Sum(i => i.RealScore() ?? 0 + i.RealNonChoiceScore() ?? 0); decimal percent = 0; if (totalScore.HasValue) { percent = score / totalScore.Value; } Percent = percent; }
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(); } }