[feat:] im- and export (pdf/json)
This commit is contained in:
+61
-8
@@ -15,6 +15,66 @@ public class CourseCrafter
|
||||
public static List<(int Semester, CourseInstance Instance)> GeneratedCourses
|
||||
= new();
|
||||
|
||||
private static Sport? ResolveSportFromCourseName(string courseName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(courseName) ||
|
||||
string.Equals(courseName, "null", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return Settings.Instance.Sports.FirstOrDefault(sport =>
|
||||
string.Equals(sport.Name, courseName, StringComparison.OrdinalIgnoreCase) ||
|
||||
sport.AlternativeNames.Any(alt => string.Equals(alt, courseName, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
|
||||
public static void RebuildGeneratedCoursesFromResults(IEnumerable<Student> importedResults)
|
||||
{
|
||||
var importedById = importedResults
|
||||
.Where(student => !string.IsNullOrWhiteSpace(student.ID))
|
||||
.GroupBy(student => student.ID, StringComparer.OrdinalIgnoreCase)
|
||||
.ToDictionary(group => group.Key, group => group.First(), StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var generatedCourses = new Dictionary<(int Semester, string SportName), CourseInstance>();
|
||||
|
||||
foreach (var student in Settings.Instance.Students)
|
||||
{
|
||||
if (!importedById.TryGetValue(student.ID, out var importedStudent))
|
||||
continue;
|
||||
|
||||
for (int semesterIndex = 0; semesterIndex < 4; semesterIndex++)
|
||||
{
|
||||
if (importedStudent.Result.Length <= semesterIndex)
|
||||
continue;
|
||||
|
||||
var resultName = importedStudent.Result[semesterIndex];
|
||||
var sport = ResolveSportFromCourseName(resultName);
|
||||
if (sport == null)
|
||||
continue;
|
||||
|
||||
var key = (semesterIndex + 1, sport.Name);
|
||||
if (!generatedCourses.TryGetValue(key, out var course))
|
||||
{
|
||||
course = new CourseInstance
|
||||
{
|
||||
Sport = sport,
|
||||
Students = new List<string>()
|
||||
};
|
||||
generatedCourses[key] = course;
|
||||
}
|
||||
|
||||
if (!course.Students.Contains(student.ID))
|
||||
course.Students.Add(student.ID);
|
||||
}
|
||||
}
|
||||
|
||||
GeneratedCourses = generatedCourses
|
||||
.Select(entry => (Semester: entry.Key.Semester, Instance: entry.Value))
|
||||
.OrderBy(course => course.Semester)
|
||||
.ThenBy(course => course.Instance.Sport.Name)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static void Craft()
|
||||
{
|
||||
GeneratedCourses = new();
|
||||
@@ -651,14 +711,7 @@ public class CourseCrafter
|
||||
|
||||
Sport? ResolveSportFromSelection(string selectedCourseName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(selectedCourseName) ||
|
||||
string.Equals(selectedCourseName, "null", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return Settings.Instance.Sports
|
||||
.FirstOrDefault(sport => sport.AlternativeNames.Contains(selectedCourseName));
|
||||
return ResolveSportFromCourseName(selectedCourseName);
|
||||
}
|
||||
|
||||
int getSemesterForSport(Sport sp, List<string> interestedStudents)
|
||||
|
||||
Reference in New Issue
Block a user