List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet getLastRowNum
@Override public int getLastRowNum()
From source file:org.egov.egf.web.actions.budget.BudgetLoadAction.java
License:Open Source License
private void prepareOutPutFileWithErrors(List<BudgetUpload> budgetUploadList) { FileInputStream fsIP;/* w ww. j a va 2 s . c o m*/ try { fsIP = new FileInputStream(budgetInXls); Map<String, String> errorsMap = new HashMap<String, String>(); final POIFSFileSystem fs = new POIFSFileSystem(fsIP); final HSSFWorkbook wb = new HSSFWorkbook(fs); wb.getNumberOfSheets(); final HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row = sheet.getRow(3); HSSFCell cell = row.createCell(7); cell.setCellValue("Error Reason"); for (BudgetUpload budget : budgetUploadList) errorsMap.put(budget.getFundCode() + "-" + budget.getFunctionCode() + "-" + budget.getDeptCode() + "-" + budget.getBudgetHead(), budget.getErrorReason()); for (int i = DATA_STARTING_ROW_INDEX; i <= sheet.getLastRowNum(); i++) { HSSFRow errorRow = sheet.getRow(i); HSSFCell errorCell = errorRow.createCell(7); errorCell.setCellValue(errorsMap.get((getStrValue(sheet.getRow(i).getCell(FUNDCODE_CELL_INDEX)) + "-" + getStrValue(sheet.getRow(i).getCell(FUNCTIONCODE_CELL_INDEX)) + "-" + getStrValue(sheet.getRow(i).getCell(DEPARTMENTCODE_CELL_INDEX)) + "-" + getStrValue(sheet.getRow(i).getCell(GLCODE_CELL_INDEX))))); } FileOutputStream output_file = new FileOutputStream(budgetInXls); wb.write(output_file); output_file.close(); if (budgetInXlsFileName.contains("_budget_original_")) { budgetOutPutFileName = budgetInXlsFileName.split("_budget_original_")[0] + "_budget_output_" + timeStamp + "." + budgetInXlsFileName.split("\\.")[1]; } else if (budgetInXlsFileName.contains("_budget_output_")) { budgetOutPutFileName = budgetInXlsFileName.split("_budget_output_")[0] + "_budget_output_" + timeStamp + "." + budgetInXlsFileName.split("\\.")[1]; } else { if (budgetInXlsFileName.length() > 60) { throw new ValidationException(Arrays .asList(new ValidationError(getText("file.name.should.be.less.then.60.characters"), getText("file.name.should.be.less.then.60.characters")))); } else budgetOutPutFileName = budgetInXlsFileName.split("\\.")[0] + "_budget_output_" + timeStamp + "." + budgetInXlsFileName.split("\\.")[1]; } final FileStoreMapper outPutFileStore = fileStoreService.store(budgetInXls, budgetOutPutFileName, budgetInXlsContentType, FinancialConstants.MODULE_NAME_APPCONFIG); persistenceService.persist(outPutFileStore); outPutFileStoreId = outPutFileStore.getFileStoreId(); } catch (FileNotFoundException e) { throw new ValidationException(Arrays.asList(new ValidationError(e.getMessage(), e.getMessage()))); } catch (IOException e) { throw new ValidationException(Arrays.asList(new ValidationError(e.getMessage(), e.getMessage()))); } }
From source file:org.egov.egf.web.actions.budget.BudgetLoadAction.java
License:Open Source License
private void prepareOutPutFileWithFinalStatus(List<BudgetUpload> budgetUploadList) { FileInputStream fsIP;//from w w w . ja v a 2 s .co m try { fsIP = new FileInputStream(budgetInXls); Map<String, String> errorsMap = new HashMap<String, String>(); final POIFSFileSystem fs = new POIFSFileSystem(fsIP); final HSSFWorkbook wb = new HSSFWorkbook(fs); wb.getNumberOfSheets(); final HSSFSheet sheet = wb.getSheetAt(0); Map<String, String> finalStatusMap = new HashMap<String, String>(); HSSFRow row = sheet.getRow(3); HSSFCell cell = row.createCell(7); cell.setCellValue("Status"); for (BudgetUpload budget : budgetUploadList) finalStatusMap.put(budget.getFundCode() + "-" + budget.getFunctionCode() + "-" + budget.getDeptCode() + "-" + budget.getBudgetHead(), budget.getFinalStatus()); for (int i = DATA_STARTING_ROW_INDEX; i <= sheet.getLastRowNum(); i++) { HSSFRow finalStatusRow = sheet.getRow(i); HSSFCell finalStatusCell = finalStatusRow.createCell(7); finalStatusCell .setCellValue(finalStatusMap.get((getStrValue(sheet.getRow(i).getCell(FUNDCODE_CELL_INDEX)) + "-" + getStrValue(sheet.getRow(i).getCell(FUNCTIONCODE_CELL_INDEX)) + "-" + getStrValue(sheet.getRow(i).getCell(DEPARTMENTCODE_CELL_INDEX)) + "-" + getStrValue(sheet.getRow(i).getCell(GLCODE_CELL_INDEX))))); } FileOutputStream output_file = new FileOutputStream(budgetInXls); wb.write(output_file); output_file.close(); if (budgetInXlsFileName.contains("_budget_original_")) { budgetOutPutFileName = budgetInXlsFileName.split("_budget_original_")[0] + "_budget_output_" + timeStamp + "." + budgetInXlsFileName.split("\\.")[1]; } else if (budgetInXlsFileName.contains("_budget_output_")) { budgetOutPutFileName = budgetInXlsFileName.split("_budget_output_")[0] + "_budget_output_" + timeStamp + "." + budgetInXlsFileName.split("\\.")[1]; } else { if (budgetInXlsFileName.length() > 60) { throw new ValidationException(Arrays .asList(new ValidationError(getText("file.name.should.be.less.then.60.characters"), getText("file.name.should.be.less.then.60.characters")))); } else budgetOutPutFileName = budgetInXlsFileName.split("\\.")[0] + "_budget_output_" + timeStamp + "." + budgetInXlsFileName.split("\\.")[1]; } final FileStoreMapper outPutFileStore = fileStoreService.store(budgetInXls, budgetOutPutFileName, budgetInXlsContentType, FinancialConstants.MODULE_NAME_APPCONFIG); persistenceService.persist(outPutFileStore); outPutFileStoreId = outPutFileStore.getFileStoreId(); } catch (FileNotFoundException e) { throw new ValidationException(Arrays.asList(new ValidationError(e.getMessage(), e.getMessage()))); } catch (IOException e) { throw new ValidationException(Arrays.asList(new ValidationError(e.getMessage(), e.getMessage()))); } }
From source file:org.egov.egf.web.actions.budget.BudgetLoadAction.java
License:Open Source License
private List<BudgetUpload> loadToBudgetUpload(HSSFSheet sheet) { List<BudgetUpload> budgetUploadList = new ArrayList<BudgetUpload>(); try {// w w w . ja v a2s. co m for (int i = DATA_STARTING_ROW_INDEX; i <= sheet.getLastRowNum(); i++) budgetUploadList.add(getBudgetUpload(sheet.getRow(i))); } catch (final ValidationException e) { throw new ValidationException(Arrays.asList( new ValidationError(e.getErrors().get(0).getMessage(), e.getErrors().get(0).getMessage()))); } catch (final Exception e) { throw new ValidationException(Arrays.asList(new ValidationError(e.getMessage(), e.getMessage()))); } return budgetUploadList; }
From source file:org.etudes.mneme.impl.AttachmentServiceImpl.java
License:Apache License
HSSFWorkbook createAsmtStatsSheet(HSSFWorkbook workbook, List<Submission> submissions) { if (submissions == null || submissions.size() == 0) return null; Map<String, Integer> userRowMap = new HashMap(); HSSFSheet sheet = workbook.createSheet("Submission responses"); HSSFRow headerRow = sheet.createRow((short) 0); HSSFCellStyle style = workbook.createCellStyle(); HSSFFont font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); style.setFont(font);/*www . j a v a 2 s. c om*/ // Printing header row and question text HSSFCell cell0 = headerRow.createCell((short) (0)); cell0.setCellStyle(style); cell0.setCellValue(this.messages.getFormattedMessage("asmt_name", null)); HSSFCell cell1 = headerRow.createCell((short) (1)); cell1.setCellStyle(style); cell1.setCellValue(this.messages.getFormattedMessage("asmt_uname", null)); HSSFCell cell2 = headerRow.createCell((short) (2)); cell2.setCellStyle(style); cell2.setCellValue(this.messages.getFormattedMessage("asmt_started", null)); HSSFCell cell3 = headerRow.createCell((short) (3)); cell3.setCellStyle(style); cell3.setCellValue(this.messages.getFormattedMessage("asmt_finished", null)); HSSFCell cell4 = headerRow.createCell((short) (4)); cell4.setCellStyle(style); cell4.setCellValue(this.messages.getFormattedMessage("asmt_status", null)); HSSFCell cell5 = headerRow.createCell((short) (5)); cell5.setCellStyle(style); cell5.setCellValue(this.messages.getFormattedMessage("asmt_ascore", null)); HSSFCell cell6 = headerRow.createCell((short) (6)); cell6.setCellStyle(style); cell6.setCellValue(this.messages.getFormattedMessage("asmt_final", null) + " " + this.messages.getFormattedMessage("asmt_outof", null) + " " + submissions.get(0).getAssessment().getPoints() + ")"); HSSFCell cell7 = headerRow.createCell((short) (7)); cell7.setCellStyle(style); cell7.setCellValue(this.messages.getFormattedMessage("asmt_released", null)); for (Submission sub : submissions) { HSSFRow row; int rowNum = sheet.getLastRowNum() + 1; row = sheet.createRow(rowNum); try { User user = this.userDirectoryService.getUser(sub.getUserId()); row.createCell((short) 0).setCellValue(user.getSortName()); row.createCell((short) 1).setCellValue(user.getDisplayId()); } catch (UserNotDefinedException e) { M_log.warn("createAsmtStatsSheet: " + e.toString()); } if (sub.getStartDate() != null && !sub.getIsNonSubmit()) row.createCell((short) 2).setCellValue(formatDate(sub.getStartDate())); if (sub.getSubmittedDate() != null && !sub.getIsNonSubmit()) row.createCell((short) 3).setCellValue(formatDate(sub.getSubmittedDate())); row.createCell((short) 4).setCellValue(getSubmissionStatus(sub)); if (sub.getAnswersAutoScore() != null) row.createCell((short) 5).setCellValue(sub.getAnswersAutoScore().floatValue()); if (sub.getTotalScore() != null) row.createCell((short) 6).setCellValue(sub.getTotalScore().floatValue()); row.createCell((short) 7).setCellValue(sub.getIsReleased().booleanValue()); } return workbook; }
From source file:org.etudes.mneme.impl.AttachmentServiceImpl.java
License:Apache License
/** * Creates Fill Blanks tab for answers Item Analysis * * @param fb_questions List of Fill Blanks questions * @param workbook Workbook object// w w w .ja va2 s . c o m * @param assessment Assessment object */ void createFillBlanksTab(List<Question> fb_questions, HSSFWorkbook workbook, Assessment assessment) { if (fb_questions == null || fb_questions.size() == 0) return; String assmtId = assessment.getId(); HSSFSheet sheet = null; HSSFRow row; boolean headerRowDone = false; for (Iterator it = fb_questions.iterator(); it.hasNext();) { Question q = (Question) it.next(); Map<String, Integer> fbqMap = new HashMap<String, Integer>(); List<Answer> answers = this.submissionService.findSubmissionAnswers(assessment, q, FindAssessmentSubmissionsSort.userName_a, null, null); if (answers == null || answers.size() == 0) return; if (!headerRowDone) { sheet = workbook.createSheet("FillBlanks"); HSSFRow headerRow = sheet.createRow((short) 0); HSSFCellStyle style = workbook.createCellStyle(); HSSFFont font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); style.setFont(font); // Printing header row HSSFCell cell0 = headerRow.createCell((short) (0)); cell0.setCellStyle(style); cell0.setCellValue(this.messages.getFormattedMessage("item_analysis_question", null)); headerRowDone = true; } for (Answer answer : answers) { TypeSpecificAnswer a = answer.getTypeSpecificAnswer(); if (a instanceof FillBlanksAnswerImpl) { FillBlanksAnswerImpl fb = (FillBlanksAnswerImpl) a; String[] fbAnswers = fb.getAnswers(); for (int i = 0; i < fbAnswers.length; i++) { String fbAnswer; if (fb.correctFillAnswer(fbAnswers[i], i)) fbAnswer = "*" + fbAnswers[i] + "*"; else fbAnswer = fbAnswers[i]; if (fbqMap.get(fbAnswer) != null) { int count = fbqMap.get(fbAnswer).intValue(); count++; fbqMap.put(fbAnswer, count); } else fbqMap.put(fbAnswer, new Integer(1)); } } } int rowNum = sheet.getLastRowNum() + 1; row = sheet.createRow(rowNum); String quest_desc = stripHtml(((FillBlanksQuestionImpl) q.getTypeSpecificQuestion()).getText()); row.createCell((short) 0).setCellValue(quest_desc); int j = 1; if (fbqMap != null && fbqMap.size() > 0) { Iterator itsec = fbqMap.entrySet().iterator(); while (itsec.hasNext()) { Map.Entry pairs = (Map.Entry) itsec.next(); if (pairs.getValue() != null) { row.createCell((short) j).setCellValue("(" + pairs.getValue() + ") " + pairs.getKey()); j++; } } } } }
From source file:org.etudes.mneme.impl.AttachmentServiceImpl.java
License:Apache License
/** * Creates Fill Inline tab for answers Item Analysis * * @param fb_questions List of Fill Blanks questions * @param workbook Workbook object/*w w w . j a v a2 s . com*/ * @param assessment Assessment object */ void createFillInlineTab(List<Question> fi_questions, HSSFWorkbook workbook, Assessment assessment) { if (fi_questions == null || fi_questions.size() == 0) return; String assmtId = assessment.getId(); HSSFSheet sheet = null; HSSFRow row; boolean headerRowDone = false; for (Iterator it = fi_questions.iterator(); it.hasNext();) { Question q = (Question) it.next(); Map<String, Integer> fbqMap = new HashMap<String, Integer>(); List<Answer> answers = this.submissionService.findSubmissionAnswers(assessment, q, FindAssessmentSubmissionsSort.userName_a, null, null); if (answers == null || answers.size() == 0) return; List<ArrayList<String>> selectionLists = new ArrayList<ArrayList<String>>(); List<String> correctAnswers = new ArrayList<String>(); if (!headerRowDone) { sheet = workbook.createSheet("InlineDropdown"); HSSFRow headerRow = sheet.createRow((short) 0); HSSFCellStyle style = workbook.createCellStyle(); HSSFFont font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); style.setFont(font); // Printing header row HSSFCell cell0 = headerRow.createCell((short) (0)); cell0.setCellStyle(style); cell0.setCellValue(this.messages.getFormattedMessage("item_analysis_question", null)); int i = 1; int k = 0; ((FillInlineQuestionImpl) q.getTypeSpecificQuestion()).parseSelectionLists(selectionLists, correctAnswers); for (List<String> selList : selectionLists) { for (String str : selList) { HSSFCell cell1 = headerRow.createCell((short) (i)); cell1.setCellStyle(style); cell1.setCellValue(str); fbqMap.put(Integer.toString(k) + str, 0); i++; } k++; } headerRowDone = true; } for (Answer answer : answers) { TypeSpecificAnswer a = answer.getTypeSpecificAnswer(); if (a instanceof FillInlineAnswerImpl) { FillInlineAnswerImpl fb = (FillInlineAnswerImpl) a; String[] fbAnswers = fb.getAnswers(); for (int i = 0; i < fbAnswers.length; i++) { String fbAnswer = fbAnswers[i]; if (fbqMap.get(Integer.toString(i) + fbAnswer) != null) { int count = fbqMap.get(Integer.toString(i) + fbAnswer).intValue(); count++; fbqMap.put(Integer.toString(i) + fbAnswer, count); } } } } int rowNum = sheet.getLastRowNum() + 1; row = sheet.createRow(rowNum); String quest_desc = stripHtml(((FillInlineQuestionImpl) q.getTypeSpecificQuestion()).getText()); row.createCell((short) 0).setCellValue(quest_desc); int j = 1; if (fbqMap != null && fbqMap.size() > 0) { int k = 0; for (List<String> selList : selectionLists) { for (String str : selList) { if (str.equals(correctAnswers.get(k))) row.createCell((short) j) .setCellValue("*" + fbqMap.get(Integer.toString(k) + str) + "*"); else row.createCell((short) j).setCellValue(fbqMap.get(Integer.toString(k) + str)); j++; } k++; } } } }
From source file:org.etudes.mneme.impl.AttachmentServiceImpl.java
License:Apache License
/** * Creates main frequency tab for Item analysis * * @param questions List of questions/*w ww . ja va2s.c o m*/ * @param workbook Workbook object * @param assessment Assessment object * @return True if answers exist, false if not */ boolean createFrequencyTab(List<Question> questions, HSSFWorkbook workbook, Assessment assessment) { if (questions == null || questions.size() == 0) return false; String assmtId = assessment.getId(); HSSFSheet sheet = null; HSSFRow row; boolean headerRowDone = false; List<Submission> submissions = this.submissionService.findAssessmentSubmissions(assessment, SubmissionService.FindAssessmentSubmissionsSort.sdate_a, Boolean.TRUE, null, null, null, null); boolean answersExist = false; for (Iterator it = questions.iterator(); it.hasNext();) { Question q = (Question) it.next(); TypeSpecificQuestion tsq = q.getTypeSpecificQuestion(); int count = 0; if (!(tsq instanceof EssayQuestionImpl) && !(tsq instanceof TaskQuestionImpl)) { List<Answer> allAnswers = this.submissionService.findSubmissionAnswers(assessment, q, FindAssessmentSubmissionsSort.userName_a, null, null); if (allAnswers == null || allAnswers.size() == 0) continue; List<Answer> answers = filterOutMultiples(allAnswers, submissions); answersExist = true; if (!headerRowDone) { sheet = workbook.createSheet("ItemAnalysis"); HSSFRow headerRow = sheet.createRow((short) 0); HSSFCellStyle style = workbook.createCellStyle(); HSSFFont font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); style.setFont(font); // Printing header row HSSFCell cell0 = headerRow.createCell((short) (0)); cell0.setCellStyle(style); cell0.setCellValue(this.messages.getFormattedMessage("item_analysis_question", null)); HSSFCell cell9 = headerRow.createCell((short) (1)); cell9.setCellStyle(style); cell9.setCellValue(this.messages.getFormattedMessage("item_analysis_title", null)); HSSFCell cell1 = headerRow.createCell((short) (2)); cell1.setCellStyle(style); cell1.setCellValue(this.messages.getFormattedMessage("item_analysis_pool", null)); HSSFCell cell2 = headerRow.createCell((short) (3)); cell2.setCellStyle(style); cell2.setCellValue(this.messages.getFormattedMessage("item_analysis_numbers", null)); HSSFCell cell3 = headerRow.createCell((short) (4)); cell3.setCellStyle(style); cell3.setCellValue(this.messages.getFormattedMessage("item_analysis_whole_group", null)); HSSFCell cell4 = headerRow.createCell((short) (5)); cell4.setCellStyle(style); cell4.setCellValue(this.messages.getFormattedMessage("item_analysis_upper_27", null)); HSSFCell cell5 = headerRow.createCell((short) (6)); cell5.setCellStyle(style); cell5.setCellValue(this.messages.getFormattedMessage("item_analysis_lower_27", null)); HSSFCell cell6 = headerRow.createCell((short) (7)); cell6.setCellStyle(style); cell6.setCellValue(this.messages.getFormattedMessage("item_analysis_diff_in", null)); HSSFCell cell7 = headerRow.createCell((short) (8)); cell7.setCellStyle(style); cell7.setCellValue(this.messages.getFormattedMessage("item_analysis_disc", null)); HSSFCell cell8 = headerRow.createCell((short) (9)); cell8.setCellStyle(style); cell8.setCellValue(this.messages.getFormattedMessage("item_analysis_freq", null)); headerRowDone = true; } int rowNum = sheet.getLastRowNum() + 1; row = sheet.createRow(rowNum); String quest_desc = null; if (tsq instanceof FillBlanksQuestionImpl) { quest_desc = stripHtml(((FillBlanksQuestionImpl) tsq).getText()); } else if (tsq instanceof FillInlineQuestionImpl) { quest_desc = stripHtml(((FillInlineQuestionImpl) tsq).getText()); } else { quest_desc = stripHtml(q.getDescription()); if (tsq instanceof OrderQuestionImpl) { List<OrderQuestionImpl.OrderQuestionChoice> choiceList = ((OrderQuestionImpl) tsq) .getChoicesAsAuthored(); String[] choiceTextArray = new String[choiceList.size()]; int j = 0; for (OrderQuestionImpl.OrderQuestionChoice oqc : choiceList) { choiceTextArray[j] = (j + 1) + "." + stripHtml(oqc.getText()); j++; } quest_desc = quest_desc + getCommaAnswers(choiceTextArray); } } row.createCell((short) 0).setCellValue(quest_desc); row.createCell((short) 1).setCellValue(q.getTitle()); row.createCell((short) 2).setCellValue(q.getPool().getTitle()); row.createCell((short) 3).setCellValue(answers.size()); int numCorrects = numberOfCorrects(answers); double ncPc = 0.0; if (numCorrects > 0) ncPc = ((double) numberOfCorrects(answers) / answers.size()) * 100; row.createCell((short) 4).setCellValue(roundTwoDecimals(ncPc) + "%" + "(N=" + numCorrects + ")"); List<ScoreUser> scoreUserList = createScoreUserList(answers); List<String> upperUserList = fetchUpperList(scoreUserList, 27); List<String> lowerUserList = fetchLowerList(scoreUserList, 27); int upCorrectCount = calculateCorrects(upperUserList, answers); double uppPc = 0.0; if (upCorrectCount > 0) uppPc = ((double) upCorrectCount / upperUserList.size()) * 100; row.createCell((short) 5) .setCellValue(roundTwoDecimals(uppPc) + "%" + "(N=" + upCorrectCount + ")"); int loCorrectCount = calculateCorrects(lowerUserList, answers); double lowPc = 0.0; if (loCorrectCount > 0) lowPc = ((double) loCorrectCount / lowerUserList.size()) * 100; row.createCell((short) 6) .setCellValue(roundTwoDecimals(lowPc) + "%" + "(N=" + loCorrectCount + ")"); double diffIdx = (uppPc + lowPc) / 2; double discrim = (uppPc - lowPc) / 100; row.createCell((short) 7).setCellValue(roundTwoDecimals(diffIdx)); row.createCell((short) 8).setCellValue(roundTwoDecimals(discrim)); for (Submission s : submissions) { if (s.getIsPhantom()) continue; if (!s.getIsComplete()) continue; Answer a = s.getAnswer(q); if (a != null) { if (!a.getIsAnswered()) { count++; } } } row.createCell((short) 9).setCellValue(count); } } return answersExist; }
From source file:org.etudes.mneme.impl.AttachmentServiceImpl.java
License:Apache License
/** * Creates Likert Scale tab for answers Item Analysis * * @param ls_questions List of Likert Scale questions * @param workbook Workbook object/*from w w w. j av a 2 s. co m*/ * @param assessment Assessment object */ void createLikertScaleTab(List<Question> ls_questions, HSSFWorkbook workbook, Assessment assessment) { if (ls_questions == null || ls_questions.size() == 0) return; String assmtId = assessment.getId(); HSSFSheet sheet = null; HSSFRow row; boolean headerRowDone = false; for (Iterator it = ls_questions.iterator(); it.hasNext();) { Question q = (Question) it.next(); Map<String, LikertScaleCount> lsqMap = new HashMap<String, LikertScaleCount>(); List<LikertScaleQuestionImpl.LikertScaleQuestionChoice> choiceList = ((LikertScaleQuestionImpl) q .getTypeSpecificQuestion()).getChoices(); for (Iterator chIt = choiceList.iterator(); chIt.hasNext();) { LikertScaleQuestionImpl.LikertScaleQuestionChoice chObj = (LikertScaleQuestionImpl.LikertScaleQuestionChoice) chIt .next(); lsqMap.put(chObj.getId(), new LikertScaleCount(chObj.getText(), 0)); } List<Answer> answers = this.submissionService.findSubmissionAnswers(assessment, q, FindAssessmentSubmissionsSort.userName_a, null, null); if (answers == null || answers.size() == 0) return; if (!headerRowDone) { sheet = workbook.createSheet("LikertScale"); HSSFRow headerRow = sheet.createRow((short) 0); HSSFCellStyle style = workbook.createCellStyle(); HSSFFont font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); style.setFont(font); // Printing header row HSSFCell cell0 = headerRow.createCell((short) (0)); cell0.setCellStyle(style); cell0.setCellValue(this.messages.getFormattedMessage("item_analysis_question", null)); headerRowDone = true; } for (Answer answer : answers) { TypeSpecificAnswer a = answer.getTypeSpecificAnswer(); if (a instanceof LikertScaleAnswerImpl) { LikertScaleAnswerImpl ls = (LikertScaleAnswerImpl) a; for (Iterator chItn = choiceList.iterator(); chItn.hasNext();) { LikertScaleQuestionImpl.LikertScaleQuestionChoice lqc = (LikertScaleQuestionImpl.LikertScaleQuestionChoice) chItn .next(); if (lqc.getId().equals(ls.getAnswer())) { LikertScaleCount lscObj = (LikertScaleCount) lsqMap.get(lqc.getId()); lscObj.count++; } } } } int rowNum = sheet.getLastRowNum() + 1; row = sheet.createRow(rowNum); String quest_desc = stripHtml(q.getDescription()); row.createCell((short) 0).setCellValue(quest_desc); int i = 1; if (lsqMap != null && lsqMap.size() > 0) { Iterator itsec = lsqMap.entrySet().iterator(); while (itsec.hasNext()) { Map.Entry pairs = (Map.Entry) itsec.next(); if (pairs.getValue() != null) { LikertScaleCount lscObj = (LikertScaleCount) pairs.getValue(); row.createCell((short) i).setCellValue("(" + lscObj.getCount() + ") " + lscObj.getText()); i++; } } } } }
From source file:org.etudes.mneme.impl.AttachmentServiceImpl.java
License:Apache License
/** * Creates Match tab for answers Item Analysis * * @param ma_questions List of Match questions * @param workbook Workbook object/* ww w . java 2 s.c o m*/ * @param assessment Assessment object */ void createMatchTab(List<Question> ma_questions, HSSFWorkbook workbook, Assessment assessment) { if (ma_questions == null || ma_questions.size() == 0) return; String assmtId = assessment.getId(); HSSFSheet sheet = null; HSSFRow row; boolean headerRowDone = false; for (Iterator it = ma_questions.iterator(); it.hasNext();) { Question q = (Question) it.next(); Map<String, Integer> maMap = new HashMap<String, Integer>(); List<Answer> answers = this.submissionService.findSubmissionAnswers(assessment, q, FindAssessmentSubmissionsSort.userName_a, null, null); if (answers == null || answers.size() == 0) return; if (!headerRowDone) { sheet = workbook.createSheet("Match"); HSSFRow headerRow = sheet.createRow((short) 0); HSSFCellStyle style = workbook.createCellStyle(); HSSFFont font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); style.setFont(font); // Printing header row HSSFCell cell0 = headerRow.createCell((short) (0)); cell0.setCellStyle(style); cell0.setCellValue(this.messages.getFormattedMessage("item_analysis_question", null)); headerRowDone = true; } for (Answer answer : answers) { TypeSpecificAnswer a = answer.getTypeSpecificAnswer(); if (a instanceof MatchAnswerImpl) { MatchAnswerImpl ma = (MatchAnswerImpl) a; Map matchMap = (LinkedHashMap) ma.getAnswer(); Iterator it2 = matchMap.entrySet().iterator(); List choiceList = ((MatchQuestionImpl) ma.getAnswerObject().getQuestion() .getTypeSpecificQuestion()).getPairsForDelivery(); while (it2.hasNext()) { StringBuffer matchStrBuf = new StringBuffer(); Map.Entry entry = (Map.Entry) it2.next(); String key = (String) entry.getKey(); String value = (String) ((Value) entry.getValue()).getValue(); String matchVal = fetchName(choiceList, key, true); boolean correctMatch = checkCorrectMatch(choiceList, key, value); if (correctMatch) matchStrBuf.append("*"); matchStrBuf.append(stripHtml(matchVal)); matchStrBuf.append("->"); String choiceVal = fetchName(choiceList, value, false); matchStrBuf.append(stripHtml(choiceVal)); if (correctMatch) matchStrBuf.append("*"); String finalStr = matchStrBuf.toString(); if (maMap.get(finalStr) != null) { int count = maMap.get(finalStr).intValue(); count++; maMap.put(finalStr, count); } else maMap.put(finalStr, new Integer(1)); } } } int rowNum = sheet.getLastRowNum() + 1; row = sheet.createRow(rowNum); String quest_desc = stripHtml(q.getDescription()); row.createCell((short) 0).setCellValue(quest_desc); int j = 1; if (maMap != null && maMap.size() > 0) { Iterator itsec = maMap.entrySet().iterator(); while (itsec.hasNext()) { Map.Entry pairs = (Map.Entry) itsec.next(); if (pairs.getValue() != null) { row.createCell((short) j).setCellValue("(" + pairs.getValue() + ") " + pairs.getKey()); j++; } } } } }
From source file:org.etudes.mneme.impl.AttachmentServiceImpl.java
License:Apache License
/** * Creates the Multiple Choice tab for answers Item Analysis * * @param mc_questions List of Multiple Choice questions * @param workbook Workbook object/*from w ww . ja va2 s . c om*/ * @param assessment Assessment object */ void createMultipleChoiceTab(List<Question> mc_questions, HSSFWorkbook workbook, Assessment assessment) { if (mc_questions == null || mc_questions.size() == 0) return; String assmtId = assessment.getId(); HSSFSheet sheet = null; HSSFRow row; String[] choiceLabels = new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "0", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y" }; int[] choiceCount = new int[25]; boolean[] choiceCorrect = new boolean[25]; //Determine which question has most number of choices so as to determine header column count int headerSize = getMaxChoices(mc_questions); boolean headerRowDone = false; //Iterate through each question for (Iterator it = mc_questions.iterator(); it.hasNext();) { Question q = (Question) it.next(); //Fetch all submissions to the question List<Answer> answers = this.submissionService.findSubmissionAnswers(assessment, q, FindAssessmentSubmissionsSort.userName_a, null, null); if (answers == null || answers.size() == 0) return; //Create header row once if (!headerRowDone) { sheet = workbook.createSheet("MultipleChoice"); HSSFRow headerRow = sheet.createRow((short) 0); HSSFCellStyle style = workbook.createCellStyle(); HSSFFont font = workbook.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); style.setFont(font); // Printing header row HSSFCell cell0 = headerRow.createCell((short) (0)); cell0.setCellStyle(style); cell0.setCellValue(this.messages.getFormattedMessage("item_analysis_question", null)); for (int i = 1; i <= headerSize; i++) { HSSFCell cell1 = headerRow.createCell((short) (i)); cell1.setCellStyle(style); cell1.setCellValue(choiceLabels[i - 1]); } headerRowDone = true; } int choiceListSize = 0; Set<Integer> correctAnswers = ((MultipleChoiceQuestionImpl) q.getTypeSpecificQuestion()) .getCorrectAnswerSet(); List<MultipleChoiceQuestionImpl.MultipleChoiceQuestionChoice> choiceList = ((MultipleChoiceQuestionImpl) q .getTypeSpecificQuestion()).getChoicesAsAuthored(); choiceListSize = choiceList.size(); //Set the choiceCorrect array so we know which ones are correct choices //for this question int pos = 0; for (Iterator chIt = choiceList.iterator(); chIt.hasNext();) { MultipleChoiceQuestionImpl.MultipleChoiceQuestionChoice mq = (MultipleChoiceQuestionImpl.MultipleChoiceQuestionChoice) chIt .next(); if (correctAnswers.contains(Integer.parseInt(mq.getId()))) { choiceCorrect[pos] = true; } pos++; } //Iterate through each submission for (Answer answer : answers) { TypeSpecificAnswer a = answer.getTypeSpecificAnswer(); if (a instanceof MultipleChoiceAnswerImpl) { MultipleChoiceAnswerImpl mc = (MultipleChoiceAnswerImpl) a; String[] ansArray = mc.getAnswers(); //Iterate and compare answer and increment choiceCount for (int l = 0; l < ansArray.length; l++) { int ansPos = 0; for (Iterator chIt = choiceList.iterator(); chIt.hasNext();) { MultipleChoiceQuestionImpl.MultipleChoiceQuestionChoice mq = (MultipleChoiceQuestionImpl.MultipleChoiceQuestionChoice) chIt .next(); if (mq.getId().equals(ansArray[l])) { choiceCount[ansPos]++; } ansPos++; } } } } int rowNum = sheet.getLastRowNum() + 1; row = sheet.createRow(rowNum); String quest_desc = stripHtml(q.getDescription()); row.createCell((short) 0).setCellValue(quest_desc); for (int k = 1; k <= choiceListSize; k++) { if (choiceCorrect[k - 1]) row.createCell((short) k).setCellValue("*" + choiceCount[k - 1] + "*"); else row.createCell((short) k).setCellValue(choiceCount[k - 1]); } for (int k = 1; k <= choiceListSize; k++) { choiceCount[k - 1] = 0; choiceCorrect[k - 1] = false; } } }