Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions PoliNetwork.Graduatorie.Common/Objects/EnrollType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#region

using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

#endregion

namespace PoliNetwork.Graduatorie.Common.Objects;

[Serializable]
[JsonObject(MemberSerialization.Fields, NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class EnrollType
{
public bool? CanEnroll;
public string? Course;
public string? Type;

public int GetHashWithoutLastUpdate()
{
var i = "EnrollTypeNotNull".GetHashCode();
i ^= Course?.GetHashCode() ?? "Course".GetHashCode();
i ^= Type?.GetHashCode() ?? "Type".GetHashCode();
i ^= CanEnroll?.GetHashCode() ?? "CanEnroll".GetHashCode();

return i;
}
}
30 changes: 30 additions & 0 deletions PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#region

using PoliNetwork.Graduatorie.Common.Objects;

#endregion

namespace PoliNetwork.Graduatorie.Common.Utils;

public class EnrollUtil
{
public static EnrollType GetEnrollType(string? rowCanEnrollInto, bool rowCanEnroll)
{
if (rowCanEnroll == false)
return new EnrollType { CanEnroll = false, Course = null, Type = null };

if (string.IsNullOrEmpty(rowCanEnrollInto))
return new EnrollType { CanEnroll = true, Course = null, Type = null };

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 };

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);
return new EnrollType { CanEnroll = true, Course = course, Type = type };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static RankingSummary From(Ranking ranking)
var courseTableStatsList = ranking.ByCourse?.Select(x => x.GetStats())
.OrderBy(x => x.Title).ThenBy(x => x.Location).ToList();

var howManyCanEnroll = byMeritRows?.Count(x => x.CanEnroll ?? false);
var howManyCanEnroll = byMeritRows?.Count(x => x.EnrollType?.CanEnroll ?? false);


var groupBy = courseTableStatsList?.GroupBy(x =>
Expand Down
8 changes: 4 additions & 4 deletions PoliNetwork.Graduatorie.Parser/Objects/StudentResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using PoliNetwork.Graduatorie.Common.Objects;

#endregion

Expand All @@ -12,9 +13,8 @@ namespace PoliNetwork.Graduatorie.Parser.Objects;
public class StudentResult
{
public DateOnly? BirthDate;
public bool? CanEnroll;
public string? CanEnrollInto;
public int? EnglishCorrectAnswers;
public EnrollType? EnrollType;
public string? Id;
public SortedDictionary<string, bool>? Ofa; // maybe change it
public int? PositionAbsolute;
Expand All @@ -26,13 +26,13 @@ public int GetHashWithoutLastUpdate()
{
var i = "StudentResult".GetHashCode();
i ^= BirthDate?.GetHashCode() ?? "BirthDate".GetHashCode();
i ^= CanEnroll?.GetHashCode() ?? "CanEnroll".GetHashCode();
i ^= CanEnrollInto?.GetHashCode() ?? "CanEnrollInto".GetHashCode();
i ^= EnrollType?.GetHashWithoutLastUpdate() ?? "EnrollType".GetHashCode();
i ^= EnglishCorrectAnswers?.GetHashCode() ?? "EnglishCorrectAnswers".GetHashCode();
i ^= Id?.GetHashCode() ?? "Id".GetHashCode();
i ^= PositionAbsolute?.GetHashCode() ?? "PositionAbsolute".GetHashCode();
i ^= PositionCourse?.GetHashCode() ?? "PositionCourse".GetHashCode();
i ^= Result?.GetHashCode() ?? "Result".GetHashCode();
i ^= EnrollType?.GetHashCode() ?? "EnrollType".GetHashCode();
if (Ofa == null)
i ^= "Ofa".GetHashCode();
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static CourseTableStats From(CourseTable courseTable)
if (howManyStudentsCount == 0 || courseTableRows is null)
return stats;

var studentsWhoCanEnroll = courseTableRows.Where(x => x.CanEnroll ?? false).ToList();
var studentsWhoCanEnroll = courseTableRows.Where(x => x.EnrollType?.CanEnroll ?? false).ToList();
var studentsWhoCanEnrollCount = studentsWhoCanEnroll.Count;
var minValueToEnroll =
studentsWhoCanEnrollCount > 0 ? studentsWhoCanEnroll.Min(x => x.Result) : null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#region

using PoliNetwork.Graduatorie.Common.Utils;
using PoliNetwork.Graduatorie.Parser.Objects;
using PoliNetwork.Graduatorie.Parser.Objects.Tables.Course;
using PoliNetwork.Graduatorie.Parser.Objects.Tables.Merit;
Expand All @@ -13,21 +14,22 @@ public static class Converter
public static StudentResult FromMeritTableToStudentResult(MeritTableRow row)
{
var rowCanEnroll = row.CanEnroll ?? false;
var rowCanEnrollInto = rowCanEnroll ? row.CanEnrollInto : null;
return new StudentResult
{
Id = row.Id,
Ofa = row.Ofa,
Result = row.Result,
BirthDate = null,
CanEnroll = rowCanEnroll,
CanEnrollInto = rowCanEnroll ? row.CanEnrollInto : null,
PositionAbsolute = row.Position,
PositionCourse = null,
SectionsResults = null,
EnglishCorrectAnswers = null
EnglishCorrectAnswers = null,
EnrollType = EnrollUtil.GetEnrollType(rowCanEnrollInto, rowCanEnroll)
};
}


public static StudentResult FromCourseTableRowToStudentResult(CourseTableRow row, Table<CourseTableRow> course)
{
var rowCanEnroll = row.CanEnroll ?? false;
Expand All @@ -37,8 +39,7 @@ public static StudentResult FromCourseTableRowToStudentResult(CourseTableRow row
Ofa = row.Ofa,
Result = row.Result,
BirthDate = row.BirthDate,
CanEnroll = rowCanEnroll,
CanEnrollInto = rowCanEnroll ? course.CourseTitle : null,
EnrollType = EnrollUtil.GetEnrollType(course.CourseTitle, rowCanEnroll),
PositionAbsolute = null,
PositionCourse = row.Position,
SectionsResults = row.SectionsResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using PoliNetwork.Graduatorie.Common.Extensions;
using PoliNetwork.Graduatorie.Common.Objects;
using PoliNetwork.Graduatorie.Common.Objects.RankingNS;
using PoliNetwork.Graduatorie.Common.Utils;
using PoliNetwork.Graduatorie.Common.Utils.HashNS;
using PoliNetwork.Graduatorie.Parser.Objects;
using PoliNetwork.Graduatorie.Parser.Objects.Json.Indexes.Specific;
Expand Down Expand Up @@ -585,8 +586,7 @@ Table<CourseTableRow> course
Ofa = row.Ofa,
Result = row.Result,
BirthDate = row.BirthDate,
CanEnroll = canEnroll,
CanEnrollInto = canEnroll ? course.CourseTitle : null,
EnrollType = EnrollUtil.GetEnrollType(course.CourseTitle, canEnroll),
PositionCourse = row.Position,
SectionsResults = row.SectionsResults,
EnglishCorrectAnswers = row.EnglishCorrectAnswers
Expand All @@ -600,7 +600,7 @@ Table<CourseTableRow> course
return student;

student.PositionAbsolute = meritRow.Position;
student.CanEnrollInto = canEnroll ? meritRow.CanEnrollInto : null;
student.EnrollType = EnrollUtil.GetEnrollType(meritRow.CanEnrollInto, canEnroll);
return student;
}

Expand All @@ -623,8 +623,7 @@ IEnumerable<CourseTable> courses
var canEnroll = row.CanEnroll ?? false;
var student = new StudentResult
{
CanEnroll = canEnroll,
CanEnrollInto = canEnroll ? row.CanEnrollInto : null,
EnrollType = EnrollUtil.GetEnrollType(row.CanEnrollInto, canEnroll),
Id = row.Id,
PositionAbsolute = row.Position,
Result = row.Result,
Expand All @@ -651,7 +650,7 @@ IEnumerable<CourseTable> courses
return student;

var finalRow = canEnroll
? studentCoursesRows.Find(c => c?.CanEnroll ?? false)
? studentCoursesRows.Find(c => c?.EnrollType?.CanEnroll ?? false)
: studentCoursesRows.OrderBy(c => c?.PositionCourse).First();

if (finalRow == null)
Expand Down