parent
							
								
									c8b1cae947
								
							
						
					
					
						commit
						aca7684414
					
				| @ -0,0 +1,30 @@ | ||||
| class AddCourseContributorScore < ActiveRecord::Migration | ||||
|   def up | ||||
|     # course_count = Course.all.count / 30 + 1 | ||||
|     # transaction do | ||||
|     #   for i in 1 ... course_count do i | ||||
|       Course.all.each do |course| | ||||
|         if course.course_activities.count > 1 | ||||
|           course.student.each do |s| | ||||
|             puts course.id | ||||
|             puts course.name | ||||
|             puts s.student_id | ||||
|             board_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?",s.student_id, course.id, "Message").count * 2 | ||||
|             message_reply_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.student_id} and me.parent_id is not null;").count * 1 | ||||
|             common_reply_count = Comment.find_by_sql("select cm.* from comments cm, news n where cm.author_id = #{s.student_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count * 1 | ||||
|             attachment_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "Attachment").count * 5 | ||||
|             journal_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? ", s.student_id, course.id, "Course").count * 1 | ||||
|             # journal_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "JournalsForMessage").count * 1 | ||||
|             # journal_reply_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? and status =?", s.student_id, course.id, "Course",1).count * 1 | ||||
|             CourseContributorScore.create(:course_id => course.id, :user_id => s.student_id, :message_num => board_count, :message_reply_num => message_reply_count, | ||||
|                                               :news_reply_num => common_reply_count, :resource_num => attachment_count, :journal_num => journal_count, :journal_reply_num => 0) | ||||
|           end | ||||
|         end | ||||
|       end | ||||
|     #   end | ||||
|     # end | ||||
|   end | ||||
| 
 | ||||
|   def down | ||||
|   end | ||||
| end | ||||
					Loading…
					
					
				
		Reference in new issue