Subversion Repositories bacoAlunos

Rev

Rev 1830 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1574 jmachado 1
package pt.estgp.estgweb.services.questionarios.pedagogico.reportprocessors;
1569 jmachado 2
 
1586 jmachado 3
import jomm.dao.impl.AbstractDao;
1569 jmachado 4
import jomm.utils.PdfUtils;
5
import org.apache.fop.apps.FOPException;
6
import org.apache.log4j.Logger;
7
import org.dom4j.DocumentException;
1814 jmachado 8
import pt.estgp.estgweb.utils.Globals;
1569 jmachado 9
import pt.estgp.estgweb.domain.Course;
1585 jmachado 10
import pt.estgp.estgweb.domain.QuestionarioReportCursoFile;
11
import pt.estgp.estgweb.domain.QuestionarioReportCursoFileImpl;
12
import pt.estgp.estgweb.domain.QuestionarioReportFileGroupCursosAnoImpl;
1569 jmachado 13
import pt.estgp.estgweb.domain.dao.DaoFactory;
1585 jmachado 14
import pt.estgp.estgweb.filters.chains.ResourceAccessControlEnum;
1574 jmachado 15
import pt.estgp.estgweb.services.jobs.ServiceJob;
16
import pt.estgp.estgweb.services.logresults.ILogMessages;
1585 jmachado 17
import pt.estgp.estgweb.services.logresults.LogMessageTypeEnum;
18
import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessage;
1574 jmachado 19
import pt.estgp.estgweb.services.logresults.impl.DefaultLogMessages;
1585 jmachado 20
import pt.estgp.estgweb.services.questionarios.pedagogico.reportprocessors.queries.*;
1576 jmachado 21
import pt.estgp.estgweb.services.questionarios.pedagogico.reportprocessors.reportdomains.CursoPublicReport;
22
import pt.estgp.estgweb.services.questionarios.pedagogico.reportprocessors.reportdomains.EntityEvaluated;
1574 jmachado 23
import pt.estgp.estgweb.services.questionarios.pedagogico.reportprocessors.utils.*;
1569 jmachado 24
import pt.estgp.estgweb.utils.ConfigProperties;
25
import pt.estgp.estgweb.utils.DatesUtils;
26
import pt.estgp.estgweb.utils.Dom4jUtil;
1814 jmachado 27
import pt.estgp.estgweb.utils.DatesWebUtils;
1569 jmachado 28
 
29
import javax.xml.transform.TransformerException;
30
import javax.xml.transform.dom.DOMSource;
1571 jmachado 31
import java.awt.*;
1705 jmachado 32
import java.io.*;
1570 jmachado 33
import java.text.SimpleDateFormat;
34
import java.util.*;
1571 jmachado 35
import java.util.List;
1569 jmachado 36
 
37
/**
38
 * Created by jorgemachado on 16/12/16.
39
 */
