public IEnumerable <ParsedSubject> Parse(TmpObject input, ScheduleGroupType groupType) { var result = new List <ParsedSubject>(); input.Content = input.Content .Replace("Курс по выбору :", "") .Replace("Курс по выбору:", "") .Replace("Курс по выбору : ,", ""); var subjects = input.Content.Split(','); var lastSubjectName = ""; foreach (var subject in subjects) { var notation = ""; var fixedName = ""; if (subject.Contains("(")) { notation = "(" + subject.Split('(', ')')[1] + ")"; fixedName = subject.Replace(notation, ""); } else { fixedName = subject; } fixedName = Regex.Match(fixedName, @"[А-ЯA-Z].*").Value; var cabinet = Regex.Match(fixedName, @"\d+").Value; var teacher = Regex.Match(fixedName, @"[А-Я][а-я]+\s?[А-Я].[А-Я]?.?").Value; var subjectName = fixedName .Replace(teacher, "") .Replace(cabinet, "") .Replace("()", "") .Replace(" ", "") .Replace("\t", ""); subjectName = Regex.Replace(subjectName, @"[\d]", string.Empty); var parsedSubject = new ParsedSubject { SubjectName = subjectName, Time = input.Time, Cabinet = cabinet, Teacher = teacher, Type = groupType, Course = input.Course, Notation = notation }; if (parsedSubject.SubjectName.Length < 2) { parsedSubject.SubjectName = lastSubjectName; } else { lastSubjectName = subjectName; } result.Add(parsedSubject); } return(result); }
protected SetUpElectiveGroupCommand(ScheduleGroupType type, IBotDataStorage storage, IScheduleService scheduler, IKeyboardsFactory keyboards, string command, ILogger logger = null) : base(command) { this.GroupType = type; this.Storage = storage; this.Scheduler = scheduler; this.Keyboards = keyboards; this.logger = logger; Cache = new Dictionary <long, ValueTuple <IScheduleGroup, IScheduleGroup> >(); }
protected GetElectiveGroupsCommand(ScheduleGroupType type, string triggerName, string responseText, string notFoundResponseText, IBotDataStorage storage, IScheduleService scheduler, IKeyboardsFactory keyboards, string command) : base(command) { GroupType = type; this.TriggerName = triggerName; this.Storage = storage; this.Scheduler = scheduler; ResponseText = responseText; this.NotFoundResponseText = notFoundResponseText; this.Keyboards = new AdditionalCoursesKeyboardDecorator(keyboards); }
public CommonTypedRule(string name, ScheduleGroupType secondType, string academicStarts, string targetCourse, string flow = "1", string academicRegexp = null) : base(name, (g1, g2) => true) { CheckFunc = (first, second) => { IScheduleGroup academic = null; IScheduleGroup typed = null; if (first.GType == ScheduleGroupType.Academic) { academic = first; } if (first.GType == secondType) { typed = first; } if (second.GType == ScheduleGroupType.Academic) { academic = second; } if (second.GType == secondType) { typed = second; } if (typed == null || academic == null) { return(false); } if (typed.Name.ToLowerInvariant().EndsWith(flow) && typed.Name.ToLowerInvariant().Contains(targetCourse)) { var trimmed = (academic.Name.Trim()); return(trimmed.StartsWith(academicStarts) && (academicRegexp == null || Regex.IsMatch(trimmed, academicRegexp))); } return(false); }; }
public IEnumerable <IScheduleGroup> GetAllowedGroups(ScheduleGroupType ofType, IScheduleGroup target) { return(allGroups.Values.Where(g => g.GType == ofType && (rules?.Any(rule => rule.AreCompatible(target, g)) ?? true)) .ToList()); }