app/controllers/lottery_controller.rb
# This method is called for assignments which have their is_intelligent property set to 1. It runs a stable match algorithm and assigns topics
# to strongest contenders (team strength, priority of bids)
This method is called for assignments which have their is_intelligent property set to 1. It runs a stable match algorithm and assigns topics
to strongest contenders (team strength, priority of bids)
This method is called for assignments which have their is_intelligent property set to 1 . It runs a stable match algorithm and assigns topics to strongest contenders ( team strength priority of bids )
def run_intelligent_bid
    unless Assignment.find_by(id: params[:id]).is_intelligent 
      flash[:error] = "This action not allowed. The assignment " + Assignment.find_by(id: params[:id]).name + " does not enabled intelligent assignments."
      redirect_to controller: 'tree_display', action: 'list'
      return
    end
    sign_up_topics = SignUpTopic.where("assignment_id = ? and max_choosers > 0", params[:id])
    unassigned_teams = AssignmentTeam.where(parent_id: params[:id]).reject {|t| !SignedUpTeam.where(team_id: t.id).empty? }
    unassigned_teams.sort! {|t1, t2| TeamsUser.where(team_id: t2.id).size <=> TeamsUser.where(team_id: t1.id).size }
    team_bids = []
    unassigned_teams.each do |team|
      topic_bids = []
      sign_up_topics.each do |topic|
        student_bids = []
        TeamsUser.where(team_id: team.id).each do |s|
          student_bid = Bid.where(user_id: s.user_id, topic_id: topic.id).first rescue nil
          if !student_bid.nil? and !student_bid.priority.nil?
            student_bids << student_bid.priority
          end
        end
        freq = student_bids.each_with_object(Hash.new(0)) do |v, h|
          h[v] += 1
        end
        topic_bids << {topic_id: topic.id, priority: student_bids.max_by {|v| freq[v] }} unless freq.empty?
      end
      topic_bids.sort! {|b| b[:priority] }
      team_bids << {team_id: team.id, bids: topic_bids}
    end
    team_bids.each do |tb|
      tb[:bids].each do |bid|
        signed_up_team = SignedUpTeam.where(topic_id: bid[:topic_id]).first rescue nil
        if signed_up_team.nil?
          SignedUpTeam.create(team_id: tb[:team_id], topic_id: bid[:topic_id])
          break
        end
      end
    end
    assignment = Assignment.find(params[:id])
    assignment.update_attribute(:is_intelligent, false)
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'
  end
def run_intelligent_bid unless Assignment . find_by ( id : params [ :id ] ) . is_intelligent flash [ :error ] = "This action not allowed. The assignment " + Assignment . find_by ( id : params [ :id ] ) . name + " does not enabled intelligent assignments." redirect_to controller : 'tree_display' , action : 'list' return end sign_up_topics = SignUpTopic . where ( "assignment_id = ? and max_choosers > 0" , params [ :id ] ) unassigned_teams = AssignmentTeam . where ( parent_id : params [ :id ] ) . reject { | t | ! SignedUpTeam . where ( team_id : t . id ) . empty? } unassigned_teams . sort! { | t1 , t2 | TeamsUser . where ( team_id : t2 . id ) . size <=> TeamsUser . where ( team_id : t1 . id ) . size } team_bids = [ ] unassigned_teams . each do | team | topic_bids = [ ] sign_up_topics . each do | topic | student_bids = [ ] TeamsUser . where ( team_id : team . id ) . each do | s | student_bid = Bid . where ( user_id : s . user_id , topic_id : topic . id ) . first rescue nil if ! student_bid . nil? and ! student_bid . priority . nil? student_bids << student_bid . priority end end freq = student_bids . each_with_object ( Hash . new ( 0 ) ) do | v , h | h [ v ] += 1 end topic_bids << { topic_id : topic . id , priority : student_bids . max_by { | v | freq [ v ] } } unless freq . empty? end topic_bids . sort! { | b | b [ :priority ] } team_bids << { team_id : team . id , bids : topic_bids } end team_bids . each do | tb | tb [ :bids ] . each do | bid | signed_up_team = SignedUpTeam . where ( topic_id : bid [ :topic_id ] ) . first rescue nil if signed_up_team . nil? SignedUpTeam . create ( team_id : tb [ :team_id ] , topic_id : bid [ :topic_id ] ) break end end end assignment = Assignment . find ( params [ :id ] ) assignment . update_attribute ( :is_intelligent , false ) flash [ :notice ] = 'The intelligent assignment was successfully completed for ' + assignment . name + '.' end
This method is called for assignments which have their is_intelligent property set to 1.
This method is called for assignments which have their is_intelligent property set to 1 .
# if the assignment is intelligent then redirect to the tree display list # Getting signuptopics with max_choosers > 0 # takes the most frequent priority as the team priority # auto_merge_teams unassignedTeams, finalTeamTopics # Remove is_intelligent property from assignment so that it can revert to the default signup state