1574 jmachado 40
public class CursoPublicReportGenerator extends ReportAlunosGenerator
1569 jmachado 41
{
42
    private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(DocenteReportGenerator.class);
43
 
44
 
1574 jmachado 45
 
1569 jmachado 46
    public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws 1.5.0/docs/api/java/io/IOException.html">IOException, DocumentException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, FOPException
47
    {
48
 
1586 jmachado 49
        AbstractDao.getCurrentSession().beginTransaction();
1569 jmachado 50
        //String teacherCode = "44451";
51
        //String teacherCode = "20122";
1627 jmachado 52
        1.5.0/docs/api/java/lang/String.html">String courseCode = "9119";
1573 jmachado 53
        //String courseCode = "9104";
1569 jmachado 54
        1.5.0/docs/api/java/lang/String.html">String anoLectivo = "201516";
1586 jmachado 55
        1.5.0/docs/api/java/lang/String.html">String[] periodos = new 1.5.0/docs/api/java/lang/String.html">String[]{"S2","T3","T4","A"};
56
        //String[] periodos = new String[]{"S1"};
1571 jmachado 57
        1.5.0/docs/api/java/lang/String.html">String[] degrees = new 1.5.0/docs/api/java/lang/String.html">String[]{"L","M","T","E"};
1705 jmachado 58
        new CursoPublicReportGenerator(anoLectivo,periodos,degrees,courseCode).processCourse(courseCode,new 1.5.0/docs/api/java/io/File.html">File(Globals.TMP_DIR),true);
1586 jmachado 59
        AbstractDao.getCurrentSession().getTransaction().commit();
1569 jmachado 60
 
61
    }
62
 
1579 jmachado 63
    public CursoPublicReportGenerator() {
64
        super(null, null, null);
65
    }
66
 
1705 jmachado 67
    public CursoPublicReportGenerator(1.5.0/docs/api/java/lang/String.html">String anoLectivo, 1.5.0/docs/api/java/lang/String.html">String[] periodos, 1.5.0/docs/api/java/lang/String.html">String[] degrees, 1.5.0/docs/api/java/lang/String.html">String courseCode)
68
    {
1569 jmachado 69
        super(anoLectivo, periodos, degrees);
70
    }
71
 
1586 jmachado 72
    public CursoPublicReport processCourse(1.5.0/docs/api/java/lang/String.html">String courseCode,1.5.0/docs/api/java/io/File.html">File reportCourseFolder) throws 1.5.0/docs/api/java/io/IOException.html">IOException, DocumentException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, FOPException
1569 jmachado 73
    {
1705 jmachado 74
        return processCourse(courseCode, reportCourseFolder,false);
75
    }
76
    public CursoPublicReport processCourse(1.5.0/docs/api/java/lang/String.html">String courseCode,1.5.0/docs/api/java/io/File.html">File reportCourseFolder,boolean ommitCourse) throws 1.5.0/docs/api/java/io/IOException.html">IOException, DocumentException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, FOPException
77
    {
1586 jmachado 78
 
1705 jmachado 79
        CursoPublicReport cursoReport = getCoursePublicReport(courseCode,ommitCourse);
1569 jmachado 80
        if(cursoReport == null)
81
        {
1585 jmachado 82
            1.5.0/docs/api/java/lang/String.html">String msg = " Curso " + courseCode + " nao tem respostas nestas condições ";
83
            logger.warn(msg);
84
            serviceLogWarn(msg);
85
            1.5.0/docs/api/java/lang/System.html">System.out.println();
86
            return cursoReport;
1569 jmachado 87
        }
88
 
89
        ChartBuilderUtil.createChartTiposAlunos(cursoReport, "tiposAlunosTmp");
90
        ChartBuilderUtil.createChartTaxaRespostas(cursoReport, "taxaRespostasTmp");
91
        ChartBuilderUtil.createChartTaxaParticipacao(cursoReport, "taxaParticipacaoTmp");
92
        ChartBuilderUtil.createChartUnidadesContribuicao(cursoReport,"unidadesContribuicao");
93
 
94
 
1705 jmachado 95
        1.5.0/docs/api/java/lang/String.html">String path = generatePdfReport(cursoReport,reportCourseFolder,ommitCourse);
1585 jmachado 96
        cursoReport.setPathGeneratedPdfTemp(path);
97
        return cursoReport;
1569 jmachado 98
 
99
    }
100
 
1705 jmachado 101
    private 1.5.0/docs/api/java/lang/String.html">String generatePdfReport(CursoPublicReport cursoReport,1.5.0/docs/api/java/io/File.html">File reportCourseFolder,boolean ommitCourse) throws DocumentException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, 1.5.0/docs/api/java/io/IOException.html">IOException, FOPException {
1586 jmachado 102
 
103
        if(!reportCourseFolder.exists())
104
        {
105
            reportCourseFolder.mkdirs();
106
        }
107
        1.5.0/docs/api/java/lang/String.html">String startPath = reportCourseFolder.getAbsolutePath()  + 1.5.0/docs/api/java/io/File.html">File.separator + "reportCurso" +  cursoReport.getCursoStats().getCodigoCurso();
1571 jmachado 108
        1.5.0/docs/api/java/lang/String.html">String path = startPath + ".pdf";
1569 jmachado 109
 
110
        1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream out = new 1.5.0/docs/api/java/io/FileOutputStream.html">FileOutputStream(path);
111
        Map<String,Object> params = new HashMap<String,Object>();
1844 jmachado 112
        params.put("site", Globals.SERVICE_URL);
1814 jmachado 113
        params.put("updateDate", DatesWebUtils.getStringFromDate(new 5+0%2Fdocs%2Fapi+Date">Date()));
1569 jmachado 114
 
115
 
116
        org.w3c.dom.5+0%2Fdocs%2Fapi+Document">Document dom2 = cursoReport.serialize();
117
        Dom4jUtil.writeSout(dom2);
1705 jmachado 118
        1.5.0/docs/api/java/io/File.html">File xmlFile = new java.io.1.5.0/docs/api/java/io/File.html">File(startPath + ".xml");
119
 
1571 jmachado 120
        Dom4jUtil.write(dom2,new java.io.1.5.0/docs/api/java/io/File.html">File(startPath + ".xml"));
1569 jmachado 121
 
1705 jmachado 122
        if(ommitCourse)
123
        {
124
            1.5.0/docs/api/java/io/File.html">File xmlFileOmmit = new java.io.1.5.0/docs/api/java/io/File.html">File(startPath + "-ommit.xml");
125
 
126
            1.5.0/docs/api/java/io/FileReader.html">FileReader fr = new 1.5.0/docs/api/java/io/FileReader.html">FileReader(xmlFile);
127
            1.5.0/docs/api/java/io/FileWriter.html">FileWriter frOut = new 1.5.0/docs/api/java/io/FileWriter.html">FileWriter(xmlFileOmmit);
128
            1.5.0/docs/api/java/lang/String.html">String s;
129
            try {
130
                1.5.0/docs/api/java/io/BufferedReader.html">BufferedReader br = new 1.5.0/docs/api/java/io/BufferedReader.html">BufferedReader(fr);
131
 
132
                while ((s = br.readLine()) != null)
133
                {
134
                    s = s.replaceAll(cursoReport.getCursoStats().getNomeCurso(),"Curso fictício");
135
                    s = s.replaceAll(cursoReport.getCursoStats().getCodigoCurso(),"0000");
136
 
137
                    int i = 1;
138
                    for(UnidadeStats stat : cursoReport.getCursoStats().getUnidadesStats())
139
                    {
140
                        s = s.replaceAll(stat.getNomeUnidade(),"Unidade" + i);
141
                        s = s.replaceAll(stat.getCodigoUnidade(),"0000" + i);
142
                        i++;
143
                    }
144
                    // do something with the resulting line
145
                    frOut.write(s);
146
                }
147
                frOut.flush();
148
                frOut.close();
149
                fr.close();
150
                dom2 = Dom4jUtil.toW3c(Dom4jUtil.parse(xmlFileOmmit));
151
            }catch(1.5.0/docs/api/java/lang/Exception.html">Exception e)
152
            {
153
 
154
            }
155
        }
156
 
157
 
158
 
1569 jmachado 159
        PdfUtils.setAuthority("Relatório de Avaliação Pedagógica - Relatório Público de Curso - " +
160
                cursoReport.getCursoStats().getNomeCurso() + " (" + cursoReport.getCursoStats().getCodigoCurso() + " ) " +
161
                "- Ano letivo " + cursoReport.getAnoLectivo() + " - Periodos " + cursoReport.getSemestres().toString() + "" +
162
                " Tipos de Curso - " + cursoReport.getDegrees().toString(),
163
                cursoReport.getCursoStats().getNomeCurso(), "Avaliação Pedagógica Docentes, Inqueritos aos Alunos");
1574 jmachado 164
        PdfUtils.createPdfFromXml(new 1.5.0/docs/api/javax/xml/transform/dom/DOMSource.html">DOMSource(dom2), "pt/estgp/estgweb/services/questionarios/pedagogico/reportprocessors/xsl/cursoPublicReport.fo.xsl", out, params);
1569 jmachado 165
        out.flush();
166
        out.close();
1574 jmachado 167
        return path;
1569 jmachado 168
    }
169
 
1705 jmachado 170
    private CursoPublicReport getCoursePublicReport(1.5.0/docs/api/java/lang/String.html">String courseCode,boolean ommitCourse) throws 1.5.0/docs/api/java/io/IOException.html">IOException {
1569 jmachado 171
 
1585 jmachado 172
        //AbstractDao.getCurrentSession().beginTransaction();
1569 jmachado 173
 
174
        Course c = DaoFactory.getCourseDaoImpl().findCourseByCode(courseCode);
175
 
176
        CursoPublicReport cursoReport = new CursoPublicReport();
177
 
178
        //dados relativos ao questionario
179
        cursoReport.setAnoLectivo(DatesUtils.getImportYearFormatted(anoLectivo));
180
        cursoReport.setSemestres(ReportUtils.getFormatedSemestres(periodos));
181
        cursoReport.setDegrees(ReportUtils.getFormatedDegrees(degrees));
182
 
183
 
184
        //dados relativos ao curso
1586 jmachado 185
        cursoReport.getCursoStats().setDegreeDescricao(ConfigProperties.getProperty("course.degree.desc." + c.getDegree()));
186
        cursoReport.getCursoStats().setDegree(c.getDegree());
1569 jmachado 187
        cursoReport.getCursoStats().setCodigoCurso(courseCode);
188
        cursoReport.getCursoStats().setNomeCurso(c.getName());
189
        cursoReport.getCursoStats().setCodigoCurso(c.getCode());
1692 jmachado 190
        cursoReport.getCursoStats().setNomeInstituicao(c.getDepartment().getCourseSchool().getName());
191
        cursoReport.getCursoStats().setCodigoInstituicao(c.getDepartment().getCourseSchool().getInstitutionalCode());
192
 
193
        cursoReport.getCursoStats().setCodigoNacionalInstituicao(ConfigProperties.getProperty("institution.national.code." + c.getDepartment().getCourseSchool().getInstitutionalCode()));
194
        cursoReport.getCursoStats().setAbreviaturaInstituicao(ConfigProperties.getProperty("institution.code.prefix." + c.getDepartment().getCourseSchool().getInstitutionalCode()));
1569 jmachado 195
        cursoReport.setAnoLectivo(anoLectivo);
196
 
197
 
198
 
199
 
200
 
1585 jmachado 201
        //Caso nao haja respostas
202
        //este metodo preenche todas as questões relativas a respostas e generos m/f e idades, mas
203
        // devolve total de respostas para ser usada aqui como verificacao
204
        int respostas = AlunosQueryDao.countAlunosQueResponderamAoCurso(courseCode, anoLectivo, cursoReport, periodos, degrees);
205
        QuestionariosQueryDao.countQuestionariosRespostasAoCurso(courseCode, anoLectivo, cursoReport, periodos, degrees);
206
        //todo testar curso sem respostas
207
        if(respostas > 0)
1569 jmachado 208
        {
1585 jmachado 209
            AlunosQueryDao.countTiposAlunosComRespostasAoCurso(courseCode, anoLectivo, cursoReport, periodos, degrees);
210
            AlunosQueryDao.countIdadesAlunosComRespostasAoCurso(courseCode, anoLectivo, cursoReport, periodos, degrees);
211
 
212
            //TABELAS
213
            QuestionariosQueryDao.createDataTableIdades(cursoReport, "Alunos");
214
            QuestionariosQueryDao.createDataTableLocalidadesAoCurso(cursoReport, courseCode, anoLectivo, periodos, degrees, "Alunos");
1569 jmachado 215
        }
216
 
1570 jmachado 217
        UnidadesQueryDao.createTableTaxaRespostaUnidadeAoCurso(cursoReport, courseCode, anoLectivo, periodos, degrees);
1569 jmachado 218
 
1585 jmachado 219
        if(respostas > 0)
220
        {
1626 jmachado 221
            //EVOLUCAO DAS RESPOSTAS
222
            List<Object[]> semanaContagemCurso = QuestionariosQueryDao.obtainEvolucaoRespostas(new 1.5.0/docs/api/java/lang/String.html">String[]{courseCode}, EntityEvaluated.CURSO,anoLectivo,periodos,degrees);
223
            List<Object[]> semanaContagemEscola = QuestionariosQueryDao.obtainEvolucaoRespostas(new 1.5.0/docs/api/java/lang/String.html">String[]{cursoReport.getCursoStats().getCodigoInstituicao()},EntityEvaluated.ESCOLA,anoLectivo,periodos,degrees);
224
            1.5.0/docs/api/java/lang/String.html">String distRespostas = ChartBuilderUtil.createTimeSeriesCursoRepostas("distribuicaoRespostasSemanal",cursoReport.getCursoStats().getNomeCurso(),cursoReport.getCursoStats().getAbreviaturaInstituicao(),semanaContagemCurso,semanaContagemEscola);
225
            cursoReport.setPathDistribuicaoRespostasSemanalChart(distRespostas);
1569 jmachado 226
 
1626 jmachado 227
            DataTable tableEvolucaoRespostas = criarEvolucaoTaxasRespostas(semanaContagemCurso,cursoReport.getQuestionariosReqTotal());
228
            cursoReport.setTabelaEvolucaoRespostas(tableEvolucaoRespostas);
1570 jmachado 229
 
230
 
1626 jmachado 231
            //Os cursos na Escola são todos os cursos, na pratica nao serve para nada porque
232
            //A media de todos os cursos na escola é a media da escola considerando a restricao de graus e periodos
233
            //media nas Escolas por pergunta e media nos Cursos por pergunta é igual
234
            //A media da entidade neste caso é a do curso
235
            List<String> codigosTodosCursosDaEscola = QueryDaoUtils.getCodigosCursosEscola(cursoReport.getCursoStats().getCodigoInstituicao(),anoLectivo, periodos, degrees);
1571 jmachado 236
 
1626 jmachado 237
            //List<String> codigosEscola = QueryDaoUtils.getCodigosEscolaDocente(teacherCode, anoLectivo, periodos, degrees);
238
            List<String> codigosEscola = new ArrayList<String>();
239
            codigosEscola.add(cursoReport.getCursoStats().getCodigoInstituicao());
1569 jmachado 240
 
241
 
1626 jmachado 242
            cursoReport.getCursoStats().setDocentesDoCurso((int) QueryDaoUtils.countDocentesNosCursos(courseCode, anoLectivo, periodos, degrees));
243
            cursoReport.getCursoStats().setDocentesDaEscola((int) QueryDaoUtils.countDocentesNasEscolas(cursoReport.getCursoStats().getCodigoInstituicao(), anoLectivo, periodos, degrees));
1569 jmachado 244
 
1626 jmachado 245
            // @todoRefactor
246
            // O DocenteReport tem as unidades na escola e as unidades no curso
247
            // O CursoReport nao tem, estao antes no CursoStats
248
            // Uma vez que sao usados em todos os reports de Alunos poderiam ser colocados no QuestionarioAlunos não é problematico
249
            // vai buscar às cadeiras temos de fazer override do metodo e puxa-lo para o QuestionarioAlunos
250
            //ou nao porque o UnidadesDaEscola foi introduzido dentro do Curso não se puxou para o QuestionarioAlunos
251
            //o xsl vai ter de usar este caso o use
252
            cursoReport.getCursoStats().setUnidadesDoCurso((int) QueryDaoUtils.countUnidadesNosCursos(courseCode, anoLectivo, periodos, degrees));
253
            cursoReport.getCursoStats().setUnidadesDaEscola((int) QueryDaoUtils.countUnidadesNasEscolas(cursoReport.getCursoStats().getCodigoInstituicao(), anoLectivo, periodos, degrees));
1569 jmachado 254
 
1571 jmachado 255
 
1626 jmachado 256
            ReportAlunosGenerator.criarGraficosRespostasAgregadas(new 1.5.0/docs/api/java/lang/String.html">String[]{courseCode},
257
                    EntityEvaluated.CURSO,
258
                    anoLectivo,
259
                    cursoReport,
260
                    codigosTodosCursosDaEscola,
261
                    codigosEscola,
262
                    0,
263
                    cursoReport.getCursoStats().getRespostasAgregadasGrupoUnidade().getRespostasAgregadasChartTable(),
264
                    cursoReport.getCursoStats().getRespostasAgregadasGrupoUnidade(),
265
                    PerguntasGrupoQueryDao.GRUPO_UNIDADE_CODE_PERGUNTAS, null,
266
                    periodos, degrees, true);
1569 jmachado 267
 
1626 jmachado 268
            ReportAlunosGenerator.criarGraficosRespostasAgregadas(new 1.5.0/docs/api/java/lang/String.html">String[]{courseCode},
269
                    EntityEvaluated.CURSO,
270
                    anoLectivo,
271
                    cursoReport,
272
                    codigosTodosCursosDaEscola,
273
                    codigosEscola,
274
                    2000,
275
                    cursoReport.getCursoStats().getRespostasAgregadasGrupoUnidade().getRespostasAgregadasChartTable2Secs(),
276
                    cursoReport.getCursoStats().getRespostasAgregadasGrupoUnidade(),
277
                    PerguntasGrupoQueryDao.GRUPO_UNIDADE_CODE_PERGUNTAS, null,
278
                    periodos, degrees, false);
1569 jmachado 279
 
1571 jmachado 280
 
1626 jmachado 281
            ReportAlunosGenerator.criarGraficosRespostasAgregadas(new 1.5.0/docs/api/java/lang/String.html">String[]{courseCode},
282
                    EntityEvaluated.CURSO,
283
                    anoLectivo,
284
                    cursoReport,
285
                    codigosTodosCursosDaEscola,
286
                    codigosEscola,
287
                    0,
288
                    cursoReport.getCursoStats().getRespostasAgregadasGrupoSalas().getRespostasAgregadasChartTable(),
289
                    cursoReport.getCursoStats().getRespostasAgregadasGrupoSalas(),
290
                    PerguntasGrupoQueryDao.GRUPO_SALAS_CODE_PERGUNTAS, null,
291
                    periodos, degrees, true);
1569 jmachado 292
 
1626 jmachado 293
            ReportAlunosGenerator.criarGraficosRespostasAgregadas(new 1.5.0/docs/api/java/lang/String.html">String[]{courseCode},
294
                    EntityEvaluated.CURSO,
295
                    anoLectivo,
296
                    cursoReport,
297
                    codigosTodosCursosDaEscola,
298
                    codigosEscola,
299
                    2000,
300
                    cursoReport.getCursoStats().getRespostasAgregadasGrupoSalas().getRespostasAgregadasChartTable2Secs(),
301
                    cursoReport.getCursoStats().getRespostasAgregadasGrupoSalas(),
302
                    PerguntasGrupoQueryDao.GRUPO_SALAS_CODE_PERGUNTAS, null,
303
                    periodos, degrees, false);
1569 jmachado 304
 
305
 
1585 jmachado 306
            UnidadesQueryDao.criarTabelasCadeirasCurso(courseCode,
307
                    anoLectivo,
308
                    cursoReport,
309
                    0, periodos, degrees,cursoReport.getCursoStats().getUnidadesStats());
1571 jmachado 310
 
1569 jmachado 311
 
1705 jmachado 312
 
313
            ChartWithDataTable analiseConjuntaChartWithTable = criarAnaliseConjuntaDeUnidades(cursoReport.getCursoStats().getUnidadesStats(),ommitCourse);
1585 jmachado 314
            cursoReport.setAnaliseConjuntaChartWithTable(analiseConjuntaChartWithTable);
1569 jmachado 315
 
1705 jmachado 316
            1.5.0/docs/api/java/lang/String.html">String pathOrdenadaMediaUnidades = criarAnaliseConjuntaDeUnidadesOrdenadaMediaUnidades(cursoReport.getCursoStats().getUnidadesStats(),ommitCourse);
1585 jmachado 317
            cursoReport.setAnaliseConjuntaChartOrderMediaUnidades(pathOrdenadaMediaUnidades);
1569 jmachado 318
 
1705 jmachado 319
            1.5.0/docs/api/java/lang/String.html">String pathOrdenadaMediaSalas = criarAnaliseConjuntaDeUnidadesOrdenadaMediaSalas(cursoReport.getCursoStats().getUnidadesStats(),ommitCourse);
1585 jmachado 320
            cursoReport.setAnaliseConjuntaChartOrderMediaSalas(pathOrdenadaMediaSalas);
1569 jmachado 321
 
1585 jmachado 322
            ArrayList<TabelaPerguntaComparativosUnidades> listaTabelasComparativasUnidadesPergunta = criarAnaliseConjuntaDeUnidadesAPergunta(cursoReport.getCursoStats().getRespostasAgregadasGrupoUnidade().getPerguntasStats(), cursoReport.getCursoStats().getUnidadesStats(),PerguntasGrupoQueryDao.GRUPO_UNIDADE_CODE_PERGUNTAS,null);
323
            cursoReport.setListaUnidadesComprativasPergunta(listaTabelasComparativasUnidadesPergunta);
1569 jmachado 324
 
1585 jmachado 325
            ArrayList<TabelaPerguntaComparativosUnidades> listaTabelasComparativasUnidadesPerguntaSalas = criarAnaliseConjuntaDeUnidadesAPergunta(cursoReport.getCursoStats().getRespostasAgregadasGrupoUnidade().getPerguntasStats(), cursoReport.getCursoStats().getUnidadesStats(),PerguntasGrupoQueryDao.GRUPO_SALAS_CODE_PERGUNTAS,null);
326
            cursoReport.setListaUnidadesComprativasPerguntaSalas(listaTabelasComparativasUnidadesPerguntaSalas);
1569 jmachado 327
 
1585 jmachado 328
            DataTable dataTableTodasAsUndiadesTodasPerguntas = criarTabelaComRespostasATodasAsPerguntas(cursoReport);
329
            cursoReport.setTodasAsRespostasMediasGruposUnidadesESalas(dataTableTodasAsUndiadesTodasPerguntas);
1569 jmachado 330
 
1585 jmachado 331
        }
332
        //AbstractDao.getCurrentSession().getTransaction().commit();
1572 jmachado 333
        return cursoReport;
334
    }
1569 jmachado 335
 
1572 jmachado 336
    private DataTable criarTabelaComRespostasATodasAsPerguntas(CursoPublicReport cursoReport) {
337
        DataTable tabelaComRespostasATodasAsPerguntasUnidadesSalas = new DataTable();
1569 jmachado 338
 
1572 jmachado 339
        DataTable.Row headerHidden = tabelaComRespostasATodasAsPerguntasUnidadesSalas.addRowHeader();
340
        headerHidden.setInvisible(true);
341
        DataTable.Row headerGroups = tabelaComRespostasATodasAsPerguntasUnidadesSalas.addRowHeader();
342
        DataTable.Row header = tabelaComRespostasATodasAsPerguntasUnidadesSalas.addRowHeader();
1569 jmachado 343
 
1572 jmachado 344
 
345
        headerHidden.addColTextCenter("Inv " + "Unidade Curricular");
346
        headerGroups.addColInvisible();
1573 jmachado 347
        header.addColTextCenter("Unidade Curricular");
1572 jmachado 348
 
1573 jmachado 349
 
350
 
351
 
1572 jmachado 352
        headerHidden.addColTextCenter("Inv " + "Curso");
353
        headerGroups.addColInvisible();
1573 jmachado 354
        header.addColTextCenter("Curso");
1572 jmachado 355
 
1573 jmachado 356
        //CABECALHOS UNIDADES
357
        List<PerguntaStats> perguntaStatsesUnidadeHeader = cursoReport.getCursoStats().getRespostasAgregadasGrupoUnidade().getPerguntasStats();
358
        if(perguntaStatsesUnidadeHeader.size() > 0)
359
        {
360
            DataTable.Row.Col c = headerGroups.addColTextCenter("Unidade Curricular");
361
            c.setColspan(perguntaStatsesUnidadeHeader.size());
362
            c.setBackgroundColor(ChartBuilderUtil.getRgbXslColor(ChartBuilderUtil.COLOR_SECTION_GREEN));
363
            1.5.0/docs/api/java/util/Collections.html">Collections.sort(perguntaStatsesUnidadeHeader,new Comparator<PerguntaStats>() {
364
                @1.5.0/docs/api/java/lang/Override.html">Override
365
                public int compare(PerguntaStats o1, PerguntaStats o2) {
366
                    return 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(o1.getNumero()) - 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(o2.getNumero());
367
                }
368
            });
369
            for(PerguntaStats perguntaStats : perguntaStatsesUnidadeHeader)
370
            {
371
                headerHidden.addColTextCenter("Inv " + perguntaStats.getNumero());
1626 jmachado 372
                header.addColTextCenter("Q" + perguntaStats.getNumero()).setBackgroundColor(ChartBuilderUtil.getRgbXslColor(ChartBuilderUtil.COLOR_SECTION_GREEN));
1572 jmachado 373
            }
374
        }
375
 
1573 jmachado 376
        //CABECALHOS SALAS
377
        List<PerguntaStats> perguntaStatsesSalasHeader = cursoReport.getCursoStats().getRespostasAgregadasGrupoSalas().getPerguntasStats();
378
        if(perguntaStatsesSalasHeader.size() > 0)
379
        {
380
            DataTable.Row.Col c = headerGroups.addColTextCenter("Instalações");
381
            c.setColspan(perguntaStatsesSalasHeader.size());
382
            c.setBackgroundColor(ChartBuilderUtil.getRgbXslColor(ChartBuilderUtil.COLOR_SECTION_ROSE));
383
            1.5.0/docs/api/java/util/Collections.html">Collections.sort(perguntaStatsesSalasHeader,new Comparator<PerguntaStats>() {
384
                @1.5.0/docs/api/java/lang/Override.html">Override
385
                public int compare(PerguntaStats o1, PerguntaStats o2) {
386
                    return 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(o1.getNumero()) - 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(o2.getNumero());
387
                }
388
            });
389
            for(PerguntaStats perguntaStats : perguntaStatsesSalasHeader)
390
            {
1626 jmachado 391
                header.addColTextCenter("Q" + perguntaStats.getNumero());
392
                headerHidden.addColTextCenter("Inv Q" + perguntaStats.getNumero()).setBackgroundColor(ChartBuilderUtil.getRgbXslColor(ChartBuilderUtil.COLOR_SECTION_ROSE));
1572 jmachado 393
            }
394
        }
395
 
1573 jmachado 396
 
397
 
398
 
1572 jmachado 399
        header.addColTextCenter("Insc.");
400
        headerHidden.addColTextCenter("Inv Insc.");
401
        headerGroups.addColInvisible();
402
 
1626 jmachado 403
        header.addColTextCenter("Docen.");
404
        headerHidden.addColTextCenter("Inv Docentes");
405
        headerGroups.addColInvisible();
406
 
407
        header.addColTextCenter("Resp. Esp.");
408
        headerHidden.addColTextCenter("Inv Resp. Esperadas");
409
        headerGroups.addColInvisible();
410
 
1572 jmachado 411
        headerHidden.addColTextCenter("Inv Resps.");
412
        header.addColTextCenter("Resps.");
413
        headerGroups.addColInvisible();
414
 
1626 jmachado 415
        headerHidden.addColTextCenter("Inv % Resps.");
416
        header.addColTextCenter("% Resps.");
417
        headerGroups.addColInvisible();
418
 
1705 jmachado 419
 
1572 jmachado 420
        for(UnidadeStats unidadeStats: cursoReport.getCursoStats().getUnidadesStats())
421
        {
422
            DataTable.Row unidadeRow = tabelaComRespostasATodasAsPerguntasUnidadesSalas.addRowNormal();
1705 jmachado 423
 
1572 jmachado 424
            unidadeRow.addColTextCenter(unidadeStats.getNomeUnidade());
425
            unidadeRow.addColTextCenter(unidadeStats.getNomeCurso());
426
 
427
            //COLUNA POR CADA MEDIA DE CADA PERGUNTA NAS UNIDADES
428
            List<PerguntaStats> perguntaStatsesUnidades = unidadeStats.getUnidadeStatsGrupoUnidade().getPerguntasStats();
429
            1.5.0/docs/api/java/util/Collections.html">Collections.sort(perguntaStatsesUnidades,new Comparator<PerguntaStats>() {
430
                @1.5.0/docs/api/java/lang/Override.html">Override
431
                public int compare(PerguntaStats o1, PerguntaStats o2) {
432
                    return 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(o1.getNumero()) - 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(o2.getNumero());
433
                }
434
            });
1573 jmachado 435
 
436
            for(PerguntaStats guiaHeader: perguntaStatsesUnidadeHeader)
1572 jmachado 437
            {
1573 jmachado 438
                boolean found = false;
439
                for(PerguntaStats perguntaStats : perguntaStatsesUnidades)
440
                {
441
                    if(perguntaStats.getNumero().equals(guiaHeader.getNumero()))
442
                    {
443
                        unidadeRow.addColPercentageDefinedCenter(perguntaStats.getMediaEntidadeEmAvaliacaoPrint(), perguntaStats.getPercentMediaEntidadeEmAvaliacao(), true);
444
                        found = true;
445
                        break;
446
                    }
447
                }
448
                if(!found)
449
                    unidadeRow.addColTextCenter("--");
1572 jmachado 450
            }
451
 
1573 jmachado 452
 
1572 jmachado 453
            //COLUNA POR CADA MEDIA DE CADA PERGUNTA NAS SALAS
454
            List<PerguntaStats> perguntaStatsSalas = unidadeStats.getUnidadeStatsGrupoSalas().getPerguntasStats();
455
            1.5.0/docs/api/java/util/Collections.html">Collections.sort(perguntaStatsSalas,new Comparator<PerguntaStats>() {
456
                @1.5.0/docs/api/java/lang/Override.html">Override
457
                public int compare(PerguntaStats o1, PerguntaStats o2) {
458
                    return 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(o1.getNumero()) - 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(o2.getNumero());
459
                }
460
            });
1573 jmachado 461
            for(PerguntaStats guiaHeader: perguntaStatsesSalasHeader)
1572 jmachado 462
            {
1573 jmachado 463
                boolean found = false;
464
                for(PerguntaStats perguntaStats : perguntaStatsSalas)
465
                {
466
                    if(perguntaStats.getNumero().equals(guiaHeader.getNumero()))
467
                    {
468
                        unidadeRow.addColPercentageDefinedCenter(perguntaStats.getMediaEntidadeEmAvaliacaoPrint(), perguntaStats.getPercentMediaEntidadeEmAvaliacao(), true);
469
                        found = true;
470
                        break;
471
                    }
472
                }
473
                if(!found)
474
                    unidadeRow.addColTextCenter("--");
1572 jmachado 475
            }
476
 
1573 jmachado 477
 
1572 jmachado 478
            unidadeRow.addColTextCenter("" + unidadeStats.getInscritos());
1626 jmachado 479
            unidadeRow.addColTextCenter("" + unidadeStats.getDocentes());
480
            unidadeRow.addColTextCenter("" + unidadeStats.getRespostasEsperadas());
1572 jmachado 481
            unidadeRow.addColTextCenter("" + unidadeStats.getRespostas());
1626 jmachado 482
            unidadeRow.addColPercentageCenter(unidadeStats.getTaxaRespostaPrint0Slots(),true);
483
 
1572 jmachado 484
        }
485
        return tabelaComRespostasATodasAsPerguntasUnidadesSalas;
1569 jmachado 486
    }
