Commit e2015bfa by Your Name

first kpi working as rake task

parent ce4d5f0b
24723: Locked by 24723 at Wed Dec 12 09:48:44 -0500 2012
24723: Locked by 24723 at Wed Dec 12 15:28:20 -0500 2012
......@@ -6,15 +6,19 @@ cursor_positions:
- :path: models/comment_thread.rb
:cursor_offset: 532
:timestamp: 2012-12-02 13:22:28 -05:00
- :path: models/comment.rb
:cursor_offset: 620
:timestamp: 2012-12-04 11:08:37 -05:00
- :path: models/content.rb
:cursor_offset: 602
:timestamp: 2012-12-12 10:56:18 -05:00
:selection_offset: 400
:block_selection_mode: false
- :path: lib/tasks/flags.rake
:cursor_offset: 0
:timestamp: 2012-12-12 10:56:18 -05:00
- :path: models/comment.rb
:cursor_offset: 523
:timestamp: 2012-12-11 09:28:12 -05:00
- :path: lib/tasks/kpis.rake
:cursor_offset: 463
:timestamp: 2012-12-12 15:28:12 -05:00
- :path: models/content.rb
:cursor_offset: 299
:timestamp: 2012-12-12 15:28:12 -05:00
- :path: .gitignore
:cursor_offset: 281
:timestamp: 2012-12-12 10:58:16 -05:00
files_to_retain: 0
---
open_files:
- models/comment.rb
- lib/tasks/kpis.rake
- .gitignore
- models/content.rb
1355327896
1355346191
#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
......
......@@ -5,34 +5,46 @@ roots['test'] = "http://localhost:8000"
roots['production'] = "http://edx.org"
ROOT = roots[ENV['SINATRA_ENV']]
namespace :kps do
namespace :kpis do
#USAGE
#SINATRA_ENV=development rake flags:flagged
#SINATRA_ENV=development rake kpis:prolific
task :prolific => :environment do
flagged = Content.flagged
courses = {}
count = 10
flagged.each do |f|
contributors = {}
if not courses[f.course_id]
courses[f.course_id] = []
end
map = "function(){emit(this.author_id,1)}"
reduce = "function(k, vals) { var sum = 0; for(var i in vals) sum += vals[i]; return sum; }"
courses[f.course_id] << f
courses = Content.all.distinct("course_id")
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
courses.each do |k,v|
puts "#{k.upcase}"
puts "****************"
v.each do |f|
puts "#{ROOT}/courses/#{f.course_id}/discussion/forum/#{f.commentable_id}/threads/#{f.comment_thread_id} (#{f.class})"
end
puts "\n\n\n\n"
#now sort and limit them
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)]
#now output
puts "\n\n\n"
puts c
contributors[c].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
end
end
......@@ -9,4 +9,5 @@ class Content
(anonymous || anonymous_to_peers) ? attr_when_anonymous : author.send(attr)
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