Raspisanie/Zurnal/UI/Info.cs

52 lines
2.0 KiB
C#
Raw Normal View History

2024-10-28 08:22:33 +00:00
using Zurnal.RemaDateBase.DateDao;
public class GroupAttendanceService
{
public class AttendanceInfo
{
public int TotalStudents { get; set; }
public int TotalLessons { get; set; }
public double AttendancePercentage { get; set; }
public List<StudentAttendance> StudentAttendances { get; set; }
}
public class StudentAttendance
{
public string FIO { get; set; }
public int AttendedLessons { get; set; }
public int MissedLessons { get; set; }
public double AttendanceRate { get; set; }
}
public AttendanceInfo GetGroupAttendanceInfo(GroupDao group, List<PresnceDao> presences)
{
var students = group.Users.ToList();
var totalLessons = presences.Select(p => p.LessonNumber).Distinct().Count();
var totalStudents = students.Count;
var studentAttendances = students.Select(student =>
{
var studentPresences = presences.Where(p => p.userDao.Guid == student.Guid).ToList();
var attendedLessons = studentPresences.Count(p => p.IsAttendensy);
var missedLessons = totalLessons - attendedLessons;
var attendanceRate = totalLessons > 0 ? (double)attendedLessons / totalLessons * 100 : 0;
return new StudentAttendance
{
FIO = student.FIO,
AttendedLessons = attendedLessons,
MissedLessons = missedLessons,
AttendanceRate = attendanceRate
};
}).ToList();
var attendancePercentage = totalStudents > 0 ? (double)studentAttendances.Sum(s => s.AttendedLessons) / (totalStudents * totalLessons) * 100 : 0;
return new AttendanceInfo
{
TotalStudents = totalStudents,
TotalLessons = totalLessons,
AttendancePercentage = attendancePercentage,
StudentAttendances = studentAttendances
};
}
}