68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
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 = ',';
|
|
string header = $"SchuelerID{separator}Sem1{separator}Sem2{separator}Sem3{separator}Sem4";
|
|
string output = header + "\n";
|
|
foreach (var student in Settings.Instance.Students)
|
|
{
|
|
output += $"{student.ID}{separator}{student.Result[0]}{separator}{student.Result[1]}{separator}{student.Result[2]}{separator}{student.Result[3]}\n";
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|