Compare commits
85 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a0eac4ae95 | |||
| 22e9377062 | |||
| 11e6aab8fd | |||
| 13f313d4a0 | |||
| 64951c579f | |||
| 4130c36335 | |||
| 7f2fc99d0b | |||
| eb640ff749 | |||
| 54a564df04 | |||
| 71dc63f2a2 | |||
| 68f673c8d7 | |||
| d5b7fd7af3 | |||
| 573e7c86e8 | |||
| 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 | |||
| 8bfa22451e | |||
| 8be9a9a925 | |||
| d1f5444caf | |||
| aec57d7d9d | |||
| 2f18629e83 | |||
| 5f44e63129 | |||
| 0df27f7e50 | |||
| df282d1164 | |||
| af2ad3dab7 | |||
| 8672b09ff0 | |||
| d23c8870ed | |||
| 1bfd2f5219 | |||
| 77ca5aa1ff | |||
| 12606d45fb | |||
| ce1eeab166 | |||
| 4ac8182cf2 | |||
| 3cdfb61586 | |||
| e3d504ceb7 | |||
| 99a6bdd473 | |||
| 8b92b32e60 | |||
| 5868ca882b | |||
| b3e8c7ee5e | |||
| 6b769f413c | |||
| b772e29084 | |||
| 8b0703f25e | |||
| 1b07d0e2ab | |||
| 6a08694753 | |||
| fabefabe0f | |||
| a572fdf72b | |||
| a855f0664a | |||
| f8f5140d47 | |||
| e9c7b61ced | |||
| e27a6b88d4 | |||
| 70c028aee7 | |||
| bbfe6299b5 | |||
| d5ff2aeee0 | |||
| 60c8a19a58 | |||
| dd30ebd516 | |||
| 186a77eacc | |||
| a7c2b7e5d1 | |||
| 8a8803395f |
+195
-14
@@ -3,24 +3,25 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="spplus.MainWindow"
|
||||
Title="SP+">
|
||||
x:Class="spplus.MainWindow" WindowState="Maximized"
|
||||
Title="spplus">
|
||||
<Border>
|
||||
<Grid RowDefinitions="30,*">
|
||||
<Menu Background="#50888888">
|
||||
<MenuItem Header="Datei">
|
||||
<!-- <MenuItem Click="MnuSettings_OnClick" x:Name="MnuSettings" Header="Einstellungen" /> -->
|
||||
<!-- <Separator /> -->
|
||||
<MenuItem x:Name="MnuExpSettings" Header="Einstellungen exportieren" />
|
||||
<MenuItem x:Name="MnuExit" Header="Beenden" />
|
||||
<MenuItem x:Name="MnuExpSettings" Header="Einstellungen exportieren" Click="MnuExpSettings_OnClick" />
|
||||
<MenuItem x:Name="MnuImpResult" Header="Berechnung importieren" Click="MnuImpResult_OnClick" />
|
||||
<MenuItem x:Name="MnuExit" Header="Beenden" Click="MnuExit_OnClick"/>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Hilfe">
|
||||
<MenuItem Header="Onlinehilfe" x:Name="MnuHelp" />
|
||||
<MenuItem Header="Git" x:Name="MnuGit" />
|
||||
<MenuItem Header="Über" x:Name="MnuAbout" />
|
||||
<MenuItem Header="Onlinehilfe" x:Name="MnuHelp" Click="MnuHelp_OnClick"/>
|
||||
<MenuItem Header="Git" x:Name="MnuGit" Click="MnuGit_OnClick"/>
|
||||
<MenuItem Header="Über" x:Name="MnuAbout" Click="MnuAbout_OnClick" />
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
<TabControl Grid.Row="1">
|
||||
<TabControl x:Name="TclMainView" Grid.Row="1" TabStripPlacement="Left">
|
||||
<TabItem>
|
||||
<TabItem.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
@@ -28,7 +29,72 @@
|
||||
<Label FontSize="20" Content="Planung" VerticalContentAlignment="Center" />
|
||||
</StackPanel>
|
||||
</TabItem.Header>
|
||||
<Grid RowDefinitions="2*,*,*">
|
||||
<Grid ColumnDefinitions="*,2*" RowDefinitions="*,*">
|
||||
<Button Grid.RowSpan="2" Margin="0,10,0,0" x:Name="BtnImport" VerticalAlignment="Top" Height="50" HorizontalAlignment="Stretch" Click="BtnImport_OnClick" HorizontalContentAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<LucideIcon Kind="Import" Width="36" Height="36" />
|
||||
<Label Content="Importieren..." VerticalContentAlignment="Center" FontSize="15"
|
||||
FontWeight="Bold" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<Button Grid.RowSpan="2" Margin="0,00,0,10" x:Name="BtnCraftCourses" VerticalAlignment="Bottom" Height="50" HorizontalAlignment="Stretch" Click="BtnCraftCourses_OnClick" HorizontalContentAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<LucideIcon Kind="Pickaxe" Width="36" Height="36" />
|
||||
<Label Content="Kurse basteln" VerticalContentAlignment="Center" FontSize="15"
|
||||
FontWeight="Bold" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
|
||||
<ListBox Grid.RowSpan="2" x:Name="LbStudentsImported" SelectionChanged="LbStudentsImported_OnSelectionChanged" Margin="0,70,0,70" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"></ListBox>
|
||||
|
||||
<StackPanel Grid.Column="1" Grid.Row="0" Margin="10,10,10,10" Orientation="Vertical" Spacing="10">
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="ID"></Label>
|
||||
<TextBox Grid.Column="1" x:Name="TbStudentID" TextChanged="TbStudentID_OnTextChanged"></TextBox>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Name"></Label>
|
||||
<TextBox Grid.Column="1" x:Name="TbStudentName" TextChanged="TbStudentName_OnTextChanged"></TextBox>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Sport 1"></Label>
|
||||
<Label Grid.Column="1" x:Name="LblSport1"></Label>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Sport 2"></Label>
|
||||
<Label Grid.Column="1" x:Name="LblSport2"></Label>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Sport 3"></Label>
|
||||
<Label Grid.Column="1" x:Name="LblSport3"></Label>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Sport 4"></Label>
|
||||
<Label Grid.Column="1" x:Name="LblSport4"></Label>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="1" Grid.Row="1" Margin="10,10,10,10" Orientation="Vertical" Spacing="10">
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Anzahl Einträge"></Label>
|
||||
<Label Grid.Column="1" x:Name="LblStudentAmount"></Label>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<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>
|
||||
|
||||
|
||||
</Grid>
|
||||
@@ -40,22 +106,137 @@
|
||||
<Label FontSize="20" Content="Kurse" VerticalContentAlignment="Center" />
|
||||
</StackPanel>
|
||||
</TabItem.Header>
|
||||
<Grid RowDefinitions="2*,*,*">
|
||||
<Grid ColumnDefinitions="*,2*">
|
||||
<StackPanel Grid.ColumnSpan="2" Orientation="Horizontal" Spacing="10">
|
||||
<Button Margin="0,10,0,0" x:Name="BtnImportDefaultCourses" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnImportDefaultCourses_OnClick" HorizontalContentAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<LucideIcon Kind="Import" Width="24" Height="24" />
|
||||
<Label Content="Standardkurse importieren..." VerticalContentAlignment="Center" FontSize="12"
|
||||
FontWeight="Bold" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Margin="0,10,0,0" x:Name="BtnDeleteSinleCourse" Background="#99963434" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnDeleteSinleCourse_OnClick" HorizontalContentAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<LucideIcon Kind="Trash2" Width="24" Height="24" />
|
||||
<Label Content="Ausgewähltes entfernen" VerticalContentAlignment="Center" FontSize="12"
|
||||
FontWeight="Bold" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button Margin="0,10,0,0" x:Name="BtnClearCourseList" Background="#99963434" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnClearCourseList_OnClick" HorizontalContentAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<LucideIcon Kind="Trash" Width="24" Height="24" />
|
||||
<Label Content="Liste leeren" VerticalContentAlignment="Center" FontSize="12"
|
||||
FontWeight="Bold" />
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<ListBox Grid.Column="0" x:Name="LbSportCourses" SelectionChanged="LbSportCourses_OnSelectionChanged" Margin="0,55,0,0" />
|
||||
<StackPanel Grid.Column="1" Grid.Row="0" Margin="10,10,10,10" Orientation="Vertical" Spacing="10">
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="ID"></Label>
|
||||
<Label Grid.Column="1" x:Name="LblSportID"></Label>
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Name"></Label>
|
||||
<TextBox Grid.Column="1" x:Name="TbSportName" TextChanged="TbSportName_OnTextChanged"></TextBox>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Maximale Schüler*innenanzahl"></Label>
|
||||
<NumericUpDown Grid.Column="1" x:Name="NudSportMaxStudents" ValueChanged="NudSportMaxStudents_OnValueChanged"></NumericUpDown>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Minimale Schüler*innenanzahl"></Label>
|
||||
<NumericUpDown Grid.Column="1" x:Name="NudSportMinStudents" ValueChanged="NudSportMinStudents_OnValueChanged"></NumericUpDown>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Anzahl Angebote Semester 1"></Label>
|
||||
<NumericUpDown Grid.Column="1" x:Name="NudAmountCoursesSem1" ValueChanged="NudAmountCoursesSem1_OnValueChanged"></NumericUpDown>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Anzahl Angebote Semester 2"></Label>
|
||||
<NumericUpDown Grid.Column="1" x:Name="NudAmountCoursesSem2" ValueChanged="NudAmountCoursesSem2_OnValueChanged"></NumericUpDown>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Anzahl Angebote Semester 3"></Label>
|
||||
<NumericUpDown Grid.Column="1" x:Name="NudAmountCoursesSem3" ValueChanged="NudAmountCoursesSem3_OnValueChanged"></NumericUpDown>
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="*,3*">
|
||||
<Label Content="Anzahl Angebote Semester 4"></Label>
|
||||
<NumericUpDown Grid.Column="1" x:Name="NudAmountCoursesSem4" ValueChanged="NudAmountCoursesSem4_OnValueChanged"></NumericUpDown>
|
||||
</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="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="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 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>
|
||||
|
||||
<TabItem>
|
||||
<TabItem x:Name="TbiResults">
|
||||
<TabItem.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<LucideIcon Kind="Sparkles" Width="32" Height="32" Size="32" />
|
||||
<Label FontSize="20" Content="Ergebnisse" VerticalContentAlignment="Center" />
|
||||
</StackPanel>
|
||||
</TabItem.Header>
|
||||
<Grid RowDefinitions="2*,*,*">
|
||||
|
||||
|
||||
<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>
|
||||
|
||||
@@ -1,11 +1,462 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
|
||||
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)
|
||||
{
|
||||
var res = MessageBox.Show(this, "Dieses Feature ist noch nicht implementiert", "Fehlend");
|
||||
}
|
||||
|
||||
private void MnuExit_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
private void MnuHelp_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "https://git.mypapercloud.de/fierke/spplus/wiki",
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void MnuGit_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "https://git.mypapercloud.de/fierke/spplus",
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void MnuAbout_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Window w = new();
|
||||
w.WindowState = WindowState.Normal;
|
||||
w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
w.Width = 300;
|
||||
w.Height = 120;
|
||||
Grid g = new();
|
||||
TextBlock tb = new()
|
||||
{
|
||||
Text = $"spplus {MainWindow.ApplicationVersion}\n(c)2026 MyPapertown, Elias Fierke"
|
||||
};
|
||||
g.Children.Add(tb);
|
||||
w.Content = g;
|
||||
w.Show();
|
||||
}
|
||||
|
||||
private async void BtnImport_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var topLevel = GetTopLevel(this);
|
||||
var file = await topLevel!.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
Title = "CSV-Datei auswählen",
|
||||
AllowMultiple = false,
|
||||
FileTypeFilter = new[]
|
||||
{
|
||||
new FilePickerFileType(".csv-Datei")
|
||||
{
|
||||
Patterns = new[] { "*.csv" }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (file == null) return;
|
||||
if (file.Count == 0) return;
|
||||
|
||||
var imported_students = import.ImportStudentsFromFile(file[0].Path.LocalPath.ToString());
|
||||
foreach (var s in imported_students)
|
||||
{
|
||||
Settings.Instance.Students.Add(s);
|
||||
}
|
||||
RefreshImportedStudentList();
|
||||
|
||||
}
|
||||
|
||||
private void RefreshImportedStudentList()
|
||||
{
|
||||
LbStudentsImported.Items.Clear();
|
||||
int count_selected = 0;
|
||||
foreach (var s in Settings.Instance.Students)
|
||||
{
|
||||
LbStudentsImported.Items.Add(s);
|
||||
count_selected += s.SelectedCourseNames.Count;
|
||||
}
|
||||
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)
|
||||
{
|
||||
CourseCrafter.Craft();
|
||||
RefreshResultView();
|
||||
TclMainView.SelectedIndex = 2;
|
||||
//TbiResults.Focus();
|
||||
}
|
||||
|
||||
private void RefreshResultView()
|
||||
{
|
||||
LbResult.Items.Clear();
|
||||
foreach (Student s in Settings.Instance.Students)
|
||||
{
|
||||
try
|
||||
{
|
||||
for(int i = 0; i<s.Result.Length;i++)
|
||||
{
|
||||
LbResult.Items.Add($"{s.Name} ({s.ID}) - {i+1}. Semester: {s.Result[i]}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
TbResultStatistics.Text = CourseCrafter.GenerateStatistics();
|
||||
}
|
||||
|
||||
private void LbStudentsImported_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
Prepare();
|
||||
var stud = (Student)LbStudentsImported.SelectedItem;
|
||||
if (stud == null)
|
||||
{
|
||||
TbStudentName.Text = string.Empty;
|
||||
TbStudentID.Text = string.Empty;
|
||||
SetEmpty();
|
||||
return;
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
TbStudentName.Text = stud.Name;
|
||||
TbStudentID.Text = stud.ID;
|
||||
LblSport1.Content = stud.SelectedCourseNames[0];
|
||||
LblSport2.Content = stud.SelectedCourseNames[1];
|
||||
LblSport3.Content = stud.SelectedCourseNames[2];
|
||||
LblSport4.Content = stud.SelectedCourseNames[3];
|
||||
}
|
||||
catch
|
||||
{
|
||||
SetEmpty();
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
void SetEmpty()
|
||||
{
|
||||
if(LblSport1.Content == "null") LblSport1.Content = "ungewählt";
|
||||
if(LblSport2.Content == "null") LblSport2.Content = "ungewählt";
|
||||
if(LblSport3.Content == "null") LblSport3.Content = "ungewählt";
|
||||
if(LblSport4.Content == "null") LblSport4.Content = "ungewählt";
|
||||
}
|
||||
|
||||
void Prepare()
|
||||
{
|
||||
LblSport1.Content = "null";
|
||||
LblSport2.Content = "null";
|
||||
LblSport3.Content = "null";
|
||||
LblSport4.Content = "null";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void TbStudentName_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Student)LbStudentsImported.SelectedItem).Name = TbStudentName.Text;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
private void TbStudentID_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Student)LbStudentsImported.SelectedItem).ID = TbStudentID.Text;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnImportDefaultCourses_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Settings.ImportInitial();
|
||||
RefreshCoursesList();
|
||||
}
|
||||
|
||||
private void RefreshCoursesList()
|
||||
{
|
||||
LbSportCourses.Items.Clear();
|
||||
foreach (var sp in Settings.Instance.Sports)
|
||||
{
|
||||
LbSportCourses.Items.Add(sp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void LbSportCourses_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (LbSportCourses.SelectedItem != null)
|
||||
{
|
||||
if (LbSportCourses.SelectedItem is Sport item)
|
||||
{
|
||||
LblSportID.Content = item.ID;
|
||||
TbSportName.Text = item.Name;
|
||||
NudSportMaxStudents.Value = item.MaxStudents;
|
||||
NudSportMinStudents.Value = item.MinStudents;
|
||||
NudAmountCoursesSem1.Value = item.Semester[0];
|
||||
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));
|
||||
// }
|
||||
LbAlternativeNames.Items.Clear();
|
||||
foreach (var alternative in item.AlternativeNames)
|
||||
{
|
||||
LbAlternativeNames.Items.Add(alternative);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TbSportName_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Sport)LbSportCourses.SelectedItem).Name = TbSportName.Text;
|
||||
} catch {}
|
||||
}
|
||||
|
||||
private void NudSportMaxStudents_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Sport)LbSportCourses.SelectedItem).MaxStudents = Convert.ToInt32(NudSportMaxStudents.Value);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
private void NudSportMinStudents_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Sport)LbSportCourses.SelectedItem).MinStudents = Convert.ToInt32(NudSportMinStudents.Value);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
private void NudAmountCoursesSem1_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Sport)LbSportCourses.SelectedItem).Semester[0] = Convert.ToInt32(NudAmountCoursesSem1.Value);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
private void NudAmountCoursesSem2_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Sport)LbSportCourses.SelectedItem).Semester[1] = Convert.ToInt32(NudAmountCoursesSem2.Value);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
private void NudAmountCoursesSem3_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Sport)LbSportCourses.SelectedItem).Semester[2] = Convert.ToInt32(NudAmountCoursesSem3.Value);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
private void NudAmountCoursesSem4_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Sport)LbSportCourses.SelectedItem).Semester[3] = Convert.ToInt32(NudAmountCoursesSem4.Value);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
private void BtnAlternativeCourseAdd_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
//((Sport)LbSportCourses.SelectedItem).AlternativeNames.Add(TbSportAlternativeName.Text);
|
||||
//TbSportAlternativeCourse.Text = "";
|
||||
} catch {}
|
||||
}
|
||||
|
||||
private void BtnAlternativeNameAdd_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Sport)LbSportCourses.SelectedItem).AlternativeNames.Add(TbSportAlternativeName.Text);
|
||||
LbAlternativeNames.Items.Add(TbSportAlternativeName.Text);
|
||||
TbSportAlternativeName.Text = "";
|
||||
|
||||
int curr_selected = LbSportCourses.SelectedIndex;
|
||||
RefreshCoursesList();
|
||||
LbSportCourses.SelectedIndex = curr_selected;
|
||||
} catch {}
|
||||
}
|
||||
|
||||
private void BtnAlternativeNameRemove_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
//try
|
||||
//{
|
||||
LbAlternativeNames.Items.Remove(LbAlternativeNames.SelectedItem);
|
||||
((Sport)LbSportCourses.SelectedItem).AlternativeNames.Clear();
|
||||
foreach (string s in LbAlternativeNames.Items)
|
||||
{
|
||||
((Sport)LbSportCourses.SelectedItem).AlternativeNames.Add(s);
|
||||
}
|
||||
|
||||
int curr_selected = LbSportCourses.SelectedIndex;
|
||||
RefreshCoursesList();
|
||||
LbSportCourses.SelectedIndex = curr_selected;
|
||||
//} catch (Exception ex) {}
|
||||
}
|
||||
|
||||
private async void BtnClearCourseList_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var result = await MessageBox.Show(this,
|
||||
"Möchten Sie wirklich alle Kurse löschen?\n Dies kann nicht rückgängig gemacht werden.",
|
||||
"Wirklich fortfahren?", MessageBoxButton.YesNo);
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
Settings.Instance.Sports.Clear();
|
||||
RefreshCoursesList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void BtnDeleteSinleCourse_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Settings.Instance.Sports.Remove(LbSportCourses.SelectedItem as Sport);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
private async void MnuImpResult_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
// Hier importieren
|
||||
var topLevel = GetTopLevel(this);
|
||||
var file = await topLevel!.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
Title = "CSV-Datei laden",
|
||||
SuggestedFileType = new FilePickerFileType(".csv-Datei")
|
||||
{
|
||||
Patterns = new[] { "*.csv" }
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (file == null) return;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" SizeToContent="WidthAndHeight"
|
||||
x:Class="spplus.MessageBox"
|
||||
x:Class="spplus.MessageBox" WindowStartupLocation="CenterScreen"
|
||||
Title="MessageBox">
|
||||
<StackPanel>
|
||||
<TextBlock Name="Text" Margin="10" TextWrapping="Wrap" />
|
||||
|
||||
@@ -1,3 +1,27 @@
|
||||
# spplus
|
||||
# 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
|
||||
* \+ Statistiken
|
||||
* \+ Pflege von Sportkursen (inkl. Kürzel/ alternativen Bezeichnungen)
|
||||
* \+ CSV-Export
|
||||
* ~ Fehleransicht für nicht-existente, aber gewählte Kurse
|
||||
* ~ PDF-Export
|
||||
|
||||
\+ Vorhanden, ~ Pending
|
||||
|
||||
## Nutzung
|
||||
* Build from source:
|
||||
* Benötigt .NET-SDK 9.0
|
||||
* Im Projektordner: `dotnet run`
|
||||
* Release:
|
||||
* Suche `spplus` bzw. `spplus.exe` und führe aus
|
||||
* Linux/MacOS evl.: `chmod +x spplus`
|
||||
|
||||
|
||||

|
||||
+892
@@ -0,0 +1,892 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace spplus;
|
||||
|
||||
public class CourseCrafter
|
||||
{
|
||||
public class CourseInstance
|
||||
{
|
||||
public Sport Sport = null!;
|
||||
public int Remaining;
|
||||
public List<string> Students = new();
|
||||
}
|
||||
public static List<(int Semester, CourseInstance Instance)> GeneratedCourses
|
||||
= new();
|
||||
|
||||
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, item.Item2);
|
||||
if (semester <= 0) goto semeq0;
|
||||
var inst = new CourseInstance();
|
||||
inst.Sport = item.Item1;
|
||||
inst.Students = new List<string>();
|
||||
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 < getEffectiveMinStudents(inst.Sport, semester))
|
||||
{
|
||||
// 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));
|
||||
}
|
||||
|
||||
semeq0: ;
|
||||
}
|
||||
}
|
||||
|
||||
FillExistingCourses();
|
||||
|
||||
// Kurs umdisponieren (besser verteilen)
|
||||
bool changed;
|
||||
int maxIterations = 20;
|
||||
int iteration = 0;
|
||||
|
||||
do
|
||||
{
|
||||
changed = false;
|
||||
iteration++;
|
||||
|
||||
var sports = GeneratedCourses
|
||||
.GroupBy(c => c.Instance.Sport.Name);
|
||||
|
||||
foreach (var sportGroup in sports)
|
||||
{
|
||||
var courses = sportGroup.ToList();
|
||||
|
||||
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];
|
||||
|
||||
if (cA.Instance.Students.Count <= cB.Instance.Students.Count + 1)
|
||||
continue;
|
||||
|
||||
for (int k = cA.Instance.Students.Count - 1; k >= 0; k--)
|
||||
{
|
||||
string stud = cA.Instance.Students[k];
|
||||
|
||||
if (!isStudentFree(cB.Semester, stud))
|
||||
continue;
|
||||
|
||||
if (cB.Instance.Students.Count >= cB.Instance.Sport.MaxStudents)
|
||||
continue;
|
||||
|
||||
// Quellkurs darf nicht unter effektives Min fallen
|
||||
if (cA.Instance.Students.Count - 1 < getEffectiveMinStudents(cA.Instance.Sport, cA.Semester))
|
||||
continue;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} while (changed && iteration < maxIterations);
|
||||
|
||||
// --- Kurse nachträglich aufteilen, um NumCoursesPerSemester exakt zu erreichen ---
|
||||
for (int semester = 1; semester <= 4; semester++)
|
||||
{
|
||||
int cancel = 0;
|
||||
while (GeneratedCourses.Count(c => c.Semester == semester) < Settings.Instance.NumCoursesPerSemester)
|
||||
{
|
||||
cancel++;
|
||||
if (cancel >= 20) break;
|
||||
|
||||
var candidate = GeneratedCourses
|
||||
.Where(c => c.Semester == semester)
|
||||
.Where(c => c.Instance.Students.Count >= getEffectiveMinStudents(c.Instance.Sport, c.Semester) * 2)
|
||||
.Where(c =>
|
||||
{
|
||||
int sportCount = GeneratedCourses.Count(g =>
|
||||
g.Semester == semester &&
|
||||
g.Instance.Sport.Name == c.Instance.Sport.Name);
|
||||
|
||||
int allowed = c.Instance.Sport.Semester[semester - 1];
|
||||
return sportCount < allowed;
|
||||
})
|
||||
.OrderByDescending(c => c.Instance.Students.Count)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (candidate.Instance == null)
|
||||
break;
|
||||
|
||||
var students = candidate.Instance.Students;
|
||||
int totalStudents = students.Count;
|
||||
int movedCount = totalStudents / 2;
|
||||
int remainingCount = totalStudents - movedCount;
|
||||
|
||||
if (movedCount < getEffectiveMinStudents(candidate.Instance.Sport, candidate.Semester) ||
|
||||
remainingCount < getEffectiveMinStudents(candidate.Instance.Sport, candidate.Semester))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var newCourse = new CourseInstance
|
||||
{
|
||||
Sport = candidate.Instance.Sport,
|
||||
Students = new List<string>()
|
||||
};
|
||||
|
||||
var moved = students
|
||||
.Skip(remainingCount)
|
||||
.Take(movedCount)
|
||||
.ToList();
|
||||
|
||||
foreach (var s in moved)
|
||||
{
|
||||
candidate.Instance.Students.Remove(s);
|
||||
newCourse.Students.Add(s);
|
||||
}
|
||||
|
||||
GeneratedCourses.Add((semester, newCourse));
|
||||
}
|
||||
}
|
||||
|
||||
bool rescueChanged;
|
||||
do
|
||||
{
|
||||
rescueChanged = FillExistingCourses();
|
||||
|
||||
foreach (var item in initial_sportlist)
|
||||
{
|
||||
if (TryCreateRescueCourse(item.Item1, item.Item2))
|
||||
{
|
||||
rescueChanged = true;
|
||||
}
|
||||
}
|
||||
} while (rescueChanged);
|
||||
|
||||
OptimizeStudentWishCoverage();
|
||||
|
||||
// --- Ringtausch: Schüler mit 4 Wünschen aber < 4 Zuteilungen neu zuordnen ---
|
||||
foreach (var student in Settings.Instance.Students)
|
||||
{
|
||||
if (student.SelectedCourseNames.Count < 4)
|
||||
continue;
|
||||
|
||||
var currentAssignments = GetAssignmentsBySemester(student.ID);
|
||||
int currentCount = currentAssignments.Count(a => a != null);
|
||||
|
||||
if (currentCount >= 4)
|
||||
continue;
|
||||
|
||||
// Alle aktuellen Zuteilungen entfernen (temporär)
|
||||
foreach (var assignment in currentAssignments)
|
||||
{
|
||||
if (assignment == null) continue;
|
||||
assignment.Value.Instance.Students.Remove(student.ID);
|
||||
students_in_semester[assignment.Value.Semester - 1].Remove(student.ID);
|
||||
}
|
||||
|
||||
// Alle gewünschten Sports ermitteln
|
||||
var desiredSports = student.SelectedCourseNames
|
||||
.Select(ResolveSportFromSelection)
|
||||
.Where(s => s != null)
|
||||
.DistinctBy(s => s!.Name)
|
||||
.Select(s => s!)
|
||||
.ToList();
|
||||
|
||||
// Kandidatenkurse pro Semester: Kurse mit freiem Platz, die einem Wunschsport entsprechen
|
||||
var candidatesPerSemester = new List<(int Semester, CourseInstance Instance)>[4];
|
||||
for (int si = 0; si < 4; si++)
|
||||
{
|
||||
candidatesPerSemester[si] = GeneratedCourses
|
||||
.Where(c => c.Semester == si + 1)
|
||||
.Where(c => c.Instance.Students.Count < c.Instance.Sport.MaxStudents)
|
||||
.Where(c => desiredSports.Any(ds => ds.Name == c.Instance.Sport.Name))
|
||||
.ToList();
|
||||
candidatesPerSemester[si].Insert(0, default); // default = kein Kurs
|
||||
}
|
||||
|
||||
(int Semester, CourseInstance Instance)?[] bestAssignment = currentAssignments;
|
||||
int bestScore = currentCount;
|
||||
|
||||
int s0 = candidatesPerSemester[0].Count;
|
||||
int s1 = candidatesPerSemester[1].Count;
|
||||
int s2 = candidatesPerSemester[2].Count;
|
||||
int s3 = candidatesPerSemester[3].Count;
|
||||
|
||||
var sportSelectedCounts = student.SelectedCourseNames
|
||||
.Select(ResolveSportFromSelection)
|
||||
.Where(sp => sp != null)
|
||||
.GroupBy(sp => sp!.Name)
|
||||
.ToDictionary(g => g.Key, g => g.Count());
|
||||
|
||||
for (int i0 = 0; i0 < s0; i0++)
|
||||
for (int i1 = 0; i1 < s1; i1++)
|
||||
for (int i2 = 0; i2 < s2; i2++)
|
||||
for (int i3 = 0; i3 < s3; i3++)
|
||||
{
|
||||
var c0 = candidatesPerSemester[0][i0];
|
||||
var c1 = candidatesPerSemester[1][i1];
|
||||
var c2 = candidatesPerSemester[2][i2];
|
||||
var c3 = candidatesPerSemester[3][i3];
|
||||
|
||||
var chosen = new (int Semester, CourseInstance Instance)?[]
|
||||
{
|
||||
c0.Instance != null ? (c0.Semester, c0.Instance) : null,
|
||||
c1.Instance != null ? (c1.Semester, c1.Instance) : null,
|
||||
c2.Instance != null ? (c2.Semester, c2.Instance) : null,
|
||||
c3.Instance != null ? (c3.Semester, c3.Instance) : null
|
||||
};
|
||||
|
||||
bool valid = true;
|
||||
var sportUsageCounts = new Dictionary<string, int>();
|
||||
|
||||
for (int si = 0; si < 4; si++)
|
||||
{
|
||||
if (chosen[si] == null) continue;
|
||||
string sportName = chosen[si]!.Value.Instance.Sport.Name;
|
||||
sportUsageCounts.TryGetValue(sportName, out int used);
|
||||
int allowed = sportSelectedCounts.GetValueOrDefault(sportName, 0);
|
||||
if (used >= allowed) { valid = false; break; }
|
||||
sportUsageCounts[sportName] = used + 1;
|
||||
}
|
||||
|
||||
if (!valid) continue;
|
||||
|
||||
int score = chosen.Count(c => c != null);
|
||||
if (score > bestScore)
|
||||
{
|
||||
bestScore = score;
|
||||
bestAssignment = chosen;
|
||||
}
|
||||
}
|
||||
|
||||
// Beste Zuteilung anwenden
|
||||
foreach (var assignment in bestAssignment)
|
||||
{
|
||||
if (assignment == null) continue;
|
||||
assignment.Value.Instance.Students.Add(student.ID);
|
||||
students_in_semester[assignment.Value.Semester - 1].Add(student.ID);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Lokale Hilfsfunktionen
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
int getEffectiveMinStudents(Sport sport, int semester)
|
||||
{
|
||||
int reduction = (semester >= 3) ? 2 : 0;
|
||||
return Math.Max(1, sport.MinStudents - reduction);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool requestExit()
|
||||
{
|
||||
globalCount++;
|
||||
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;
|
||||
}
|
||||
|
||||
int total_missing = 0;
|
||||
foreach (var tuple in initial_sportlist)
|
||||
{
|
||||
int[] missingPerSemester = new int[4];
|
||||
foreach (var studentId in tuple.Item2.Distinct())
|
||||
{
|
||||
for (int semesterIndex = 0; semesterIndex < 4; semesterIndex++)
|
||||
{
|
||||
if (!students_in_semester[semesterIndex].Contains(studentId))
|
||||
{
|
||||
missingPerSemester[semesterIndex]++;
|
||||
total_missing++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow.Instance.TbResultTextout.Text +=
|
||||
$"{tuple.Item1}: {tuple.Item2.Count} remaining ({missingPerSemester[0]},{missingPerSemester[1]},{missingPerSemester[2]},{missingPerSemester[3]})\n";
|
||||
}
|
||||
MainWindow.Instance.TbResultTextout.Text += $"\n total remaining: {total_missing}";
|
||||
|
||||
bool FillExistingCourses()
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
foreach (var item in initial_sportlist)
|
||||
{
|
||||
if (item.Item2.Count == 0)
|
||||
continue;
|
||||
|
||||
foreach (var ci in GeneratedCourses
|
||||
.Where(ci => ci.Instance.Sport.Name == item.Item1.Name)
|
||||
.OrderBy(ci => ci.Instance.Students.Count))
|
||||
{
|
||||
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))
|
||||
continue;
|
||||
|
||||
ci.Instance.Students.Add(stud);
|
||||
students_in_semester[semester - 1].Add(stud);
|
||||
added.Add(stud);
|
||||
}
|
||||
|
||||
foreach (string s in added)
|
||||
{
|
||||
item.Item2.Remove(s);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool TryCreateRescueCourse(Sport sport, List<string> remainingStudents)
|
||||
{
|
||||
if (remainingStudents.Count == 0)
|
||||
return false;
|
||||
|
||||
for (int semester = 1; semester <= 4; semester++)
|
||||
{
|
||||
int semesterIndex = semester - 1;
|
||||
|
||||
if (sport.Semester[semesterIndex] == 0)
|
||||
continue;
|
||||
|
||||
int sportCoursesInSemester = GeneratedCourses.Count(c =>
|
||||
c.Semester == semester && c.Instance.Sport.Name == sport.Name);
|
||||
if (sportCoursesInSemester >= sport.Semester[semesterIndex])
|
||||
continue;
|
||||
|
||||
if (GeneratedCourses.Count(c => c.Semester == semester) >= Settings.Instance.NumCoursesPerSemester)
|
||||
continue;
|
||||
|
||||
var directlyPlaceable = remainingStudents
|
||||
.Distinct()
|
||||
.Where(studentId => !students_in_semester[semesterIndex].Contains(studentId))
|
||||
.ToList();
|
||||
|
||||
var donorMoves = new List<((int Semester, CourseInstance Instance) Course, string StudentId)>();
|
||||
foreach (var course in GeneratedCourses
|
||||
.Where(c => c.Instance.Sport.Name == sport.Name && c.Semester != semester)
|
||||
.OrderByDescending(c => c.Instance.Students.Count))
|
||||
{
|
||||
int movableCount = course.Instance.Students.Count - getEffectiveMinStudents(sport, course.Semester);
|
||||
if (movableCount <= 0)
|
||||
continue;
|
||||
|
||||
foreach (var studentId in course.Instance.Students.ToList())
|
||||
{
|
||||
if (movableCount <= 0)
|
||||
break;
|
||||
|
||||
if (students_in_semester[semesterIndex].Contains(studentId))
|
||||
continue;
|
||||
|
||||
donorMoves.Add((course, studentId));
|
||||
movableCount--;
|
||||
}
|
||||
}
|
||||
|
||||
if (directlyPlaceable.Count + donorMoves.Count < getEffectiveMinStudents(sport, semester))
|
||||
continue;
|
||||
|
||||
var newCourse = new CourseInstance
|
||||
{
|
||||
Sport = sport,
|
||||
Students = new List<string>()
|
||||
};
|
||||
|
||||
foreach (var studentId in directlyPlaceable)
|
||||
{
|
||||
if (newCourse.Students.Count >= sport.MaxStudents)
|
||||
break;
|
||||
|
||||
newCourse.Students.Add(studentId);
|
||||
}
|
||||
|
||||
foreach (var move in donorMoves)
|
||||
{
|
||||
if (newCourse.Students.Count >= sport.MaxStudents)
|
||||
break;
|
||||
|
||||
if (newCourse.Students.Contains(move.StudentId))
|
||||
continue;
|
||||
|
||||
move.Course.Instance.Students.Remove(move.StudentId);
|
||||
students_in_semester[move.Course.Semester - 1].Remove(move.StudentId);
|
||||
newCourse.Students.Add(move.StudentId);
|
||||
}
|
||||
|
||||
if (newCourse.Students.Count < getEffectiveMinStudents(sport, semester))
|
||||
continue;
|
||||
|
||||
foreach (var studentId in newCourse.Students)
|
||||
{
|
||||
remainingStudents.Remove(studentId);
|
||||
students_in_semester[semesterIndex].Add(studentId);
|
||||
}
|
||||
|
||||
GeneratedCourses.Add((semester, newCourse));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OptimizeStudentWishCoverage()
|
||||
{
|
||||
bool changed;
|
||||
int iterations = 0;
|
||||
|
||||
do
|
||||
{
|
||||
changed = false;
|
||||
iterations++;
|
||||
|
||||
foreach (var student in Settings.Instance.Students)
|
||||
{
|
||||
if (TryImproveStudentCoverage(student))
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
} while (changed && iterations < 20);
|
||||
}
|
||||
|
||||
bool TryImproveStudentCoverage(Student student)
|
||||
{
|
||||
var assignments = GetAssignmentsBySemester(student.ID);
|
||||
if (assignments.All(a => a != null))
|
||||
return false;
|
||||
|
||||
var openSemesters = Enumerable.Range(0, 4)
|
||||
.Where(i => assignments[i] == null)
|
||||
.Select(i => i + 1)
|
||||
.ToList();
|
||||
if (openSemesters.Count == 0)
|
||||
return false;
|
||||
|
||||
var assignedSports = assignments
|
||||
.Where(a => a != null)
|
||||
.Select(a => a!.Value.Instance.Sport.Name)
|
||||
.ToHashSet();
|
||||
|
||||
var preferredSports = student.SelectedCourseNames
|
||||
.Select(ResolveSportFromSelection)
|
||||
.Where(sport => sport != null)
|
||||
.DistinctBy(sport => sport!.Name)
|
||||
.Select(sport => sport!)
|
||||
.Where(sport => !assignedSports.Contains(sport.Name))
|
||||
.ToList();
|
||||
|
||||
foreach (var desiredSport in preferredSports)
|
||||
{
|
||||
for (int sourceSemester = 1; sourceSemester <= 4; sourceSemester++)
|
||||
{
|
||||
var currentCourse = assignments[sourceSemester - 1];
|
||||
if (currentCourse == null)
|
||||
continue;
|
||||
|
||||
var currentCourseValue = currentCourse.Value;
|
||||
|
||||
var desiredCourse = GeneratedCourses
|
||||
.FirstOrDefault(course =>
|
||||
course.Semester == sourceSemester &&
|
||||
course.Instance.Sport.Name == desiredSport.Name &&
|
||||
course.Instance.Students.Count < course.Instance.Sport.MaxStudents);
|
||||
|
||||
if (desiredCourse.Instance == null)
|
||||
continue;
|
||||
|
||||
foreach (var targetSemester in openSemesters)
|
||||
{
|
||||
var relocationTarget = GeneratedCourses
|
||||
.FirstOrDefault(course =>
|
||||
course.Semester == targetSemester &&
|
||||
course.Instance.Sport.Name == currentCourseValue.Instance.Sport.Name &&
|
||||
course.Instance.Students.Count < course.Instance.Sport.MaxStudents);
|
||||
|
||||
if (relocationTarget.Instance == null)
|
||||
continue;
|
||||
|
||||
if (!CanRelocateStudent(student.ID, currentCourseValue, relocationTarget))
|
||||
continue;
|
||||
|
||||
currentCourseValue.Instance.Students.Remove(student.ID);
|
||||
students_in_semester[sourceSemester - 1].Remove(student.ID);
|
||||
|
||||
relocationTarget.Instance.Students.Add(student.ID);
|
||||
students_in_semester[targetSemester - 1].Add(student.ID);
|
||||
|
||||
desiredCourse.Instance.Students.Add(student.ID);
|
||||
students_in_semester[sourceSemester - 1].Add(student.ID);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CanRelocateStudent(
|
||||
string studentId,
|
||||
(int Semester, CourseInstance Instance) sourceCourse,
|
||||
(int Semester, CourseInstance Instance) targetCourse)
|
||||
{
|
||||
if (sourceCourse.Semester == targetCourse.Semester)
|
||||
return false;
|
||||
|
||||
if (sourceCourse.Instance.Students.Count - 1 < getEffectiveMinStudents(sourceCourse.Instance.Sport, sourceCourse.Semester))
|
||||
return false;
|
||||
|
||||
if (targetCourse.Instance.Students.Count >= targetCourse.Instance.Sport.MaxStudents)
|
||||
return false;
|
||||
|
||||
if (!isStudentFree(targetCourse.Semester, studentId))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
(int Semester, CourseInstance Instance)?[] GetAssignmentsBySemester(string studentId)
|
||||
{
|
||||
var assignments = new (int Semester, CourseInstance Instance)?[4];
|
||||
|
||||
foreach (var course in GeneratedCourses)
|
||||
{
|
||||
if (course.Instance.Students.Contains(studentId))
|
||||
{
|
||||
assignments[course.Semester - 1] = course;
|
||||
}
|
||||
}
|
||||
|
||||
return assignments;
|
||||
}
|
||||
|
||||
Sport? ResolveSportFromSelection(string selectedCourseName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(selectedCourseName) ||
|
||||
string.Equals(selectedCourseName, "null", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return Settings.Instance.Sports
|
||||
.FirstOrDefault(sport => sport.AlternativeNames.Contains(selectedCourseName));
|
||||
}
|
||||
|
||||
int getSemesterForSport2(Sport sp, List<string> interestedStudents)
|
||||
{
|
||||
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;
|
||||
|
||||
int sportCoursesInSemester = GeneratedCourses
|
||||
.Count(g => g.Semester == i + 1 && g.Instance.Sport.Name == sp.Name);
|
||||
|
||||
if (sportCoursesInSemester >= sp.Semester[i])
|
||||
continue;
|
||||
|
||||
int freeInterestedStudents = interestedStudents
|
||||
.Distinct()
|
||||
.Count(studentId => !students_in_semester[i].Contains(studentId));
|
||||
|
||||
if (freeInterestedStudents < getEffectiveMinStudents(sp, i + 1))
|
||||
continue;
|
||||
|
||||
if (semcount[i] < Settings.Instance.NumCoursesPerSemester &&
|
||||
semcount[i] < minCourses)
|
||||
{
|
||||
minCourses = semcount[i];
|
||||
bestSem = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return bestSem;
|
||||
}
|
||||
|
||||
int getSemesterForSport(Sport sp, List<string> interestedStudents)
|
||||
{
|
||||
int[] totalCoursesPerSemester = new int[4];
|
||||
foreach (var inst in GeneratedCourses)
|
||||
totalCoursesPerSemester[inst.Semester - 1]++;
|
||||
|
||||
int bestSem = 0;
|
||||
int minCourses = int.MaxValue;
|
||||
int maxFreeInterestedStudents = -1;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (sp.Semester[i] == 0)
|
||||
continue;
|
||||
|
||||
int semesterNumber = i + 1;
|
||||
|
||||
int sportCoursesInThisSemester = GeneratedCourses
|
||||
.Count(g => g.Semester == semesterNumber &&
|
||||
g.Instance.Sport.Name == sp.Name);
|
||||
|
||||
if (sportCoursesInThisSemester >= sp.Semester[i])
|
||||
continue;
|
||||
|
||||
if (totalCoursesPerSemester[i] >= Settings.Instance.NumCoursesPerSemester)
|
||||
continue;
|
||||
|
||||
int freeInterestedStudents = interestedStudents
|
||||
.Distinct()
|
||||
.Count(studentId => !students_in_semester[i].Contains(studentId));
|
||||
|
||||
if (freeInterestedStudents < getEffectiveMinStudents(sp, semesterNumber))
|
||||
continue;
|
||||
|
||||
if (freeInterestedStudents > maxFreeInterestedStudents ||
|
||||
(freeInterestedStudents == maxFreeInterestedStudents &&
|
||||
totalCoursesPerSemester[i] < minCourses))
|
||||
{
|
||||
maxFreeInterestedStudents = freeInterestedStudents;
|
||||
minCourses = totalCoursesPerSemester[i];
|
||||
bestSem = semesterNumber;
|
||||
}
|
||||
}
|
||||
|
||||
return bestSem;
|
||||
}
|
||||
|
||||
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 student in Settings.Instance.Students)
|
||||
{
|
||||
student.Result = new string[4];
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
GeneratedCourses.Sort((x,y) => x.Semester.CompareTo(y.Semester) );
|
||||
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 List<string> ValidateCourses(List<(int Semester, CourseInstance Instance)> courses)
|
||||
{
|
||||
List<string> errors = new();
|
||||
|
||||
// --- 1. Min/Max + Semester erlaubt ---
|
||||
foreach (var tuple in courses)
|
||||
{
|
||||
int semester = tuple.Semester;
|
||||
var inst = tuple.Instance;
|
||||
var sport = inst.Sport;
|
||||
|
||||
if (inst.Students.Count < sport.MinStudents)
|
||||
{
|
||||
errors.Add($"[Min] {sport.Name} (Sem {semester}): {inst.Students.Count} < {sport.MinStudents}");
|
||||
}
|
||||
|
||||
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
@@ -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);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 194 KiB |
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace spplus;
|
||||
|
||||
public static class import
|
||||
{
|
||||
public static List<Student> ImportStudentsFromFile(string path)
|
||||
{
|
||||
var dict = new Dictionary<string, (string Name, List<string> Courses)>();
|
||||
|
||||
foreach (var line in File.ReadLines(path).Skip(1)) // Header überspringen
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line))
|
||||
continue;
|
||||
|
||||
var parts = line.Split(',');
|
||||
if (parts.Length < 3)
|
||||
continue;
|
||||
|
||||
string nameWithId = parts[0].Trim();
|
||||
string course = parts[2].Replace("(2)", "").Replace("(3)", "").Replace("(4)", "").Trim();
|
||||
|
||||
int open = nameWithId.LastIndexOf('(');
|
||||
int close = nameWithId.LastIndexOf(')');
|
||||
if (open < 0 || close < 0 || close <= open)
|
||||
continue;
|
||||
|
||||
string name = nameWithId[..open].Trim();
|
||||
string id = nameWithId[(open + 1)..close].Trim();
|
||||
|
||||
if (!dict.ContainsKey(id))
|
||||
dict[id] = (name, new List<string>());
|
||||
|
||||
dict[id].Courses.Add(course);
|
||||
}
|
||||
|
||||
var result = new List<Student>();
|
||||
|
||||
foreach (var (id, data) in dict)
|
||||
{
|
||||
var student = new Student(id, data.Name, data.Courses);
|
||||
result.Add(student);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<Student> ImportResultFromFile(string path)
|
||||
{
|
||||
var dict = new Dictionary<string, (string Name, List<string> Courses)>();
|
||||
|
||||
foreach (var line in File.ReadLines(path).Skip(1)) // Header überspringen
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line))
|
||||
continue;
|
||||
|
||||
var parts = line.Split(',');
|
||||
if (parts.Length < 3)
|
||||
continue;
|
||||
|
||||
string nameWithId = parts[0].Trim();
|
||||
string course = parts[2].Replace("(2)", "").Replace("(3)", "").Replace("(4)", "").Trim();
|
||||
|
||||
int open = nameWithId.LastIndexOf('(');
|
||||
int close = nameWithId.LastIndexOf(')');
|
||||
if (open < 0 || close < 0 || close <= open)
|
||||
continue;
|
||||
|
||||
string name = nameWithId[..open].Trim();
|
||||
string id = nameWithId[(open + 1)..close].Trim();
|
||||
|
||||
if (!dict.ContainsKey(id))
|
||||
dict[id] = (name, new List<string>());
|
||||
|
||||
dict[id].Courses.Add(course);
|
||||
}
|
||||
|
||||
var result = new List<Student>();
|
||||
|
||||
foreach (var (id, data) in dict)
|
||||
{
|
||||
var student = new Student(id, data.Name, data.Courses);
|
||||
result.Add(student);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 67 KiB |
+76
-14
@@ -1,50 +1,81 @@
|
||||
using System.Collections.Generic;
|
||||
using Avalonia.Data;
|
||||
|
||||
namespace spplus;
|
||||
|
||||
public abstract class Sport
|
||||
public class Sport
|
||||
{
|
||||
public int ID { get; set; } = 0;
|
||||
public string Name { get; set; } = "Neuer Kurs"; // Kursname
|
||||
public int MaxCoursesPerSemester { get; set; } = 1; // Maximale Anzahl an Kursen pro Semester
|
||||
public int MaxStudents { get; set; } = 20; // Maximale Anzahl an Schülern pro Kurs
|
||||
|
||||
public int MaxStudents { get; set; } = 25; // Maximale Anzahl an Schülern pro Kurs
|
||||
public int MinStudents { get; set; } = 5; // Minimale Anzahl an Schülern pro Kurs
|
||||
public int[] Semester { get; set; } = [1, 2, 3, 4]; // Angebot in diesen Semestern
|
||||
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();
|
||||
|
||||
protected Sport()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected Sport(string name)
|
||||
public Sport(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
protected Sport(string name, int maxCoursesPerSemester, int maxStudents, int minStudents, int[] semester)
|
||||
public Sport(string name, int maxCoursesPerSemester, int maxStudents, int minStudents, int[] semester, List<string> alternativeNames)
|
||||
{
|
||||
Name = name;
|
||||
MaxCoursesPerSemester = maxCoursesPerSemester;
|
||||
MaxStudents = maxStudents;
|
||||
MinStudents = minStudents;
|
||||
Semester = semester;
|
||||
AlternativeNames = alternativeNames;
|
||||
}
|
||||
|
||||
// public void AddAlternativeSport(int id)
|
||||
// {
|
||||
// AlternativeCourses.Add(id);
|
||||
// }
|
||||
//
|
||||
// public void ClearAlternativeSport()
|
||||
// {
|
||||
// AlternativeCourses.Clear();
|
||||
// }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var alt = "";
|
||||
foreach (var s in AlternativeNames)
|
||||
{
|
||||
alt += s + ", ";
|
||||
}
|
||||
return $"{Name} ({alt})";
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class Student
|
||||
public class Student
|
||||
{
|
||||
public string Name { get; set; } = ""; // Name des Schülers
|
||||
public Sport[] SelectedCourses { get; set; } = new Sport[4]; // Kurswahl
|
||||
public List<string>? Result { get; set; } = null;
|
||||
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 string[] Result { get; set; } = new string[4];
|
||||
|
||||
protected Student()
|
||||
public Student()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected Student(string name, Sport[] selectedCourses)
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Name} ({ID})";
|
||||
}
|
||||
|
||||
public Student(string id, string name, List<string> selectedCoursesNames)
|
||||
{
|
||||
ID = id;
|
||||
Name = name;
|
||||
SelectedCourses = selectedCourses;
|
||||
SelectedCourseNames = selectedCoursesNames;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +85,7 @@ public class Settings
|
||||
|
||||
public List<Student> Students { get; set; } = [];
|
||||
public List<Sport> Sports { get; set; } = [];
|
||||
public int NumCoursesPerSemester { get; set; } = 10; // Exact Amount of courses, not a maximum
|
||||
|
||||
public Settings()
|
||||
{
|
||||
@@ -64,4 +96,34 @@ public class Settings
|
||||
{
|
||||
// Hier importieren...
|
||||
}
|
||||
|
||||
public static void ImportInitial()
|
||||
{
|
||||
Instance.Sports.Add(new Sport("Tischtennis"){ AlternativeNames = {"Sport_TT"}});
|
||||
Instance.Sports.Add(new Sport("Badminton"){ AlternativeNames = {"Sport_BM"}});
|
||||
Instance.Sports.Add(new Sport("Gymnastik/Tanz"){ AlternativeNames = {"Sport_Gym"}});
|
||||
Instance.Sports.Add(new Sport("Schwimmen"){ AlternativeNames = {"Sport_SW"}, Semester = [1, 1, 1, 1], MaxStudents = 18});
|
||||
Instance.Sports.Add(new Sport("Bouldern"){ AlternativeNames = {"Sport_BO"}, Semester = [1, 1, 1, 1]});
|
||||
Instance.Sports.Add(new Sport("Basketball"){ AlternativeNames = {"Sport_BS"}});
|
||||
Instance.Sports.Add(new Sport("Fitness"){ AlternativeNames = {"Sport_Fit"}});
|
||||
Instance.Sports.Add(new Sport("Fußball"){ AlternativeNames = {"Sport_Fuß"}, Semester = [1, 0, 1, 0]});
|
||||
Instance.Sports.Add(new Sport("Handball"){ AlternativeNames = {"Sport_HB"}});
|
||||
Instance.Sports.Add(new Sport("Leichtathletik"){ AlternativeNames = {"Sport_LA"}, Semester = [1, 0, 1, 0], MaxStudents = 18});
|
||||
Instance.Sports.Add(new Sport("Tennis"){ AlternativeNames = {"Sport_Te"}});
|
||||
Instance.Sports.Add(new Sport("Turnen"){ AlternativeNames = {"Sport_Tur"}});
|
||||
Instance.Sports.Add(new Sport("Volleyball"){ AlternativeNames = {"Sport_VB"}});
|
||||
}
|
||||
|
||||
public static string? GetSportNameFromID(int id)
|
||||
{
|
||||
foreach (var s in Instance.Sports)
|
||||
{
|
||||
if (s.ID == id)
|
||||
{
|
||||
return s.Name;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user