Example usage for org.apache.poi.hssf.usermodel HSSFWorkbook createCellStyle

List of usage examples for org.apache.poi.hssf.usermodel HSSFWorkbook createCellStyle

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFWorkbook createCellStyle.

Prototype

@Override
public HSSFCellStyle createCellStyle() 

Source Link

Document

Create a new Cell style and add it to the workbook's style table.

Usage

From source file:org.emmanet.controllers.statsSpreadsheetController.java

License:Apache License

public boolean createHeaderCells(HSSFWorkbook arg1, HSSFSheet sheet, String[] fieldNames) {

    headerTitle = fieldNames;/*from   w w  w  .j a v  a 2 s .c o m*/
    HSSFRow header = sheet.createRow(0);

    /**********************************************
     *
     *  CELL HEADER STYLE
     * 
     * ********************************************
     */
    HSSFCellStyle style = arg1.createCellStyle();
    style.setFillBackgroundColor(HSSFColor.AQUA.index);
    style.setFillForegroundColor(HSSFColor.WHITE.index);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

    for (int i = 0; i < headerTitle.length; i++) {
        HSSFRichTextString richString = new HSSFRichTextString(headerTitle[i]);
        HSSFCell cell = header.createCell((short) i);
        cell.setCellStyle(style);
        cell.setCellValue(richString);
    }

    return true;
}

From source file:org.emmanet.util.CreateSpreadsheet.java

License:Apache License

