Compare commits
4 Commits
6f1ffd40b6
...
d70770e2f0
| Author | SHA1 | Date | |
|---|---|---|---|
| d70770e2f0 | |||
| 2c2f2d2d94 | |||
| c5a234cea7 | |||
| c6f9994c25 |
@@ -199,20 +199,24 @@
|
|||||||
<Label FontSize="20" Content="Ergebnisse" VerticalContentAlignment="Center" />
|
<Label FontSize="20" Content="Ergebnisse" VerticalContentAlignment="Center" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</TabItem.Header>
|
</TabItem.Header>
|
||||||
<Grid ColumnDefinitions="*,*">
|
<Grid ColumnDefinitions="*,*" RowDefinitions="50,2*,*">
|
||||||
<ListBox x:Name="LbResult" Margin="10,10,10,10"></ListBox>
|
<ListBox Grid.RowSpan="2" x:Name="LbResult" Margin="10,10,10,10"></ListBox>
|
||||||
<StackPanel Orientation="Vertical" Grid.Column="1" Spacing="10">
|
<Button Grid.Row="0" Grid.Column="1" Margin="0,10,0,0" x:Name="BtnExportCoursePDF" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnExportCoursePDF_OnClick" HorizontalContentAlignment="Center">
|
||||||
<Button Margin="0,10,0,0" x:Name="BtnExportCoursePDF" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnExportCoursePDF_OnClick" HorizontalContentAlignment="Center">
|
<StackPanel Orientation="Horizontal">
|
||||||
<StackPanel Orientation="Horizontal">
|
<LucideIcon Kind="FileText" Width="24" Height="24" />
|
||||||
<LucideIcon Kind="FileText" Width="24" Height="24" />
|
<Label Content="Export (PDF)..." VerticalContentAlignment="Center" FontSize="12"
|
||||||
<Label Content="Export (PDF)..." VerticalContentAlignment="Center" FontSize="12"
|
FontWeight="Bold" />
|
||||||
FontWeight="Bold" />
|
</StackPanel>
|
||||||
</StackPanel>
|
</Button>
|
||||||
</Button>
|
<ScrollViewer Grid.Row="1" Grid.Column="1" Margin="0,5,0,10" Background="#44CCCCCC">
|
||||||
<ScrollViewer>
|
<TextBlock x:Name="TbResultStatistics"></TextBlock>
|
||||||
<TextBlock x:Name="TbResultStatistics"></TextBlock>
|
</ScrollViewer>
|
||||||
</ScrollViewer>
|
<ScrollViewer Grid.Row="2" Grid.Column="1" Margin="0" Background="#44CCCCCC">
|
||||||
</StackPanel>
|
<TextBlock x:Name="TbResultTextout" FontFamily="Consolas"></TextBlock>
|
||||||
|
</ScrollViewer>
|
||||||
|
<ScrollViewer Grid.Row="2" Grid.Column="0" Margin="0" Background="#44CCCCCC">
|
||||||
|
<TextBlock x:Name="TbResultLog" FontFamily="Consolas"></TextBlock>
|
||||||
|
</ScrollViewer>
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</TabControl>
|
</TabControl>
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ namespace spplus;
|
|||||||
|
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
|
public static MainWindow Instance { get; set; }
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Settings.ImportInitial();
|
Settings.ImportInitial();
|
||||||
|
Instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MnuExpSettings_OnClick(object? sender, RoutedEventArgs e)
|
private void MnuExpSettings_OnClick(object? sender, RoutedEventArgs e)
|
||||||
@@ -115,7 +117,6 @@ public partial class MainWindow : Window
|
|||||||
LblStudentAmount.Content = Settings.Instance.Students.Count.ToString();
|
LblStudentAmount.Content = Settings.Instance.Students.Count.ToString();
|
||||||
LblSelectedAmount.Content = count_selected.ToString();
|
LblSelectedAmount.Content = count_selected.ToString();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BtnCraftCourses_OnClick(object? sender, RoutedEventArgs e)
|
private void BtnCraftCourses_OnClick(object? sender, RoutedEventArgs e)
|
||||||
|
|||||||
235
crafter.cs
235
crafter.cs
@@ -10,11 +10,225 @@ public class CourseCrafter
|
|||||||
{
|
{
|
||||||
public Sport Sport = null!;
|
public Sport Sport = null!;
|
||||||
public int Remaining;
|
public int Remaining;
|
||||||
public List<Student> Students = new();
|
public List<string> Students = new();
|
||||||
}
|
}
|
||||||
public static List<(int Semester, CourseInstance Instance)> GeneratedCourses
|
public static List<(int Semester, CourseInstance Instance)> GeneratedCourses
|
||||||
= new();
|
= new();
|
||||||
|
|
||||||
public static void Craft()
|
public static void Craft()
|
||||||
|
{
|
||||||
|
GeneratedCourses = new();
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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: ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// foreach (var item in initial_sportlist)
|
||||||
|
// {
|
||||||
|
// Console.WriteLine($"{item.Item1.Name}: {item.Item2.Count}x gewählt");
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int getSemester()
|
||||||
|
{
|
||||||
|
//int sem = 0;
|
||||||
|
if (GeneratedCourses.Count == 0) return 1; // zunächst im ersten Semester beginnen
|
||||||
|
int[] semcount = new int[4] {0,0,0,0}; // Anzahl der generierten Kurse im jeweiligen Semester
|
||||||
|
foreach (var inst in GeneratedCourses)
|
||||||
|
{
|
||||||
|
semcount[inst.Semester - 1]++; // ...füllen
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i<semcount.Length; i++) // durchlaufen und prüfen
|
||||||
|
{
|
||||||
|
if (semcount[i] < Settings.Instance.NumCoursesPerSemester)
|
||||||
|
{
|
||||||
|
return i+1; // Semester zurückgeben, wenn genug da sind
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
// // max Anzahl in allen Semestern
|
||||||
|
// foreach(int sem in new[]{1,2,3,4})
|
||||||
|
// {
|
||||||
|
// int count = 0;
|
||||||
|
// foreach (var inst in GeneratedCourses)
|
||||||
|
// {
|
||||||
|
// if (inst.Semester == sem) count++;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (sem >= Settings.Instance.NumCoursesPerSemester);
|
||||||
|
// }
|
||||||
|
|
||||||
|
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 >= 12) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var tuple in initial_sportlist)
|
||||||
|
{
|
||||||
|
MainWindow.Instance.TbResultTextout.Text += $"{tuple.Item1}: {tuple.Item2.Count} remaining\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
int getSemesterForSport(Sport sp)
|
||||||
|
{
|
||||||
|
int[] semcount = new int[4] {0,0,0,0};
|
||||||
|
|
||||||
|
foreach (var inst in GeneratedCourses)
|
||||||
|
{
|
||||||
|
semcount[inst.Semester - 1]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
// 1. Ist der Sport in diesem Semester erlaubt?
|
||||||
|
if (sp.Semester[i] == 0) continue;
|
||||||
|
|
||||||
|
// 2. Ist noch Platz für Kurse?
|
||||||
|
if (semcount[i] < Settings.Instance.NumCoursesPerSemester)
|
||||||
|
{
|
||||||
|
return i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public static void CraftOld()
|
||||||
{
|
{
|
||||||
GeneratedCourses = new();
|
GeneratedCourses = new();
|
||||||
|
|
||||||
@@ -101,7 +315,7 @@ public class CourseCrafter
|
|||||||
if (st.Result![sem] != "Fehler")
|
if (st.Result![sem] != "Fehler")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
inst.Students.Add(st);
|
//inst.Students.Add(st);
|
||||||
inst.Remaining--;
|
inst.Remaining--;
|
||||||
st.Result[sem] = sp.Name;
|
st.Result[sem] = sp.Name;
|
||||||
filled++;
|
filled++;
|
||||||
@@ -110,8 +324,8 @@ public class CourseCrafter
|
|||||||
// Falls Mindestanzahl nicht erreicht → Instanz verwerfen
|
// Falls Mindestanzahl nicht erreicht → Instanz verwerfen
|
||||||
if (inst.Students.Count < sp.MinStudents)
|
if (inst.Students.Count < sp.MinStudents)
|
||||||
{
|
{
|
||||||
foreach (var st in inst.Students)
|
//foreach (var st in inst.Students)
|
||||||
st.Result[sem] = "Fehler";
|
//st.Result[sem] = "Fehler";
|
||||||
|
|
||||||
GeneratedCourses.Remove((sem, inst));
|
GeneratedCourses.Remove((sem, inst));
|
||||||
remainingSemesterSlots++;
|
remainingSemesterSlots++;
|
||||||
@@ -123,6 +337,19 @@ public class CourseCrafter
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static string GenerateStatistics()
|
public static string GenerateStatistics()
|
||||||
|
{
|
||||||
|
string sb = $"Generierte Kurse: {GeneratedCourses.Count}\n\n";
|
||||||
|
foreach (var genc in GeneratedCourses)
|
||||||
|
{
|
||||||
|
sb += $"Sem. {genc.Semester}: {genc.Instance.Sport.Name} ({genc.Instance.Students.Count} SuS)\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return sb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GenerateStatisticsOld()
|
||||||
{
|
{
|
||||||
var settings = Settings.Instance;
|
var settings = Settings.Instance;
|
||||||
var students = settings.Students;
|
var students = settings.Students;
|
||||||
|
|||||||
Reference in New Issue
Block a user