Compare commits
31 Commits
8bfa22451e
...
spplus1.2.
| Author | SHA1 | Date | |
|---|---|---|---|
| a1bf573a07 | |||
| 525f3fb4ae | |||
| 9f298d8ce8 | |||
| 11d9c641a6 | |||
| c2f7adc1d0 | |||
| c19f96ea37 | |||
| 9bbde62d70 | |||
| a83f97828c | |||
| 44654dd784 | |||
| 410055c9f2 | |||
| ce75d8aa0b | |||
| be436f1b1c | |||
| 14c11b81b6 | |||
| dd38b91d68 | |||
| 987f27fcbc | |||
| 42ecde799c | |||
| ce70d86fd3 | |||
| ea280ea05d | |||
| c2e230ca48 | |||
| 30317dd1bb | |||
| 6753acc04f | |||
| 4468651373 | |||
| b6de508ea0 | |||
| d70770e2f0 | |||
| 2c2f2d2d94 | |||
| c5a234cea7 | |||
| c6f9994c25 | |||
| 6f1ffd40b6 | |||
| 8ab928be7c | |||
| 30c8b2ef92 | |||
| 24416dc345 |
@@ -4,7 +4,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="spplus.MainWindow" WindowState="Maximized"
|
||||
Title="SP+">
|
||||
Title="spplus">
|
||||
<Border>
|
||||
<Grid RowDefinitions="30,*">
|
||||
<Menu Background="#50888888">
|
||||
@@ -20,7 +20,7 @@
|
||||
<MenuItem Header="Über" x:Name="MnuAbout" Click="MnuAbout_OnClick" />
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
<TabControl x:Name="TclMainView" Grid.Row="1">
|
||||
<TabControl x:Name="TclMainView" Grid.Row="1" TabStripPlacement="Left">
|
||||
<TabItem>
|
||||
<TabItem.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
@@ -88,6 +88,11 @@
|
||||
<Label Content="Anzahl gewählte Kurse"></Label>
|
||||
<Label Grid.Column="1" x:Name="LblSelectedAmount"></Label>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Wahlzahlen"></Label>
|
||||
<Label Grid.Column="1" x:Name="LblNumVoted"></Label>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
@@ -165,46 +170,34 @@
|
||||
<NumericUpDown Grid.Column="1" x:Name="NudAmountCoursesSem4" ValueChanged="NudAmountCoursesSem4_OnValueChanged"></NumericUpDown>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Alternativkurse"></Label>
|
||||
<StackPanel Grid.Column="1" Orientation="Vertical">
|
||||
<Grid ColumnDefinitions="*,50">
|
||||
<ComboBox Height="35" HorizontalAlignment="Stretch" x:Name="CbAlternativCourse"></ComboBox>
|
||||
<Button Grid.Column="1" Margin="0,10,0,0" x:Name="BtnAlternativeCourseAdd" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnAlternativeCourseAdd_OnClick" HorizontalContentAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<LucideIcon Kind="Plus" Width="24" Height="24" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</Grid>
|
||||
<ListBox x:Name="LbAlternativeCourses">
|
||||
|
||||
</ListBox>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Alternativbezeichnungen"></Label>
|
||||
<StackPanel Grid.Column="1" Orientation="Vertical">
|
||||
<Grid ColumnDefinitions="*,50,50">
|
||||
<TextBox Grid.Column="0" Height="35" HorizontalAlignment="Stretch" x:Name="TbSportAlternativeName"></TextBox>
|
||||
<Button Grid.Column="1" Margin="0,10,0,0" x:Name="BtnAlternativeNameAdd" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnAlternativeNameAdd_OnClick" HorizontalContentAlignment="Center">
|
||||
<Button Grid.Column="1" Margin="5,0,0,0" x:Name="BtnAlternativeNameAdd" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnAlternativeNameAdd_OnClick" HorizontalContentAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<LucideIcon Kind="Plus" Width="24" Height="24" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Grid.Column="2" Margin="0,10,0,0" x:Name="BtnAlternativeNameRemove" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnAlternativeNameRemove_OnClick" HorizontalContentAlignment="Center">
|
||||
<Button Grid.Column="2" Margin="5,0,0,0" x:Name="BtnAlternativeNameRemove" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnAlternativeNameRemove_OnClick" HorizontalContentAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<LucideIcon Kind="Minus" Width="24" Height="24" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</Grid>
|
||||
<ListBox x:Name="LbAlternativeNames">
|
||||
<ListBox Margin="0,5,0,0" x:Name="LbAlternativeNames">
|
||||
|
||||
</ListBox>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
<Line />
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Maximale Sportkursanzahl pro Semester"></Label>
|
||||
<NumericUpDown Grid.Column="1" x:Name="NudSportMaxPerSemester" ValueChanged="NudSportMaxPerSemester_OnValueChanged"></NumericUpDown>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
@@ -216,11 +209,33 @@
|
||||
<Label FontSize="20" Content="Ergebnisse" VerticalContentAlignment="Center" />
|
||||
</StackPanel>
|
||||
</TabItem.Header>
|
||||
<Grid ColumnDefinitions="*,*">
|
||||
<ListBox x:Name="LbResult" Margin="10,10,10,10"></ListBox>
|
||||
<ScrollViewer Grid.Column="1">
|
||||
<Grid ColumnDefinitions="*,*" RowDefinitions="50,2*,*">
|
||||
<ListBox Grid.RowSpan="2" x:Name="LbResult" Margin="0,10,10,10"></ListBox>
|
||||
<Grid Grid.Row="0" Grid.Column="1" Grid.ColumnDefinitions="*,*">
|
||||
<Button Grid.Column="0" Margin="0,10,0,0" x:Name="BtnExportCoursePDF" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnExportCoursePDF_OnClick" HorizontalContentAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<LucideIcon Kind="FileText" Width="24" Height="24" />
|
||||
<Label Content="Export (PDF)..." VerticalContentAlignment="Center" FontSize="12"
|
||||
FontWeight="Bold" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Grid.Column="1" Margin="5,10,0,0" x:Name="BtnExportCourseCSV" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnExportCourseCSV_OnClick" HorizontalContentAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<LucideIcon Kind="FileJson" Width="24" Height="24" />
|
||||
<Label Content="Export (CSV)..." VerticalContentAlignment="Center" FontSize="12"
|
||||
FontWeight="Bold" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</Grid>
|
||||
<ScrollViewer Grid.Row="1" Grid.Column="1" Margin="0,5,0,10" Background="#44CCCCCC">
|
||||
<TextBlock x:Name="TbResultStatistics"></TextBlock>
|
||||
</ScrollViewer>
|
||||
<ScrollViewer Grid.Row="2" Grid.Column="1" Margin="0,0,0,10" Background="#44CCCCCC">
|
||||
<TextBlock x:Name="TbResultTextout" FontFamily="Consolas"></TextBlock>
|
||||
</ScrollViewer>
|
||||
<ScrollViewer Grid.Row="2" Grid.Column="0" Margin="0,0,10,10" Background="#44CCCCCC">
|
||||
<TextBlock x:Name="TbResultLog" FontFamily="Consolas"></TextBlock>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
||||
@@ -10,9 +10,18 @@ namespace spplus;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public static MainWindow Instance { get; set; }
|
||||
public static string ApplicationVersion = "v1.2.24";
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
Settings.ImportInitial();
|
||||
Instance = this;
|
||||
RefreshCoursesList();
|
||||
try
|
||||
{
|
||||
NudSportMaxPerSemester.Value = Settings.Instance.NumCoursesPerSemester;
|
||||
} catch {}
|
||||
}
|
||||
|
||||
private void MnuExpSettings_OnClick(object? sender, RoutedEventArgs e)
|
||||
@@ -32,7 +41,7 @@ public partial class MainWindow : Window
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "https://git.mypapercloud.de/fierke/spplus/wiki",
|
||||
UseShellExecute = true // Wichtig für Plattformübergreifendes Öffnen
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -48,7 +57,7 @@ public partial class MainWindow : Window
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "https://git.mypapercloud.de/fierke/spplus",
|
||||
UseShellExecute = true // Wichtig für Plattformübergreifendes Öffnen
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -67,7 +76,7 @@ public partial class MainWindow : Window
|
||||
Grid g = new();
|
||||
TextBlock tb = new()
|
||||
{
|
||||
Text = "spplus v1.0.0\n(c)2026 MyPapertown, Elias Fierke"
|
||||
Text = $"spplus {MainWindow.ApplicationVersion}\n(c)2026 MyPapertown, Elias Fierke"
|
||||
};
|
||||
g.Children.Add(tb);
|
||||
w.Content = g;
|
||||
@@ -114,15 +123,40 @@ public partial class MainWindow : Window
|
||||
LblStudentAmount.Content = Settings.Instance.Students.Count.ToString();
|
||||
LblSelectedAmount.Content = count_selected.ToString();
|
||||
|
||||
List<(Sport, List<string>)> initial_sportlist = new();
|
||||
foreach (var sp in Settings.Instance.Sports)
|
||||
{
|
||||
initial_sportlist.Add((sp, new()));
|
||||
}
|
||||
foreach (Student s in Settings.Instance.Students)
|
||||
{
|
||||
foreach (var sp in s.SelectedCourseNames)
|
||||
{
|
||||
foreach (var item in initial_sportlist)
|
||||
{
|
||||
if (item.Item1.AlternativeNames.Contains(sp))
|
||||
{
|
||||
item.Item2.Add(s.ID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LblNumVoted.Content = "";
|
||||
foreach (var s in initial_sportlist)
|
||||
{
|
||||
LblNumVoted.Content += $"{s.Item1.Name}: {s.Item2.Count}\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void BtnCraftCourses_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
// Craft courses here / call course-crafter
|
||||
CourseCrafter.Craft();
|
||||
RefreshResultView();
|
||||
TbiResults.Focus();
|
||||
TclMainView.SelectedIndex = 2;
|
||||
//TbiResults.Focus();
|
||||
}
|
||||
|
||||
private void RefreshResultView()
|
||||
@@ -132,7 +166,7 @@ public partial class MainWindow : Window
|
||||
{
|
||||
try
|
||||
{
|
||||
for(int i = 0; i<s.Result.Count;i++)
|
||||
for(int i = 0; i<s.Result.Length;i++)
|
||||
{
|
||||
LbResult.Items.Add($"{s.Name} ({s.ID}) - {i+1}. Semester: {s.Result[i]}");
|
||||
}
|
||||
@@ -245,11 +279,11 @@ public partial class MainWindow : Window
|
||||
NudAmountCoursesSem2.Value = item.Semester[1];
|
||||
NudAmountCoursesSem3.Value = item.Semester[2];
|
||||
NudAmountCoursesSem4.Value = item.Semester[3];
|
||||
LbAlternativeCourses.Items.Clear();
|
||||
foreach (var alternative in item.AlternativeCourses)
|
||||
{
|
||||
LbAlternativeCourses.Items.Add(Settings.GetSportNameFromID(alternative));
|
||||
}
|
||||
// LbAlternativeCourses.Items.Clear();
|
||||
// foreach (var alternative in item.AlternativeCourses)
|
||||
// {
|
||||
// LbAlternativeCourses.Items.Add(Settings.GetSportNameFromID(alternative));
|
||||
// }
|
||||
LbAlternativeNames.Items.Clear();
|
||||
foreach (var alternative in item.AlternativeNames)
|
||||
{
|
||||
@@ -376,4 +410,36 @@ public partial class MainWindow : Window
|
||||
RefreshCoursesList();
|
||||
} catch (Exception ex){}
|
||||
}
|
||||
|
||||
private void BtnExportCoursePDF_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
// Export as PDF
|
||||
}
|
||||
|
||||
private void NudSportMaxPerSemester_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Settings.Instance.NumCoursesPerSemester = Convert.ToInt32(NudSportMaxPerSemester.Value);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
private async void BtnExportCourseCSV_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var topLevel = GetTopLevel(this);
|
||||
var file = await topLevel!.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
|
||||
{
|
||||
Title = "CSV-Datei speichern",
|
||||
SuggestedFileType = new FilePickerFileType(".csv-Datei")
|
||||
{
|
||||
Patterns = new[] { "*.csv" }
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (file == null) return;
|
||||
|
||||
ExportUtility.ExportToCSV(file.Path.AbsolutePath);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
# SP+
|
||||
|
||||
Interaktiver Sportkursplaner für Oberstufen auf Basis einer Sportkurswahl durch SuS.
|
||||
Plattformunabhängiger (Windows, Linux, Mac), interaktiver Sportkursplaner für Oberstufen auf Basis einer Sportkurswahl durch SuS.
|
||||
|
||||
## Features
|
||||
* \+ Import von CSV-Dateien mit Kurswahl
|
||||
* ~ Wahlansicht
|
||||
* \+ Wahlansicht
|
||||
* \+ Statistiken
|
||||
* ~ Pflege von Sportkursen (inkl. Kürzel/ alternativen Bezeichnungen)
|
||||
* \+ Pflege von Sportkursen (inkl. Kürzel/ alternativen Bezeichnungen)
|
||||
* \+ CSV-Export
|
||||
* ~ Fehleransicht für nicht-existente, aber gewählte Kurse
|
||||
* ~ PDF-Export
|
||||
|
||||
\+ Vorhanden, ~ Pending
|
||||
|
||||
|
||||
552
crafter.cs
552
crafter.cs
@@ -10,176 +10,446 @@ public class CourseCrafter
|
||||
{
|
||||
public Sport Sport = null!;
|
||||
public int Remaining;
|
||||
public List<Student> Students = new();
|
||||
public List<string> Students = new();
|
||||
}
|
||||
public static List<(int Semester, CourseInstance Instance)> GeneratedCourses
|
||||
= new();
|
||||
|
||||
public static void Craft()
|
||||
{
|
||||
GeneratedCourses = new();
|
||||
|
||||
var settings = Settings.Instance;
|
||||
var students = settings.Students;
|
||||
var sports = settings.Sports;
|
||||
|
||||
if (students.Count == 0 || sports.Count == 0)
|
||||
return;
|
||||
|
||||
int semesterCount = sports.Max(s => s.Semester.Length);
|
||||
|
||||
foreach (var st in students)
|
||||
st.Result = Enumerable.Repeat("Fehler", semesterCount).ToList();
|
||||
|
||||
var nameMap = new Dictionary<string, Sport>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var sp in sports)
|
||||
int globalCount = 0;
|
||||
List<(Sport, List<string>)> initial_sportlist = new();
|
||||
List<string>[] students_in_semester = new List<string>[4] { new(), new(), new(), new() };
|
||||
foreach (var sp in Settings.Instance.Sports)
|
||||
{
|
||||
nameMap[sp.Name] = sp;
|
||||
foreach (var alt in sp.AlternativeNames)
|
||||
nameMap[alt] = sp;
|
||||
initial_sportlist.Add((sp, new()));
|
||||
}
|
||||
|
||||
// Nachfrage je Sport
|
||||
var demand = new Dictionary<Sport, List<Student>>();
|
||||
foreach (var sp in sports)
|
||||
demand[sp] = new List<Student>();
|
||||
|
||||
foreach (var st in students)
|
||||
foreach (Student s in Settings.Instance.Students)
|
||||
{
|
||||
foreach (var sel in st.SelectedCourseNames.Distinct())
|
||||
foreach (var sp in s.SelectedCourseNames)
|
||||
{
|
||||
if (nameMap.TryGetValue(sel, out var sp))
|
||||
demand[sp].Add(st);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Semesterweise echte Verteilung =====
|
||||
for (int sem = 0; sem < semesterCount; sem++)
|
||||
foreach (var item in initial_sportlist)
|
||||
{
|
||||
int remainingSemesterSlots = settings.NumCoursesPerSemester;
|
||||
|
||||
foreach (var sp in sports)
|
||||
if (item.Item1.AlternativeNames.Contains(sp))
|
||||
{
|
||||
if (sem >= sp.Semester.Length)
|
||||
continue;
|
||||
|
||||
if (remainingSemesterSlots <= 0)
|
||||
break;
|
||||
|
||||
var interested = demand[sp]
|
||||
.Where(st =>
|
||||
st.Result![sem] == "Fehler" &&
|
||||
!st.Result.Contains(sp.Name))
|
||||
.ToList();
|
||||
|
||||
if (interested.Count < sp.MinStudents)
|
||||
continue;
|
||||
|
||||
int maxInstances = Math.Min(sp.Semester[sem], remainingSemesterSlots);
|
||||
int instanceCount = 0;
|
||||
int index = 0;
|
||||
|
||||
while (interested.Count - index >= sp.MinStudents &&
|
||||
instanceCount < maxInstances)
|
||||
{
|
||||
var inst = new CourseInstance
|
||||
{
|
||||
Sport = sp,
|
||||
Remaining = sp.MaxStudents
|
||||
};
|
||||
|
||||
GeneratedCourses.Add((sem, inst));
|
||||
remainingSemesterSlots--;
|
||||
instanceCount++;
|
||||
|
||||
int filled = 0;
|
||||
|
||||
while (filled < sp.MaxStudents &&
|
||||
index < interested.Count)
|
||||
{
|
||||
var st = interested[index++];
|
||||
|
||||
if (st.Result![sem] != "Fehler")
|
||||
continue;
|
||||
|
||||
inst.Students.Add(st);
|
||||
inst.Remaining--;
|
||||
st.Result[sem] = sp.Name;
|
||||
filled++;
|
||||
}
|
||||
|
||||
// Falls Mindestanzahl nicht erreicht → Instanz verwerfen
|
||||
if (inst.Students.Count < sp.MinStudents)
|
||||
{
|
||||
foreach (var st in inst.Students)
|
||||
st.Result[sem] = "Fehler";
|
||||
|
||||
GeneratedCourses.Remove((sem, inst));
|
||||
remainingSemesterSlots++;
|
||||
item.Item2.Add(s.ID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (!requestExit())
|
||||
{
|
||||
Console.WriteLine($"Calculating... ({globalCount})");
|
||||
foreach (var item in initial_sportlist)
|
||||
{
|
||||
if (item.Item2.Count >= item.Item1.MinStudents)
|
||||
{
|
||||
int semester = getSemesterForSport(item.Item1);
|
||||
if (semester <= 0) goto semeq0;
|
||||
var inst = new CourseInstance();
|
||||
inst.Sport = item.Item1;
|
||||
inst.Students = new List<string>();
|
||||
// int dist = 1;
|
||||
for (int i = item.Item2.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (inst.Students.Count >= inst.Sport.MaxStudents)
|
||||
break;
|
||||
|
||||
string stud = item.Item2[i];
|
||||
|
||||
if (!students_in_semester[semester - 1].Contains(stud))
|
||||
{
|
||||
inst.Students.Add(stud);
|
||||
students_in_semester[semester - 1].Add(stud);
|
||||
item.Item2.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
if (inst.Students.Count < inst.Sport.MinStudents)
|
||||
{
|
||||
// Rückgängig machen
|
||||
foreach (var s in inst.Students)
|
||||
{
|
||||
students_in_semester[semester-1].Remove(s);
|
||||
item.Item2.Add(s);
|
||||
}
|
||||
continue; // Kurs nicht erstellen
|
||||
}
|
||||
GeneratedCourses.Add((semester, inst));
|
||||
|
||||
//MainWindow.Instance.TbResultLog.Text += ($"{semester} -> {inst.Students.Count}\n");
|
||||
//MainWindow.Instance.TbResultLog.Text += ($"{students_in_semester[0].Count} - {students_in_semester[1].Count} - {students_in_semester[2].Count} - {students_in_semester[3].Count}\n\n");
|
||||
}
|
||||
|
||||
semeq0: ;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Kurse auffüllen (mit restl. Leuten)
|
||||
foreach (var item in initial_sportlist)
|
||||
{
|
||||
if (item.Item2.Count > 0)
|
||||
{
|
||||
foreach (var ci in GeneratedCourses)
|
||||
{
|
||||
|
||||
if (item.Item1.ID == ci.Instance.Sport.ID)
|
||||
{
|
||||
int semester = ci.Semester;
|
||||
List<string> added = new();
|
||||
foreach (string stud in item.Item2)
|
||||
{
|
||||
if (ci.Instance.Students.Count >= ci.Instance.Sport.MaxStudents) break;
|
||||
if (!students_in_semester[semester-1].Contains(stud))
|
||||
{
|
||||
ci.Instance.Students.Add(stud);
|
||||
students_in_semester[semester-1].Add(stud);
|
||||
//ci.Instance.Students.Add(stud);
|
||||
added.Add(stud);
|
||||
}
|
||||
}
|
||||
|
||||
// Hinzugefügte aus Initialkurs entfernen
|
||||
foreach (string s in added)
|
||||
{
|
||||
item.Item2.Remove(s);
|
||||
}
|
||||
}
|
||||
//MainWindow.Instance.TbResultLog.Text += ($"{ci.Semester} -> {ci.Instance.Students.Count}\n");
|
||||
//MainWindow.Instance.TbResultLog.Text += ($"{students_in_semester[0].Count} - {students_in_semester[1].Count} - {students_in_semester[2].Count} - {students_in_semester[3].Count}\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Kurs umdisponieren (besser verteilen)
|
||||
// Kurs umdisponieren (besser verteilen)
|
||||
bool changed;
|
||||
int maxIterations = 20;
|
||||
int iteration = 0;
|
||||
|
||||
do
|
||||
{
|
||||
changed = false;
|
||||
iteration++;
|
||||
|
||||
// nach Sport gruppieren
|
||||
var sports = GeneratedCourses
|
||||
.GroupBy(c => c.Instance.Sport.ID);
|
||||
|
||||
foreach (var sportGroup in sports)
|
||||
{
|
||||
var courses = sportGroup.ToList();
|
||||
|
||||
// paarweise vergleichen
|
||||
for (int i = 0; i < courses.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < courses.Count; j++)
|
||||
{
|
||||
if (i == j) continue;
|
||||
|
||||
var cA = courses[i];
|
||||
var cB = courses[j];
|
||||
|
||||
// nur sinnvoll, wenn Unterschied
|
||||
if (cA.Instance.Students.Count <= cB.Instance.Students.Count + 1)
|
||||
continue;
|
||||
|
||||
// Kandidaten aus A nach B verschieben
|
||||
for (int k = cA.Instance.Students.Count - 1; k >= 0; k--)
|
||||
{
|
||||
string stud = cA.Instance.Students[k];
|
||||
|
||||
// 1. Zielsemester frei?
|
||||
if (!isStudentFree(cB.Semester, stud))
|
||||
continue;
|
||||
|
||||
// 2. Zielkurs hat noch Platz?
|
||||
if (cB.Instance.Students.Count >= cB.Instance.Sport.MaxStudents)
|
||||
continue;
|
||||
|
||||
// 3. Quellkurs darf nicht unter Min fallen
|
||||
if (cA.Instance.Students.Count - 1 < cA.Instance.Sport.MinStudents)
|
||||
continue;
|
||||
|
||||
// --- MOVE durchführen ---
|
||||
cA.Instance.Students.RemoveAt(k);
|
||||
students_in_semester[cA.Semester - 1].Remove(stud);
|
||||
|
||||
cB.Instance.Students.Add(stud);
|
||||
students_in_semester[cB.Semester - 1].Add(stud);
|
||||
|
||||
changed = true;
|
||||
break; // nach jedem Move neu bewerten
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} while (changed && iteration < maxIterations);
|
||||
|
||||
|
||||
bool isStudentFree(int semester, string studentID)
|
||||
{
|
||||
foreach (var inst in GeneratedCourses)
|
||||
{
|
||||
if (semester != inst.Semester) continue;
|
||||
foreach (string stud in inst.Instance.Students)
|
||||
{
|
||||
if (stud == studentID) return false; // Schüler in genanntem Semester bereits gefunden
|
||||
}
|
||||
}
|
||||
|
||||
// Schüler nicht gefunden:
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool requestExit()
|
||||
{
|
||||
globalCount++;
|
||||
// max Kursanzahl
|
||||
if (GeneratedCourses.Count >= Settings.Instance.NumCoursesPerSemester * 4) return true;
|
||||
|
||||
|
||||
int low = 0;
|
||||
foreach (var item in initial_sportlist)
|
||||
{
|
||||
if (item.Item2.Count < item.Item1.MinStudents) low++;
|
||||
}
|
||||
|
||||
if (low >= initial_sportlist.Count) return true;
|
||||
|
||||
if (globalCount >= 20) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var tuple in initial_sportlist)
|
||||
{
|
||||
MainWindow.Instance.TbResultTextout.Text += $"{tuple.Item1}: {tuple.Item2.Count} remaining\n";
|
||||
}
|
||||
|
||||
// ...existing code...
|
||||
int getSemesterForSport2(Sport sp)
|
||||
{
|
||||
int[] semcount = new int[4];
|
||||
|
||||
foreach (var inst in GeneratedCourses)
|
||||
semcount[inst.Semester - 1]++;
|
||||
|
||||
int bestSem = 0;
|
||||
int minCourses = int.MaxValue;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (sp.Semester[i] == 0) continue;
|
||||
|
||||
// prüfen, ob für diesen Sport im Semester i schon die maximale Anzahl erreicht ist
|
||||
int sportCoursesInSemester = GeneratedCourses
|
||||
.Count(g => g.Semester == i + 1 && g.Instance.Sport.ID == sp.ID);
|
||||
|
||||
if (sportCoursesInSemester >= sp.Semester[i])
|
||||
continue;
|
||||
|
||||
if (semcount[i] < Settings.Instance.NumCoursesPerSemester &&
|
||||
semcount[i] < minCourses)
|
||||
{
|
||||
minCourses = semcount[i];
|
||||
bestSem = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return bestSem;
|
||||
}
|
||||
|
||||
int getSemesterForSport(Sport sp)
|
||||
{
|
||||
// 1. Zähle alle Kurse pro Semester (egal welche Sportart)
|
||||
int[] totalCoursesPerSemester = new int[4];
|
||||
foreach (var inst in GeneratedCourses)
|
||||
totalCoursesPerSemester[inst.Semester - 1]++;
|
||||
|
||||
int bestSem = 0;
|
||||
int minCourses = int.MaxValue;
|
||||
|
||||
// 2. Kandidaten-Semester durchgehen
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
// a) Sport darf in diesem Semester gar nicht stattfinden?
|
||||
if (sp.Semester[i] == 0)
|
||||
continue;
|
||||
|
||||
int semesterNumber = i + 1;
|
||||
|
||||
// b) Wie viele Kurse DIESES Sports gibt es schon in diesem Semester?
|
||||
int sportCoursesInThisSemester = GeneratedCourses
|
||||
.Count(g => g.Semester == semesterNumber &&
|
||||
g.Instance.Sport.Name == sp.Name);
|
||||
|
||||
// c) Pro-Sport-Limit erreicht?
|
||||
if (sportCoursesInThisSemester >= sp.Semester[i])
|
||||
continue;
|
||||
|
||||
// d) Globales Limit pro Semester erreicht?
|
||||
if (totalCoursesPerSemester[i] >= Settings.Instance.NumCoursesPerSemester)
|
||||
continue;
|
||||
|
||||
// e) Wähle das Semester mit bisher insgesamt den wenigsten Kursen
|
||||
if (totalCoursesPerSemester[i] < minCourses)
|
||||
{
|
||||
minCourses = totalCoursesPerSemester[i];
|
||||
bestSem = semesterNumber;
|
||||
}
|
||||
}
|
||||
|
||||
return bestSem; // 0, falls kein zulässiges Semester gefunden
|
||||
}
|
||||
|
||||
var errors = ValidateCourses(GeneratedCourses);
|
||||
|
||||
if (errors.Count == 0)
|
||||
{
|
||||
MainWindow.Instance.TbResultLog.Text = "--- Alle generierten Kursen erfüllen die gegebenen Voraussetzungen ---";
|
||||
}
|
||||
else
|
||||
{
|
||||
MainWindow.Instance.TbResultLog.Text = "--- Bei der Generierung sind folgende Fehler aufgetreten: ---\n\n";
|
||||
foreach (var e in errors)
|
||||
MainWindow.Instance.TbResultLog.Text += e + "\n";
|
||||
}
|
||||
|
||||
foreach (var course in GeneratedCourses)
|
||||
{
|
||||
foreach (var student in Settings.Instance.Students)
|
||||
{
|
||||
if (course.Instance.Students.Contains(student.ID))
|
||||
{
|
||||
student.Result[course.Semester-1] = course.Instance.Sport.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static string GenerateStatistics()
|
||||
{
|
||||
var settings = Settings.Instance;
|
||||
var students = settings.Students;
|
||||
|
||||
if (GeneratedCourses == null || GeneratedCourses.Count == 0)
|
||||
return "Keine Kurse generiert.";
|
||||
|
||||
int semesterCount = students
|
||||
.Where(s => s.Result != null)
|
||||
.Select(s => s.Result!.Count)
|
||||
.DefaultIfEmpty(0)
|
||||
.Max();
|
||||
|
||||
var sb = new System.Text.StringBuilder();
|
||||
|
||||
sb.AppendLine($"Anzahl generierter Kurse: {GeneratedCourses.Count}");
|
||||
sb.AppendLine("Übersicht:");
|
||||
|
||||
// ===== Kursübersicht =====
|
||||
var grouped = GeneratedCourses
|
||||
.GroupBy(g => new { g.Semester, g.Instance.Sport.Name })
|
||||
.OrderBy(g => g.Key.Semester)
|
||||
.ThenBy(g => g.Key.Name);
|
||||
|
||||
foreach (var group in grouped)
|
||||
GeneratedCourses.Sort((x,y) => x.Semester.CompareTo(y.Semester) );
|
||||
string sb = $"Generierte Kurse: {GeneratedCourses.Count}\n\n";
|
||||
foreach (var genc in GeneratedCourses)
|
||||
{
|
||||
int counter = 1;
|
||||
sb += $"Sem. {genc.Semester}: {genc.Instance.Sport.Name} ({genc.Instance.Students.Count} SuS)\n";
|
||||
}
|
||||
|
||||
foreach (var entry in group)
|
||||
|
||||
|
||||
return sb;
|
||||
}
|
||||
|
||||
public static List<string> ValidateCourses(List<(int Semester, CourseInstance Instance)> courses)
|
||||
{
|
||||
int semester = group.Key.Semester + 1;
|
||||
string sportName = group.Key.Name;
|
||||
string number = counter.ToString("D2");
|
||||
int count = entry.Instance.Students.Count;
|
||||
List<string> errors = new();
|
||||
|
||||
sb.AppendLine(
|
||||
$"Semester {semester}: {sportName} {number}: {count} Schüler*innen"
|
||||
);
|
||||
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
sb.AppendLine();
|
||||
sb.AppendLine("Fehlerübersicht:");
|
||||
|
||||
// ===== Fehler pro Semester =====
|
||||
for (int sem = 0; sem < semesterCount; sem++)
|
||||
// --- 1. Min/Max + Semester erlaubt ---
|
||||
foreach (var tuple in courses)
|
||||
{
|
||||
int errors = students.Count(st =>
|
||||
st.Result != null &&
|
||||
st.Result.Count > sem &&
|
||||
st.Result[sem] == "Fehler");
|
||||
int semester = tuple.Semester;
|
||||
var inst = tuple.Instance;
|
||||
var sport = inst.Sport;
|
||||
|
||||
sb.AppendLine($"Semester {sem + 1}: {errors} Fehler");
|
||||
if (inst.Students.Count < sport.MinStudents)
|
||||
{
|
||||
errors.Add($"[Min] {sport.Name} (Sem {semester}): {inst.Students.Count} < {sport.MinStudents}");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
if (inst.Students.Count > sport.MaxStudents)
|
||||
{
|
||||
errors.Add($"[Max] {sport.Name} (Sem {semester}): {inst.Students.Count} > {sport.MaxStudents}");
|
||||
}
|
||||
|
||||
if (sport.Semester[semester - 1] == 0)
|
||||
{
|
||||
errors.Add($"[Semester] {sport.Name} darf nicht in Semester {semester} stattfinden");
|
||||
}
|
||||
|
||||
// --- doppelte Schüler im selben Kurs ---
|
||||
for (int i = 0; i < inst.Students.Count; i++)
|
||||
{
|
||||
for (int j = i + 1; j < inst.Students.Count; j++)
|
||||
{
|
||||
if (inst.Students[i] == inst.Students[j])
|
||||
{
|
||||
errors.Add($"[Kurs-Duplikat] {inst.Students[i]} mehrfach in {sport.Name} (Sem {semester})");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- 2. Schüler doppelt im Semester ---
|
||||
for (int sem = 1; sem <= 4; sem++)
|
||||
{
|
||||
List<string> students = new();
|
||||
|
||||
foreach (var tuple in courses)
|
||||
{
|
||||
if (tuple.Semester != sem) continue;
|
||||
|
||||
foreach (var stud in tuple.Instance.Students)
|
||||
{
|
||||
// prüfen ob schon drin
|
||||
bool exists = false;
|
||||
foreach (var s in students)
|
||||
{
|
||||
if (s == stud)
|
||||
{
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (exists)
|
||||
{
|
||||
errors.Add($"[Doppelt] Schüler {stud} doppelt in Semester {sem}");
|
||||
}
|
||||
else
|
||||
{
|
||||
students.Add(stud);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- 3. Sport-Angebote pro Semester zählen ---
|
||||
// (ohne Dictionary: wir iterieren über alle Kurse und zählen jeweils erneut)
|
||||
|
||||
foreach (var tuple in courses)
|
||||
{
|
||||
int semester = tuple.Semester;
|
||||
var sport = tuple.Instance.Sport;
|
||||
|
||||
int count = 0;
|
||||
|
||||
foreach (var other in courses)
|
||||
{
|
||||
if (other.Semester == semester &&
|
||||
other.Instance.Sport.Name == sport.Name)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
int allowed = sport.Semester[semester - 1];
|
||||
|
||||
if (count > allowed)
|
||||
{
|
||||
errors.Add($"[Sport-Semester] {sport.Name} in Sem {semester}: {count} Kurse > erlaubt {allowed}");
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
19
exporter.cs
Normal file
19
exporter.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.IO;
|
||||
|
||||
namespace spplus;
|
||||
|
||||
public static class ExportUtility
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
22
structs.cs
22
structs.cs
@@ -12,7 +12,7 @@ public class Sport
|
||||
public int MinStudents { get; set; } = 5; // Minimale Anzahl an Schülern pro Kurs
|
||||
public int[] Semester { get; set; } = [2, 2, 2, 2]; // Maximale Anzahl an Angeboten in den jeweiligen Index-Semestern (0 => 1. Semester)
|
||||
public List<string> AlternativeNames { get; set; } = new();
|
||||
public List<int> AlternativeCourses { get; set; } = new();
|
||||
//public List<int> AlternativeCourses { get; set; } = new();
|
||||
|
||||
protected Sport()
|
||||
{
|
||||
@@ -33,15 +33,15 @@ public class Sport
|
||||
AlternativeNames = alternativeNames;
|
||||
}
|
||||
|
||||
public void AddAlternativeSport(int id)
|
||||
{
|
||||
AlternativeCourses.Add(id);
|
||||
}
|
||||
|
||||
public void ClearAlternativeSport()
|
||||
{
|
||||
AlternativeCourses.Clear();
|
||||
}
|
||||
// public void AddAlternativeSport(int id)
|
||||
// {
|
||||
// AlternativeCourses.Add(id);
|
||||
// }
|
||||
//
|
||||
// public void ClearAlternativeSport()
|
||||
// {
|
||||
// AlternativeCourses.Clear();
|
||||
// }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
@@ -59,7 +59,7 @@ public class Student
|
||||
public string ID { get; set; } = ""; // ID des Schüler (z.B. NolteSeb)
|
||||
public string Name { get; set; } = ""; // Name des Schülers
|
||||
public List<string> SelectedCourseNames { get; set; } = new();
|
||||
public List<string>? Result { get; set; } = null;
|
||||
public string[] Result { get; set; } = new string[4];
|
||||
|
||||
public Student()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user