using System; using System.Collections.Generic; using System.Linq; using Zurnal.RemaDateBase.DateDao; public class GroupAttendanceService { private List attendances; public GroupAttendanceService(List records) { attendances = records; } public void DisplayGroupInfo(Guid userGuid, object GroupName, IEnumerable users) { Console.WriteLine($"Группа: {GroupName}"); Console.WriteLine($"Количество студентов: {users.Count()}"); var totalClasses = new AttendanceCounter(attendances).CountAttendances(userGuid); Console.WriteLine($"Количество проведенных занятий: {totalClasses}"); var overallAttendancePercentage = CalculateAttendancePercentage(attendances, userGuid); Console.WriteLine($"Общий процент посещаемости: {overallAttendancePercentage:F2}%"); Console.WriteLine("Список студентов:"); foreach (var user in users) { var attendanceInfo = GetAttendanceInfo(user); Console.WriteLine($"{user.FIO}: Посещенные занятия: {attendanceInfo.AttendedClasses}, Пропущенные занятия: {attendanceInfo.MissedClasses}, Процент посещаемости: {attendanceInfo.AttendancePercentage:F2}%"); } } public class AttendanceCounter { private List _attendances; public AttendanceCounter(List attendances) { _attendances = attendances; } public int CountAttendances(Guid userGuid) { return _attendances.Count(a => a.UserGuid == userGuid && a.IsAttendensy); } } public static double CalculateAttendancePercentage(List attendanceRecords, Guid userGuid) { var userRecords = attendanceRecords.Where(record => record.UserGuid == userGuid).ToList(); if (userRecords.Count == 0) return 0; int totalLessons = userRecords.Count; int attendedLessons = userRecords.Count(record => record.IsAttendensy); return (double)attendedLessons / totalLessons * 100; } private (int AttendedClasses, int MissedClasses, double AttendancePercentage) GetAttendanceInfo(UserDao user) { var attendanceRecords = this.attendances.Where(record => record.UserGuid == user.UserGuid).ToList(); int attendedClasses = attendanceRecords.Count(record => record.IsAttendensy); int missedClasses = attendanceRecords.Count - attendedClasses; double attendancePercentage = attendanceRecords.Count == 0 ? 0 : (double)attendedClasses / attendanceRecords.Count * 100; return (attendedClasses, missedClasses, attendancePercentage); } public List GetAttendanceByUser(Guid userGuid) { return attendances.Where(record => record.UserGuid == userGuid).ToList(); } public Dictionary GetAttendanceSummary(Guid userGuid) { var userAttendance = attendances.Where(record => record.UserGuid == userGuid); var summary = new Dictionary(); foreach (var record in userAttendance) { if (summary.ContainsKey(record.Date)) { summary[record.Date]++; } else { summary[record.Date] = 1; } } return summary; } }