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

Adds stats to the sprint demo rake task #127

Merged
merged 6 commits into from Mar 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tasks/sprint/008courses.rake
Expand Up @@ -10,7 +10,7 @@ namespace :sprint do
puts "Added 'student' as a student to 'Being Taken'"
puts "Added 'teacher' as a teacher to 'Being Taught'"
puts "Added 'both' as a teacher and student to 'Both'"
puts "Added task plans and tasks for users"
puts "Added task plan id #{result.outputs.stats_task_plan.id} with partially completed tasks"
else
result.errors.each { |e| puts "Error: " + Lev::ErrorTranslator.translate(e) }
end
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/sprint/008tryanother.rake
@@ -1,7 +1,7 @@
namespace :sprint do
desc 'Sprint 8'
task :'008', [:username] => :environment do |t, args|
require_relative 'sprint_008/main.rb'
task :'008tryanother', [:username] => :environment do |t, args|
require_relative 'sprint_008/try_another.rb'
result = Sprint008::TryAnother.call

if result.errors.none?
Expand Down
29 changes: 24 additions & 5 deletions lib/tasks/sprint/sprint_008/main.rb
Expand Up @@ -43,14 +43,12 @@ def exec
tp.tasking_plans << FactoryGirl.create(:tasking_plan, target: student,
task_plan: tp)
DistributeTasks.call(tp)

tp = FactoryGirl.create :task_plan, assistant: a,
owner: course1,
settings: { page_ids: [3] }
tp.tasking_plans << FactoryGirl.create(:tasking_plan, target: student,
task_plan: tp)
DistributeTasks.call(tp)

tp = FactoryGirl.create :task_plan, assistant: a,
owner: course1,
settings: { page_ids: [4] }
Expand All @@ -59,18 +57,39 @@ def exec
DistributeTasks.call(tp)

# Set up a practice widget

Domain::ResetPracticeWidget.call(role: student_role, page_ids: [])

# Set up a task plan that will have activity for the stats
stats_tp = FactoryGirl.create :task_plan, assistant: a,
owner: course1,
settings: { page_ids: [1,2,3] }

0.upto(30).each do |i|
user = FactoryGirl.create :user, username: "student_#{i}"
stats_tp.tasking_plans << FactoryGirl.create(:tasking_plan,target: user, task_plan: stats_tp)
end
DistributeTasks.call(stats_tp)
# mark some steps as complete and correct
stats_tp.reload.tasks.each_with_index{ |task,index|
task.task_steps.each{ |ts|
next unless 0==index%2 # only mark 1/2 complete
if ts.tasked_type == "TaskedExercise" && 1 != rand(0..4) # and 3/4 of those correct
ts.tasked.answer_id = ts.tasked.correct_answer_id
ts.tasked.free_response = Faker::Company.bs
ts.tasked.save!
end
MarkTaskStepCompleted.call(task_step: ts) }
}

# Outputs

outputs[:teacher] = teacher
outputs[:student] = student
outputs[:teacher_and_student] = teacher_and_student
outputs[:course1] = course1
outputs[:course2] = course2

outputs[:stats_task_plan] = stats_tp
end

end
end
end
10 changes: 9 additions & 1 deletion spec/lib/tasks/sprint/sprint_008/main_spec.rb
Expand Up @@ -30,10 +30,18 @@
api_get(route, student_token)
print_response(outputs[:student], route, response)

route = "/api/courses/#{outputs[:course1].id}/events"
api_get(route, teacher_token)
print_response(outputs[:teacher], route, response)

route = "/api/courses/#{outputs[:course1].id}/practice"
api_get(route, student_token)
print_response(outputs[:student], route, response)

stats_task_plan = outputs[:stats_task_plan]
route = "/api/plans/#{stats_task_plan.id}"
api_get(route, teacher_token)
print_response(outputs[:teacher], route, response)
end

def token_for(user)
Expand All @@ -52,4 +60,4 @@ def print_response(user, route, response)
puts "```"
end

end
end
19 changes: 19 additions & 0 deletions spec/routines/calculate_i_reading_stats_spec.rb
Expand Up @@ -56,5 +56,24 @@

end

context "after tasks are marked as correct" do

it "records them" do
first_task = task_plan.tasks.first
first_task.task_steps.each{ |ts|
if ts.tasked_type == "TaskedExercise"
ts.tasked.answer_id = ts.tasked.correct_answer_id
ts.tasked.free_response = 'a sentence explaining all the things'
ts.tasked.save!
end
MarkTaskStepCompleted.call(task_step: ts)
}
stats = CalculateIReadingStats.call(plan: task_plan.reload).outputs.stats
page = stats.course.current_pages.first
expect(page['page']['title']).to eq('Force')
expect(page['student_count']).to eq(8)
end

end

end