# lib/tasks/quiz_stats.rake
|
|
namespace :quiz do
|
|
desc "Show quiz statistics from Oct 17, 2025"
|
|
task stats: :environment do
|
|
results = QuizResult.where("created_at >= ?", Date.new(2025, 10, 17))
|
|
|
|
total = results.count
|
|
by_locale = results.group(:locale).count
|
|
scores = results.group(:score).count
|
|
avg_score = results.average(:score)
|
|
|
|
# Calculate result categories
|
|
questions = Node.at_depth(1).tmpl_article.viewable.ordered.to_a
|
|
questions_count = questions.count
|
|
result_categories = { "People" => 0, "Planet" => 0, "Balanced" => 0 }
|
|
|
|
results.each do |qr|
|
|
people_score = questions_count - qr.score
|
|
score_diff = people_score - qr.score
|
|
|
|
category = case
|
|
when score_diff >= 2
|
|
"People"
|
|
when score_diff <= -2
|
|
"Planet"
|
|
else
|
|
"Balanced"
|
|
end
|
|
result_categories[category] += 1
|
|
end
|
|
|
|
puts "Quiz Results from Oct 17, 2025"
|
|
puts "=" * 40
|
|
puts "Total: #{total}"
|
|
|
|
puts "\nBy locale:"
|
|
by_locale.sort.each do |locale, count|
|
|
locale_name = I18n.t(locale, scope: 'languages')
|
|
puts " #{locale_name}: #{count}"
|
|
end
|
|
|
|
puts "\nScore distribution:"
|
|
scores.sort.each do |score, count|
|
|
puts " Score #{score}: #{count}"
|
|
end
|
|
|
|
puts "\nAverage score: #{avg_score&.round(2)}"
|
|
|
|
puts "\nResult categories:"
|
|
result_categories.each do |category, count|
|
|
percentage = total > 0 ? (count.to_f / total * 100).round(1) : 0
|
|
puts " #{category}: #{count} (#{percentage}%)"
|
|
end
|
|
|
|
# Question by question breakdown
|
|
|
|
puts "\n\nQuestion breakdown:"
|
|
puts "=" * 40
|
|
questions.each_with_index do |question, i|
|
|
answers = Answer.where(node_id: question.id).where("created_at >= ?", Date.new(2025, 10, 17))
|
|
answer_counts = answers.group(:value).count
|
|
|
|
planet_answer = (i == 0 || i == 3) ? 0 : 1
|
|
people_answer = (i == 0 || i == 3) ? 1 : 0
|
|
|
|
planet_count = answer_counts[planet_answer] || 0
|
|
people_count = answer_counts[people_answer] || 0
|
|
total_answers = planet_count + people_count
|
|
|
|
puts "\nQ#{i + 1}: #{question.title}"
|
|
if total_answers > 0
|
|
planet_pct = (planet_count.to_f / total_answers * 100).round(1)
|
|
people_pct = (people_count.to_f / total_answers * 100).round(1)
|
|
puts " Planet: #{planet_count} (#{planet_pct}%)"
|
|
puts " People: #{people_count} (#{people_pct}%)"
|
|
else
|
|
puts " No answers"
|
|
end
|
|
end
|
|
end
|
|
end
|