app/controllers/meetings_controller.rb
# Show the ranking regarding a single Meeting
# Assumes params[:id] refers to a specific Meeting row.
#
# === Optional parameters:
# - team_id, to highlight a specific team
#
Show the ranking regarding a single Meeting
Assumes params[:id] refers to a specific Meeting row.

Optional parameters:
team_id, to highlight a specific team
Show the ranking regarding a single Meeting Assumes params [ : id ] refers to a specific Meeting row . Optional parameters : team_id to highlight a specific team
def show_ranking
    @preselected_team_id = params[:team_id]
    if ( @meeting.meeting_team_scores.exists? )
      @meeting_team_scores = @meeting.meeting_team_scores
        .joins( :team, :team_affiliation )
        .includes( :team, :team_affiliation )
    else
      team_scores_hash = {}
      mir = @meeting.meeting_individual_results.is_valid
      mrr = @meeting.meeting_relay_results.is_valid
      mir.each { |ind_result|
        team_score = team_scores_hash[ ind_result.team_id ] || MeetingTeamScore.new( team_id: ind_result.team_id, meeting_id: @meeting.id )
        team_score.meeting_individual_points += ind_result.standard_points
        team_scores_hash[ ind_result.team_id ] = team_score
      }
      mrr.each { |relay_result|
        team_score = team_scores_hash[ relay_result.team_id ] || MeetingTeamScore.new( team_id: relay_result.team_id, meeting_id: @meeting.id )
        team_score.meeting_relay_points += relay_result.standard_points
        team_scores_hash[ relay_result.team_id ] = team_score
      }
      @meeting_team_scores = team_scores_hash.values
    end
    @meeting_team_scores = @meeting_team_scores.sort_by do |row|
      (row.meeting_individual_points + row.meeting_relay_points + row.meeting_team_points).to_i
    end.reverse
    @existing_team_bonus_sum = 0
    @meeting_team_scores.each_with_index{ |team_score, index|
      team_score.rank = index + 1
      @existing_team_bonus_sum += team_score.meeting_team_points
    }
    @max_updated_at = get_timestamp_from_relation_chain() 
  end
def show_ranking @preselected_team_id = params [ :team_id ] if ( @meeting . meeting_team_scores . exists? ) @meeting_team_scores = @meeting . meeting_team_scores . joins ( :team , :team_affiliation ) . includes ( :team , :team_affiliation ) else team_scores_hash = { } mir = @meeting . meeting_individual_results . is_valid mrr = @meeting . meeting_relay_results . is_valid mir . each { | ind_result | team_score = team_scores_hash [ ind_result . team_id ] || MeetingTeamScore . new ( team_id : ind_result . team_id , meeting_id : @meeting . id ) team_score . meeting_individual_points += ind_result . standard_points team_scores_hash [ ind_result . team_id ] = team_score } mrr . each { | relay_result | team_score = team_scores_hash [ relay_result . team_id ] || MeetingTeamScore . new ( team_id : relay_result . team_id , meeting_id : @meeting . id ) team_score . meeting_relay_points += relay_result . standard_points team_scores_hash [ relay_result . team_id ] = team_score } @meeting_team_scores = team_scores_hash . values end @meeting_team_scores = @meeting_team_scores . sort_by do | row | ( row . meeting_individual_points + row . meeting_relay_points + row . meeting_team_points ) . to_i end . reverse @existing_team_bonus_sum = 0 @meeting_team_scores . each_with_index { | team_score , index | team_score . rank = index + 1 @existing_team_bonus_sum += team_score . meeting_team_points } @max_updated_at = get_timestamp_from_relation_chain ( ) end
Show the ranking regarding a single Meeting
Assumes params[:id] refers to a specific Meeting row.
Show the ranking regarding a single Meeting Assumes params [ : id ] refers to a specific Meeting row .
# [Steve, 20131231] Cannot order via SQL since rank could be blank for CSI meetings #  (as in  .order('meeting_team_scores.rank')) # Sum all individual scores into each team score row: # Save the updated score into the collection Hash: # Sum all relay scores into each team score row: # Save the updated score into the collection Hash: # Collect the individual score rows and sort them: # Do the manual sorting of the array to assure a valorized ranking: # Finally, update ranking according to the sorted array: # Get a timestamp for the cache key: # default: MIR