public static IEnumerable <Grade> FetchAll(ProblemMapping problems, IEnumerable <IDictionary <string, string> > students) { return (from student in students let grade = new Grade(problems, student) where grade.Type != null && problems.ContainsKey(grade.Type) select grade); }
public Grade(ProblemMapping problems, IDictionary <string, string> student) { Type = student[problems.TypeField]; student.Remove(new KeyValuePair <string, string>(problems.TypeField, Type)); if (string.IsNullOrWhiteSpace(Type) || !problems.ContainsKey(Type)) { Type = null; return; } _problemMapping = problems; var studentProblems = problems[Type]; OriginalStudent = new Dictionary <string, string>(student); Student = new Dictionary <string, string>(student); foreach (var problem in studentProblems) { string grade; if (!Student.TryGetValue(problem.Key, out grade)) { grade = "0"; } _problems[problem.Value] = new Comment(problem.Key, grade); Student.Remove(new KeyValuePair <string, string>(problem.Key, grade)); foreach (var kvp in Student) { var split = kvp.Key.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (split.Count() < 2) { continue; } var id = split.LastOrDefault(); int identity; if (string.IsNullOrWhiteSpace(id) || !int.TryParse(id, out identity)) { continue; } Student[kvp.Key] = Total.ToString(); break; } var comments = ToString(); if (!string.IsNullOrWhiteSpace(comments)) { Student[CommentHeader] = comments; Student[CommentFormatHeader] = FormatText; } } }
public Grade(ProblemMapping problems, IDictionary <string, string> studentGrade, bool canDisplayAllGrades, bool relativeGrades) { _commentHeader = Settings.Default.CommentHeader; _commentFormatHeader = Settings.Default.CommentFormatHeader; var formatText = Settings.Default.CommentFormat; CanDisplayAllGrades = canDisplayAllGrades; _problemMapping = problems; var student = new Dictionary <string, string>(studentGrade); Student = student; Id = student[Settings.Default.IdField]; student.Remove(Settings.Default.IdField); if (String.IsNullOrWhiteSpace(Id) || !problems.ContainsKey(Id)) { Id = null; return; } var studentProblems = problems[Id]; foreach (var problem in studentProblems) { string grade; if (!student.TryGetValue(problem.Value.GetNumber(problem.Key), out grade)) { grade = "0"; } var comment = new Comment(problem.Key, problem.Value.IsMixed, canDisplayAllGrades, relativeGrades, grade, problem.Value.IsMultiplier() ? problem.Value.TotalMultiplier : problem.Value.TotalPoints); _problems[problem.Value] = comment; var numberString = comment.Problem.ToNumberString(); student.Remove(numberString); foreach (var kvp in student) { var split = kvp.Key.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (split.Count() < 2) { continue; } var id = split.LastOrDefault(); int identity; if (String.IsNullOrWhiteSpace(id) || !Int32.TryParse(id, out identity)) { continue; } student[kvp.Key] = Total.ToString("N2"); break; } } var comments = ToString(); if (!String.IsNullOrWhiteSpace(comments)) { student[_commentHeader] = comments; student[_commentFormatHeader] = formatText; } foreach (var key in student.Keys.ToArray()) { var split = key.Split(new[] { Settings.Default.ProblemSeparator }, 2); int dummy; if (split.Length > 1 && int.TryParse(split[1], out dummy)) { student.Remove(key); } } }