Commit 9052a76c by Kevin Chugh

working kpi 4

parent 4eb8da90
...@@ -91,35 +91,38 @@ namespace :kpis do ...@@ -91,35 +91,38 @@ namespace :kpis do
puts "\n" puts "\n"
end end
end
task :epu => :environment do
#USAGE
#SINATRA_ENV=development rake kpis:epu
#or
#SINATRA_ENV=development bundle exec rake kpis:epu
task :epu => :environment do courses = Content.all.distinct("course_id")
#USAGE puts "\n\n*****************************************************************************************************************"
#SINATRA_ENV=development rake kpis:epu puts "Average contributions (votes, threads, or comments) per contributing user per course on edX (#{Date.today}) "
#or puts "*********************************************************************************************************************\n\n"
#SINATRA_ENV=development bundle exec rake kpis:epu
courses.each do |c|
courses = Content.all.distinct("course_id") #first, get all the users who have contributed
puts "\n\n**************************************************************************************************************************************" summary = Content.summary({"course_id" => c})
puts "Average contributions (votes, threads, or comments) per contributing user per course on edX (#{Date.today}) " total_users = summary["contributor_count"]
puts "******************************************************************************************************************************************\n\n" total_activity = summary['thread_count']
total_activity += summary['comment_count']
courses.each do |c| total_activity += summary['vote_count']
#first, get all the users who have contributed ratio = total_activity.to_f / total_users.to_f
summary = Content.summary({"course_id" => c})
total_users = summary["contributor_count"]
total_activity = summary['thread_count'] puts c
total_activity += summary['comment_count'] puts "*********************"
total_activity += summary['vote_count'] puts "Total Threads: #{summary['thread_count']}"
ratio = total_activity.to_f / total_users.to_f puts "Total Comments: #{summary['comment_count']}"
puts "Total Votes: #{summary['vote_count']}\n\n"
puts "Total Threads: #{summary['thread_count']}" puts "Total Users: #{summary['contributor_count']}"
puts "Total Comments: #{summary['comment_count']}" puts "Total Engagements: #{total_activity}\n\n"
puts "Total Votes: #{summary['vote_count']}" puts "Average Engagement Per Engaging User: #{ratio}\n\n\n "
puts "--------------------------------------------------------"
puts "Total Engagements: #{total_activity}"
puts "Average Engagement Per Engaging User: #{ratio}"
end
end end
end end
......
...@@ -53,7 +53,7 @@ class Content ...@@ -53,7 +53,7 @@ class Content
contributors << c["votes"]["up"] contributors << c["votes"]["up"]
contributors << c["votes"]["down"] contributors << c["votes"]["down"]
vote_count += c["votes"]["count"] vote_count += c["votes"]["count"]
if c._type == "ContentThread" if c._type == "CommentThread"
thread_count += 1 thread_count += 1
elsif c._type == "Comment" elsif c._type == "Comment"
comment_count += 1 comment_count += 1
...@@ -66,9 +66,9 @@ class Content ...@@ -66,9 +66,9 @@ class Content
#assemble the answer and ship #assemble the answer and ship
answer["vote_count"] = vote_count answer["vote_count"] = vote_count
answer["thread_count"] = vote_count answer["thread_count"] = thread_count
answer["comment_count"] = vote_count answer["comment_count"] = comment_count
answer["contributor_count"] = contributor_count answer["contributor_count"] = contributors.count
answer answer
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment