Пример #1
0
        private async Task <List <PerguntaDTO> > RetornaRelatorioMatematica(filtrosRelatorioDTO filtro, NpgsqlConnection conexao, string query, int totalDeAlunos)
        {
            var ListaPerguntaEhRespostasRelatorio = await conexao.QueryAsync <PerguntasRespostasDTO>(query.ToString(),
                                                                                                     new
            {
                AnoDaTurma             = filtro.AnoEscolar,
                CodigoEscola           = filtro.CodigoUe,
                CodigoDRE              = filtro.CodigoDre,
                AnoLetivo              = filtro.AnoLetivo,
                PeriodoId              = filtro.PeriodoId,
                ComponenteCurricularId = filtro.ComponenteCurricularId
            });

            var relatorioAgrupado = ListaPerguntaEhRespostasRelatorio.GroupBy(p => p.PerguntaId).ToList();

            var lista = new List <PerguntaDTO>();

            relatorioAgrupado.ForEach(x =>
            {
                var pergunta = new PerguntaDTO();
                CalculaPercentualTotalPergunta(totalDeAlunos, x, pergunta);

                var listaPr        = x.Where(y => y.PerguntaId == x.Key).ToList();
                var totalRespostas = x.Where(y => y.PerguntaId == x.Key).Sum(q => q.QtdRespostas);
                CalculaPercentualRespostas(totalDeAlunos, pergunta, listaPr, totalRespostas);
                lista.Add(pergunta);
            });


            return(lista);
        }
Пример #2
0
        public static async Task <int> BuscaTotalDeAlunosEOl(filtrosRelatorioDTO filtro)
        {
            var DatasPeriodo = await BuscaDatasPeriodoFixoAnual(filtro);

            if (DatasPeriodo.Count() == 0)
            {
                return(0);
            }

            var endpointsApi = new EndpointsAPI();
            var alunoApi     = new AlunosAPI(endpointsApi);

            var filtroAlunos = new FiltroTotalAlunosAtivos()
            {
                AnoLetivo  = filtro.AnoLetivo,
                AnoTurma   = filtro.AnoEscolar,
                DreId      = filtro.CodigoDre,
                UeId       = filtro.CodigoUe,
                DataInicio = DatasPeriodo.First().DataInicio,
                DataFim    = DatasPeriodo.First().DataFim
            };


            var totalDeAlunos = await alunoApi.ObterTotalAlunosAtivosPorPeriodo(filtroAlunos);

            return(totalDeAlunos);
        }
Пример #3
0
        public async Task <RelatorioConsolidadoDTO> ObterRelatorioMatematicaAutoral(filtrosRelatorioDTO filtro)
        {
            IncluiIdDoComponenteCurricularEhDoPeriodoNoFiltro(filtro);
            int totalDeAlunos = await ConsultaTotalDeAlunos.BuscaTotalDeAlunosEOl(filtro);

            var query     = ConsultasRelatorios.QueryRelatorioMatematicaAutoral(filtro);
            var relatorio = new RelatorioConsolidadoDTO();

            using (var conexao = new NpgsqlConnection(Environment.GetEnvironmentVariable("sondagemConnection")))
            {
                relatorio.Perguntas = await RetornaRelatorioMatematica(filtro, conexao, query, totalDeAlunos);
            }

            relatorio.Graficos = new List <GraficosRelatorioDTO>();


            foreach (var pergunta in relatorio.Perguntas)
            {
                var grafico = new GraficosRelatorioDTO();
                grafico.nomeGrafico = pergunta.Nome;
                grafico.Barras      = new List <BarrasGraficoDTO>();
                pergunta.Respostas.ForEach(resposta =>
                {
                    var barra   = new BarrasGraficoDTO();
                    barra.label = resposta.Nome;
                    barra.value = resposta.quantidade;
                    grafico.Barras.Add(barra);
                });

                relatorio.Graficos.Add(grafico);
            }
            return(relatorio);
        }
        public async Task <IEnumerable <AlunosNaTurmaDTO> > ObterAlunosEOL(string schoolYear, string codigoTurmaEol, string term)
        {
            filtrosRelatorioDTO filtro = new filtrosRelatorioDTO()
            {
                AnoLetivo = int.Parse(schoolYear),
                PeriodoId = ""
            };

            using (var contexto = new SMEManagementContextData())
            {
                var periodo = contexto.Periodo.Where(x => x.Descricao == term).FirstOrDefault();
                filtro.PeriodoId = periodo.Id;
            }

            var periodos = await ConsultaTotalDeAlunos.BuscaDatasPeriodoFixoAnual(filtro);

            if (periodos.Count() == 0)
            {
                throw new Exception("Período fixo anual não encontrado");
            }

            var endpoits = new EndpointsAPI();
            var alunoApi = new AlunosAPI(endpoits);

            return((await alunoApi.ObterAlunosAtivosPorTurmaEPeriodo(codigoTurmaEol, periodos.First().DataFim)).OrderBy(a => a.NomeAluno));
        }
