<commit_before>class CommunityTrackPlugin::TrackListBlock < Block

  include CommunityTrackPlugin::StepHelper

  settings_items :limit, :type => :integer, :default => 3
  settings_items :more_another_page, :type => :boolean, :default => false
  settings_items :category_ids, :type => Array, :default => []
  settings_items :order, :type => :string, :default => 'hits'

  attr_accessible :more_another_page, :category_ids, :order

  def self.description
    _('Track List')
  end

  def help
    _('This block displays a list of most relevant tracks.')
  end

  def track_partial
    'track'
  end

  def tracks(page=1, per_page=limit)
    tracks = all_tracks
    tracks = case order
             when 'hits'
               tracks.order('hits DESC')
             when 'newer'
               tracks.order('created_at DESC')
             when 'random'
               tracks.order('random()')
             else
               tracks
             end
    tracks.paginate(:per_page => per_page, :page => page)
  end

  def count_tracks
    all_tracks.count<commit_msg>community_track: set default order to 'hits'<commit_after>class CommunityTrackPlugin::TrackListBlock < Block

  include CommunityTrackPlugin::StepHelper

  settings_items :limit, :type => :integer, :default => 3
  settings_items :more_another_page, :type => :boolean, :default => false
  settings_items :category_ids, :type => Array, :default => []
  settings_items :order, :type => :string, :default => 'hits'

  attr_accessible :more_another_page, :category_ids, :order

  def self.description
    _('Track List')
  end

  def help
    _('This block displays a list of most relevant tracks.')
  end

  def track_partial
    'track'
  end

  def tracks(page=1, per_page=limit)
    tracks = all_tracks
    tracks = case order
             when 'newer'
               tracks.order('created_at DESC')
             when 'random'
               tracks.order('random()')
             else
               tracks.order('hits DESC')
             end
    tracks.paginate(:per_page => per_page, :page => page)
  end

  def count_tracks
    all_tracks.count
{'fraction_non_alphanumeric': 0.1038899430740038, 'fraction_numerical': 0.0018975332068311196, 'mean_word_length': 2.7460035523978688, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '7661419', 'n_tokens_mistral': 639, 'n_tokens_neox': 607, 'n_words': 167}