Example usage for java.lang Math log10

List of usage examples for java.lang Math log10

Introduction

In this page you can find the example usage for java.lang Math log10.

Prototype

@HotSpotIntrinsicCandidate
public static double log10(double a) 

Source Link

Document

Returns the base 10 logarithm of a double value.

Usage

From source file:com.example.sensingapp.SensingApp.java

private void calculateAudioSoundLevel() {
    long nTotalVal;
    int nLen;// w w  w  . j  a  v a  2 s  .com
    short shtBuffer[];

    while (m_soundLevelThread != null && m_blnRecordSoundLevel == true) {

        if (m_nAudioReadCount != AudioRecord.ERROR_INVALID_OPERATION) {
            nTotalVal = 0;

            shtBuffer = DataUtil.Bytes2Shorts(m_btAudioBuffer, m_nAudioReadCount);

            nLen = shtBuffer.length;

            for (int i = 0; i < nLen; i++) {
                nTotalVal = nTotalVal + shtBuffer[i] * shtBuffer[i];
            }

            double fMean = nTotalVal * 1.0 / nLen;

            if (fMean == 0) {
                m_fSoundLevelDb = 1000;
            } else {
                m_fSoundLevelDb = 10 * Math.log10(fMean);
            }

            if (Double.isInfinite(m_fSoundLevelDb) || Double.isNaN(m_fSoundLevelDb)) {

            } else {
                recordSoundLevel(m_fSoundLevelDb);
            }

        } // if

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {

        }
    } // while
}

From source file:com.sonicle.webtop.mail.Service.java

private void outputJarMailFolder(String foldername, Message msgs[], JarOutputStream jos) throws Exception {
    int digits = (msgs.length > 0 ? (int) Math.log10(msgs.length) + 1 : 1);
    for (int i = 0; i < msgs.length; ++i) {
        Message msg = msgs[i];/* www  .  j  a v  a 2 s.  co m*/
        String subject = msg.getSubject();
        if (subject != null)
            subject = subject.replace('/', '_').replace('\\', '_').replace(':', '-');
        else
            subject = "";
        java.util.Date date = msg.getReceivedDate();
        if (date == null)
            date = new java.util.Date();

        String fname = LangUtils.zerofill(i + 1, digits) + " - " + subject + ".eml";
        String fullname = null;
        if (foldername != null && !foldername.isEmpty())
            fullname = foldername + "/" + fname;
        else
            fullname = fname;
        JarEntry je = new JarEntry(fullname);
        je.setTime(date.getTime());
        jos.putNextEntry(je);
        msg.writeTo(jos);
        jos.closeEntry();
    }
    jos.flush();
}

From source file:org.sakaiproject.assignment.impl.BaseAssignmentService.java

/**
 * Access and output the grades spreadsheet for the reference, either for an assignment or all assignments in a context.
 *
 * @param out// w ww  . jav a 2s.c om
 *        The outputStream to stream the grades spreadsheet into.
 * @param ref
 *        The reference, either to a specific assignment, or just to an assignment context.
 * @return Whether the grades spreadsheet is successfully output.
 * @throws IdUnusedException
 *         if there is no object with this id.
 * @throws PermissionException
 *         if the current user is not allowed to access this.
 */
