From 03ddeba846ab90b1ce8426e616c28b4ccb05d75d Mon Sep 17 00:00:00 2001 From: Robin Weichselbraun Date: Sat, 12 Oct 2024 17:36:23 +0200 Subject: [PATCH] Performance update with HTMLAgilityPack Added Branches Added LinksToScrape Added ScrapedLinks --- .../Controllers/LectureController.cs | 3 + UWLecturePlan/Models/LecturesViewModel.cs | 8 +- UWLecturePlan/Views/Lecture/Index.cshtml | 63 ++- UWLib/Lecture.cs | 2 +- UWLib/LectureContext.cs | 8 +- UWLib/LinkToScrape.cs | 16 + .../20241012131142_ScrapedLinks.Designer.cs | 108 +++++ .../Migrations/20241012131142_ScrapedLinks.cs | 34 ++ .../20241012131329_Branch.Designer.cs | 112 +++++ UWLib/Migrations/20241012131329_Branch.cs | 29 ++ .../20241012140426_LinksToScrape.Designer.cs | 125 ++++++ .../20241012140426_LinksToScrape.cs | 33 ++ .../Migrations/LectureContextModelSnapshot.cs | 30 ++ UWLib/ScrapedLink.cs | 17 + UWScraper/Program.cs | 397 ++++++++++++------ UWScraper/Properties/launchSettings.json | 8 + UWScraper/UWScraper.csproj | 4 + UWScraper/lecture.db | Bin 0 -> 40960 bytes 18 files changed, 843 insertions(+), 154 deletions(-) create mode 100644 UWLib/LinkToScrape.cs create mode 100644 UWLib/Migrations/20241012131142_ScrapedLinks.Designer.cs create mode 100644 UWLib/Migrations/20241012131142_ScrapedLinks.cs create mode 100644 UWLib/Migrations/20241012131329_Branch.Designer.cs create mode 100644 UWLib/Migrations/20241012131329_Branch.cs create mode 100644 UWLib/Migrations/20241012140426_LinksToScrape.Designer.cs create mode 100644 UWLib/Migrations/20241012140426_LinksToScrape.cs create mode 100644 UWLib/ScrapedLink.cs create mode 100644 UWScraper/Properties/launchSettings.json create mode 100644 UWScraper/lecture.db diff --git a/UWLecturePlan/Controllers/LectureController.cs b/UWLecturePlan/Controllers/LectureController.cs index 9389891..ec2533a 100644 --- a/UWLecturePlan/Controllers/LectureController.cs +++ b/UWLecturePlan/Controllers/LectureController.cs @@ -25,6 +25,7 @@ namespace UWLecturePlan.Controllers model.LectureEvents = db.LectureEvents.Include(x=>x.Lecture) .Where(x => x.From >= from) .Where(x => x.Lecture.Semester == model.CurrentSemester) + .Where(x => x.Lecture.Branch == model.BranchFilter || model.BranchFilter == null) .ToList(); if (model.LocationFilter != null) @@ -33,6 +34,8 @@ namespace UWLecturePlan.Controllers .Where(x => x.Location.Contains(model.LocationFilter)).ToList(); } + model.Branches = db.LectureEvents.Select(x => x.Lecture.Branch).Distinct().OrderBy(x=>x).ToList(); + return View(model); } diff --git a/UWLecturePlan/Models/LecturesViewModel.cs b/UWLecturePlan/Models/LecturesViewModel.cs index 145147b..cd7850a 100644 --- a/UWLecturePlan/Models/LecturesViewModel.cs +++ b/UWLecturePlan/Models/LecturesViewModel.cs @@ -7,8 +7,12 @@ namespace UWLecturePlan.Models public string CurrentSemester { get; set; } - public string LocationFilter { get; set; } + public string? LocationFilter { get; set; } - public List LectureEvents { get; set; } + public string? BranchFilter { get; set; } + + public List LectureEvents { get; set; } + + public List Branches { get; set; } } } diff --git a/UWLecturePlan/Views/Lecture/Index.cshtml b/UWLecturePlan/Views/Lecture/Index.cshtml index b6eb6fb..d910399 100644 --- a/UWLecturePlan/Views/Lecture/Index.cshtml +++ b/UWLecturePlan/Views/Lecture/Index.cshtml @@ -1,4 +1,21 @@ -@model LecturesViewModel +@using System.Text.RegularExpressions +@model LecturesViewModel +@{ + string GetBranchName(string branch) + { + Regex regex = new Regex(@".* - (.*)"); + + var match = regex.Match(branch); + if (match.Success) + { + return match.Groups[1].Value; + } + else + { + return branch; + } + } +}