Skip to content

Commit

Permalink
Merge pull request #442 from kzi-nastava/feat/pdf-report
Browse files Browse the repository at this point in the history
Feat/pdf report
  • Loading branch information
natasakasikovic authored May 27, 2024
2 parents 2c3127c + 50d0aee commit a1ebd93
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 13 deletions.
32 changes: 32 additions & 0 deletions LangLang/BusinessLogic/UseCases/PdfService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System;
using System.Collections.Generic;
using LangLang.Domain.Models;

namespace LangLang.BusinessLogic.UseCases
{
Expand Down Expand Up @@ -63,6 +64,7 @@ public PdfGrid DataToGrid(Dictionary<string, List<double>> data)
}
return grid;
}

public PdfGrid DataToGrid(float[] data)
{
PdfGrid grid = new PdfGrid();
Expand All @@ -74,6 +76,7 @@ public PdfGrid DataToGrid(float[] data)
row.Cells[3].Value = data[3].ToString();
return grid;
}

public PdfGrid DataToGrid(Dictionary<string, float[]> data)
{
PdfGrid grid = new PdfGrid();
Expand All @@ -85,9 +88,38 @@ public PdfGrid DataToGrid(Dictionary<string, float[]> data)
row.Cells[1].Value = item.Value[0].ToString();
row.Cells[2].Value = item.Value[1].ToString();
row.Cells[3].Value = item.Value[2].ToString();
}
return grid;
}

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

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;
}

}
}
5 changes: 5 additions & 0 deletions LangLang/BusinessLogic/UseCases/PenaltyPointService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public List<Student> GetStudentsByPenaltyCount(Course course, int penaltyCount)
{
List<Student> students = new();
var studentService = new StudentService();
var courseService = new CourseService();

if (penaltyCount == 0)
return courseService.GetStudentsAttended(course);

foreach (var point in GetByCourse(course))
{
var student = studentService.Get(point.StudentId);
Expand Down
2 changes: 1 addition & 1 deletion LangLang/BusinessLogic/UseCases/ReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Dictionary<Course, int> GetPenaltiesLastYear()

foreach (var course in courseService.GetCoursesHeldInLastYear())
{
for (int i = 0; i < Constants.MAX_PENALTY_POINTS; i++)
for (int i = 0; i <= Constants.MAX_PENALTY_POINTS; i++)
{
var key = (course, i);
averageGrades[key] = GetAverageGrade(course, i);
Expand Down
44 changes: 35 additions & 9 deletions LangLang/BusinessLogic/UseCases/SenderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using LangLang.Domain.Models;
using LangLang.Domain.RepositoryInterfaces;
using LangLang.Utilities;
using System;
using System.Collections.Generic;

namespace LangLang.BusinessLogic.UseCases
Expand Down Expand Up @@ -74,6 +75,20 @@ public void SendCoursesAccomplishments(Director director)

}

public void SendGratitudeMail(Course course, List<Student> students)
{
foreach (var student in students)
{
string subject = GetGratitudeSubject();
string body = GetGratitudeMessage();

subject = Utils.ReplacePlaceholders(subject, GetSubjectReplacements(course));
body = Utils.ReplacePlaceholders(body, GetBodyReplacements(student));

EmailService.SendEmail(student.Profile.Email, subject, body);
}
}

public void SendAveragePoints(Director director)
{
var reportService = new ReportService();
Expand All @@ -97,18 +112,29 @@ public void SendAveragePenaltyPoints(Director director)
var document = PdfService.GeneratePdf<Dictionary<string, double>>(reportService.GetAveragePenaltyPoints(), headers, reportName, data => pdfService.DataToGrid(data));
EmailService.SendEmail(director.Profile.Email, reportName, "", document);
}
public void SendGratitudeMail(Course course, List<Student> students)

internal void SendAverageGradeByPenaltyCount(Director director)
{
foreach (var student in students)
{
string subject = GetGratitudeSubject();
string body = GetGratitudeMessage();
var reportService = new ReportService();
var pdfService = new PdfService();

subject = Utils.ReplacePlaceholders(subject, GetSubjectReplacements(course));
body = Utils.ReplacePlaceholders(body, GetBodyReplacements(student));
var reportName = "Average grade by penalty count";
var headers = new string[] { "Language", "Level", "Num of penalties", "Average grade" };

EmailService.SendEmail(student.Profile.Email, subject, body);
}
var document = PdfService.GeneratePdf<Dictionary<(Course, int), double>>(reportService.GetAverageGradeByPenaltyCount(), headers, reportName, data => pdfService.DataToGrid(data));
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)
Expand Down
14 changes: 13 additions & 1 deletion LangLang/WPF/ViewModels/DirectorViewModels/ReportsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using LangLang.BusinessLogic.UseCases;
using LangLang.Domain.Models;
using System;
using System.Windows;

namespace LangLang.WPF.ViewModels.DirectorViewModels
Expand All @@ -24,6 +25,18 @@ public void SentAveragePenaltyPoints()
senderService.SendAveragePenaltyPoints(_director);
ShowSuccess();
}
public void SendAverageGradeByPenaltyCount()
{
var senderService = new SenderService();
senderService.SendAverageGradeByPenaltyCount(_director);
ShowSuccess();
}
public void SendPenaltiesCountLastYear()
{
var senderService = new SenderService();
senderService.SendPenaltiesCountLastYear(_director);
ShowSuccess();
}

public void SentAverageCourseGrades()
{
Expand All @@ -47,6 +60,5 @@ private void ShowSuccess()
{
MessageBox.Show("Successfully completed!", "Notification", MessageBoxButton.OK, MessageBoxImage.Information);
}

}
}
4 changes: 2 additions & 2 deletions LangLang/WPF/Views/DirectorView/Tabs/Reports.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<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="1" Content="The average grade of students who had n points (0 ≤ n ≤ 3)" 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" />
<Button Grid.Row="4" Content="Number of created courses for each of the existing languages in the system in the last year" BorderBrush="White" Background="#FFFFDBDB" Foreground="#FF817C7C" FontFamily="Segoe UI Black" />
Expand Down
12 changes: 12 additions & 0 deletions LangLang/WPF/Views/DirectorView/Tabs/Reports.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,26 @@ private void AveragePenaltyPoints_Click(object sender, System.Windows.RoutedEven
_viewModel.SentAveragePenaltyPoints();
}

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

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

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

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

private void CoursesAccomplishments_Click(object sender, System.Windows.RoutedEventArgs e)
{
_viewModel.SentCoursesAccomplishments();
Expand Down

0 comments on commit a1ebd93

Please sign in to comment.