[feat:] im- and export (pdf/json)

This commit is contained in:
2026-06-04 18:59:01 +02:00
parent 5ef41b21b0
commit 66596b530b
5 changed files with 242 additions and 51 deletions
+49 -1
View File
@@ -1,9 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.Json;
namespace spplus;
public static class ExportUtility
{
private sealed class ConfigurationExport
{
public List<Sport> Sports { get; set; } = [];
public int[] NumCoursesPerSemester { get; set; } = [];
}
public static void ExportToCSV(string filepath)
{
char separator = ',';
@@ -16,4 +26,42 @@ public static class ExportUtility
File.WriteAllText(filepath, output);
}
}
private sealed class ResultExportEntry
{
public int Semester { get; set; }
public string SportName { get; set; } = string.Empty;
public List<string> Students { get; set; } = new();
}
public static void ExportResultsToJson(string filepath)
{
var list = CourseCrafter.GeneratedCourses
.Select(g => new ResultExportEntry
{
Semester = g.Semester,
SportName = g.Instance.Sport.Name,
Students = g.Instance.Students.ToList()
})
.ToList();
var json = JsonSerializer.Serialize(list, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(filepath, json);
}
public static void ExportConfigurationToJson(string filepath)
{
var export = new ConfigurationExport
{
Sports = Settings.Instance.Sports,
NumCoursesPerSemester = Settings.Instance.NumCoursesPerSemester
};
var json = JsonSerializer.Serialize(export, new JsonSerializerOptions
{
WriteIndented = true
});
File.WriteAllText(filepath, json);
}
}