-
Notifications
You must be signed in to change notification settings - Fork 194
E2609: Review Calibration - participant management & report pipeline #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8b40c0b
fcbf205
36f41df
552e5c6
61f209c
d2795c3
7f9a687
9b041c7
79c5d35
673b65b
d7c0fba
a154eed
a9f02bf
65ab354
55c3979
1a1f624
7adee79
d83ca22
16567b2
18e2ffa
3e3210b
a5aae2d
4cbbdf9
32549ed
0c9126c
d131bf7
709d725
d3f53e5
537712e
d6acbbc
8d6b6b8
f5e418a
9b1fcde
4dac539
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Reports live in their own controller per Expertiza convention: a single | ||
| # controller responsible only for rendering reports, dispatching to per-report | ||
| # actions. Feature controllers (e.g. ReviewMappingsController) should not | ||
| # embed report logic, since that violates SRP and hides the code from other | ||
| # consumers who need the same information. | ||
| class ReportsController < ApplicationController | ||
| include Authorization | ||
| before_action :set_assignment | ||
|
|
||
| # Reports are viewable only by teaching staff for the assignment (instructor | ||
| # of the assignment, the course instructor, or a TA mapped to the course). | ||
| def action_allowed? | ||
| current_user_teaching_staff_of_assignment?(params[:assignment_id]) | ||
| end | ||
|
|
||
| # GET /assignments/:assignment_id/reports/calibration/:map_id | ||
| # | ||
| # Renders the calibration comparison report for one instructor map. | ||
| # All assembly logic (rubric items, student responses, per-item score | ||
| # histograms, submitted content) lives in Reports::CalibrationReport, | ||
| # which follows the iterator pattern from Reports::Base — responses are | ||
| # walked one at a time via find_each, never preloaded into an ad-hoc array. | ||
| def calibration | ||
| instructor_map = ReviewResponseMap.find_by!( | ||
| id: params[:map_id], | ||
| reviewed_object_id: @assignment.id, | ||
| for_calibration: true | ||
| ) | ||
| render json: Reports::CalibrationReport.new(instructor_map).render, status: :ok | ||
| rescue ActiveRecord::RecordNotFound | ||
| render_error('Calibration review map not found', :not_found) | ||
| rescue Reports::CalibrationReport::InstructorResponseMissing, | ||
| Reports::CalibrationReport::RubricMissing => e | ||
| render_error(e.message, :unprocessable_entity) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def set_assignment | ||
| @assignment = Assignment.find(params[:assignment_id]) | ||
| end | ||
|
|
||
| def render_error(message, status) | ||
| render json: { error: message }, status: status | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -62,6 +62,45 @@ def aggregate_questionnaire_score | |||||||||||||||||
| sum | ||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| # Returns the Answer this response recorded for a specific rubric item, or | ||||||||||||||||||
| # nil if no answer was given. Centralises item-lookup here (Information Expert) | ||||||||||||||||||
| # so callers don't scatter `scores.find { |a| a.item_id == item.id }` everywhere. | ||||||||||||||||||
| def answer_for(item) | ||||||||||||||||||
| scores.find { |a| a.item_id == item.id } | ||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| # Ordered rubric items used for this response, or [] if the rubric cannot be | ||||||||||||||||||
| # resolved (e.g. no AssignmentQuestionnaire for this round). Belongs here | ||||||||||||||||||
| # rather than in a controller because the response knows which questionnaire | ||||||||||||||||||
| # applies to it. | ||||||||||||||||||
| def rubric_items | ||||||||||||||||||
| questionnaire.items.order(:seq) | ||||||||||||||||||
| rescue NoMethodError | ||||||||||||||||||
| [] | ||||||||||||||||||
| end | ||||||||||||||||||
|
Comment on lines
+76
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid broad Line 71 can silently mask unrelated bugs and return Suggested fix def rubric_items
- questionnaire.items.order(:seq)
-rescue NoMethodError
- []
+ assignment_questionnaire = response_assignment.assignment_questionnaires.find_by(used_in_round: round)
+ assignment_questionnaire&.questionnaire&.items&.order(:seq) || []
end📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| # JSON representation of this response for calibration reports. Keeps the | ||||||||||||||||||
| # serialization next to the class that owns the data (Information Expert), | ||||||||||||||||||
| # so any consumer that needs a response rendered for a calibration view can | ||||||||||||||||||
| # ask the response for it. | ||||||||||||||||||
| def as_calibration_json | ||||||||||||||||||
| { | ||||||||||||||||||
| id: id, | ||||||||||||||||||
| map_id: map_id, | ||||||||||||||||||
| reviewer_id: map.reviewer_id, | ||||||||||||||||||
| reviewer_name: map.reviewer&.fullname, | ||||||||||||||||||
| is_submitted: is_submitted, | ||||||||||||||||||
| updated_at: updated_at, | ||||||||||||||||||
| answers: scores.map do |answer| | ||||||||||||||||||
| { | ||||||||||||||||||
| item_id: answer.item_id, | ||||||||||||||||||
| score: answer.answer, | ||||||||||||||||||
| comments: answer.comments | ||||||||||||||||||
| } | ||||||||||||||||||
| end | ||||||||||||||||||
| } | ||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| # Returns the maximum possible score for this response | ||||||||||||||||||
| def maximum_score | ||||||||||||||||||
| # only count the scorable questions, only when the answer is not nil (we accept nil as | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid rescuing
StandardErrorinto a 422 with raw exception text.On Line 95, this turns unexpected server failures into client-validation errors and exposes internals via
e.message. Keep422for known domain errors, and return a generic500for unknown exceptions.Suggested hardening
📝 Committable suggestion
🤖 Prompt for AI Agents