Skip to content

Commit

Permalink
Merge c754c12 into bd0ecad
Browse files Browse the repository at this point in the history
  • Loading branch information
amulyausem committed Nov 7, 2023
2 parents bd0ecad + c754c12 commit 906f435
Show file tree
Hide file tree
Showing 10 changed files with 396 additions and 69 deletions.
32 changes: 23 additions & 9 deletions app/controllers/review_bids_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def show
@assigned_review_maps = []
ReviewResponseMap.where(reviewed_object_id: @assignment.id, reviewer_id: @participant.id).each do |review_map|
@assigned_review_maps << review_map
@count= ReviewBid.all.count
end

# explicitly render view since it's in the sign up sheet views
Expand Down Expand Up @@ -94,22 +95,35 @@ def set_priority

# assign bidding topics to reviewers
def assign_bidding
# sets parameters used for running bidding algorithm
assignment_id = params[:assignment_id].to_i
# list of reviewer id's from a specific assignment
reviewer_ids = AssignmentParticipant.where(parent_id: assignment_id).ids
bidding_data = ReviewBid.bidding_data(assignment_id, reviewer_ids)
matched_topics = run_bidding_algorithm(bidding_data)
ReviewBid.assign_review_topics(assignment_id, reviewer_ids, matched_topics)
Assignment.find(assignment_id).update(can_choose_topic_to_review: false) # turns off bidding for students
assignment = Assignment.find(params[:assignment_id])
reviewer_ids = AssignmentParticipant.where(parent_id: assignment.id).ids

if ReviewBid.where(assignment_id: assignment.id).empty?
# No bids - randomly assign
topics = SignUpTopic.where(assignment_id: assignment.id)
topics.each do |topic|
reviewer_id = reviewer_ids.sample
ReviewBid.create(assignment_id: assignment.id,
signuptopic_id: topic.id,
participant_id: reviewer_id)
end
else
@review_bid = ReviewBid.new
bidding_data = @review_bid.bidding_data(assignment_id, reviewer_ids)
matched_topics = assign_reviewers(bidding_data)
@review_bid.assign_review_topics(assignment_id, reviewer_ids, matched_topics)
end

Assignment.find(assignment_id).update(can_choose_topic_to_review: false)

redirect_back fallback_location: root_path
end

# call webserver for running assigning algorithm
# passing webserver: student_ids, topic_ids, student_preferences, time_stamps
# webserver returns:
# returns matched assignments as json body
def run_bidding_algorithm(bidding_data)
def assign_reviewers(bidding_data)
# begin
url = 'http://app-csc517.herokuapp.com/match_topics' # hard coding for the time being
response = RestClient.post url, bidding_data.to_json, content_type: 'application/json', accept: :json
Expand Down
52 changes: 30 additions & 22 deletions app/models/review_bid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,66 @@ class ReviewBid < ApplicationRecord
belongs_to :participant, class_name: 'Participant'
belongs_to :assignment, class_name: 'Assignment'

validates :signuptopic_id, presence: true
validates :participant_id, numericality: { only_integer: true }
# method to get bidding data
# returns the bidding data needed for the assigning algorithm
# student_ids, topic_ids, student_preferences, topic_preferences, max reviews allowed

def self.bidding_data(assignment_id, reviewer_ids)
def bidding_data(assignment_id, reviewer_ids)
# create basic hash and set basic hash data
bidding_data = { 'tid' => [], 'users' => {}, 'max_accepted_proposals' => [] }
bidding_data['tid'] = SignUpTopic.where(assignment_id: assignment_id).ids
bidding_data['max_accepted_proposals'] = Assignment.where(id: assignment_id).pluck(:num_reviews_allowed).first
bid_data = { 'tid' => [], 'users' => {}, 'max_accepted_proposals' => [] }
bid_data['tid'] = SignUpTopic.where(assignment_id: assignment_id).ids
bid_data['max_accepted_proposals'] = Assignment.where(id: assignment_id).pluck(:num_reviews_allowed).first

# loop through reviewer_ids to get reviewer specific bidding data
reviewer_ids.each do |reviewer_id|
bidding_data['users'][reviewer_id] = reviewer_bidding_data(reviewer_id, assignment_id)
bid_data['users'][reviewer_id] = reviewer_bidding_data(reviewer_id, assignment_id)
end
bidding_data
return [] if bid_data['tid'].nil?
return [] if bid_data['max_accepted_proposals'].nil?
bid_data
end

# assigns topics to reviews as matched by the webservice algorithm
def self.assign_review_topics(assignment_id, reviewer_ids, matched_topics, _min_num_reviews = 2)
# if review response map already created, delete it
if ReviewResponseMap.where(reviewed_object_id: assignment_id)
ReviewResponseMap.where(reviewed_object_id: assignment_id).destroy_all
end
# loop through reviewer_ids to assign reviews to each reviewer
def assign_review_topics(assignment_id, reviewer_ids, matched_topics, _min_num_reviews = 2)
ReviewResponseMap.where(reviewed_object_id: assignment_id).destroy_all

