< Summary

Information
Class: Syki.Back.Features.Academic.FinalizeClasses.FinalizeClassesService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Academic/FinalizeClasses/FinalizeClassesService.cs
Tag: 22_11348620282
Line coverage
93%
Covered lines: 31
Uncovered lines: 2
Coverable lines: 33
Total lines: 58
Line coverage: 93.9%
Branch coverage
81%
Covered branches: 18
Total branches: 22
Branch coverage: 81.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Finalize()83.33%18.171892%

File(s)

/home/runner/work/syki/syki/Back/Features/Academic/FinalizeClasses/FinalizeClassesService.cs

#LineLine coverage
 1namespace Syki.Back.Features.Academic.FinalizeClasses;
 2
 2713public class FinalizeClassesService(SykiDbContext ctx) : IAcademicService
 4{
 5    public async Task<OneOf<SykiSuccess, SykiError>> Finalize(Guid institutionId, FinalizeClassesIn data)
 6    {
 57        var classes = await ctx.Classes
 58            .Include(x => x.Lessons)
 59                .ThenInclude(x => x.Attendances)
 510            .Include(x => x.Students)
 511            .Include(t => t.ExamGrades)
 512            .Where(c => c.InstitutionId == institutionId && data.Classes.Contains(c.Id))
 513            .ToListAsync();
 14
 615        if (classes.Count == 0) return new InvalidClassesList();
 16
 817        var statusOk = classes.All(x => x.Status == ClassStatus.Started);
 618        if (!statusOk) return new ClassMustHaveStartedStatus();
 19
 420        var results = classes.ConvertAll(c => c.Finish());
 721        foreach (var result in results)
 22        {
 323            if (result.IsError()) return result.GetError();
 24        }
 25
 226        var ids = classes.ConvertAll(x => x.Id);
 127        var classesStudents = await ctx.ClassesStudents.Where(x => ids.Contains(x.ClassId)).ToListAsync();
 28
 129        var configs = await ctx.Configs.FirstAsync(x => x.InstitutionId == institutionId);
 30
 431        foreach (var @class in classes)
 32        {
 2233            var lessons = @class.Lessons.Count(x => x.Attendances.Count > 0);
 434            foreach (var student in @class.Students)
 35            {
 436                var studentExamGrades = @class.ExamGrades.Where(g => g.StudentId == student.Id).ToList();
 137                var averageNote = studentExamGrades.GetAverageNote();
 4338                var presences = @class.Lessons.Count(x => x.Attendances.Exists(a => a.StudentId == student.Id && a.Prese
 139                var frequency = lessons == 0 ? 0.00M : 100M * (1M * presences / (1M * lessons));
 240                var link = classesStudents.First(x => x.ClassId == @class.Id && x.SykiStudentId == student.Id);
 41
 142                link.StudentDisciplineStatus = StudentDisciplineStatus.Aprovado;
 143                if (averageNote < configs.NoteLimit)
 44                {
 145                    link.StudentDisciplineStatus = StudentDisciplineStatus.ReprovadoPorNota;
 46                }
 047                else if (frequency < configs.FrequencyLimit)
 48                {
 049                    link.StudentDisciplineStatus = StudentDisciplineStatus.ReprovadoPorFalta;
 50                }
 51            }
 52        }
 53
 154        await ctx.SaveChangesAsync();
 55
 156        return new SykiSuccess();
 557    }
 58}