Raspisanie/Zurnal/UI/Info.cs

95 lines
3.4 KiB
C#
Raw Normal View History

2024-10-28 12:03:35 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
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;
2024-10-30 07:17:34 +00:00
public GroupAttendanceService(List<PresnceDao> records)
{
attendances = records;
}
public void DisplayGroupInfo(Guid userGuid, object GroupName, IEnumerable<UserDao> users)
2024-10-28 08:22:33 +00:00
{
2024-10-28 12:03:35 +00:00
Console.WriteLine($"Группа: {GroupName}");
2024-10-30 07:17:34 +00:00
Console.WriteLine($"Количество студентов: {users.Count()}");
2024-10-28 12:03:35 +00:00
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("Список студентов:");
2024-10-30 07:17:34 +00:00
foreach (var user in users)
2024-10-28 11:03:42 +00:00
{
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
}
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)
{
2024-10-30 07:17:34 +00:00
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;
2024-10-28 11:03:42 +00:00
2024-10-30 07:17:34 +00:00
return (attendedClasses, missedClasses, attendancePercentage);
2024-10-28 11:03:42 +00:00
}
public List<PresnceDao> GetAttendanceByUser(Guid userGuid)
{
2024-10-30 07:17:34 +00:00
return attendances.Where(record => record.UserGuid == userGuid).ToList();
2024-10-28 11:03:42 +00:00
}
public Dictionary<DateOnly, int> GetAttendanceSummary(Guid userGuid)
{
2024-10-30 07:17:34 +00:00
var userAttendance = attendances.Where(record => record.UserGuid == userGuid);
2024-10-28 11:03:42 +00:00
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;
}
2024-10-30 07:17:34 +00:00
}