Subversion Repositories bacoAlunos

Rev

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

Rev Author Line No. Line
1814 jmachado 1
package pt.estgp.estgweb.services.courses;
2
 
1830 jmachado 3
 
4
import jomm.dao.impl.AbstractDao;
5
import jomm.utils.StreamsUtils;
1814 jmachado 6
import org.apache.log4j.Logger;
1830 jmachado 7
import org.json.JSONArray;
8
import org.json.JSONException;
9
import org.json.JSONObject;
1814 jmachado 10
import pt.estgp.estgweb.domain.CourseUnit;
1830 jmachado 11
import pt.estgp.estgweb.domain.CourseUnitImpl;
1814 jmachado 12
import pt.estgp.estgweb.domain.dao.DaoFactory;
1830 jmachado 13
import pt.estgp.estgweb.services.courses.coursereport.CourseReportUtils;
14
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.*;
15
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.courseunitreport.CourseUnitSection;
16
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components.UnitsLearningResultSemester;
17
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components.UnitsLearningResultUc;
18
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components.UnitsLearningResultYear;
19
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components.UnitsLearningResultsTable;
20
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.reportucsummary.CourseUnitDtpStat;
21
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.reportucsummary.UnitDtpSemester;
22
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.reportucsummary.UnitsDtpTable;
23
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.surveys.SurveysResultsSection;
24
import pt.estgp.estgweb.services.questionarios.QuestionariosReportsService;
25
import pt.estgp.estgweb.services.questionarios.pedagogico.reportprocessors.utils.DataTable;
26
import pt.estgp.estgweb.utils.Globals;
27
import pt.estgp.estgweb.utils.documentBuilder.DocumentSection;
28
import pt.estgp.estgweb.utils.documentBuilder.QuestionariosDataTableComponent;
1814 jmachado 29
import pt.utl.ist.berserk.logic.serviceManager.IService;
30
 
1830 jmachado 31
import java.io.IOException;
32
import java.io.InputStream;
33
import java.net.URL;
34
import java.util.*;
1814 jmachado 35
 
36
/**
37
 * Created by jorgemachado on 14/10/17.
38
 */
39
public class CourseReportServices implements IService
40
{
41
    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(CourseReportServices.class);
42
 
1830 jmachado 43
 
44
 
45
 
46
 
47
 
48
 
49
    /****************************************************************************/
50
    /* SERVICOS CORE DOS REPORTS
51
    /****************************************************************************/
52
 
53
 
54
    /**
55
     * Gera uma tabela de estatisticas dos DTP recorrendo ao servico WS de
56
     * load de tabelas DTP, caso o serviço nao devolva unidades são criadas novas
57
     * com os valores a falso.
58
     *
59
     * @param courseCode
60
     * @param year
61
     * @return UnitsDtpTable
62
     * @throws IOException
63
     * @throws JSONException
64
     */
65
    public UnitsDtpTable updateDtpStatsTable4Course(ReportCourseDocument reportCourseDocument, 1.5.0/docs/api/java/lang/String.html">String courseCode, 1.5.0/docs/api/java/lang/String.html">String year) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException
1814 jmachado 66
    {
1830 jmachado 67
 
68
        ReportsUcSummarySection reportsUcSummarySection = (ReportsUcSummarySection) reportCourseDocument.findDocumentSection(ReportsUcSummarySection.class);
69
        UnitsDtpTable unitsDtpTable = (UnitsDtpTable) reportsUcSummarySection.findDocComponent(UnitsDtpTable.class);
70
        UnitDtpSemester semester1 = new UnitDtpSemester();
71
        UnitDtpSemester semester2 = new UnitDtpSemester();
72
        unitsDtpTable.setSemester1(semester1);
73
        unitsDtpTable.setSemester1(semester2);
74
 
75
        List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year);
76
 
77
        1.5.0/docs/api/java/lang/String.html">String json = loadCourseUnitDtpStats(courseCode,year);
78
        JSONObject response = new JSONObject(json);
79
        JSONArray stats = (JSONArray) ((JSONObject)response.get("response")).get("dtpstats");
80
        CourseUnitDtpStat[] statsLoaded = CourseUnitDtpStat.fromJson(stats);
81
 
82
        for(CourseUnit cu :units)
1814 jmachado 83
        {
1830 jmachado 84
            CourseUnitDtpStat statFound = CourseReportUtils.findCourseUnitDtpStat(statsLoaded, (CourseUnitImpl) cu);
85
            if(statFound == null)
1814 jmachado 86
            {
1830 jmachado 87
                statFound = CourseReportUtils.createCourseUnitDtpStat(cu);
1814 jmachado 88
            }
1830 jmachado 89
 
90
            if(((CourseUnitImpl) cu).getSemestreAbsolutoS1S2().equals("S1"))
91
                semester1.getCourseUnitDtpStats().add(statFound);
92
            else
93
                semester2.getCourseUnitDtpStats().add(statFound);
94
        }
95
 
96
        return unitsDtpTable;
97
 
98
    }
