2011-02-01 09:57:29 +08:00
|
|
|
#
|
2017-04-28 04:06:18 +08:00
|
|
|
# Copyright (C) 2011 - present Instructure, Inc.
|
2011-02-01 09:57:29 +08:00
|
|
|
#
|
|
|
|
# This file is part of Canvas.
|
|
|
|
#
|
|
|
|
# Canvas is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
# Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
2015-04-09 01:21:08 +08:00
|
|
|
require 'hashery/dictionary'
|
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# Contains a dictionary of arrays with hashes in them. This is so that
|
|
|
|
# we can get all the submissions for a course grouped by date and
|
|
|
|
# ordered by date, person, then assignment. Since working with this is
|
|
|
|
# a loop in a loop in a loop, it gets a little awkward for controllers
|
|
|
|
# and views, so I contain it in a class with some helper methods. The
|
|
|
|
# dictionary comes from facets, a stable and mature library that's been
|
2015-07-14 01:52:37 +08:00
|
|
|
# around for years. A dictionary is just an ordered hash.
|
|
|
|
#
|
|
|
|
# To use this:
|
|
|
|
#
|
2011-02-01 09:57:29 +08:00
|
|
|
# s = SubmissionList.new(course)
|
|
|
|
# s.each {|e| # lists each submission hash in the right order }
|
|
|
|
# s.each_day {|e| # lists each day with an array of submission hashes }
|
2015-07-14 01:52:37 +08:00
|
|
|
#
|
2011-02-01 09:57:29 +08:00
|
|
|
# The submission hash has some very useful meta data in there:
|
2015-07-14 01:52:37 +08:00
|
|
|
#
|
2012-08-24 05:02:00 +08:00
|
|
|
# :grader => printable name of the grader, or Graded on submission if unknown
|
2011-02-01 09:57:29 +08:00
|
|
|
# :grader_id => user_id of the grader
|
|
|
|
# :previous_grade => the grade previous to this one, or nil
|
|
|
|
# :current_grade => the most current grade, the last submission for this assignment and student
|
|
|
|
# :new_grade => the new grade this submission received
|
|
|
|
# :assignment_name => a printable name of the assignment
|
|
|
|
# :student_user_id => the user_id of the student
|
|
|
|
# :course_id => the course id
|
|
|
|
# :assignment_id => the assignment id
|
|
|
|
# :student_name => a printable name of the student
|
|
|
|
# :graded_on => the day (not the time) the submission was made
|
2014-08-21 23:02:40 +08:00
|
|
|
# :score_before_regrade => the score prior to regrading
|
2015-07-14 01:52:37 +08:00
|
|
|
#
|
|
|
|
# The version data is actually pulled from some yaml storage through
|
2011-02-01 09:57:29 +08:00
|
|
|
# simply_versioned.
|
|
|
|
class SubmissionList
|
2016-11-12 06:17:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
VALID_KEYS = [
|
2016-11-12 06:17:40 +08:00
|
|
|
:assignment_id, :assignment_name, :attachment_id, :attachment_ids,
|
|
|
|
:body, :course_id, :created_at, :current_grade, :current_graded_at,
|
|
|
|
:current_grader, :grade_matches_current_submission, :graded_at,
|
|
|
|
:graded_on, :grader, :grader_id, :group_id, :id, :new_grade,
|
2011-02-01 09:57:29 +08:00
|
|
|
:new_graded_at, :new_grader, :previous_grade, :previous_graded_at,
|
2019-07-26 21:07:23 +08:00
|
|
|
:previous_grader, :processed, :published_grade,
|
2016-11-12 06:17:40 +08:00
|
|
|
:published_score, :safe_grader_id, :score, :student_entered_score,
|
|
|
|
:student_user_id, :submission_id, :student_name, :submission_type,
|
|
|
|
:updated_at, :url, :user_id, :workflow_state, :score_before_regrade
|
2015-07-14 01:52:37 +08:00
|
|
|
].freeze
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
class << self
|
|
|
|
# Shortcut for SubmissionList.each(course) { ... }
|
|
|
|
def each(course, &block)
|
|
|
|
sl = new(course)
|
|
|
|
sl.each(&block)
|
|
|
|
end
|
2015-07-14 01:52:37 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
def each_day(course, &block)
|
|
|
|
sl = new(course)
|
|
|
|
sl.each_day(&block)
|
|
|
|
end
|
2015-07-14 01:52:37 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
def days(course)
|
|
|
|
new(course).days
|
|
|
|
end
|
2015-07-14 01:52:37 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
def submission_entries(course)
|
|
|
|
new(course).submission_entries
|
|
|
|
end
|
2015-07-14 01:52:37 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
def list(course)
|
|
|
|
new(course).list
|
|
|
|
end
|
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# The course
|
|
|
|
attr_reader :course
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# The dictionary of submissions
|
|
|
|
attr_reader :list
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
def initialize(course)
|
2011-05-07 02:44:34 +08:00
|
|
|
raise ArgumentError, "Must provide a course." unless course && course.is_a?(Course)
|
2011-02-01 09:57:29 +08:00
|
|
|
@course = course
|
|
|
|
process
|
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# An iterator on a sorted and filtered list of submission versions.
|
|
|
|
def each(&block)
|
|
|
|
self.submission_entries.each do |entry|
|
|
|
|
yield(entry)
|
|
|
|
end
|
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# An iterator on the day only, not each submission
|
|
|
|
def each_day(&block)
|
|
|
|
self.list.each &block
|
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# An array of days with an array of grader open structs for that day and course.
|
|
|
|
# TODO - This needes to be refactored, it is way slow and I cant figure out why.
|
|
|
|
def days
|
|
|
|
# start = Time.now
|
|
|
|
# current = Time.now
|
|
|
|
# puts "----------------------------------------------"
|
|
|
|
# puts "starting"
|
|
|
|
# puts "---------------------------------------------------------------------------------"
|
|
|
|
self.list.map do |day, value|
|
2014-08-21 23:02:40 +08:00
|
|
|
# puts "-----------------------------------------------item #{Time.now - current}----------------------------"
|
2011-02-01 09:57:29 +08:00
|
|
|
# current = Time.now
|
|
|
|
OpenObject.new(:date => day, :graders => graders_for_day(day))
|
|
|
|
end
|
|
|
|
# puts "----------------------------------------------"
|
|
|
|
# puts Time.now - start
|
|
|
|
# puts "---------------------------------------------------------------------------------"
|
|
|
|
# foo
|
|
|
|
end
|
2011-10-13 00:19:46 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# A filtered list of hashes of all submission versions that change the
|
|
|
|
# grade with all the meta data finally included. This list can be sorted
|
2014-08-21 23:02:40 +08:00
|
|
|
# and displayed.
|
2011-02-01 09:57:29 +08:00
|
|
|
def submission_entries
|
|
|
|
return @submission_entries if @submission_entries
|
|
|
|
@submission_entries = filtered_submissions.map do |s|
|
|
|
|
entry = current_grade_map[s[:id]]
|
|
|
|
s[:current_grade] = entry.grade
|
|
|
|
s[:current_graded_at] = entry.graded_at
|
|
|
|
s[:current_grader] = entry.grader
|
|
|
|
s
|
|
|
|
end
|
|
|
|
trim_keys(@submission_entries)
|
|
|
|
end
|
|
|
|
|
|
|
|
# A cleaner look at a SubmissionList
|
|
|
|
def inspect
|
|
|
|
"SubmissionList: course: #{self.course.name} submissions used: #{self.submission_entries.size} days used: #{self.list.keys.inspect} graders: #{self.graders.map(&:name).inspect}"
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
# Returns an array of graders with an array of assignment open structs
|
|
|
|
def graders_for_day(day)
|
|
|
|
hsh = self.list[day].inject({}) do |h, submission|
|
|
|
|
grader = submission[:grader]
|
|
|
|
h[grader] ||= OpenObject.new(
|
2014-08-21 23:02:40 +08:00
|
|
|
:assignments => assignments_for_grader_and_day(grader, day),
|
|
|
|
:name => grader,
|
2011-02-01 09:57:29 +08:00
|
|
|
:grader_id => submission[:grader_id]
|
|
|
|
)
|
|
|
|
h
|
|
|
|
end
|
|
|
|
hsh.values
|
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# Returns an array of assignments with an array of submission open structs.
|
|
|
|
def assignments_for_grader_and_day(grader, day)
|
2016-11-12 06:17:40 +08:00
|
|
|
start = Time.now
|
2011-02-01 09:57:29 +08:00
|
|
|
hsh = submission_entries.find_all {|e| e[:grader] == grader and e[:graded_on] == day}.inject({}) do |h, submission|
|
|
|
|
assignment = submission[:assignment_name]
|
|
|
|
h[assignment] ||= OpenObject.new(
|
2014-08-21 23:02:40 +08:00
|
|
|
:name => assignment,
|
2011-02-01 09:57:29 +08:00
|
|
|
:assignment_id => submission[:assignment_id],
|
|
|
|
:submissions => []
|
|
|
|
)
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
h[assignment].submissions << OpenObject.new(submission)
|
|
|
|
|
|
|
|
h
|
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2017-02-08 00:46:29 +08:00
|
|
|
hsh.each_value do |v|
|
|
|
|
v['submissions'] = Canvas::ICU.collate_by(v.submissions, &:student_name)
|
2011-02-01 09:57:29 +08:00
|
|
|
v.submission_count = v.submissions.size
|
|
|
|
end
|
2017-02-08 00:46:29 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
hsh.values
|
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# Produce @list, wich is a sorted, filtered, list of submissions with
|
2014-08-21 23:02:40 +08:00
|
|
|
# all the meta data we need and no banned keys included.
|
2011-02-01 09:57:29 +08:00
|
|
|
def process
|
2014-03-18 04:54:26 +08:00
|
|
|
@list = self.submission_entries.sort_by { |a| [a[:graded_at] ? -a[:graded_at].to_f : CanvasSort::Last, a[:safe_grader_id], a[:assignment_id]] }.
|
2017-01-03 05:36:48 +08:00
|
|
|
inject(Hashery::Dictionary.new) do |d, se|
|
2011-02-01 09:57:29 +08:00
|
|
|
d[se[:graded_on]] ||= []
|
|
|
|
d[se[:graded_on]] << se
|
|
|
|
d
|
|
|
|
end
|
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# A hash of the current grades of each submission, keyed by submission.id
|
|
|
|
def current_grade_map
|
2017-06-20 00:26:30 +08:00
|
|
|
@current_grade_map ||= self.course.submissions.not_placeholder.inject({}) do |hash, submission|
|
2012-08-24 05:02:00 +08:00
|
|
|
grader = if submission.grader_id.present?
|
|
|
|
self.grader_map[submission.grader_id].try(:name)
|
|
|
|
end
|
|
|
|
grader ||= I18n.t('gradebooks.history.graded_on_submission', 'Graded on submission')
|
|
|
|
|
2015-07-14 01:52:37 +08:00
|
|
|
hash[submission.id] = OpenObject.new(:grade => translate_grade(submission),
|
2012-08-24 05:02:00 +08:00
|
|
|
:graded_at => submission.graded_at,
|
|
|
|
:grader => grader)
|
|
|
|
hash
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
|
|
|
end
|
2012-08-24 05:02:00 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# Ensures that the final product only has approved keys in it. This
|
2014-08-21 23:02:40 +08:00
|
|
|
# makes our final product much more yummy.
|
2011-02-01 09:57:29 +08:00
|
|
|
def trim_keys(list)
|
|
|
|
list.each do |hsh|
|
|
|
|
hsh.delete_if { |key, v| ! VALID_KEYS.include?(key) }
|
|
|
|
end
|
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# Creates a list of any submissions that change the grade. Adds:
|
|
|
|
# * previous_grade
|
|
|
|
# * previous_graded_at
|
|
|
|
# * previous_grader
|
|
|
|
# * new_grade
|
|
|
|
# * new_graded_at
|
|
|
|
# * new_grader
|
|
|
|
# * current_grade
|
|
|
|
# * current_graded_at
|
|
|
|
# * current_grader
|
|
|
|
def filtered_submissions
|
|
|
|
return @filtered_submissions if @filtered_submissions
|
2013-10-02 01:03:38 +08:00
|
|
|
# Sorts by submission then updated at in ascending order. So:
|
|
|
|
# submission 1 1/1/2009, submission 1 1/15/2009, submission 2 1/1/2009
|
|
|
|
full_hash_list.sort_by! { |a| [a[:id], a[:updated_at]] }
|
2011-02-01 09:57:29 +08:00
|
|
|
prior_submission_id, prior_grade, prior_score, prior_graded_at, prior_grader = nil
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
@filtered_submissions = full_hash_list.inject([]) do |l, h|
|
|
|
|
# If the submission is different (not null for the first one, or just
|
|
|
|
# different than the last one), set the previous_grade to nil (this is
|
|
|
|
# the first version that changes a grade), set the new_grade to this
|
2014-08-21 23:02:40 +08:00
|
|
|
# version's grade, and add this to the list.
|
2011-02-01 09:57:29 +08:00
|
|
|
if prior_submission_id != h[:submission_id]
|
|
|
|
h[:previous_grade] = nil
|
|
|
|
h[:previous_graded_at] = nil
|
|
|
|
h[:previous_grader] = nil
|
2015-07-14 01:52:37 +08:00
|
|
|
h[:new_grade] = translate_grade(h)
|
|
|
|
h[:new_score] = translate_score(h)
|
2011-02-01 09:57:29 +08:00
|
|
|
h[:new_graded_at] = h[:graded_at]
|
|
|
|
h[:new_grader] = h[:grader]
|
2014-08-21 23:02:40 +08:00
|
|
|
l << h
|
2011-02-01 09:57:29 +08:00
|
|
|
# If the prior_grade is different than the grade for this version, the
|
|
|
|
# grade for this submission has been changed. That's because we know
|
2014-08-21 23:02:40 +08:00
|
|
|
# that this submission must be the same as the prior submission.
|
2011-02-01 09:57:29 +08:00
|
|
|
# Set the prevous grade and the new grade and add this to the list.
|
2011-10-13 00:19:46 +08:00
|
|
|
# Remove the old submission so that it doesn't show up twice in the
|
|
|
|
# grade history.
|
2011-02-01 09:57:29 +08:00
|
|
|
elsif prior_score != h[:score]
|
2012-01-07 06:47:17 +08:00
|
|
|
l.pop if prior_graded_at.try(:to_date) == h[:graded_at].try(:to_date) && prior_grader == h[:grader]
|
2011-02-01 09:57:29 +08:00
|
|
|
h[:previous_grade] = prior_grade
|
|
|
|
h[:previous_graded_at] = prior_graded_at
|
|
|
|
h[:previous_grader] = prior_grader
|
2015-07-14 01:52:37 +08:00
|
|
|
h[:new_grade] = translate_grade(h)
|
|
|
|
h[:new_score] = translate_score(h)
|
2011-02-01 09:57:29 +08:00
|
|
|
h[:new_graded_at] = h[:graded_at]
|
|
|
|
h[:new_grader] = h[:grader]
|
|
|
|
l << h
|
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# At this point, we are only working with versions that have changed a
|
|
|
|
# grade. Go ahead and save that grade and save this version as the
|
2014-08-21 23:02:40 +08:00
|
|
|
# prior version and iterate.
|
2015-07-14 01:52:37 +08:00
|
|
|
prior_grade = translate_grade(h)
|
|
|
|
prior_score = translate_score(h)
|
2011-02-01 09:57:29 +08:00
|
|
|
prior_graded_at = h[:graded_at]
|
|
|
|
prior_grader = h[:grader]
|
|
|
|
prior_submission_id = h[:submission_id]
|
|
|
|
l
|
|
|
|
end
|
|
|
|
end
|
2013-10-02 01:03:38 +08:00
|
|
|
|
2015-07-14 01:52:37 +08:00
|
|
|
def translate_grade(submission)
|
|
|
|
submission[:excused] ? "EX" : submission[:grade]
|
|
|
|
end
|
|
|
|
|
|
|
|
def translate_score(submission)
|
|
|
|
submission[:excused] ? "EX" : submission[:score]
|
|
|
|
end
|
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# A list of all versions in YAML format
|
|
|
|
def yaml_list
|
2017-06-20 00:26:30 +08:00
|
|
|
@yaml_list ||= self.course.submissions.not_placeholder.preload(:versions).map do |s|
|
2016-11-12 06:11:01 +08:00
|
|
|
s.versions.map { |v| v.yaml }
|
|
|
|
end.flatten
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# A list of hashes. All the versions of all the submissions for a
|
2014-08-21 23:02:40 +08:00
|
|
|
# course, unfiltered and unsorted.
|
2011-02-01 09:57:29 +08:00
|
|
|
def raw_hash_list
|
2014-08-21 23:02:40 +08:00
|
|
|
@hash_list ||= begin
|
|
|
|
hash_list = yaml_list.map { |y| YAML.load(y).symbolize_keys }
|
|
|
|
add_regrade_info(hash_list)
|
|
|
|
end
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
|
|
|
# This method will add regrade details to the existing raw_hash_list
|
|
|
|
def add_regrade_info(hash_list)
|
|
|
|
quiz_submission_ids = hash_list.map { |y| y[:quiz_submission_id]}.compact
|
|
|
|
return hash_list if quiz_submission_ids.blank?
|
|
|
|
quiz_submissions = Quizzes::QuizSubmission.where("id IN (?) AND score_before_regrade IS NOT NULL", quiz_submission_ids)
|
|
|
|
quiz_submissions.each do |qs|
|
|
|
|
matches = hash_list.select { |a| a[:id] == qs.submission_id}
|
|
|
|
matches.each do |h|
|
|
|
|
h[:score_before_regrade] = qs.score_before_regrade
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
hash_list
|
|
|
|
end
|
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# Still a list of unsorted, unfiltered hashes, but the meta data is inserted at this point
|
|
|
|
def full_hash_list
|
|
|
|
@full_hash_list ||= self.raw_hash_list.map do |h|
|
2014-10-14 05:50:55 +08:00
|
|
|
h[:grader] = if h.has_key? :score_before_regrade
|
|
|
|
I18n.t('gradebooks.history.regraded', "Regraded")
|
|
|
|
elsif h[:grader_id] && grader_map[h[:grader_id]]
|
|
|
|
grader_map[h[:grader_id]].name
|
|
|
|
else
|
|
|
|
I18n.t('gradebooks.history.graded_on_submission', 'Graded on submission')
|
|
|
|
end
|
2011-02-01 09:57:29 +08:00
|
|
|
h[:safe_grader_id] = h[:grader_id] ? h[:grader_id] : 0
|
|
|
|
h[:assignment_name] = self.assignment_map[h[:assignment_id]].title
|
|
|
|
h[:student_user_id] = h[:user_id]
|
|
|
|
h[:student_name] = self.student_map[h[:user_id]].name
|
|
|
|
h[:course_id] = self.course.id
|
|
|
|
h[:submission_id] = h[:id]
|
2012-08-21 02:40:14 +08:00
|
|
|
h[:graded_on] = h[:graded_at].in_time_zone.to_date if h[:graded_at]
|
2011-02-01 09:57:29 +08:00
|
|
|
|
|
|
|
h
|
|
|
|
end
|
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# A unique list of all grader ids
|
|
|
|
def all_grader_ids
|
2016-11-12 06:17:40 +08:00
|
|
|
@all_grader_ids ||= raw_hash_list.map { |e| e[:grader_id] }.uniq.compact
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# A complete list of all graders that have graded submissions for this
|
2014-08-21 23:02:40 +08:00
|
|
|
# course as User models
|
2011-02-01 09:57:29 +08:00
|
|
|
def graders
|
2015-07-25 00:01:44 +08:00
|
|
|
@graders ||= User.where(:id => all_grader_ids).to_a
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# A hash of graders by their ids, for easy lookup in full_hash_list
|
|
|
|
def grader_map
|
|
|
|
@grader_map ||= graders.inject({}) do |h, g|
|
2016-11-12 06:17:40 +08:00
|
|
|
h[g.id] = g
|
2011-02-01 09:57:29 +08:00
|
|
|
h
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# A unique list of all student ids
|
|
|
|
def all_student_ids
|
2016-11-12 06:17:40 +08:00
|
|
|
@all_student_ids ||= raw_hash_list.map { |e| e[:user_id] }.uniq.compact
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# A complete list of all students that have submissions for this course
|
2014-08-21 23:02:40 +08:00
|
|
|
# as User models
|
2011-02-01 09:57:29 +08:00
|
|
|
def students
|
2015-07-25 00:01:44 +08:00
|
|
|
@students ||= User.where(:id => all_student_ids).to_a
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# A hash of students by their ids, for easy lookup in full_hash_list
|
|
|
|
def student_map
|
|
|
|
@student_map ||= students.inject({}) do |h, s|
|
2016-11-12 06:17:40 +08:00
|
|
|
h[s.id] = s
|
2011-02-01 09:57:29 +08:00
|
|
|
h
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# A unique list of all assignment ids
|
|
|
|
def all_assignment_ids
|
2016-11-12 06:17:40 +08:00
|
|
|
@all_assignment_ids ||= raw_hash_list.map { |e| e[:assignment_id] }.uniq.compact
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# A complete list of assignments that have submissions for this course
|
|
|
|
def assignments
|
2015-07-25 00:01:44 +08:00
|
|
|
@assignments ||= Assignment.where(:id => all_assignment_ids).to_a
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
2014-08-21 23:02:40 +08:00
|
|
|
|
2011-02-01 09:57:29 +08:00
|
|
|
# A hash of assignments by their ids, for easy lookup in full_hash_list
|
|
|
|
def assignment_map
|
|
|
|
@assignment_map ||= assignments.inject({}) do |h, a|
|
2016-11-12 06:17:40 +08:00
|
|
|
h[a.id] = a
|
2011-02-01 09:57:29 +08:00
|
|
|
h
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-13 00:19:46 +08:00
|
|
|
end
|