Пример #5
0
        private static void IncluiIdDoComponenteCurricularEhDoPeriodoNoFiltro(filtrosRelatorioDTO filtro)
        {
            using (var contexto = new SMEManagementContextData())
            {
                var componenteCurricular = contexto.ComponenteCurricular.Where(x => x.Descricao == filtro.DescricaoDisciplina).FirstOrDefault();

                filtro.ComponenteCurricularId = componenteCurricular.Id;
                var periodo = contexto.Periodo.Where(x => x.Descricao == filtro.DescricaoPeriodo).FirstOrDefault();
                filtro.PeriodoId = periodo.Id;
            }
        }
Пример #6
0
        private async Task RetornaPerguntasDoRelatorio(filtrosRelatorioDTO filtro, RelatorioMatematicaPorTurmaDTO relatorio)
        {
            relatorio.Perguntas = new List <PerguntasRelatorioDTO>();
            using (var contexto = new SMEManagementContextData())
            {
                var perguntasBanco = await contexto.PerguntaAnoEscolar.Include(x => x.Pergunta).Where(perguntaAnoEscolar => perguntaAnoEscolar.AnoEscolar == filtro.AnoEscolar).OrderBy(x => x.Ordenacao).Select(x => MapearPergunta(x)).ToListAsync();

                relatorio.Perguntas = perguntasBanco.Select(x => new PerguntasRelatorioDTO
                {
                    Id   = x.Id,
                    Nome = x.Descricao
                }).ToList();
            }
        }
Пример #7
0
    private filtrosRelatorioDTO CriaMapFiltroRelatorio(RelatorioPortuguesFiltroDto filtro)
    {
        var filtroRelatorio = new filtrosRelatorioDTO()
        {
            AnoEscolar             = filtro.AnoEscolar,
            AnoLetivo              = filtro.AnoLetivo,
            CodigoDre              = filtro.CodigoDre,
            CodigoUe               = filtro.CodigoUe,
            ComponenteCurricularId = filtro.ComponenteCurricularId,
            PeriodoId              = filtro.PeriodoId,
            GrupoId        = filtro.GrupoId,
            CodigoTurmaEol = filtro.CodigoTurma
        };

        return(filtroRelatorio);
    }
Пример #8
0
    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();
        }
    }
Пример #9
0
    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);
    }
