class GroupHomeworkCopyWork < ActiveRecord::Migration
  def up
    homeworks = HomeworkCommon.where("homework_type = 3")
    count = homeworks.count / 30 + 2
    transaction do
      for i in 1 ... count do i
      homeworks.page(i).per(30).each do |homework|
        homework.student_works.each do |stu|
          stu.student_work_projects.each do |stu_pro|
            if stu_pro.is_leader == 0
              new_stu = StudentWork.new(:name => stu.name, :description => stu.description, :homework_common_id =>homework.id, :user_id => stu_pro.user_id, :final_score => stu.final_score, :teacher_score => stu.teacher_score, :student_score => stu.student_score, :teaching_asistant_score => stu.teaching_asistant_score,
                                         :project_id => stu.project_id, :late_penalty => stu.late_penalty,:absence_penalty => stu.absence_penalty,:work_score => stu.work_score,:work_status => 3,:commit_time => stu.commit_time)
              new_stu.save
            end
          end
        end
        end
      end
    end
  end

  def down
  end
end
