<commit_before># encoding: utf-8

=begin

= MeetingStatCalculator
  - Goggles framework vers.:  6.085
  - author: Leega

 Utility class to calculate meeting stats from meeting results or entries.

=== Members:
 - <tt>:swimmer_male_count</tt> => Count of male swimmers with result

=end
class MeetingStatCalculator
  # These must be initialized on creation:
  attr_reader :meeting

  # Creates a new instance.
  # Note the ascending precision of the parameters, which allows to skip
  # the rarely used ones.
  #
  def initialize( meeting )
    unless meeting && meeting.instance_of?( Meeting )
      raise ArgumentError.new("Meeting stat needs a valid meeting")
    end

    @meeting       = meeting
    @meeting_stats = MeetingStatDAO.new( meeting )
  end

  def get_meeting
    @meeting
  end
  # ---------------------------------------------------------------------------

  # Verify if meeting has results
  # Meeting should have are_results_acquired flag set to true
  # and some meeting_individual_results
  # and more than one team partecipating
  #
  def has_results?()
    (( @meeting.are_results_acquired || @meeting.meeting_individual_results.exists? ) && @meeting.teams.distinct.count > 1 )
  end

  # Verify if meeting has relays
  # Meeting should have results
  # and some meeting_relay_results
  #
  def has_relays?()
    ( has_results? && @meeting.meeting_relay_results.exists? )
  end

  # Verify if meeting has entries
  # Meeting should have some meeting_entries
  # and more than one entered team
  #
  def has_entries?()
    ( @meeting.meeting_entries.exists? && @meeting.meeting_entries.select('team_id').distinct.count > 1 )
  end
  # ---------------------------------------------------------------------------

  # Retrieves the teams lis for the meeting
  # If results are acquired the teams are those with at least one result
  # If results are not acquired the teams are those with at least one entry
  #
  def get_teams()
    if has_results?
      teams = @meeting.teams.sort_by_name('ASC').distinct
    elsif has_entries?
      teams = []<commit_msg>Fix stats team order<commit_after># encoding: utf-8

=begin

= MeetingStatCalculator
  - Goggles framework vers.:  6.085
  - author: Leega

 Utility class to calculate meeting stats from meeting results or entries.

=== Members:
 - <tt>:swimmer_male_count</tt> => Count of male swimmers with result

=end
class MeetingStatCalculator
  # These must be initialized on creation:
  attr_reader :meeting

  # Creates a new instance.
  # Note the ascending precision of the parameters, which allows to skip
  # the rarely used ones.
  #
  def initialize( meeting )
    unless meeting && meeting.instance_of?( Meeting )
      raise ArgumentError.new("Meeting stat needs a valid meeting")
    end

    @meeting       = meeting
    @meeting_stats = MeetingStatDAO.new( meeting )
  end

  def get_meeting
    @meeting
  end
  # ---------------------------------------------------------------------------

  # Verify if meeting has results
  # Meeting should have are_results_acquired flag set to true
  # and some meeting_individual_results
  # and more than one team partecipating
  #
  def has_results?()
    (( @meeting.are_results_acquired || @meeting.meeting_individual_results.exists? ) && @meeting.teams.distinct.count > 1 )
  end

  # Verify if meeting has relays
  # Meeting should have results
  # and some meeting_relay_results
  #
  def has_relays?()
    ( has_results? && @meeting.meeting_relay_results.exists? )
  end

  # Verify if meeting has entries
  # Meeting should have some meeting_entries
  # and more than one entered team
  #
  def has_entries?()
    ( @meeting.meeting_entries.exists? && @meeting.meeting_entries.select('team_id').distinct.count > 1 )
  end
  # ---------------------------------------------------------------------------

  # Retrieves the teams lis for the meeting
  # If results are acquired the teams are those with at least one result
  # If results are not acquired the teams are those with at least one entry
  #
  def get_teams()
    if has_results?
      teams = @meeting.teams.unscope(:order).sort_by_name('ASC').distinct
    elsif has_entries?
      teams = []
{'fraction_non_alphanumeric': 0.1443939756155869, 'fraction_numerical': 0.0033468802295003584, 'mean_word_length': 2.56692242114237, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5757258', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1180, 'n_words': 395}