reviewer_ids.each do |reviewer_id|
topics_to_assign = matched_topics[reviewer_id.to_s]
topics_to_assign = matched_topics[reviewer_id.to_s] || []
next if topics_to_assign.empty? # Skip if no topics to assign

topics_to_assign.each do |topic|
assign_topic_to_reviewer(assignment_id, reviewer_id, topic)
end
end
end

# method to assign a single topic to a reviewer
def self.assign_topic_to_reviewer(assignment_id, reviewer_id, topic)
def assign_topic_to_reviewer(assignment_id, reviewer_id, topic)
team_to_review = SignedUpTeam.where(topic_id: topic).pluck(:team_id).first
team_to_review.nil? ? [] : ReviewResponseMap.create(reviewed_object_id: assignment_id, reviewer_id: reviewer_id, reviewee_id: team_to_review, type: 'ReviewResponseMap')
return [] if team_to_review.nil?

ReviewResponseMap.find_or_create_by(
reviewed_object_id: assignment_id,
reviewer_id: reviewer_id,
reviewee_id: team_to_review
) { |map| map.type = 'ReviewResponseMap' }
end

# method for getting individual reviewer_ids bidding data
# returns user's bidding data hash
def self.reviewer_bidding_data(reviewer_id, assignment_id)
def reviewer_bidding_data(reviewer_id, assignment_id)
reviewer_user_id = AssignmentParticipant.find(reviewer_id).user_id
self_topic = SignedUpTeam.topic_id(assignment_id, reviewer_user_id)
bidding_data = { 'tid' => [], 'otid' => self_topic, 'priority' => [], 'time' => [] }
bid_data = { 'tid' => [], 'otid' => self_topic, 'priority' => [], 'time' => [] }
bids = ReviewBid.where(participant_id: reviewer_id)

# loop through each bid for a topic to get specific data
bids.each do |bid|
bidding_data['tid'] << bid.signuptopic_id
bidding_data['priority'] << bid.priority
bidding_data['time'] << bid.updated_at
bid_data['tid'] << bid.signuptopic_id
bid_data['priority'] << bid.priority
bid_data['time'] << bid.updated_at
end
bidding_data
bid_data
end
end
4 changes: 2 additions & 2 deletions app/views/assignments/edit/_topics.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<%= label_tag('assignment_form[assignment][use_bookmark]', 'Allow participants to create bookmarks?') %>

<br>
<% if @assignment_form.assignment.can_choose_topic_to_review? == true %>

<input name="assignment_form[assignment][bidding_for_reviews_enabled]" type="hidden" value="false"/>
<%= check_box_tag(
'assignment_form[assignment][bidding_for_reviews_enabled]',
Expand All @@ -40,7 +40,7 @@
<% if @assignment_form.assignment.bidding_for_reviews_enabled %>
<%= button_to 'Run Review Algorithm', :controller=>'review_bids', :action=>'assign_bidding', :assignment_id => @assignment_form.assignment.id %>
<% end %>
<% end %>


<br><br>
<% if @assignment_form.assignment.staggered_deadline == true %>
Expand Down
11 changes: 4 additions & 7 deletions app/views/sign_up_sheet/review_bids_others_work.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@
<td>
<b><%= "#{title} #{review_no}." %></b>
<!--In ‘review_bids/index’ page, if the topic_identifier is empty, ‘:’ sign should not be displayed.-->
<% if !topic_id.nil? %>
<% if SignUpTopic.find(topic_id).topic_identifier != '' %>
<%= " #{SignUpTopic.find(topic_id).topic_identifier}: #{SignUpTopic.find(topic_id).topic_name}" %>
<% else %>
<%= " #{SignUpTopic.find(topic_id).topic_name}" %>
<% end %>
<% if !topic_id.nil? && SignUpTopic.find(topic_id).topic_identifier != '' %>
<%= " #{SignUpTopic.find(topic_id).topic_identifier}: #{SignUpTopic.find(topic_id).topic_name}" %>
<% elsif !topic_id.nil? %>
<%= " #{SignUpTopic.find(topic_id).topic_name}" %>
<% end %>
<%if !@assignment.is_anonymous%>
&nbsp; (author: <%= participant.fullname%>)
<%end%>
Expand Down
1 change: 1 addition & 0 deletions app/views/sign_up_sheet/review_bids_show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<h1>Bidding sheet for <%= @assignment.name %> reviews</h1>
<h2> Total number of bids made<%= @count %></h2>
<div style="display:block">
<h3 style="width: 40%; float: left">Topics</h3>
<h3 style="width: 40%; float:right">Review Bid Selections</h3>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
post :assign_bidding
post :set_priority
post :index
post :run_bidding_algorithm
post :assign_reviewers
get :show
end
end
Expand Down

0 comments on commit 906f435

Please sign in to comment.