Skip to content
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

Issue#952 feature progressive tips #961

Closed
wants to merge 10 commits into from
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ coverage/

vendor/cache/**
*.cache

node_modules/**

**/*.rsa*
**/*.gem
4 changes: 4 additions & 0 deletions app/helpers/assignment_result_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def manual_evaluation_comment(assignment)
end
end

def showable_tips_html(assignment)
Mumukit::ContentType::Markdown.to_html assignment.showable_tips.map { |tip| "* #{tip}" }.join "\n"
end

private

def solution_octet_data(assignment)
Expand Down
6 changes: 5 additions & 1 deletion app/models/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Assignment < ApplicationRecord
define_method(field) { self[field]&.map { |it| it.symbolize_keys } }
end

delegate :language, :name, :visible_success_output?, to: :exercise
delegate :language, :name, :visible_success_output?, :tips, to: :exercise
delegate :output_content_type, to: :language
delegate :should_retry?, to: :status

Expand Down Expand Up @@ -140,6 +140,10 @@ def as_platform_json
}})
end

def showable_tips
tips.select { |tries, _| tries <= attemps_count }.map &:second
end

private

def update_submissions_count!
Expand Down
2 changes: 2 additions & 0 deletions app/models/exercise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Exercise < ApplicationRecord

belongs_to :guide

serialize :tips, Array

defaults { self.submissions_count = 0 }

validates_presence_of :submissions_count,
Expand Down
4 changes: 3 additions & 1 deletion app/models/submission/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def save_submission!(assignment)
end

def save_results!(results, assignment)
assignment.update! results
assignment.attemps_count += 1 unless results[:status] == :passed
assignment.update results
assignment.save!
end

def notify_results!(results, assignment)
Expand Down
1 change: 1 addition & 0 deletions app/views/exercise_solutions/_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
</div>
<% end %>
<div id="results-section" class="<%= 'collapse' if render_feedback?(assignment) %> results-item">
<%= showable_tips_html assignment %>
<%= render_test_results assignment %>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddFailedSubmissionsCountToAssignments < ActiveRecord::Migration[5.1]
def change
add_column :assignments, :attemps_count, :integer, default: 0
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddProgressiveTipsToExercises < ActiveRecord::Migration[5.1]
def change
add_column :exercises, :tips, :text
end
end
2 changes: 2 additions & 0 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
t.string "queries", default: [], array: true
t.text "query_results"
t.text "manual_evaluation_comment"
t.integer "attemps_count", default: 0
t.index ["exercise_id"], name: "index_assignments_on_exercise_id"
t.index ["submission_id"], name: "index_assignments_on_submission_id"
t.index ["submitter_id"], name: "index_assignments_on_submitter_id"
Expand Down Expand Up @@ -136,6 +137,7 @@
t.text "goal"
t.string "initial_state"
t.string "final_state"
t.text "tips"
t.index ["guide_id"], name: "index_exercises_on_guide_id"
t.index ["language_id"], name: "index_exercises_on_language_id"
end
Expand Down
46 changes: 46 additions & 0 deletions spec/features/progressive_tips_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'spec_helper'

feature 'Progressive Tips', organization_workspace: :test do
let(:user) { create(:user) }

let(:haskell) { create(:haskell) }

let!(:problem) { build(:problem, name: 'Succ1', description: 'Description of Succ1', layout: :input_right, tips: [[5, 'try this'], [10, 'try that']] ) }
let(:assignment) { problem.find_or_init_assignment_for(user) }

let!(:chapter) {
create(:chapter, name: 'Functional Programming', lessons: [
create(:lesson, name: 'getting-started', description: 'An awesome guide', language: haskell, exercises: [problem])
]) }

before { reindex_current_organization! }

context 'visit failed exercise' do
before { set_current_user! user }
before { assignment.update! status: :failed }

scenario '2 failed submissions' do
assignment.update! attemps_count: 2
visit "/exercises/#{problem.slug}"

expect(page).to_not have_text('try this')
expect(page).to_not have_text('try that')
end

scenario '5 failed submissions' do
assignment.update! attemps_count: 5
visit "/exercises/#{problem.id}"

expect(page).to have_text('try this')
expect(page).to_not have_text('try that')
end

scenario '10 failed submissions' do
assignment.update! attemps_count: 10
visit "/exercises/#{problem.id}"

expect(page).to have_text('try this')
expect(page).to have_text('try that')
end
end
end
3 changes: 3 additions & 0 deletions spec/models/event_generation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
feedback: nil,
test_results: nil,
submissions_count: 2,
attemps_count: 0,
manual_evaluation_comment: nil,
exercise: {
eid: exercise.bibliotheca_id,
Expand Down Expand Up @@ -97,6 +98,7 @@
feedback: nil,
test_results: nil,
submissions_count: 2,
attemps_count: 0,
manual_evaluation_comment: nil,
exercise: {
name: exercise.name,
Expand Down Expand Up @@ -151,6 +153,7 @@
feedback: nil,
test_results: nil,
submissions_count: 2,
attemps_count: 0,
manual_evaluation_comment: nil,
exercise: {
eid: exercise.bibliotheca_id,
Expand Down