Commit dd0de522 by Your Name

refactored to make rake task more generic and moved logic into the Content model

parent e2015bfa
1355346191
1355422201
#get_marked_text(text) /home/kevin/mitx_all/cs_comments_service/spec/models/at_user_observer_spec.rb describe "#get_marked_text(text)" do
#get_valid_at_position_list(text) /home/kevin/mitx_all/cs_comments_service/spec/models/at_user_observer_spec.rb describe "#get_valid_at_position_list(text)" do
A /home/kevin/mitx_all/cs_comments_service/spec/models/at_user_observer_spec.rb class A
......@@ -148,6 +148,7 @@ new_dumb_thread /home/kevin/mitx_all/cs_comments_service/models/comment_thread.r
parse /home/kevin/mitx_all/cs_comments_service/spec/spec_helper.rb def parse(text)
perform_search /home/kevin/mitx_all/cs_comments_service/models/comment_thread.rb def self.perform_search(params, options={})
process_at_notifications /home/kevin/mitx_all/cs_comments_service/models/observers/at_user_observer.rb def self.process_at_notifications(content)
prolific_metric /home/kevin/mitx_all/cs_comments_service/models/content.rb def self.prolific_metric
respond ok when unfollowing user twice /home/kevin/mitx_all/cs_comments_service/spec/api/subscription_and_notification_spec.rb it "respond ok when unfollowing user twice" do
retrieve information of a single comment /home/kevin/mitx_all/cs_comments_service/spec/api/comment_spec.rb it "retrieve information of a single comment" do
retrieve information of a single comment with its sub comments /home/kevin/mitx_all/cs_comments_service/spec/api/comment_spec.rb it "retrieve information of a single comment with its sub comments" do
......
......@@ -8,43 +8,58 @@ ROOT = roots[ENV['SINATRA_ENV']]
namespace :kpis do
#USAGE
#SINATRA_ENV=development rake kpis:prolific
task :prolific => :environment do
count = 10
contributors = {}
map = "function(){emit(this.author_id,1)}"
reduce = "function(k, vals) { var sum = 0; for(var i in vals) sum += vals[i]; return sum; }"
#USAGE
#SINATRA_ENV=development rake kpis:prolific
#or
#SINATRA_ENV=development bundle exed rake kpis:prolific
courses = Content.all.distinct("course_id")
puts "\n\n*********************************************************************"
puts " Users who have created the most forum content on edX (#{Date.today}) "
puts "*********************************************************************\n\n"
courses.each do |c|
contributors[c] = []
Content.where(course_id: c).map_reduce(map,reduce).out(replace: "results").each do |d|
contributors[c] << d
end
contributors = Content.prolific_metric({"course_id" => c})
#now output
puts c
puts "*********************"
contributors.each do |p|
url = ROOT + "/courses/#{c}/discussion/forum/users/#{p['_id']}"
count_string = "#{p['value'].to_i} contributions:".rjust(25)
puts "#{count_string} #{url} "
end
puts "\n"
end
#now sort and limit them
end
task :starters => :environment do
#USAGE
#SINATRA_ENV=development rake kpis:starters
#or
#SINATRA_ENV=development bundle exed rake kpis:startersgimp
courses = Content.all.distinct("course_id")
puts "\n\n*********************************************************************"
puts " Users who have started the most threads on edX (#{Date.today}) "
puts "*********************************************************************\n\n"
courses.each do |c|
#first sort destructively
contributors[c].sort! {|a,b| -a["value"] <=> -b["value"]}
#then trim it
contributors[c] = contributors[c][0..(count - 1)]
contributors = Content.prolific_metric({"course_id" => c, "_type" => "CommentThread"})
#now output
puts "\n\n\n"
puts c
contributors[c].each do |p|
puts "*********************"
contributors.each do |p|
url = ROOT + "/courses/#{c}/discussion/forum/users/#{p['_id']}"
count_string = "#{p['value'].to_i} contributions:".rjust(25)
puts "#{count_string} #{url} "
end
end
puts "\n"
end
end
end
class Content
include Mongoid::Document
def author_with_anonymity(attr=nil, attr_when_anonymous=nil)
if not attr
(anonymous || anonymous_to_peers) ? nil : author
......@@ -9,5 +9,31 @@ class Content
(anonymous || anonymous_to_peers) ? attr_when_anonymous : author.send(attr)
end
end
def self.prolific_metric what
#take a hash of criteria (where) and return a hash of hashes
#course => user => count
count = 10
contributors = {}
map = "function(){emit(this.author_id,1)}"
reduce = "function(k, vals) { var sum = 0; for(var i in vals) sum += vals[i]; return sum; }"
contributors = []
self.where(what).map_reduce(map,reduce).out(replace: "results").each do |d|
contributors << d
end
#now sort and limit them
#first sort destructively
contributors.sort! {|a,b| -a["value"] <=> -b["value"]}
#then trim it
contributors = contributors[0..(count - 1)]
contributors
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