< Summary - Syki

Information
Class: Syki.Back.Features.Academic.CreateClass.Class
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Academic/CreateClass/Class.cs
Tag: 21_17346963026
Line coverage
78%
Covered lines: 115
Uncovered lines: 32
Coverable lines: 147
Total lines: 255
Line coverage: 78.2%
Branch coverage
92%
Covered branches: 13
Total branches: 14
Branch coverage: 92.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Id()100%11100%
get_InstitutionId()100%11100%
get_DisciplineId()100%11100%
get_Discipline()100%11100%
get_PeriodId()100%11100%
get_Period()100%11100%
get_Vacancies()100%11100%
get_Status()100%11100%
get_Workload()100%11100%
get_CampusId()100%11100%
get_TeacherId()100%11100%
get_Teacher()100%11100%
get_Schedules()100%11100%
get_Lessons()100%11100%
get_Students()100%11100%
get_Activities()100%11100%
get_Notes()100%11100%
get_FillRatio()100%11100%
.ctor()100%11100%
.ctor(...)100%11100%
New(...)100%11100%
CreateLessons()100%66100%
Start()100%11100%
AddActivity(...)100%22100%
GetNotesRemainingWeights()100%22100%
Finish()100%22100%
GetScheduleAsString()100%11100%
GetWorkloadAsString()100%11100%
GetProgressAsString()100%11100%
SetFillRatio(...)100%11100%
ToOut()50%22100%
ToGetAcademicClassOut()100%11100%
ToTeacherClassOut()100%11100%
ToStudentClassOut(...)100%210%
ToTeacherClassesOut()100%210%
ToTeacherCurrentClassOut()100%210%
ToStudentCurrentClassOut()100%210%

File(s)

/home/runner/work/syki/syki/Back/Features/Academic/CreateClass/Class.cs