99
 
100
    /**
101
     *
102
     * @param courseCode
103
     * @param year
104
     * @return
105
     * @throws IOException
106
     * @throws JSONException
107
     */
108
    public ReportCourseDocument createNewCourseReportDocument(1.5.0/docs/api/java/lang/String.html">String courseCode,1.5.0/docs/api/java/lang/String.html">String year) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException
109
    {
110
        ReportCourseDocument reportCourseDocument = new ReportCourseDocument();
111
        reportCourseDocument.init();
112
 
113
        List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year);
114
 
115
        //FIRST SERVICE TO CALL TO OBTAIN UNITS AND EVALUATIONS
116
        //THIS IS THE BASE FOR THE REMAIN SERVICE CALLS
117
        List<DocumentSection> courseUnitSections = updateCleanCourseUnitSections(courseCode, year, reportCourseDocument, units);
118
 
119
        //A tabela de resultados globais não vai ser utilizada
120
        UnitsLearningResultsTable unitsLearningResultsTable = updateCleanLearningResultsFromCourseUnitsSections(reportCourseDocument);
121
 
122
 
123
        //Atualiza no DOC a tabela de analise DTP
124
        UnitsDtpTable unitsDtpTable = updateDtpStatsTable4Course(reportCourseDocument, courseCode, year);
125
 
126
 
127
        //Atualiza as tabelas dos Quesitonários pedagogicos
128
        SurveysResultsSection surveysResultsSection = updateSurveysDataTables(courseCode, year, reportCourseDocument);
129
 
130
 
131
        return reportCourseDocument;
132
    }
133
 
134
    public SurveysResultsSection updateSurveysDataTables(1.5.0/docs/api/java/lang/String.html">String courseCode, 1.5.0/docs/api/java/lang/String.html">String year, ReportCourseDocument reportCourseDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException {
135
        SurveysSection surveysSection = (SurveysSection) reportCourseDocument.findDocumentSection(SurveysSection.class);
136
        SurveysResultsSection surveysResultsSection = (SurveysResultsSection) surveysSection.findSubSection(SurveysResultsSection.class);
137
        QuestionariosDataTableComponent dataTableComponentS1 = (QuestionariosDataTableComponent) surveysResultsSection.getComponents().get(0);
138
        QuestionariosDataTableComponent dataTableComponentS2 = (QuestionariosDataTableComponent) surveysResultsSection.getComponents().get(1);
139
 
140
        QuestionariosReportsService questionariosReportsService = new QuestionariosReportsService();
141
        1.5.0/docs/api/java/lang/String.html">String jsonDataTableS1 = questionariosReportsService.loadReportUnidadesSalasJson(courseCode,year,"S1");
142
        1.5.0/docs/api/java/lang/String.html">String jsonDataTableS2 = questionariosReportsService.loadReportUnidadesSalasJson(courseCode,year,"S2");
143
        DataTable dataTableS1 = DataTable.fromJson(jsonDataTableS1);
144
        DataTable dataTableS2 = DataTable.fromJson(jsonDataTableS2);
145
        dataTableComponentS1.setDataTable(dataTableS1);
146
        dataTableComponentS2.setDataTable(dataTableS2);
147
        return surveysResultsSection;
148
    }
149
 
150
    /**
151
     * Este serviço atualiza a tabela de resultados de aprendizagem com base nas courseunitssections
152
     * @param reportCourseDocument
153
     * @return UnitsLearningResultsTable
154
     */
155
    public UnitsLearningResultsTable updateCleanLearningResultsFromCourseUnitsSections(ReportCourseDocument reportCourseDocument) {
156
        CourseUnitsReportsSection unitReportsSection = (CourseUnitsReportsSection) reportCourseDocument.findDocumentSection(CourseUnitsReportsSection.class);
157
 
158
        LearningResultsSection learningResultsSection = (LearningResultsSection) reportCourseDocument.findDocumentSection(LearningResultsSection.class);
159
        UnitsLearningResultsTable learningResultsTable = (UnitsLearningResultsTable) learningResultsSection.findDocComponent(UnitsLearningResultsTable.class);
160
 
161
        Map<Integer,UnitsLearningResultYear> anosPlano = new HashMap<Integer, UnitsLearningResultYear>();
162
        Map<String,UnitsLearningResultSemester> anoSemestre = new HashMap<String, UnitsLearningResultSemester>();
163
        for(DocumentSection subSection : unitReportsSection.getSubSections())
164
        {
165
            CourseUnitSection unitSection = (CourseUnitSection) subSection;
166
            int anoPlano = unitSection.getAnoPlano();
167
            UnitsLearningResultYear anoFound = anosPlano.get(anoPlano);
168
            if(anoFound == null)
1814 jmachado 169
            {
1830 jmachado 170
                anoFound = new UnitsLearningResultYear(anoPlano);
171
                anosPlano.put(anoPlano,anoFound);
172
                learningResultsTable.getYears().add(anoFound);
1814 jmachado 173
            }
174
 
1830 jmachado 175
            1.5.0/docs/api/java/lang/String.html">String semestreCode = ((CourseUnitSection) subSection).getPeriod();
176
            UnitsLearningResultSemester semestreFound = anoSemestre.get(anoPlano + "$" + semestreCode);
177
            if(semestreFound == null)
1814 jmachado 178
            {
1830 jmachado 179
                semestreFound = new UnitsLearningResultSemester(semestreCode);
180
                anoSemestre.put(anoPlano + "$" + semestreCode,semestreFound);
181
                anoFound.getSemesters().add(semestreFound);
1814 jmachado 182
            }
1830 jmachado 183
 
184
            UnitsLearningResultUc uc = new UnitsLearningResultUc();
185
            uc.setPeriod(semestreCode);
186
            uc.setName(unitSection.getName());
187
            uc.setSigesCode(unitSection.getSigesCode());
188
            if(unitSection.getCourseUnitEvaluation() != null)
189
            {
190
                uc.setAlunosInscritos(1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(unitSection.getCourseUnitEvaluation().getNumAlunosInscritos()));
191
 
192
                uc.setAprovados1013(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1013());
193
                uc.setAprovados1416(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1416());
194
                uc.setAprovados1720(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1720());
195
                uc.setSemElementos(unitSection.getCourseUnitEvaluation().getNumAlunosSemElementosAvaliacao());
196
                uc.setAprovados(unitSection.getCourseUnitEvaluation().getNumAlunosAprovTotal());
197
                uc.setReprovados(unitSection.getCourseUnitEvaluation().getNumAlunosReprovados());
198
 
199
                if(uc.getAlunosInscritos() > 0)
200
                {
201
                    uc.setAprovadosPercent((float) (uc.getAprovados() * 100.0 / uc.getAlunosInscritos()));
202
                    uc.setReprovadosPercent((float) (uc.getReprovados() * 100.0 / uc.getAlunosInscritos()));
203
                    uc.setSemElementosPercent((float) (uc.getSemElementos() * 100.0 / uc.getAlunosInscritos()));
204
                }
205
 
206
                if(uc.getAprovados() > 0)
207
                {
208
                    uc.setAprovados1013Percent((float) (uc.getAprovados1013() * 100.0 / uc.getAprovados()));
209
                    uc.setAprovados1416Percent((float) (uc.getAprovados1416() * 100.0 / uc.getAprovados()));
210
                    uc.setAprovados1720Percent((float) (uc.getAprovados1720() * 100.0 / uc.getAprovados()));
211
                }
212
            }
213
            semestreFound.getUcs().add(uc);
1814 jmachado 214
        }
1830 jmachado 215
 
216
        1.5.0/docs/api/java/util/Collections.html">Collections.sort(learningResultsTable.getYears(), new Comparator<UnitsLearningResultYear>() {
217
            @1.5.0/docs/api/java/lang/Override.html">Override
218
            public int compare(UnitsLearningResultYear o1, UnitsLearningResultYear o2) {
219
                return o1.getAno() - o2.getAno();
220
            }
221
        });
222
 
223
        for(UnitsLearningResultYear learningYearLine: learningResultsTable.getYears())
224
        {
225
            1.5.0/docs/api/java/util/Collections.html">Collections.sort(learningYearLine.getSemesters(),new Comparator<UnitsLearningResultSemester>() {
226
                @1.5.0/docs/api/java/lang/Override.html">Override
227
                public int compare(UnitsLearningResultSemester o1, UnitsLearningResultSemester o2) {
228
                    return o1.getSemestre().compareTo(o2.getSemestre());
229
                }
230
            });
231
        }
232
 
233
        float totalCumProgPercentGlobal = 0;
234
        int totalInscritosGlobal = 0;
235
        float totalReprovadosPercentGlobal = 0;
236
        float totalAprovadosPercentGlobal = 0;
237
        float totalSemElementosPercentGlobal = 0;
238
        int totalAprovados1013PercentGlobal = 0;
239
        float totalAprovados1416PercentGlobal = 0;
240
        float totalAprovados1720PercentGlobal = 0;
241
        for(UnitsLearningResultYear learningYearLine: learningResultsTable.getYears())
242
        {
243
            float totalCumProgPercentAno = 0;
244
            int totalInscritosAno = 0;
245
            float totalReprovadosPercentAno = 0;
246
            float totalAprovadosPercentAno = 0;
247
            float totalSemElementosPercentAno = 0;
248
            int totalAprovados1013PercentAno = 0;
249
            float totalAprovados1416PercentAno = 0;
250
            float totalAprovados1720PercentAno = 0;
251
 
252
            for(UnitsLearningResultSemester semester: learningYearLine.getSemesters())
253
            {
254
                float totalCumProgPercent = 0;
255
                int totalInscritos = 0;
256
                float totalReprovadosPercent = 0;
257
                float totalAprovadosPercent = 0;
258
                float totalSemElementosPercent = 0;
259
                int totalAprovados1013Percent = 0;
260
                float totalAprovados1416Percent = 0;
261
                float totalAprovados1720Percent = 0;
262
                for(UnitsLearningResultUc uc: semester.getUcs())
263
                {
264
                    totalCumProgPercent += uc.getCumprimentoProgramaPercent();
265
                    totalInscritos += uc.getAlunosInscritos();
266
                    totalAprovadosPercent += uc.getAprovadosPercent();
267
                    totalReprovadosPercent += uc.getReprovadosPercent();
268
                    totalSemElementosPercent += uc.getSemElementosPercent();
269
                    totalAprovados1013Percent += uc.getAprovados1013();
270
                    totalAprovados1416Percent += uc.getAprovados1416();
271
                    totalAprovados1720Percent += uc.getAprovados1720();
272
                }
273
                //media de inscritos
274
                if(semester.getUcs().size() > 0)
275
                {
276
                    semester.setCumprimentoProgramaPercent( totalCumProgPercent / ((float)semester.getUcs().size()));
277
                    semester.setAlunosInscritos( totalInscritos  / (semester.getUcs().size()));
278
                    semester.setAprovadosPercent( totalAprovadosPercent  / ((float)semester.getUcs().size()));
279
                    semester.setReprovadosPercent( totalReprovadosPercent  / ((float)semester.getUcs().size()));
280
                    semester.setSemElementosPercent( totalSemElementosPercent / ((float)semester.getUcs().size()));
281
                    semester.setAprovados1013Percent( totalAprovados1013Percent / ((float)semester.getUcs().size()));
282
                    semester.setAprovados1416Percent( totalAprovados1416Percent / ((float)semester.getUcs().size()));
283
                    semester.setAprovados1720Percent( totalAprovados1720Percent / ((float)semester.getUcs().size()));
284
                }
285
                totalCumProgPercentAno += semester.getCumprimentoProgramaPercent();
286
                totalInscritosAno += semester.getAlunosInscritos();
287
                totalAprovadosPercentAno += semester.getAprovadosPercent();
288
                totalReprovadosPercentAno += semester.getReprovadosPercent();
289
                totalSemElementosPercentAno += semester.getSemElementosPercent();
290
                totalAprovados1013PercentAno += semester.getAprovados1013();
291
                totalAprovados1416PercentAno += semester.getAprovados1416();
292
                totalAprovados1720PercentAno += semester.getAprovados1720();
293
            }
294
            //media de inscritos
295
            if(learningYearLine.getSemesters().size() > 0)
296
            {
297
                learningYearLine.setCumprimentoProgramaPercent( totalCumProgPercentAno / ((float)learningYearLine.getSemesters().size()));
298
                learningYearLine.setAlunosInscritos( totalInscritosAno  / (learningYearLine.getSemesters().size()));
299
                learningYearLine.setAprovadosPercent( totalAprovadosPercentAno  / ((float)learningYearLine.getSemesters().size()));
300
                learningYearLine.setReprovadosPercent( totalReprovadosPercentAno  / ((float)learningYearLine.getSemesters().size()));
301
                learningYearLine.setSemElementosPercent( totalSemElementosPercentAno / ((float)learningYearLine.getSemesters().size()));
302
                learningYearLine.setAprovados1013Percent( totalAprovados1013PercentAno / ((float)learningYearLine.getSemesters().size()));
303
                learningYearLine.setAprovados1416Percent( totalAprovados1416PercentAno / ((float)learningYearLine.getSemesters().size()));
304
                learningYearLine.setAprovados1720Percent( totalAprovados1720PercentAno / ((float)learningYearLine.getSemesters().size()));
305
            }
306
            totalCumProgPercentGlobal += learningYearLine.getCumprimentoProgramaPercent();
307
            totalInscritosGlobal += learningYearLine.getAlunosInscritos();
308
            totalAprovadosPercentGlobal += learningYearLine.getAprovadosPercent();
309
            totalReprovadosPercentGlobal += learningYearLine.getReprovadosPercent();
310
            totalSemElementosPercentGlobal += learningYearLine.getSemElementosPercent();
311
            totalAprovados1013PercentGlobal += learningYearLine.getAprovados1013();
312
            totalAprovados1416PercentGlobal += learningYearLine.getAprovados1416();
313
            totalAprovados1720PercentGlobal += learningYearLine.getAprovados1720();
314
        }
