From d8c07ebb08166eee30eac561a7fa77aefe53881a Mon Sep 17 00:00:00 2001 From: Userok Date: Wed, 30 Oct 2024 10:17:34 +0300 Subject: [PATCH] --- Zurnal/UI/Info.cs | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/Zurnal/UI/Info.cs b/Zurnal/UI/Info.cs index abbd59b..7e5e46f 100644 --- a/Zurnal/UI/Info.cs +++ b/Zurnal/UI/Info.cs @@ -1,17 +1,21 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text.RegularExpressions; using Zurnal.RemaDateBase.DateDao; public class GroupAttendanceService { private List attendances; - public void DisplayGroupInfo() + public GroupAttendanceService(List records) + { + attendances = records; + } + + public void DisplayGroupInfo(Guid userGuid, object GroupName, IEnumerable users) { Console.WriteLine($"Группа: {GroupName}"); - Console.WriteLine($"Количество студентов: {Count()}"); + Console.WriteLine($"Количество студентов: {users.Count()}"); var totalClasses = new AttendanceCounter(attendances).CountAttendances(userGuid); Console.WriteLine($"Количество проведенных занятий: {totalClasses}"); @@ -20,7 +24,7 @@ public class GroupAttendanceService Console.WriteLine($"Общий процент посещаемости: {overallAttendancePercentage:F2}%"); Console.WriteLine("Список студентов:"); - foreach (var user in Group.Users) + foreach (var user in users) { var attendanceInfo = GetAttendanceInfo(user); Console.WriteLine($"{user.FIO}: Посещенные занятия: {attendanceInfo.AttendedClasses}, Пропущенные занятия: {attendanceInfo.MissedClasses}, Процент посещаемости: {attendanceInfo.AttendancePercentage:F2}%"); @@ -40,11 +44,6 @@ public class GroupAttendanceService { return _attendances.Count(a => a.UserGuid == userGuid && a.IsAttendensy); } - - internal object CountAttendances(object userGuid) - { - throw new NotImplementedException(); - } } public static double CalculateAttendancePercentage(List attendanceRecords, Guid userGuid) @@ -60,21 +59,22 @@ public class GroupAttendanceService private (int AttendedClasses, int MissedClasses, double AttendancePercentage) GetAttendanceInfo(UserDao user) { - private List attendanceRecords; + 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; - public AttendanceService(List records) - { - attendanceRecords = records; + return (attendedClasses, missedClasses, attendancePercentage); } public List GetAttendanceByUser(Guid userGuid) { - return attendanceRecords.Where(record => record.UserGuid == userGuid).ToList(); + return attendances.Where(record => record.UserGuid == userGuid).ToList(); } public Dictionary GetAttendanceSummary(Guid userGuid) { - var userAttendance = attendanceRecords.Where(record => record.UserGuid == userGuid); + var userAttendance = attendances.Where(record => record.UserGuid == userGuid); var summary = new Dictionary(); foreach (var record in userAttendance) @@ -91,5 +91,4 @@ public class GroupAttendanceService return summary; } - } -} \ No newline at end of file +}