app/controllers/meetings_controller.rb
# Show all details regarding a single Team for the whole Meeting.
#
# === Params:
# - id: Meeting row id.
# - team_id: Team id.
#
Show all details regarding a single Team for the whole Meeting.
Params:
id: Meeting row id.
Show all details regarding a single Team for the whole Meeting . Params : id : Meeting row id .
def show_team_results
    mir = @meeting.meeting_individual_results.for_team(@team).unscope(:order)
    mrr = @meeting.meeting_relay_results.for_team(@team).unscope(:order)
    unless ( mir.exists? || mrr.exists? )
      flash[:error] = I18n.t(:no_result_to_show)
      redirect_to( meetings_current_path() ) and return
    end
    @meeting_team_swimmers =  mir.joins(:swimmer).includes(:swimmer)
      .group(:swimmer_id)
      .order('swimmers.complete_name ASC')
      .map{ |row| row.swimmer }
    @team_ranks_1 = mir.is_valid.has_rank(1).count
    @team_ranks_2 = mir.is_valid.has_rank(2).count
    @team_ranks_3 = mir.is_valid.has_rank(3).count
    @team_ranks_4 = mir.is_valid.has_rank(4).count
    @team_outstanding_scores = mir.is_valid.for_over_that_score().count 
    meeting_team_swimmers_ids = @meeting_team_swimmers.collect{|row| row.id}
    @events_per_swimmers = {}
    meeting_team_swimmers_ids.each do |id|
      @events_per_swimmers[ id ] = mir
          .where([ 'meeting_individual_results.swimmer_id = ?', id ])
    end
    ind_event_ids = mir.map{ |row| row.meeting_event.id }.uniq
    rel_event_ids = mrr.map{ |row| row.meeting_event.id }.uniq
    event_ids = (ind_event_ids + rel_event_ids).uniq.sort
    @team_tot_events = event_ids.size
    @meeting_events_list = MeetingEvent.where( id: event_ids )
      .joins( :event_type, :stroke_type )
      .includes( :event_type, :stroke_type )
      .order( 'event_types.is_a_relay, meeting_events.event_order' )
    @team_ranks_1 += mrr.is_valid.has_rank(1).count
    @team_ranks_2 += mrr.is_valid.has_rank(2).count
    @team_ranks_3 += mrr.is_valid.has_rank(3).count
    @team_ranks_4 += mrr.is_valid.has_rank(4).count
    @team_outstanding_scores += mrr.is_valid.for_over_that_score().count
    ind_prg_ids = MeetingIndividualResult.joins(:meeting, :meeting_program)
      .includes(:meeting, :meeting_program)
      .where([
        'meetings.id = ? AND meeting_individual_results.team_id = ?',
        @meeting.id, @team.id
      ])
      .map{ |row| row.meeting_program_id }
      .uniq
    rel_prg_ids = MeetingRelayResult.joins(:meeting, :meeting_program)
      .includes(:meeting, :meeting_program)
      .where([
        'meetings.id = ? AND meeting_relay_results.team_id = ?',
        @meeting.id, @team.id
      ])
      .map{ |row| row.meeting_program_id }
      .uniq
    prg_ids = (ind_prg_ids + rel_prg_ids).uniq.sort
    @meeting_programs_list = MeetingProgram.where( id: prg_ids )
      .joins( :event_type, :stroke_type )
      .includes( :event_type, :stroke_type )
      .order( 'event_types.is_a_relay, meeting_events.event_order' )
    @top_scores = {}
    if mir.has_points.exists?
      GenderType.individual_only.each do |gender_type|
        @top_scores["#{gender_type.code}-standard_points"] = mir.for_gender_type( gender_type ).sort_by_standard_points.first if mir.for_gender_type( gender_type ).has_points.exists?
      end
    end
    if mir.has_points('goggle_cup_points').exists?
      @top_scores["goggle_cup_points"] = mir.sort_by_goggle_cup.first
    end
    max_mir_updated_at = mir.exists? ? mir.select( "meeting_individual_results.updated_at" ).order(:updated_at).last.updated_at.to_i : 0
    max_mrr_updated_at = mrr.exists? ? mrr.select( "meeting_relay_results.updated_at" ).order(:updated_at).last.updated_at.to_i : 0
    @max_updated_at = max_mir_updated_at >= max_mrr_updated_at ? max_mir_updated_at : max_mrr_updated_at
  end