315
 
316
        if(learningResultsTable.getYears().size() > 0)
317
        {
318
            learningResultsTable.setCumprimentoProgramaPercent( totalCumProgPercentGlobal / ((float)learningResultsTable.getYears().size()));
319
            learningResultsTable.setAlunosInscritos( totalInscritosGlobal  / (learningResultsTable.getYears().size()));
320
            learningResultsTable.setAprovadosPercent( totalAprovadosPercentGlobal  / ((float)learningResultsTable.getYears().size()));
321
            learningResultsTable.setReprovadosPercent( totalReprovadosPercentGlobal  / ((float)learningResultsTable.getYears().size()));
322
            learningResultsTable.setSemElementosPercent( totalSemElementosPercentGlobal / ((float)learningResultsTable.getYears().size()));
323
            learningResultsTable.setAprovados1013Percent( totalAprovados1013PercentGlobal / ((float)learningResultsTable.getYears().size()));
324
            learningResultsTable.setAprovados1416Percent( totalAprovados1416PercentGlobal / ((float)learningResultsTable.getYears().size()));
325
            learningResultsTable.setAprovados1720Percent( totalAprovados1720PercentGlobal / ((float)learningResultsTable.getYears().size()));
326
        }
327
 
328
 
329
 
330
 
331
        return learningResultsTable;