Пример #10
0
    private static async Task <IEnumerable <AlunoPerguntaRespostaDTO> > RetornaListaRespostasAlunoPorTurma(filtrosRelatorioDTO filtro, string QueryAlunosRespostas)
    {
        using (var conexao = new NpgsqlConnection(Environment.GetEnvironmentVariable("sondagemConnection")))
        {
            var listaAlunoRespostas = await conexao.QueryAsync <AlunoPerguntaRespostaDTO>(QueryAlunosRespostas.ToString(),
                                                                                          new
            {
                GrupoId                = filtro.GrupoId,
                CodigoTurmaEol         = filtro.CodigoTurmaEol,
                AnoLetivo              = filtro.AnoLetivo,
                PeriodoId              = filtro.PeriodoId,
                ComponenteCurricularId = filtro.ComponenteCurricularId
            });

            return(listaAlunoRespostas);
        }
    }
        public async Task <ActionResult <string> > ObterDados([FromBody] ParametersModel parameters)
        {
            var businessPoll = new Data.Business.PollPortuguese(_config);

            if (int.Parse(parameters.CodigoCurso) >= 7 && parameters.Discipline == "Matemática")
            {
                var filtro = new filtrosRelatorioDTO()
                {
                    AnoEscolar          = int.Parse(parameters.CodigoCurso),
                    AnoLetivo           = int.Parse(parameters.SchoolYear),
                    CodigoDre           = parameters.CodigoDRE,
                    CodigoUe            = parameters.CodigoEscola,
                    CodigoTurmaEol      = parameters.CodigoTurmaEol,
                    DescricaoDisciplina = parameters.Discipline,
                    DescricaoPeriodo    = parameters.Term,
                };
                var obj = new RelatorioMatematicaAutoral();

                if (parameters.ClassroomReport)
                {
                    var relatorioPorTurma = await obj.ObterRelatorioPorTurma(filtro);

                    return(Ok(relatorioPorTurma));
                }
                var relatorioConsolidado = await obj.ObterRelatorioMatematicaAutoral(filtro);

                return(Ok(relatorioConsolidado));
            }

            Periodo periodo = await businessPoll.ObterPeriodoRelatorioPorDescricao(parameters.Term);


            if (parameters.Discipline == "Língua Portuguesa")
            {
                if (parameters.ClassroomReport)
                {
                    if (Convert.ToInt32(parameters.CodigoCurso) < 4)
                    {
                        PollReportPortugueseStudentResult result = new PollReportPortugueseStudentResult();
                        result = await BuscarDadosPorTurmaAsync(parameters, periodo);

                        return(Ok(result));
                    }

                    if (parameters.GrupoId != null && parameters.GrupoId.Equals("e27b99a3-789d-43fb-a962-7df8793622b1"))
                    {
                        var relatorioCapacidadeLeitura = new RelatorioPortuguesCapacidadeLeitura();
                        var relatorio = await relatorioCapacidadeLeitura.ObterRelatorioCapacidadeLeituraPorTurma(new RelatorioPortuguesFiltroDto
                        {
                            AnoEscolar             = Convert.ToInt32(parameters.CodigoCurso),
                            AnoLetivo              = Convert.ToInt32(parameters.SchoolYear),
                            CodigoDre              = parameters.CodigoDRE,
                            CodigoUe               = parameters.CodigoEscola,
                            ComponenteCurricularId = "c65b2c0a-7a58-4d40-b474-23f0982f14b1",
                            GrupoId     = "e27b99a3-789d-43fb-a962-7df8793622b1",
                            PeriodoId   = periodo.Id,
                            CodigoTurma = parameters.CodigoTurmaEol
                        });

                        return(Ok(relatorio));
                    }

                    return(Ok(await ObterRelatorioProducaoTextoLeituraVozAlta(parameters, periodo)));
                }
                else
                {
                    if (periodo == null)
                    {
                        return(StatusCode(500, $"Não foi possivel encontrar o périodo com descrição {parameters.Term}"));
                    }

                    if (Convert.ToInt32(parameters.CodigoCurso) < 4)
                    {
                        PollReportPortugueseResult result = new PollReportPortugueseResult();
                        result = await BuscarDadosSyncAsync(parameters, parameters.SchoolYear, parameters.CodigoDRE, parameters.CodigoEscola, parameters.CodigoCurso, businessPoll, periodo);

                        return(Ok(result));
                    }

                    if (parameters.GrupoId.Equals("e27b99a3-789d-43fb-a962-7df8793622b1"))
                    {
                        var relatorioCapacidadeLeitura = new RelatorioPortuguesCapacidadeLeitura();
                        var relatorioCapacidade        = await relatorioCapacidadeLeitura.ObterRelatorioCapacidadeLeitura(new RelatorioPortuguesFiltroDto
                        {
                            AnoEscolar             = Convert.ToInt32(parameters.CodigoCurso),
                            AnoLetivo              = Convert.ToInt32(parameters.SchoolYear),
                            CodigoDre              = parameters.CodigoDRE,
                            CodigoUe               = parameters.CodigoEscola,
                            ComponenteCurricularId = "c65b2c0a-7a58-4d40-b474-23f0982f14b1",
                            GrupoId   = "e27b99a3-789d-43fb-a962-7df8793622b1",
                            PeriodoId = periodo.Id
                        });

                        return(Ok(relatorioCapacidade));
                    }
                    return(Ok(await BuscarDadosAutoralAsync(parameters, periodo.Id)));
                }
            }
            else if (parameters.Discipline == "Matemática")
            {
                if (parameters.ClassroomReport)
                {
                    if (parameters.Proficiency == "Números")
                    {
                        PollReportMathStudentNumbersResult result = await BuscaDadosMathTurmaNumbersAsync(parameters.Proficiency,
                                                                                                          parameters.Term,
                                                                                                          parameters.CodigoDRE,
                                                                                                          parameters.CodigoEscola,
                                                                                                          parameters.CodigoTurmaEol, parameters.CodigoCurso, parameters.SchoolYear);

                        return(Ok(result));
                    }
                    else
                    {
                        PollReportMathStudentResult result = await BuscaDadosMathTurmaAsync(parameters.Proficiency,
                                                                                            parameters.Term,
                                                                                            parameters.CodigoDRE,
                                                                                            parameters.CodigoEscola,
                                                                                            parameters.CodigoTurmaEol, parameters.CodigoCurso, parameters.SchoolYear);

                        return(Ok(result));
                    }
                }

                else    // cONSOLIDADO
                {
                    var result = await BuscaDadosMathAsync(parameters, parameters.SchoolYear, parameters.CodigoDRE, parameters.CodigoEscola, parameters.CodigoCurso, periodo);

                    return(Ok(result));
                }
            }

            return(NotFound());
        }
        public static string QueryRelatorioMatematicaAutoral(filtrosRelatorioDTO filtro)
        {
            var queryRelatorio = @"SELECT
								p.""Id"" as ""PerguntaId"",
							    p.""Descricao"" as ""PerguntaDescricao"",
								r.""Id"" as ""RespostaId"",
								r.""Descricao"" as ""RespostaDescricao"",
	                            pa.""Ordenacao"",
                                pr.""Ordenacao"",
								count(tabela.""RespostaId"") as ""QtdRespostas""
							    from
								""Pergunta"" p
								inner join ""PerguntaAnoEscolar"" pa on
							    pa.""PerguntaId"" = p.""Id""

								and pa.""AnoEscolar"" = @AnoDaTurma
								inner join ""PerguntaResposta"" pr on
								pr.""PerguntaId"" = p.""Id""
								inner join ""Resposta"" r on
								r.""Id"" = pr.""RespostaId""
								left join (
									select
									s.""AnoLetivo"",
									s.""AnoTurma"",
									per.""Descricao"",
									c.""Descricao"",
									sa.""NomeAluno"",
									p.""Id"" as""PerguntaId"",
									p.""Descricao"" as ""PerguntaDescricao"",
									r.""Id"" as ""RespostaId"",
									r.""Descricao"" as ""RespostaDescricao""
								from
									""SondagemAlunoRespostas"" sar
								inner join ""SondagemAluno"" sa on
									sa.""Id"" = ""SondagemAlunoId""
								inner join ""Sondagem"" s on
									s.""Id"" = sa.""SondagemId""
								inner join ""Pergunta"" p on
									p.""Id"" = sar.""PerguntaId""
								inner join ""Resposta"" r on
									r.""Id"" = sar.""RespostaId""
								inner join ""Periodo"" per on
									per.""Id"" = s.""PeriodoId""
								inner join ""ComponenteCurricular"" c on
									c.""Id"" = s.""ComponenteCurricularId""
								where
									s.""Id"" in (
									select
										""Id""
									from
										""Sondagem""
									where
									   ""ComponenteCurricularId"" = @ComponenteCurricularId
										"                                        ;


            var query = new StringBuilder();

            query.Append(queryRelatorio);
            if (!string.IsNullOrEmpty(filtro.CodigoDre))
            {
                query.AppendLine(@" and ""CodigoDre"" =  @CodigoDRE");
            }
            if (!string.IsNullOrEmpty(filtro.CodigoUe))
            {
                query.AppendLine(@"and ""CodigoUe"" =  @CodigoEscola");
            }

            query.Append(@" and ""AnoLetivo"" = @AnoLetivo
	                            and ""AnoTurma"" =  @AnoDaTurma
                                  and ""PeriodoId"" = @PeriodoId
                                                          ) ) as tabela on
	                                p.""Id"" = tabela.""PerguntaId"" and
	                                r.""Id""= tabela.""RespostaId""
	                            group by
	                                r.""Id"",
	                                r.""Descricao"",
	                                p.""Id"",
	                                p.""Descricao"",
                                    pa.""Ordenacao"",
                                    pr.""Ordenacao""
	                            order by
                                    pa.""Ordenacao"",
                                    pr.""Ordenacao"",
	                                p.""Descricao"",
	                                r.""Descricao"" "                            );
            return(query.ToString());
        }
Пример #13
0
        public static async Task <IEnumerable <DatasPeriodoFixoAnualDTO> > BuscaDatasPeriodoFixoAnual(filtrosRelatorioDTO filtro)
        {
            using (var conexao = new NpgsqlConnection(Environment.GetEnvironmentVariable("sondagemConnection")))
            {
                var queryPeriodoFixoAnual = ConsultasRelatorios.QueryPeriodoFixoAnual;
                var DatasPeriodo          = await conexao.QueryAsync <DatasPeriodoFixoAnualDTO>(queryPeriodoFixoAnual.ToString(),
                                                                                                new
                {
                    PeriodoId = filtro.PeriodoId,
                    AnoLetivo = filtro.AnoLetivo,
                });

                return(DatasPeriodo);
            }
        }
Пример #14
0
        public async Task <RelatorioMatematicaPorTurmaDTO> ObterRelatorioPorTurma(filtrosRelatorioDTO filtro)
        {
            IncluiIdDoComponenteCurricularEhDoPeriodoNoFiltro(filtro);
            var periodos = await ConsultaTotalDeAlunos.BuscaDatasPeriodoFixoAnual(filtro);

            if (periodos.Count() == 0)
            {
                throw new Exception("Periodo fixo anual nao encontrado");
            }

            var endpoits  = new EndpointsAPI();
            var alunoApi  = new AlunosAPI(endpoits);
            var alunosEol = await alunoApi.ObterAlunosAtivosPorTurmaEPeriodo(filtro.CodigoTurmaEol, periodos.First().DataFim);

            var QueryAlunosRespostas = ConsultasRelatorios.QueryRelatorioPorTurmaMatematica();
            var listaAlunoRespostas  = await RetornaListaRespostasAlunoPorTurma(filtro, QueryAlunosRespostas);

            var AlunosAgrupados = listaAlunoRespostas.GroupBy(x => x.CodigoAluno);
            var relatorio       = new RelatorioMatematicaPorTurmaDTO();

            await RetornaPerguntasDoRelatorio(filtro, relatorio);

            var ListaAlunos = new List <AlunoPorTurmaRelatorioDTO>();

            alunosEol.ForEach(alunoRetorno =>
            {
                var aluno         = new AlunoPorTurmaRelatorioDTO();
                aluno.CodigoAluno = alunoRetorno.CodigoAluno;
                aluno.NomeAluno   = alunoRetorno.NomeAlunoRelatorio;
                aluno.Perguntas   = new List <PerguntaRespostaPorAluno>();

                var alunoRespostas = AlunosAgrupados.Where(x => x.Key == aluno.CodigoAluno.ToString()).ToList();

                foreach (var perguntaBanco in relatorio.Perguntas)
                {
                    var pergunta = new PerguntaRespostaPorAluno()
                    {
                        Id    = perguntaBanco.Id,
                        Valor = string.Empty
                    };

                    var respostaAluno = listaAlunoRespostas.Where(x => x.PerguntaId == perguntaBanco.Id && x.CodigoAluno == aluno.CodigoAluno.ToString()).FirstOrDefault();
                    if (respostaAluno != null)
                    {
                        pergunta.Valor = respostaAluno.RespostaDescricao;
                    }
                    aluno.Perguntas.Add(pergunta);
                }
                ListaAlunos.Add(aluno);
            });
            relatorio.Alunos   = ListaAlunos.OrderBy(aluno => aluno.NomeAluno);
            relatorio.Graficos = new List <GraficosRelatorioDTO>();


            using (var contexto = new SMEManagementContextData())
            {
                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();


                foreach (var pergunta in relatorio.Perguntas)
                {
                    var grafico = new GraficosRelatorioDTO();
                    grafico.nomeGrafico = pergunta.Nome;
                    grafico.Barras      = new List <BarrasGraficoDTO>();
                    var listaRespostas = perguntasBanco.Where(x => x.Pergunta.Id == pergunta.Id).ToList();

                    listaRespostas.ForEach(resposta =>
                    {
                        var barra   = new BarrasGraficoDTO();
                        barra.label = resposta.Resposta.Descricao;
                        barra.value = relatorio.Alunos.Count(x => x.Perguntas.Any(r => r.Id == pergunta.Id && r.Valor == resposta.Resposta.Descricao));
                        grafico.Barras.Add(barra);
                    });

                    var barraAlunosSemPreenchimento = new BarrasGraficoDTO();
                    barraAlunosSemPreenchimento.label = "Sem Preenchimento";
                    barraAlunosSemPreenchimento.value = relatorio.Alunos.Count() - grafico.Barras.Sum(x => x.value);
                    grafico.Barras.Add(barraAlunosSemPreenchimento);
                    relatorio.Graficos.Add(grafico);
                }
            }
            return(relatorio);
        }