2024-12-23 09:12:26 +00:00
|
|
|
|
using System;
|
2024-11-17 16:24:01 +00:00
|
|
|
|
using System.Collections.Generic;
|
2024-12-23 09:12:26 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using presence.domain.UseCase;
|
|
|
|
|
using presence.data.Repository;
|
2024-11-17 16:24:01 +00:00
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
namespace presence.ui
|
2024-11-17 16:24:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
public class PresenceConsoleUI
|
2024-11-17 16:24:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
private readonly PresenceUseCase _presenceUseCase;
|
2024-11-17 16:24:01 +00:00
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
private readonly IPresenceRepository _presenceRepository;
|
|
|
|
|
public PresenceConsoleUI(PresenceUseCase presenceUseCase, IPresenceRepository presenceRepository)
|
2024-11-17 16:24:01 +00:00
|
|
|
|
{
|
|
|
|
|
_presenceUseCase = presenceUseCase;
|
2024-12-05 09:30:01 +00:00
|
|
|
|
_presenceRepository = presenceRepository;
|
2024-11-17 16:24:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
public void GetPresenceByGroup(string groupId)
|
2024-11-17 16:24:01 +00:00
|
|
|
|
{
|
2024-12-05 09:30:01 +00:00
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
int Id;
|
|
|
|
|
bool isParsed = int.TryParse(groupId, out Id);
|
|
|
|
|
if (!isParsed)
|
2024-11-17 16:24:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
Console.WriteLine("Введено не число");
|
2024-11-17 16:24:01 +00:00
|
|
|
|
}
|
2024-12-23 09:12:26 +00:00
|
|
|
|
StringBuilder presenceOutput = new StringBuilder();
|
|
|
|
|
var presence = _presenceUseCase.GetPresenceByGroup(Id);
|
|
|
|
|
foreach (var p in presence)
|
2024-12-05 09:30:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
presenceOutput.AppendLine($"{p.User.Id}\t{p.User.FIO}\t{p.ClassNumber}\t{p.Date}\t{p.IsAttendence}");
|
2024-12-05 09:30:01 +00:00
|
|
|
|
}
|
2024-12-23 09:12:26 +00:00
|
|
|
|
Console.WriteLine(presenceOutput);
|
2024-11-17 16:24:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
public void GetPresenceByGroupAndDate(string groupId, string date)
|
2024-11-17 16:24:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
int Id;
|
|
|
|
|
DateOnly Data;
|
|
|
|
|
bool isParsed = int.TryParse(groupId, out Id);
|
|
|
|
|
bool isParsedData = DateOnly.TryParse(date, out Data);
|
|
|
|
|
if (!isParsed && !isParsedData)
|
2024-11-17 16:24:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
Console.WriteLine("Введено не число в группе ID или введена неправильно дата");
|
2024-11-17 16:24:01 +00:00
|
|
|
|
}
|
2024-12-23 09:12:26 +00:00
|
|
|
|
StringBuilder presenceOutput = new StringBuilder();
|
|
|
|
|
var presence = _presenceUseCase.GetPresenceByGroupAndDate(Id, Data);
|
|
|
|
|
foreach (var p in presence)
|
2024-11-17 16:24:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
presenceOutput.AppendLine($"{p.User.Id}\t{p.User.FIO}\t{p.ClassNumber}\t{p.Date}\t{p.IsAttendence}");
|
2024-12-05 09:30:01 +00:00
|
|
|
|
}
|
2024-12-23 09:12:26 +00:00
|
|
|
|
Console.WriteLine(presenceOutput);
|
2024-11-17 16:24:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
public void UncheckAttendence(string firstClass, string lastClass, string date, string userId)
|
2024-11-17 16:24:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
int fClass;
|
|
|
|
|
int lClass;
|
|
|
|
|
int uId;
|
|
|
|
|
DateOnly Data;
|
|
|
|
|
bool isParsedFClass = int.TryParse(firstClass, out fClass);
|
|
|
|
|
bool isParsedLClass = int.TryParse(lastClass, out lClass);
|
|
|
|
|
bool isParsedUId = int.TryParse(userId, out uId);
|
|
|
|
|
bool isParsedData = DateOnly.TryParse(date, out Data);
|
|
|
|
|
if (!isParsedFClass && !isParsedData && !isParsedLClass && !isParsedUId)
|
2024-11-17 16:24:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
Console.WriteLine("Введен не числа для одних из этих значений: первый урок, последний урок, ID юзера или неправильно введена датаю");
|
2024-11-17 16:24:01 +00:00
|
|
|
|
}
|
2024-12-23 09:12:26 +00:00
|
|
|
|
string output = _presenceUseCase.UncheckAttendence(fClass, lClass, Data, uId) ?
|
|
|
|
|
"Посещаемость обновлена" : "Посещаемость не обновлена";
|
|
|
|
|
Console.WriteLine(output);
|
2024-11-17 16:24:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
public void AddPresence(string firstClass, string lastClass, string groupId, string date)
|
2024-11-17 16:24:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
int fClass;
|
|
|
|
|
int lClass;
|
|
|
|
|
int gId;
|
|
|
|
|
DateOnly data;
|
|
|
|
|
bool isParsedFClass = int.TryParse(firstClass, out fClass);
|
|
|
|
|
bool isParsedLClass = int.TryParse(lastClass, out lClass);
|
|
|
|
|
bool isParsedGId = int.TryParse(groupId, out gId);
|
|
|
|
|
bool isParsedData = DateOnly.TryParse(date, out data);
|
|
|
|
|
if (!isParsedFClass && !isParsedData && !isParsedLClass && !isParsedGId)
|
2024-12-05 09:30:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
Console.WriteLine("Введен не числа для одних из этих значений: первый урок, последний урок, ID группы или неправильно введена датаю");
|
2024-12-05 09:30:01 +00:00
|
|
|
|
}
|
2024-12-23 09:12:26 +00:00
|
|
|
|
_presenceUseCase.AddPresence(fClass, lClass, gId, data);
|
|
|
|
|
Console.WriteLine("Посещаемость добавлена");
|
2024-11-17 16:24:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
public void GetPresenceStatsByGroup(string groupId)
|
2024-11-17 16:24:01 +00:00
|
|
|
|
{
|
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
int Id;
|
|
|
|
|
bool isParsed = int.TryParse(groupId, out Id);
|
|
|
|
|
if (!isParsed)
|
2024-11-17 16:24:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
Console.WriteLine("Введено не число");
|
2024-11-17 16:24:01 +00:00
|
|
|
|
}
|
2024-12-05 09:30:01 +00:00
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
var stats = _presenceUseCase.GetPresenceStatsByGroup(Id);
|
|
|
|
|
StringBuilder output = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
output.AppendLine($"Информация о группе {groupId}:");
|
|
|
|
|
output.AppendLine($"Количество студентов: {stats["Количество студентов"]}");
|
|
|
|
|
output.AppendLine($"Количество занятий: {stats["Количество занятий"]}");
|
|
|
|
|
output.AppendLine($"Общий процент посещаемости: {stats["Процент посещаемости"]}%");
|
|
|
|
|
output.AppendLine("\nСтатистика по студентам:");
|
|
|
|
|
|
|
|
|
|
var presence = _presenceUseCase.GetPresenceByGroup(Id);
|
|
|
|
|
var students = presence.GroupBy(p => p.User)
|
|
|
|
|
.Select(g => new
|
|
|
|
|
{
|
|
|
|
|
Student = g.Key,
|
|
|
|
|
Total = stats["Количество занятий"],
|
|
|
|
|
Attended = g.Count(p => p.IsAttendence),
|
|
|
|
|
Missed = stats["Количество занятий"] - g.Count(p => p.IsAttendence),
|
|
|
|
|
Percentage = (g.Count(p => p.IsAttendence) * 100) / stats["Количество занятий"]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
foreach (var student in students)
|
2024-12-05 09:30:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
output.AppendLine($"\nСтудент: {student.Student.FIO}");
|
|
|
|
|
output.AppendLine($"Посещено занятий: {student.Attended}");
|
|
|
|
|
output.AppendLine($"Пропущено занятий: {student.Missed}");
|
|
|
|
|
output.AppendLine($"Процент посещаемости: {student.Percentage}%");
|
2024-12-05 09:30:01 +00:00
|
|
|
|
}
|
2024-12-23 09:12:26 +00:00
|
|
|
|
|
|
|
|
|
Console.WriteLine(output.ToString());
|
2024-12-05 09:30:01 +00:00
|
|
|
|
}
|
2024-11-17 16:24:01 +00:00
|
|
|
|
|
2024-12-23 09:12:26 +00:00
|
|
|
|
public void GenerateWeeklyPresence(string firstClass, string lastClass, string groupId, string date)
|
|
|
|
|
{
|
|
|
|
|
int fClass;
|
|
|
|
|
int lClass;
|
|
|
|
|
int gId;
|
|
|
|
|
DateOnly data;
|
|
|
|
|
bool isParsedFClass = int.TryParse(firstClass, out fClass);
|
|
|
|
|
bool isParsedLClass = int.TryParse(lastClass, out lClass);
|
|
|
|
|
bool isParsedGId = int.TryParse(groupId, out gId);
|
|
|
|
|
bool isParsedData = DateOnly.TryParse(date, out data);
|
|
|
|
|
if (!isParsedFClass && !isParsedData && !isParsedLClass && !isParsedGId)
|
2024-12-05 09:30:01 +00:00
|
|
|
|
{
|
2024-12-23 09:12:26 +00:00
|
|
|
|
Console.WriteLine("Введен не числа для одних из этих значений: первый урок, последний урок, ID группы или неправильно введена дата");
|
2024-12-05 09:30:01 +00:00
|
|
|
|
}
|
2024-12-23 09:12:26 +00:00
|
|
|
|
_presenceUseCase.GenerateWeeklyPresence(fClass, lClass, gId, data);
|
|
|
|
|
Console.WriteLine("Посещаемость на неделю сгенерирована");
|
2024-12-05 09:30:01 +00:00
|
|
|
|
}
|
2024-11-17 16:24:01 +00:00
|
|
|
|
}
|
2024-12-23 09:12:26 +00:00
|
|
|
|
}
|