| | 1 | | namespace Syki.Shared; |
| | 2 | |
|
| | 3 | | public static class ListExtensions |
| | 4 | | { |
| | 5 | | public static bool IsSubsetOf(this List<Guid> selfs, List<Guid> others) |
| | 6 | | { |
| 504 | 7 | | HashSet<Guid> set = []; |
| 4857 | 8 | | foreach (var self in selfs) |
| | 9 | | { |
| 2031 | 10 | | if (!set.Add(self)) return false; |
| | 11 | |
|
| 2229 | 12 | | if (!others.Contains(self)) return false; |
| | 13 | | } |
| | 14 | |
|
| 297 | 15 | | return true; |
| 207 | 16 | | } |
| | 17 | |
|
| | 18 | | public static List<AgendaDayOut> ToAgendas(this List<EnrollmentClassOut> classes) |
| | 19 | | { |
| 6 | 20 | | var agendas = new List<AgendaDayOut>(); |
| | 21 | |
|
| 38 | 22 | | foreach (var @class in classes) |
| | 23 | | { |
| 58 | 24 | | foreach (var schedule in @class.Schedules) |
| | 25 | | { |
| 16 | 26 | | var discipline = new AgendaDisciplineOut { Name = @class.Discipline, Start = schedule.StartAt, End = sch |
| | 27 | |
|
| 36 | 28 | | var agenda = agendas.FirstOrDefault(a => a.Day == schedule.Day); |
| 16 | 29 | | if (agenda == null) |
| | 30 | | { |
| 12 | 31 | | agenda = new AgendaDayOut { Day = schedule.Day }; |
| 12 | 32 | | agenda.Disciplines.Add(discipline); |
| 12 | 33 | | agendas.Add(agenda); |
| 12 | 34 | | continue; |
| | 35 | | } |
| | 36 | |
|
| 4 | 37 | | agenda.Disciplines.Add(discipline); |
| | 38 | | } |
| | 39 | | } |
| | 40 | |
|
| 18 | 41 | | agendas = agendas.OrderBy(a => a.Day).ToList(); |
| 36 | 42 | | foreach (var agenda in agendas) |
| | 43 | | { |
| 28 | 44 | | agenda.Disciplines = agenda.Disciplines.OrderBy(d => d.Start).ToList(); |
| | 45 | | } |
| | 46 | |
|
| 6 | 47 | | return agendas; |
| | 48 | | } |
| | 49 | |
|
| | 50 | | public static T PickRandom<T>(this IEnumerable<T> source) |
| | 51 | | { |
| 0 | 52 | | return source.PickRandom(1).Single(); |
| | 53 | | } |
| | 54 | |
|
| | 55 | | public static IEnumerable<T> PickRandom<T>(this IEnumerable<T> source, int count) |
| | 56 | | { |
| 6 | 57 | | return source.Shuffle().Take(count); |
| | 58 | | } |
| | 59 | |
|
| | 60 | | public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source) |
| | 61 | | { |
| 135 | 62 | | return source.OrderBy(x => Guid.NewGuid()); |
| | 63 | | } |
| | 64 | | } |