332
        //CRIAR A TABELA DE RESUTLADOS GLOBAIS GERAIS COMO UM RESUMO DA ANTERIOR
333
        /*for(UnitsLearningResultYear learningYearLine: learningResultsTable.getYears())
334
        {
335
 
336
        }*/
1814 jmachado 337
    }
338
 
1830 jmachado 339
 
340
    /**
341
     * Update course unit sections with reports, this method dows not change learning results table
342
     * values from learning results stays in unit but does not change learning results Table
343
     * @param courseCode
344
     * @param year
345
     * @param reportCourseDocument
346
     * @param units
347
     * @throws JSONException
348
     * @throws IOException
349
     * @return a list of CourseUnitSection
350
     */
351
    public List<DocumentSection> updateCleanCourseUnitSections(1.5.0/docs/api/java/lang/String.html">String courseCode, 1.5.0/docs/api/java/lang/String.html">String year, ReportCourseDocument reportCourseDocument, List<CourseUnit> units) throws JSONException, 1.5.0/docs/api/java/io/IOException.html">IOException {
352
        1.5.0/docs/api/java/lang/String.html">String courseUnitSectionsJson = loadCourseEvaluationSections(courseCode,year);
353
        JSONObject object = new JSONObject(courseUnitSectionsJson);
354
        JSONArray evaluations = object.getJSONArray("evaluations");
355
        CourseUnitSection[] courseUnitSections = CourseUnitSection.fromJsonArray(evaluations.toString());
356
 
357
        CourseUnitsReportsSection unitReportsSection = (CourseUnitsReportsSection) reportCourseDocument.findDocumentSection(CourseUnitsReportsSection.class);
358
        List<DocumentSection> subSections = new ArrayList<DocumentSection>();
359
        unitReportsSection.setSubSections(subSections);
360
        for(CourseUnit cu :units)
361
        {
362
            CourseUnitSection sectionFound = CourseReportUtils.findCourseUnitSection(courseUnitSections, (CourseUnitImpl) cu);
363
            if(sectionFound == null)
364
            {
365
                sectionFound = CourseReportUtils.createCourseUnitEvaluationSection((CourseUnitImpl) cu);
366
            }
367
            unitReportsSection.getSubSections().add(sectionFound);
368
        }
369
        return subSections;
370
    }
371
 
372
 
373
 
374
    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, JSONException {
375
        AbstractDao.getCurrentSession().beginTransaction();
376
 
377
        ReportCourseDocument reportCourseDocument = new CourseReportServices().createNewCourseReportDocument("9119","201516");
378
        1.5.0/docs/api/java/lang/System.html">System.out.println(reportCourseDocument.toJson());
379
        AbstractDao.getCurrentSession().getTransaction().commit();
380
    }
381
 
382
    /*
383
 
384
    public String loadUnitsAndCreateLearningResultsTables4Course(String courseCode, String year) throws IOException, JSONException
385
    {
386
 
387
    }
388
    */
389
    //TODO loadUnitsAndCreateLearningResultsTables4Course
390
    //HIPOTESE DEVOLVER DOIS OBJECTOS
391
    //SERVICO DE ARRANQUE
392
    //DEVOLVE UM REPORT DOCUMENT E O CHAMADOR USA O QUE QUISER
393
    //A GERACAO DE GRAFICOS FAZ-SE APENAS A PEDIDO
394
 
395
    // SE ELE PEDIR PARA ATUALIZAR TUDO CARREGA-SE UNIDADES E TABELAS NU DOC NOVO
396
    // E NO BROWSER SUBSTITUI-SE ESSES ELEMENTOS NOS ANTIGOS a seccao das unidades
397
    // e as as tabelas
398
 
399
 
400
 
401
 
402
 
403
 
404
 
405
 
406
 
407
    /****************************************************************************/