1570 jmachado 487
 
1572 jmachado 488
    private ArrayList<TabelaPerguntaComparativosUnidades> criarAnaliseConjuntaDeUnidadesAPergunta(List<PerguntaStats> perguntasAgregadasGrupo, ArrayList<UnidadeStats> unidadesStats, 1.5.0/docs/api/java/lang/String.html">String grupo, 1.5.0/docs/api/java/lang/String.html">String subgrupo)
489
    {
490
        Map<String, List<UnidadePergunta>> unidadesPerguntas = new HashMap<String, List<UnidadePergunta>>();
491
        for(UnidadeStats unidadeStats: unidadesStats)
492
        {
493
            for(PerguntaStats prgStatUnidade :unidadeStats.findUnidadeStatsGrupo(grupo,subgrupo).getPerguntasStats())
494
            {
495
                List<UnidadePergunta> unidadesPerguntasList = unidadesPerguntas.get(prgStatUnidade.getPergunta());
496
                if(unidadesPerguntasList == null)
497
                {
498
                    unidadesPerguntasList = new ArrayList<UnidadePergunta>();
499
                    unidadesPerguntas.put(prgStatUnidade.getPergunta(),unidadesPerguntasList);
500
                }
501
                unidadesPerguntasList.add(new UnidadePergunta(unidadeStats,prgStatUnidade));
502
            }
503
        }
504
        ArrayList<TabelaPerguntaComparativosUnidades> tabelas = new ArrayList<TabelaPerguntaComparativosUnidades>();
505
 
1626 jmachado 506
        List<Map.Entry<String, List<UnidadePergunta>>> entradas = new ArrayList<Map.Entry<String, List<UnidadePergunta>>>(unidadesPerguntas.entrySet());
507
        1.5.0/docs/api/java/util/Collections.html">Collections.sort(entradas,new Comparator<Map.Entry<String, List<UnidadePergunta>>>() {
508
            @1.5.0/docs/api/java/lang/Override.html">Override
509
            public int compare(1.5.0/docs/api/java/util/Map.html">Map.Entry<String, List<UnidadePergunta>> o1, 1.5.0/docs/api/java/util/Map.html">Map.Entry<String, List<UnidadePergunta>> o2) {
510
                List<UnidadePergunta> o1UP = o1.getValue();
511
                List<UnidadePergunta> o2UP = o2.getValue();
512
                int numeroPergunta1 = 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(o1UP.get(0).getPerguntaStats().getNumero());
513
                int numeroPergunta2 = 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(o2UP.get(0).getPerguntaStats().getNumero());
514
                return numeroPergunta1 - numeroPergunta2;
515
            }
516
        });
