Skip to content

Commit

Permalink
numerator is marked, denominator is total assigned, all in one query
Browse files Browse the repository at this point in the history
  • Loading branch information
hemmatio committed Feb 6, 2025
1 parent fc38cb7 commit e22d9bc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions app/models/ta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ def get_groupings_by_assignment(assignment)
end

def marked_result_ids_for(assignment)
@total_results ||= {}
@total_results[assignment.id] ||= assignment.current_results
.joins(grouping: :tas)
.where('roles.id': self.id)
@marked_result_ids ||= {}
@marked_result_ids[assignment.id] ||= assignment.current_results
.joins(grouping: :tas)
.where(marking_state: Result::MARKING_STATES[:complete],
'roles.id': self.id)
.ids
@marked_result_ids[assignment.id] ||= @total_results[assignment.id]
.where(marking_state: Result::MARKING_STATES[:complete]).ids
[@total_results, @marked_result_ids]
end

# An array of all the grades for an assignment for this TA.
# If TAs are assigned to grade criteria, returns just the subtotal
# for the criteria the TA was assigned.
def percentage_grades_array(assignment)
result_ids = marked_result_ids_for(assignment)
result_ids = marked_result_ids_for(assignment)[1][2]

if assignment.assign_graders_to_criteria
criterion_ids = self.criterion_ta_associations.where(assessment_id: assignment.id).pluck(:criterion_id)
Expand Down Expand Up @@ -68,11 +70,11 @@ def grade_distribution_array(assignment, intervals = 20)
end

def get_num_marked_from_cache(assignment)
marked_result_ids_for(assignment).size
marked_result_ids_for(assignment)[1][2].size
end

def get_num_assigned_from_cache(assignment)
assignment.current_results.size
marked_result_ids_for(assignment)[0][2].size
end

private
Expand Down

0 comments on commit e22d9bc

Please sign in to comment.