Skip to content

Commit

Permalink
Add exercise feedback page for pair programming study
Browse files Browse the repository at this point in the history
  • Loading branch information
kiragrammel authored and MrSerth committed Sep 5, 2023
1 parent fc38653 commit a54001e
Show file tree
Hide file tree
Showing 15 changed files with 261 additions and 1 deletion.
17 changes: 17 additions & 0 deletions app/controllers/concerns/redirect_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,6 +105,16 @@ def redirect_to_community_solution?
@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
Expand Down
96 changes: 96 additions & 0 deletions app/controllers/pair_programming_exercise_feedbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions app/models/exercise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -590,6 +591,8 @@ def valid_submission_deadlines?
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
Expand Down
18 changes: 18 additions & 0 deletions app/models/pair_programming_exercise_feedback.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/models/programming_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/models/study_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -118,12 +120,18 @@ def after_late_deadline?
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
Expand Down
11 changes: 11 additions & 0 deletions app/policies/pair_programming_exercise_feedback_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class PairProgrammingExerciseFeedbackPolicy < AdminOnlyPolicy
def create?
everyone
end

def new?
everyone
end
end
23 changes: 23 additions & 0 deletions app/views/pair_programming_exercise_feedbacks/_form.html.slim
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= render('form')
18 changes: 18 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ de:
internal_user:
one: Interner Nutzer
other: Interne Nutzer
pair_programming_exercise_feedback:
one: Feedback
other: Feedbacks
programming_group:
one: Programmiergruppe
other: Programmiergruppen
Expand Down Expand Up @@ -975,6 +978,21 @@ de:
previous_label: '&#8592; Vorherige Seite'
file_template:
no_template_label: "Leere Datei"
pair_programming_exercise_feedback:
difficulty_easy: "Die Aufgabe war viel zu einfach."
difficulty_some_what_easy: "Die Aufgabe war etwas zu einfach."
difficulty_ok: "Die Aufgabenschwierigkeit war genau richtig."
difficulty_some_what_difficult: "Die Aufgabe war etwas zu schwierig."
difficult_too_difficult: "Die Aufgabe war viel zu schwierig."
difficulty: "Schwierigkeit der Aufgabe:"
description: "Vielen Dank für Deine Abgabe! Bevor du die Aufgabe beendest, würden wir uns freuen, wenn Du uns hier Feedback zur Aufgabe gibst."
estimated_time_less_5: "weniger als 5 Minuten"
estimated_time_5_to_10: "zwischen 5 und 10 Minuten"
estimated_time_10_to_20: "zwischen 10 und 20 Minuten"
estimated_time_20_to_30: "zwischen 20 und 30 Minuten"
estimated_time_more_30: "mehr als 30 Minuten"
working_time: "Geschätze Bearbeitungszeit für diese Aufgabe:"
no_feedback: "Es wurde noch kein Feedback zu dieser Aufgabe gegeben."
user_exercise_feedback:
difficulty_easy: "Die Aufgabe war zu einfach"
difficulty_some_what_easy: "Die Aufgabe war etwas zu einfach"
Expand Down
18 changes: 18 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ en:
internal_user:
one: Internal User
other: Internal Users
pair_programming_exercise_feedback:
one: Feedback
other: Feedbacks
programming_group:
one: Programming Group
other: Programming Groups
Expand Down Expand Up @@ -975,6 +978,21 @@ en:
previous_label: '&#8592; Previous Page'
file_template:
no_template_label: "Empty File"
pair_programming_exercise_feedback:
difficulty_easy: "The exercise was far too easy."
difficulty_some_what_easy: "The exercise was a bit too easy."
difficulty_ok: "The exercise difficulty was just right."
difficulty_some_what_difficult: "The exercise was a bit too difficult."
difficult_too_difficult: "The exercise was far too difficult."
difficulty: "Difficulty of the exercise:"
description: "Thank you for your submission! Before you finish the task, we kindly ask you for feedback for this exercise."
estimated_time_less_5: "less than 5 minutes"
estimated_time_5_to_10: "between 5 and 10 minutes"
estimated_time_10_to_20: "between 10 and 20 minutes"
estimated_time_20_to_30: "between 20 and 30 minutes"
estimated_time_more_30: "more than 30 minutes"
working_time: "Estimated time working on this exercise:"
no_feedback: "There is no feedback for this exercise yet."
user_exercise_feedback:
difficulty_easy: "the exercise was too easy"
difficulty_some_what_easy: "the exercise was somewhat easy"
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@

resources :user_exercise_feedbacks, except: %i[show index]

resources :pair_programming_exercise_feedbacks, only: %i[new create]

resources :external_users, only: %i[index show], concerns: :statistics do
resources :exercises do
get :statistics, to: 'exercises#external_user_statistics', on: :member
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

class AddPairProgrammingExerciseFeedbacks < ActiveRecord::Migration[7.0]
def change
create_table :pair_programming_exercise_feedbacks do |t|
t.references :exercise, null: false, index: true, foreign_key: true
t.references :submission, null: false, index: true, foreign_key: true
t.references :user, polymorphic: true, null: false, index: true
t.references :programming_group, null: true, index: {name: 'pp_feedback_programming_group'}, foreign_key: true
t.references :study_group, null: false, index: true, foreign_key: true
t.integer :difficulty
t.integer :user_estimated_worktime
t.integer :reason_work_alone
t.float :normalized_score

t.timestamps
end
end
end
26 changes: 25 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_09_04_180123) do
ActiveRecord::Schema[7.0].define(version: 2023_09_05_190519) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
enable_extension "pgcrypto"
Expand Down Expand Up @@ -382,6 +382,26 @@
t.index ["study_group_id"], name: "index_lti_parameters_on_study_group_id"
end

create_table "pair_programming_exercise_feedbacks", force: :cascade do |t|
t.bigint "exercise_id", null: false
t.bigint "submission_id", null: false
t.string "user_type", null: false
t.bigint "user_id", null: false
t.bigint "programming_group_id"
t.bigint "study_group_id", null: false
t.integer "difficulty"
t.integer "user_estimated_worktime"
t.integer "reason_work_alone"
t.float "normalized_score"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["exercise_id"], name: "index_pair_programming_exercise_feedbacks_on_exercise_id"
t.index ["programming_group_id"], name: "pp_feedback_programming_group"
t.index ["study_group_id"], name: "index_pair_programming_exercise_feedbacks_on_study_group_id"
t.index ["submission_id"], name: "index_pair_programming_exercise_feedbacks_on_submission_id"
t.index ["user_type", "user_id"], name: "index_pair_programming_exercise_feedbacks_on_user"
end

create_table "programming_group_memberships", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.bigint "programming_group_id", null: false
t.string "user_type", null: false
Expand Down Expand Up @@ -643,6 +663,10 @@
add_foreign_key "lti_parameters", "exercises"
add_foreign_key "lti_parameters", "external_users"
add_foreign_key "lti_parameters", "study_groups"
add_foreign_key "pair_programming_exercise_feedbacks", "exercises"
add_foreign_key "pair_programming_exercise_feedbacks", "programming_groups"
add_foreign_key "pair_programming_exercise_feedbacks", "study_groups"
add_foreign_key "pair_programming_exercise_feedbacks", "submissions"
add_foreign_key "programming_group_memberships", "programming_groups"
add_foreign_key "programming_groups", "exercises"
add_foreign_key "remote_evaluation_mappings", "study_groups"
Expand Down

0 comments on commit a54001e

Please sign in to comment.