Commit 551bceb0 by Kevin Chugh

new kpi

parent c1136868
...@@ -11,7 +11,7 @@ namespace :kpis do ...@@ -11,7 +11,7 @@ namespace :kpis do
#USAGE #USAGE
#SINATRA_ENV=development rake kpis:prolific #SINATRA_ENV=development rake kpis:prolific
#or #or
#SINATRA_ENV=development bundle exed rake kpis:prolific #SINATRA_ENV=development bundle exec rake kpis:prolific
courses = Content.all.distinct("course_id") courses = Content.all.distinct("course_id")
puts "\n\n*********************************************************************" puts "\n\n*********************************************************************"
...@@ -38,7 +38,7 @@ namespace :kpis do ...@@ -38,7 +38,7 @@ namespace :kpis do
#USAGE #USAGE
#SINATRA_ENV=development rake kpis:starters #SINATRA_ENV=development rake kpis:starters
#or #or
#SINATRA_ENV=development bundle exed rake kpis:starters #SINATRA_ENV=development bundle exec rake kpis:starters
courses = Content.all.distinct("course_id") courses = Content.all.distinct("course_id")
puts "\n\n*********************************************************************" puts "\n\n*********************************************************************"
...@@ -64,7 +64,7 @@ namespace :kpis do ...@@ -64,7 +64,7 @@ namespace :kpis do
#USAGE #USAGE
#SINATRA_ENV=development rake kpis:ppu #SINATRA_ENV=development rake kpis:ppu
#or #or
#SINATRA_ENV=development bundle exed rake kpis:ppu #SINATRA_ENV=development bundle exec rake kpis:ppu
courses = Content.all.distinct("course_id") courses = Content.all.distinct("course_id")
puts "\n\n*********************************************************************" puts "\n\n*********************************************************************"
...@@ -94,33 +94,30 @@ namespace :kpis do ...@@ -94,33 +94,30 @@ namespace :kpis do
task :epu => :environment do task :epu => :environment do
#USAGE #USAGE
#SINATRA_ENV=development rake kpis:ppu #SINATRA_ENV=development rake kpis:epu
#or #or
#SINATRA_ENV=development bundle exed rake kpis:ppu #SINATRA_ENV=development bundle exec rake kpis:epu
courses = Content.all.distinct("course_id") courses = Content.all.distinct("course_id")
puts "\n\n**************************************************************************************************************************************" puts "\n\n**************************************************************************************************************************************"
puts "Average contributions (votes, comments, endorsements, or threads or follows) per contributing user per course on edX (#{Date.today}) " puts "Average contributions (votes, threads, or comments) per contributing user per course on edX (#{Date.today}) "
puts "******************************************************************************************************************************************\n\n" puts "******************************************************************************************************************************************\n\n"
courses.each do |c| courses.each do |c|
#first, get all the users who have contributed #first, get all the users who have contributed
contributors = Content.prolific_metric({"course_id" => c}) summary = Content.summary({"course_id" => c})
total_users = contributors.count total_users = summary["contributor_count"]
total_activity = summary['thread_count']
#now, get the threads total_activity += summary['comment_count']
total_activity += summary['vote_count']
total_threads = Content.where("_type" => "CommentThread","course_id" => c).count ratio = total_activity.to_f / total_users.to_f
ratio = total_threads.to_f / total_users.to_f puts "Total Threads: #{summary['thread_count']}"
puts "Total Comments: #{summary['comment_count']}"
#now output puts "Total Votes: #{summary['vote_count']}"
puts c puts "--------------------------------------------------------"
puts "*********************" puts "Total Engagements: #{total_activity}"
puts "Total Threads: #{total_threads}" puts "Average Engagement Per Engaging User: #{ratio}"
puts "Total Users: #{total_users}"
puts "Average Thread/User: #{ratio}"
puts "\n"
end end
end end
......
...@@ -36,4 +36,43 @@ class Content ...@@ -36,4 +36,43 @@ class Content
contributors contributors
end end
def self.summary what
#take a hash of criteria (where) and return a hash of hashes
#of total users, votes, comments, endorsements,
answer = {}
vote_count = 0
thread_count = 0
comment_count = 0
contributors = []
content = self.where(what)
content.each do |c|
contributors << c.author_id
contributors << c["votes"]["up"]
contributors << c["votes"]["down"]
votes += c.votes["count"]
if c._type == "ContentThread"
thread_count += 1
elsif c._type == "Comment"
comment_count += 1
end
end
#uniquify contributors
contributors = contributors.uniq
#assemble the answer and ship
answer["vote_count"] = vote_count
answer["thread_count"] = vote_count
answer["comment_count"] = vote_count
answer["contributor_count"] = contributor_count
answer
end
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