517
        for(1.5.0/docs/api/java/util/Map.html">Map.Entry<String, List<UnidadePergunta>> entrada : entradas)
518
        //for(String pergunta: unidadesPerguntas.keySet())
1572 jmachado 519
        {
1626 jmachado 520
            1.5.0/docs/api/java/lang/String.html">String pergunta = entrada.getKey();
1572 jmachado 521
            TabelaPerguntaComparativosUnidades tabelaPerguntaComparativosUnidades = new TabelaPerguntaComparativosUnidades();
522
            tabelas.add(tabelaPerguntaComparativosUnidades);
523
            tabelaPerguntaComparativosUnidades.setPergunta(pergunta);
524
 
525
            DataTable perguntaUnidadesTable = new DataTable();
526
            tabelaPerguntaComparativosUnidades.setTabelaComparativaUnidades(perguntaUnidadesTable);
527
            DataTable.Row header = perguntaUnidadesTable.addRowHeader();
528
            header.addColTextCenter("Unidade Curricular");
529
            header.addColTextCenter("Curso");
530
            header.addColTextCenter("Insc.");
1626 jmachado 531
            header.addColTextCenter("Docentes.");/*Novo*/
532
            header.addColTextCenter("Resp. Esperadas");/*Novo*/
533
            header.addColTextCenter("Resp. Fornecidas");
534
            header.addColTextCenter("% Respostas");
1572 jmachado 535
            header.addColTextCenter("Média");
536
            header.addColTextCenter("Desvio");
537
 
538
            List<UnidadePergunta> unidadesPergunta = unidadesPerguntas.get(pergunta);
539
 
540
            //SUPOSTAMENTE VEM SEMPRE PREENCHIDO
541
            if(unidadesPergunta != null && unidadesPergunta.size() > 0)
542
                tabelaPerguntaComparativosUnidades.setPerguntaNumero(unidadesPergunta.get(0).getPerguntaStats().getNumero());
543
 
544
            1.5.0/docs/api/java/util/Collections.html">Collections.sort(unidadesPergunta,new Comparator<UnidadePergunta>() {
545
                @1.5.0/docs/api/java/lang/Override.html">Override
546
                public int compare(UnidadePergunta o1, UnidadePergunta o2) {
547
                    double sub = o2.getPerguntaStats().getMediaEntidadeEmAvaliacao() - o1.getPerguntaStats().getMediaEntidadeEmAvaliacao();
548
                    if(sub < 0.0)
549
                        return -1;
550
                    else if (sub > 0.0)
551
                        return 1;
552
                    else return 0;
553
                }
554
            });