408
    /* SERVICOS WS-API
409
    /****************************************************************************/
410
 
411
 
412
    /**
413
     * This service loads a list of course units given course code and year
414
     * with dtp stats codes pre-filled
415
     * @param courseCode
416
     * @param year
417
     * @return
418
     * @throws JSONException
419
     * @throws IOException
420
     */
421
    public 1.5.0/docs/api/java/lang/String.html">String loadCourseUnitDtpStats(1.5.0/docs/api/java/lang/String.html">String courseCode,1.5.0/docs/api/java/lang/String.html">String year) throws JSONException, 1.5.0/docs/api/java/io/IOException.html">IOException {
422
 
423
 
424
        if(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_DTP_STATS.indexOf("localhost")>=0)
425
        {
426
            JSONArray array = new JSONArray();
427
            List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year);
428
            for(CourseUnit cu: units)
429
            {
430
                CourseUnitDtpStat stat = CourseReportUtils.createCourseUnitDtpStat(cu);
431
                //sections.add(courseUnitSection);
432
                array.put(stat.toJsonObject());
433
            }
434
 
435
            JSONObject obj = new JSONObject();
436
            obj.put("dtpstats",array);
437
 
438
            return obj.toString();
439
        }
440
        else
441
        {
442
            1.5.0/docs/api/java/net/URL.html">URL url = new 1.5.0/docs/api/java/net/URL.html">URL(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_DTP_STATS + "?code=" + courseCode  + "&year=" + year);
443
            5+0%2Fdocs%2Fapi+InputStream">InputStream is = url.openStream();
444
 
445
            1.5.0/docs/api/java/lang/String.html">String json = StreamsUtils.readString(is);
446
            is.close();
447
            //TODO temos de extrair o resultado do RESPONSE
448
            JSONObject jsonObject = new JSONObject(json);
449
            return jsonObject.getString("response").toString();
450
        }
451
    }
452
 
453
 
454
 
455
 
456
    /**
457
     *
458
     * Para um determinado curso e ano o serviço faz uma listagem de todas as suas unidades curriculares
459
     * e lista a sua informação básica juntamente com o relatório de avaliação disponivel
460
     * O serviço adiciona ainda o Ano de cada unidade por inspeção do Plano de Estudos
461
     * caso a unidade não seja encontrada no Plano de estudos o ano irá ser preenchido com -1
462
     *
463
     * @param courseCode codigo Siges na base de dados
464
     * @param year  201617, 201718
465
     * @return String JSONObject with a JSON ARRAY of List<CourseUnitSection>
466
     */
467
    public 1.5.0/docs/api/java/lang/String.html">String loadCourseEvaluationSections(1.5.0/docs/api/java/lang/String.html">String courseCode,1.5.0/docs/api/java/lang/String.html">String year) throws JSONException, 1.5.0/docs/api/java/io/IOException.html">IOException {
468
 
469
 
470
        if(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_EVALUATION.indexOf("localhost")>=0)
471
        {
472
            JSONArray array = new JSONArray();
473
            List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year);
474
            for(CourseUnit cu: units)
475
            {
476
                CourseUnitSection courseUnitSection = CourseReportUtils.createCourseUnitEvaluationSection((CourseUnitImpl) cu);
477
                array.put(courseUnitSection.toJsonObject());
478
            }
479
 
480
            JSONObject obj = new JSONObject();
481
            obj.put("evaluations",array);
482
 
483
            return obj.toString();
484
        }
485
        else
486
        {
487
            1.5.0/docs/api/java/net/URL.html">URL url = new 1.5.0/docs/api/java/net/URL.html">URL(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_EVALUATION + "?code=" + courseCode  + "&year=" + year);
488
            5+0%2Fdocs%2Fapi+InputStream">InputStream is = url.openStream();
489
 
490
            1.5.0/docs/api/java/lang/String.html">String json = StreamsUtils.readString(is);
491
            is.close();
492
            JSONObject jsonObject = new JSONObject(json);
493
            return jsonObject.getString("response").toString();
494
        }
495
    }
496
 
497
 
1814 jmachado 498
}