Add exercise feedback page for pair programming study
This commit is contained in:

committed by
Sebastian Serth

parent
79422225a8
commit
4b90a2a3c5
@ -5,6 +5,13 @@ module RedirectBehavior
|
||||
|
||||
def redirect_after_submit
|
||||
Rails.logger.debug { "Redirecting user with score:s #{@submission.normalized_score}" }
|
||||
|
||||
# TEMPORARY: For the pythonjunior2023 course, we want to have a lot of feedback!
|
||||
if @submission.redirect_to_survey?
|
||||
redirect_to_pair_programming_survey
|
||||
return
|
||||
end
|
||||
|
||||
if @submission.normalized_score.to_d == BigDecimal('1.0')
|
||||
if redirect_to_community_solution?
|
||||
redirect_to_community_solution
|
||||
@ -98,6 +105,16 @@ module RedirectBehavior
|
||||
@community_solution_lock.user == current_user
|
||||
end
|
||||
|
||||
# TEMPORARY: For the pythonjunior2023 course, we introduced a pair programming survey
|
||||
def redirect_to_pair_programming_survey
|
||||
url = new_pair_programming_exercise_feedback_path(pair_programming_exercise_feedback: {exercise_id: @exercise.id, submission_id: @submission.id})
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(url) }
|
||||
format.json { render(json: {redirect: url}) }
|
||||
end
|
||||
end
|
||||
|
||||
def redirect_to_user_feedback
|
||||
uef = UserExerciseFeedback.find_by(exercise: @exercise, user: current_user)
|
||||
url = if uef
|
||||
|
@ -0,0 +1,96 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PairProgrammingExerciseFeedbacksController < ApplicationController
|
||||
include CommonBehavior
|
||||
include RedirectBehavior
|
||||
|
||||
before_action :set_presets, only: %i[new create]
|
||||
|
||||
def comment_presets
|
||||
[[0, t('pair_programming_exercise_feedback.difficulty_easy')],
|
||||
[1, t('pair_programming_exercise_feedback.difficulty_some_what_easy')],
|
||||
[2, t('pair_programming_exercise_feedback.difficulty_ok')],
|
||||
[3, t('pair_programming_exercise_feedback.difficulty_some_what_difficult')],
|
||||
[4, t('pair_programming_exercise_feedback.difficult_too_difficult')]]
|
||||
end
|
||||
|
||||
def time_presets
|
||||
[[0, t('pair_programming_exercise_feedback.estimated_time_less_5')],
|
||||
[1, t('pair_programming_exercise_feedback.estimated_time_5_to_10')],
|
||||
[2, t('pair_programming_exercise_feedback.estimated_time_10_to_20')],
|
||||
[3, t('pair_programming_exercise_feedback.estimated_time_20_to_30')],
|
||||
[4, t('pair_programming_exercise_feedback.estimated_time_more_30')]]
|
||||
end
|
||||
|
||||
def new
|
||||
exercise_id = if params[:pair_programming_exercise_feedback].nil?
|
||||
params[:exercise_id]
|
||||
else
|
||||
params[:pair_programming_exercise_feedback][:exercise_id]
|
||||
end
|
||||
@exercise = Exercise.find(exercise_id)
|
||||
|
||||
@submission = Submission.find(params[:pair_programming_exercise_feedback][:submission_id])
|
||||
authorize(@submission, :show?)
|
||||
|
||||
@uef = PairProgrammingExerciseFeedback.new(user: current_user, exercise: @exercise, programming_group:, submission: @submission)
|
||||
authorize!
|
||||
end
|
||||
|
||||
def create
|
||||
Sentry.set_extras(params: uef_params)
|
||||
|
||||
@exercise = Exercise.find(uef_params[:exercise_id])
|
||||
|
||||
if @exercise
|
||||
@uef = PairProgrammingExerciseFeedback.new(exercise: @exercise, programming_group:, study_group_id: current_user.current_study_group_id)
|
||||
@uef.update(uef_params)
|
||||
authorize!
|
||||
if validate_inputs(uef_params) && @uef.save
|
||||
redirect_after_submit
|
||||
else
|
||||
flash.now[:danger] = t('shared.message_failure')
|
||||
redirect_back fallback_location: pair_programming_exercise_feedback_path(@uef)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authorize!
|
||||
authorize(@uef || @uefs)
|
||||
end
|
||||
|
||||
def set_presets
|
||||
@texts = comment_presets.to_a
|
||||
@times = time_presets.to_a
|
||||
end
|
||||
|
||||
def uef_params
|
||||
return if params[:pair_programming_exercise_feedback].blank?
|
||||
|
||||
@submission = Submission.find(params[:pair_programming_exercise_feedback][:submission_id])
|
||||
|
||||
authorize(@submission, :show?)
|
||||
|
||||
params[:pair_programming_exercise_feedback]
|
||||
.permit(:difficulty, :user_estimated_worktime, :exercise_id)
|
||||
.merge(user: current_user,
|
||||
submission: @submission,
|
||||
normalized_score: @submission&.normalized_score)
|
||||
end
|
||||
|
||||
def validate_inputs(uef_params)
|
||||
if uef_params[:difficulty].to_i.negative? || uef_params[:difficulty].to_i >= comment_presets.size
|
||||
false
|
||||
else
|
||||
!(uef_params[:user_estimated_worktime].to_i.negative? || uef_params[:user_estimated_worktime].to_i >= time_presets.size)
|
||||
end
|
||||
rescue StandardError
|
||||
false
|
||||
end
|
||||
|
||||
def programming_group
|
||||
current_contributor if current_contributor.programming_group?
|
||||
end
|
||||
end
|
@ -25,6 +25,7 @@ class Exercise < ApplicationRecord
|
||||
has_many :tags, through: :exercise_tags
|
||||
accepts_nested_attributes_for :exercise_tags
|
||||
has_many :user_exercise_feedbacks
|
||||
has_many :pair_programming_exercise_feedbacks
|
||||
has_many :exercise_tips
|
||||
has_many :tips, through: :exercise_tips
|
||||
|
||||
@ -590,6 +591,8 @@ class Exercise < ApplicationRecord
|
||||
private :valid_submission_deadlines?
|
||||
|
||||
def needs_more_feedback?(submission)
|
||||
return false if PairProgramming23Study.experiment_course?(submission.study_group_id)
|
||||
|
||||
if submission.normalized_score.to_d == BigDecimal('1.0')
|
||||
user_exercise_feedbacks.final.size <= MAX_GROUP_EXERCISE_FEEDBACKS
|
||||
else
|
||||
|
18
app/models/pair_programming_exercise_feedback.rb
Normal file
18
app/models/pair_programming_exercise_feedback.rb
Normal file
@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PairProgrammingExerciseFeedback < ApplicationRecord
|
||||
include Creation
|
||||
|
||||
belongs_to :exercise
|
||||
belongs_to :submission
|
||||
belongs_to :study_group
|
||||
belongs_to :programming_group, optional: true
|
||||
has_one :execution_environment, through: :exercise
|
||||
|
||||
scope :intermediate, -> { where.not(normalized_score: 1.00) }
|
||||
scope :final, -> { where(normalized_score: 1.00) }
|
||||
|
||||
def to_s
|
||||
'Pair Programming Exercise Feedback'
|
||||
end
|
||||
end
|
@ -11,6 +11,7 @@ class ProgrammingGroup < ApplicationRecord
|
||||
has_many :runners, as: :contributor, dependent: :destroy
|
||||
has_many :events
|
||||
has_many :events_synchronized_editor, class_name: 'Event::SynchronizedEditor'
|
||||
has_many :pair_programming_exercise_feedbacks
|
||||
belongs_to :exercise
|
||||
|
||||
validate :min_group_size
|
||||
|
@ -11,6 +11,7 @@ class StudyGroup < ApplicationRecord
|
||||
has_many :lti_parameters, dependent: :delete_all
|
||||
has_many :events
|
||||
has_many :events_synchronized_editor, class_name: 'Event::SynchronizedEditor'
|
||||
has_many :pair_programming_exercise_feedbacks
|
||||
belongs_to :consumer
|
||||
|
||||
def users
|
||||
|
@ -17,6 +17,8 @@ class Submission < ApplicationRecord
|
||||
has_many :testruns
|
||||
has_many :structured_errors, dependent: :destroy
|
||||
has_many :comments, through: :files
|
||||
has_one :user_exercise_feedback
|
||||
has_one :pair_programming_exercise_feedback
|
||||
|
||||
belongs_to :external_users, lambda {
|
||||
where(submissions: {contributor_type: 'ExternalUser'}).includes(:submissions)
|
||||
@ -118,12 +120,18 @@ class Submission < ApplicationRecord
|
||||
end
|
||||
|
||||
def redirect_to_feedback?
|
||||
return false if PairProgramming23Study.experiment_course?(study_group_id)
|
||||
|
||||
# Redirect 10% of users to the exercise feedback page. Ensure, that always the same
|
||||
# users get redirected per exercise and different users for different exercises. If
|
||||
# desired, the number of feedbacks can be limited with exercise.needs_more_feedback?(submission)
|
||||
(contributor_id + exercise.created_at.to_i) % 10 == 1
|
||||
end
|
||||
|
||||
def redirect_to_survey?
|
||||
cause == 'submit' && pair_programming_exercise_feedback.blank? && PairProgramming23Study.experiment_course?(study_group_id)
|
||||
end
|
||||
|
||||
def own_unsolved_rfc(user)
|
||||
Pundit.policy_scope(user, RequestForComment).joins(:submission).where(submission: {contributor:}).unsolved.find_by(exercise:)
|
||||
end
|
||||
|
11
app/policies/pair_programming_exercise_feedback_policy.rb
Normal file
11
app/policies/pair_programming_exercise_feedback_policy.rb
Normal file
@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PairProgrammingExerciseFeedbackPolicy < AdminOnlyPolicy
|
||||
def create?
|
||||
everyone
|
||||
end
|
||||
|
||||
def new?
|
||||
everyone
|
||||
end
|
||||
end
|
@ -0,0 +1,23 @@
|
||||
= form_for(@uef) do |f|
|
||||
div
|
||||
h1 id="exercise-headline"
|
||||
= t('activerecord.models.user_exercise_feedback.one') + " " + @exercise.title
|
||||
= render('shared/form_errors', object: @uef)
|
||||
p
|
||||
== t('pair_programming_exercise_feedback.description')
|
||||
.mb-3
|
||||
h5.mt-4 = t('pair_programming_exercise_feedback.difficulty')
|
||||
= f.collection_radio_buttons :difficulty, @texts, :first, :last do |b|
|
||||
.form-check
|
||||
label.form-check-label
|
||||
= b.radio_button(class: 'form-check-input')
|
||||
= b.text
|
||||
h5.mt-4 = t('pair_programming_exercise_feedback.working_time')
|
||||
= f.collection_radio_buttons :user_estimated_worktime, @times, :first, :last do |b|
|
||||
.form-check
|
||||
label.form-check-label
|
||||
= b.radio_button(class: 'form-check-input')
|
||||
= b.text
|
||||
= f.hidden_field(:exercise_id, :value => @exercise.id)
|
||||
= f.hidden_field(:submission_id, :value => @submission.id)
|
||||
.actions = render('shared/submit_button', f: f, object: @uef)
|
@ -0,0 +1 @@
|
||||
= render('form')
|
Reference in New Issue
Block a user