1705 jmachado 555
 
1572 jmachado 556
            for(UnidadePergunta unidadePergunta: unidadesPergunta)
557
            {
558
                DataTable.Row rowUnidade = perguntaUnidadesTable.addRowNormal();
559
 
1705 jmachado 560
 
1572 jmachado 561
                rowUnidade.addColLabelCenter(unidadePergunta.getUnidadeStats().getNomeUnidade());
562
                rowUnidade.addColLabelCenter(unidadePergunta.getUnidadeStats().getNomeCurso());
1705 jmachado 563
 
1572 jmachado 564
                rowUnidade.addColTextRight("" + unidadePergunta.getUnidadeStats().getInscritos());
1626 jmachado 565
                rowUnidade.addColTextRight("" + unidadePergunta.getUnidadeStats().getDocentes());
566
                rowUnidade.addColTextRight("" + unidadePergunta.getUnidadeStats().getRespostasEsperadas());
1572 jmachado 567
                rowUnidade.addColTextRight("" + unidadePergunta.getUnidadeStats().getRespostas());
1626 jmachado 568
                //rowUnidade.addColTextRight("" + unidadePergunta.getUnidadeStats().getTaxaRespostaPrint0Slots());
569
                rowUnidade.addColPercentageDefinedCenter("" + unidadePergunta.getUnidadeStats().getTaxaRespostaPrint0Slots(), unidadePergunta.getUnidadeStats().getTaxaRespostaPrint0Slots(), true);
570
                rowUnidade.addColPercentageCenter(unidadePergunta.getPerguntaStats().getPercentMediaEntidadeEmAvaliacao(), true);
1572 jmachado 571
                rowUnidade.addColTextRight(unidadePergunta.getPerguntaStats().getDesvio());
572
            }
