-
Notifications
You must be signed in to change notification settings - Fork 0
/
CouplesReport.cs
90 lines (69 loc) · 3.39 KB
/
CouplesReport.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using CheckSaturday.InstituteParsers;
namespace CheckSaturday;
public static class CouplesReport
{
public static string BuildMessage(IEnumerable<ClassInfo> couples, bool needBeActual)
{
if (!couples.Any()) return "Пар не найдено.";
var maxDate = couples.Max(x => x.Date);
StringBuilder sb = new($"Расписание актуально до {maxDate:d}.\n\n");
if (maxDate.Date < DateTime.Now.Date && needBeActual)
{
sb.AppendLine("Кароче, опять не опубликовали вовремя новое расписание.");
return sb.ToString();
}
var (saturdayInfo, weekdaysInfo) = FilterCouples(couples);
sb.AppendLine(!weekdaysInfo.Any()
? "Хз, чё там с парами после 17:00 в рабочие дни. Может есть, может нет. Я не нашёл у ИФМОИОТа.\n"
: "Нашёл пары после 17:00 в рабочие дни:\n");
foreach (var i in weekdaysInfo)
sb.AppendLine(i);
sb.Append(!saturdayInfo.Any()
? "\nПары ИФМОИОТ'а на субботу отсутствуют.\nИнженерка, спи спокойно."
: "Найдены пары ИФМОИОТа в субботу:\n");
foreach (var i in saturdayInfo)
sb.AppendLine(i);
return sb.ToString();
}
private static (List<string> saturdays, List<string> weekdays) FilterCouples(IEnumerable<ClassInfo> Couples)
{
var sortStartTime = new TimeOnly(16, 00);
var weekdaysCouples = Couples.Where(x =>
!x.Day.ToLower().Contains("субб") && ActualAuditNumber(x) &&
GetTimeOfCouple(x.Time) >= sortStartTime).OrderBy(x => x.Date).ThenBy(x => GetTimeOfCouple(x.Time));
var saturdayCouples = Couples.Where(x => x.Day.ToLower().Contains("субб") && ActualAuditNumber(x))
.OrderBy(x => x.Date).ThenBy(x => GetTimeOfCouple(x.Time));
return (FindCouples(saturdayCouples), FindCouples(weekdaysCouples));
}
private static List<string> FindCouples(IEnumerable<ClassInfo> couples)
{
List<string> coupleInfo = new();
if (!couples.Any()) return coupleInfo;
foreach (var i in couples)
coupleInfo.Add(BuildCoupleInfo(i));
return coupleInfo;
}
private static TimeOnly GetTimeOfCouple(string time)
{
string startTime = time.Split('-', StringSplitOptions.RemoveEmptyEntries)[0];
var separatedTime = startTime.Split(".,:;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
int.TryParse(separatedTime[0], out int hours);
int.TryParse(separatedTime[1], out int minutes);
var res = new TimeOnly(hours, minutes);
return res;
}
private static string BuildCoupleInfo(ClassInfo c)
=> $"- - - - -\n{c.Date:d} || {c.Time} || {c.Course}-{c.Group}\n{c.Title}\n";
private static bool ActualAuditNumber(ClassInfo c)
{
var possibleNumbers = new[] { "151", "152", "153", "154", "155", "156", "157", "159" };
var audit = Regex.Match(c.Title, @"\b\d{1,}-{0,1}\d{2,}\w{0,1}$");
if (possibleNumbers.Any(x => x == audit.Value.Trim())) return true;
return false;
}
}