This commit is contained in:
Userok 2024-10-30 10:17:34 +03:00
parent fffc809c12
commit d8c07ebb08

View File

@ -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<PresnceDao> attendances;
public void DisplayGroupInfo()
public GroupAttendanceService(List<PresnceDao> records)
{
attendances = records;
}
public void DisplayGroupInfo(Guid userGuid, object GroupName, IEnumerable<UserDao> 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<PresnceDao> attendanceRecords, Guid userGuid)
@ -60,21 +59,22 @@ public class GroupAttendanceService
private (int AttendedClasses, int MissedClasses, double AttendancePercentage) GetAttendanceInfo(UserDao user)
{
private List<PresnceDao> 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<PresnceDao> records)
{
attendanceRecords = records;
return (attendedClasses, missedClasses, attendancePercentage);
}
public List<PresnceDao> GetAttendanceByUser(Guid userGuid)
{
return attendanceRecords.Where(record => record.UserGuid == userGuid).ToList();
return attendances.Where(record => record.UserGuid == userGuid).ToList();
}
public Dictionary<DateOnly, int> GetAttendanceSummary(Guid userGuid)
{
var userAttendance = attendanceRecords.Where(record => record.UserGuid == userGuid);
var userAttendance = attendances.Where(record => record.UserGuid == userGuid);
var summary = new Dictionary<DateOnly, int>();
foreach (var record in userAttendance)
@ -92,4 +92,3 @@ public class GroupAttendanceService
return summary;
}
}
}