protected void buildExcelDocument(Map map, HSSFWorkbook wb, HttpServletRequest httpServletRequest,
        HttpServletResponse httpServletResponse) throws Exception {

    data = (List) map.get("data");
    columns = (List) map.get("columns");
    String sheets[] = (String[]) map.get("sheets");
    int freeze = 1;
    String filename = (String) map.get("filename");

    // set list values
    if (filename.equals("stats")) {

        System.out.println("################################################# create spreadsheet called");

        /* Due to time constraints and difficulties returning values from model that aren't affected by duplicate col names
         * the decision was made to use existing perl script for now to generate statistics workbook
         * Perl script called from org.emmanet.utils.RunShell.java
         *//*  ww  w  .j av a  2 s. co  m*/
        RunShell rs = new RunShell();
        //TODO BEFORE GOING LIVE CHECK THAT THIS RUNS /INTERNAL/SCRIPTS/PERL/archive2excel.pl
        // AND ADD PATH AND SCRIPT IN PLACE OF BELOW AND UNCOMMENT //#####
        //String[] run = {"/home/phil/","string.pl"};
        //Hardcoded for now until this is rebuilt TODO
        String[] run = { "/data/web/internal/scripts/perl/",
                "archive2excel.pl -v -o statistics.xls -u phil.1 -p wilkinson -d emmastr" };
        //String[] run = {"/data/web/EmmaStrains/cron/","statistics.sh search strains emmastr"}; //not working either
        rs.execute(run);
        //#####httpServletResponse.sendRedirect("http://internal.emmanet.org/statistics/statistics.xls");
        httpServletResponse.sendRedirect("http://internal.emmanet.org/statistics/statistics.xls");

        columns = (List) map.get("columns_emmaStrains");
        data = (List) map.get("data_emmaStrains");
    }

    //SEND ARRAY OF NAMES TO CREATE SHEETS AND COUNT
    for (int i = 0; i < sheets.length; i++) {

        sheet = wb.createSheet(sheets[i]);
        // Create a row and put some cells in it. Rows are 0 based.
        for (int ii = 0; ii < data.size(); ii++) {

            HSSFRow row = sheet.createRow((short) ii);
            HSSFCell cell = null;
            //HEADER STYLE
            HSSFCellStyle style = wb.createCellStyle();
            style.setFillBackgroundColor(HSSFColor.AQUA.index);
            style.setFillForegroundColor(HSSFColor.WHITE.index);
            style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

            for (int iii = 0; iii < columns.size(); iii++) {
                if (ii == 0) {
                    // first row for header col name
                    for (int cn = 0; cn < columns.size(); cn++) {
                        cell = row.createCell((short) cn);
                        cell.setCellValue((String) columns.get(cn));
                        //cell.setCellValue((HSSFRichTextString) columns.get(cn));

                        //cell.setCellStyle(style);
                        //System.out.println((String) columns.get(cn));
                    }

                } else {

                    for (int cn = 0; cn < columns.size(); cn++) {

                        cell = row.createCell((short) cn);//iii
                        String s = (String) columns.get(cn);
                        //TODO FOR TEST
                        //SET DAOs
                        if (filename.equals("stats")) {
                            //sd = (StrainsDAO) data.get(ii);
                            //columns = (List)map.get("columns_emmaStrains");
                            // TODO IF STATEMENTS TO GET DATA AND SET CELL CONTENTS
                            //cell.setCellValue((String)data.get(ii).toString());

                            //cell.setCellValue((String)data.get(ii).toString());
                            //TODO CURRENTLY ITERATING OVER LIST RESULTS THEN ITERATING AGAIN OVER OBJECT
                            // NEED TO REMOVE OR REPOSITION OBJECT ITERATOR it line 68
                            //#Iterator it = data.iterator();
                            //#while (it.hasNext()) {
                            // /*while (ii < data.length) {
                            ////  Object[] dataVal = (Object[])data.get(ii);
                            // *do rest here
                            // }
                            // */
                            //# Object[] dataVal = (Object[]) it.next();
                            //System.out.println(ii + " +=+=+ ");
                            //cell.setCellValue(dataVal[0].toString());
                            //System.out.println(dataVal[0]);
                            //System.out.println(dataVal[1]);
                            //cell.setCellValue(dataVal[1].toString());
                            //System.out.println(dataVal[2]);
                            // cell.setCellValue(dataVal[2].toString());
                            //System.out.println(dataVal[3]);
                            // cell.setCellValue(dataVal[3].toString());
                            // System.out.println(dataVal[4]);
                            // cell.setCellValue(dataVal[4].toString());

                            //// if (s.equals("Muttype")) cell.setCellValue(dataVal[0].toString());
                            //if (s.equals("subtype")) cell.setCellValue(dataVal[1].toString());
                            //System.out.println(dataVal[1]);
                            //// if (s.equals("EMMA ID")) cell.setCellValue(dataVal[2].toString());
                            //System.out.println(dataVal[2].toString());
                            //// if (s.equals("name")) cell.setCellValue(dataVal[3].toString());
                            //// if (s.equals("gene")) cell.setCellValue(dataVal[4].toString());
                            //# }

                            //cell.setCellValue(dataVal.toString());
                            // System.out.println(dataVal[0]);
                            // returnedOut.put("LabServiceTimeToArch" + i, laboServiceTimes[0]);
                            // cell.setCellValue( (HSSFRichTextString) data.get(ii));

                        } else {
                            sd = (StrainsDAO) data.get(ii);
                            // }

                            //TODO //TODO FOR TEST END

                            if (s.equals("id_str"))
                                cell.setCellValue(sd.getId_str());
                            if (s.equals("code_internal"))
                                cell.setCellValue(sd.getCode_internal());
                            if (s.equals("name"))
                                cell.setCellValue(sd.getName());
                            if (s.equals("health_status"))
                                cell.setCellValue(sd.getHealth_status());
                            if (s.equals("generation"))
                                cell.setCellValue(sd.getGeneration());
                            if (s.equals("maintenance"))
                                cell.setCellValue(sd.getMaintenance());
                            if (s.equals("id_str"))
                                cell.setCellValue(sd.getCharact_gen());
                            if (s.equals("charact_gen"))
                                cell.setCellValue(sd.getStr_access());
                            if (s.equals("username"))
                                cell.setCellValue(sd.getUsername());
                            if (s.equals("last_change"))
                                cell.setCellValue(sd.getLast_change());
                            if (s.equals("pheno_text"))
                                cell.setCellValue(sd.getPheno_text());
                            if (s.equals("per_id_per"))
                                cell.setCellValue(sd.getPer_id_per());
                            if (s.equals("per_id_per_contact"))
                                cell.setCellValue(sd.getPer_id_per_contact());
                            if (s.equals("emma_id"))
                                cell.setCellValue(sd.getEmma_id());
                            if (s.equals("mgi_ref"))
                                cell.setCellValue(sd.getMgi_ref());
                            if (s.equals("str_type"))
                                cell.setCellValue(sd.getStr_type());
                            if (s.equals("mta_file"))
                                cell.setCellValue(sd.getMta_file());
                            if (s.equals("gp_release"))
                                cell.setCellValue(sd.getGp_release());
                            if (s.equals("name_status"))
                                cell.setCellValue(sd.getName_status());
                            if (s.equals("date_published"))
                                cell.setCellValue(sd.getDate_published());
                            if (s.equals("str_status"))
                                cell.setCellValue(sd.getStr_status());
                            if (s.equals("res_id"))
                                cell.setCellValue(sd.getRes_id());
                            if (s.equals("require_homozygous"))
                                cell.setCellValue(sd.getRequire_homozygous());
                            if (s.equals("archive_id"))
                                cell.setCellValue(sd.getArchive_id());
                            if (s.equals("bg_id_bg"))
                                cell.setCellValue(sd.getBg_id_bg());
                        }
                    }
                }
            }
        }
        //AUTOSIZE ACCORDING TO LIST LENGTH AT END OF DATA
        for (i = 0; i < columns.size(); i++) {
            sheet.autoSizeColumn((short) i);
        }

        // Freeze just one row, 1st row usually field names
        if (freeze == 1) {
            // freeze row
            sheet.createFreezePane(0, 1, 0, 1);
        }
    }

}

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);//w ww.  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/*from  ww w .  ja  v a2s .  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  .  ja  va2 s  . c om
 * @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  w w  .  j ava2  s.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  ww .  j a  v  a2  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//w  w w  . j a  v a 2  s  .co 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 w w  . j  a v a 2 s . c  o m
 * @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;
        }
    }
}