public boolean getGradesSpreadsheet(final OutputStream out, final String ref)
        throws IdUnusedException, PermissionException {
    boolean retVal = false;
    String typeGradesString = REF_TYPE_GRADES + Entity.SEPARATOR;
    String[] parts = ref.substring(ref.indexOf(typeGradesString) + typeGradesString.length())
            .split(Entity.SEPARATOR);
    String idSite = (parts.length > 1) ? parts[1] : parts[0];
    String context = (parts.length > 1) ? SiteService.siteGroupReference(idSite, parts[3])
            : SiteService.siteReference(idSite);

    // get site title for display purpose
    String siteTitle = "";
    String sheetName = "";
    try {
        siteTitle = (parts.length > 1)
                ? SiteService.getSite(idSite).getTitle() + " - "
                        + SiteService.getSite(idSite).getGroup((String) parts[3]).getTitle()
                : SiteService.getSite(idSite).getTitle();
        sheetName = (parts.length > 1) ? SiteService.getSite(idSite).getGroup((String) parts[3]).getTitle()
                : SiteService.getSite(idSite).getTitle();
    } catch (Exception e) {
        // ignore exception
        M_log.debug(this + ":getGradesSpreadsheet cannot get site context=" + idSite + e.getMessage());
    }

    // does current user allowed to grade any assignment?
    boolean allowGradeAny = false;
    List assignmentsList = getListAssignmentsForContext(idSite);
    for (int iAssignment = 0; !allowGradeAny && iAssignment < assignmentsList.size(); iAssignment++) {
        if (allowGradeSubmission(((Assignment) assignmentsList.get(iAssignment)).getReference())) {
            allowGradeAny = true;
        }
    }

    if (!allowGradeAny) {
        // not permitted to download the spreadsheet
        return false;
    } else {
        int rowNum = 0;
        HSSFWorkbook wb = new HSSFWorkbook();

        HSSFSheet sheet = wb.createSheet(WorkbookUtil.createSafeSheetName(sheetName));

        // Create a row and put some cells in it. Rows are 0 based.
        HSSFRow row = sheet.createRow(rowNum++);

        row.createCell(0).setCellValue(rb.getString("download.spreadsheet.title"));

        // empty line
        row = sheet.createRow(rowNum++);
        row.createCell(0).setCellValue("");

        // site title
        row = sheet.createRow(rowNum++);
        row.createCell(0).setCellValue(rb.getString("download.spreadsheet.site") + siteTitle);

        // download time
        row = sheet.createRow(rowNum++);
        row.createCell(0).setCellValue(
                rb.getString("download.spreadsheet.date") + TimeService.newTime().toStringLocalFull());

        // empty line
        row = sheet.createRow(rowNum++);
        row.createCell(0).setCellValue("");

        HSSFCellStyle style = wb.createCellStyle();

        // this is the header row number
        int headerRowNumber = rowNum;
        // set up the header cells
        row = sheet.createRow(rowNum++);
        int cellNum = 0;

        // user enterprise id column
        HSSFCell cell = row.createCell(cellNum++);
        cell.setCellStyle(style);
        cell.setCellValue(rb.getString("download.spreadsheet.column.name"));

        // user name column
        cell = row.createCell(cellNum++);
        cell.setCellStyle(style);
        cell.setCellValue(rb.getString("download.spreadsheet.column.userid"));

        // starting from this row, going to input user data
        Iterator assignments = new SortedIterator(assignmentsList.iterator(),
                new AssignmentComparator("duedate", "true"));

        // site members excluding those who can add assignments
        List members = new ArrayList();
        // hashmap which stores the Excel row number for particular user
        HashMap user_row = new HashMap();

        List allowAddAnySubmissionUsers = allowAddAnySubmissionUsers(context);
        for (Iterator iUserIds = new SortedIterator(allowAddAnySubmissionUsers.iterator(),
                new AssignmentComparator("sortname", "true")); iUserIds.hasNext();) {
            String userId = (String) iUserIds.next();
            try {
                User u = UserDirectoryService.getUser(userId);
                members.add(u);
                // create the column for user first
                row = sheet.createRow(rowNum);
                // update user_row Hashtable
                user_row.put(u.getId(), Integer.valueOf(rowNum));
                // increase row
                rowNum++;
                // put user displayid and sortname in the first two cells
                cellNum = 0;
                row.createCell(cellNum++).setCellValue(u.getSortName());
                row.createCell(cellNum).setCellValue(u.getDisplayId());
            } catch (Exception e) {
                M_log.warn(" getGradesSpreadSheet " + e.getMessage() + " userId = " + userId);
            }
        }

        int index = 0;
        // the grade data portion starts from the third column, since the first two are used for user's display id and sort name
        while (assignments.hasNext()) {
            Assignment a = (Assignment) assignments.next();

            int assignmentType = a.getContent().getTypeOfGrade();

            // for column header, check allow grade permission based on each assignment
            if (!a.getDraft() && allowGradeSubmission(a.getReference())) {
                // put in assignment title as the column header
                rowNum = headerRowNumber;
                row = sheet.getRow(rowNum++);
                cellNum = (index + 2);
                cell = row.createCell(cellNum); // since the first two column is taken by student id and name
                cell.setCellStyle(style);
                cell.setCellValue(a.getTitle());

                for (int loopNum = 0; loopNum < members.size(); loopNum++) {
                    // prepopulate the column with the "no submission" string
                    row = sheet.getRow(rowNum++);
                    cell = row.createCell(cellNum);
                    cell.setCellType(1);
                    cell.setCellValue(rb.getString("listsub.nosub"));
                }

                // begin to populate the column for this assignment, iterating through student list
                for (Iterator sIterator = getSubmissions(a).iterator(); sIterator.hasNext();) {
                    AssignmentSubmission submission = (AssignmentSubmission) sIterator.next();

                    String userId = submission.getSubmitterId();

                    if (a.isGroup()) {

                        User[] _users = submission.getSubmitters();
                        for (int i = 0; _users != null && i < _users.length; i++) {

                            userId = _users[i].getId();

                            if (user_row.containsKey(userId)) {
                                // find right row
                                row = sheet.getRow(((Integer) user_row.get(userId)).intValue());

                                if (submission.getGraded() && submission.getGrade() != null) {
                                    // graded and released
                                    if (assignmentType == 3) {
                                        try {
                                            // numeric cell type?
                                            String grade = submission.getGradeForUser(userId) == null
                                                    ? submission.getGradeDisplay()
                                                    : submission.getGradeForUser(userId);
                                            int factor = submission.getAssignment().getContent().getFactor();
                                            int dec = (int) Math.log10(factor);

                                            //We get float number no matter the locale it was managed with.
                                            NumberFormat nbFormat = FormattedText.getNumberFormat(dec, dec,
                                                    null);
                                            float f = nbFormat.parse(grade).floatValue();

                                            // remove the String-based cell first
                                            cell = row.getCell(cellNum);
                                            row.removeCell(cell);
                                            // add number based cell
                                            cell = row.createCell(cellNum);
                                            cell.setCellType(0);
                                            cell.setCellValue(f);

                                            style = wb.createCellStyle();
                                            String format = "#,##0.";
                                            for (int j = 0; j < dec; j++) {
                                                format = format.concat("0");
                                            }
                                            style.setDataFormat(wb.createDataFormat().getFormat(format));
                                            cell.setCellStyle(style);
                                        } catch (Exception e) {
                                            // if the grade is not numeric, let's make it as String type
                                            // No need to remove the cell and create a new one, as the existing one is String type.
                                            cell = row.getCell(cellNum);
                                            cell.setCellType(1);
                                            cell.setCellValue(submission.getGradeForUser(userId) == null
                                                    ? submission.getGradeDisplay()
                                                    : submission.getGradeForUser(userId));
                                        }
                                    } else {
                                        // String cell type
                                        cell = row.getCell(cellNum);
                                        cell.setCellValue(submission.getGradeForUser(userId) == null
                                                ? submission.getGradeDisplay()
                                                : submission.getGradeForUser(userId));
                                    }
                                } else if (submission.getSubmitted() && submission.getTimeSubmitted() != null) {
                                    // submitted, but no grade available yet
                                    cell = row.getCell(cellNum);
                                    cell.setCellValue(rb.getString("gen.nograd"));
                                }
                            } // if
                        }

                    } else {

                        if (user_row.containsKey(userId)) {
                            // find right row
                            row = sheet.getRow(((Integer) user_row.get(userId)).intValue());

                            if (submission.getGraded() && submission.getGrade() != null) {
                                // graded and released
                                if (assignmentType == 3) {
                                    try {
                                        // numeric cell type?
                                        String grade = submission.getGradeDisplay();
                                        int factor = submission.getAssignment().getContent().getFactor();
                                        int dec = (int) Math.log10(factor);

                                        //We get float number no matter the locale it was managed with.
                                        NumberFormat nbFormat = FormattedText.getNumberFormat(dec, dec, null);
                                        float f = nbFormat.parse(grade).floatValue();

                                        // remove the String-based cell first
                                        cell = row.getCell(cellNum);
                                        row.removeCell(cell);
                                        // add number based cell
                                        cell = row.createCell(cellNum);
                                        cell.setCellType(0);
                                        cell.setCellValue(f);

                                        style = wb.createCellStyle();
                                        String format = "#,##0.";
                                        for (int j = 0; j < dec; j++) {
                                            format = format.concat("0");
                                        }
                                        style.setDataFormat(wb.createDataFormat().getFormat(format));
                                        cell.setCellStyle(style);
                                    } catch (Exception e) {
                                        // if the grade is not numeric, let's make it as String type
                                        // No need to remove the cell and create a new one, as the existing one is String type. 
                                        cell = row.getCell(cellNum);
                                        cell.setCellType(1);
                                        // Setting grade display instead grade.
                                        cell.setCellValue(submission.getGradeDisplay());
                                    }
                                } else {
                                    // String cell type
                                    cell = row.getCell(cellNum);
                                    cell.setCellValue(submission.getGradeDisplay());
                                }
                            } else if (submission.getSubmitted() && submission.getTimeSubmitted() != null) {
                                // submitted, but no grade available yet
                                cell = row.getCell(cellNum);
                                cell.setCellValue(rb.getString("gen.nograd"));
                            }
                        } // if

                    }
                }
            }

            index++;

        }

        // output
        try {
            wb.write(out);
            retVal = true;
        } catch (IOException e) {
            M_log.warn(" getGradesSpreadsheet Can not output the grade spread sheet for reference= " + ref);
        }

        return retVal;
    }

}

