roundAndFormat: function (n) {
    if (n == null || n === '') {
      return '';
    }

    return I18n.n(round(n, round.DEFAULT));
  }
function combineAssignmentGroupGrades(assignmentGroupGrades, includeUngraded, options) {
  const scopedAssignmentGroupGrades = _.map(assignmentGroupGrades, assignmentGroupGrade => {
    const gradeVersion = includeUngraded ? assignmentGroupGrade.final : assignmentGroupGrade.current
    return {...gradeVersion, weight: assignmentGroupGrade.assignmentGroupWeight}
  })

  if (options.weightAssignmentGroups) {
    const relevantGroupGrades = scopedAssignmentGroupGrades.filter(grade => grade.possible)
    const fullWeight = sumBy(relevantGroupGrades, 'weight')

    let finalGrade = bigSum(_.map(relevantGroupGrades, weightedPercent))
    if (fullWeight === 0) {
      finalGrade = null
    } else if (fullWeight < 100) {
      finalGrade = toNumber(weightedPercent({score: finalGrade, possible: fullWeight, weight: 100}))
    }

    const submissionCount = sumBy(relevantGroupGrades, 'submission_count')
    const possible = submissionCount > 0 || includeUngraded ? 100 : 0
    let score = finalGrade && round(finalGrade, 2)
    score = isNaN(score) ? null : score

    return {score, possible}
  }

  return {
    score: sumBy(scopedAssignmentGroupGrades, 'score'),
    possible: sumBy(scopedAssignmentGroupGrades, 'possible')
  }
}
  render = (_row, _cell, grade /* value */, _columnDef, _dataContext) => {
    if (grade == null) {
      return ''
    }

    let percentage = getGradePercentage(grade.score, grade.possible)
    percentage = Number.isFinite(percentage) ? percentage : 0

    let possible = round(grade.possible, round.DEFAULT)
    possible = possible ? I18n.n(possible) : possible

    let letterGrade
    if (grade.possible && this.options.getGradingStandard()) {
      letterGrade = scoreToGrade(percentage, this.options.getGradingStandard())
    }

    let warning
    if (this.options.listMutedAssignments().length > 0) {
      warning = buildMutedAssignmentsWarning()
    }

    if (!warning) {
      const invalidAssignmentGroups = this.options.listInvalidAssignmentGroups()
      if (invalidAssignmentGroups.length > 0) {
        warning = buildInvalidAssignmentGroupsWarning(invalidAssignmentGroups)
      }
    }

    if (!warning && this.options.getTotalPointsPossible() === 0) {
      warning = buildNoPointsPossibleWarning()
    }

    const options = {
      hideTooltip: this.options.gradesAreWeighted && !warning,
      letterGrade,
      percentage: I18n.n(round(percentage, round.DEFAULT), {percentage: true}),
      possible,
      score: I18n.n(round(grade.score, round.DEFAULT)),
      showPointsNotPercent: this.options.shouldShowPoints(),
      warning
    }

    return render(options)
  }
  validateAndChangeNumber = (name, inputValue) => {
    const errorMessage = validationErrorMessage(inputValue, name);
    if (errorMessage) {
      const validationErrors = { ...this.props.latePolicy.validationErrors, [name]: errorMessage };
      return this.props.changeLatePolicy({ ...this.props.latePolicy, validationErrors });
    }

    let newValue = Round(NumberHelper.parse(inputValue), 2);
    if (name === 'missingSubmissionDeduction') {
      // "Mark missing submission with 40 percent" => missingSubmissionDeduction is 60
      newValue = 100 - newValue;
    }
    return this.changeNumber(name, newValue);
  }
