From 215b58f568e8d39cfae716af251e0c31c2d6fcac Mon Sep 17 00:00:00 2001 From: user Date: Fri, 11 Aug 2023 10:22:23 +0200 Subject: [PATCH 1/4] Update EnrollUtil.cs and PathUtils.cs --- PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs | 6 +++--- PoliNetwork.Graduatorie.Common/Utils/Path/PathUtils.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs b/PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs index 3085663e..e2a21868 100644 --- a/PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs +++ b/PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs @@ -16,7 +16,7 @@ public static EnrollType GetEnrollType(string? rowCanEnrollInto, bool rowCanEnro if (string.IsNullOrEmpty(rowCanEnrollInto)) return new EnrollType { CanEnroll = true, Course = null, Type = null }; - string[] tester = {"assegnato", "prenotato"}; + string[] tester = { "assegnato", "prenotato" }; const string sep = " - "; if (!rowCanEnrollInto.Contains(sep) || !tester.Any(t => rowCanEnrollInto.ToLower().Contains(t))) return new EnrollType { CanEnroll = true, Course = rowCanEnrollInto, Type = null }; @@ -24,7 +24,7 @@ public static EnrollType GetEnrollType(string? rowCanEnrollInto, bool rowCanEnro var s = rowCanEnrollInto.Split(sep).ToList(); var type = s.FirstOrDefault(x => tester.Any(t => t == x.ToLower())); s.Remove(type); - var course = String.Join(sep, s); + var course = string.Join(sep, s); return new EnrollType { CanEnroll = true, Course = course, Type = type }; } -} +} \ No newline at end of file diff --git a/PoliNetwork.Graduatorie.Common/Utils/Path/PathUtils.cs b/PoliNetwork.Graduatorie.Common/Utils/Path/PathUtils.cs index f052fbaf..16ed2eba 100644 --- a/PoliNetwork.Graduatorie.Common/Utils/Path/PathUtils.cs +++ b/PoliNetwork.Graduatorie.Common/Utils/Path/PathUtils.cs @@ -37,4 +37,4 @@ public static string CreateAndReturnDataFolder(string folderName) Directory.CreateDirectory(dataFolderPath); return dataFolderPath; } -} +} \ No newline at end of file From 6ea119549ea7f0334366e3a7fd04401b4c161112 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 11 Aug 2023 10:24:35 +0200 Subject: [PATCH 2/4] Update RankingOrder.cs --- .../Objects/RankingNS/RankingOrder.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PoliNetwork.Graduatorie.Parser/Objects/RankingNS/RankingOrder.cs b/PoliNetwork.Graduatorie.Parser/Objects/RankingNS/RankingOrder.cs index 2a7e9b13..5a24d668 100644 --- a/PoliNetwork.Graduatorie.Parser/Objects/RankingNS/RankingOrder.cs +++ b/PoliNetwork.Graduatorie.Parser/Objects/RankingNS/RankingOrder.cs @@ -82,6 +82,10 @@ public int GetHashWithoutLastUpdate() public void Merge(RankingOrder? rankingRankingOrder) { - throw new NotImplementedException(); + Anticipata ??= rankingRankingOrder?.Anticipata; + Phase ??= rankingRankingOrder?.Phase; + Primary ??= rankingRankingOrder?.Primary; + Secondary ??= rankingRankingOrder?.Secondary; + ExtraEu ??= rankingRankingOrder?.ExtraEu; } } \ No newline at end of file From 3614b5a1cb4a003db945a55736780fd0f2bd2828 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 11 Aug 2023 10:27:07 +0200 Subject: [PATCH 3/4] Update RankingUrl.cs, EnrollUtil.cs, HashMatricola.cs, and 3 more files --- .../Objects/RankingNS/RankingUrl.cs | 2 +- .../Utils/EnrollUtil.cs | 9 ++++++-- .../Utils/HashNS/HashMatricola.cs | 5 +---- .../Specific/BySchoolYearCourseJson.cs | 22 ++++++++++--------- .../Utils/Output/HashMatricoleWrite.cs | 10 ++++----- .../Utils/Transformer/ParserNS/Parser.cs | 14 +++++------- 6 files changed, 30 insertions(+), 32 deletions(-) diff --git a/PoliNetwork.Graduatorie.Common/Objects/RankingNS/RankingUrl.cs b/PoliNetwork.Graduatorie.Common/Objects/RankingNS/RankingUrl.cs index 5fa78164..ebafa918 100644 --- a/PoliNetwork.Graduatorie.Common/Objects/RankingNS/RankingUrl.cs +++ b/PoliNetwork.Graduatorie.Common/Objects/RankingNS/RankingUrl.cs @@ -129,7 +129,7 @@ public bool IsSameRanking(RankingUrl urlB) return AreSameRanking(this, urlB); } - public bool AreSameRanking(RankingUrl urlA, RankingUrl urlB) + public static bool AreSameRanking(RankingUrl urlA, RankingUrl urlB) { var a = urlA.Url; var b = urlB.Url; diff --git a/PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs b/PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs index e2a21868..a5446ec6 100644 --- a/PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs +++ b/PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs @@ -23,8 +23,13 @@ public static EnrollType GetEnrollType(string? rowCanEnrollInto, bool rowCanEnro var s = rowCanEnrollInto.Split(sep).ToList(); var type = s.FirstOrDefault(x => tester.Any(t => t == x.ToLower())); - s.Remove(type); + if (type != null) + { + s.Remove(type); + } + var course = string.Join(sep, s); - return new EnrollType { CanEnroll = true, Course = course, Type = type }; + return new EnrollType { CanEnroll = true, Course = course, Type = type }; + } } \ No newline at end of file diff --git a/PoliNetwork.Graduatorie.Common/Utils/HashNS/HashMatricola.cs b/PoliNetwork.Graduatorie.Common/Utils/HashNS/HashMatricola.cs index 555a0c64..f685c431 100644 --- a/PoliNetwork.Graduatorie.Common/Utils/HashNS/HashMatricola.cs +++ b/PoliNetwork.Graduatorie.Common/Utils/HashNS/HashMatricola.cs @@ -21,10 +21,7 @@ public static partial class HashMatricola if (input.Contains(' ')) input = input.Split(" ").First(x => !string.IsNullOrEmpty(x)); var s = input.Trim().ToUpper(); - if (string.IsNullOrEmpty(s)) - return null; - - return NotAlphaNumericRegex().Replace(s, ""); + return string.IsNullOrEmpty(s) ? null : NotAlphaNumericRegex().Replace(s, ""); } public static string? HashMatricolaMethod(string? input) diff --git a/PoliNetwork.Graduatorie.Parser/Objects/Json/Indexes/Specific/BySchoolYearCourseJson.cs b/PoliNetwork.Graduatorie.Parser/Objects/Json/Indexes/Specific/BySchoolYearCourseJson.cs index c449a007..947da65f 100644 --- a/PoliNetwork.Graduatorie.Parser/Objects/Json/Indexes/Specific/BySchoolYearCourseJson.cs +++ b/PoliNetwork.Graduatorie.Parser/Objects/Json/Indexes/Specific/BySchoolYearCourseJson.cs @@ -116,16 +116,17 @@ private static void AddCourseToDict( var locationDict = courseDict[fixedLocation]; var singleCourseJson = CreateCourseJson(ranking, course); - bool IsThisCourse(SingleCourseJson x) - { - return x.Link == singleCourseJson.Link && x.Location == singleCourseJson.Location; - } - if (locationDict.Any(IsThisCourse)) continue; locationDict.Add(singleCourseJson); locationDict.Sort(Comparison); + continue; + + bool IsThisCourse(SingleCourseJson x) + { + return x.Link == singleCourseJson.Link && x.Location == singleCourseJson.Location; + } } } @@ -152,14 +153,14 @@ private static bool IsSimilar(IEnumerable yearGroup, SingleCourseJson s { var enumerable = yearGroup.Where(v1 => v1.ByCourse != null); + return enumerable.Any(Predicate); + bool Predicate(Ranking v1) { return singleCourseJson.School == v1.School && singleCourseJson.Year == v1.Year && v1.RankingOrder?.Phase == singleCourseJson.Name; } - - return enumerable.Any(Predicate); } public static RankingsSet? Parse(string dataFolder) @@ -207,13 +208,14 @@ ICollection rankings var actions = new List(); foreach (var filename in year.Value) { + var collection = filename.Value.Select(Selector); + actions.AddRange(collection); + continue; + Action Selector(KeyValuePair> variable) { return () => { RankingAdd(school, year, outFolder, variable, rankings); }; } - - var collection = filename.Value.Select(Selector); - actions.AddRange(collection); } ParallelRun.Run(actions.ToArray()); diff --git a/PoliNetwork.Graduatorie.Parser/Utils/Output/HashMatricoleWrite.cs b/PoliNetwork.Graduatorie.Parser/Utils/Output/HashMatricoleWrite.cs index e2154f49..38e00e90 100644 --- a/PoliNetwork.Graduatorie.Parser/Utils/Output/HashMatricoleWrite.cs +++ b/PoliNetwork.Graduatorie.Parser/Utils/Output/HashMatricoleWrite.cs @@ -28,9 +28,8 @@ private static SortedDictionary GetDictToWrite(Ranki { var byMeritRows = ranking.ByMerit?.Rows; if (byMeritRows != null) - foreach (var student in byMeritRows) - if (!string.IsNullOrEmpty(student.Id)) - AddToDict(dictionary, ranking, student, null); + foreach (var student in byMeritRows.Where(student => !string.IsNullOrEmpty(student.Id))) + AddToDict(dictionary, ranking, student, null); var rankingByCourse = ranking.ByCourse; if (rankingByCourse == null) continue; @@ -38,9 +37,8 @@ private static SortedDictionary GetDictToWrite(Ranki { var row = courseTable.Rows; if (row == null) continue; - foreach (var studentResult in row) - if (!string.IsNullOrEmpty(studentResult.Id)) - AddToDict(dictionary, ranking, studentResult, courseTable); + foreach (var studentResult in row.Where(studentResult => !string.IsNullOrEmpty(studentResult.Id))) + AddToDict(dictionary, ranking, studentResult, courseTable); } } diff --git a/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Parser.cs b/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Parser.cs index ad41a5fe..3bd8d6dd 100644 --- a/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Parser.cs +++ b/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Parser.cs @@ -131,9 +131,7 @@ private RankingsSet ParseNewRankings(List htmls) .Select(url => { var found = meritTablePages.Find(h => h.Url.Url == url.Url); - if (found != null) - return found; - return HtmlPage.FromUrl(url, _htmlFolder); + return found ?? HtmlPage.FromUrl(url, _htmlFolder); }) .Where(h => h != null) .Select(h => h!) @@ -144,9 +142,7 @@ private RankingsSet ParseNewRankings(List htmls) .Select(url => { var found = courseTablePages.Find(h => h.Url.Url == url.Url); - if (found != null) - return found; - return HtmlPage.FromUrl(url, _htmlFolder); + return found ?? HtmlPage.FromUrl(url, _htmlFolder); }) .Where(h => h != null) .Select(h => h!) @@ -186,7 +182,7 @@ private RankingsSet ParseNewRankings(List htmls) return set; } - private Ranking? InitRanking(RankingUrl indexUrl, HtmlNode doc) + private static Ranking? InitRanking(RankingUrl indexUrl, HtmlNode doc) { var ranking = new Ranking(); // get ranking info @@ -268,7 +264,7 @@ private static IEnumerable GetTableLinks(HtmlPage html) return tablesLinks; } - private Table ParseMeritTable(IEnumerable pages) + private static Table ParseMeritTable(IEnumerable pages) { var table = JoinTables(pages); var meritTable = Table.Create( @@ -282,7 +278,7 @@ private Table ParseMeritTable(IEnumerable pages) return meritTable; } - private IEnumerable> ParseCoursesTables(IEnumerable pages) + private static IEnumerable> ParseCoursesTables(IEnumerable pages) { var tables = GetTables(pages); var coursesTables = tables.Select( From ae3bbca59c68b5a776aeb5946b18e5c4a0f89187 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 11 Aug 2023 10:28:50 +0200 Subject: [PATCH 4/4] Update BySchoolYearCourseJson.cs, BySchoolYearJson.cs, and Parser.cs --- .../Objects/Json/Indexes/Specific/BySchoolYearCourseJson.cs | 4 ++-- .../Objects/Json/Indexes/Specific/BySchoolYearJson.cs | 2 +- .../Utils/Transformer/ParserNS/Parser.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PoliNetwork.Graduatorie.Parser/Objects/Json/Indexes/Specific/BySchoolYearCourseJson.cs b/PoliNetwork.Graduatorie.Parser/Objects/Json/Indexes/Specific/BySchoolYearCourseJson.cs index 947da65f..380a36af 100644 --- a/PoliNetwork.Graduatorie.Parser/Objects/Json/Indexes/Specific/BySchoolYearCourseJson.cs +++ b/PoliNetwork.Graduatorie.Parser/Objects/Json/Indexes/Specific/BySchoolYearCourseJson.cs @@ -62,7 +62,7 @@ private static SortedDictionary< } private static void GetYearsDictSingle(IGrouping yearGroup, - SortedDictionary>>> d) + IDictionary>>> d) { if (yearGroup.Key != null) d.Add(yearGroup.Key.Value, GetCoursesDict(yearGroup)); } @@ -87,7 +87,7 @@ IEnumerable yearGroup } private static void AddCourseToDict( - SortedDictionary>> d, + IDictionary>> d, Ranking ranking, IGrouping courseGroup ) diff --git a/PoliNetwork.Graduatorie.Parser/Objects/Json/Indexes/Specific/BySchoolYearJson.cs b/PoliNetwork.Graduatorie.Parser/Objects/Json/Indexes/Specific/BySchoolYearJson.cs index 265496a0..a0749948 100644 --- a/PoliNetwork.Graduatorie.Parser/Objects/Json/Indexes/Specific/BySchoolYearJson.cs +++ b/PoliNetwork.Graduatorie.Parser/Objects/Json/Indexes/Specific/BySchoolYearJson.cs @@ -50,7 +50,7 @@ public class BySchoolYearJson : IndexJsonBase private static void AddSchool( IGrouping yearGroup, - SortedDictionary> schoolDict + IDictionary> schoolDict ) { var yearGroupKey = yearGroup.Key; diff --git a/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Parser.cs b/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Parser.cs index 3bd8d6dd..b0696910 100644 --- a/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Parser.cs +++ b/PoliNetwork.Graduatorie.Parser/Utils/Transformer/ParserNS/Parser.cs @@ -94,7 +94,7 @@ private RankingsSet ParseSavedRankings(ICollection htmls) return savedSet; } - private RankingsSet ParseNewRankings(List htmls) + private RankingsSet ParseNewRankings(IReadOnlyCollection htmls) { // pseudo // new ranking set