From source file:org.sakaiproject.assignment.tool.AssignmentAction.java

protected String build_student_review_edit_context(VelocityPortlet portlet, Context context, RunData data,
        SessionState state) {//from   w w  w  .j ava 2  s .  co m
    int gradeType = -1;
    context.put("context", state.getAttribute(STATE_CONTEXT_STRING));
    List<PeerAssessmentItem> peerAssessmentItems = (List<PeerAssessmentItem>) state
            .getAttribute(PEER_ASSESSMENT_ITEMS);
    String assignmentId = (String) state.getAttribute(VIEW_ASSIGNMENT_ID);
    User sessionUser = (User) state.getAttribute(STATE_USER);
    String assessorId = sessionUser.getId();
    if (state.getAttribute(PEER_ASSESSMENT_ASSESSOR_ID) != null) {
        assessorId = (String) state.getAttribute(PEER_ASSESSMENT_ASSESSOR_ID);
    }
    int factor = AssignmentService.getScaleFactor();
    int dec = (int) Math.log10(factor);
    Assignment assignment = getAssignment(assignmentId, "build_student_review_edit_context", state);
    if (assignment != null) {
        context.put("assignment", assignment);
        if (assignment.getContent() != null) {
            gradeType = assignment.getContent().getTypeOfGrade();
            factor = assignment.getContent().getFactor();
            dec = (int) Math.log10(factor);
        }
        context.put("peerAssessmentInstructions", assignment.getPeerAssessmentInstructions() == null ? ""
                : assignment.getPeerAssessmentInstructions());
    }
    String submissionId = "";
    SecurityAdvisor secAdv = new SecurityAdvisor() {
        @Override
        public SecurityAdvice isAllowed(String userId, String function, String reference) {
            if ("asn.submit".equals(function) || "asn.submit".equals(function)
                    || "asn.grade".equals(function)) {
                return SecurityAdvice.ALLOWED;
            }
            return null;
        }
    };
    AssignmentSubmission s = null;
    try {
        //surround with a try/catch/finally for the security advisor
        m_securityService.pushAdvisor(secAdv);
        s = getSubmission((String) state.getAttribute(GRADE_SUBMISSION_SUBMISSION_ID),
                "build_student_review_edit_context", state);
        m_securityService.popAdvisor(secAdv);
    } catch (Exception e) {
        M_log.error(e.getMessage(), e);
    } finally {
        if (secAdv != null) {
            m_securityService.popAdvisor(secAdv);
        }
    }
    if (s != null) {
        submissionId = s.getId();
        context.put("submission", s);

        ResourceProperties p = s.getProperties();
        if (p.getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT) != null) {
            context.put("prevFeedbackText",
                    p.getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_TEXT));
        }

        if (p.getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT) != null) {
            context.put("prevFeedbackComment",
                    p.getProperty(ResourceProperties.PROP_SUBMISSION_PREVIOUS_FEEDBACK_COMMENT));
        }

        if (p.getProperty(PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS) != null) {
            context.put("prevFeedbackAttachments", getPrevFeedbackAttachments(p));
        }
        if ((s.getFeedbackText() == null) || (s.getFeedbackText().length() == 0)) {
            context.put("value_feedback_text", s.getSubmittedText());
        } else {
            context.put("value_feedback_text", s.getFeedbackFormattedText());
        }

        context.put("value_feedback_text", s.getSubmittedText());
        List v = EntityManager.newReferenceList();
        Iterator attachments = s.getFeedbackAttachments().iterator();
        while (attachments.hasNext()) {
            v.add(attachments.next());
        }
        context.put("value_feedback_attachment", v);
        state.setAttribute(ATTACHMENTS, v);
    }
    if (peerAssessmentItems != null && submissionId != null) {
        //find the peerAssessmentItem for this submission:
        PeerAssessmentItem peerAssessmentItem = null;
        for (PeerAssessmentItem item : peerAssessmentItems) {
            if (submissionId.equals(item.getSubmissionId()) && assessorId.equals(item.getAssessorUserId())) {
                peerAssessmentItem = item;
                break;
            }
        }
        if (peerAssessmentItem != null) {
            //check if current user is the peer assessor, if not, only display data (no editing)
            if (!sessionUser.getId().equals(peerAssessmentItem.getAssessorUserId())) {
                context.put("view_only", true);
                try {
                    User reviewer = UserDirectoryService.getUser(peerAssessmentItem.getAssessorUserId());
                    context.put("reviewer", reviewer);
                } catch (UserNotDefinedException e) {
                    M_log.error(e.getMessage(), e);
                }
            } else {
                context.put("view_only", false);
            }

            //scores are saved as whole values
            //so a score of 1.3 would be stored as 13
            //so a DB score of 13 needs to be 1.3:
            String decSeparator = FormattedText.getDecimalSeparator();
            if (peerAssessmentItem.getScore() != null) {
                double score = peerAssessmentItem.getScore() / (double) factor;
                try {
                    String rv = StringUtils.replace(Double.toString(score),
                            (",".equals(decSeparator) ? "." : ","), decSeparator);
                    NumberFormat nbFormat = FormattedText.getNumberFormat(dec, dec, false);
                    DecimalFormat dcformat = (DecimalFormat) nbFormat;
                    Double dblGrade = dcformat.parse(rv).doubleValue();
                    rv = nbFormat.format(dblGrade);
                    context.put("value_grade", rv);
                    context.put("display_grade", rv);
                } catch (Exception e) {
                    M_log.warn(this
                            + ":build_student_review_edit_context: Parse Error in display_Grade peerAssesmentItem"
                            + e.getMessage());
                }
            } else {
                context.put("value_grade", null);
                context.put("display_grade", "");
            }
            context.put("item_removed", peerAssessmentItem.isRemoved());
            context.put("value_feedback_comment", peerAssessmentItem.getComment());

            //set previous/next values
            List userSubmissionsState = state.getAttribute(STATE_PAGEING_TOTAL_ITEMS) != null
                    ? (List) state.getAttribute(STATE_PAGEING_TOTAL_ITEMS)
                    : null;
            List<String> userSubmissions = new ArrayList<String>();
            boolean instructorView = false;
            if (userSubmissionsState != null && userSubmissionsState.size() > 0
                    && userSubmissionsState.get(0) instanceof SubmitterSubmission) {
                //from instructor view
                for (SubmitterSubmission userSubmission : (List<SubmitterSubmission>) userSubmissionsState) {
                    if (!userSubmissions.contains(userSubmission.getSubmission().getId())
                            && userSubmission.getSubmission().getSubmitted()) {
                        userSubmissions.add(userSubmission.getSubmission().getId());
                    }
                }
            } else {
                //student view
                for (PeerAssessmentItem item : peerAssessmentItems) {
                    if (!userSubmissions.contains(item.getSubmissionId()) && !item.isSubmitted()) {
                        userSubmissions.add(item.getSubmissionId());
                    }
                }
            }
            if (userSubmissions != null) {
                context.put("totalReviews", userSubmissions.size());
                //first setup map to make the navigation logic easier:
                Map<String, List<PeerAssessmentItem>> itemMap = new HashMap<String, List<PeerAssessmentItem>>();
                for (String userSubmissionId : userSubmissions) {
                    for (PeerAssessmentItem item : peerAssessmentItems) {
                        if (userSubmissionId.equals(item.getSubmissionId())) {
                            List<PeerAssessmentItem> items = itemMap.get(userSubmissionId);
                            if (items == null) {
                                items = new ArrayList<PeerAssessmentItem>();
                            }
                            items.add(item);
                            itemMap.put(item.getSubmissionId(), items);
                        }
                    }
                }
                for (int i = 0; i < userSubmissions.size(); i++) {
                    String userSubmissionId = userSubmissions.get(i);
                    if (userSubmissionId.equals(submissionId)) {
                        //we found the right submission, now find the items
                        context.put("reviewNumber", (i + 1));
                        List<PeerAssessmentItem> submissionItems = itemMap.get(submissionId);
                        if (submissionItems != null) {
                            for (int j = 0; j < submissionItems.size(); j++) {
                                PeerAssessmentItem item = submissionItems.get(j);
                                if (item.getAssessorUserId().equals(assessorId)) {
                                    context.put("anonNumber", i + 1);
                                    boolean goPT = false;
                                    boolean goNT = false;
                                    if ((i - 1) >= 0 || (j - 1) >= 0) {
                                        goPT = true;
                                    }
                                    if ((i + 1) < userSubmissions.size() || (j + 1) < submissionItems.size()) {
                                        goNT = true;
                                    }
                                    context.put("goPTButton", Boolean.valueOf(goPT));
                                    context.put("goNTButton", Boolean.valueOf(goNT));

                                    if (j > 0) {
                                        // retrieve the previous submission id
                                        context.put("prevSubmissionId",
                                                (submissionItems.get(j - 1).getSubmissionId()));
                                        context.put("prevAssessorId",
                                                (submissionItems.get(j - 1).getAssessorUserId()));
                                    } else if (i > 0) {
                                        //go to previous submission and grab the last item in that list
                                        int k = i - 1;
                                        while (k >= 0 && !itemMap.containsKey(userSubmissions.get(k))) {
                                            k--;
                                        }
                                        if (k >= 0 && itemMap.get(userSubmissions.get(k)).size() > 0) {
                                            List<PeerAssessmentItem> pItems = itemMap
                                                    .get(userSubmissions.get(k));
                                            PeerAssessmentItem pItem = pItems.get(pItems.size() - 1);
                                            context.put("prevSubmissionId", (pItem.getSubmissionId()));
                                            context.put("prevAssessorId", (pItem.getAssessorUserId()));
                                        } else {
                                            //no previous option, set to false
                                            context.put("goPTButton", Boolean.valueOf(false));
                                        }
                                    }

                                    if (j < submissionItems.size() - 1) {
                                        // retrieve the next submission id
                                        context.put("nextSubmissionId",
                                                (submissionItems.get(j + 1).getSubmissionId()));
                                        context.put("nextAssessorId",
                                                (submissionItems.get(j + 1).getAssessorUserId()));
                                    } else if (i < userSubmissions.size() - 1) {
                                        //go to previous submission and grab the last item in that list
                                        int k = i + 1;
                                        while (k < userSubmissions.size()
                                                && !itemMap.containsKey(userSubmissions.get(k))) {
                                            k++;
                                        }
                                        if (k < userSubmissions.size()
                                                && itemMap.get(userSubmissions.get(k)).size() > 0) {
                                            List<PeerAssessmentItem> pItems = itemMap
                                                    .get(userSubmissions.get(k));
                                            PeerAssessmentItem pItem = pItems.get(0);
                                            context.put("nextSubmissionId", (pItem.getSubmissionId()));
                                            context.put("nextAssessorId", (pItem.getAssessorUserId()));
                                        } else {
                                            //no next option, set to false
                                            context.put("goNTButton", Boolean.valueOf(false));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

    }

    context.put("assignment_expand_flag", state.getAttribute(GRADE_SUBMISSION_ASSIGNMENT_EXPAND_FLAG));
    context.put("user", sessionUser);
    context.put("submissionTypeTable", submissionTypeTable());
    context.put("instructorAttachments", state.getAttribute(ATTACHMENTS));
    context.put("contentTypeImageService", state.getAttribute(STATE_CONTENT_TYPE_IMAGE_SERVICE));
    context.put("service", AssignmentService.getInstance());
    // names
    context.put("name_grade_assignment_id", GRADE_SUBMISSION_ASSIGNMENT_ID);
    context.put("name_feedback_comment", GRADE_SUBMISSION_FEEDBACK_COMMENT);
    context.put("name_feedback_text", GRADE_SUBMISSION_FEEDBACK_TEXT);
    context.put("name_feedback_attachment", GRADE_SUBMISSION_FEEDBACK_ATTACHMENT);
    context.put("name_grade", GRADE_SUBMISSION_GRADE);
    context.put("name_allowResubmitNumber", AssignmentSubmission.ALLOW_RESUBMIT_NUMBER);

    // put supplement item into context
    try {
        //surround with a try/catch/finally for the security advisor
        m_securityService.pushAdvisor(secAdv);
        supplementItemIntoContext(state, context, assignment, null);
    } catch (Exception e) {
        M_log.error(e.getMessage(), e);
    } finally {
        if (secAdv != null) {
            m_securityService.popAdvisor(secAdv);
        }
    }
    // put the grade confirmation message if applicable
    if (state.getAttribute(GRADE_SUBMISSION_DONE) != null) {
        context.put("gradingDone", Boolean.TRUE);
        state.removeAttribute(GRADE_SUBMISSION_DONE);
        if (state.getAttribute(PEER_ASSESSMENT_REMOVED_STATUS) != null) {
            context.put("itemRemoved", state.getAttribute(PEER_ASSESSMENT_REMOVED_STATUS));
            state.removeAttribute(PEER_ASSESSMENT_REMOVED_STATUS);
        }
    }
    // put the grade confirmation message if applicable
    if (state.getAttribute(GRADE_SUBMISSION_SUBMIT) != null) {
        context.put("gradingSubmit", Boolean.TRUE);
        state.removeAttribute(GRADE_SUBMISSION_SUBMIT);
    }

    String template = (String) getContext(data).get("template");
    return template + TEMPLATE_STUDENT_REVIEW_EDIT;
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.Maths.java

/**
 * log10 - evaluate the logarithm function on each element of the dataset
 * @param a/*from w  ww  .ja  va  2 s . com*/
 * @return dataset
 */
@SuppressWarnings("cast")
public static AbstractDataset log10(final AbstractDataset a) {
    final int isize;
    final IndexIterator it = a.getIterator();
    AbstractDataset ds;
    final int dt = a.getDtype();

    switch (dt) {
    case AbstractDataset.INT8:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32);
        final byte[] i8data = ((ByteDataset) a).data;
        final float[] oi8data = ((FloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final byte ix = i8data[it.index];
            float ox;
            ox = (float) (Math.log10(ix));
            oi8data[i++] = ox;
        }
        break;
    case AbstractDataset.INT16:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32);
        final short[] i16data = ((ShortDataset) a).data;
        final float[] oi16data = ((FloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final short ix = i16data[it.index];
            float ox;
            ox = (float) (Math.log10(ix));
            oi16data[i++] = ox;
        }
        break;
    case AbstractDataset.INT32:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64);
        final int[] i32data = ((IntegerDataset) a).data;
        final double[] oi32data = ((DoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final int ix = i32data[it.index];
            double ox;
            ox = (double) (Math.log10(ix));
            oi32data[i++] = ox;
        }
        break;
    case AbstractDataset.INT64:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64);
        final long[] i64data = ((LongDataset) a).data;
        final double[] oi64data = ((DoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final long ix = i64data[it.index];
            double ox;
            ox = (double) (Math.log10(ix));
            oi64data[i++] = ox;
        }
        break;
    case AbstractDataset.ARRAYINT8:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32);
        isize = a.getElementsPerItem();
        final byte[] ai8data = ((CompoundByteDataset) a).data;
        final float[] oai8data = ((CompoundFloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final byte ix = ai8data[it.index + j];
                float ox;
                ox = (float) (Math.log10(ix));
                oai8data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.ARRAYINT16:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32);
        isize = a.getElementsPerItem();
        final short[] ai16data = ((CompoundShortDataset) a).data;
        final float[] oai16data = ((CompoundFloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final short ix = ai16data[it.index + j];
                float ox;
                ox = (float) (Math.log10(ix));
                oai16data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.ARRAYINT32:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64);
        isize = a.getElementsPerItem();
        final int[] ai32data = ((CompoundIntegerDataset) a).data;
        final double[] oai32data = ((CompoundDoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final int ix = ai32data[it.index + j];
                double ox;
                ox = (double) (Math.log10(ix));
                oai32data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.ARRAYINT64:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64);
        isize = a.getElementsPerItem();
        final long[] ai64data = ((CompoundLongDataset) a).data;
        final double[] oai64data = ((CompoundDoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final long ix = ai64data[it.index + j];
                double ox;
                ox = (double) (Math.log10(ix));
                oai64data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.FLOAT32:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32);
        final float[] f32data = ((FloatDataset) a).data;
        final float[] of32data = ((FloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final float ix = f32data[it.index];
            float ox;
            ox = (float) (Math.log10(ix));
            of32data[i++] = ox;
        }
        break;
    case AbstractDataset.FLOAT64:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64);
        final double[] f64data = ((DoubleDataset) a).data;
        final double[] of64data = ((DoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final double ix = f64data[it.index];
            double ox;
            ox = (double) (Math.log10(ix));
            of64data[i++] = ox;
        }
        break;
    case AbstractDataset.ARRAYFLOAT32:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32);
        isize = a.getElementsPerItem();
        final float[] af32data = ((CompoundFloatDataset) a).data;
        final float[] oaf32data = ((CompoundFloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final float ix = af32data[it.index + j];
                float ox;
                ox = (float) (Math.log10(ix));
                oaf32data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.ARRAYFLOAT64:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64);
        isize = a.getElementsPerItem();
        final double[] af64data = ((CompoundDoubleDataset) a).data;
        final double[] oaf64data = ((CompoundDoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final double ix = af64data[it.index + j];
                double ox;
                ox = (double) (Math.log10(ix));
                oaf64data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.COMPLEX64:
        ds = AbstractDataset.zeros(a, AbstractDataset.COMPLEX64);
        final float[] c64data = ((ComplexFloatDataset) a).data;
        final float[] oc64data = ((ComplexFloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final float ix = c64data[it.index];
            final float iy = c64data[it.index + 1];
            float ox;
            float oy;
            ox = (float) (Math.log10(Math.hypot(ix, iy)));
            oy = (float) (Math.atan2(iy, ix));
            oc64data[i++] = ox;
            oc64data[i++] = oy;
        }
        break;
    case AbstractDataset.COMPLEX128:
        ds = AbstractDataset.zeros(a, AbstractDataset.COMPLEX128);
        final double[] c128data = ((ComplexDoubleDataset) a).data;
        final double[] oc128data = ((ComplexDoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final double ix = c128data[it.index];
            final double iy = c128data[it.index + 1];
            double ox;
            double oy;
            ox = (double) (Math.log10(Math.hypot(ix, iy)));
            oy = (double) (Math.atan2(iy, ix));
            oc128data[i++] = ox;
            oc128data[i++] = oy;
        }
        break;
    default:
        throw new IllegalArgumentException(
                "log10 supports integer, compound integer, real, compound real, complex datasets only");
    }

    ds.setName(a.getName());
    addFunctionName(ds, "log10");
    return ds;
}

From source file:org.sakaiproject.assignment.tool.AssignmentAction.java

/**
 * read review grade information form and see if any grading information has been changed
 * @param data// w  ww.j a  va  2  s  .  co  m
 * @param state
 * @param gradeOption
 * @return
 */
public boolean saveReviewGradeForm(RunData data, SessionState state, String gradeOption) {
    String assessorUserId = UserDirectoryService.getCurrentUser().getId();
    if (state.getAttribute(PEER_ASSESSMENT_ASSESSOR_ID) != null
            && !assessorUserId.equals(state.getAttribute(PEER_ASSESSMENT_ASSESSOR_ID))) {
        //this is only set during the read only view, so just return
        return false;
    }
    ParameterParser params = data.getParameters();
    String submissionRef = params.getString("submissionId");
    String submissionId = null;
    if (submissionRef != null) {
        int i = submissionRef.lastIndexOf(Entity.SEPARATOR);
        if (i == -1) {
            submissionId = submissionRef;
        } else {
            submissionId = submissionRef.substring(i + 1);
        }
    }
    if (submissionId != null) {

        //call the DB to make sure this user can edit this assessment, otherwise it wouldn't exist
        PeerAssessmentItem item = assignmentPeerAssessmentService.getPeerAssessmentItem(submissionId,
                assessorUserId);
        if (item != null) {
            //find the original assessment item and compare to see if it has changed
            //if so, save it
            boolean changed = false;

            if (submissionId.equals(item.getSubmissionId())
                    && assessorUserId.equals(item.getAssessorUserId())) {
                //Grade
                String g = StringUtils.trimToNull(params.getCleanString(GRADE_SUBMISSION_GRADE));
                Integer score = item.getScore();
                if (g != null && !"".equals(g)) {
                    try {
                        String assignmentId = (String) state.getAttribute(VIEW_ASSIGNMENT_ID);
                        if (assignmentId == null) {
                            addAlert(state, rb.getString("peerassessment.alert.saveerrorunkown"));
                        } else {
                            Assignment a = getAssignment(assignmentId, "saveReviewGradeForm", state);
                            if (a == null) {
                                addAlert(state, rb.getString("peerassessment.alert.saveerrorunkown"));
                            } else {
                                int factor = a.getContent().getFactor();
                                int dec = (int) Math.log10(factor);
                                String decSeparator = FormattedText.getDecimalSeparator();
                                g = StringUtils.replace(g, (",".equals(decSeparator) ? "." : ","),
                                        decSeparator);
                                NumberFormat nbFormat = FormattedText.getNumberFormat(dec, dec, false);
                                DecimalFormat dcformat = (DecimalFormat) nbFormat;
                                Double dScore = dcformat.parse(g).doubleValue();

                                if (dScore < 0) {
                                    addAlert(state, rb.getString("peerassessment.alert.saveinvalidscore"));
                                } else if (dScore <= a.getContent().getMaxGradePoint() / (double) factor) {
                                    //scores are saved as whole values
                                    //so a score of 1.3 would be stored as 13
                                    score = (int) Math.round(dScore * factor);
                                } else {
                                    addAlert(state, rb.getFormattedMessage("plesuse4", new Object[] { g,
                                            a.getContent().getMaxGradePoint() / (double) factor }));
                                }
                            }
                        }
                    } catch (Exception e) {
                        addAlert(state, rb.getString("peerassessment.alert.saveinvalidscore"));
                    }
                }
                boolean scoreChanged = false;
                if (score != null && item.getScore() == null || score == null && item.getScore() != null
                        || (score != null && item.getScore() != null && !score.equals(item.getScore()))) {
                    //Score changed
                    changed = true;
                    scoreChanged = true;
                    item.setScore(score);
                }

                //Comment:
                boolean checkForFormattingErrors = true;
                String feedbackComment = processFormattedTextFromBrowser(state,
                        params.getCleanString(GRADE_SUBMISSION_FEEDBACK_COMMENT), checkForFormattingErrors);
                if (feedbackComment != null && item.getComment() == null
                        || feedbackComment == null && item.getComment() != null || (feedbackComment != null
                                && item.getComment() != null && !feedbackComment.equals(item.getComment()))) {
                    //comment changed
                    changed = true;
                    item.setComment(feedbackComment);
                }
                //Submitted
                if ("submit".equals(gradeOption)) {
                    if (item.getScore() != null
                            || (item.getComment() != null && !"".equals(item.getComment().trim()))) {
                        item.setSubmitted(true);
                        changed = true;
                    } else {
                        addAlert(state, rb.getString("peerassessment.alert.savenoscorecomment"));
                    }
                }
                if (("submit".equals(gradeOption) || "save".equals(gradeOption))
                        && state.getAttribute(STATE_MESSAGE) == null) {
                    if (changed) {
                        //save this in the DB
                        assignmentPeerAssessmentService.savePeerAssessmentItem(item);
                        if (scoreChanged) {
                            //need to re-calcuate the overall score:
                            boolean saved = assignmentPeerAssessmentService.updateScore(submissionId);
                            if (saved) {
                                //we need to make sure the GB is updated correctly (or removed)
                                String assignmentId = (String) state.getAttribute(VIEW_ASSIGNMENT_ID);
                                if (assignmentId != null) {
                                    Assignment a = getAssignment(assignmentId, "saveReviewGradeForm", state);
                                    if (a != null) {
                                        String aReference = a.getReference();
                                        String associateGradebookAssignment = StringUtils
                                                .trimToNull(a.getProperties().getProperty(
                                                        AssignmentService.PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT));
                                        // update grade in gradebook
                                        integrateGradebook(state, aReference, associateGradebookAssignment,
                                                null, null, null, -1, null, submissionId, "update", -1);
                                    }
                                }
                            }
                        }
                        state.setAttribute(GRADE_SUBMISSION_DONE, Boolean.TRUE);
                        if ("submit".equals(gradeOption)) {
                            state.setAttribute(GRADE_SUBMISSION_SUBMIT, Boolean.TRUE);
                        }
                    }
                }

                //update session state:
                List<PeerAssessmentItem> peerAssessmentItems = (List<PeerAssessmentItem>) state
                        .getAttribute(PEER_ASSESSMENT_ITEMS);
                if (peerAssessmentItems != null) {
                    for (int i = 0; i < peerAssessmentItems.size(); i++) {
                        PeerAssessmentItem sItem = peerAssessmentItems.get(i);
                        if (sItem.getSubmissionId().equals(item.getSubmissionId())
                                && sItem.getAssessorUserId().equals(item.getAssessorUserId())) {
                            //found it, just update it
                            peerAssessmentItems.set(i, item);
                            state.setAttribute(PEER_ASSESSMENT_ITEMS, peerAssessmentItems);
                            break;
                        }
                    }
                }

            }

            return changed;
        } else {
            addAlert(state, rb.getString("peerassessment.alert.saveerrorunkown"));
        }
    } else {
        addAlert(state, rb.getString("peerassessment.alert.saveerrorunkown"));

    }
    return false;
}

From source file:org.sakaiproject.assignment.tool.AssignmentAction.java

/**
 * valid grade for point based type// www.  j  a v  a2 s .co m
 * returns a double value in a string from the localized input
 */
private String validPointGrade(SessionState state, String grade, int factor) {
    if (grade != null && !"".equals(grade)) {
        if (grade.startsWith("-")) {
            // check for negative sign
            addAlert(state, rb.getString("plesuse3"));
        } else {
            int dec = (int) Math.log10(factor);
            NumberFormat nbFormat = FormattedText.getNumberFormat();
            DecimalFormat dcFormat = (DecimalFormat) nbFormat;
            String decSeparator = FormattedText.getDecimalSeparator();

            // only the right decimal separator is allowed and no other grouping separator
            if ((",".equals(decSeparator) && grade.indexOf(".") != -1)
                    || (".".equals(decSeparator) && grade.indexOf(",") != -1) || grade.indexOf(" ") != -1) {
                addAlert(state, rb.getString("plesuse1"));
                return grade;
            }

            // parse grade from localized number format
            int index = grade.indexOf(decSeparator);
            if (index != -1) {
                // when there is decimal points inside the grade, scale the number by "factor"
                // but only one decimal place is supported
                // for example, change 100.0 to 1000
                if (!decSeparator.equals(grade)) {
                    if (grade.length() > index + dec + 1) {
                        // if there are more than "factor" decimal points
                        addAlert(state,
                                rb.getFormattedMessage("plesuse2", new Object[] { String.valueOf(dec) }));
                    } else {
                        // decimal points is the only allowed character inside grade
                        // replace it with '1', and try to parse the new String into int
                        String zeros = "";
                        for (int i = 0; i < dec; i++) {
                            zeros = zeros.concat("0");
                        }
                        String gradeString = grade.endsWith(decSeparator)
                                ? grade.substring(0, index).concat(zeros)
                                : grade.substring(0, index).concat(grade.substring(index + 1));
                        try {
                            nbFormat.parse(gradeString);
                            try {
                                Integer.parseInt(gradeString);
                            } catch (NumberFormatException e) {
                                M_log.warn(this + ":validPointGrade " + e.getMessage());
                                alertInvalidPoint(state, gradeString, factor);
                            }
                        } catch (ParseException e) {
                            M_log.warn(this + ":validPointGrade " + e.getMessage());
                            addAlert(state, rb.getString("plesuse1"));
                        }
                    }
                } else {
                    // grade is decSeparator
                    addAlert(state, rb.getString("plesuse1"));
                }
            } else {
                // There is no decimal point; should be int number
                String gradeString = grade;
                for (int i = 0; i < dec; i++) {
                    gradeString = gradeString.concat("0");
                }
                try {
                    nbFormat.parse(gradeString);
                    try {
                        Integer.parseInt(gradeString);
                    } catch (NumberFormatException e) {
                        M_log.warn(this + ":validPointGrade " + e.getMessage());
                        alertInvalidPoint(state, gradeString, factor);
                    }
                } catch (ParseException e) {
                    M_log.warn(this + ":validPointGrade " + e.getMessage());
                    addAlert(state, rb.getString("plesuse1"));
                }
            }
        }
    }
    return grade;

}

From source file:org.sakaiproject.assignment.tool.AssignmentAction.java

private void alertInvalidPoint(SessionState state, String grade, int factor) {
    String decSeparator = FormattedText.getDecimalSeparator();

    String VALID_CHARS_FOR_INT = "-01234567890";

    boolean invalid = false;
    // case 1: contains invalid char for int
    for (int i = 0; i < grade.length() && !invalid; i++) {
        char c = grade.charAt(i);
        if (VALID_CHARS_FOR_INT.indexOf(c) == -1) {
            invalid = true;/* w w w.  ja  v a  2 s.c  om*/
        }
    }
    if (invalid) {
        addAlert(state, rb.getString("plesuse1"));
    } else {
        int dec = (int) Math.log10(factor);
        int maxInt = Integer.MAX_VALUE / factor;
        int maxDec = Integer.MAX_VALUE - maxInt * factor;
        // case 2: Due to our internal scaling, input String is larger than Integer.MAX_VALUE/10
        addAlert(state,
                rb.getFormattedMessage("plesuse4",
                        new Object[] {
                                grade.substring(0, grade.length() - dec) + decSeparator
                                        + grade.substring(grade.length() - dec),
                                maxInt + decSeparator + maxDec }));
    }
}

From source file:org.sakaiproject.assignment.tool.AssignmentAction.java

/**
 * display grade properly//from w w w. ja  v  a  2  s.c o  m
 */
private String displayGrade(SessionState state, String grade, int factor) {
    if (state.getAttribute(STATE_MESSAGE) == null) {
        if (grade != null && (grade.length() >= 1)) {
            int dec = (int) Math.log10(factor);
            NumberFormat nbFormat = FormattedText.getNumberFormat(dec, dec, false);
            DecimalFormat dcformat = (DecimalFormat) nbFormat;
            String decSeparator = FormattedText.getDecimalSeparator();

            if (grade.indexOf(decSeparator) != -1) {
                if (grade.startsWith(decSeparator)) {
                    grade = "0".concat(grade);
                } else if (grade.endsWith(decSeparator)) {
                    for (int i = 0; i < dec; i++) {
                        grade = grade.concat("0");
                    }
                }
            } else {
                try {
                    Integer.parseInt(grade);
                    int length = grade.length();
                    if (length > dec) {
                        grade = grade.substring(0, grade.length() - dec) + decSeparator
                                + grade.substring(grade.length() - dec);
                    } else {
                        String newGrade = "0".concat(decSeparator);
                        for (int i = length; i < dec; i++) {
                            newGrade = newGrade.concat("0");
                        }
                        grade = newGrade.concat(grade);
                    }
                } catch (NumberFormatException e) {
                    // alert
                    alertInvalidPoint(state, grade, factor);
                    M_log.warn(this + ":displayGrade cannot parse grade into integer grade = " + grade
                            + e.getMessage());
                }
            }
            try {
                // show grade in localized number format
                Double dblGrade = dcformat.parse(grade).doubleValue();
                grade = nbFormat.format(dblGrade);
            } catch (Exception e) {
                // alert
                alertInvalidPoint(state, grade, factor);
                M_log.warn(this + ":displayGrade cannot parse grade into integer grade = " + grade
                        + e.getMessage());
            }
        } else {
            grade = "";
        }
    }
    return grade;

}

From source file:org.sakaiproject.assignment.tool.AssignmentAction.java

/**
 * scale the point value by "factor" if there is a valid point grade
 *///from www .j  a  v  a 2s. com
private String scalePointGrade(SessionState state, String point, int factor) {
    String decSeparator = FormattedText.getDecimalSeparator();
    int dec = (int) Math.log10(factor);

    point = validPointGrade(state, point, factor);

    if (state.getAttribute(STATE_MESSAGE) == null) {
        if (point != null && (point.length() >= 1)) {
            // when there is decimal points inside the grade, scale the number by "factor"
            // but only one decimal place is supported
            // for example, change 100.0 to 1000
            int index = point.indexOf(decSeparator);
            if (index != -1) {
                if (index == 0) {
                    // if the point is the first char, add a 0 for the integer part
                    point = "0".concat(point.substring(1));
                } else if (index < point.length() - 1) {
                    // adjust the number of decimals, adding 0's to the end 
                    int length = point.length() - index - 1;
                    for (int i = length; i < dec; i++) {
                        point = point + "0";
                    }

                    // use scale integer for gradePoint
                    point = point.substring(0, index) + point.substring(index + 1);
                } else {
                    // decimal point is the last char
                    point = point.substring(0, index);
                    for (int i = 0; i < dec; i++) {
                        point = point + "0";
                    }
                }
            } else {
                // if there is no decimal place, scale up the integer by "factor"
                for (int i = 0; i < dec; i++) {
                    point = point + "0";
                }
            }

            // filter out the "zero grade"
            if ("00".equals(point)) {
                point = "0";
            }
        }
    }

    if (StringUtils.trimToNull(point) != null) {
        try {
            point = Integer.valueOf(point).toString();
        } catch (Exception e) {
            M_log.warn(this + " scalePointGrade: cannot parse " + point + " into integer. " + e.getMessage());
        }
    }
    return point;

}