function combineGradingPeriodGrades(gradingPeriodGradesByPeriodId, includeUngraded) {
  let scopedGradingPeriodGrades = _.map(gradingPeriodGradesByPeriodId, gradingPeriodGrade => {
    const gradeVersion = includeUngraded ? gradingPeriodGrade.final : gradingPeriodGrade.current
    return {...gradeVersion, weight: gradingPeriodGrade.gradingPeriodWeight}
  })

  if (!includeUngraded) {
    scopedGradingPeriodGrades = _.filter(scopedGradingPeriodGrades, 'possible')
  }

  const scoreSum = bigSum(_.map(scopedGradingPeriodGrades, weightedPercent))
  const totalWeight = sumBy(scopedGradingPeriodGrades, 'weight')
  const totalScore =
    totalWeight === 0 ? 0 : toNumber(scoreSum.times(100).div(Math.min(totalWeight, 100)))

  return {
    score: round(totalScore, 2),
    possible: 100
  }
}
 $(".grading_standard input[type='text']").bind('blur change', function() {
   const $standard = $(this).parents('.grading_standard')
   let val = numberHelper.parse(
     $(this)
       .parents('.grading_standard_row')
       .find('.standard_value')
       .val()
   )
   val = round(val, 2)
   $(this)
     .parents('.grading_standard_row')
     .find('.standard_value')
     .val(I18n.n(val))
   if (isNaN(val)) {
     val = null
   }
   let lastVal = val || 100
   let prevVal = val || 0
   const $list = $standard.find('.grading_standard_row:not(.blank,.to_delete)')
   for (
     var idx = $list.index($(this).parents('.grading_standard_row')) + 1;
     idx < $list.length;
     idx++
   ) {
     var $row = $list.eq(idx)
     var points = numberHelper.parse($row.find('.standard_value').val())
     if (isNaN(points)) {
       points = null
     }
     if (idx == $list.length - 1) {
       points = 0
     } else if (!points || points > lastVal - 0.1) {
       points = parseInt(lastVal) - 1
     }
     $row.find('.standard_value').val(I18n.n(points))
     lastVal = points
   }
   for (var idx = $list.index($(this).parents('.grading_standard_row')) - 1; idx >= 0; idx--) {
     var $row = $list.eq(idx)
     var points = numberHelper.parse($row.find('.standard_value').val())
     if (isNaN(points)) {
       points = null
     }
     if (idx == $list.length - 1) {
       points = 0
     } else if (!points || points < prevVal + 0.1) {
       points = parseInt(prevVal) + 1
     }
     prevVal = points
     $row.find('.standard_value').val(I18n.n(points))
   }
   lastVal = 100
   $list.each(function(idx) {
     let points = numberHelper.parse(
       $(this)
         .find('.standard_value')
         .val()
     )
     var idx = $list.index(this)
     if (isNaN(points)) {
       points = null
     }
     if (idx == $list.length - 1) {
       points = 0
     } else if (!points || points > lastVal - 0.1) {
       points = parseInt(lastVal) - 1
     }
     $(this)
       .find('.standard_value')
       .val(I18n.n(points))
     lastVal = points
   })
   prevVal = 0
   for (var idx = $list.length - 1; idx >= 0; idx--) {
     var $row = $list.eq(idx)
     var points = numberHelper.parse($row.find('.standard_value').val())
     if (isNaN(points)) {
       points = null
     }
     if (idx == $list.length - 1) {
       points = 0
     } else if ((!points || points < prevVal + 0.1) && points != 0) {
       points = parseInt(prevVal) + 1
     }
     prevVal = points
     $row.find('.standard_value').val(I18n.n(points))
   }
   $list.each(function(idx) {
     const $prev = $list.eq(idx - 1)
     let min_score = 0
     if ($prev && $prev.length > 0) {
       min_score = numberHelper.parse($prev.find('.standard_value').val())
       if (isNaN(min_score)) {
         min_score = 0
       }
       $(this)
         .find('.edit_max_score')
         .text(`< ${I18n.n(min_score)}`)
     }
   })
   $list
     .filter(':first')
     .find('.edit_max_score')
     .text(I18n.n(100))
   $list.find('.max_score_cell').each(function() {
     if (!$(this).data('label')) {
       $(this).data('label', $(this).attr('aria-label'))
     }
     const label = $(this).data('label')
     $(this).attr(
       'aria-label',
       `${label} ${$(this)
         .find('.edit_max_score')
         .text()}%`
     )
   })
 })
 $('.grading_standard').bind('grading_standard_updated', function(event, standard) {
   const $standard = $(this)
   $standard.addClass('editing')
   $standard
     .find('.update_grading_standard_url')
     .attr('href', $('#update_grading_standard_url').attr('href'))
   $standard
     .fillTemplateData({
       data: standard,
       id: `grading_standard_${standard.id || 'blank'}`,
       avoid: '.find_grading_standard',
       hrefValues: ['id']
     })
     .fillFormData(standard, {object_name: 'grading_standard'})
   const $link = $standard.find('.insert_grading_standard:first').clone(true)
   const $row = $standard
     .find('.grading_standard_row:first')
     .clone(true)
     .removeClass('blank')
   const $table = $standard.find('.grading_standard_data')
   const $thead = $table.find('thead')
   $table.empty()
   $table.append($thead)
   $table.append($link.clone(true).show())
   for (const idx in standard.data) {
     const $row_instance = $row.clone(true)
     const row = standard.data[idx]
     $row_instance.removeClass('to_delete').removeClass('to_add')
     $row_instance
       .find('.standard_name')
       .val(row[0])
       .attr('name', `grading_standard[standard_data][scheme_${idx}][name]`)
       .end()
       .find('.standard_value')
       .val(I18n.n(round(row[1] * 100, 2)))
       .attr('name', `grading_standard[standard_data][scheme_${idx}][value]`)
     $table.append($row_instance.show())
     $table.append($link.clone(true).show())
   }
   $table.find(':text:first').blur()
   $table.append($row.hide())
   $table.append($link.hide())
   $standard.find('.grading_standard_row').each(function() {
     $(this)
       .find('.name')
       .text(
         $(this)
           .find('.standard_name')
           .val()
       )
       .end()
       .find('.min_score')
       .text(
         $(this)
           .find('.standard_value')
           .val()
       )
       .end()
       .find('.max_score')
       .text(
         $(this)
           .find('.edit_max_score')
           .text()
       )
   })
   $standard.removeClass('editing')
   $standard.find('.insert_grading_standard').hide()
   if (standard.id) {
     $standard.find('.remove_grading_standard_link').removeClass('read_only')
     let put_data = {
       'assignment[grading_standard_id]': standard.id,
       'assignment[grading_type]': 'letter_grade'
     }
     let url = $('#edit_assignment_form').attr('action')
     $('input.grading_standard_id, ').val(standard.id)
     if ($('#update_course_url').length) {
       put_data = {
         'course[grading_standard_id]': standard.id
       }
       url = $('#update_course_url').attr('href')
     } else if (url && url.match(/assignments$/)) {
       url = null
     }
     if (url) {
       $.ajaxJSON(
         url,
         'PUT',
         put_data,
         data => {
           $('#course_form .grading_scheme_set').text(
             (data && data.course && data.course.grading_standard_title) ||
               I18n.t('grading_scheme_currently_set', 'Currently Set')
           )
         },
         () => {}
       )
     }
   } else {
     $standard.find('.remove_grading_standard_link').addClass('read_only')
   }
 })
