Skip to content

Commit

Permalink
Try to fix old researcher reports
Browse files Browse the repository at this point in the history
[#72440358]
  • Loading branch information
pjanik committed Jun 18, 2014
1 parent e7b082d commit 8bfb115
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/reports/detail.rb
Expand Up @@ -147,7 +147,11 @@ def run_report(stream_or_path, work_book = Spreadsheet::Workbook.new)
answers = reportables.map { |r| l.answers["#{r.class.to_s}|#{r.id}"] || default_answer_for(r) }
#Bellow is bad, it gets the answers in the wrong order!
#answers = @report_utils[l.offering].saveables(:learner => l, :embeddables => reportables )
submitted_answers = answers.select { |s| s[:submitted] }
# s[:submitted] may be nil, as this hash key was added much later. Previously there was no notion
# of submitted question, they were only answered or not. In theory we could add DB migration that
# would update this hash (see answers attribute in Report::Learner), but that would be non-trivial
# and migration itself would be very time consuming (I've done some experiments in console).
submitted_answers = answers.select { |s| s[:submitted].nil? ? s[:answered] : s[:submitted] }
correct_answers = answers.select { |s| s[:is_correct] }
# <=================================================>
# TODO: weed out answers with no length, or which are empty
Expand Down
12 changes: 8 additions & 4 deletions lib/reports/usage.rb
Expand Up @@ -81,10 +81,14 @@ def run_report(stream_or_path,book=Spreadsheet::Workbook.new)
children = (get_containers(runnable) - [runnable])
children.each do |child|
reportables = child.reportable_elements.map {|re| re[:embeddable] }
answers = reportables.map{|r| l.answers["#{r.class.to_s}|#{r.id}"] || {:answered => false, :answer => "not answered"} }
answered_answers = answers.select {|a| a[:answered] }.size
row_vals << answered_answers
row_vals << percent(answered_answers, reportables.size)
answers = reportables.map{|r| l.answers["#{r.class.to_s}|#{r.id}"] || {:answered => false, :submitted => false, :answer => "not answered"} }
# a[:submitted] may be nil, as this hash key was added much later. Previously there was no notion
# of submitted question, they were only answered or not. In theory we could add DB migration that
# would update this hash (see answers attribute in Report::Learner), but that would be non-trivial
# and migration itself would be very time consuming (I've done some experiments in console).
submitted_answers = answers.select { |a| a[:submitted].nil? ? a[:answered] : a[:submitted] }.size
row_vals << submitted_answers
row_vals << percent(submitted_answers, reportables.size)
end
end

Expand Down

0 comments on commit 8bfb115

Please sign in to comment.