#LineLine coverage
 1using Syki.Back.Features.Academic.CreateTeacher;
 2using Syki.Back.Features.Academic.CreateStudent;
 3using Syki.Back.Features.Academic.CreateDiscipline;
 4using Syki.Back.Features.Teacher.CreateClassActivity;
 5using Syki.Back.Features.Teacher.AddClassActivityNote;
 6using Syki.Back.Features.Academic.CreateAcademicPeriod;
 7
 8namespace Syki.Back.Features.Academic.CreateClass;
 9
 10/// <summary>
 11/// Turma
 12/// </summary>
 13public class Class
 14{
 1715015    public Guid Id { get; set; }
 82416    public Guid InstitutionId { get; set; }
 81017    public Guid DisciplineId { get; set; }
 83018    public Discipline Discipline { get; set; }
 231419    public string PeriodId { get; set; }
 9160420    public AcademicPeriod Period { get; set; }
 133421    public int Vacancies { get; set; }
 331822    public ClassStatus Status { get; set; }
 2564623    public int Workload { get; set; }
 24
 69025    public Guid? CampusId { get; set; }
 69826    public Guid? TeacherId { get; set; }
 63627    public SykiTeacher Teacher { get; set; }
 28
 195229    public List<Schedule> Schedules { get; set; }
 1547630    public List<ClassLesson> Lessons { get; set; }
 91431    public List<SykiStudent> Students { get; set; }
 133232    public List<ClassActivity> Activities { get; set; }
 68033    public List<StudentClassNote> Notes { get; set; }
 34
 64435    public string FillRatio { get; set; }
 36
 542837    private Class() {}
 38
 67839    public Class(
 67840        Guid institutionId,
 67841        Guid disciplineId,
 67842        Guid? campusId,
 67843        Guid? teacherId,
 67844        string period,
 67845        int vacancies,
 67846        List<Schedule> schedules
 67847    ) {
 67848        Id = Guid.CreateVersion7();
 67849        InstitutionId = institutionId;
 67850        DisciplineId = disciplineId;
 67851        CampusId = campusId;
 67852        TeacherId = teacherId;
 67853        PeriodId = period;
 67854        Vacancies = vacancies;
 67855        Status = ClassStatus.OnPreEnrollment;
 67856        Schedules = schedules;
 67857        Lessons = [];
 67858        Students = [];
 67859        Activities = [];
 67860        Notes = [];
 67861    }
 62
 63    public static OneOf<Class, SykiError> New(
 64        Guid institutionId,
 65        Guid disciplineId,
 66        Guid? campusId,
 67        Guid? teacherId,
 68        string period,
 69        int vacancies,
 70        List<Schedule> schedules
 71    ) {
 67472        return new Class(institutionId, disciplineId, campusId, teacherId, period, vacancies, schedules);
 73    }
 74
 75    public void CreateLessons()
 76    {
 66077        var schedules = Schedules.OrderBy(x => x.Day).ThenBy(x => x.Start).ToList();
 78
 61279        var number = 1;
 61280        var current = Period.StartAt;
 9097481        while (current < Period.EndAt)
 82        {
 36074083            foreach (var schedule in schedules)
 84            {
 9000885                if (current.DayOfWeek.Is(schedule.Day))
 86                {
 1280887                    Lessons.Add(new(Id, number, current, schedule.Start, schedule.End));
 1280888                    Workload += schedule.GetDiff();
 1280889                    number++;
 90                }
 91            }
 9036292            current = current.AddDays(1);
 93        }
 61294    }
 95
 96    public void Start()
 97    {
 47698        Status = ClassStatus.Started;
 47699    }
 100
 101    public OneOf<SykiSuccess, SykiError> AddActivity(ClassActivity activity)
 102    {
 852103        var sum = Activities.Where(x => x.Note == activity.Note).Sum(x => x.Weight);
 104
 346105        if (sum + activity.Weight > 100) return new InvalidClassActivityWeight();
 106
 266107        Activities.Add(activity);
 108
 266109        return new SykiSuccess();
 110    }
 111
 112    public List<ClassNoteRemainingWeightsOut> GetNotesRemainingWeights()
 113    {
 8114        var weights = new List<ClassNoteRemainingWeightsOut>();
 64115        foreach (var note in Enum.GetValues<ClassNoteType>())
 116        {
 128117            var sum = Activities.Where(x => x.Note == note).Sum(x => x.Weight);
 24118            weights.Add(new() { Note = note, Weight = 100 - sum });
 119        }
 120
 8121        return weights;
 122    }
 123
 124    public OneOf<SykiSuccess, SykiError> Finish()
 125    {
 62126        if (Lessons.Any(x => x.Status != ClassLessonStatus.Finalized))
 4127            return new AllClassLessonsMustHaveFinalizedStatus();
 128
 4129        Status = ClassStatus.Finalized;
 4130        return new SykiSuccess();
 131    }
 132
 133    private string GetScheduleAsString()
 134    {
 42135        return string.Join(" | ", Schedules.OrderBy(h => h.Day).ThenBy(h => h.Start).ToList().ConvertAll(h => h.ToString
 136    }
 137
 138    private string GetWorkloadAsString()
 139    {
 16140        return Workload.MinutesToString();
 141    }
 142
 143    private string GetProgressAsString()
 144    {
 16145        var total = Lessons.Count;
 202146        var finalized = Lessons.Count(x => x.Status == ClassLessonStatus.Finalized);
 16147        return $"{finalized}/{total}";
 148    }
 149
 150    public void SetFillRatio(int count)
 151    {
 24152        FillRatio = $"{count}/{Vacancies}";
 24153    }
 154
 155    // OUTS
 156
 157    public ClassOut ToOut()
 158    {
 13442159        var presences = Lessons.Sum(l => l.Attendances.Count(a => a.Present));
 13442160        var attendances = Lessons.Sum(l => l.Attendances.Count);
 604161        return new()
 604162        {
 604163            Id = Id,
 604164            Discipline = Discipline.Name,
 604165            Teacher = Teacher.Name,
 604166            Period = PeriodId,
 604167            Vacancies = Vacancies,
 604168            Status = Status,
 596169            Schedules = Schedules.ConvertAll(h => h.ToOut()),
 604170            FillRatio = FillRatio,
 604171            Frequency = attendances == 0 ? 0.00M : 100M * (1M * presences / (1M * attendances)),
 25676172            Lessons = Lessons.OrderBy(x => x.Number).Select(x => x.ToOut()).ToList(),
 604173        };
 174    }
 175
 176    public GetAcademicClassOut ToGetAcademicClassOut()
 177    {
 16178        return new()
 16179        {
 16180            Id = Id,
 16181            Discipline = Discipline.Name,
 16182            Code = Discipline.Code,
 16183            Teacher = Teacher.Name,
 16184            Period = PeriodId,
 16185            Vacancies = Vacancies,
 16186            Status = Status,
 18187            Schedules = Schedules.ConvertAll(h => h.ToOut()),
 372188            Lessons = Lessons.OrderBy(x => x.Number).Select(x => x.ToOut()).ToList(),
 16189            SchedulesInline = GetScheduleAsString(),
 16190            Workload = GetWorkloadAsString(),
 16191            Progress = GetProgressAsString(),
 16192            FillRatio = FillRatio,
 16193        };
 194    }
 195
 196    public TeacherClassOut ToTeacherClassOut()
 197    {
 2198        return new()
 2199        {
 2200            Id = Id,
 2201            Discipline = Discipline.Name,
 2202            Code = Discipline.Code,
 2203            Period = PeriodId,
 2204            Status = Status,
 2205        };
 206    }
 207
 208    public StudentClassOut ToStudentClassOut(decimal n1, decimal n2, decimal n3, decimal average, decimal frequency)
 209    {
 0210        return new()
 0211        {
 0212            Id = Id,
 0213            Discipline = Discipline.Name,
 0214            Code = Discipline.Code,
 0215            Period = PeriodId,
 0216            Status = Status,
 0217            N1 = n1,
 0218            N2 = n2,
 0219            N3 = n3,
 0220            Average = average,
 0221            Frequency = frequency,
 0222        };
 223    }
 224
 225    public TeacherClassesOut ToTeacherClassesOut()
 226    {
 0227        return new()
 0228        {
 0229            Id = Id,
 0230            Discipline = Discipline.Name,
 0231            Code = Discipline.Code,
 0232            Period = PeriodId,
 0233            Schedules = Schedules.ConvertAll(h => h.ToOut()),
 0234            SchedulesInline = GetScheduleAsString(),
 0235        };
 236    }
 237
 238    public TeacherCurrentClassOut ToTeacherCurrentClassOut()
 239    {
 0240        return new()
 0241        {
 0242            Id = Id,
 0243            Discipline = Discipline.Name,
 0244        };
 245    }
 246
 247    public StudentCurrentClassOut ToStudentCurrentClassOut()
 248    {
 0249        return new()
 0250        {
 0251            Id = Id,
 0252            Discipline = Discipline.Name,
 0253        };
 254    }
 255}