Skip to content

Commit

Permalink
[feat] Add report generation for penalty points received in each cour…
Browse files Browse the repository at this point in the history
…se over the past year
  • Loading branch information
anasinik committed May 27, 2024
1 parent e7d5e7f commit ced1a50
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
15 changes: 14 additions & 1 deletion LangLang/BusinessLogic/UseCases/PdfService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public PdfGrid DataToGrid(Dictionary<string, double> data)

public PdfGrid DataToGrid(Dictionary<(Course, int), double> data)
{
PdfGrid grid = new PdfGrid();
PdfGrid grid = new();
grid.Columns.Add(4);
foreach (var item in data)
{
Expand All @@ -67,5 +67,18 @@ public PdfGrid DataToGrid(Dictionary<(Course, int), double> data)
return grid;
}

public PdfGrid DataToGrid(Dictionary<Course, int> data)
{
PdfGrid grid = new();
grid.Columns.Add(2);
foreach (var item in data)
{
PdfGridRow row = grid.Rows.Add();
row.Cells[0].Value = item.Key.Language + " " + item.Key.Level.ToString();
row.Cells[1].Value = item.Value.ToString();
}

return grid;
}
}
}
14 changes: 13 additions & 1 deletion LangLang/BusinessLogic/UseCases/SenderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void SendAveragePenaltyPoints(Director director)
EmailService.SendEmail(director.Profile.Email, reportName, "", document);
}

internal void SentAverageGradeByPenaltyCount(Director director)
internal void SendAverageGradeByPenaltyCount(Director director)
{
var reportService = new ReportService();
var pdfService = new PdfService();
Expand All @@ -89,6 +89,18 @@ internal void SentAverageGradeByPenaltyCount(Director director)
EmailService.SendEmail(director.Profile.Email, reportName, "", document);
}

internal void SendPenaltiesCountLastYear(Director director)
{
var reportService = new ReportService();
var pdfService = new PdfService();

var reportName = "Number of penalties per course in last year.";
var headers = new string[] { "Language", "Num of penalties" };

var document = PdfService.GeneratePdf<Dictionary<Course, int>>(reportService.GetPenaltiesLastYear(), headers, reportName, data => pdfService.DataToGrid(data));
EmailService.SendEmail(director.Profile.Email, reportName, "", document);
}

private string[] GetBodyReplacements(ExamResult result, ExamSlot exam)
{
return new string[] {
Expand Down
11 changes: 8 additions & 3 deletions LangLang/WPF/ViewModels/DirectorViewModels/ReportsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ public void SentAveragePenaltyPoints()
senderService.SendAveragePenaltyPoints(_director);
ShowSuccess();
}
public void SentAverageGradeByPenaltyCount()
public void SendAverageGradeByPenaltyCount()
{
var senderService = new SenderService();
senderService.SentAverageGradeByPenaltyCount(_director);
senderService.SendAverageGradeByPenaltyCount(_director);
ShowSuccess();
}
public void SendPenaltiesCountLastYear()
{
var senderService = new SenderService();
senderService.SendPenaltiesCountLastYear(_director);
ShowSuccess();
}

private void ShowSuccess()
{
MessageBox.Show("Successfully completed!", "Notification", MessageBoxButton.OK, MessageBoxImage.Information);
}

}
}
2 changes: 1 addition & 1 deletion LangLang/WPF/Views/DirectorView/Tabs/Reports.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<Button Grid.Row="0" Content="The number of penalty points received in each course in the past year" BorderBrush="White" Background="#FFFFDBDB" Foreground="#FF817C7C" FontFamily="Segoe UI Black" />
<Button Grid.Row="0" Content="The number of penalty points received in each course in the past year" BorderBrush="White" Background="#FFFFDBDB" Foreground="#FF817C7C" FontFamily="Segoe UI Black" Click="PenaltiesCountLastYear_Click" />
<Button Grid.Row="1" Content="The average grade of students who had n points (0 ≤ n ≤ 3)" BorderBrush="White" Background="#FFFFDBDB" Foreground="#FF817C7C" FontFamily="Segoe UI Black" Click="AverageGradeByPenaltyCount_Click" />
<Button Grid.Row="2" Content="Number of average points per language" BorderBrush="White" Background="#FFFFDBDB" Foreground="#FF817C7C" FontFamily="Segoe UI Black" Click="AveragePoints_Click" />
<Button Grid.Row="3" Content="Number of average penalty points per language" BorderBrush="White" Background="#FFFFDBDB" Foreground="#FF817C7C" FontFamily="Segoe UI Black" Click="AveragePenaltyPoints_Click" />
Expand Down
7 changes: 6 additions & 1 deletion LangLang/WPF/Views/DirectorView/Tabs/Reports.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ private void AveragePenaltyPoints_Click(object sender, System.Windows.RoutedEven

private void AverageGradeByPenaltyCount_Click(object sender, System.Windows.RoutedEventArgs e)
{
_viewModel.SentAverageGradeByPenaltyCount();
_viewModel.SendAverageGradeByPenaltyCount();
}

private void PenaltiesCountLastYear_Click(object sender, System.Windows.RoutedEventArgs e)
{
_viewModel.SendPenaltiesCountLastYear();
}
}
}

0 comments on commit ced1a50

Please sign in to comment.