Compare commits
23 Commits
d70770e2f0
...
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 |
@@ -4,7 +4,7 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="spplus.MainWindow" WindowState="Maximized"
|
x:Class="spplus.MainWindow" WindowState="Maximized"
|
||||||
Title="SP+">
|
Title="spplus">
|
||||||
<Border>
|
<Border>
|
||||||
<Grid RowDefinitions="30,*">
|
<Grid RowDefinitions="30,*">
|
||||||
<Menu Background="#50888888">
|
<Menu Background="#50888888">
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
<MenuItem Header="Über" x:Name="MnuAbout" Click="MnuAbout_OnClick" />
|
<MenuItem Header="Über" x:Name="MnuAbout" Click="MnuAbout_OnClick" />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
</Menu>
|
</Menu>
|
||||||
<TabControl x:Name="TclMainView" Grid.Row="1">
|
<TabControl x:Name="TclMainView" Grid.Row="1" TabStripPlacement="Left">
|
||||||
<TabItem>
|
<TabItem>
|
||||||
<TabItem.Header>
|
<TabItem.Header>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
@@ -88,6 +88,11 @@
|
|||||||
<Label Content="Anzahl gewählte Kurse"></Label>
|
<Label Content="Anzahl gewählte Kurse"></Label>
|
||||||
<Label Grid.Column="1" x:Name="LblSelectedAmount"></Label>
|
<Label Grid.Column="1" x:Name="LblSelectedAmount"></Label>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
<Grid ColumnDefinitions="*,3*">
|
||||||
|
<Label Content="Wahlzahlen"></Label>
|
||||||
|
<Label Grid.Column="1" x:Name="LblNumVoted"></Label>
|
||||||
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
|
||||||
@@ -171,23 +176,28 @@
|
|||||||
<StackPanel Grid.Column="1" Orientation="Vertical">
|
<StackPanel Grid.Column="1" Orientation="Vertical">
|
||||||
<Grid ColumnDefinitions="*,50,50">
|
<Grid ColumnDefinitions="*,50,50">
|
||||||
<TextBox Grid.Column="0" Height="35" HorizontalAlignment="Stretch" x:Name="TbSportAlternativeName"></TextBox>
|
<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">
|
<StackPanel Orientation="Horizontal">
|
||||||
<LucideIcon Kind="Plus" Width="24" Height="24" />
|
<LucideIcon Kind="Plus" Width="24" Height="24" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Button>
|
</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">
|
<StackPanel Orientation="Horizontal">
|
||||||
<LucideIcon Kind="Minus" Width="24" Height="24" />
|
<LucideIcon Kind="Minus" Width="24" Height="24" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
<ListBox x:Name="LbAlternativeNames">
|
<ListBox Margin="0,5,0,0" x:Name="LbAlternativeNames">
|
||||||
|
|
||||||
</ListBox>
|
</ListBox>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
</Grid>
|
</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>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
@@ -200,21 +210,30 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</TabItem.Header>
|
</TabItem.Header>
|
||||||
<Grid ColumnDefinitions="*,*" RowDefinitions="50,2*,*">
|
<Grid ColumnDefinitions="*,*" RowDefinitions="50,2*,*">
|
||||||
<ListBox Grid.RowSpan="2" x:Name="LbResult" Margin="10,10,10,10"></ListBox>
|
<ListBox Grid.RowSpan="2" x:Name="LbResult" Margin="0,10,10,10"></ListBox>
|
||||||
<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">
|
<Grid Grid.Row="0" Grid.Column="1" Grid.ColumnDefinitions="*,*">
|
||||||
<StackPanel Orientation="Horizontal">
|
<Button Grid.Column="0" Margin="0,10,0,0" x:Name="BtnExportCoursePDF" VerticalAlignment="Top" Height="35" HorizontalAlignment="Stretch" Click="BtnExportCoursePDF_OnClick" HorizontalContentAlignment="Center">
|
||||||
<LucideIcon Kind="FileText" Width="24" Height="24" />
|
<StackPanel Orientation="Horizontal">
|
||||||
<Label Content="Export (PDF)..." VerticalContentAlignment="Center" FontSize="12"
|
<LucideIcon Kind="FileText" Width="24" Height="24" />
|
||||||
FontWeight="Bold" />
|
<Label Content="Export (PDF)..." VerticalContentAlignment="Center" FontSize="12"
|
||||||
</StackPanel>
|
FontWeight="Bold" />
|
||||||
</Button>
|
</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">
|
<ScrollViewer Grid.Row="1" Grid.Column="1" Margin="0,5,0,10" Background="#44CCCCCC">
|
||||||
<TextBlock x:Name="TbResultStatistics"></TextBlock>
|
<TextBlock x:Name="TbResultStatistics"></TextBlock>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
<ScrollViewer Grid.Row="2" Grid.Column="1" Margin="0" Background="#44CCCCCC">
|
<ScrollViewer Grid.Row="2" Grid.Column="1" Margin="0,0,0,10" Background="#44CCCCCC">
|
||||||
<TextBlock x:Name="TbResultTextout" FontFamily="Consolas"></TextBlock>
|
<TextBlock x:Name="TbResultTextout" FontFamily="Consolas"></TextBlock>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
<ScrollViewer Grid.Row="2" Grid.Column="0" Margin="0" Background="#44CCCCCC">
|
<ScrollViewer Grid.Row="2" Grid.Column="0" Margin="0,0,10,10" Background="#44CCCCCC">
|
||||||
<TextBlock x:Name="TbResultLog" FontFamily="Consolas"></TextBlock>
|
<TextBlock x:Name="TbResultLog" FontFamily="Consolas"></TextBlock>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -1,386 +1,445 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
|
|
||||||
namespace spplus;
|
namespace spplus;
|
||||||
|
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
public static MainWindow Instance { get; set; }
|
public static MainWindow Instance { get; set; }
|
||||||
public MainWindow()
|
public static string ApplicationVersion = "v1.2.24";
|
||||||
{
|
public MainWindow()
|
||||||
InitializeComponent();
|
{
|
||||||
Settings.ImportInitial();
|
InitializeComponent();
|
||||||
Instance = this;
|
Settings.ImportInitial();
|
||||||
}
|
Instance = this;
|
||||||
|
RefreshCoursesList();
|
||||||
private void MnuExpSettings_OnClick(object? sender, RoutedEventArgs e)
|
try
|
||||||
{
|
{
|
||||||
var res = MessageBox.Show(this, "Dieses Feature ist noch nicht implementiert", "Fehlend");
|
NudSportMaxPerSemester.Value = Settings.Instance.NumCoursesPerSemester;
|
||||||
}
|
} catch {}
|
||||||
|
}
|
||||||
private void MnuExit_OnClick(object? sender, RoutedEventArgs e)
|
|
||||||
{
|
private void MnuExpSettings_OnClick(object? sender, RoutedEventArgs e)
|
||||||
Environment.Exit(0);
|
{
|
||||||
}
|
var res = MessageBox.Show(this, "Dieses Feature ist noch nicht implementiert", "Fehlend");
|
||||||
|
}
|
||||||
private void MnuHelp_OnClick(object? sender, RoutedEventArgs e)
|
|
||||||
{
|
private void MnuExit_OnClick(object? sender, RoutedEventArgs e)
|
||||||
try
|
{
|
||||||
{
|
Environment.Exit(0);
|
||||||
Process.Start(new ProcessStartInfo
|
}
|
||||||
{
|
|
||||||
FileName = "https://git.mypapercloud.de/fierke/spplus/wiki",
|
private void MnuHelp_OnClick(object? sender, RoutedEventArgs e)
|
||||||
UseShellExecute = true // Wichtig für Plattformübergreifendes Öffnen
|
{
|
||||||
});
|
try
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
Process.Start(new ProcessStartInfo
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}");
|
FileName = "https://git.mypapercloud.de/fierke/spplus/wiki",
|
||||||
}
|
UseShellExecute = true
|
||||||
}
|
});
|
||||||
|
}
|
||||||
private void MnuGit_OnClick(object? sender, RoutedEventArgs e)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
try
|
Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}");
|
||||||
{
|
}
|
||||||
Process.Start(new ProcessStartInfo
|
}
|
||||||
{
|
|
||||||
FileName = "https://git.mypapercloud.de/fierke/spplus",
|
private void MnuGit_OnClick(object? sender, RoutedEventArgs e)
|
||||||
UseShellExecute = true // Wichtig für Plattformübergreifendes Öffnen
|
{
|
||||||
});
|
try
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
Process.Start(new ProcessStartInfo
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}");
|
FileName = "https://git.mypapercloud.de/fierke/spplus",
|
||||||
}
|
UseShellExecute = true
|
||||||
}
|
});
|
||||||
|
}
|
||||||
private void MnuAbout_OnClick(object? sender, RoutedEventArgs e)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Window w = new();
|
Console.WriteLine($"Fehler beim Öffnen des Links: {ex.Message}");
|
||||||
w.WindowState = WindowState.Normal;
|
}
|
||||||
w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
}
|
||||||
w.Width = 300;
|
|
||||||
w.Height = 120;
|
private void MnuAbout_OnClick(object? sender, RoutedEventArgs e)
|
||||||
Grid g = new();
|
{
|
||||||
TextBlock tb = new()
|
Window w = new();
|
||||||
{
|
w.WindowState = WindowState.Normal;
|
||||||
Text = "spplus v1.0.0\n(c)2026 MyPapertown, Elias Fierke"
|
w.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||||
};
|
w.Width = 300;
|
||||||
g.Children.Add(tb);
|
w.Height = 120;
|
||||||
w.Content = g;
|
Grid g = new();
|
||||||
w.Show();
|
TextBlock tb = new()
|
||||||
}
|
{
|
||||||
|
Text = $"spplus {MainWindow.ApplicationVersion}\n(c)2026 MyPapertown, Elias Fierke"
|
||||||
private async void BtnImport_OnClick(object? sender, RoutedEventArgs e)
|
};
|
||||||
{
|
g.Children.Add(tb);
|
||||||
var topLevel = GetTopLevel(this);
|
w.Content = g;
|
||||||
var file = await topLevel!.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
w.Show();
|
||||||
{
|
}
|
||||||
Title = "CSV-Datei auswählen",
|
|
||||||
AllowMultiple = false,
|
private async void BtnImport_OnClick(object? sender, RoutedEventArgs e)
|
||||||
FileTypeFilter = new[]
|
{
|
||||||
{
|
var topLevel = GetTopLevel(this);
|
||||||
new FilePickerFileType(".csv-Datei")
|
var file = await topLevel!.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||||
{
|
{
|
||||||
Patterns = new[] { "*.csv" }
|
Title = "CSV-Datei auswählen",
|
||||||
}
|
AllowMultiple = false,
|
||||||
}
|
FileTypeFilter = new[]
|
||||||
});
|
{
|
||||||
|
new FilePickerFileType(".csv-Datei")
|
||||||
if (file == null) return;
|
{
|
||||||
if (file.Count == 0) return;
|
Patterns = new[] { "*.csv" }
|
||||||
|
}
|
||||||
var imported_students = import.ImportStudentsFromFile(file[0].Path.LocalPath.ToString());
|
}
|
||||||
foreach (var s in imported_students)
|
});
|
||||||
{
|
|
||||||
Settings.Instance.Students.Add(s);
|
if (file == null) return;
|
||||||
}
|
if (file.Count == 0) return;
|
||||||
RefreshImportedStudentList();
|
|
||||||
|
var imported_students = import.ImportStudentsFromFile(file[0].Path.LocalPath.ToString());
|
||||||
}
|
foreach (var s in imported_students)
|
||||||
|
{
|
||||||
private void RefreshImportedStudentList()
|
Settings.Instance.Students.Add(s);
|
||||||
{
|
}
|
||||||
LbStudentsImported.Items.Clear();
|
RefreshImportedStudentList();
|
||||||
int count_selected = 0;
|
|
||||||
foreach (var s in Settings.Instance.Students)
|
}
|
||||||
{
|
|
||||||
LbStudentsImported.Items.Add(s);
|
private void RefreshImportedStudentList()
|
||||||
count_selected += s.SelectedCourseNames.Count;
|
{
|
||||||
}
|
LbStudentsImported.Items.Clear();
|
||||||
LblStudentAmount.Content = Settings.Instance.Students.Count.ToString();
|
int count_selected = 0;
|
||||||
LblSelectedAmount.Content = count_selected.ToString();
|
foreach (var s in Settings.Instance.Students)
|
||||||
|
{
|
||||||
}
|
LbStudentsImported.Items.Add(s);
|
||||||
|
count_selected += s.SelectedCourseNames.Count;
|
||||||
private void BtnCraftCourses_OnClick(object? sender, RoutedEventArgs e)
|
}
|
||||||
{
|
LblStudentAmount.Content = Settings.Instance.Students.Count.ToString();
|
||||||
// Craft courses here / call course-crafter
|
LblSelectedAmount.Content = count_selected.ToString();
|
||||||
CourseCrafter.Craft();
|
|
||||||
RefreshResultView();
|
List<(Sport, List<string>)> initial_sportlist = new();
|
||||||
TbiResults.Focus();
|
foreach (var sp in Settings.Instance.Sports)
|
||||||
}
|
{
|
||||||
|
initial_sportlist.Add((sp, new()));
|
||||||
private void RefreshResultView()
|
}
|
||||||
{
|
foreach (Student s in Settings.Instance.Students)
|
||||||
LbResult.Items.Clear();
|
{
|
||||||
foreach (Student s in Settings.Instance.Students)
|
foreach (var sp in s.SelectedCourseNames)
|
||||||
{
|
{
|
||||||
try
|
foreach (var item in initial_sportlist)
|
||||||
{
|
{
|
||||||
for(int i = 0; i<s.Result.Count;i++)
|
if (item.Item1.AlternativeNames.Contains(sp))
|
||||||
{
|
{
|
||||||
LbResult.Items.Add($"{s.Name} ({s.ID}) - {i+1}. Semester: {s.Result[i]}");
|
item.Item2.Add(s.ID);
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
}
|
||||||
{
|
}
|
||||||
Console.WriteLine(ex.StackTrace);
|
}
|
||||||
}
|
|
||||||
}
|
LblNumVoted.Content = "";
|
||||||
|
foreach (var s in initial_sportlist)
|
||||||
TbResultStatistics.Text = CourseCrafter.GenerateStatistics();
|
{
|
||||||
}
|
LblNumVoted.Content += $"{s.Item1.Name}: {s.Item2.Count}\n";
|
||||||
|
}
|
||||||
private void LbStudentsImported_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
|
||||||
{
|
}
|
||||||
Prepare();
|
|
||||||
var stud = (Student)LbStudentsImported.SelectedItem;
|
private void BtnCraftCourses_OnClick(object? sender, RoutedEventArgs e)
|
||||||
if (stud == null)
|
{
|
||||||
{
|
CourseCrafter.Craft();
|
||||||
TbStudentName.Text = string.Empty;
|
RefreshResultView();
|
||||||
TbStudentID.Text = string.Empty;
|
TclMainView.SelectedIndex = 2;
|
||||||
SetEmpty();
|
//TbiResults.Focus();
|
||||||
return;
|
}
|
||||||
};
|
|
||||||
|
private void RefreshResultView()
|
||||||
try
|
{
|
||||||
{
|
LbResult.Items.Clear();
|
||||||
TbStudentName.Text = stud.Name;
|
foreach (Student s in Settings.Instance.Students)
|
||||||
TbStudentID.Text = stud.ID;
|
{
|
||||||
LblSport1.Content = stud.SelectedCourseNames[0];
|
try
|
||||||
LblSport2.Content = stud.SelectedCourseNames[1];
|
{
|
||||||
LblSport3.Content = stud.SelectedCourseNames[2];
|
for(int i = 0; i<s.Result.Length;i++)
|
||||||
LblSport4.Content = stud.SelectedCourseNames[3];
|
{
|
||||||
}
|
LbResult.Items.Add($"{s.Name} ({s.ID}) - {i+1}. Semester: {s.Result[i]}");
|
||||||
catch
|
}
|
||||||
{
|
}
|
||||||
SetEmpty();
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
|
Console.WriteLine(ex.StackTrace);
|
||||||
return;
|
}
|
||||||
|
}
|
||||||
void SetEmpty()
|
|
||||||
{
|
TbResultStatistics.Text = CourseCrafter.GenerateStatistics();
|
||||||
if(LblSport1.Content == "null") LblSport1.Content = "ungewählt";
|
}
|
||||||
if(LblSport2.Content == "null") LblSport2.Content = "ungewählt";
|
|
||||||
if(LblSport3.Content == "null") LblSport3.Content = "ungewählt";
|
private void LbStudentsImported_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||||
if(LblSport4.Content == "null") LblSport4.Content = "ungewählt";
|
{
|
||||||
}
|
Prepare();
|
||||||
|
var stud = (Student)LbStudentsImported.SelectedItem;
|
||||||
void Prepare()
|
if (stud == null)
|
||||||
{
|
{
|
||||||
LblSport1.Content = "null";
|
TbStudentName.Text = string.Empty;
|
||||||
LblSport2.Content = "null";
|
TbStudentID.Text = string.Empty;
|
||||||
LblSport3.Content = "null";
|
SetEmpty();
|
||||||
LblSport4.Content = "null";
|
return;
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
try
|
||||||
|
{
|
||||||
private void TbStudentName_OnTextChanged(object? sender, TextChangedEventArgs e)
|
TbStudentName.Text = stud.Name;
|
||||||
{
|
TbStudentID.Text = stud.ID;
|
||||||
try
|
LblSport1.Content = stud.SelectedCourseNames[0];
|
||||||
{
|
LblSport2.Content = stud.SelectedCourseNames[1];
|
||||||
((Student)LbStudentsImported.SelectedItem).Name = TbStudentName.Text;
|
LblSport3.Content = stud.SelectedCourseNames[2];
|
||||||
}
|
LblSport4.Content = stud.SelectedCourseNames[3];
|
||||||
catch
|
}
|
||||||
{
|
catch
|
||||||
|
{
|
||||||
}
|
SetEmpty();
|
||||||
}
|
}
|
||||||
private void TbStudentID_OnTextChanged(object? sender, TextChangedEventArgs e)
|
|
||||||
{
|
return;
|
||||||
try
|
|
||||||
{
|
void SetEmpty()
|
||||||
((Student)LbStudentsImported.SelectedItem).ID = TbStudentID.Text;
|
{
|
||||||
}
|
if(LblSport1.Content == "null") LblSport1.Content = "ungewählt";
|
||||||
catch
|
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()
|
||||||
private void BtnImportDefaultCourses_OnClick(object? sender, RoutedEventArgs e)
|
{
|
||||||
{
|
LblSport1.Content = "null";
|
||||||
Settings.ImportInitial();
|
LblSport2.Content = "null";
|
||||||
RefreshCoursesList();
|
LblSport3.Content = "null";
|
||||||
}
|
LblSport4.Content = "null";
|
||||||
|
}
|
||||||
private void RefreshCoursesList()
|
|
||||||
{
|
}
|
||||||
LbSportCourses.Items.Clear();
|
|
||||||
foreach (var sp in Settings.Instance.Sports)
|
private void TbStudentName_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
LbSportCourses.Items.Add(sp);
|
try
|
||||||
}
|
{
|
||||||
}
|
((Student)LbStudentsImported.SelectedItem).Name = TbStudentName.Text;
|
||||||
|
}
|
||||||
|
catch
|
||||||
private void LbSportCourses_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
{
|
||||||
{
|
|
||||||
if (LbSportCourses.SelectedItem != null)
|
}
|
||||||
{
|
}
|
||||||
if (LbSportCourses.SelectedItem is Sport item)
|
private void TbStudentID_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
LblSportID.Content = item.ID;
|
try
|
||||||
TbSportName.Text = item.Name;
|
{
|
||||||
NudSportMaxStudents.Value = item.MaxStudents;
|
((Student)LbStudentsImported.SelectedItem).ID = TbStudentID.Text;
|
||||||
NudSportMinStudents.Value = item.MinStudents;
|
}
|
||||||
NudAmountCoursesSem1.Value = item.Semester[0];
|
catch
|
||||||
NudAmountCoursesSem2.Value = item.Semester[1];
|
{
|
||||||
NudAmountCoursesSem3.Value = item.Semester[2];
|
|
||||||
NudAmountCoursesSem4.Value = item.Semester[3];
|
}
|
||||||
// LbAlternativeCourses.Items.Clear();
|
}
|
||||||
// foreach (var alternative in item.AlternativeCourses)
|
|
||||||
// {
|
private void BtnImportDefaultCourses_OnClick(object? sender, RoutedEventArgs e)
|
||||||
// LbAlternativeCourses.Items.Add(Settings.GetSportNameFromID(alternative));
|
{
|
||||||
// }
|
Settings.ImportInitial();
|
||||||
LbAlternativeNames.Items.Clear();
|
RefreshCoursesList();
|
||||||
foreach (var alternative in item.AlternativeNames)
|
}
|
||||||
{
|
|
||||||
LbAlternativeNames.Items.Add(alternative);
|
private void RefreshCoursesList()
|
||||||
}
|
{
|
||||||
}
|
LbSportCourses.Items.Clear();
|
||||||
}
|
foreach (var sp in Settings.Instance.Sports)
|
||||||
}
|
{
|
||||||
|
LbSportCourses.Items.Add(sp);
|
||||||
private void TbSportName_OnTextChanged(object? sender, TextChangedEventArgs e)
|
}
|
||||||
{
|
}
|
||||||
try
|
|
||||||
{
|
|
||||||
((Sport)LbSportCourses.SelectedItem).Name = TbSportName.Text;
|
private void LbSportCourses_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||||
} catch {}
|
{
|
||||||
}
|
if (LbSportCourses.SelectedItem != null)
|
||||||
|
{
|
||||||
private void NudSportMaxStudents_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
if (LbSportCourses.SelectedItem is Sport item)
|
||||||
{
|
{
|
||||||
try
|
LblSportID.Content = item.ID;
|
||||||
{
|
TbSportName.Text = item.Name;
|
||||||
((Sport)LbSportCourses.SelectedItem).MaxStudents = Convert.ToInt32(NudSportMaxStudents.Value);
|
NudSportMaxStudents.Value = item.MaxStudents;
|
||||||
} catch {}
|
NudSportMinStudents.Value = item.MinStudents;
|
||||||
}
|
NudAmountCoursesSem1.Value = item.Semester[0];
|
||||||
|
NudAmountCoursesSem2.Value = item.Semester[1];
|
||||||
private void NudSportMinStudents_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
NudAmountCoursesSem3.Value = item.Semester[2];
|
||||||
{
|
NudAmountCoursesSem4.Value = item.Semester[3];
|
||||||
try
|
// LbAlternativeCourses.Items.Clear();
|
||||||
{
|
// foreach (var alternative in item.AlternativeCourses)
|
||||||
((Sport)LbSportCourses.SelectedItem).MinStudents = Convert.ToInt32(NudSportMinStudents.Value);
|
// {
|
||||||
} catch {}
|
// LbAlternativeCourses.Items.Add(Settings.GetSportNameFromID(alternative));
|
||||||
}
|
// }
|
||||||
|
LbAlternativeNames.Items.Clear();
|
||||||
private void NudAmountCoursesSem1_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
foreach (var alternative in item.AlternativeNames)
|
||||||
{
|
{
|
||||||
try
|
LbAlternativeNames.Items.Add(alternative);
|
||||||
{
|
}
|
||||||
((Sport)LbSportCourses.SelectedItem).Semester[0] = Convert.ToInt32(NudAmountCoursesSem1.Value);
|
}
|
||||||
} catch {}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NudAmountCoursesSem2_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
private void TbSportName_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
((Sport)LbSportCourses.SelectedItem).Semester[1] = Convert.ToInt32(NudAmountCoursesSem2.Value);
|
((Sport)LbSportCourses.SelectedItem).Name = TbSportName.Text;
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NudAmountCoursesSem3_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
private void NudSportMaxStudents_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
((Sport)LbSportCourses.SelectedItem).Semester[2] = Convert.ToInt32(NudAmountCoursesSem3.Value);
|
((Sport)LbSportCourses.SelectedItem).MaxStudents = Convert.ToInt32(NudSportMaxStudents.Value);
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NudAmountCoursesSem4_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
private void NudSportMinStudents_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
((Sport)LbSportCourses.SelectedItem).Semester[3] = Convert.ToInt32(NudAmountCoursesSem4.Value);
|
((Sport)LbSportCourses.SelectedItem).MinStudents = Convert.ToInt32(NudSportMinStudents.Value);
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BtnAlternativeCourseAdd_OnClick(object? sender, RoutedEventArgs e)
|
private void NudAmountCoursesSem1_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//((Sport)LbSportCourses.SelectedItem).AlternativeNames.Add(TbSportAlternativeName.Text);
|
((Sport)LbSportCourses.SelectedItem).Semester[0] = Convert.ToInt32(NudAmountCoursesSem1.Value);
|
||||||
//TbSportAlternativeCourse.Text = "";
|
} catch {}
|
||||||
} catch {}
|
}
|
||||||
}
|
|
||||||
|
private void NudAmountCoursesSem2_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
||||||
private void BtnAlternativeNameAdd_OnClick(object? sender, RoutedEventArgs e)
|
{
|
||||||
{
|
try
|
||||||
try
|
{
|
||||||
{
|
((Sport)LbSportCourses.SelectedItem).Semester[1] = Convert.ToInt32(NudAmountCoursesSem2.Value);
|
||||||
((Sport)LbSportCourses.SelectedItem).AlternativeNames.Add(TbSportAlternativeName.Text);
|
} catch {}
|
||||||
LbAlternativeNames.Items.Add(TbSportAlternativeName.Text);
|
}
|
||||||
TbSportAlternativeName.Text = "";
|
|
||||||
|
private void NudAmountCoursesSem3_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
||||||
int curr_selected = LbSportCourses.SelectedIndex;
|
{
|
||||||
RefreshCoursesList();
|
try
|
||||||
LbSportCourses.SelectedIndex = curr_selected;
|
{
|
||||||
} catch {}
|
((Sport)LbSportCourses.SelectedItem).Semester[2] = Convert.ToInt32(NudAmountCoursesSem3.Value);
|
||||||
}
|
} catch {}
|
||||||
|
}
|
||||||
private void BtnAlternativeNameRemove_OnClick(object? sender, RoutedEventArgs e)
|
|
||||||
{
|
private void NudAmountCoursesSem4_OnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
|
||||||
//try
|
{
|
||||||
//{
|
try
|
||||||
LbAlternativeNames.Items.Remove(LbAlternativeNames.SelectedItem);
|
{
|
||||||
((Sport)LbSportCourses.SelectedItem).AlternativeNames.Clear();
|
((Sport)LbSportCourses.SelectedItem).Semester[3] = Convert.ToInt32(NudAmountCoursesSem4.Value);
|
||||||
foreach (string s in LbAlternativeNames.Items)
|
} catch {}
|
||||||
{
|
}
|
||||||
((Sport)LbSportCourses.SelectedItem).AlternativeNames.Add(s);
|
|
||||||
}
|
private void BtnAlternativeCourseAdd_OnClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
int curr_selected = LbSportCourses.SelectedIndex;
|
try
|
||||||
RefreshCoursesList();
|
{
|
||||||
LbSportCourses.SelectedIndex = curr_selected;
|
//((Sport)LbSportCourses.SelectedItem).AlternativeNames.Add(TbSportAlternativeName.Text);
|
||||||
//} catch (Exception ex) {}
|
//TbSportAlternativeCourse.Text = "";
|
||||||
}
|
} catch {}
|
||||||
|
}
|
||||||
private async void BtnClearCourseList_OnClick(object? sender, RoutedEventArgs e)
|
|
||||||
{
|
private void BtnAlternativeNameAdd_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.",
|
try
|
||||||
"Wirklich fortfahren?", MessageBoxButton.YesNo);
|
{
|
||||||
if (result == MessageBoxResult.Yes)
|
((Sport)LbSportCourses.SelectedItem).AlternativeNames.Add(TbSportAlternativeName.Text);
|
||||||
{
|
LbAlternativeNames.Items.Add(TbSportAlternativeName.Text);
|
||||||
Settings.Instance.Sports.Clear();
|
TbSportAlternativeName.Text = "";
|
||||||
RefreshCoursesList();
|
|
||||||
}
|
int curr_selected = LbSportCourses.SelectedIndex;
|
||||||
|
RefreshCoursesList();
|
||||||
}
|
LbSportCourses.SelectedIndex = curr_selected;
|
||||||
|
} catch {}
|
||||||
private void BtnDeleteSinleCourse_OnClick(object? sender, RoutedEventArgs e)
|
}
|
||||||
{
|
|
||||||
try
|
private void BtnAlternativeNameRemove_OnClick(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Settings.Instance.Sports.Remove(LbSportCourses.SelectedItem as Sport);
|
//try
|
||||||
RefreshCoursesList();
|
//{
|
||||||
} catch (Exception ex){}
|
LbAlternativeNames.Items.Remove(LbAlternativeNames.SelectedItem);
|
||||||
}
|
((Sport)LbSportCourses.SelectedItem).AlternativeNames.Clear();
|
||||||
|
foreach (string s in LbAlternativeNames.Items)
|
||||||
private void BtnExportCoursePDF_OnClick(object? sender, RoutedEventArgs e)
|
{
|
||||||
{
|
((Sport)LbSportCourses.SelectedItem).AlternativeNames.Add(s);
|
||||||
// Export as PDF
|
}
|
||||||
}
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
# SP+
|
# 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
|
## Features
|
||||||
* \+ Import von CSV-Dateien mit Kurswahl
|
* \+ Import von CSV-Dateien mit Kurswahl
|
||||||
* \+ Wahlansicht
|
* \+ Wahlansicht
|
||||||
* \+ Statistiken
|
* \+ 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
|
* ~ Fehleransicht für nicht-existente, aber gewählte Kurse
|
||||||
|
* ~ PDF-Export
|
||||||
|
|
||||||
\+ Vorhanden, ~ Pending
|
\+ Vorhanden, ~ Pending
|
||||||
|
|
||||||
|
|||||||
399
crafter.cs
399
crafter.cs
@@ -80,17 +80,13 @@ public class CourseCrafter
|
|||||||
}
|
}
|
||||||
GeneratedCourses.Add((semester, inst));
|
GeneratedCourses.Add((semester, inst));
|
||||||
|
|
||||||
MainWindow.Instance.TbResultLog.Text += ($"{semester} -> {inst.Students.Count}\n");
|
//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");
|
//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: ;
|
semeq0: ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// foreach (var item in initial_sportlist)
|
|
||||||
// {
|
|
||||||
// Console.WriteLine($"{item.Item1.Name}: {item.Item2.Count}x gewählt");
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,32 +120,79 @@ public class CourseCrafter
|
|||||||
item.Item2.Remove(s);
|
item.Item2.Remove(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainWindow.Instance.TbResultLog.Text += ($"{ci.Semester} -> {ci.Instance.Students.Count}\n");
|
//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");
|
//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;
|
||||||
|
|
||||||
int getSemester()
|
do
|
||||||
{
|
{
|
||||||
//int sem = 0;
|
changed = false;
|
||||||
if (GeneratedCourses.Count == 0) return 1; // zunächst im ersten Semester beginnen
|
iteration++;
|
||||||
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
|
// nach Sport gruppieren
|
||||||
|
var sports = GeneratedCourses
|
||||||
|
.GroupBy(c => c.Instance.Sport.ID);
|
||||||
|
|
||||||
|
foreach (var sportGroup in sports)
|
||||||
{
|
{
|
||||||
if (semcount[i] < Settings.Instance.NumCoursesPerSemester)
|
var courses = sportGroup.ToList();
|
||||||
|
|
||||||
|
// paarweise vergleichen
|
||||||
|
for (int i = 0; i < courses.Count; i++)
|
||||||
{
|
{
|
||||||
return i+1; // Semester zurückgeben, wenn genug da sind
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
} while (changed && iteration < maxIterations);
|
||||||
|
|
||||||
|
|
||||||
bool isStudentFree(int semester, string studentID)
|
bool isStudentFree(int semester, string studentID)
|
||||||
{
|
{
|
||||||
@@ -173,17 +216,6 @@ public class CourseCrafter
|
|||||||
// max Kursanzahl
|
// max Kursanzahl
|
||||||
if (GeneratedCourses.Count >= Settings.Instance.NumCoursesPerSemester * 4) return true;
|
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;
|
int low = 0;
|
||||||
foreach (var item in initial_sportlist)
|
foreach (var item in initial_sportlist)
|
||||||
@@ -193,7 +225,7 @@ public class CourseCrafter
|
|||||||
|
|
||||||
if (low >= initial_sportlist.Count) return true;
|
if (low >= initial_sportlist.Count) return true;
|
||||||
|
|
||||||
if (globalCount >= 12) return true;
|
if (globalCount >= 20) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,142 +234,111 @@ public class CourseCrafter
|
|||||||
MainWindow.Instance.TbResultTextout.Text += $"{tuple.Item1}: {tuple.Item2.Count} remaining\n";
|
MainWindow.Instance.TbResultTextout.Text += $"{tuple.Item1}: {tuple.Item2.Count} remaining\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSemesterForSport(Sport sp)
|
// ...existing code...
|
||||||
|
int getSemesterForSport2(Sport sp)
|
||||||
{
|
{
|
||||||
int[] semcount = new int[4] {0,0,0,0};
|
int[] semcount = new int[4];
|
||||||
|
|
||||||
foreach (var inst in GeneratedCourses)
|
foreach (var inst in GeneratedCourses)
|
||||||
{
|
|
||||||
semcount[inst.Semester - 1]++;
|
semcount[inst.Semester - 1]++;
|
||||||
}
|
|
||||||
|
int bestSem = 0;
|
||||||
|
int minCourses = int.MaxValue;
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
// 1. Ist der Sport in diesem Semester erlaubt?
|
|
||||||
if (sp.Semester[i] == 0) continue;
|
if (sp.Semester[i] == 0) continue;
|
||||||
|
|
||||||
// 2. Ist noch Platz für Kurse?
|
// prüfen, ob für diesen Sport im Semester i schon die maximale Anzahl erreicht ist
|
||||||
if (semcount[i] < Settings.Instance.NumCoursesPerSemester)
|
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)
|
||||||
{
|
{
|
||||||
return i + 1;
|
minCourses = semcount[i];
|
||||||
|
bestSem = i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return bestSem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
int getSemesterForSport(Sport sp)
|
||||||
public static void CraftOld()
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
nameMap[sp.Name] = sp;
|
// 1. Zähle alle Kurse pro Semester (egal welche Sportart)
|
||||||
foreach (var alt in sp.AlternativeNames)
|
int[] totalCoursesPerSemester = new int[4];
|
||||||
nameMap[alt] = sp;
|
foreach (var inst in GeneratedCourses)
|
||||||
}
|
totalCoursesPerSemester[inst.Semester - 1]++;
|
||||||
|
|
||||||
// Nachfrage je Sport
|
int bestSem = 0;
|
||||||
var demand = new Dictionary<Sport, List<Student>>();
|
int minCourses = int.MaxValue;
|
||||||
foreach (var sp in sports)
|
|
||||||
demand[sp] = new List<Student>();
|
|
||||||
|
|
||||||
foreach (var st in students)
|
// 2. Kandidaten-Semester durchgehen
|
||||||
{
|
for (int i = 0; i < 4; i++)
|
||||||
foreach (var sel in st.SelectedCourseNames.Distinct())
|
|
||||||
{
|
{
|
||||||
if (nameMap.TryGetValue(sel, out var sp))
|
// a) Sport darf in diesem Semester gar nicht stattfinden?
|
||||||
demand[sp].Add(st);
|
if (sp.Semester[i] == 0)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===== Semesterweise echte Verteilung =====
|
|
||||||
for (int sem = 0; sem < semesterCount; sem++)
|
|
||||||
{
|
|
||||||
int remainingSemesterSlots = settings.NumCoursesPerSemester;
|
|
||||||
|
|
||||||
foreach (var sp in sports)
|
|
||||||
{
|
|
||||||
if (sem >= sp.Semester.Length)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (remainingSemesterSlots <= 0)
|
int semesterNumber = i + 1;
|
||||||
break;
|
|
||||||
|
|
||||||
var interested = demand[sp]
|
// b) Wie viele Kurse DIESES Sports gibt es schon in diesem Semester?
|
||||||
.Where(st =>
|
int sportCoursesInThisSemester = GeneratedCourses
|
||||||
st.Result![sem] == "Fehler" &&
|
.Count(g => g.Semester == semesterNumber &&
|
||||||
!st.Result.Contains(sp.Name))
|
g.Instance.Sport.Name == sp.Name);
|
||||||
.ToList();
|
|
||||||
|
|
||||||
if (interested.Count < sp.MinStudents)
|
// c) Pro-Sport-Limit erreicht?
|
||||||
|
if (sportCoursesInThisSemester >= sp.Semester[i])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int maxInstances = Math.Min(sp.Semester[sem], remainingSemesterSlots);
|
// d) Globales Limit pro Semester erreicht?
|
||||||
int instanceCount = 0;
|
if (totalCoursesPerSemester[i] >= Settings.Instance.NumCoursesPerSemester)
|
||||||
int index = 0;
|
continue;
|
||||||
|
|
||||||
while (interested.Count - index >= sp.MinStudents &&
|
// e) Wähle das Semester mit bisher insgesamt den wenigsten Kursen
|
||||||
instanceCount < maxInstances)
|
if (totalCoursesPerSemester[i] < minCourses)
|
||||||
{
|
{
|
||||||
var inst = new CourseInstance
|
minCourses = totalCoursesPerSemester[i];
|
||||||
{
|
bestSem = semesterNumber;
|
||||||
Sport = sp,
|
}
|
||||||
Remaining = sp.MaxStudents
|
}
|
||||||
};
|
|
||||||
|
|
||||||
GeneratedCourses.Add((sem, inst));
|
return bestSem; // 0, falls kein zulässiges Semester gefunden
|
||||||
remainingSemesterSlots--;
|
}
|
||||||
instanceCount++;
|
|
||||||
|
|
||||||
int filled = 0;
|
var errors = ValidateCourses(GeneratedCourses);
|
||||||
|
|
||||||
while (filled < sp.MaxStudents &&
|
if (errors.Count == 0)
|
||||||
index < interested.Count)
|
{
|
||||||
{
|
MainWindow.Instance.TbResultLog.Text = "--- Alle generierten Kursen erfüllen die gegebenen Voraussetzungen ---";
|
||||||
var st = interested[index++];
|
}
|
||||||
|
else
|
||||||
if (st.Result![sem] != "Fehler")
|
{
|
||||||
continue;
|
MainWindow.Instance.TbResultLog.Text = "--- Bei der Generierung sind folgende Fehler aufgetreten: ---\n\n";
|
||||||
|
foreach (var e in errors)
|
||||||
//inst.Students.Add(st);
|
MainWindow.Instance.TbResultLog.Text += e + "\n";
|
||||||
inst.Remaining--;
|
}
|
||||||
st.Result[sem] = sp.Name;
|
|
||||||
filled++;
|
foreach (var course in GeneratedCourses)
|
||||||
}
|
{
|
||||||
|
foreach (var student in Settings.Instance.Students)
|
||||||
// Falls Mindestanzahl nicht erreicht → Instanz verwerfen
|
{
|
||||||
if (inst.Students.Count < sp.MinStudents)
|
if (course.Instance.Students.Contains(student.ID))
|
||||||
{
|
{
|
||||||
//foreach (var st in inst.Students)
|
student.Result[course.Semester-1] = course.Instance.Sport.Name;
|
||||||
//st.Result[sem] = "Fehler";
|
|
||||||
|
|
||||||
GeneratedCourses.Remove((sem, inst));
|
|
||||||
remainingSemesterSlots++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GenerateStatistics()
|
public static string GenerateStatistics()
|
||||||
{
|
{
|
||||||
|
GeneratedCourses.Sort((x,y) => x.Semester.CompareTo(y.Semester) );
|
||||||
string sb = $"Generierte Kurse: {GeneratedCourses.Count}\n\n";
|
string sb = $"Generierte Kurse: {GeneratedCourses.Count}\n\n";
|
||||||
foreach (var genc in GeneratedCourses)
|
foreach (var genc in GeneratedCourses)
|
||||||
{
|
{
|
||||||
@@ -349,64 +350,106 @@ public class CourseCrafter
|
|||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GenerateStatisticsOld()
|
public static List<string> ValidateCourses(List<(int Semester, CourseInstance Instance)> courses)
|
||||||
{
|
{
|
||||||
var settings = Settings.Instance;
|
List<string> errors = new();
|
||||||
var students = settings.Students;
|
|
||||||
|
|
||||||
if (GeneratedCourses == null || GeneratedCourses.Count == 0)
|
// --- 1. Min/Max + Semester erlaubt ---
|
||||||
return "Keine Kurse generiert.";
|
foreach (var tuple in courses)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
int counter = 1;
|
int semester = tuple.Semester;
|
||||||
|
var inst = tuple.Instance;
|
||||||
|
var sport = inst.Sport;
|
||||||
|
|
||||||
foreach (var entry in group)
|
if (inst.Students.Count < sport.MinStudents)
|
||||||
{
|
{
|
||||||
int semester = group.Key.Semester + 1;
|
errors.Add($"[Min] {sport.Name} (Sem {semester}): {inst.Students.Count} < {sport.MinStudents}");
|
||||||
string sportName = group.Key.Name;
|
}
|
||||||
string number = counter.ToString("D2");
|
|
||||||
int count = entry.Instance.Students.Count;
|
|
||||||
|
|
||||||
sb.AppendLine(
|
if (inst.Students.Count > sport.MaxStudents)
|
||||||
$"Semester {semester}: {sportName} {number}: {count} Schüler*innen"
|
{
|
||||||
);
|
errors.Add($"[Max] {sport.Name} (Sem {semester}): {inst.Students.Count} > {sport.MaxStudents}");
|
||||||
|
}
|
||||||
|
|
||||||
counter++;
|
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})");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.AppendLine();
|
// --- 2. Schüler doppelt im Semester ---
|
||||||
sb.AppendLine("Fehlerübersicht:");
|
for (int sem = 1; sem <= 4; sem++)
|
||||||
|
|
||||||
// ===== Fehler pro Semester =====
|
|
||||||
for (int sem = 0; sem < semesterCount; sem++)
|
|
||||||
{
|
{
|
||||||
int errors = students.Count(st =>
|
List<string> students = new();
|
||||||
st.Result != null &&
|
|
||||||
st.Result.Count > sem &&
|
|
||||||
st.Result[sem] == "Fehler");
|
|
||||||
|
|
||||||
sb.AppendLine($"Semester {sem + 1}: {errors} Fehler");
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.ToString();
|
// --- 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,7 +59,7 @@ public class Student
|
|||||||
public string ID { get; set; } = ""; // ID des Schüler (z.B. NolteSeb)
|
public string ID { get; set; } = ""; // ID des Schüler (z.B. NolteSeb)
|
||||||
public string Name { get; set; } = ""; // Name des Schülers
|
public string Name { get; set; } = ""; // Name des Schülers
|
||||||
public List<string> SelectedCourseNames { get; set; } = new();
|
public List<string> SelectedCourseNames { get; set; } = new();
|
||||||
public List<string>? Result { get; set; } = null;
|
public string[] Result { get; set; } = new string[4];
|
||||||
|
|
||||||
public Student()
|
public Student()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user