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