Raspisanie/Zurnal/UI/Info.cs

95 lines
3.1 KiB
C#
Raw Normal View History

2024-10-28 12:03:35 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
2024-10-28 11:03:42 +00:00
using Zurnal.RemaDateBase.DateDao;
2024-10-28 08:22:33 +00:00
public class GroupAttendanceService
2024-10-28 11:03:42 +00:00
{
private List<PresnceDao> attendances;
public void DisplayGroupInfo()
2024-10-28 08:22:33 +00:00
{
2024-10-28 12:03:35 +00:00
Console.WriteLine($"Группа: {GroupName}");
Console.WriteLine($"Количество студентов: {Count()}");
var totalClasses = new AttendanceCounter(attendances).CountAttendances(userGuid);
2024-10-28 11:03:42 +00:00
Console.WriteLine($"Количество проведенных занятий: {totalClasses}");
2024-10-28 12:03:35 +00:00
var overallAttendancePercentage = CalculateAttendancePercentage(attendances, userGuid);
2024-10-28 11:03:42 +00:00
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}%");
}
}
2024-10-28 12:03:35 +00:00
public class AttendanceCounter
2024-10-28 08:22:33 +00:00
{
2024-10-28 12:03:35 +00:00
private List<PresnceDao> _attendances;
2024-10-28 08:22:33 +00:00
2024-10-28 12:03:35 +00:00
public AttendanceCounter(List<PresnceDao> attendances)
{
_attendances = attendances;
}
public int CountAttendances(Guid userGuid)
{
return _attendances.Count(a => a.UserGuid == userGuid && a.IsAttendensy);
}
2024-10-28 11:03:42 +00:00
internal object CountAttendances(object userGuid)
2024-10-28 08:22:33 +00:00
{
2024-10-28 11:03:42 +00:00
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;
}
2024-10-28 08:22:33 +00:00
2024-10-28 11:03:42 +00:00
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))
2024-10-28 08:22:33 +00:00
{
2024-10-28 11:03:42 +00:00
summary[record.Date]++;
}
else
2024-10-28 08:22:33 +00:00
{
2024-10-28 11:03:42 +00:00
summary[record.Date] = 1;
}
2024-10-28 08:22:33 +00:00
}
2024-10-28 11:03:42 +00:00
return summary;
}
}
}