Rev 1837 | Rev 1842 | 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); |
||
75 | unitsDtpTable.setSemester1(semester2); |
||
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 | |||
1841 | jmachado | 195 | uc.setAlunosInscritos(unitSection.getCourseUnitEvaluation().getNumAlunosInscritos()); |
196 | |||
1830 | jmachado | 197 | uc.setAprovados1013(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1013()); |
198 | uc.setAprovados1416(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1416()); |
||
199 | uc.setAprovados1720(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1720()); |
||
200 | uc.setSemElementos(unitSection.getCourseUnitEvaluation().getNumAlunosSemElementosAvaliacao()); |
||
201 | uc.setAprovados(unitSection.getCourseUnitEvaluation().getNumAlunosAprovTotal()); |
||
202 | uc.setReprovados(unitSection.getCourseUnitEvaluation().getNumAlunosReprovados()); |
||
203 | |||
204 | if(uc.getAlunosInscritos() > 0) |
||
205 | { |
||
206 | uc.setAprovadosPercent((float) (uc.getAprovados() * 100.0 / uc.getAlunosInscritos())); |
||
207 | uc.setReprovadosPercent((float) (uc.getReprovados() * 100.0 / uc.getAlunosInscritos())); |
||
208 | uc.setSemElementosPercent((float) (uc.getSemElementos() * 100.0 / uc.getAlunosInscritos())); |
||
209 | } |
||
210 | |||
211 | if(uc.getAprovados() > 0) |
||
212 | { |
||
213 | uc.setAprovados1013Percent((float) (uc.getAprovados1013() * 100.0 / uc.getAprovados())); |
||
214 | uc.setAprovados1416Percent((float) (uc.getAprovados1416() * 100.0 / uc.getAprovados())); |
||
215 | uc.setAprovados1720Percent((float) (uc.getAprovados1720() * 100.0 / uc.getAprovados())); |
||
216 | } |
||
217 | } |
||
218 | semestreFound.getUcs().add(uc); |
||
1814 | jmachado | 219 | } |
1830 | jmachado | 220 | |
221 | 1.5.0/docs/api/java/util/Collections.html">Collections.sort(learningResultsTable.getYears(), new Comparator<UnitsLearningResultYear>() { |
||
222 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
223 | public int compare(UnitsLearningResultYear o1, UnitsLearningResultYear o2) { |
||
224 | return o1.getAno() - o2.getAno(); |
||
225 | } |
||
226 | }); |
||
227 | |||
228 | for(UnitsLearningResultYear learningYearLine: learningResultsTable.getYears()) |
||
229 | { |
||
230 | 1.5.0/docs/api/java/util/Collections.html">Collections.sort(learningYearLine.getSemesters(),new Comparator<UnitsLearningResultSemester>() { |
||
231 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
232 | public int compare(UnitsLearningResultSemester o1, UnitsLearningResultSemester o2) { |
||
233 | return o1.getSemestre().compareTo(o2.getSemestre()); |
||
234 | } |
||
235 | }); |
||
236 | } |
||
237 | |||
1841 | jmachado | 238 | |
239 | //UPDATE TOTAIS DE SEMESTRES E DE ANOS |
||
1830 | jmachado | 240 | float totalCumProgPercentGlobal = 0; |
241 | int totalInscritosGlobal = 0; |
||
242 | float totalReprovadosPercentGlobal = 0; |
||
243 | float totalAprovadosPercentGlobal = 0; |
||
244 | float totalSemElementosPercentGlobal = 0; |
||
245 | int totalAprovados1013PercentGlobal = 0; |
||
246 | float totalAprovados1416PercentGlobal = 0; |
||
247 | float totalAprovados1720PercentGlobal = 0; |
||
248 | for(UnitsLearningResultYear learningYearLine: learningResultsTable.getYears()) |
||
249 | { |
||
250 | float totalCumProgPercentAno = 0; |
||
251 | int totalInscritosAno = 0; |
||
252 | float totalReprovadosPercentAno = 0; |
||
253 | float totalAprovadosPercentAno = 0; |
||
254 | float totalSemElementosPercentAno = 0; |
||
255 | int totalAprovados1013PercentAno = 0; |
||
256 | float totalAprovados1416PercentAno = 0; |
||
257 | float totalAprovados1720PercentAno = 0; |
||
258 | |||
259 | for(UnitsLearningResultSemester semester: learningYearLine.getSemesters()) |
||
260 | { |
||
261 | float totalCumProgPercent = 0; |
||
262 | int totalInscritos = 0; |
||
263 | float totalReprovadosPercent = 0; |
||
264 | float totalAprovadosPercent = 0; |
||
265 | float totalSemElementosPercent = 0; |
||
266 | int totalAprovados1013Percent = 0; |
||
267 | float totalAprovados1416Percent = 0; |
||
268 | float totalAprovados1720Percent = 0; |
||
269 | for(UnitsLearningResultUc uc: semester.getUcs()) |
||
270 | { |
||
271 | totalCumProgPercent += uc.getCumprimentoProgramaPercent(); |
||
272 | totalInscritos += uc.getAlunosInscritos(); |
||
273 | totalAprovadosPercent += uc.getAprovadosPercent(); |
||
274 | totalReprovadosPercent += uc.getReprovadosPercent(); |
||
275 | totalSemElementosPercent += uc.getSemElementosPercent(); |
||
276 | totalAprovados1013Percent += uc.getAprovados1013(); |
||
277 | totalAprovados1416Percent += uc.getAprovados1416(); |
||
278 | totalAprovados1720Percent += uc.getAprovados1720(); |
||
279 | } |
||
280 | //media de inscritos |
||
281 | if(semester.getUcs().size() > 0) |
||
282 | { |
||
283 | semester.setCumprimentoProgramaPercent( totalCumProgPercent / ((float)semester.getUcs().size())); |
||
284 | semester.setAlunosInscritos( totalInscritos / (semester.getUcs().size())); |
||
285 | semester.setAprovadosPercent( totalAprovadosPercent / ((float)semester.getUcs().size())); |
||
286 | semester.setReprovadosPercent( totalReprovadosPercent / ((float)semester.getUcs().size())); |
||
287 | semester.setSemElementosPercent( totalSemElementosPercent / ((float)semester.getUcs().size())); |
||
288 | semester.setAprovados1013Percent( totalAprovados1013Percent / ((float)semester.getUcs().size())); |
||
289 | semester.setAprovados1416Percent( totalAprovados1416Percent / ((float)semester.getUcs().size())); |
||
290 | semester.setAprovados1720Percent( totalAprovados1720Percent / ((float)semester.getUcs().size())); |
||
291 | } |
||
292 | totalCumProgPercentAno += semester.getCumprimentoProgramaPercent(); |
||
293 | totalInscritosAno += semester.getAlunosInscritos(); |
||
294 | totalAprovadosPercentAno += semester.getAprovadosPercent(); |
||
295 | totalReprovadosPercentAno += semester.getReprovadosPercent(); |
||
296 | totalSemElementosPercentAno += semester.getSemElementosPercent(); |
||
297 | totalAprovados1013PercentAno += semester.getAprovados1013(); |
||
298 | totalAprovados1416PercentAno += semester.getAprovados1416(); |
||
299 | totalAprovados1720PercentAno += semester.getAprovados1720(); |
||
300 | } |
||
301 | //media de inscritos |
||
302 | if(learningYearLine.getSemesters().size() > 0) |
||
303 | { |
||
304 | learningYearLine.setCumprimentoProgramaPercent( totalCumProgPercentAno / ((float)learningYearLine.getSemesters().size())); |
||
305 | learningYearLine.setAlunosInscritos( totalInscritosAno / (learningYearLine.getSemesters().size())); |
||
306 | learningYearLine.setAprovadosPercent( totalAprovadosPercentAno / ((float)learningYearLine.getSemesters().size())); |
||
307 | learningYearLine.setReprovadosPercent( totalReprovadosPercentAno / ((float)learningYearLine.getSemesters().size())); |
||
308 | learningYearLine.setSemElementosPercent( totalSemElementosPercentAno / ((float)learningYearLine.getSemesters().size())); |
||
309 | learningYearLine.setAprovados1013Percent( totalAprovados1013PercentAno / ((float)learningYearLine.getSemesters().size())); |
||
310 | learningYearLine.setAprovados1416Percent( totalAprovados1416PercentAno / ((float)learningYearLine.getSemesters().size())); |
||
311 | learningYearLine.setAprovados1720Percent( totalAprovados1720PercentAno / ((float)learningYearLine.getSemesters().size())); |
||
312 | } |
||
313 | totalCumProgPercentGlobal += learningYearLine.getCumprimentoProgramaPercent(); |
||
314 | totalInscritosGlobal += learningYearLine.getAlunosInscritos(); |
||
315 | totalAprovadosPercentGlobal += learningYearLine.getAprovadosPercent(); |
||
316 | totalReprovadosPercentGlobal += learningYearLine.getReprovadosPercent(); |
||
317 | totalSemElementosPercentGlobal += learningYearLine.getSemElementosPercent(); |
||
318 | totalAprovados1013PercentGlobal += learningYearLine.getAprovados1013(); |
||
319 | totalAprovados1416PercentGlobal += learningYearLine.getAprovados1416(); |
||
320 | totalAprovados1720PercentGlobal += learningYearLine.getAprovados1720(); |
||
321 | } |
||
322 | |||
323 | if(learningResultsTable.getYears().size() > 0) |
||
324 | { |
||
325 | learningResultsTable.setCumprimentoProgramaPercent( totalCumProgPercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
326 | learningResultsTable.setAlunosInscritos( totalInscritosGlobal / (learningResultsTable.getYears().size())); |
||
327 | learningResultsTable.setAprovadosPercent( totalAprovadosPercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
328 | learningResultsTable.setReprovadosPercent( totalReprovadosPercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
329 | learningResultsTable.setSemElementosPercent( totalSemElementosPercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
330 | learningResultsTable.setAprovados1013Percent( totalAprovados1013PercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
331 | learningResultsTable.setAprovados1416Percent( totalAprovados1416PercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
332 | learningResultsTable.setAprovados1720Percent( totalAprovados1720PercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
333 | } |
||
334 | |||
335 | |||
336 | |||
337 | |||
338 | return learningResultsTable; |
||
339 | //CRIAR A TABELA DE RESUTLADOS GLOBAIS GERAIS COMO UM RESUMO DA ANTERIOR |
||
340 | /*for(UnitsLearningResultYear learningYearLine: learningResultsTable.getYears()) |
||
341 | { |
||
342 | |||
343 | }*/ |
||
1814 | jmachado | 344 | } |
345 | |||
1830 | jmachado | 346 | |
347 | /** |
||
348 | * Update course unit sections with reports, this method dows not change learning results table |
||
349 | * values from learning results stays in unit but does not change learning results Table |
||
350 | * @param courseCode |
||
351 | * @param year |
||
352 | * @param reportCourseDocument |
||
353 | * @throws JSONException |
||
354 | * @throws IOException |
||
355 | * @return a list of CourseUnitSection |
||
356 | */ |
||
1841 | jmachado | 357 | 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 { |
358 | |||
359 | List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
||
360 | |||
1830 | jmachado | 361 | 1.5.0/docs/api/java/lang/String.html">String courseUnitSectionsJson = loadCourseEvaluationSections(courseCode,year); |
362 | JSONObject object = new JSONObject(courseUnitSectionsJson); |
||
363 | JSONArray evaluations = object.getJSONArray("evaluations"); |
||
364 | CourseUnitSection[] courseUnitSections = CourseUnitSection.fromJsonArray(evaluations.toString()); |
||
365 | |||
366 | CourseUnitsReportsSection unitReportsSection = (CourseUnitsReportsSection) reportCourseDocument.findDocumentSection(CourseUnitsReportsSection.class); |
||
367 | List<DocumentSection> subSections = new ArrayList<DocumentSection>(); |
||
368 | unitReportsSection.setSubSections(subSections); |
||
369 | for(CourseUnit cu :units) |
||
370 | { |
||
371 | CourseUnitSection sectionFound = CourseReportUtils.findCourseUnitSection(courseUnitSections, (CourseUnitImpl) cu); |
||
372 | if(sectionFound == null) |
||
373 | { |
||
374 | sectionFound = CourseReportUtils.createCourseUnitEvaluationSection((CourseUnitImpl) cu); |
||
375 | } |
||
1841 | jmachado | 376 | if(sectionFound.getCourseUnitEvaluation() == null) |
377 | { |
||
378 | CourseUnitEvaluationImpl courseUnitEvaluation = DomainObjectFactory.createCourseUnitEvaluationImpl(); |
||
379 | courseUnitEvaluation.setAutoGeneratedCourseReport(true); |
||
380 | DaoFactory.getCourseUnitEvaluationDaoImpl().save(courseUnitEvaluation); |
||
381 | cu.setCourseUnitEvaluation(courseUnitEvaluation); |
||
382 | sectionFound.setCourseUnitEvaluation(courseUnitEvaluation); |
||
383 | } |
||
1830 | jmachado | 384 | unitReportsSection.getSubSections().add(sectionFound); |
385 | } |
||
386 | return subSections; |
||
387 | } |
||
388 | |||
389 | |||
390 | |||
391 | 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 { |
||
392 | AbstractDao.getCurrentSession().beginTransaction(); |
||
393 | |||
1841 | jmachado | 394 | ReportCourseDocument reportCourseDocument = new CourseReportServices().createNewCourseReportDocument("9005","201516"); |
1830 | jmachado | 395 | 1.5.0/docs/api/java/lang/System.html">System.out.println(reportCourseDocument.toJson()); |
396 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
397 | } |
||
398 | |||
399 | /* |
||
400 | |||
401 | public String loadUnitsAndCreateLearningResultsTables4Course(String courseCode, String year) throws IOException, JSONException |
||
402 | { |
||
403 | |||
404 | } |
||
405 | */ |
||
406 | //TODO loadUnitsAndCreateLearningResultsTables4Course |
||
407 | //HIPOTESE DEVOLVER DOIS OBJECTOS |
||
408 | //SERVICO DE ARRANQUE |
||
409 | //DEVOLVE UM REPORT DOCUMENT E O CHAMADOR USA O QUE QUISER |
||
410 | //A GERACAO DE GRAFICOS FAZ-SE APENAS A PEDIDO |
||
411 | |||
412 | // SE ELE PEDIR PARA ATUALIZAR TUDO CARREGA-SE UNIDADES E TABELAS NU DOC NOVO |
||
413 | // E NO BROWSER SUBSTITUI-SE ESSES ELEMENTOS NOS ANTIGOS a seccao das unidades |
||
414 | // e as as tabelas |
||
415 | |||
416 | |||
417 | |||
418 | |||
419 | |||
420 | |||
421 | |||
422 | |||
423 | |||
424 | /****************************************************************************/ |
||
425 | /* SERVICOS WS-API |
||
426 | /****************************************************************************/ |
||
427 | |||
428 | |||
429 | /** |
||
430 | * This service loads a list of course units given course code and year |
||
431 | * with dtp stats codes pre-filled |
||
432 | * @param courseCode |
||
433 | * @param year |
||
434 | * @return |
||
435 | * @throws JSONException |
||
436 | * @throws IOException |
||
437 | */ |
||
438 | 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 { |
||
439 | |||
440 | |||
441 | if(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_DTP_STATS.indexOf("localhost")>=0) |
||
442 | { |
||
443 | JSONArray array = new JSONArray(); |
||
444 | List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
||
445 | for(CourseUnit cu: units) |
||
446 | { |
||
447 | CourseUnitDtpStat stat = CourseReportUtils.createCourseUnitDtpStat(cu); |
||
448 | //sections.add(courseUnitSection); |
||
449 | array.put(stat.toJsonObject()); |
||
450 | } |
||
451 | |||
452 | JSONObject obj = new JSONObject(); |
||
453 | obj.put("dtpstats",array); |
||
454 | |||
455 | return obj.toString(); |
||
456 | } |
||
457 | else |
||
458 | { |
||
459 | 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); |
||
460 | 5+0%2Fdocs%2Fapi+InputStream">InputStream is = url.openStream(); |
||
461 | |||
462 | 1.5.0/docs/api/java/lang/String.html">String json = StreamsUtils.readString(is); |
||
463 | is.close(); |
||
464 | //TODO temos de extrair o resultado do RESPONSE |
||
465 | JSONObject jsonObject = new JSONObject(json); |
||
1837 | jmachado | 466 | return jsonObject.get("response").toString(); |
1830 | jmachado | 467 | } |
468 | } |
||
469 | |||
470 | |||
471 | |||
472 | |||
473 | /** |
||
474 | * |
||
475 | * Para um determinado curso e ano o serviço faz uma listagem de todas as suas unidades curriculares |
||
476 | * e lista a sua informação básica juntamente com o relatório de avaliação disponivel |
||
477 | * O serviço adiciona ainda o Ano de cada unidade por inspeção do Plano de Estudos |
||
478 | * caso a unidade não seja encontrada no Plano de estudos o ano irá ser preenchido com -1 |
||
479 | * |
||
480 | * @param courseCode codigo Siges na base de dados |
||
481 | * @param year 201617, 201718 |
||
482 | * @return String JSONObject with a JSON ARRAY of List<CourseUnitSection> |
||
483 | */ |
||
484 | 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 { |
||
485 | |||
486 | |||
487 | if(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_EVALUATION.indexOf("localhost")>=0) |
||
488 | { |
||
489 | JSONArray array = new JSONArray(); |
||
490 | List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
||
491 | for(CourseUnit cu: units) |
||
492 | { |
||
493 | CourseUnitSection courseUnitSection = CourseReportUtils.createCourseUnitEvaluationSection((CourseUnitImpl) cu); |
||
494 | array.put(courseUnitSection.toJsonObject()); |
||
495 | } |
||
496 | |||
497 | JSONObject obj = new JSONObject(); |
||
498 | obj.put("evaluations",array); |
||
499 | |||
500 | return obj.toString(); |
||
501 | } |
||
502 | else |
||
503 | { |
||
504 | 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); |
||
505 | 5+0%2Fdocs%2Fapi+InputStream">InputStream is = url.openStream(); |
||
506 | |||
507 | 1.5.0/docs/api/java/lang/String.html">String json = StreamsUtils.readString(is); |
||
508 | is.close(); |
||
509 | JSONObject jsonObject = new JSONObject(json); |
||
1837 | jmachado | 510 | return jsonObject.get("response").toString(); |
1830 | jmachado | 511 | } |
512 | } |
||
513 | |||
514 | |||
1814 | jmachado | 515 | } |