app/controllers/lottery_controller.rb
# This method is to send request to web service and use k-means and students' bidding data to build teams automatically.
This method is to send request to web service and use k-means and students' bidding data to build teams automatically.
This method is to send request to web service and use k - means and students ' bidding data to build teams automatically .
def run_intelligent_assignment
    priority_info = []
    topic_ids = SignUpTopic.where(assignment_id: params[:id]).map(&:id)
    user_ids = Participant.where(parent_id: params[:id]).map(&:user_id)
    user_ids.each do |user_id|
      bids = []
      topic_ids.each do |topic_id|
        bid_record = Bid.where(user_id: user_id, topic_id: topic_id).first rescue nil
        bids << (bid_record.nil? ? 0 : bid_record.priority ||= 0)
      end
      priority_info << {pid: user_id, ranks: bids} if bids.uniq != [0]
    end
    assignment = Assignment.find_by(id: params[:id])
    data = {users: priority_info, max_team_size: assignment.max_team_size}
    url = WEBSERVICE_CONFIG["topic_bidding_webservice_url"]
    begin
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json
      teams = JSON.parse(response)["teams"]
      create_new_teams_for_bidding_response(teams, assignment)
      run_intelligent_bid
    rescue => err
      flash[:error] = err.message
    end
    redirect_to controller: 'tree_display', action: 'list'
  end
def run_intelligent_assignment priority_info = [ ] topic_ids = SignUpTopic . where ( assignment_id : params [ :id ] ) . map ( & :id ) user_ids = Participant . where ( parent_id : params [ :id ] ) . map ( & :user_id ) user_ids . each do | user_id | bids = [ ] topic_ids . each do | topic_id | bid_record = Bid . where ( user_id : user_id , topic_id : topic_id ) . first rescue nil bids << ( bid_record . nil? ? 0 : bid_record . priority ||= 0 ) end priority_info << { pid : user_id , ranks : bids } if bids . uniq != [ 0 ] end assignment = Assignment . find_by ( id : params [ :id ] ) data = { users : priority_info , max_team_size : assignment . max_team_size } url = WEBSERVICE_CONFIG [ "topic_bidding_webservice_url" ] begin response = RestClient . post url , data . to_json , content_type : :json , accept : :json teams = JSON . parse ( response ) [ "teams" ] create_new_teams_for_bidding_response ( teams , assignment ) run_intelligent_bid rescue => err flash [ :error ] = err . message end redirect_to controller : 'tree_display' , action : 'list' end
This method is to send request to web service and use k-means and students' bidding data to build teams automatically.
This method is to send request to web service and use k - means and students ' bidding data to build teams automatically .
# grab student id and list of bids # store each summary in a hashmap and use the question as the key