private static async Task CriaGraficosRelatorio(RelatorioCapacidadeLeituraPorTurma relatorio, SMEManagementContextData contexto) { var perguntasBanco = await contexto.PerguntaResposta.Include(x => x.Pergunta).Include(y => y.Resposta).Where(pr => relatorio.Perguntas.Any(p => p.Id == pr.Pergunta.Id)).ToListAsync(); relatorio.Graficos = new List <GraficoOrdem>(); relatorio.Ordens.ForEach(o => { var graficoOrdem = new GraficoOrdem(); graficoOrdem.Ordem = o.Nome; graficoOrdem.perguntasGrafico = new List <Grafico>(); relatorio.Perguntas.ForEach(p => { var grafico = new Grafico(); grafico.NomeGrafico = p.Nome; var listaRespostas = perguntasBanco.Where(x => x.Pergunta.Id == p.Id); listaRespostas.ForEach(r => { var barra = new GraficoBarra(); barra.Label = r.Resposta.Descricao; barra.Value = relatorio.Alunos.Count(x => x.Ordens.Any(ordem => ordem.Id == o.Id && ordem.Perguntas.Any(pr => pr.Id == p.Id && pr.Valor == r.Resposta.Descricao))); grafico.Barras.Add(barra); }); var barraAlunosSemPreenchimento = new GraficoBarra(); barraAlunosSemPreenchimento.Label = "Sem Preenchimento"; barraAlunosSemPreenchimento.Value = relatorio.Alunos.Count() - grafico.Barras.Sum(x => x.Value); grafico.Barras.Add(barraAlunosSemPreenchimento); graficoOrdem.perguntasGrafico.Add(grafico); }); relatorio.Graficos.Add(graficoOrdem); }); }
private async Task IncluiOrdensEPerguntasNoRelatorio(filtrosRelatorioDTO filtro, RelatorioCapacidadeLeituraPorTurma relatorio) { using (var contexto = new SMEManagementContextData()) { var listaOrdemPergunta = await contexto.OrdemPergunta.Include(x => x.Pergunta).Where(y => y.GrupoId == filtro.GrupoId).OrderBy(x => x.OrdenacaoNaTela).ToListAsync(); relatorio.Perguntas = listaOrdemPergunta.Select(x => new PerguntasRelatorioDTO { Id = x.PerguntaId, Nome = x.Pergunta.Descricao }).ToList(); var grupos = await contexto.Grupo.Include(x => x.Ordem).Where(x => x.Id == filtro.GrupoId).FirstOrDefaultAsync(); relatorio.Ordens = grupos.Ordem.OrderBy(x => x.Ordenacao).Select(x => new OrdemRelatorioPorTurmaDTO { Id = x.Id, Nome = x.Descricao }).ToList(); } }
private async Task <RelatorioCapacidadeLeituraPorTurma> CriaRelatorioAlunos(filtrosRelatorioDTO filtrosRelatorio, IEnumerable <AlunosNaTurmaDTO> alunosEol, IEnumerable <AlunoPerguntaRespostaDTO> listaAlunoRespostas) { var relatorio = new RelatorioCapacidadeLeituraPorTurma(); await IncluiOrdensEPerguntasNoRelatorio(filtrosRelatorio, relatorio); var alunosAgrupados = listaAlunoRespostas.GroupBy(x => x.CodigoAluno); relatorio.Alunos = new List <AlunoPorTurmaCapacidadeLeituraDTO>(); alunosEol.ForEach(alunoRetorno => { var aluno = new AlunoPorTurmaCapacidadeLeituraDTO(); aluno.CodigoAluno = alunoRetorno.CodigoAluno; aluno.NomeAluno = alunoRetorno.NomeAlunoRelatorio; aluno.Ordens = new List <OrdemPorAlunoCapacidadeLeituraDTO>(); var alunoRespostas = alunosAgrupados.Where(x => x.Key == aluno.CodigoAluno.ToString()).ToList(); relatorio.Ordens.ForEach(o => { var ordemDto = new OrdemPorAlunoCapacidadeLeituraDTO() { Id = o.Id, Nome = o.Nome, Perguntas = new List <PerguntaRespostaPorAluno>() }; ordemDto.Perguntas = relatorio.Perguntas.Select(p => new PerguntaRespostaPorAluno { Id = p.Id, Valor = RetornaRespostaAluno(listaAlunoRespostas, p.Id, o.Id, alunoRetorno.CodigoAluno.ToString()) }).ToList(); aluno.Ordens.Add(ordemDto); }); relatorio.Alunos.Add(aluno); }); return(relatorio); }