Raspisanie/Zurnal/UI/Info.cs
2024-10-28 14:03:42 +03:00

92 lines
3.0 KiB
C#

using System.Text.RegularExpressions;
using Zurnal.RemaDateBase.DateDao;
public class GroupAttendanceService
{
private List<PresnceDao> attendances;
public void DisplayGroupInfo()
{
Console.WriteLine( $"Группа: {GroupName}");
Console.WriteLine( $"Количество студентов: {Count()}");
var totalClasses = new AttendanceCounter(attendances).CountAttendances(UserGuid);
Console.WriteLine($"Количество проведенных занятий: {totalClasses}");
var overallAttendancePercentage = CalculateAttendancePercentage();
Console.WriteLine($"Общий процент посещаемости: {overallAttendancePercentage:F2}%");
Console.WriteLine("Список студентов:");
foreach (var user in Group.Users)
{
var attendanceInfo = GetAttendanceInfo(user);
Console.WriteLine($"{user.FIO}: Посещенные занятия: {attendanceInfo.AttendedClasses}, Пропущенные занятия: {attendanceInfo.MissedClasses}, Процент посещаемости: {attendanceInfo.AttendancePercentage:F2}%");
}
}
public class AttendanceCounter
{
private List<PresnceDao> _attendances;
public AttendanceCounter(List<PresnceDao> attendances)
{
_attendances = attendances;
}
public int CountAttendances(Guid userGuid)
{
return _attendances.Count(a => a.UserGuid == userGuid && a.IsAttendensy);
}
internal object CountAttendances(object userGuid)
{
throw new NotImplementedException();
}
}
public static double CalculateAttendancePercentage(List<PresnceDao> 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)
{
private List<PresnceDao> attendanceRecords;
public AttendanceService(List<PresnceDao> records)
{
attendanceRecords = records;
}
public List<PresnceDao> GetAttendanceByUser(Guid userGuid)
{
return attendanceRecords.Where(record => record.UserGuid == userGuid).ToList();
}
public Dictionary<DateOnly, int> GetAttendanceSummary(Guid userGuid)
{
var userAttendance = attendanceRecords.Where(record => record.UserGuid == userGuid);
var summary = new Dictionary<DateOnly, int>();
foreach (var record in userAttendance)
{
if (summary.ContainsKey(record.Date))
{
summary[record.Date]++;
}
else
{
summary[record.Date] = 1;
}
}
return summary;
}
}
}