function roundedNumber(val) {
  return I18n.n(round(val, round.DEFAULT))
}
Example #9
0
 function roundAndFormat (value) {
   return I18n.n(round(value, round.DEFAULT));
 }
Example #10
0
function formatPercentageGrade (score, options) {
  const percent = options.pointsPossible ? score / options.pointsPossible * 100 : score;
  return I18n.n(round(percent, 2), { percentage: true, precision: 2, strip_insignificant_zeros: true });
}
Example #11
0
    if (grade == null || grade === '') {
      return ('defaultValue' in options) ? options.defaultValue : grade;
    }

    if (isExcused(grade)) {
      return excused();
    }

    let parsedGrade = GradeFormatHelper.parseGrade(grade, options);

    if (shouldFormatGrade(parsedGrade, options.gradingType)) {
      if (isPassFail(parsedGrade, options.gradingType)) {
        parsedGrade = normalizeCompleteIncompleteGrade(parsedGrade);
        formattedGrade = parsedGrade === 'complete' ? I18n.t('complete') : I18n.t('incomplete');
      } else {
        const roundedGrade = round(parsedGrade, options.precision || 2);
        formattedGrade = I18n.n(roundedGrade, { percentage: isPercent(grade, options.gradingType) });
      }
    }

    return formattedGrade;
  },

  /**
   * Given a localized point or percentage grade string,
   * returns delocalized point or percentage string.
   * Otherwise, returns input.
   */
  delocalizeGrade (localizedGrade) {
    if (localizedGrade === undefined ||
        localizedGrade === null ||
function markMissingSubmissionsDefaultValue (missingSubmissionDeduction) {
  return Round(100 - missingSubmissionDeduction, 2).toString();
}
Example #13
0
   *
   * @return {string} Given grade rounded to two decimal places and formatted with I18n
   * if it is a point or percent grade.
   */
  formatGrade (grade, opts = {}) {
    let formattedGrade;

    if (grade === undefined || grade === null || grade === '') {
      return Object.prototype.hasOwnProperty.call(opts, 'defaultValue') ? opts.defaultValue : grade;
    }

    formattedGrade = grade.toString();

    if (shouldFormatGrade(formattedGrade, opts.gradingType)) {
      formattedGrade = formattedGrade.replace(/%/g, '');
      formattedGrade = round(numberHelper.parse(formattedGrade), opts.precision || 2);
      formattedGrade = I18n.n(formattedGrade, { percentage: isPercent(grade, opts.gradingType) });
    }

    return formattedGrade;
  },

  /**
   * Given a localized point or percentage grade string,
   * returns delocalized point or percentage string.
   * Otherwise, returns input.
   */
  delocalizeGrade (localizedGrade) {
    if (localizedGrade === undefined ||
        localizedGrade === null ||
        typeof localizedGrade !== 'string') {
function getGradePercentage(score, pointsPossible) {
  const grade = scoreToPercentage(score, pointsPossible)
  return round(grade, round.DEFAULT)
}
function getGradePercentage (score, pointsPossible) {
  const grade = (score / pointsPossible) * 100;
  return round(grade, round.DEFAULT);
}
 function roundWeight (val) {
   const value = numberHelper.parse(val);
   return isNaN(value) ? null : round(value, 2);
 };