canvas-lms/app/presenters/grade_summary_assignment_pr...

207 lines
4.6 KiB
Ruby
Raw Normal View History

class GradeSummaryAssignmentPresenter
attr_reader :assignment, :submission
def initialize(summary, current_user, assignment, submission)
@summary = summary
@current_user = current_user
@assignment = assignment
@submission = submission
end
def hide_distribution_graphs?
submission_count = @summary.submission_counts[assignment.id] || 0
submission_count < 5 || assignment.context.hide_distribution_graphs?
end
def is_unread?
(submission.present? ? @summary.unread_submission_ids.include?(submission.id) : false)
end
def graded?
submission && submission.grade && !assignment.muted?
end
def is_letter_graded?
assignment.grading_type == 'letter_grade'
end
gpa scale grading standard fixes CNVS-8931 makes a new grading standard type called "gpa scale" only allows for grades on the GPA scale modifies GB2 dom elements if gpa scaled modifies rubric_assessment response to properly change grade adds dialog when selecting gpa scale grading type refactors grading_standard.rb to use instance methods (not class) added related tests test plan: - As a Teacher, create an assignment with GPA Scaled grading type - Enter a grading scheme like the one in grading_standard.rb/default_gpa_scheme - Go to GB2 and grade this assignment - grades not in the schema should be "-" - letters that aren't in the scheme should be a "-" - if "3.0" is in the grading standard an input of 3 should switch to 3.0 automatically - letters in the scheme should work upper or lower case - setting default grade should work with the same rules - dom elements of this assignment should have a special class - Other assignments should work as usual in GB2 - Go to Assignment Edit Page - when selecting Display Grade as "GPA Scale" a ? icon should pop up - clicking this icon should open a modal with sane text - Go to GB1 - Grading an assignment should work like GB2 - GB1 should work as expected for non GPA Scale Assignments - Go to the SpeedGrader - grading assignments that are GPA Scaled should work similarly to GB2 - SpeedGrader should work as expected for non GPA Scale Assignments - Enable Rubric based grading on an assignment - once the rubric is filled out in SpeedGrader, the correctly rounded GPA should be inserted on save - once the rubric is filled out in Submission Edit page, the correctly rounded GPA should be inserted on save - rubrics should work as expected for non GPA Scale Assignments - Other areas in which GradingStandards are used should work as expected Change-Id: Ide1ea5ca13a70116ae3535b2c8e105ece79a34c8 Reviewed-on: https://gerrit.instructure.com/29742 Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Product-Review: Hilary Scharton <hilary@instructure.com> Product-Review: Mike Nomitch <mnomitch@instructure.com>
2014-02-05 01:57:32 +08:00
def is_gpa_scaled?
assignment.grading_type == 'gpa_scale'
end
def is_letter_graded_or_gpa_scaled?
is_letter_graded? || is_gpa_scaled?
end
def is_assignment?
assignment.class.to_s == "Assignment"
end
def has_no_group_weight?
!(assignment.group_weight rescue false)
end
def has_no_score_display?
assignment.muted? || submission.nil?
end
def unchangeable?
(!@summary.editable? || assignment.special_class)
end
def has_comments?
submission && submission.visible_submission_comments && !submission.visible_submission_comments.empty?
end
def has_scoring_details?
submission && submission.score && assignment.points_possible && assignment.points_possible > 0 && !assignment.muted?
end
def has_grade_distribution?
assignment && assignment.points_possible && assignment.points_possible > 0 && !assignment.muted?
end
def has_rubric_assessments?
!rubric_assessments.empty?
end
def is_text_entry?
submission.submission_type == 'online_text_entry'
end
def is_online_upload?
submission.submission_type == 'online_upload'
end
def should_display_details?
!assignment.special_class && (has_comments? || has_scoring_details?)
end
def special_class
assignment.special_class ? ("hard_coded " + assignment.special_class) : "editable"
end
def published_grade
gpa scale grading standard fixes CNVS-8931 makes a new grading standard type called "gpa scale" only allows for grades on the GPA scale modifies GB2 dom elements if gpa scaled modifies rubric_assessment response to properly change grade adds dialog when selecting gpa scale grading type refactors grading_standard.rb to use instance methods (not class) added related tests test plan: - As a Teacher, create an assignment with GPA Scaled grading type - Enter a grading scheme like the one in grading_standard.rb/default_gpa_scheme - Go to GB2 and grade this assignment - grades not in the schema should be "-" - letters that aren't in the scheme should be a "-" - if "3.0" is in the grading standard an input of 3 should switch to 3.0 automatically - letters in the scheme should work upper or lower case - setting default grade should work with the same rules - dom elements of this assignment should have a special class - Other assignments should work as usual in GB2 - Go to Assignment Edit Page - when selecting Display Grade as "GPA Scale" a ? icon should pop up - clicking this icon should open a modal with sane text - Go to GB1 - Grading an assignment should work like GB2 - GB1 should work as expected for non GPA Scale Assignments - Go to the SpeedGrader - grading assignments that are GPA Scaled should work similarly to GB2 - SpeedGrader should work as expected for non GPA Scale Assignments - Enable Rubric based grading on an assignment - once the rubric is filled out in SpeedGrader, the correctly rounded GPA should be inserted on save - once the rubric is filled out in Submission Edit page, the correctly rounded GPA should be inserted on save - rubrics should work as expected for non GPA Scale Assignments - Other areas in which GradingStandards are used should work as expected Change-Id: Ide1ea5ca13a70116ae3535b2c8e105ece79a34c8 Reviewed-on: https://gerrit.instructure.com/29742 Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Product-Review: Hilary Scharton <hilary@instructure.com> Product-Review: Mike Nomitch <mnomitch@instructure.com>
2014-02-05 01:57:32 +08:00
is_letter_graded_or_gpa_scaled? ? "(#{submission.published_grade})" : ''
end
def display_score
if has_no_score_display?
''
else
"#{submission.published_score} #{published_grade}"
end
end
def turnitin
t = if is_text_entry?
submission.turnitin_data && submission.turnitin_data[submission.asset_string]
elsif is_online_upload? && file
submission.turnitin_data[file.asset_string]
else
nil
end
t.try(:[], :state) ? t : nil
end
def grade_distribution
@grade_distribution ||= begin
stats = @summary.assignment_stats[assignment.id]
[stats.max.to_f.round(1),
stats.min.to_f.round(1),
stats.avg.to_f.round(1)]
end
end
def graph
@graph ||= begin
high, low, mean = grade_distribution
score = submission && submission.score
GradeSummaryGraph.new(high, low, mean, assignment.points_possible, score)
end
end
def file
@file ||= submission.attachments.detect{|a| submission.turnitin_data && submission.turnitin_data[a.asset_string] }
end
def comments
submission.visible_submission_comments
end
def rubric_assessments
@visible_rubric_assessments ||= begin
if submission && !assignment.muted?
assessments = submission.rubric_assessments.select { |a| a.grants_right?(@current_user, :read) }
assessments.sort_by { |a| [a.assessment_type == 'grading' ? CanvasSort::First : CanvasSort::Last, a.assessor_name] }
else
[]
end
end
end
def group
@group ||= assignment && assignment.assignment_group
end
def viewing_fake_student?
@summary.student_enrollment.fake_student?
end
end
class GradeSummaryGraph
FULLWIDTH = 150.0
def initialize(high, low, mean, points_possible, score)
@high = high.to_f
@mean = mean.to_f
@low = low.to_f
@points_possible = points_possible.to_f
@score = score
end
def low_width
pixels_for(@low)
end
def high_left
pixels_for(@high)
end
def high_width
pixels_for(@points_possible - @high)
end
def mean_left
pixels_for(@mean)
end
def mean_low_width
pixels_for(@mean - @low)
end
def mean_high_width
pixels_for(@high - @mean)
end
def max_left
[FULLWIDTH.round, (pixels_for(@high) + 3)].max
end
def score_left
pixels_for(@score) - 5
end
def title
I18n.t('#grade_summary.graph_title', "Mean %{mean}, High %{high}, Low %{low}", {
mean: @mean.to_s, high: @high.to_s, low: @low.to_s
})
end
private
def pixels_for(value)
(value.to_f / @points_possible * FULLWIDTH).round
end
end