From 187561882b0a49fc9b7d7743f3b1cca275187613 Mon Sep 17 00:00:00 2001 From: Yishan Zhao Date: Sat, 21 Nov 2020 11:51:26 -0500 Subject: [PATCH] bug fix --- .../Views/MainPageView.xaml.cs | 2 +- CourseScheduler.Core/Crawler.cs | 20 ++----------------- CourseScheduler.Core/DataStrucures/Section.cs | 19 +++++++++--------- 3 files changed, 12 insertions(+), 29 deletions(-) diff --git a/CourseScheduler.Avalonia/Views/MainPageView.xaml.cs b/CourseScheduler.Avalonia/Views/MainPageView.xaml.cs index 3475127..86a0fce 100644 --- a/CourseScheduler.Avalonia/Views/MainPageView.xaml.cs +++ b/CourseScheduler.Avalonia/Views/MainPageView.xaml.cs @@ -38,7 +38,7 @@ public static void ScheduleTimeTable(List
sections) for (int i = 0; i < sections.Count; i++) { - foreach (var myClass in sections[i].ClassSequences.Values) + foreach (var myClass in sections[i].ClassSequences) { foreach (var weekday in myClass.Weekdays) { diff --git a/CourseScheduler.Core/Crawler.cs b/CourseScheduler.Core/Crawler.cs index 3acd18c..5c98041 100644 --- a/CourseScheduler.Core/Crawler.cs +++ b/CourseScheduler.Core/Crawler.cs @@ -78,7 +78,7 @@ public static async Task GetCourse(string courseName, string termID) instructor += instructors[i]; } - Dictionary classes = new Dictionary(); + List classes = new List(); // Enumerate through each class of the section foreach (var row in rows) { @@ -121,23 +121,7 @@ public static async Task GetCourse(string courseName, string termID) weekdays.Add(new Weekday(day, new ClassSpan(start, end))); } - IEnumerable possibleName = row.Descendants("div") - .Where(node => node.GetAttributeValue("class", "") == "two columns"); - string className; - if (possibleName.Count() != 0) - { - className = possibleName.First().Descendants("span").First().InnerText; - } - else if (!classes.ContainsKey("Lecture")) - { - className = "Lecture"; - } - else - { - className = "Alt. Lecture"; - } - - classes.Add(className, new ClassSequence(instructor, location, weekdays.ToArray())); + classes.Add(new ClassSequence(instructor, location, weekdays.ToArray())); } sections.Add(new Section(courseName, name, openSeats, waitlist, classes.ToArray())); diff --git a/CourseScheduler.Core/DataStrucures/Section.cs b/CourseScheduler.Core/DataStrucures/Section.cs index fd2e970..911dd5d 100644 --- a/CourseScheduler.Core/DataStrucures/Section.cs +++ b/CourseScheduler.Core/DataStrucures/Section.cs @@ -9,7 +9,7 @@ namespace CourseScheduler.Core.DataStrucures { public class Section : IVisible { - public Section(string course, string name, int openSeats, int waitList, params KeyValuePair[] classTypesAndSchedules) + public Section(string course, string name, int openSeats, int waitList, params ClassSequence[] classTypesAndSchedules) { Course = course; Name = name; @@ -18,18 +18,17 @@ public Section(string course, string name, int openSeats, int waitList, params K foreach (var myClass in classTypesAndSchedules) { - ClassSequences.Add(myClass.Key, myClass.Value); - if (!Instructors.Contains(myClass.Value.Instructor)) + ClassSequences.Add(myClass); + if (!Instructors.Contains(myClass.Instructor)) { - Instructors.Add(myClass.Value.Instructor); + Instructors.Add(myClass.Instructor); } } } // like {LEC, class times ...} - public readonly Dictionary ClassSequences = new Dictionary(); - [Visible(nameof(ClassSequences), name:nameof(ClassSequences))] - public List SimplifiedClassSequence => ClassSequences.Select(p => p.Value).ToList(); + [Visible(nameof(ClassSequences), name: nameof(ClassSequences))] + public List ClassSequences { get; } = new List(); public string Course { get; } public string Name { get; set; } [Visible(nameof(OpenSeats), name: nameof(OpenSeats))] @@ -46,9 +45,9 @@ public Section(string course, string name, int openSeats, int waitList, params K public bool IsOverlap(Section another) { - foreach (var myClass in ClassSequences.Values) + foreach (var myClass in ClassSequences) { - foreach (var anotherClass in another.ClassSequences.Values) + foreach (var anotherClass in another.ClassSequences) { if (myClass.IsOverlap(anotherClass)) { @@ -77,7 +76,7 @@ public bool IsAvailable(bool isOpenSectionOnly, bool doesShowFC, IEnumerable