[feat:] im- and export (pdf/json)
This commit is contained in:
+49
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user