<commit_before>require 'bcrypt'

class User < ActiveRecord::Base
  # has_many :followers, through: :relationships
  has_many :subscriptions
  has_many :categories
  has_many :tasks
  has_many :assignments
  has_many :votes

  # users.password_hash in the database is a :string
  include BCrypt

  def password
    @password ||= Password.new(password_<PASSWORD>)
  end

  def password=(new_password)
    @password = Password.create(new_password)
    self.password_hash = @password
  end

  def subscribe(args)
    args[:user_id] = self.id
    Subscription.create(args)
    self.subscriptions.last.assign_new_tasks
  end

  def public_tasks #fetch public tasks that are not yours
    # all_public = Task.where(public: true)
  end

  def active_tasks #fetch unfinished tasks
    assignments = Assignment.active_assignments({user_id: self.id})
    tasks = assignments.map do |assignment|
      Task.find(assignment.task_id)
    end
    output = {}
    assignments.each_with_index do |assignment, index|
      output[assignment.id] = [ assignment, tasks[index]]
    end
    return output
  end

  def update_subscriptions
    self.subscriptions.each do |subscription|
      subscription.update
    end
  end
end
<commit_msg>Maybe maurits will be happy now.<commit_after>require 'bcrypt'

class User < ActiveRecord::Base
  # has_many :followers, through: :relationships
  has_many :subscriptions
  has_many :categories
  has_many :tasks
  has_many :assignments
  has_many :votes

  # users.password_hash in the database is a :string
  include BCrypt

  def password
    @password ||= <PASSWORD>(<PASSWORD>)
  end

  def password=(new_password)
    @password = Password.create(new_password)
    self.password_hash = @password
  end

  def subscribe(args)
    args[:user_id] = self.id
    Subscription.create(args)
    self.subscriptions.last.assign_new_tasks
  end

  def public_tasks #fetch public tasks that are not yours
    # all_public = Task.where(public: true)
  end

  def active_tasks #fetch unfinished tasks
    assignments = Assignment.active_assignments({user_id: self.id})
    tasks = assignments.map do |assignment|
      task  = Task.find(assignment.task_id)
      task = task.to_json

      new_format = JSON.parse(task)
      new_format[:assignemnt_id] = assignment.id
      new_format
    end
    return tasks
  end

  def update_subscriptions
    self.subscriptions.each do |subscription|
      subscription.update
    end
  end
end

{'fraction_non_alphanumeric': 0.0801635991820041, 'fraction_numerical': 0.0, 'mean_word_length': 3.5805243445692883, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, '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': '85269', 'n_tokens_mistral': 772, 'n_tokens_neox': 754, 'n_words': 194}