<commit_before>class EventService
  def initialize(client)
    @client = client
  end

  def get_all_events_ids
    Event.where(active: true)
        .where("user_level <= ?", @client.level)
        .order(created_at: :asc)
        .map(&:id)
  end

  def get_outdate_user_events_ids
    date = Date.today
    events = @client.user_events
      .where("updated_at < ?",
        date.at_beginning_of_week
      )
    events.each do |event|
      unless event.expired
        event.expired = true
        event.save
      end
    end
    ids = events.map(&:event_id)
  end

  def get_events_ids_taken_by_user
    @client.user_events.map(&:event_id)
  end

  def get_available_events
    all_events_ids = get_all_events_ids()
    outdate_user_events_ids = get_outdate_user_events_ids()
    events_ids_taken_by_user = get_events_ids_taken_by_user()
    all_events_ids - outdate_user_events_ids - events_ids_taken_by_user
  end

  def get_notification_events_count
    events_availables = get_available_events()
    events = Event.where(id: events_availables).order(created_at: :asc)
    events = @client.user_events.where(completed: false, expired: false).count === 1 ? [] : events
    count = 0<commit_msg>reset events once user have taken all<commit_after>class EventService
  def initialize(client)
    @client = client
  end

  def get_all_events_ids
    Event.where(active: true)
        .where("user_level <= ?", @client.level)
        .order(created_at: :asc)
        .map(&:id)
  end

  def get_outdate_user_events_ids
    date = Date.today
    events = @client.user_events
      .where("updated_at < ?",
        date.at_beginning_of_week
      )
    events.each do |event|
      unless event.expired
        event.expired = true
        event.save
      end
    end
    ids = events.map(&:event_id)
  end

  def not_event_in_progress
    @client.user_events
          .where(expired: false, completed: false)
          .count == 0
  end

  def get_events_ids_taken_by_user
    @client.user_events.map(&:event_id)
  end

  def get_available_events
    all_events_ids = get_all_events_ids()
    outdate_user_events_ids = get_outdate_user_events_ids()
    events_ids_taken_by_user = get_events_ids_taken_by_user()
    all_events_was_taken = (all_events_ids - events_ids_taken_by_user).empty?
    if all_events_was_taken && not_event_in_progress
      @client.user_events.where(expired: true).destroy_all
      events_ids_taken_by_user = get_events_ids_taken_by_user()
    end
    all_events_ids - outdate_user_events_ids - events_ids_taken_by_user
  end

  def get_notification_events_count
    events_availables = get_available_events()
    events = Event.where(id: events_availables).order(created_at: :asc)
    events = @client.user_events.where(completed: false, expired: false).count === 1 ? [] : events
    count = 0
{'fraction_non_alphanumeric': 0.08675637393767706, 'fraction_numerical': 0.0017705382436260624, 'mean_word_length': 3.3328220858895707, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '1979660', 'n_tokens_mistral': 990, 'n_tokens_neox': 954, 'n_words': 168}