예제 #1
0
        public override string ResolveStudyGroup(string grade)
        {
            if (grade == null)
            {
                logger.LogDebug($"Grade must not be empty.");
                return(null);
            }

            return(gradeStudyGroupsCache.ContainsKey(grade) ? IdResolver.Resolve(gradeStudyGroupsCache[grade]) : null);
        }
예제 #2
0
        public override string ResolveStudyGroup(string grade, string subject, string teacher)
        {
            if (grade == null)
            {
                logger.LogDebug($"Grade must not be empty.");
                return(null);
            }

            if (subject == null)
            {
                logger.LogDebug($"Subject must not be empty.");
                return(null);
            }

            if (!tuitionsCache.ContainsKey(grade))
            {
                logger.LogDebug($"Grade {grade} does not exist.");
                return(null);
            }

            var candidates = tuitionsCache[grade].Where(x => x.Subject == subject);

            if (!candidates.Any())
            {
                logger.LogDebug($"Did not find any tuition for grade {grade}, subject {subject} and teacher {teacher}");
                return(null);
            }

            if (candidates.Count() == 1)
            {
                return(IdResolver.Resolve(candidates.First().StudyGroup));
            }

            var teachers = candidates.Select(x => x.Tuition.TeacherRef.Acronym).ToList();

            logger.LogDebug($"Possible teachers are: {string.Join(", ", teachers)}");

            if (string.IsNullOrEmpty(teacher))
            {
                logger.LogDebug($"Ambiguous tuition found for grade {grade} and subject {subject}. Teacher needs to be specified.");
                return(null);
            }

            foreach (var candidate in candidates.Where(x => x.Tuition.TeacherRef != null))
            {
                if (candidate.Tuition.TeacherRef.Acronym == teacher)
                {
                    return(IdResolver.Resolve(candidate.Tuition, candidate.StudyGroup));
                }
            }

            logger.LogDebug($"Did not find any tuition for grade {grade}, subject {subject} and teacher {teacher}");
            return(null);
        }
        public List <string> Resolve(string tuition, Exam exam, string start, string end)
        {
            var date     = exam.Date;
            var students = new List <string>();
            var section  = GetSectionForDate(date);

            if (section == null)
            {
                logger.LogError($"Cannot find any SchILD section for date {date.ToShortDateString()}. Students will be empty.");
                return(students);
            }

            var key = $"{section.SchoolYear}-{section.Section}";

            if (!tuitionCache.ContainsKey(key))
            {
                logger.LogError($"Did not find any tuitions for {key}. Students will be emtpy.");
                return(students);
            }

            var match = tuitionCache[key].FirstOrDefault(x => IdResolver.Resolve(x.Tuition, x.StudyGroup) == tuition);

            if (match == null)
            {
                logger.LogError($"Did not find any tuitions for {tuition}. Students will be emtpy.");
                return(students);
            }

            foreach (var membership in match.StudyGroup.Memberships)
            {
                var student   = studentCache.ContainsKey(membership.Student.Id.ToString()) ? studentCache[membership.Student.Id.ToString()] : null;
                var candidate = settings.Rules.FirstOrDefault(x => x.Grades.Contains(membership.Grade) && x.Sections.Contains(section.Section) && x.Types.Contains(membership.Type));

                if (candidate == null)
                {
                    logger.LogDebug($"Did not find any rule for student {membership.Student.Id} (Grade: {membership.Grade}, Type: {membership.Type}, Section: {section.Section}. Ignore student.");
                }
                else if (!string.IsNullOrWhiteSpace(start) && !string.IsNullOrWhiteSpace(end) && student != null && (String.Compare(student.Lastname.ToUpper(), start.ToUpper()) < 0 || student.Lastname.ToUpper().Substring(0, end.Length) != end.ToUpper()))
                {
                    logger.LogDebug($"Ignore student with lastname {student.Lastname} because {start} <= {student.Lastname} <= {end} is not true.");
                }
                else
                {
                    students.Add(membership.Student.Id.ToString());
                }
            }

            return(students);
        }