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