app/controllers/lottery_controller.rb
# This method is called to automerge smaller teams to teams which were assigned topics through intelligent assignment
This method is called to automerge smaller teams to teams which were assigned topics through intelligent assignment
This method is called to automerge smaller teams to teams which were assigned topics through intelligent assignment
def auto_merge_teams(unassigned_teams, _final_team_topics)
    assignment = Assignment.find(params[:id])
    unassigned_teams = Team.where(id: unassigned_teams).sort_by {|t| !t.users.size }
    unassigned_teams.each do |team|
      sorted_bids = Bid.where(user_id: team.id).sort_by(&:priority) 
      sorted_bids.each do |b|
        winning_team = SignedUpTeam.where(topic: b.topic_id).first.team_id
        next unless TeamsUser.where(team_id: winning_team).size + team.users.size <= assignment.max_team_size 
        TeamsUser.where(team_id: team.id).update_all(team_id: winning_team)
        Bid.delete_all(user_id: team.id)
        Team.delete(team.id)
        break
      end
    end
  end
def auto_merge_teams ( unassigned_teams , _final_team_topics ) assignment = Assignment . find ( params [ :id ] ) unassigned_teams = Team . where ( id : unassigned_teams ) . sort_by { | t | ! t . users . size } unassigned_teams . each do | team | sorted_bids = Bid . where ( user_id : team . id ) . sort_by ( & :priority ) sorted_bids . each do | b | winning_team = SignedUpTeam . where ( topic : b . topic_id ) . first . team_id next unless TeamsUser . where ( team_id : winning_team ) . size + team . users . size <= assignment . max_team_size TeamsUser . where ( team_id : team . id ) . update_all ( team_id : winning_team ) Bid . delete_all ( user_id : team . id ) Team . delete ( team . id ) break end end end
This method is called to automerge smaller teams to teams which were assigned topics through intelligent assignment
This method is called to automerge smaller teams to teams which were assigned topics through intelligent assignment
# Sort unassigned # Get priority for each unassignmed team # SignedUpTeam.where(:topic=>b.topic_id).first.team_id # If the team can be merged to a bigger team
unassigned_teams
_final_team_topics