<commit_before>class LevelAccess < Struct.new(:team)

  def can_access?(level)
    return true if level == 1
    score = get_score_for(level-1)
    required = get_required_for(level-1)
    score >= required
  end

  def get_required_for(level)
    count = get_count_for(level)
    count > 1 ? count-1 : count
  end

  private

  def get_count_for(level)
    counts[level] || 0
  end

  def get_score_for(level)
    scores[level] || 0
  end

  def scores
    @scores ||= Puzzle.where(:id => guessed_puzzle_ids).group(:level).count
  end

  def counts
    @counts ||= Puzzle.group(:level).count
  end

  def guessed_puzzle_ids
    Guess.where(:team_id => team.id, :correct => true).select('distinct(puzzle_id)')<commit_msg>Enable level 2 for everyone<commit_after>class LevelAccess < Struct.new(:team)

  def can_access?(level)
    return true if level == 1
    return true if level == 2
    score = get_score_for(level-1)
    required = get_required_for(level-1)
    score >= required
  end

  def get_required_for(level)
    count = get_count_for(level)
    count > 1 ? count-1 : count
  end

  private

  def get_count_for(level)
    counts[level] || 0
  end

  def get_score_for(level)
    scores[level] || 0
  end

  def scores
    @scores ||= Puzzle.where(:id => guessed_puzzle_ids).group(:level).count
  end

  def counts
    @counts ||= Puzzle.group(:level).count
  end

  def guessed_puzzle_ids
    Guess.where(:team_id => team.id, :correct => true).select('distinct(puzzle_id)')
{'fraction_non_alphanumeric': 0.11709286675639301, 'fraction_numerical': 0.010767160161507403, 'mean_word_length': 3.4124629080118694, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '214557', 'n_tokens_mistral': 549, 'n_tokens_neox': 514, 'n_words': 116}