573
 
574
        }
575
 
576
        return tabelas;
577
    }
578
 
1705 jmachado 579
    private ChartWithDataTable criarAnaliseConjuntaDeUnidades(List<UnidadeStats> unidadesStats,boolean ommitCourse)
1571 jmachado 580
    {
581
        DataTable tabelaDocenteUnidade = new DataTable();
582
        try {
1570 jmachado 583
 
1571 jmachado 584
            1.5.0/docs/api/java/util/Collections.html">Collections.sort(unidadesStats, new Comparator<UnidadeStats>() {
585
                @1.5.0/docs/api/java/lang/Override.html">Override
586
                public int compare(UnidadeStats o1, UnidadeStats o2) {
587
                    return o1.getNomeUnidade().compareTo(o2.getNomeUnidade());
588
                }
589
            });
590
            1.5.0/docs/api/java/lang/String.html">String unidadeSalasPath = criarChartETabelaMediaGruposPorUnidade(500,30, unidadesStats,
591
                    PerguntasGrupoQueryDao.GRUPO_UNIDADE_CODE_PERGUNTAS,
592
                    null,
593
                    PerguntasGrupoQueryDao.GRUPO_SALAS_CODE_PERGUNTAS,
594
                    null,
595
                    tabelaDocenteUnidade,
596
                    "unidadeSalas",
597
                    new 1.5.0/docs/api/java/awt/Color.html">Color[]{ChartBuilderUtil.COLOR_SECTION_GREEN_DARK,ChartBuilderUtil.COLOR_SECTION_ROSE_DARK},
1705 jmachado 598
                    new 1.5.0/docs/api/java/awt/Color.html">Color[]{1.5.0/docs/api/java/awt/Color.html">Color.black,1.5.0/docs/api/java/awt/Color.html">Color.black},
599
                    ommitCourse
1571 jmachado 600
            );
1570 jmachado 601
 
1571 jmachado 602
            return
603
                    new ChartWithDataTable(
604
                            "Analise Conjunta de Unidades",
605
                            "Unidade VS Instalações/Equipamentos/Outros Recursos",
606
                            unidadeSalasPath,
607
                            tabelaDocenteUnidade);
608
 
609
        } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) {
610
            logger.error(e,e);
611
        }
612
        return null;
613
 
614
    }
615
 
1705 jmachado 616
    private 1.5.0/docs/api/java/lang/String.html">String criarAnaliseConjuntaDeUnidadesOrdenadaMediaUnidades(List<UnidadeStats> unidadesStats,boolean ommitCourse)
1571 jmachado 617
    {
618
        try {
619
 
620
            1.5.0/docs/api/java/util/Collections.html">Collections.sort(unidadesStats,new Comparator<UnidadeStats>() {
621
                @1.5.0/docs/api/java/lang/Override.html">Override
622
                public int compare(UnidadeStats o1, UnidadeStats o2) {
623
 
624
                    double sub = (o2.getUnidadeStatsGrupoUnidade().getMediasGrupo().getAvaliacaoMedia()
625
                            -
626
                            o1.getUnidadeStatsGrupoUnidade().getMediasGrupo().getAvaliacaoMedia());
627
                    if(sub > 0.0)
628
                        return 1;
629
                    else if (sub < 0.0)
630
                        return -1;
631
                    return 0;
632
                }
633
            });
634
            1.5.0/docs/api/java/lang/String.html">String unidadeSalasPath = criarChartETabelaMediaGruposPorUnidade(500,30, unidadesStats,
635
                    PerguntasGrupoQueryDao.GRUPO_UNIDADE_CODE_PERGUNTAS,
636
                    null,
637
                    PerguntasGrupoQueryDao.GRUPO_SALAS_CODE_PERGUNTAS,
638
                    null,
639
                    null,
640
                    "unidadeSalasOrderMediaUnidades",
641
                    new 1.5.0/docs/api/java/awt/Color.html">Color[]{ChartBuilderUtil.COLOR_SECTION_GREEN_DARK,ChartBuilderUtil.COLOR_SECTION_ROSE_DARK},
1705 jmachado 642
                    new 1.5.0/docs/api/java/awt/Color.html">Color[]{1.5.0/docs/api/java/awt/Color.html">Color.black,1.5.0/docs/api/java/awt/Color.html">Color.black},
643
                    ommitCourse
1571 jmachado 644
            );
645
 
646
            return unidadeSalasPath;
647
 
648
        } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) {
649
            logger.error(e,e);
650
        }
651
        return null;
652
 
653
    }
654
 
1705 jmachado 655
    private 1.5.0/docs/api/java/lang/String.html">String criarAnaliseConjuntaDeUnidadesOrdenadaMediaSalas(List<UnidadeStats> unidadesStats,boolean ommitCourse)
1571 jmachado 656
    {
657
        try {
658
 
659
            1.5.0/docs/api/java/util/Collections.html">Collections.sort(unidadesStats,new Comparator<UnidadeStats>() {
660
                @1.5.0/docs/api/java/lang/Override.html">Override
661
                public int compare(UnidadeStats o1, UnidadeStats o2) {
662
 
663
                    double sub = (o2.getUnidadeStatsGrupoSalas().getMediasGrupo().getAvaliacaoMedia()
664
                            -
665
                            o1.getUnidadeStatsGrupoSalas().getMediasGrupo().getAvaliacaoMedia());
666
                    if(sub > 0.0)
667
                        return 1;
668
                    else if (sub < 0.0)
669
                        return -1;
670
                    return 0;
671
                }
672
            });
673
            1.5.0/docs/api/java/lang/String.html">String unidadeSalasPath = criarChartETabelaMediaGruposPorUnidade(500,30, unidadesStats,
674
                    PerguntasGrupoQueryDao.GRUPO_UNIDADE_CODE_PERGUNTAS,
675
                    null,
676
                    PerguntasGrupoQueryDao.GRUPO_SALAS_CODE_PERGUNTAS,
677
                    null,
678
                    null,
679
                    "unidadeSalasOrderMediaSalas",
680
                    new 1.5.0/docs/api/java/awt/Color.html">Color[]{ChartBuilderUtil.COLOR_SECTION_GREEN_DARK,ChartBuilderUtil.COLOR_SECTION_ROSE_DARK},
