Skip to content

Commit

Permalink
Merge eb82e07 into bd0ecad
Browse files Browse the repository at this point in the history
  • Loading branch information
amulyausem committed Oct 31, 2023
2 parents bd0ecad + eb82e07 commit 75faff7
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 40 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
28 changes: 14 additions & 14 deletions app/models/review_bid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ class ReviewBid < ApplicationRecord
# 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
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)
def 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
Expand All @@ -36,25 +36,25 @@ def self.assign_review_topics(assignment_id, reviewer_ids, matched_topics, _min_
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')
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
6 changes: 3 additions & 3 deletions spec/controllers/review_bids_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@
end
end

describe '#run_bidding_algorithm' do
describe '#assign_reviewers' do
render_views
it 'connects to the webservice to run bidding algorithm' do
post :run_bidding_algorithm
it 'connects to the webservice to assign reviewers' do
post :assign_reviewers
expect(response).to have_http_status(302)
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/helpers/review_bids_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@
end
end
end
describe '#get_topic_bg_color_review_bids' do
context 'when bid count is 0' do
it 'changes colour' do
allow(ReviewBid).to receive(:where).and_return([])
num_bids=0
expect(helper.get_topic_bg_color_review_bids(topic,2)).to eq("rgb(47,352,0)")
end
end
end
end
17 changes: 13 additions & 4 deletions spec/models/review_bid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,47 @@
end

describe '#bidding_data validation' do
before do
@review_bid = ReviewBid.new
end
it 'checks if get_bidding_data returns bidding_data as a hash' do
test_reviewers = [1]
allow(AssignmentParticipant).to receive(:find).with(1).and_return(participant)
allow(SignedUpTeam).to receive(:topic_id).and_return(1)
allow(ReviewBid).to receive(:where).and_return([bid1, bid2])
expect(ReviewBid.bidding_data(bid1.assignment_id, test_reviewers)).to eq('max_accepted_proposals' => nil, 'tid' => [], 'users' => { 1 => { 'otid' => 1, 'priority' => [3, 2], 'tid' => [123, 124], 'time' => ['2018-01-01 00:00:00.000000000 +0000', nil] } })
expect(@review_bid.bidding_data(bid1.assignment_id, test_reviewers)).to eq('max_accepted_proposals' => nil, 'tid' => [], 'users' => { 1 => { 'otid' => 1, 'priority' => [3, 2], 'tid' => [123, 124], 'time' => ['2018-01-01 00:00:00.000000000 +0000', nil] } })
end
end

describe '#assign_review_topics' do
before do
@review_bid = ReviewBid.new
end
it 'calls assigns_topics_to_reviewer for as many topics associated' do
maps = [response_map]
matched_topics = { '1' => [topic] }
allow(ReviewResponseMap).to receive(:where).and_return(maps)
allow(maps).to receive(:destroy_all).and_return(true)
expect(ReviewBid).to receive(:assign_topic_to_reviewer).with(1, 1, topic)
ReviewBid.assign_review_topics(1, [1], matched_topics)
@review_bid.assign_review_topics(1, [1], matched_topics)
end
end

describe '#assign_topic_to_reviewer' do
before do
@review_bid = ReviewBid.new
end
context 'when there are no SignUpTeam' do
it 'returns an empty array' do
allow(SignedUpTeam).to receive_message_chain(:where, :pluck, :first).and_return(nil)
expect(ReviewBid.assign_topic_to_reviewer(1, 1, topic)).to eq([])
expect(@review_bid.assign_topic_to_reviewer(1, 1, topic)).to eq([])
end
end
context 'when there is a team to review' do
it 'calls ReviewResponseMap' do
allow(SignedUpTeam).to receive_message_chain(:where, :pluck, :first).and_return(team1)
expect(ReviewResponseMap).to receive(:create)
ReviewBid.assign_topic_to_reviewer(1, 1, topic)
@review_bid.assign_topic_to_reviewer(1, 1, topic)
end
end
end
Expand Down

0 comments on commit 75faff7

Please sign in to comment.