<commit_before>#= Revision model
class Revision < ActiveRecord::Base
  belongs_to :user
  belongs_to :article
  scope :after_date, -> (date) { where('date > ?', date) }

  ####################
  # Instance methods #
  ####################
  def update(data={}, save=true)
    self.attributes = data

    self.save if save
  end

  #################
  # Class methods #
  #################
  def self.update_all_revisions(courses=nil)
    results = []
    courses = [courses] if courses.is_a? Course
    courses ||= Course.all
    courses.each do |c|
      start = c.start
      has_new_user = c.users.role('student').where(revision_count: 0).count
      start = c.revisions.order('date DESC').first.date unless has_new_user
      start = start.strftime('%Y%m%d')
      revisions = Utils.chunk_requests(c.users.role('student'), 40) do |block|
        Replica.get_revisions block, start, c.end.strftime('%Y%m%d')
      end
      results += revisions
    end

    import_revisions(results)

    result_ids = results.map do |_a_id, a|
      a['revisions'].map { |r| r['id'] }<commit_msg>Only pull new revision/article data for current courses<commit_after>#= Revision model
class Revision < ActiveRecord::Base
  belongs_to :user
  belongs_to :article
  scope :after_date, -> (date) { where('date > ?', date) }

  ####################
  # Instance methods #
  ####################
  def update(data={}, save=true)
    self.attributes = data

    self.save if save
  end

  #################
  # Class methods #
  #################
  def self.update_all_revisions(courses=nil)
    results = []
    courses = [courses] if courses.is_a? Course
    courses ||= Course.current
    courses.each do |c|
      start = c.start
      has_new_user = c.users.role('student').where(revision_count: 0).count
      start = c.revisions.order('date DESC').first.date unless has_new_user
      start = start.strftime('%Y%m%d')
      revisions = Utils.chunk_requests(c.users.role('student'), 40) do |block|
        Replica.get_revisions block, start, c.end.strftime('%Y%m%d')
      end
      results += revisions
    end

    import_revisions(results)

    result_ids = results.map do |_a_id, a|
      a['revisions'].map { |r| r['id'] }
{'fraction_non_alphanumeric': 0.19122965641952983, 'fraction_numerical': 0.0027124773960217, 'mean_word_length': 3.382178217821782, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3704746', 'n_tokens_mistral': 760, 'n_tokens_neox': 725, 'n_words': 157}