1705 jmachado 681
                    new 1.5.0/docs/api/java/awt/Color.html">Color[]{1.5.0/docs/api/java/awt/Color.html">Color.black,1.5.0/docs/api/java/awt/Color.html">Color.black},
682
                    ommitCourse
1571 jmachado 683
            );
684
 
685
            return unidadeSalasPath;
686
 
687
        } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) {
688
            logger.error(e,e);
689
        }
690
        return null;
691
 
692
    }
693
 
694
 
1570 jmachado 695
    /**
696
     *
697
     * @param semanaContagemCurso List<[count,Week,Year]>
698
     */
699
    private DataTable criarEvolucaoTaxasRespostas(List<Object[]> semanaContagemCurso, int respostasRequisitadas)
700
    {
701
        DataTable tableEvolucaoRespostas = new DataTable();
702
 
703
        DataTable.Row header = tableEvolucaoRespostas.addRowHeader();
704
 
705
        header.addColTextCenter("Semana");
706
        header.addColTextCenter("Respostas obtidas na semana");
707
        header.addColTextCenter("Respostas Acumuladas");
708
        header.addColTextCenter("Por Responder");
709
        header.addColTextCenter("Esperadas");
710
        header.addColTextCenter("%");
711
 
712
        int acumuladas = 0;
713
 
714
        1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat dateFormat = new 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat( "dd-MMM-yyyy" );
715
 
716
        if(semanaContagemCurso.size() > 0)
717
        {
718
            for(5+0%2Fdocs%2Fapi+Object">Object[] semanaObj :  semanaContagemCurso)
719
            {
720
                1.5.0/docs/api/java/lang/Long.html">Long count = (1.5.0/docs/api/java/lang/Long.html">Long) semanaObj[0];
721
                acumuladas += count;
722
                int faltam = respostasRequisitadas - acumuladas;
723
                1.5.0/docs/api/java/lang/Integer.html">Integer semana = (1.5.0/docs/api/java/lang/Integer.html">Integer) semanaObj[1];
724
                1.5.0/docs/api/java/lang/Integer.html">Integer ano = (1.5.0/docs/api/java/lang/Integer.html">Integer) semanaObj[2];
725
                1.5.0/docs/api/java/lang/String.html">String percentagemPrt = ChartBuilderUtil.getPercentagemPrint0Slots(acumuladas,respostasRequisitadas);
726
                double percentagem = ChartBuilderUtil.getPercentagem(acumuladas,respostasRequisitadas);
727
 
728
                1.5.0/docs/api/java/util/Calendar.html">Calendar calendar = 1.5.0/docs/api/java/util/Calendar.html">Calendar.getInstance();
729
                calendar.clear();
730
 
1571 jmachado 731
                calendar.set(1.5.0/docs/api/java/util/Calendar.html">Calendar.YEAR, ano);
732
                calendar.set(1.5.0/docs/api/java/util/Calendar.html">Calendar.WEEK_OF_YEAR, semana);
733
                calendar.set(1.5.0/docs/api/java/util/Calendar.html">Calendar.DAY_OF_WEEK, 7);
1570 jmachado 734
                1.5.0/docs/api/java/lang/String.html">String dataFinalDaSemana = dateFormat.format(calendar.getTime());
735
 
736
                DataTable.Row rowSemana = tableEvolucaoRespostas.addRowNormal();
737
                rowSemana.addColTextCenter(dataFinalDaSemana);
738
                rowSemana.addColNumberRight(count + "");
739
                rowSemana.addColNumberRight(acumuladas + "").setBackgroundColor(DataTable.getColorGradientForPercentage(percentagem/100.0));
740
                rowSemana.addColNumberRight(faltam + "");
741
                rowSemana.addColNumberRight(""+ respostasRequisitadas);
742
                rowSemana.addColPercentageProgressCenter(percentagemPrt);
743
            }
744
        }
745
        return tableEvolucaoRespostas;
746
    }
1574 jmachado 747
 
1585 jmachado 748
 
1574 jmachado 749
    protected ILogMessages runJobServiceTask() throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable
750
    {
751
        long questionarioReportId = 1.5.0/docs/api/java/lang/Long.html">Long.parseLong(getParametersMap().get(ServiceJob.JOB_questionario_report_id_KEY).getObject());
1830 jmachado 752
 
753
 
1574 jmachado 754
        DefaultLogMessages logMessages = new DefaultLogMessages();
1585 jmachado 755
 
756
        int cursosEncontrados = 0;
757
        int cursosProcessados = 0;
758
        int cursosFalhados = 0;
759
        int cursosSemRespostas = 0;
760
        int cursosSemUnidadesAfetas = 0;
761
        int cursosComRespostas = 0;
762
 
763
        QuestionarioReportFileGroupCursosAnoImpl reportGroup = (QuestionarioReportFileGroupCursosAnoImpl) DaoFactory.getQuestionarioReportFileGroupCursosAnoDaoImpl().load(questionarioReportId);
1586 jmachado 764
        reportGroup.setActive(false);
765
        1.5.0/docs/api/java/io/File.html">File reportGroupFolder = new 1.5.0/docs/api/java/io/File.html">File(Globals.TMP_DIR + 1.5.0/docs/api/java/io/File.html">File.separator + "reportGroup" + reportGroup.getId());
1585 jmachado 766
 
767
        anoLectivo = reportGroup.getImportYear();
768
        periodos = reportGroup.getPeriodosArray();
769
        degrees = reportGroup.getDegreesArray();
770
 
771
        1.5.0/docs/api/java/lang/String.html">String msg = "Starting process for Report Cursos (" + questionarioReportId + "): " + reportGroup.getTitle();
772
        serviceLogInfo(msg);
773
        logger.info(msg);
774
 
1830 jmachado 775
        1.5.0/docs/api/java/lang/String.html">String generateOnlyThisSigesCode = null;
776
        List<String> courseCodes = null;
777
        if(getParametersMap().get(ServiceJob.JOB_questionario_sigesCode_KEY) != null)
778
        {
779
            generateOnlyThisSigesCode = getParametersMap().get(ServiceJob.JOB_questionario_sigesCode_KEY).getObject();
780
            msg = "GENERATING ONLY COURSE " + generateOnlyThisSigesCode;
781
            serviceLogInfo(msg);
782
            logger.info(msg);
1585 jmachado 783
 
1830 jmachado 784
            if(reportGroup.getRepositoryStreamZipFile() != null && reportGroup.getRepositoryStreamZipFile().length() > 0)
785
            {
786
                unZipFolder(reportGroup,reportGroupFolder);
787
            }
788
            courseCodes = new ArrayList<String>();
789
            courseCodes.add(generateOnlyThisSigesCode);
790
        }
791
        else
792
             courseCodes = QuestionariosQueryDao.findCoursesSigesCodes(reportGroup.getImportYear(), periodos, degrees);
1585 jmachado 793
 
794
        msg = "Vai processar " + courseCodes.size() + " Cursos ";
795
        serviceLogInfo(msg);
796
        logger.info(msg);  
797
        for(1.5.0/docs/api/java/lang/String.html">String sigesCode: courseCodes)
798
        {
799
            if(sigesCode == null)
800
            {
801
                msg = "Found Course with siges code null, not known but has units in " + reportGroup.getImportYear();
802
                serviceLogInfo(msg);
803
                logger.info(msg);
804
                continue;
805
            }
806
            cursosEncontrados++;
807
 
1586 jmachado 808
            /** COMMIT OPERATION **/   //Tem mais um para contemplar o zip folder operation
809
            setProgress((int)((((float)cursosEncontrados)/((float)courseCodes.size()+1))*100.0f));
1585 jmachado 810
            commitPartially();
1586 jmachado 811
            reportGroup = (QuestionarioReportFileGroupCursosAnoImpl) DaoFactory.getQuestionarioReportFileGroupCursosAnoDaoImpl().load(questionarioReportId);
1585 jmachado 812
            /** COMMIT OPERATION **/
813
 
814
            try{
815
                Course c = DaoFactory.getCourseDaoImpl().findCourseByCode(""+sigesCode);
816
                msg = "(" + cursosEncontrados + "/" + courseCodes.size() + ") Found Course sigesCode: " + sigesCode + " " + c.getName() + " will start process";
817
                serviceLogInfo(msg);
818
                logger.info(msg);
1586 jmachado 819
                CursoPublicReport cursoReport = processCourse("" + sigesCode,reportGroupFolder);
1585 jmachado 820
 
821
 
822
                if(cursoReport == null)
823
                    cursosSemRespostas++;
824
                else{
825
                    1.5.0/docs/api/java/lang/String.html">String tmpPath = cursoReport.getPathGeneratedPdfTemp();
826
 
827
                    QuestionarioReportCursoFile q = DaoFactory.getQuestionarioReportCursoFileDaoImpl().findBySigesCode(1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(sigesCode),reportGroup.getId());
828
                    if(q == null)
829
                    {
830
                        q = new QuestionarioReportCursoFileImpl();
831
                        q.setReportGroup(reportGroup);
832
                        q.setEntityCode("" + sigesCode);
833
                        q.setEntityName(c.getName());
834
                        //q.setCourse(c);
835
                        DaoFactory.getQuestionarioReportCursoFileDaoImpl().save(q);
836
                    }
837
 
1586 jmachado 838
                    q.setActive(true);
1585 jmachado 839
                    q.setInquiridos(cursoReport.getInquiridosTotal());
840
                    q.setInquiridosComResposta(cursoReport.getInquiridosComResposta());
841
                    q.setRespostasRequisitadas(cursoReport.getQuestionariosReqTotal());
842
                    q.setRespostas(cursoReport.getQuestionariosReqRespondidos());
843
                    q.setUnidades(cursoReport.getUnidadesRequisitadas());
1586 jmachado 844
                    q.setPercentagemRespostas(cursoReport.getQuestionariosReqRespondidosPercentagem());
845
                    q.setPercentagemInquiridos(cursoReport.getInquiridosComRespostaPercent());
846
                    q.setCitiesJson(cursoReport.getDistritosJson());
847
                    q.setTipoCurso(cursoReport.getCursoStats().getDegreeDescricao());
848
                    q.setEscola(cursoReport.getCursoStats().getAbreviaturaInstituicao());
849
                    q.setCodigoEscola(cursoReport.getCursoStats().getCodigoNacionalInstituicao());
1585 jmachado 850
 
1830 jmachado 851
                    //serializing DataTable for CourseReports
852
                    DataTable dataTable = cursoReport.getTodasAsRespostasMediasGruposUnidadesESalas();
853
                    1.5.0/docs/api/java/lang/String.html">String courseReportQuestionsXml = dataTable.serializeString();
854
                    1.5.0/docs/api/java/lang/String.html">String json = dataTable.toJson();
855
                    q.setCourseReportQuestionsXml(courseReportQuestionsXml);
856
                    q.setCourseReportQuestionsJson(json);
857
 
858
 
859
 
860
 
1585 jmachado 861
                    //STATS
862
                    if(q.getInquiridos() == 0)
863
                        cursosSemUnidadesAfetas++;
864
                    else if(q.getRespostas() == 0)
865
                        cursosSemRespostas++;
866
                    else
867
                        cursosComRespostas++;
868
 
869
 
870
                    1.5.0/docs/api/java/io/File.html">File tmpFile = new 1.5.0/docs/api/java/io/File.html">File(tmpPath);
1586 jmachado 871
                    1.5.0/docs/api/java/lang/String.html">String descricao = "Relatório dos Resultados do Inquérito Pedagógico aos Alunos - Relatório de Curso Público: " + c.getName() + " (" + sigesCode + ") " + " ano:" + anoLectivo + " periodos:" + 1.5.0/docs/api/java/util/Arrays.html">Arrays.toString(periodos) + " degrees:" + 1.5.0/docs/api/java/util/Arrays.html">Arrays.toString(degrees);
872
                    sendPdfToRepository( q,
873
                            tmpFile,
874
                            descricao,
875
                            ResourceAccessControlEnum.questionariosReportCurso);
876
 
1585 jmachado 877
                }
878
                //Final
879
                cursosProcessados++;
880
            }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
881
            {
882
                msg = "FAIL - Teacher with siges: " + sigesCode;
883
                serviceLogError(msg,e);
884
                logger.error(msg,e);
885
                cursosFalhados++;
886
            }
887
        }
1586 jmachado 888
        /** COMMIT OPERATION **/   //Tem mais um para contemplar o zip folder operation
889
        setProgress((int)((((float)cursosEncontrados)/((float)courseCodes.size()+1))*100.0f));
890
        commitPartially();
891
        reportGroup = (QuestionarioReportFileGroupCursosAnoImpl) DaoFactory.getQuestionarioReportFileGroupCursosAnoDaoImpl().load(questionarioReportId);
1585 jmachado 892
 
893
        serviceLogInfo("######################################");
894
        serviceLogInfo("######################################");
895
        serviceLogInfo("#Cursos Encontrados:" + cursosEncontrados);
896
        serviceLogInfo("#Cursos Processados:" + cursosProcessados);
897
        serviceLogInfo("#Cursos Com Resposta:" + cursosComRespostas);
898
        serviceLogInfo("#Cursos Sem Respostas:" + cursosSemRespostas);
899
        serviceLogInfo("#Cursos Sem Unidades Afetas:" + cursosSemUnidadesAfetas);
900
        serviceLogInfo("#Cursos Falhados:" + cursosFalhados);
901
 
902
        logger.info("######################################");
903
        logger.info("######################################");
904
        logger.info("#Cursos Encontrados:" + cursosEncontrados);
905
        logger.info("#Cursos Processados:" + cursosProcessados);
906
        logger.info("#Cursos Falhados:" + cursosFalhados);
907
        logger.info("#Cursos Com Resposta:" + cursosComRespostas);
908
        logger.info("#Cursos Sem Respostas:" + cursosSemRespostas);
909
        logger.info("#Cursos Sem Unidades Afetas:" + cursosSemUnidadesAfetas);
910
 
911
        reportGroup = (QuestionarioReportFileGroupCursosAnoImpl) DaoFactory.getQuestionarioReportFileGroupCursosAnoDaoImpl().load(questionarioReportId);
912
        reportGroup.setEntidadesEncontradas(cursosEncontrados);
913
        reportGroup.setEntidadesProcessadas(cursosProcessados);
914
        reportGroup.setEntidadesFalhadas(cursosFalhados);
915
        reportGroup.setEntidadesComRespostas(cursosComRespostas);
916
        reportGroup.setEntidadesSemRespostas(cursosSemRespostas);
917
        reportGroup.setEntidadesSemUnidadesAfetas(cursosSemUnidadesAfetas);
918
 
1607 jmachado 919
 
920
        commitPartially();
921
        reportGroup = (QuestionarioReportFileGroupCursosAnoImpl) DaoFactory.getQuestionarioReportFileGroupCursosAnoDaoImpl().load(questionarioReportId);
922
 
923
        logger.info("ziping files");
924
        serviceLogInfo("ziping files");
925
        logMessages.addMessage(new DefaultLogMessage("ziping files", LogMessageTypeEnum.INFO));
926
 
927
        zipFolder(
928
                reportGroup,
929
                reportGroupFolder,
930
                "Relatórios de Curso ZIPADOS " + " ano:" + anoLectivo + " periodos:" + 1.5.0/docs/api/java/util/Arrays.html">Arrays.toString(periodos) + " degrees:" + 1.5.0/docs/api/java/util/Arrays.html">Arrays.toString(degrees),
931
                ResourceAccessControlEnum.questionariosReportCurso);
932
 
1585 jmachado 933
        setProgress(100);
934
        commitPartially();
1607 jmachado 935
 
936
 
937
        logger.info("terminating course reports generation");
938
        serviceLogInfo("terminating course reports generation");
939
        logMessages.addMessage(new DefaultLogMessage("report.docente.gen.terminating", LogMessageTypeEnum.INFO));
940
 
941
 
942
 
1579 jmachado 943
        return logMessages;
1574 jmachado 944
    }
1586 jmachado 945
 
946
 
1569 jmachado 947
}