From source file:org.etudes.mneme.impl.AttachmentServiceImpl.java

License:Apache License

/**
 * Creates the Order tab for answers Item Analysis
 *
 * @param or_questions List of Order questions
 * @param workbook Workbook object//from  w  w  w  .jav a  2 s . com
 * @param assessment Assessment object
 */
void createOrderTab(List<Question> or_questions, HSSFWorkbook workbook, Assessment assessment) {
    if (or_questions == null || or_questions.size() == 0)
        return;

    String assmtId = assessment.getId();
    HSSFSheet sheet = null;
    HSSFRow row;
    String[] choiceLabels = new String[] { "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10." };
    int[] choiceCount = new int[10];

    //Determine which question has most number of choices so as to determine header column count
    int headerSize = getMaxChoices(or_questions);

    boolean headerRowDone = false;
    //Iterate through each question
    for (Iterator it = or_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("Order");
            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 = ((OrderQuestionImpl) q.getTypeSpecificQuestion()).getCorrectAnswerSet();

        List<OrderQuestionImpl.OrderQuestionChoice> choiceList = ((OrderQuestionImpl) q
                .getTypeSpecificQuestion()).getChoicesAsAuthored();
        choiceListSize = choiceList.size();

        //Iterate through each submission
        for (Answer answer : answers) {
            TypeSpecificAnswer a = answer.getTypeSpecificAnswer();

            if (a instanceof OrderAnswerImpl) {
                OrderAnswerImpl oa = (OrderAnswerImpl) a;
                Map<String, Value> ansMap = oa.getAnswer();

                int l = 0;
                for (OrderQuestionImpl.OrderQuestionChoice oqc : choiceList) {
                    if (ansMap.get(oqc.getId()) != null) {
                        Value value = ansMap.get(oqc.getId());
                        if (value.getValue() != null && value.getValue().equals(String.valueOf(l))) {
                            choiceCount[l]++;
                        }
                    }
                    l++;
                }

            }
        }
        int rowNum = sheet.getLastRowNum() + 1;
        row = sheet.createRow(rowNum);

        String[] choiceTextArray = new String[choiceList.size()];
        int j = 0;

        for (OrderQuestionImpl.OrderQuestionChoice oqc : choiceList) {
            choiceTextArray[j] = (j + 1) + "." + stripHtml(oqc.getText());
            j++;
        }
        String quest_desc = stripHtml(q.getDescription()) + getCommaAnswers(choiceTextArray);
        row.createCell((short) 0).setCellValue(quest_desc);
        for (int k = 1; k <= choiceListSize; k++) {
            row.createCell((short) k).setCellValue(choiceCount[k - 1]);
        }
        for (int k = 1; k <= choiceListSize; k++) {
            choiceCount[k - 1] = 0;
        }
    }
}