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();
            }
        }
 private void InitOverviewScoreTests(IEnumerable<Test> tests, List<int> userids, List<int> testids)
 {
     AllTests = tests.OrderBy(t => t.TestTitle).ToList();
     AllUsers = tests.SelectMany(i => i.UserInTests.Select(k => k.User)).GroupBy(i => i).Select(i => i.Key).OrderBy(k => k.Name).ToList();
     var checkedTests = AllTests.Where(i => testids.Contains(i.TestID));
     CheckedTestsSorted = checkedTests.OrderBy(i => i.TestTitle).ToList();
     var checkedUsers = AllUsers.Where(i => userids.Contains(i.UserID));
     CheckedUsersSorted = checkedUsers.OrderBy(i =>
     {
         var key = i.Name;
         if (string.IsNullOrEmpty(key))
         {
             key = i.UserMail;
         }
         return key;
     }).ToList();
     OverviewScores = new List<OverviewScoreOnUser>();
     foreach (var u in CheckedUsersSorted)
     {
         var scoreOnUser = new OverviewScoreOnUser();
         var scoreList = new List<ScoreUserItem>();
         foreach (var t in CheckedTestsSorted)
         {
             ScoreUserItem item = null;
             if (CheckedTestsSorted.Select(i => i.TestID).Contains(t.TestID))
             {
                 item = new ScoreUserItem(u, t);
             }
             else
             {
                 item = new ScoreUserItem(u);
             }
             scoreList.Add(item);
         }
         var totalOfAllTests = CheckedTestsSorted.Where(i => i.UserInTests.Select(t => t.UserID).Contains(u.UserID)).SelectMany(i => i.Questions).TotalRealScore();
         var gainScore = CheckedTestsSorted.SelectMany(i => i.UserInTests).Where(i => i.UserID == u.UserID).FilterInTestsOnAttempSetting().Sum(i => i.Score);
         var percentString = string.Empty;
         if (totalOfAllTests == 0)
         {
             percentString = "N/A";
             scoreOnUser.OverallDecimalPercent = null;
         }
         else
         {
             percentString = (gainScore / totalOfAllTests).ToPercent();
             if (gainScore == 0) {
                 scoreOnUser.OverallDecimalPercent = null;
             }
             else {
                 scoreOnUser.OverallDecimalPercent = (gainScore / totalOfAllTests);
             }
         }
         scoreOnUser.Overall = percentString;
         scoreOnUser.Name = u.Name;
         scoreOnUser.Scores = scoreList;
         OverviewScores.Add(scoreOnUser);
         var names = CheckedUsersSorted.Select(i => i.Name).Aggregate((i, o) => i + "," + o);
         if (names != null) { ScoreUsersNameLabel = names; }
     }
 }