private void problemsListView_SelectedIndexChanged(object sender, EventArgs e) { problemsListView.BeginUpdate(); if (SelectedProblem != null) { testCaseGroupBox.Text = String.Format("Test Case Breakdown for {0}", SelectedProblem.Name); testCaseListView.Items.Clear(); foreach (TestCase testCase in SelectedProblem.TestCases) { var runs = DataContext.Runs.Where(r => r.ContestId == Contest.ContestId && r.ProblemId == testCase.ProblemId); if (!Contest.IsScoringSet(ContestScoring.TestCaseScoring)) { runs = runs.Where(r => r.TestRuns.Any(tr => tr.TestCaseId >= testCase.TestCaseId)); } int attempted = runs.Count(); int accepted = runs.Count(r => !r.TestRuns.Any(tr => tr.TestCaseId == testCase.TestCaseId)); testCaseListView.Items.Add(new ListViewItem(new[] { testCase.TestCaseId.ToString(), attempted.ToString(), accepted.ToString(), (attempted == 0 ? 0 : 1 - (accepted / (double)attempted)).ToString(), Math.Max(0.10, accepted == 0 ? 0 : 1 - accepted / (double)attempted).ToString() })); } } problemsListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); problemsListView.EndUpdate(); }
private void SetScoring(Contest contest) { foreach (CheckBox checkBox in scoringPanel.Controls.Cast <CheckBox>()) { if (contest.IsScoringSet((ContestScoring)checkBox.Tag)) { checkBox.Checked = true; } else { checkBox.Checked = false; } } }
private void userTestCaseListView_SelectedIndexChanged(object sender, EventArgs e) { userListView.BeginUpdate(); if (SelectedUser != null) { userListView.Items.Clear(); var userRuns = DataContext.Runs.Where(r => r.ContestId == Contest.ContestId && r.UserId == SelectedUser.UserId && r.ProblemId == SelectedProblem.ProblemId); var run = userRuns.SingleOrDefault(r => r.RunId == userRuns.Max(ur => ur.RunId)); double avgPoints = run.AvgPoints / DataContext.TestCases.Count(tc => tc.ProblemId == SelectedProblem.ProblemId); double sum = 0; foreach (TestCase testCase in run.Problem.TestCases) { var runs = DataContext.Runs.Where(r => r.ContestId == Contest.ContestId && r.UserId == SelectedUser.UserId && r.ProblemId == SelectedProblem.ProblemId && (!r.TestRuns.Any() || r.TestRuns.Any(tr => tr.TestCaseId >= testCase.TestCaseId))); int failed = runs.Count() - runs.Count(r => !r.TestRuns.Any(tr => tr.TestCaseId == testCase.TestCaseId)); var testCaseRuns = DataContext.Runs.Where(r => r.ContestId == Contest.ContestId && r.ProblemId == testCase.ProblemId); if (!Contest.IsScoringSet(ContestScoring.TestCaseScoring)) { testCaseRuns = testCaseRuns.Where(r => r.TestRuns.Any(tr => tr.TestCaseId >= testCase.TestCaseId)); } int attempted = testCaseRuns.Count(); int accepted = testCaseRuns.Count(r => !r.TestRuns.Any(tr => tr.TestCaseId == testCase.TestCaseId)); double ratio = Math.Max(0.10, accepted == 0 ? 0 : 1 - accepted / (double)attempted); bool solved = !run.TestRuns.Any(tr => tr.TestCaseId == testCase.TestCaseId); double points = (solved ? avgPoints * ratio * Math.Pow(0.99, failed) : 0); sum += points; userListView.Items.Add(new ListViewItem(new[] { testCase.TestCaseId.ToString(), failed.ToString(), solved.ToString(), points.ToString() })); } userGroupBox.Text = String.Format("Test Case Breakdown for {0}'s Final Run ({1} points)", SelectedUser.FirstName + " " + SelectedUser.LastName, sum); } userListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); userListView.EndUpdate(); }