def show_team_results mir = @meeting . meeting_individual_results . for_team ( @team ) . unscope ( :order ) mrr = @meeting . meeting_relay_results . for_team ( @team ) . unscope ( :order ) unless ( mir . exists? || mrr . exists? ) flash [ :error ] = I18n . t ( :no_result_to_show ) redirect_to ( meetings_current_path ( ) ) and return end @meeting_team_swimmers = mir . joins ( :swimmer ) . includes ( :swimmer ) . group ( :swimmer_id ) . order ( 'swimmers.complete_name ASC' ) . map { | row | row . swimmer } @team_ranks_1 = mir . is_valid . has_rank ( 1 ) . count @team_ranks_2 = mir . is_valid . has_rank ( 2 ) . count @team_ranks_3 = mir . is_valid . has_rank ( 3 ) . count @team_ranks_4 = mir . is_valid . has_rank ( 4 ) . count @team_outstanding_scores = mir . is_valid . for_over_that_score ( ) . count meeting_team_swimmers_ids = @meeting_team_swimmers . collect { | row | row . id } @events_per_swimmers = { } meeting_team_swimmers_ids . each do | id | @events_per_swimmers [ id ] = mir . where ( [ 'meeting_individual_results.swimmer_id = ?' , id ] ) end ind_event_ids = mir . map { | row | row . meeting_event . id } . uniq rel_event_ids = mrr . map { | row | row . meeting_event . id } . uniq event_ids = ( ind_event_ids + rel_event_ids ) . uniq . sort @team_tot_events = event_ids . size @meeting_events_list = MeetingEvent . where ( id : event_ids ) . joins ( :event_type , :stroke_type ) . includes ( :event_type , :stroke_type ) . order ( 'event_types.is_a_relay, meeting_events.event_order' ) @team_ranks_1 += mrr . is_valid . has_rank ( 1 ) . count @team_ranks_2 += mrr . is_valid . has_rank ( 2 ) . count @team_ranks_3 += mrr . is_valid . has_rank ( 3 ) . count @team_ranks_4 += mrr . is_valid . has_rank ( 4 ) . count @team_outstanding_scores += mrr . is_valid . for_over_that_score ( ) . count ind_prg_ids = MeetingIndividualResult . joins ( :meeting , :meeting_program ) . includes ( :meeting , :meeting_program ) . where ( [ 'meetings.id = ? AND meeting_individual_results.team_id = ?' , @meeting . id , @team . id ] ) . map { | row | row . meeting_program_id } . uniq rel_prg_ids = MeetingRelayResult . joins ( :meeting , :meeting_program ) . includes ( :meeting , :meeting_program ) . where ( [ 'meetings.id = ? AND meeting_relay_results.team_id = ?' , @meeting . id , @team . id ] ) . map { | row | row . meeting_program_id } . uniq prg_ids = ( ind_prg_ids + rel_prg_ids ) . uniq . sort @meeting_programs_list = MeetingProgram . where ( id : prg_ids ) . joins ( :event_type , :stroke_type ) . includes ( :event_type , :stroke_type ) . order ( 'event_types.is_a_relay, meeting_events.event_order' ) @top_scores = { } if mir . has_points . exists? GenderType . individual_only . each do | gender_type | @top_scores [ "#{gender_type.code}-standard_points" ] = mir . for_gender_type ( gender_type ) . sort_by_standard_points . first if mir . for_gender_type ( gender_type ) . has_points . exists? end end if mir . has_points ( 'goggle_cup_points' ) . exists? @top_scores [ "goggle_cup_points" ] = mir . sort_by_goggle_cup . first end max_mir_updated_at = mir . exists? ? mir . select ( "meeting_individual_results.updated_at" ) . order ( :updated_at ) . last . updated_at . to_i : 0 max_mrr_updated_at = mrr . exists? ? mrr . select ( "meeting_relay_results.updated_at" ) . order ( :updated_at ) . last . updated_at . to_i : 0 @max_updated_at = max_mir_updated_at >= max_mrr_updated_at ? max_mir_updated_at : max_mrr_updated_at end
Show all details regarding a single Team for the whole Meeting.
Show all details regarding a single Team for the whole Meeting .
# Get the events filtered by team_id: # Get the swimmer list and some stats: # TODO # Refactor with medal_types # Calculate team highligths # Use default standard_points and 800 # Collect an Hash with the swimmer_id pointing to the description of all the events performed by each swimmer: # Add to the stats the relay results: # Get the programs filtered by team_id: # Find out top scorer # Get a timestamp for the cache key: