<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bsingh8</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bsingh8"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Bsingh8"/>
	<updated>2026-05-21T14:49:53Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114889</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114889"/>
		<updated>2017-12-25T16:30:08Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Key Changes in Part B of the Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favours increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      D(i,j) = 1/N * &amp;amp;sum; [ M -U(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let U(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              E(i) = 1/U(i)&lt;br /&gt;
              Calculate D(i,j)                &lt;br /&gt;
              Weight(i,j) = E(i) / D(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the web service, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignment. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calculate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calculate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviewer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Re factoring the methods: The method that we are working on was very long. We will re factor it into several smaller methods of around 20 lines (altogether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common score list, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the score list belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from score list)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores corresponding to that topic from score list)&lt;br /&gt;
** Continue the above process until the score list is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readable. We divided it into several methods &lt;br /&gt;
&lt;br /&gt;
==== New Assignment Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
     add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Forming teams even for conference reviewers ====&lt;br /&gt;
* We decided to make Part A run even for conference reviewers. Thus, even reviewers can form teams. &lt;br /&gt;
* Files Changed: Lottery_controller.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Use of Conference_slot variable ====&lt;br /&gt;
While we defined some of our own variables when creating the new functionality, we also have used the conference_slots option to control the assignment of topics to reviewers. &lt;br /&gt;
* Code Changes : Given in the next sub section&lt;br /&gt;
&lt;br /&gt;
==== Balancing of Assignment of Topics to Reviewers ====&lt;br /&gt;
* This was discussed above&lt;br /&gt;
* Basically, in the case none/some of the teams have no preferences, then these teams should be assigned topics such that each topic has more or less the same number of reviewers assigned.&lt;br /&gt;
* There can be two cases in which this does not happen: more number of teams via-a-vis topics or vice versa.&lt;br /&gt;
* File Changed: lottery_controller.rb&lt;br /&gt;
* Code Changes:&lt;br /&gt;
&lt;br /&gt;
  #we are adjusting the max limit of teams with below formula so that topic assignments is done in a balancing way&lt;br /&gt;
    balanced_max_limit_of_teams = ((all_topics.length * assignment.max_reviews_per_submission) / teams.length.to_f).ceil&lt;br /&gt;
    balanced_max_limit_of_teams = [balanced_max_limit_of_teams , assignment.max_reviews_per_submission].min&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      #we are adjusting the max limit of topics with below formaula so that topic assignments is done in a balancing way&lt;br /&gt;
      balanced_max_limit_of_topics = ((teams.length * max_limit_of_topics[s.topic_id]) / all_topics.length.to_f).ceil&lt;br /&gt;
      balanced_max_limit_of_topics = [balanced_max_limit_of_topics , max_limit_of_topics[s.topic_id]].min&lt;br /&gt;
      if((incomplete_topics[s.topic_id]&amp;lt; (s.score &amp;lt; base ? max_limit_of_topics[s.topic_id] : balanced_max_limit_of_topics) ) &amp;amp;&amp;amp; (incomplete_teams[s.team_id]&amp;lt;  (s.score &amp;lt; base ? assignment.max_reviews_per_submission : balanced_max_limit_of_teams)   ))&lt;br /&gt;
        SignedUpTeam.create(team_id: s.team_id, topic_id: s.topic_id)&lt;br /&gt;
        incomplete_teams[s.team_id]+= 1&lt;br /&gt;
        incomplete_topics[s.topic_id]+= 1&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Use of Latest Expertiza Code Base ====&lt;br /&gt;
In the latest revision, we have used the latest expertiza code base for our project&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as an instructor&lt;br /&gt;
** Go to an Assignment&lt;br /&gt;
** Go to topics section, add few topics for the assignment. Later check the enable bidding checkbox button.&lt;br /&gt;
** Go to add participants page, add few student to the assignment.&lt;br /&gt;
** Now save the assignment.&lt;br /&gt;
** Login as student (who is a participant of the assignment)&lt;br /&gt;
** Go to the assignment page, then go to sign up sheet and bid for topics.&lt;br /&gt;
** Do the above the step for the participants.&lt;br /&gt;
** Login back to an instructor, go to manage assignments page, click on the run intelligent assignment button.&lt;br /&gt;
** Go to the topics tab in the assignment, here you will be able to view all the team's assignments to their topics.&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review : In this case all topics are assigned same bid score. Topics are assigned to users on the basis of &amp;quot;balanced assignment&amp;quot;, first come first serve.&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review: It will be first come, first serve.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of topics exceed the number of teams: Some topics may not be reviewed,depending on the limits put by the conference. It is responsibility of administrator to add more teams in such a situation&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114888</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114888"/>
		<updated>2017-12-25T16:29:08Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Use of Conference_slot variable */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favours increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      D(i,j) = 1/N * &amp;amp;sum; [ M -U(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let U(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              E(i) = 1/U(i)&lt;br /&gt;
              Calculate D(i,j)                &lt;br /&gt;
              Weight(i,j) = E(i) / D(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the web service, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignment. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calculate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calculate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviewer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Re factoring the methods: The method that we are working on was very long. We will re factor it into several smaller methods of around 20 lines (altogether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common score list, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the score list belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from score list)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores corresponding to that topic from score list)&lt;br /&gt;
** Continue the above process until the score list is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readable. We divided it into several methods &lt;br /&gt;
&lt;br /&gt;
==== New Assignment Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
     add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Forming teams even for conference reviewers ====&lt;br /&gt;
* We decided to make Part A run even for conference reviewers. Thus, even reviewers can form teams. &lt;br /&gt;
* Files Changed: Lottery_controller.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Use of Conference_slot variable ====&lt;br /&gt;
While we defined some of our own variables when creating the new functionality, we also have used the conference_slots option to control the assignment of topics to reviewers. &lt;br /&gt;
* Code Changes : Given in the next sub section&lt;br /&gt;
&lt;br /&gt;
==== Balancing of Assignment of Topics to Reviewers ====&lt;br /&gt;
* This was discussed above&lt;br /&gt;
* Basically, in the case none/some of the teams have no preferences, then these teams should be assigned topics such that each topic has more or less the same number of reviewers assigned.&lt;br /&gt;
* There can be two cases in which this does not happen: more number of teams via-a-vis topics or vice versa.&lt;br /&gt;
* File Changed: lottery_controller.rb&lt;br /&gt;
* Code Changes:&lt;br /&gt;
&lt;br /&gt;
  #we are adjusting the max limit of teams with below formula so that topic assignments is done in a balancing way&lt;br /&gt;
    balanced_max_limit_of_teams = ((all_topics.length * assignment.max_reviews_per_submission) / teams.length.to_f).ceil&lt;br /&gt;
    balanced_max_limit_of_teams = [balanced_max_limit_of_teams , assignment.max_reviews_per_submission].min&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      #we are adjusting the max limit of topics with below formaula so that topic assignments is done in a balancing way&lt;br /&gt;
      balanced_max_limit_of_topics = ((teams.length * max_limit_of_topics[s.topic_id]) / all_topics.length.to_f).ceil&lt;br /&gt;
      balanced_max_limit_of_topics = [balanced_max_limit_of_topics , max_limit_of_topics[s.topic_id]].min&lt;br /&gt;
      if((incomplete_topics[s.topic_id]&amp;lt; (s.score &amp;lt; base ? max_limit_of_topics[s.topic_id] : balanced_max_limit_of_topics) ) &amp;amp;&amp;amp; (incomplete_teams[s.team_id]&amp;lt;  (s.score &amp;lt; base ? assignment.max_reviews_per_submission : balanced_max_limit_of_teams)   ))&lt;br /&gt;
        SignedUpTeam.create(team_id: s.team_id, topic_id: s.topic_id)&lt;br /&gt;
        incomplete_teams[s.team_id]+= 1&lt;br /&gt;
        incomplete_topics[s.topic_id]+= 1&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Use of Latest Expertiza Code Base ====&lt;br /&gt;
In the latest revision, we have used the latest expertiza code base for our project&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as an instructor&lt;br /&gt;
** Go to an Assignment&lt;br /&gt;
** Go to topics section, add few topics for the assignment. Later check the enable bidding checkbox button.&lt;br /&gt;
** Go to add participants page, add few student to the assignment.&lt;br /&gt;
** Now save the assignment.&lt;br /&gt;
** Login as student (who is a participant of the assignment)&lt;br /&gt;
** Go to the assignment page, then go to sign up sheet and bid for topics.&lt;br /&gt;
** Do the above the step for the participants.&lt;br /&gt;
** Login back to an instructor, go to manage assignments page, click on the run intelligent assignment button.&lt;br /&gt;
** Go to the topics tab in the assignment, here you will be able to view all the team's assignments to their topics.&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review : In this case all topics are assigned same bid score. Topics are assigned to users on the basis of &amp;quot;balanced assignment&amp;quot;, first come first serve.&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review: It will be first come, first serve.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of topics exceed the number of teams: Some topics may not be reviewed,depending on the limits put by the conference. It is responsibility of administrator to add more teams in such a situation&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114887</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114887"/>
		<updated>2017-12-25T15:10:26Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favours increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      D(i,j) = 1/N * &amp;amp;sum; [ M -U(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let U(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              E(i) = 1/U(i)&lt;br /&gt;
              Calculate D(i,j)                &lt;br /&gt;
              Weight(i,j) = E(i) / D(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the web service, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignment. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calculate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calculate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviewer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Re factoring the methods: The method that we are working on was very long. We will re factor it into several smaller methods of around 20 lines (altogether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common score list, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the score list belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from score list)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores corresponding to that topic from score list)&lt;br /&gt;
** Continue the above process until the score list is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readable. We divided it into several methods &lt;br /&gt;
&lt;br /&gt;
==== New Assignment Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
     add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Forming teams even for conference reviewers ====&lt;br /&gt;
* We decided to make Part A run even for conference reviewers. Thus, even reviewers can form teams. &lt;br /&gt;
* Files Changed: Lottery_controller.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Use of Conference_slot variable ====&lt;br /&gt;
While we defined some of our own variables when creating the new functionality, we also have used the conference_slots option to control the assignment of topics to reviewers. &lt;br /&gt;
* Code Changes :&lt;br /&gt;
   all_topics.each do |topic|&lt;br /&gt;
      #getting the max limit of each topic into a hash map&lt;br /&gt;
      max_limit_of_topics.store(topic.id,topic.max_choosers)&lt;br /&gt;
      max_topics_for_assignment =max_topics_for_assignment + topic.max_choosers&lt;br /&gt;
    end&lt;br /&gt;
   #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      #Here we are checking whether max limit of the particular topic reached or not. if not we then assign a team to that topic. &lt;br /&gt;
      if((incomplete_topics[s.topic_id]&amp;lt;max_limit_of_topics[s.topic_id]) &amp;amp;&amp;amp; (incomplete_teams[s.team_id]&amp;lt;assignment.max_reviews_per_submission))&lt;br /&gt;
        SignedUpTeam.create(team_id: s.team_id, topic_id: s.topic_id)&lt;br /&gt;
        incomplete_teams[s.team_id]+= 1&lt;br /&gt;
        incomplete_topics[s.topic_id]+= 1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
==== Balancing of Assignment of Topics to Reviewers ====&lt;br /&gt;
* This was discussed above&lt;br /&gt;
* Basically, in the case none/some of the teams have no preferences, then these teams should be assigned topics such that each topic has more or less the same number of reviewers assigned.&lt;br /&gt;
* There can be two cases in which this does not happen: more number of teams via-a-vis topics or vice versa.&lt;br /&gt;
* File Changed: lottery_controller.rb&lt;br /&gt;
* Code Changes:&lt;br /&gt;
&lt;br /&gt;
  #we are adjusting the max limit of teams with below formula so that topic assignments is done in a balancing way&lt;br /&gt;
    balanced_max_limit_of_teams = ((all_topics.length * assignment.max_reviews_per_submission) / teams.length.to_f).ceil&lt;br /&gt;
    balanced_max_limit_of_teams = [balanced_max_limit_of_teams , assignment.max_reviews_per_submission].min&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      #we are adjusting the max limit of topics with below formaula so that topic assignments is done in a balancing way&lt;br /&gt;
      balanced_max_limit_of_topics = ((teams.length * max_limit_of_topics[s.topic_id]) / all_topics.length.to_f).ceil&lt;br /&gt;
      balanced_max_limit_of_topics = [balanced_max_limit_of_topics , max_limit_of_topics[s.topic_id]].min&lt;br /&gt;
      if((incomplete_topics[s.topic_id]&amp;lt; (s.score &amp;lt; base ? max_limit_of_topics[s.topic_id] : balanced_max_limit_of_topics) ) &amp;amp;&amp;amp; (incomplete_teams[s.team_id]&amp;lt;  (s.score &amp;lt; base ? assignment.max_reviews_per_submission : balanced_max_limit_of_teams)   ))&lt;br /&gt;
        SignedUpTeam.create(team_id: s.team_id, topic_id: s.topic_id)&lt;br /&gt;
        incomplete_teams[s.team_id]+= 1&lt;br /&gt;
        incomplete_topics[s.topic_id]+= 1&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Use of Latest Expertiza Code Base ====&lt;br /&gt;
In the latest revision, we have used the latest expertiza code base for our project&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as an instructor&lt;br /&gt;
** Go to an Assignment&lt;br /&gt;
** Go to topics section, add few topics for the assignment. Later check the enable bidding checkbox button.&lt;br /&gt;
** Go to add participants page, add few student to the assignment.&lt;br /&gt;
** Now save the assignment.&lt;br /&gt;
** Login as student (who is a participant of the assignment)&lt;br /&gt;
** Go to the assignment page, then go to sign up sheet and bid for topics.&lt;br /&gt;
** Do the above the step for the participants.&lt;br /&gt;
** Login back to an instructor, go to manage assignments page, click on the run intelligent assignment button.&lt;br /&gt;
** Go to the topics tab in the assignment, here you will be able to view all the team's assignments to their topics.&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review : In this case all topics are assigned same bid score. Topics are assigned to users on the basis of &amp;quot;balanced assignment&amp;quot;, first come first serve.&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review: It will be first come, first serve.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of topics exceed the number of teams: Some topics may not be reviewed,depending on the limits put by the conference. It is responsibility of administrator to add more teams in such a situation&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114886</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114886"/>
		<updated>2017-12-25T15:02:17Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Log: Key Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods &lt;br /&gt;
&lt;br /&gt;
==== New Assignemnt Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
     add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Forming teams even for conference reviewers ====&lt;br /&gt;
* We decided to make Part A run even for conference reviewers. Thus, even reviewers can form teams. &lt;br /&gt;
* Files Changed: Lottery_controller.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Use of Conference_slot variable ====&lt;br /&gt;
While we defined some of our own variables when creating the new functionality, we also have used the conference_slots option to control the assignment of topics to reviewers. &lt;br /&gt;
* Code Changes :&lt;br /&gt;
   all_topics.each do |topic|&lt;br /&gt;
      #getting the max limit of each topic into a hash map&lt;br /&gt;
      max_limit_of_topics.store(topic.id,topic.max_choosers)&lt;br /&gt;
      max_topics_for_assignment =max_topics_for_assignment + topic.max_choosers&lt;br /&gt;
    end&lt;br /&gt;
   #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      #Here we are checking whether max limit of the particular topic reached or not. if not we then assign a team to that topic. &lt;br /&gt;
      if((incomplete_topics[s.topic_id]&amp;lt;max_limit_of_topics[s.topic_id]) &amp;amp;&amp;amp; (incomplete_teams[s.team_id]&amp;lt;assignment.max_reviews_per_submission))&lt;br /&gt;
        SignedUpTeam.create(team_id: s.team_id, topic_id: s.topic_id)&lt;br /&gt;
        incomplete_teams[s.team_id]+= 1&lt;br /&gt;
        incomplete_topics[s.topic_id]+= 1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
==== Balancing of Assignment of Topics to Reviewers ====&lt;br /&gt;
* This was discussed above&lt;br /&gt;
* Basically, in the case none/some of the teams have no preferences, then these teams should be assinged topics such that each topic has more or less the same number of reviwers assigned.&lt;br /&gt;
* There can be two cases in which this does not happen: more number of teams vis-a-vis topics or vice versa.&lt;br /&gt;
* File Changed: lottery_controller.rb&lt;br /&gt;
* Code Changes:&lt;br /&gt;
&lt;br /&gt;
  #we are adjusting the max limit of teams with below formaula so that topic assignments is done in a balancing way&lt;br /&gt;
    balanced_max_limit_of_teams = ((all_topics.length * assignment.max_reviews_per_submission) / teams.length.to_f).ceil&lt;br /&gt;
    balanced_max_limit_of_teams = [balanced_max_limit_of_teams , assignment.max_reviews_per_submission].min&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      #we are adjusting the max limit of topics with below formaula so that topic assignments is done in a balancing way&lt;br /&gt;
      balanced_max_limit_of_topics = ((teams.length * max_limit_of_topics[s.topic_id]) / all_topics.length.to_f).ceil&lt;br /&gt;
      balanced_max_limit_of_topics = [balanced_max_limit_of_topics , max_limit_of_topics[s.topic_id]].min&lt;br /&gt;
      if((incomplete_topics[s.topic_id]&amp;lt; (s.score &amp;lt; base ? max_limit_of_topics[s.topic_id] : balanced_max_limit_of_topics) ) &amp;amp;&amp;amp; (incomplete_teams[s.team_id]&amp;lt;  (s.score &amp;lt; base ? assignment.max_reviews_per_submission : balanced_max_limit_of_teams)   ))&lt;br /&gt;
        SignedUpTeam.create(team_id: s.team_id, topic_id: s.topic_id)&lt;br /&gt;
        incomplete_teams[s.team_id]+= 1&lt;br /&gt;
        incomplete_topics[s.topic_id]+= 1&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Use of Latest Expertiza Code Base ====&lt;br /&gt;
In the latest revision, we have used the latest expertiza code base for our project&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as an instructor&lt;br /&gt;
** Go to an Assignment&lt;br /&gt;
** Go to topics section, add few topics for the assignment. Later check the enable bidding checkbox button.&lt;br /&gt;
** Go to add participants page, add few student to the assignment.&lt;br /&gt;
** Now save the assignment.&lt;br /&gt;
** Login as student (who is a participant of the assignment)&lt;br /&gt;
** Go to the assignment page, then go to sign up sheet and bid for topics.&lt;br /&gt;
** Do the above the step for the participants.&lt;br /&gt;
** Login back to an instructor, go to manage assignments page, click on the run intelligent assignment button.&lt;br /&gt;
** Go to the topics tab in the assignment, here you will be able to view all the team's assignments to their topics.&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114885</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114885"/>
		<updated>2017-12-25T15:00:58Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Log: Key Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.  &lt;br /&gt;
&lt;br /&gt;
==== New Assignemnt Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
     add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Forming teams even for conference reviewers ====&lt;br /&gt;
* We decided to make Part A run even for conference reviewers. Thus, even reviewers can form teams. &lt;br /&gt;
* Files Changed: Lottery_controller.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Use of Conference_slot variable ====&lt;br /&gt;
While we defined some of our own variables when creating the new functionality, we also have used the conference_slots option to control the assignment of topics to reviewers. &lt;br /&gt;
* Code Changes :&lt;br /&gt;
   all_topics.each do |topic|&lt;br /&gt;
      #getting the max limit of each topic into a hash map&lt;br /&gt;
      max_limit_of_topics.store(topic.id,topic.max_choosers)&lt;br /&gt;
      max_topics_for_assignment =max_topics_for_assignment + topic.max_choosers&lt;br /&gt;
    end&lt;br /&gt;
   #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      #Here we are checking whether max limit of the particular topic reached or not. if not we then assign a team to that topic. &lt;br /&gt;
      if((incomplete_topics[s.topic_id]&amp;lt;max_limit_of_topics[s.topic_id]) &amp;amp;&amp;amp; (incomplete_teams[s.team_id]&amp;lt;assignment.max_reviews_per_submission))&lt;br /&gt;
        SignedUpTeam.create(team_id: s.team_id, topic_id: s.topic_id)&lt;br /&gt;
        incomplete_teams[s.team_id]+= 1&lt;br /&gt;
        incomplete_topics[s.topic_id]+= 1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
==== Balancing of Assignment of Topics to Reviewers ====&lt;br /&gt;
* This was discussed above&lt;br /&gt;
* Basically, in the case none/some of the teams have no preferences, then these teams should be assinged topics such that each topic has more or less the same number of reviwers assigned.&lt;br /&gt;
* There can be two cases in which this does not happen: more number of teams vis-a-vis topics or vice versa.&lt;br /&gt;
* File Changed: lottery_controller.rb&lt;br /&gt;
* Code Changes:&lt;br /&gt;
&lt;br /&gt;
  #we are adjusting the max limit of teams with below formaula so that topic assignments is done in a balancing way&lt;br /&gt;
    balanced_max_limit_of_teams = ((all_topics.length * assignment.max_reviews_per_submission) / teams.length.to_f).ceil&lt;br /&gt;
    balanced_max_limit_of_teams = [balanced_max_limit_of_teams , assignment.max_reviews_per_submission].min&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      #we are adjusting the max limit of topics with below formaula so that topic assignments is done in a balancing way&lt;br /&gt;
      balanced_max_limit_of_topics = ((teams.length * max_limit_of_topics[s.topic_id]) / all_topics.length.to_f).ceil&lt;br /&gt;
      balanced_max_limit_of_topics = [balanced_max_limit_of_topics , max_limit_of_topics[s.topic_id]].min&lt;br /&gt;
      if((incomplete_topics[s.topic_id]&amp;lt; (s.score &amp;lt; base ? max_limit_of_topics[s.topic_id] : balanced_max_limit_of_topics) ) &amp;amp;&amp;amp; (incomplete_teams[s.team_id]&amp;lt;  (s.score &amp;lt; base ? assignment.max_reviews_per_submission : balanced_max_limit_of_teams)   ))&lt;br /&gt;
        SignedUpTeam.create(team_id: s.team_id, topic_id: s.topic_id)&lt;br /&gt;
        incomplete_teams[s.team_id]+= 1&lt;br /&gt;
        incomplete_topics[s.topic_id]+= 1&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Use of Latest Expertiza Code Base ====&lt;br /&gt;
In the latest revision, we have used the latest expertiza code base for our project&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as an instructor&lt;br /&gt;
** Go to an Assignment&lt;br /&gt;
** Go to topics section, add few topics for the assignment. Later check the enable bidding checkbox button.&lt;br /&gt;
** Go to add participants page, add few student to the assignment.&lt;br /&gt;
** Now save the assignment.&lt;br /&gt;
** Login as student (who is a participant of the assignment)&lt;br /&gt;
** Go to the assignment page, then go to sign up sheet and bid for topics.&lt;br /&gt;
** Do the above the step for the participants.&lt;br /&gt;
** Login back to an instructor, go to manage assignments page, click on the run intelligent assignment button.&lt;br /&gt;
** Go to the topics tab in the assignment, here you will be able to view all the team's assignments to their topics.&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114884</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114884"/>
		<updated>2017-12-25T14:59:57Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Use of Conference_slot variable */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.  &lt;br /&gt;
&lt;br /&gt;
==== New Assignemnt Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
     add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Forming teams even for conference reviewers ====&lt;br /&gt;
* We decided to make Part A run even for conference reviewers. Thus, even reviewers can form teams. &lt;br /&gt;
* Files Changed: Lottery_controller.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Use of Conference_slot variable ====&lt;br /&gt;
While we defined some of our own variables when creating the new functionality, we also have used the conference_slots option to control the assignment of topics to reviewers. &lt;br /&gt;
* Code Changes :&lt;br /&gt;
   all_topics.each do |topic|&lt;br /&gt;
      #getting the max limit of each topic into a hash map&lt;br /&gt;
      max_limit_of_topics.store(topic.id,topic.max_choosers)&lt;br /&gt;
      max_topics_for_assignment =max_topics_for_assignment + topic.max_choosers&lt;br /&gt;
    end&lt;br /&gt;
   #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      #Here we are checking whether max limit of the particular topic reached or not. if not we then assign a team to that topic. &lt;br /&gt;
      if((incomplete_topics[s.topic_id]&amp;lt;max_limit_of_topics[s.topic_id]) &amp;amp;&amp;amp; (incomplete_teams[s.team_id]&amp;lt;assignment.max_reviews_per_submission))&lt;br /&gt;
        SignedUpTeam.create(team_id: s.team_id, topic_id: s.topic_id)&lt;br /&gt;
        incomplete_teams[s.team_id]+= 1&lt;br /&gt;
        incomplete_topics[s.topic_id]+= 1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
==== Balancing of Assignment of Topics to Reviewers ====&lt;br /&gt;
* This was discussed above&lt;br /&gt;
* Basically, in the case none/some of the teams have no preferences, then these teams should be assinged topics such that each topic has more or less the same number of reviwers assigned.&lt;br /&gt;
* There can be two cases in which this does not happen: more number of teams vis-a-vis topics or vice versa.&lt;br /&gt;
* File Changed: lottery_controller.rb&lt;br /&gt;
* Code Changes:&lt;br /&gt;
&lt;br /&gt;
  #we are adjusting the max limit of teams with below formaula so that topic assignments is done in a balancing way&lt;br /&gt;
    balanced_max_limit_of_teams = ((all_topics.length * assignment.max_reviews_per_submission) / teams.length.to_f).ceil&lt;br /&gt;
    balanced_max_limit_of_teams = [balanced_max_limit_of_teams , assignment.max_reviews_per_submission].min&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      #we are adjusting the max limit of topics with below formaula so that topic assignments is done in a balancing way&lt;br /&gt;
      balanced_max_limit_of_topics = ((teams.length * max_limit_of_topics[s.topic_id]) / all_topics.length.to_f).ceil&lt;br /&gt;
      balanced_max_limit_of_topics = [balanced_max_limit_of_topics , max_limit_of_topics[s.topic_id]].min&lt;br /&gt;
      if((incomplete_topics[s.topic_id]&amp;lt; (s.score &amp;lt; base ? max_limit_of_topics[s.topic_id] : balanced_max_limit_of_topics) ) &amp;amp;&amp;amp; (incomplete_teams[s.team_id]&amp;lt;  (s.score &amp;lt; base ? assignment.max_reviews_per_submission : balanced_max_limit_of_teams)   ))&lt;br /&gt;
        SignedUpTeam.create(team_id: s.team_id, topic_id: s.topic_id)&lt;br /&gt;
        incomplete_teams[s.team_id]+= 1&lt;br /&gt;
        incomplete_topics[s.topic_id]+= 1&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as an instructor&lt;br /&gt;
** Go to an Assignment&lt;br /&gt;
** Go to topics section, add few topics for the assignment. Later check the enable bidding checkbox button.&lt;br /&gt;
** Go to add participants page, add few student to the assignment.&lt;br /&gt;
** Now save the assignment.&lt;br /&gt;
** Login as student (who is a participant of the assignment)&lt;br /&gt;
** Go to the assignment page, then go to sign up sheet and bid for topics.&lt;br /&gt;
** Do the above the step for the participants.&lt;br /&gt;
** Login back to an instructor, go to manage assignments page, click on the run intelligent assignment button.&lt;br /&gt;
** Go to the topics tab in the assignment, here you will be able to view all the team's assignments to their topics.&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114883</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114883"/>
		<updated>2017-12-25T14:59:37Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Log: Key Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.  &lt;br /&gt;
&lt;br /&gt;
==== New Assignemnt Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
     add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Forming teams even for conference reviewers ====&lt;br /&gt;
* We decided to make Part A run even for conference reviewers. Thus, even reviewers can form teams. &lt;br /&gt;
* Files Changed: Lottery_controller.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Use of Conference_slot variable ====&lt;br /&gt;
While we defined some of our own variables when creating the new functionality, we also have used the conference_slots option to control the assignment of topics to reviewers. &lt;br /&gt;
* Code Changes :&lt;br /&gt;
   all_topics.each do |topic|&lt;br /&gt;
      #getting the max limit of each topic into a hash map&lt;br /&gt;
      max_limit_of_topics.store(topic.id,topic.max_choosers)&lt;br /&gt;
      max_topics_for_assignment =max_topics_for_assignment + topic.max_choosers&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
   #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      #Here we are checking whether max limit of the particular topic reached or not. if not we then assign a team to that topic. &lt;br /&gt;
      if((incomplete_topics[s.topic_id]&amp;lt;max_limit_of_topics[s.topic_id]) &amp;amp;&amp;amp; (incomplete_teams[s.team_id]&amp;lt;assignment.max_reviews_per_submission))&lt;br /&gt;
        SignedUpTeam.create(team_id: s.team_id, topic_id: s.topic_id)&lt;br /&gt;
        incomplete_teams[s.team_id]+= 1&lt;br /&gt;
        incomplete_topics[s.topic_id]+= 1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
==== Balancing of Assignment of Topics to Reviewers ====&lt;br /&gt;
* This was discussed above&lt;br /&gt;
* Basically, in the case none/some of the teams have no preferences, then these teams should be assinged topics such that each topic has more or less the same number of reviwers assigned.&lt;br /&gt;
* There can be two cases in which this does not happen: more number of teams vis-a-vis topics or vice versa.&lt;br /&gt;
* File Changed: lottery_controller.rb&lt;br /&gt;
* Code Changes:&lt;br /&gt;
&lt;br /&gt;
  #we are adjusting the max limit of teams with below formaula so that topic assignments is done in a balancing way&lt;br /&gt;
    balanced_max_limit_of_teams = ((all_topics.length * assignment.max_reviews_per_submission) / teams.length.to_f).ceil&lt;br /&gt;
    balanced_max_limit_of_teams = [balanced_max_limit_of_teams , assignment.max_reviews_per_submission].min&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      #we are adjusting the max limit of topics with below formaula so that topic assignments is done in a balancing way&lt;br /&gt;
      balanced_max_limit_of_topics = ((teams.length * max_limit_of_topics[s.topic_id]) / all_topics.length.to_f).ceil&lt;br /&gt;
      balanced_max_limit_of_topics = [balanced_max_limit_of_topics , max_limit_of_topics[s.topic_id]].min&lt;br /&gt;
      if((incomplete_topics[s.topic_id]&amp;lt; (s.score &amp;lt; base ? max_limit_of_topics[s.topic_id] : balanced_max_limit_of_topics) ) &amp;amp;&amp;amp; (incomplete_teams[s.team_id]&amp;lt;  (s.score &amp;lt; base ? assignment.max_reviews_per_submission : balanced_max_limit_of_teams)   ))&lt;br /&gt;
        SignedUpTeam.create(team_id: s.team_id, topic_id: s.topic_id)&lt;br /&gt;
        incomplete_teams[s.team_id]+= 1&lt;br /&gt;
        incomplete_topics[s.topic_id]+= 1&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as an instructor&lt;br /&gt;
** Go to an Assignment&lt;br /&gt;
** Go to topics section, add few topics for the assignment. Later check the enable bidding checkbox button.&lt;br /&gt;
** Go to add participants page, add few student to the assignment.&lt;br /&gt;
** Now save the assignment.&lt;br /&gt;
** Login as student (who is a participant of the assignment)&lt;br /&gt;
** Go to the assignment page, then go to sign up sheet and bid for topics.&lt;br /&gt;
** Do the above the step for the participants.&lt;br /&gt;
** Login back to an instructor, go to manage assignments page, click on the run intelligent assignment button.&lt;br /&gt;
** Go to the topics tab in the assignment, here you will be able to view all the team's assignments to their topics.&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114882</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114882"/>
		<updated>2017-12-25T08:15:10Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Log: Key Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.  &lt;br /&gt;
&lt;br /&gt;
==== New Assignemnt Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
     add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Forming teams even for conference reviewers ====&lt;br /&gt;
* We decided to make Part A run even for conference reviewers. Thus, even reviewers can form teams. &lt;br /&gt;
* Files Changed: Lottery_controller.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
==== Use of Conference_slot variable ====&lt;br /&gt;
While we defined some of our own variables when creating the new functionality, we also have used the conference_slots option to control the assignment of topics to reviewers. &lt;br /&gt;
* Code Changes :&lt;br /&gt;
   all_topics.each do |topic|&lt;br /&gt;
      #getting the max limit of each topic into a hash map&lt;br /&gt;
      max_limit_of_topics.store(topic.id,topic.max_choosers)&lt;br /&gt;
      max_topics_for_assignment =max_topics_for_assignment + topic.max_choosers&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
   #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      #Here we are checking whether max limit of the particular topic reached or not. if not we then assign a team to that topic. &lt;br /&gt;
      if((incomplete_topics[s.topic_id]&amp;lt;max_limit_of_topics[s.topic_id]) &amp;amp;&amp;amp; (incomplete_teams[s.team_id]&amp;lt;assignment.max_reviews_per_submission))&lt;br /&gt;
        SignedUpTeam.create(team_id: s.team_id, topic_id: s.topic_id)&lt;br /&gt;
        incomplete_teams[s.team_id]+= 1&lt;br /&gt;
        incomplete_topics[s.topic_id]+= 1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as an instructor&lt;br /&gt;
** Go to an Assignment&lt;br /&gt;
** Go to topics section, add few topics for the assignment. Later check the enable bidding checkbox button.&lt;br /&gt;
** Go to add participants page, add few student to the assignment.&lt;br /&gt;
** Now save the assignment.&lt;br /&gt;
** Login as student (who is a participant of the assignment)&lt;br /&gt;
** Go to the assignment page, then go to sign up sheet and bid for topics.&lt;br /&gt;
** Do the above the step for the participants.&lt;br /&gt;
** Login back to an instructor, go to manage assignments page, click on the run intelligent assignment button.&lt;br /&gt;
** Go to the topics tab in the assignment, here you will be able to view all the team's assignments to their topics.&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114878</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114878"/>
		<updated>2017-12-25T08:05:56Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Log: Key Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.  &lt;br /&gt;
&lt;br /&gt;
==== New Assignemnt Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
     add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Forming teams even for conference reviewers ====&lt;br /&gt;
* We decided to make Part A run even for conference reviewers. Thus, even reviewers can form teams. &lt;br /&gt;
* Files Changed: Lottery_controller.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
**** Use of Conference_slot variable ****&lt;br /&gt;
While we defined some of our own variables when creating the new functionality, we also have used the conference_slots option to control the assignment of topics to reviewers. &lt;br /&gt;
* Code Changes : &lt;br /&gt;
&lt;br /&gt;
****&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as an instructor&lt;br /&gt;
** Go to an Assignment&lt;br /&gt;
** Go to topics section, add few topics for the assignment. Later check the enable bidding checkbox button.&lt;br /&gt;
** Go to add participants page, add few student to the assignment.&lt;br /&gt;
** Now save the assignment.&lt;br /&gt;
** Login as student (who is a participant of the assignment)&lt;br /&gt;
** Go to the assignment page, then go to sign up sheet and bid for topics.&lt;br /&gt;
** Do the above the step for the participants.&lt;br /&gt;
** Login back to an instructor, go to manage assignments page, click on the run intelligent assignment button.&lt;br /&gt;
** Go to the topics tab in the assignment, here you will be able to view all the team's assignments to their topics.&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114876</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114876"/>
		<updated>2017-12-25T08:03:17Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Log: Key Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.  &lt;br /&gt;
&lt;br /&gt;
==== New Assignemnt Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
     add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Forming teams even for conference reviewers ====&lt;br /&gt;
* We decided to make Part A run even for conference reviewers. Thus, even reviewers can form teams. &lt;br /&gt;
* Files Changed: Lottery_controller.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114875</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114875"/>
		<updated>2017-12-25T08:02:27Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Log: Key Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
==== New Assignemnt Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
     add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Forming teams even for conference reviewers ====&lt;br /&gt;
* We decided to make Part A run even for conference reviewers. Thus, even reviewers can form teams. &lt;br /&gt;
* Files Changed: Lottery_controller.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114874</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114874"/>
		<updated>2017-12-25T08:01:32Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Log: Key Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
==== New Assignemnt Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
     add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== Forming teams even for conference reviewers ====&lt;br /&gt;
* We decided to make Part A run even for conference reviewers. Thus, even reviewers can form teams. &lt;br /&gt;
* Files Changed: Lottery_controller.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114873</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114873"/>
		<updated>2017-12-25T07:59:17Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Log: Key Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== New Assignemnt Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
     add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114872</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114872"/>
		<updated>2017-12-25T07:58:48Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Log: Key Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
==== New Assignemnt Type ====&lt;br /&gt;
* We realize that we must create the conference &amp;quot;assignment&amp;quot; to be compatible with the whole of Expertiza, and it must be different from a course assignment. To do this, we create a new column &amp;quot;is_conference?&amp;quot; in the assignment table &lt;br /&gt;
* This variable is boolean, and if true, then it means the assignment is a conference assignment&lt;br /&gt;
* We created a migration for the same&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
 class AddIsConferenceToAssginment &amp;lt; ActiveRecord::Migration&lt;br /&gt;
  def change&lt;br /&gt;
		add_column :assignments, :is_conference?, :boolean , default: false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114871</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114871"/>
		<updated>2017-12-25T07:55:31Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* New Bid Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** When all the reviewers submit their preferences.&lt;br /&gt;
** When there are no preferences from any user.&lt;br /&gt;
** When few have their preferences and few don't.&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114869</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114869"/>
		<updated>2017-12-25T07:55:07Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* New Bid Object Model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114868</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114868"/>
		<updated>2017-12-25T07:54:50Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Log: Key Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114867</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114867"/>
		<updated>2017-12-25T07:54:04Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Log: Key Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.&lt;br /&gt;
&lt;br /&gt;
==== New Bid Object Model ====&lt;br /&gt;
Following the design methodology, we defined a new model to store the &amp;quot;scorelist&amp;quot; of bids along with the topics and the team ids. &lt;br /&gt;
&lt;br /&gt;
* Files created: bid_score.rb&lt;br /&gt;
* Code: &lt;br /&gt;
&lt;br /&gt;
  class BidScore&lt;br /&gt;
  include ActiveModel::Validations&lt;br /&gt;
  include ActiveModel::Conversion&lt;br /&gt;
  extend ActiveModel::Naming&lt;br /&gt;
&lt;br /&gt;
  attr_accessor :score, :team_id, :topic_id&lt;br /&gt;
  validates_presence_of :name, :team_id, :topic_id&lt;br /&gt;
# Since the toics assignment is done by sorting of scores, this object keeps track of every bid: score, topic and team&lt;br /&gt;
  def initialize(score,teamId,topicId)&lt;br /&gt;
    @score = score&lt;br /&gt;
    @team_id = teamId&lt;br /&gt;
    @topic_id = topicId&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def persisted?&lt;br /&gt;
    false&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114866</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114866"/>
		<updated>2017-12-25T07:50:22Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Method Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.&lt;br /&gt;
&lt;br /&gt;
==== Balanced Assignemnt of Topics ====&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114865</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114865"/>
		<updated>2017-12-25T07:49:55Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Changing Existing Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Log: Key Changes ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. We discuss these changes in the following sub sections:  &lt;br /&gt;
&lt;br /&gt;
==== Method Refactoring ==== &lt;br /&gt;
* Files Changed: lottery_controller.rb&lt;br /&gt;
* Description of Change: Earlier the lottery_controller.rb consisted of one method of 50 lines, which is not readible. We divided it into several methods, as shown below: &lt;br /&gt;
&lt;br /&gt;
def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
    # store each summary in a hashmap and use the question as the key&lt;br /&gt;
    teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
    create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
    if !assignment.is_conference?&lt;br /&gt;
      begin&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid assignment&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
* As can be seen, not all methods are shown. However, the new methods size is more or less the same size.&lt;br /&gt;
&lt;br /&gt;
==== Balanced Assignemnt of Topics ====&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114864</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114864"/>
		<updated>2017-12-25T07:41:55Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Key Changes in Part B of the Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
    n4 = R&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate m1 = floor (n1 * n3 / n2)&lt;br /&gt;
* Calcuate m2 = floor (n2 * n4 / n1)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , m1) topics, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one reviwer should not be assigned more then P topics, and each topic should not get more then the minimum of (R , m2) reviewers, provided that the score of the bid is lesser then the base score&lt;br /&gt;
* When the bid score is greater then the base score, then the normal test conditions apply&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. &lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114863</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114863"/>
		<updated>2017-12-25T06:27:53Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Changing Existing Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate n = floor (n1 * n3 / n2)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , n) topics.&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
We extended the code for bidding in the lottery controller, made a separate type of assignment in the database using a new column &amp;quot;is_conference?&amp;quot;. In addition, a new bid object model was also defined. &lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114862</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114862"/>
		<updated>2017-12-25T01:14:50Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Key Changes in Part B of the Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate n = floor (n1 * n3 / n2)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , n) topics.&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
== Design Methodology ==&lt;br /&gt;
The design methodologies that we will use while writing the code is discussed here. &lt;br /&gt;
&lt;br /&gt;
* We will implement this new algorithm such that the code is DRY&lt;br /&gt;
* Use of naming conventions: To define the new variable to differentiate between project and conference topics as is_conference?&lt;br /&gt;
* Refactoring the methods: The method that we are working on was very long. We will refactor it into several smaller methods of around 20 lines (altoghether, these new smaller methods should be visible on a screen as a whole)&lt;br /&gt;
* No hard coding of the data assignments&lt;br /&gt;
* Use of new database objects if required&lt;br /&gt;
* To understand and to use existing database column values, even in the case they are not used in the situation as of now. We have to implement this with the entry conference_slots&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This subsection details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114861</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114861"/>
		<updated>2017-12-25T01:05:33Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
== Key Changes in Part B of the Design ==&lt;br /&gt;
In the 2 part design proposed in the above section, there were major changes in part B. These are discussed below:&lt;br /&gt;
&lt;br /&gt;
====Proposed Score Calculation Algorithm====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate n = floor (n1 * n3 / n2)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , n) topics.&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
==== Methodology ====&lt;br /&gt;
We will implement this new algorithm such that the code is DRY, proper naming conventions are used&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This subsection details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114860</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114860"/>
		<updated>2017-12-25T01:03:38Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Assignment of Topics in Part B */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores of Part B====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics in Part B====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
        where the meanings of R and P are as above&lt;br /&gt;
&lt;br /&gt;
* Then calcucate n = floor (n1 * n3 / n2)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , n) topics.&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
==== Methodology ====&lt;br /&gt;
We will implement this new algorithm such that the code is DRY, proper naming conventions are used&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This subsection details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114859</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114859"/>
		<updated>2017-12-25T01:02:51Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Meaning of the Scores of Part B */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores of Part B====&lt;br /&gt;
* As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
&lt;br /&gt;
==== Assignment of Topics in Part B====&lt;br /&gt;
* All scores are arranged in ascending order. &lt;br /&gt;
* For the following values:&lt;br /&gt;
&lt;br /&gt;
    n1 = total number of teams&lt;br /&gt;
    n2 = total number of topics&lt;br /&gt;
    n3 = P&lt;br /&gt;
* Then calucate n = floor (n1 * n3 / n2)&lt;br /&gt;
* The topics are assigned on the basis of this order of scores, with the restriction that one topic should not be assigned to more then R reviewers, and each reviewer should not get more then the minimum of (P , n) topics.&lt;br /&gt;
* This last modification is done for the balancing of assignment of topics in the case no team has submitted a preference list. In this case, this change tries to ensure that every topic is assigned in such a way that there are more or less equal number of reviewers reviewing each topic.&lt;br /&gt;
&lt;br /&gt;
==== Methodology ====&lt;br /&gt;
We will implement this new algorithm such that the code is DRY, proper naming conventions are used&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This subsection details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114858</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114858"/>
		<updated>2017-12-25T00:55:06Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Meaning of the Scores of Part B====&lt;br /&gt;
As we can see, each user gets a separate score for each topic there is to bid for. The scores are assigned on the basis of the preference list submitted. &lt;br /&gt;
* Two users can get identical scores only when their preference list is identical. Even if user 2 has all topics of user 1 except the last one in the same order as user 1, still all topics of both users get different scores.&lt;br /&gt;
* All scores are arranged in ascending order. The topics are assinged on the basis of this order of scores, with the restriction that one topic should not be assigned to more then P reviewers, and each reviewer should not get more then T topics.&lt;br /&gt;
&lt;br /&gt;
==== Methodology ====&lt;br /&gt;
We will implement this new algorithm such that the code is DRY, proper naming conventions are used&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This subsection details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114857</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114857"/>
		<updated>2017-12-25T00:48:13Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M (M is a positive number)&lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 0 items and a maximum of L items, to allot items to teams such that each team gets at most P items and each item (to be bid on) is assigned to at most R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M &amp;gt;= 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = 1 / (num/den + B)&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = 1 / B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = 1/ (B - num/den)&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Methodology ====&lt;br /&gt;
We will implement this new algorithm such that the code is DRY, proper naming conventions are used&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This subsection details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114856</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114856"/>
		<updated>2017-12-25T00:44:00Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Existing Algorithm */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 0 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = num/den + B&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = B - num/den&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Methodology ====&lt;br /&gt;
We will implement this new algorithm such that the code is DRY, proper naming conventions are used&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This subsection details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114855</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114855"/>
		<updated>2017-12-25T00:43:16Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Project Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
* To ensure that the topic assignment algorithm assigns topics in a balanced manner in the case no reviewer has bid for any topic&lt;br /&gt;
* To develop a variable name in the database so as to distinguish between a project topic and a reviewer topic&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = num/den + B&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = B - num/den&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Methodology ====&lt;br /&gt;
We will implement this new algorithm such that the code is DRY, proper naming conventions are used&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This subsection details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114854</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114854"/>
		<updated>2017-12-25T00:39:03Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support a conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the functionality for bidding for topics is present though only for specific situations. The bidding ability is only for bidding for a topic for (teams of) students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is responsible for the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers can be individual or team based&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = num/den + B&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = B - num/den&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Methodology ====&lt;br /&gt;
We will implement this new algorithm such that the code is DRY, proper naming conventions are used&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This subsection details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114773</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114773"/>
		<updated>2017-12-13T16:26:28Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Project Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifically, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is a software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then post a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in a team) with close preferences are assigned to a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams, the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section, we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment) and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also, the second requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are allocated to teams such that each team gets a unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user, not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X-axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully, more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = num/den + B&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = B - num/den&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Methodology ====&lt;br /&gt;
We will implement this new algorithm such that the code is DRY, proper naming conventions are used&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving topic and participant information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics and bid====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding Algorithm====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Display assigned paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes in bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline, all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algorithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process until the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This subsection details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for the bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference for each user, and append it to priority information list. Afterward, it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as shown below:&lt;br /&gt;
The update involves the use of the existing assignment bidding tables since the UI and table entries specific to conference paper bidding has not been created and is out of scope for this project.&lt;br /&gt;
&lt;br /&gt;
Proposal: Allow the instructor to choose whether is it a topic assignment bid or conference paper bid via an update of a flag variable from the UI. For example, the is_assignment variable is used to indicate if it is an assignment bidding. If not the flag is set to false and assumes it is a conference bid. This enables the reuse of existing precondition variables and table entries. The bidding is run by calculating the weighted scores for each team's bidding priority of all the topics. Score calculation is done as explained in the Design section.&lt;br /&gt;
&lt;br /&gt;
Upon score calculation, the topics are used to populate the singed_up table for the corresponding teams and topic id. The resulting assigned topics can be viewed through the sing up sheet view by each participant. Each topic can be assigned to multiple teams as denoted by the max_per_topic variable. A hash map is used to keep track of how many times the same topic has been assigned to a team. Hence we are able to restrict the number of times the same paper/topic can be reviewed.&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    incomplete_teams = Hash.new(0)&lt;br /&gt;
    incomplete_topics = Hash.new(0)&lt;br /&gt;
    all_topics=[]&lt;br /&gt;
    all_topics = assignment.sign_up_topics&lt;br /&gt;
    score_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    sorted_list=Array.new(teams.length*all_topics.length){Array.new(3)}&lt;br /&gt;
    temp=[]&lt;br /&gt;
    base = 10&lt;br /&gt;
    p = 0&lt;br /&gt;
    #looping through each team to calculate score for each topic in the assignment&lt;br /&gt;
    teams.each do |t|&lt;br /&gt;
      incomplete_teams.store(t.id,0)&lt;br /&gt;
      team_bids = Bid.where(team_id: t.id)&lt;br /&gt;
      denom = 0&lt;br /&gt;
      b_length = team_bids.length&lt;br /&gt;
      (1..b_length).each do |i|&lt;br /&gt;
        denom = denom+all_topics.length - i&lt;br /&gt;
      end&lt;br /&gt;
      #Score calculation based on bid priority&lt;br /&gt;
      all_topics.each do |j|&lt;br /&gt;
        if(team_bids.any?{|tb| tb.topic_id == j.id})&lt;br /&gt;
          bid_priority = Bid.where(team_id:t.id,topic_id:j.id).first.priority&lt;br /&gt;
          score = base+((all_topics.length+1-bid_priority)*base*all_topics.length) / denom&lt;br /&gt;
        elsif(team_bids.length!=0)&lt;br /&gt;
          score = base-(base*all_topics.length)/denom&lt;br /&gt;
        else&lt;br /&gt;
          score = base&lt;br /&gt;
        end&lt;br /&gt;
        score_list[p][0] = score&lt;br /&gt;
        score_list[p][1] = t.id&lt;br /&gt;
        score_list[p][2] = j.id&lt;br /&gt;
        p+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    sorted_list = score_list.sort_by{|e| [e[0],e[1],e[2]]}.each{|line| p line}&lt;br /&gt;
    sorted_list.reverse!&lt;br /&gt;
    all_topics.each do |k|&lt;br /&gt;
      incomplete_topics.store(k.id,0)&lt;br /&gt;
    end&lt;br /&gt;
    if(all_topics.length*team_per_topic&amp;lt;teams.length)&lt;br /&gt;
      flash[:error] = 'There are not enough reviews to be assigned'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    #Assigning topics to teams based on highest score&lt;br /&gt;
    sorted_list.each do |s|&lt;br /&gt;
      if((incomplete_topics[s[2]]&amp;lt;team_per_topic) &amp;amp;&amp;amp; (incomplete_teams[s[1]]&amp;lt;topic_per_team))&lt;br /&gt;
        SignedUpTeam.create(team_id: s[1], topic_id: s[2])&lt;br /&gt;
        incomplete_teams[s[1]]+=1&lt;br /&gt;
        incomplete_topics[s[2]]+=1&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    assignment.update_attribute(:is_intelligent,false)&lt;br /&gt;
    flash[:notice] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
* No UI has been created been created for the conference paper review bidding. Hence assignment bidding controller is used to manually test the code on a local host to determine the feasibility of code.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance, we will do Rspec test in cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is matched first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many teams with same first preference and assigning many teams with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create an object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submit exactly the same list of topics to review.&lt;br /&gt;
&lt;br /&gt;
* Case 3: Number of teams exceed the number of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114085</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114085"/>
		<updated>2017-12-01T21:20:19Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Data Flow Diagram */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We explain in the terms of the actors: Reviewer and Administrator&lt;br /&gt;
* Before the deadline all the reviewers have to submit preference list of papers. They can save, modify list as many times as they want, but they can submit once&lt;br /&gt;
* This information is saved in the database&lt;br /&gt;
* When the deadline is passed, stop accepting preference lists&lt;br /&gt;
* The administrator runs the paper assignment algroithm&lt;br /&gt;
** For every topic, calculate the score for each user&lt;br /&gt;
** Make a common scorelist, which keeps score assigned to every topic of every user. There should be a way to find out the topic and user a particular element of the scorelist belongs to&lt;br /&gt;
** Now start assigning topics according to highest score&lt;br /&gt;
** Keep track of the number of topics assigned to each user and the number of users assigned to each topic&lt;br /&gt;
** If the number of topics assigned to one user reaches the maximum value, remove that user from consideration (remove all scores corresponding to that user from scorelist)&lt;br /&gt;
** If the number of users assigned to one topic reaches the maximum value, remove that topic from consideration (remove all scores correspoinding to that topic from scorelist)&lt;br /&gt;
** Continue the above process till the scorelist is empty&lt;br /&gt;
* Save the bidding into the database&lt;br /&gt;
* Inform users about the results of the bidding&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = num/den + B&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = B - num/den&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Methodology ====&lt;br /&gt;
We will implement this new algorithm such that the code is DRY, proper naming conventions are used&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114057</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114057"/>
		<updated>2017-12-01T18:32:11Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Methodology */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = num/den + B&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = B - num/den&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Methodology ====&lt;br /&gt;
We will implement this new algorithm such that the code is DRY, proper naming conventions are used&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114056</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114056"/>
		<updated>2017-12-01T18:31:57Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = num/den + B&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = B - num/den&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
==== Methodology ====&lt;br /&gt;
We will implement this new algorithm such that the code is DRY, propere naming conventions are used&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114055</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114055"/>
		<updated>2017-12-01T18:30:57Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = num/den + B&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = B - num/den&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
** Log in as a participants/student&lt;br /&gt;
** Go to Assignment&lt;br /&gt;
** Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
** Click submit and wait for bidding deadline&lt;br /&gt;
** After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114054</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114054"/>
		<updated>2017-12-01T18:29:21Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Additional Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = num/den + B&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = B - num/den&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114053</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114053"/>
		<updated>2017-12-01T18:28:56Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Changing Existing Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = num/den + B&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = B - num/den&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
== Additional Changes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With this change, we will have to add a new function: run_conference_bid(teams, assignment), with pseudo-code as shown below:&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    set topic_set to false;&lt;br /&gt;
    for each team in teams&lt;br /&gt;
      append the team in team_list&lt;br /&gt;
      retrieve bidding ranks of each team&lt;br /&gt;
      sum all rank values in list&lt;br /&gt;
      for each topic priority/rank value in ranks list&lt;br /&gt;
        if topic_set is false&lt;br /&gt;
           append topic_id to topic_list&lt;br /&gt;
        end if&lt;br /&gt;
        calculate percentage of the rank value in comparison to sum of rank values &lt;br /&gt;
        if sum is 0 &lt;br /&gt;
          change percentage to 1/length_of_rank_list&lt;br /&gt;
        end if&lt;br /&gt;
        score rank value by doing (percent_rank_values *(number_of_topics^2) + (number_of_topics^2) / length_of_rank_list)&lt;br /&gt;
        append [team_id, score] to team_scores dictionary with team_id as key&lt;br /&gt;
      end for&lt;br /&gt;
      set topic_set to true&lt;br /&gt;
    end for&lt;br /&gt;
    sort team_scores dictionary by values/scores in descending order&lt;br /&gt;
    for score in team_scores&lt;br /&gt;
      if team not in team_list or topic not in topic_list&lt;br /&gt;
        remove score&lt;br /&gt;
        continue to next iteration&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id to topic_assignment list&lt;br /&gt;
      if number of occurrences of current topic in topic_assignment is same as topic_per_team&lt;br /&gt;
        remove this topic_id from topic_list&lt;br /&gt;
      end if&lt;br /&gt;
      append team_id to team_assignment list&lt;br /&gt;
      if number of occurrences of current team in team_assignment is same as team_per_topic&lt;br /&gt;
        remove this team_id from team_list&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id and team_id pair to team_bids&lt;br /&gt;
    end for&lt;br /&gt;
    save sign up information stored in team_bids to database&lt;br /&gt;
  end def&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114052</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114052"/>
		<updated>2017-12-01T18:27:34Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = (N + 1 - r) * B * N&lt;br /&gt;
              score[topic][user] = num/den + B&lt;br /&gt;
         if(user has preferred no topic)&lt;br /&gt;
              score[topic][user] = B&lt;br /&gt;
         if(user has not preferred this topic)&lt;br /&gt;
              num = B * N&lt;br /&gt;
              score[topic][user] = B - num/den&lt;br /&gt;
&lt;br /&gt;
Now find_den =  &amp;amp;sum; [ N + 1 ] - &amp;amp;sum; [k] where the iterating variable k varies from 1 to t&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Changes ===&lt;br /&gt;
&lt;br /&gt;
To accommodate this code to fit our needs, we have proposed to add 3 new variable&lt;br /&gt;
&lt;br /&gt;
  bidding_for_reviews?&lt;br /&gt;
  topic_per_team&lt;br /&gt;
  team_per_topic&lt;br /&gt;
&lt;br /&gt;
new_intelligent_property will check if an assignment is using conference paper bidding or team assignment bidding, it will be true if bidding is on conference paper review and false if bidding is on team assignment; topic_per_team will record required number of topics that can be chosen per a team; and team_per_topic will record required number of teams that can be assigned to a topic.&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      if new_intelligent_property&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids }&lt;br /&gt;
      else&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if !new_intelligent_property&lt;br /&gt;
      data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
      url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
      begin&lt;br /&gt;
        response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
        # store each summary in a hashmap and use the question as the key&lt;br /&gt;
        teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
        create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid(teams, assignment, topic_per_team, team_per_topic)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Additional Changes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With this change, we will have to add a new function: run_conference_bid(teams, assignment), with pseudo-code as shown below:&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    set topic_set to false;&lt;br /&gt;
    for each team in teams&lt;br /&gt;
      append the team in team_list&lt;br /&gt;
      retrieve bidding ranks of each team&lt;br /&gt;
      sum all rank values in list&lt;br /&gt;
      for each topic priority/rank value in ranks list&lt;br /&gt;
        if topic_set is false&lt;br /&gt;
           append topic_id to topic_list&lt;br /&gt;
        end if&lt;br /&gt;
        calculate percentage of the rank value in comparison to sum of rank values &lt;br /&gt;
        if sum is 0 &lt;br /&gt;
          change percentage to 1/length_of_rank_list&lt;br /&gt;
        end if&lt;br /&gt;
        score rank value by doing (percent_rank_values *(number_of_topics^2) + (number_of_topics^2) / length_of_rank_list)&lt;br /&gt;
        append [team_id, score] to team_scores dictionary with team_id as key&lt;br /&gt;
      end for&lt;br /&gt;
      set topic_set to true&lt;br /&gt;
    end for&lt;br /&gt;
    sort team_scores dictionary by values/scores in descending order&lt;br /&gt;
    for score in team_scores&lt;br /&gt;
      if team not in team_list or topic not in topic_list&lt;br /&gt;
        remove score&lt;br /&gt;
        continue to next iteration&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id to topic_assignment list&lt;br /&gt;
      if number of occurrences of current topic in topic_assignment is same as topic_per_team&lt;br /&gt;
        remove this topic_id from topic_list&lt;br /&gt;
      end if&lt;br /&gt;
      append team_id to team_assignment list&lt;br /&gt;
      if number of occurrences of current team in team_assignment is same as team_per_topic&lt;br /&gt;
        remove this team_id from team_list&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id and team_id pair to team_bids&lt;br /&gt;
    end for&lt;br /&gt;
    save sign up information stored in team_bids to database&lt;br /&gt;
  end def&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114051</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114051"/>
		<updated>2017-12-01T18:21:33Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
====Proposed Algorithm for Part B====&lt;br /&gt;
Let N = Number of topics&lt;br /&gt;
    B = Base score&lt;br /&gt;
    t = Total number of topics an user prefers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For every topic i:&lt;br /&gt;
     den = find_den&lt;br /&gt;
     for every user j:&lt;br /&gt;
         if(user has preferred this topic)&lt;br /&gt;
              r = priority(topic)&lt;br /&gt;
              num = find_num&lt;br /&gt;
              score[topic][user] = num/den&lt;br /&gt;
&lt;br /&gt;
Now den =&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Changes ===&lt;br /&gt;
&lt;br /&gt;
To accommodate this code to fit our needs, we have proposed to add 3 new variable&lt;br /&gt;
&lt;br /&gt;
  bidding_for_reviews?&lt;br /&gt;
  topic_per_team&lt;br /&gt;
  team_per_topic&lt;br /&gt;
&lt;br /&gt;
new_intelligent_property will check if an assignment is using conference paper bidding or team assignment bidding, it will be true if bidding is on conference paper review and false if bidding is on team assignment; topic_per_team will record required number of topics that can be chosen per a team; and team_per_topic will record required number of teams that can be assigned to a topic.&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      if new_intelligent_property&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids }&lt;br /&gt;
      else&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if !new_intelligent_property&lt;br /&gt;
      data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
      url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
      begin&lt;br /&gt;
        response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
        # store each summary in a hashmap and use the question as the key&lt;br /&gt;
        teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
        create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid(teams, assignment, topic_per_team, team_per_topic)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Additional Changes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With this change, we will have to add a new function: run_conference_bid(teams, assignment), with pseudo-code as shown below:&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    set topic_set to false;&lt;br /&gt;
    for each team in teams&lt;br /&gt;
      append the team in team_list&lt;br /&gt;
      retrieve bidding ranks of each team&lt;br /&gt;
      sum all rank values in list&lt;br /&gt;
      for each topic priority/rank value in ranks list&lt;br /&gt;
        if topic_set is false&lt;br /&gt;
           append topic_id to topic_list&lt;br /&gt;
        end if&lt;br /&gt;
        calculate percentage of the rank value in comparison to sum of rank values &lt;br /&gt;
        if sum is 0 &lt;br /&gt;
          change percentage to 1/length_of_rank_list&lt;br /&gt;
        end if&lt;br /&gt;
        score rank value by doing (percent_rank_values *(number_of_topics^2) + (number_of_topics^2) / length_of_rank_list)&lt;br /&gt;
        append [team_id, score] to team_scores dictionary with team_id as key&lt;br /&gt;
      end for&lt;br /&gt;
      set topic_set to true&lt;br /&gt;
    end for&lt;br /&gt;
    sort team_scores dictionary by values/scores in descending order&lt;br /&gt;
    for score in team_scores&lt;br /&gt;
      if team not in team_list or topic not in topic_list&lt;br /&gt;
        remove score&lt;br /&gt;
        continue to next iteration&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id to topic_assignment list&lt;br /&gt;
      if number of occurrences of current topic in topic_assignment is same as topic_per_team&lt;br /&gt;
        remove this topic_id from topic_list&lt;br /&gt;
      end if&lt;br /&gt;
      append team_id to team_assignment list&lt;br /&gt;
      if number of occurrences of current team in team_assignment is same as team_per_topic&lt;br /&gt;
        remove this team_id from team_list&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id and team_id pair to team_bids&lt;br /&gt;
    end for&lt;br /&gt;
    save sign up information stored in team_bids to database&lt;br /&gt;
  end def&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114050</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114050"/>
		<updated>2017-12-01T18:16:40Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Proposed Design====&lt;br /&gt;
Keeping the existing algorithm and the project requirements in mind, we decided to divide the code into 2 parts:&lt;br /&gt;
* Part A: Make teams for people not in a team (and if applicable, complete incomplete teams)&lt;br /&gt;
* Part B: Assign topics to teams&lt;br /&gt;
&lt;br /&gt;
We note that Part A has been implemented on a web service independent of Expertiza. We also note that the algorithm explained above applies only to Part A, and that it is pretty sophisticated. Hence we choose to keep the existing code as is for this part. We will simply call the webservice, provide the list of people, their bidding preference and also the max_team_size.&lt;br /&gt;
&lt;br /&gt;
Part B is implemented as one line. It is pretty simple. We also note that it simply cannot be used for conference paper review assignemnt. Hence we completely change this section and implement it using a new algorithm. &lt;br /&gt;
&lt;br /&gt;
In addition since the existing algorithm is partly running on a web-service we cannot directly modify, it will be difficult to modify the code for the conference requirements and later integrate the two.&lt;br /&gt;
&lt;br /&gt;
However, with the new requirements, in addition we need to add completely new code.&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Changes ===&lt;br /&gt;
&lt;br /&gt;
To accommodate this code to fit our needs, we have proposed to add 3 new variable&lt;br /&gt;
&lt;br /&gt;
  bidding_for_reviews?&lt;br /&gt;
  topic_per_team&lt;br /&gt;
  team_per_topic&lt;br /&gt;
&lt;br /&gt;
new_intelligent_property will check if an assignment is using conference paper bidding or team assignment bidding, it will be true if bidding is on conference paper review and false if bidding is on team assignment; topic_per_team will record required number of topics that can be chosen per a team; and team_per_topic will record required number of teams that can be assigned to a topic.&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      if new_intelligent_property&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids }&lt;br /&gt;
      else&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if !new_intelligent_property&lt;br /&gt;
      data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
      url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
      begin&lt;br /&gt;
        response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
        # store each summary in a hashmap and use the question as the key&lt;br /&gt;
        teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
        create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid(teams, assignment, topic_per_team, team_per_topic)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Additional Changes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With this change, we will have to add a new function: run_conference_bid(teams, assignment), with pseudo-code as shown below:&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    set topic_set to false;&lt;br /&gt;
    for each team in teams&lt;br /&gt;
      append the team in team_list&lt;br /&gt;
      retrieve bidding ranks of each team&lt;br /&gt;
      sum all rank values in list&lt;br /&gt;
      for each topic priority/rank value in ranks list&lt;br /&gt;
        if topic_set is false&lt;br /&gt;
           append topic_id to topic_list&lt;br /&gt;
        end if&lt;br /&gt;
        calculate percentage of the rank value in comparison to sum of rank values &lt;br /&gt;
        if sum is 0 &lt;br /&gt;
          change percentage to 1/length_of_rank_list&lt;br /&gt;
        end if&lt;br /&gt;
        score rank value by doing (percent_rank_values *(number_of_topics^2) + (number_of_topics^2) / length_of_rank_list)&lt;br /&gt;
        append [team_id, score] to team_scores dictionary with team_id as key&lt;br /&gt;
      end for&lt;br /&gt;
      set topic_set to true&lt;br /&gt;
    end for&lt;br /&gt;
    sort team_scores dictionary by values/scores in descending order&lt;br /&gt;
    for score in team_scores&lt;br /&gt;
      if team not in team_list or topic not in topic_list&lt;br /&gt;
        remove score&lt;br /&gt;
        continue to next iteration&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id to topic_assignment list&lt;br /&gt;
      if number of occurrences of current topic in topic_assignment is same as topic_per_team&lt;br /&gt;
        remove this topic_id from topic_list&lt;br /&gt;
      end if&lt;br /&gt;
      append team_id to team_assignment list&lt;br /&gt;
      if number of occurrences of current team in team_assignment is same as team_per_topic&lt;br /&gt;
        remove this team_id from team_list&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id and team_id pair to team_bids&lt;br /&gt;
    end for&lt;br /&gt;
    save sign up information stored in team_bids to database&lt;br /&gt;
  end def&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114049</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114049"/>
		<updated>2017-12-01T18:09:37Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====The Combined Problem====&lt;br /&gt;
The combined problem statement is as follows: Given a list of people (students or reviewers) and also a list of N items to bid on (project topics or conference paper reviews), we require the following: &lt;br /&gt;
* To form teams of Maximum size M &lt;br /&gt;
* Based on preference lists submitted by people/teams having a minimum of 1 item and a maximum of L topics, to allot topics to teams such that each team gets P items and each item (to be bid on) is assigned to R teams. &lt;br /&gt;
&lt;br /&gt;
==== Points of Discussion====&lt;br /&gt;
&lt;br /&gt;
We note the differences:&lt;br /&gt;
* For Bidding for Assignment Topics, M is generally greater then 1, but P = 1 and R = 1. The item to be bid on is the project topics.&lt;br /&gt;
* For Bidding for Conference Paper Reviews, M = 1 but P and R are generally greater then 1. The item to be bid on is the conference paper reviews.&lt;br /&gt;
&lt;br /&gt;
We note that a team of 1 person makes little sense, but we still implement it to be so that the code is compatible for both the applications.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Subsequent Discussion===&lt;br /&gt;
Because the two situations are similar, it was hoped that the conference bidding would call the code of the (existing) assignment bidding. It was also hoped that the conference bidding would be modified to make it more general.&lt;br /&gt;
&lt;br /&gt;
However, in a subsequent meeting with the mentor, it was found that the two bidding algorithms are incompatible.  The existing algorithm will not work for conference bidding are:&lt;br /&gt;
* Team based versus Individual based: The existing algoritm is designed to assign topics to teams, whereas we have to assign topics to individuals&lt;br /&gt;
* The current bidding implementation only returns one bidding result (per graph) each time, whereas expected bidding implementation must be able to return multiple bidding results every time.&lt;br /&gt;
* In the case of a priority tie, the current bidding algorithm assigns topic to bidding team that has most members whom have worked together in the past. This will not work for a conference bidding since now there is no collaboration in conference paper review.&lt;br /&gt;
&lt;br /&gt;
In addition since the existing algorithm is partly running on a web-service we cannot directly modify, it will be difficult to modify the code for the conference requirements and later integrate the two.&lt;br /&gt;
&lt;br /&gt;
However, with the new requirements, in addition we need to add completely new code.&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Changes ===&lt;br /&gt;
&lt;br /&gt;
To accommodate this code to fit our needs, we have proposed to add 3 new variable&lt;br /&gt;
&lt;br /&gt;
  bidding_for_reviews?&lt;br /&gt;
  topic_per_team&lt;br /&gt;
  team_per_topic&lt;br /&gt;
&lt;br /&gt;
new_intelligent_property will check if an assignment is using conference paper bidding or team assignment bidding, it will be true if bidding is on conference paper review and false if bidding is on team assignment; topic_per_team will record required number of topics that can be chosen per a team; and team_per_topic will record required number of teams that can be assigned to a topic.&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      if new_intelligent_property&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids }&lt;br /&gt;
      else&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if !new_intelligent_property&lt;br /&gt;
      data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
      url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
      begin&lt;br /&gt;
        response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
        # store each summary in a hashmap and use the question as the key&lt;br /&gt;
        teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
        create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid(teams, assignment, topic_per_team, team_per_topic)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Additional Changes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With this change, we will have to add a new function: run_conference_bid(teams, assignment), with pseudo-code as shown below:&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    set topic_set to false;&lt;br /&gt;
    for each team in teams&lt;br /&gt;
      append the team in team_list&lt;br /&gt;
      retrieve bidding ranks of each team&lt;br /&gt;
      sum all rank values in list&lt;br /&gt;
      for each topic priority/rank value in ranks list&lt;br /&gt;
        if topic_set is false&lt;br /&gt;
           append topic_id to topic_list&lt;br /&gt;
        end if&lt;br /&gt;
        calculate percentage of the rank value in comparison to sum of rank values &lt;br /&gt;
        if sum is 0 &lt;br /&gt;
          change percentage to 1/length_of_rank_list&lt;br /&gt;
        end if&lt;br /&gt;
        score rank value by doing (percent_rank_values *(number_of_topics^2) + (number_of_topics^2) / length_of_rank_list)&lt;br /&gt;
        append [team_id, score] to team_scores dictionary with team_id as key&lt;br /&gt;
      end for&lt;br /&gt;
      set topic_set to true&lt;br /&gt;
    end for&lt;br /&gt;
    sort team_scores dictionary by values/scores in descending order&lt;br /&gt;
    for score in team_scores&lt;br /&gt;
      if team not in team_list or topic not in topic_list&lt;br /&gt;
        remove score&lt;br /&gt;
        continue to next iteration&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id to topic_assignment list&lt;br /&gt;
      if number of occurrences of current topic in topic_assignment is same as topic_per_team&lt;br /&gt;
        remove this topic_id from topic_list&lt;br /&gt;
      end if&lt;br /&gt;
      append team_id to team_assignment list&lt;br /&gt;
      if number of occurrences of current team in team_assignment is same as team_per_topic&lt;br /&gt;
        remove this team_id from team_list&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id and team_id pair to team_bids&lt;br /&gt;
    end for&lt;br /&gt;
    save sign up information stored in team_bids to database&lt;br /&gt;
  end def&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114048</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114048"/>
		<updated>2017-12-01T17:58:19Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Design */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
== Design ==&lt;br /&gt;
In the following subsections, we discuss the problem, proposed design and code. We are trying to combine the code so that it can be used for both the project topic bidding as well as the conference paper review bidding.&lt;br /&gt;
&lt;br /&gt;
====Understanding the Combined Problem====&lt;br /&gt;
* Objects (being bid on) are often assigned by having the bidders providing a preference list of bids. &lt;br /&gt;
** Expertiza provides a way for students to bid on different assignment topics. This allows the fair topic assignment distribution among students, particularly when multiple students or groups (of students) are bidding on same topic or paper. &lt;br /&gt;
**This is very similar to the kind of bidding that a conference implements for reviewers (who bid for proposed papers)&lt;br /&gt;
* The other requirements are extending the above idea to get new features or an improved algorithm. We discuss these in more detail below. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Subsequent Discussion===&lt;br /&gt;
Because the two situations are similar, it was hoped that the conference bidding would call the code of the (existing) assignment bidding. It was also hoped that the conference bidding would be modified to make it more general.&lt;br /&gt;
&lt;br /&gt;
However, in a subsequent meeting with the mentor, it was found that the two bidding algorithms are incompatible.  The existing algorithm will not work for conference bidding are:&lt;br /&gt;
* Team based versus Individual based: The existing algoritm is designed to assign topics to teams, whereas we have to assign topics to individuals&lt;br /&gt;
* The current bidding implementation only returns one bidding result (per graph) each time, whereas expected bidding implementation must be able to return multiple bidding results every time.&lt;br /&gt;
* In the case of a priority tie, the current bidding algorithm assigns topic to bidding team that has most members whom have worked together in the past. This will not work for a conference bidding since now there is no collaboration in conference paper review.&lt;br /&gt;
&lt;br /&gt;
In addition since the existing algorithm is partly running on a web-service we cannot directly modify, it will be difficult to modify the code for the conference requirements and later integrate the two.&lt;br /&gt;
&lt;br /&gt;
However, with the new requirements, in addition we need to add completely new code.&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Changes ===&lt;br /&gt;
&lt;br /&gt;
To accommodate this code to fit our needs, we have proposed to add 3 new variable&lt;br /&gt;
&lt;br /&gt;
  bidding_for_reviews?&lt;br /&gt;
  topic_per_team&lt;br /&gt;
  team_per_topic&lt;br /&gt;
&lt;br /&gt;
new_intelligent_property will check if an assignment is using conference paper bidding or team assignment bidding, it will be true if bidding is on conference paper review and false if bidding is on team assignment; topic_per_team will record required number of topics that can be chosen per a team; and team_per_topic will record required number of teams that can be assigned to a topic.&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      if new_intelligent_property&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids }&lt;br /&gt;
      else&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if !new_intelligent_property&lt;br /&gt;
      data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
      url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
      begin&lt;br /&gt;
        response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
        # store each summary in a hashmap and use the question as the key&lt;br /&gt;
        teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
        create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid(teams, assignment, topic_per_team, team_per_topic)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Additional Changes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With this change, we will have to add a new function: run_conference_bid(teams, assignment), with pseudo-code as shown below:&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    set topic_set to false;&lt;br /&gt;
    for each team in teams&lt;br /&gt;
      append the team in team_list&lt;br /&gt;
      retrieve bidding ranks of each team&lt;br /&gt;
      sum all rank values in list&lt;br /&gt;
      for each topic priority/rank value in ranks list&lt;br /&gt;
        if topic_set is false&lt;br /&gt;
           append topic_id to topic_list&lt;br /&gt;
        end if&lt;br /&gt;
        calculate percentage of the rank value in comparison to sum of rank values &lt;br /&gt;
        if sum is 0 &lt;br /&gt;
          change percentage to 1/length_of_rank_list&lt;br /&gt;
        end if&lt;br /&gt;
        score rank value by doing (percent_rank_values *(number_of_topics^2) + (number_of_topics^2) / length_of_rank_list)&lt;br /&gt;
        append [team_id, score] to team_scores dictionary with team_id as key&lt;br /&gt;
      end for&lt;br /&gt;
      set topic_set to true&lt;br /&gt;
    end for&lt;br /&gt;
    sort team_scores dictionary by values/scores in descending order&lt;br /&gt;
    for score in team_scores&lt;br /&gt;
      if team not in team_list or topic not in topic_list&lt;br /&gt;
        remove score&lt;br /&gt;
        continue to next iteration&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id to topic_assignment list&lt;br /&gt;
      if number of occurrences of current topic in topic_assignment is same as topic_per_team&lt;br /&gt;
        remove this topic_id from topic_list&lt;br /&gt;
      end if&lt;br /&gt;
      append team_id to team_assignment list&lt;br /&gt;
      if number of occurrences of current team in team_assignment is same as team_per_topic&lt;br /&gt;
        remove this team_id from team_list&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id and team_id pair to team_bids&lt;br /&gt;
    end for&lt;br /&gt;
    save sign up information stored in team_bids to database&lt;br /&gt;
  end def&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114047</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114047"/>
		<updated>2017-12-01T17:54:37Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Use Case Diagram */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
The changes in the first sub section below were prior to the mentor meeting, where we had a major change in our problem statement.&lt;br /&gt;
Earlier, we assumed that we only had to change the existing code, which is reflected above. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Understanding the Requirements===&lt;br /&gt;
* Objects (being bid on) are often assigned by having the bidders providing a preference list of bids. &lt;br /&gt;
** Expertiza provides a way for students to bid on different assignment topics. This allows the fair topic assignment distribution among students, particularly when multiple students or groups (of students) are bidding on same topic or paper. &lt;br /&gt;
**This is very similar to the kind of bidding that a conference implements for reviewers (who bid for proposed papers)&lt;br /&gt;
* The other requirements are extending the above idea to get new features or an improved algorithm. We discuss these in more detail below. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Subsequent Discussion===&lt;br /&gt;
Because the two situations are similar, it was hoped that the conference bidding would call the code of the (existing) assignment bidding. It was also hoped that the conference bidding would be modified to make it more general.&lt;br /&gt;
&lt;br /&gt;
However, in a subsequent meeting with the mentor, it was found that the two bidding algorithms are incompatible.  The existing algorithm will not work for conference bidding are:&lt;br /&gt;
* Team based versus Individual based: The existing algoritm is designed to assign topics to teams, whereas we have to assign topics to individuals&lt;br /&gt;
* The current bidding implementation only returns one bidding result (per graph) each time, whereas expected bidding implementation must be able to return multiple bidding results every time.&lt;br /&gt;
* In the case of a priority tie, the current bidding algorithm assigns topic to bidding team that has most members whom have worked together in the past. This will not work for a conference bidding since now there is no collaboration in conference paper review.&lt;br /&gt;
&lt;br /&gt;
In addition since the existing algorithm is partly running on a web-service we cannot directly modify, it will be difficult to modify the code for the conference requirements and later integrate the two.&lt;br /&gt;
&lt;br /&gt;
However, with the new requirements, in addition we need to add completely new code.&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Changes ===&lt;br /&gt;
&lt;br /&gt;
To accommodate this code to fit our needs, we have proposed to add 3 new variable&lt;br /&gt;
&lt;br /&gt;
  bidding_for_reviews?&lt;br /&gt;
  topic_per_team&lt;br /&gt;
  team_per_topic&lt;br /&gt;
&lt;br /&gt;
new_intelligent_property will check if an assignment is using conference paper bidding or team assignment bidding, it will be true if bidding is on conference paper review and false if bidding is on team assignment; topic_per_team will record required number of topics that can be chosen per a team; and team_per_topic will record required number of teams that can be assigned to a topic.&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      if new_intelligent_property&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids }&lt;br /&gt;
      else&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if !new_intelligent_property&lt;br /&gt;
      data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
      url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
      begin&lt;br /&gt;
        response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
        # store each summary in a hashmap and use the question as the key&lt;br /&gt;
        teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
        create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid(teams, assignment, topic_per_team, team_per_topic)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Additional Changes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With this change, we will have to add a new function: run_conference_bid(teams, assignment), with pseudo-code as shown below:&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    set topic_set to false;&lt;br /&gt;
    for each team in teams&lt;br /&gt;
      append the team in team_list&lt;br /&gt;
      retrieve bidding ranks of each team&lt;br /&gt;
      sum all rank values in list&lt;br /&gt;
      for each topic priority/rank value in ranks list&lt;br /&gt;
        if topic_set is false&lt;br /&gt;
           append topic_id to topic_list&lt;br /&gt;
        end if&lt;br /&gt;
        calculate percentage of the rank value in comparison to sum of rank values &lt;br /&gt;
        if sum is 0 &lt;br /&gt;
          change percentage to 1/length_of_rank_list&lt;br /&gt;
        end if&lt;br /&gt;
        score rank value by doing (percent_rank_values *(number_of_topics^2) + (number_of_topics^2) / length_of_rank_list)&lt;br /&gt;
        append [team_id, score] to team_scores dictionary with team_id as key&lt;br /&gt;
      end for&lt;br /&gt;
      set topic_set to true&lt;br /&gt;
    end for&lt;br /&gt;
    sort team_scores dictionary by values/scores in descending order&lt;br /&gt;
    for score in team_scores&lt;br /&gt;
      if team not in team_list or topic not in topic_list&lt;br /&gt;
        remove score&lt;br /&gt;
        continue to next iteration&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id to topic_assignment list&lt;br /&gt;
      if number of occurrences of current topic in topic_assignment is same as topic_per_team&lt;br /&gt;
        remove this topic_id from topic_list&lt;br /&gt;
      end if&lt;br /&gt;
      append team_id to team_assignment list&lt;br /&gt;
      if number of occurrences of current team in team_assignment is same as team_per_topic&lt;br /&gt;
        remove this team_id from team_list&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id and team_id pair to team_bids&lt;br /&gt;
    end for&lt;br /&gt;
    save sign up information stored in team_bids to database&lt;br /&gt;
  end def&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114046</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114046"/>
		<updated>2017-12-01T17:53:41Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
The changes in the first sub section below were prior to the mentor meeting, where we had a major change in our problem statement.&lt;br /&gt;
Earlier, we assumed that we only had to change the existing code, which is reflected above. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Understanding the Requirements===&lt;br /&gt;
* Objects (being bid on) are often assigned by having the bidders providing a preference list of bids. &lt;br /&gt;
** Expertiza provides a way for students to bid on different assignment topics. This allows the fair topic assignment distribution among students, particularly when multiple students or groups (of students) are bidding on same topic or paper. &lt;br /&gt;
**This is very similar to the kind of bidding that a conference implements for reviewers (who bid for proposed papers)&lt;br /&gt;
* The other requirements are extending the above idea to get new features or an improved algorithm. We discuss these in more detail below. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Subsequent Discussion===&lt;br /&gt;
Because the two situations are similar, it was hoped that the conference bidding would call the code of the (existing) assignment bidding. It was also hoped that the conference bidding would be modified to make it more general.&lt;br /&gt;
&lt;br /&gt;
However, in a subsequent meeting with the mentor, it was found that the two bidding algorithms are incompatible.  The existing algorithm will not work for conference bidding are:&lt;br /&gt;
* Team based versus Individual based: The existing algoritm is designed to assign topics to teams, whereas we have to assign topics to individuals&lt;br /&gt;
* The current bidding implementation only returns one bidding result (per graph) each time, whereas expected bidding implementation must be able to return multiple bidding results every time.&lt;br /&gt;
* In the case of a priority tie, the current bidding algorithm assigns topic to bidding team that has most members whom have worked together in the past. This will not work for a conference bidding since now there is no collaboration in conference paper review.&lt;br /&gt;
&lt;br /&gt;
In addition since the existing algorithm is partly running on a web-service we cannot directly modify, it will be difficult to modify the code for the conference requirements and later integrate the two.&lt;br /&gt;
&lt;br /&gt;
However, with the new requirements, in addition we need to add completely new code.&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Changes ===&lt;br /&gt;
&lt;br /&gt;
To accommodate this code to fit our needs, we have proposed to add 3 new variable&lt;br /&gt;
&lt;br /&gt;
  bidding_for_reviews?&lt;br /&gt;
  topic_per_team&lt;br /&gt;
  team_per_topic&lt;br /&gt;
&lt;br /&gt;
new_intelligent_property will check if an assignment is using conference paper bidding or team assignment bidding, it will be true if bidding is on conference paper review and false if bidding is on team assignment; topic_per_team will record required number of topics that can be chosen per a team; and team_per_topic will record required number of teams that can be assigned to a topic.&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      if new_intelligent_property&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids }&lt;br /&gt;
      else&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if !new_intelligent_property&lt;br /&gt;
      data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
      url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
      begin&lt;br /&gt;
        response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
        # store each summary in a hashmap and use the question as the key&lt;br /&gt;
        teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
        create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid(teams, assignment, topic_per_team, team_per_topic)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Additional Changes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With this change, we will have to add a new function: run_conference_bid(teams, assignment), with pseudo-code as shown below:&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    set topic_set to false;&lt;br /&gt;
    for each team in teams&lt;br /&gt;
      append the team in team_list&lt;br /&gt;
      retrieve bidding ranks of each team&lt;br /&gt;
      sum all rank values in list&lt;br /&gt;
      for each topic priority/rank value in ranks list&lt;br /&gt;
        if topic_set is false&lt;br /&gt;
           append topic_id to topic_list&lt;br /&gt;
        end if&lt;br /&gt;
        calculate percentage of the rank value in comparison to sum of rank values &lt;br /&gt;
        if sum is 0 &lt;br /&gt;
          change percentage to 1/length_of_rank_list&lt;br /&gt;
        end if&lt;br /&gt;
        score rank value by doing (percent_rank_values *(number_of_topics^2) + (number_of_topics^2) / length_of_rank_list)&lt;br /&gt;
        append [team_id, score] to team_scores dictionary with team_id as key&lt;br /&gt;
      end for&lt;br /&gt;
      set topic_set to true&lt;br /&gt;
    end for&lt;br /&gt;
    sort team_scores dictionary by values/scores in descending order&lt;br /&gt;
    for score in team_scores&lt;br /&gt;
      if team not in team_list or topic not in topic_list&lt;br /&gt;
        remove score&lt;br /&gt;
        continue to next iteration&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id to topic_assignment list&lt;br /&gt;
      if number of occurrences of current topic in topic_assignment is same as topic_per_team&lt;br /&gt;
        remove this topic_id from topic_list&lt;br /&gt;
      end if&lt;br /&gt;
      append team_id to team_assignment list&lt;br /&gt;
      if number of occurrences of current team in team_assignment is same as team_per_topic&lt;br /&gt;
        remove this team_id from team_list&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id and team_id pair to team_bids&lt;br /&gt;
    end for&lt;br /&gt;
    save sign up information stored in team_bids to database&lt;br /&gt;
  end def&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114045</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114045"/>
		<updated>2017-12-01T17:53:00Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Implementing the Project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Existing Algorithm ==&lt;br /&gt;
&lt;br /&gt;
==== Problem ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
==== Functionality ====&lt;br /&gt;
The topics are assigned to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* Assigning topics to teams: This is implemented as a one line, comparing bid preferences to allot topics.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Understanding the Requirements===&lt;br /&gt;
* Objects (being bid on) are often assigned by having the bidders providing a preference list of bids. &lt;br /&gt;
** Expertiza provides a way for students to bid on different assignment topics. This allows the fair topic assignment distribution among students, particularly when multiple students or groups (of students) are bidding on same topic or paper. &lt;br /&gt;
**This is very similar to the kind of bidding that a conference implements for reviewers (who bid for proposed papers)&lt;br /&gt;
* The other requirements are extending the above idea to get new features or an improved algorithm. We discuss these in more detail below. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Subsequent Discussion===&lt;br /&gt;
Because the two situations are similar, it was hoped that the conference bidding would call the code of the (existing) assignment bidding. It was also hoped that the conference bidding would be modified to make it more general.&lt;br /&gt;
&lt;br /&gt;
However, in a subsequent meeting with the mentor, it was found that the two bidding algorithms are incompatible.  The existing algorithm will not work for conference bidding are:&lt;br /&gt;
* Team based versus Individual based: The existing algoritm is designed to assign topics to teams, whereas we have to assign topics to individuals&lt;br /&gt;
* The current bidding implementation only returns one bidding result (per graph) each time, whereas expected bidding implementation must be able to return multiple bidding results every time.&lt;br /&gt;
* In the case of a priority tie, the current bidding algorithm assigns topic to bidding team that has most members whom have worked together in the past. This will not work for a conference bidding since now there is no collaboration in conference paper review.&lt;br /&gt;
&lt;br /&gt;
In addition since the existing algorithm is partly running on a web-service we cannot directly modify, it will be difficult to modify the code for the conference requirements and later integrate the two.&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
The changes in the first sub section below were prior to the mentor meeting, where we had a major change in our problem statement.&lt;br /&gt;
Earlier, we assumed that we only had to change the existing code, which is reflected above. &lt;br /&gt;
&lt;br /&gt;
However, with the new requirements, in addition we need to add completely new code.&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Changes ===&lt;br /&gt;
&lt;br /&gt;
To accommodate this code to fit our needs, we have proposed to add 3 new variable&lt;br /&gt;
&lt;br /&gt;
  bidding_for_reviews?&lt;br /&gt;
  topic_per_team&lt;br /&gt;
  team_per_topic&lt;br /&gt;
&lt;br /&gt;
new_intelligent_property will check if an assignment is using conference paper bidding or team assignment bidding, it will be true if bidding is on conference paper review and false if bidding is on team assignment; topic_per_team will record required number of topics that can be chosen per a team; and team_per_topic will record required number of teams that can be assigned to a topic.&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      if new_intelligent_property&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids }&lt;br /&gt;
      else&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if !new_intelligent_property&lt;br /&gt;
      data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
      url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
      begin&lt;br /&gt;
        response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
        # store each summary in a hashmap and use the question as the key&lt;br /&gt;
        teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
        create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid(teams, assignment, topic_per_team, team_per_topic)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Additional Changes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With this change, we will have to add a new function: run_conference_bid(teams, assignment), with pseudo-code as shown below:&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    set topic_set to false;&lt;br /&gt;
    for each team in teams&lt;br /&gt;
      append the team in team_list&lt;br /&gt;
      retrieve bidding ranks of each team&lt;br /&gt;
      sum all rank values in list&lt;br /&gt;
      for each topic priority/rank value in ranks list&lt;br /&gt;
        if topic_set is false&lt;br /&gt;
           append topic_id to topic_list&lt;br /&gt;
        end if&lt;br /&gt;
        calculate percentage of the rank value in comparison to sum of rank values &lt;br /&gt;
        if sum is 0 &lt;br /&gt;
          change percentage to 1/length_of_rank_list&lt;br /&gt;
        end if&lt;br /&gt;
        score rank value by doing (percent_rank_values *(number_of_topics^2) + (number_of_topics^2) / length_of_rank_list)&lt;br /&gt;
        append [team_id, score] to team_scores dictionary with team_id as key&lt;br /&gt;
      end for&lt;br /&gt;
      set topic_set to true&lt;br /&gt;
    end for&lt;br /&gt;
    sort team_scores dictionary by values/scores in descending order&lt;br /&gt;
    for score in team_scores&lt;br /&gt;
      if team not in team_list or topic not in topic_list&lt;br /&gt;
        remove score&lt;br /&gt;
        continue to next iteration&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id to topic_assignment list&lt;br /&gt;
      if number of occurrences of current topic in topic_assignment is same as topic_per_team&lt;br /&gt;
        remove this topic_id from topic_list&lt;br /&gt;
      end if&lt;br /&gt;
      append team_id to team_assignment list&lt;br /&gt;
      if number of occurrences of current team in team_assignment is same as team_per_topic&lt;br /&gt;
        remove this team_id from team_list&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id and team_id pair to team_bids&lt;br /&gt;
    end for&lt;br /&gt;
    save sign up information stored in team_bids to database&lt;br /&gt;
  end def&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114043</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114043"/>
		<updated>2017-12-01T17:11:44Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Implementing the Project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Implementing the Project ==&lt;br /&gt;
&lt;br /&gt;
==== Existing Algorithm ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
assigns the topics to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here].&lt;br /&gt;
** The basic cost function used in the algorithm is:      C(i,j) = 1/N * &amp;amp;sum; [ M -S(i) ] where i varies from 1 to N&lt;br /&gt;
** The Algorithm calculates the weights for every user not a team or part of an incomplete team. It then assigns teams using the weights, by plotting graphs for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M students per team; &lt;br /&gt;
** The Algorithm is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Understanding the Requirements===&lt;br /&gt;
* Objects (being bid on) are often assigned by having the bidders providing a preference list of bids. &lt;br /&gt;
** Expertiza provides a way for students to bid on different assignment topics. This allows the fair topic assignment distribution among students, particularly when multiple students or groups (of students) are bidding on same topic or paper. &lt;br /&gt;
**This is very similar to the kind of bidding that a conference implements for reviewers (who bid for proposed papers)&lt;br /&gt;
* The other requirements are extending the above idea to get new features or an improved algorithm. We discuss these in more detail below. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Subsequent Discussion===&lt;br /&gt;
Because the two situations are similar, it was hoped that the conference bidding would call the code of the (existing) assignment bidding. It was also hoped that the conference bidding would be modified to make it more general.&lt;br /&gt;
&lt;br /&gt;
However, in a subsequent meeting with the mentor, it was found that the two bidding algorithms are incompatible.  The existing algorithm will not work for conference bidding are:&lt;br /&gt;
* Team based versus Individual based: The existing algoritm is designed to assign topics to teams, whereas we have to assign topics to individuals&lt;br /&gt;
* The current bidding implementation only returns one bidding result (per graph) each time, whereas expected bidding implementation must be able to return multiple bidding results every time.&lt;br /&gt;
* In the case of a priority tie, the current bidding algorithm assigns topic to bidding team that has most members whom have worked together in the past. This will not work for a conference bidding since now there is no collaboration in conference paper review.&lt;br /&gt;
&lt;br /&gt;
In addition since the existing algorithm is partly running on a web-service we cannot directly modify, it will be difficult to modify the code for the conference requirements and later integrate the two.&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
The changes in the first sub section below were prior to the mentor meeting, where we had a major change in our problem statement.&lt;br /&gt;
Earlier, we assumed that we only had to change the existing code, which is reflected above. &lt;br /&gt;
&lt;br /&gt;
However, with the new requirements, in addition we need to add completely new code.&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Changes ===&lt;br /&gt;
&lt;br /&gt;
To accommodate this code to fit our needs, we have proposed to add 3 new variable&lt;br /&gt;
&lt;br /&gt;
  bidding_for_reviews?&lt;br /&gt;
  topic_per_team&lt;br /&gt;
  team_per_topic&lt;br /&gt;
&lt;br /&gt;
new_intelligent_property will check if an assignment is using conference paper bidding or team assignment bidding, it will be true if bidding is on conference paper review and false if bidding is on team assignment; topic_per_team will record required number of topics that can be chosen per a team; and team_per_topic will record required number of teams that can be assigned to a topic.&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      if new_intelligent_property&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids }&lt;br /&gt;
      else&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if !new_intelligent_property&lt;br /&gt;
      data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
      url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
      begin&lt;br /&gt;
        response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
        # store each summary in a hashmap and use the question as the key&lt;br /&gt;
        teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
        create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid(teams, assignment, topic_per_team, team_per_topic)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Additional Changes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With this change, we will have to add a new function: run_conference_bid(teams, assignment), with pseudo-code as shown below:&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    set topic_set to false;&lt;br /&gt;
    for each team in teams&lt;br /&gt;
      append the team in team_list&lt;br /&gt;
      retrieve bidding ranks of each team&lt;br /&gt;
      sum all rank values in list&lt;br /&gt;
      for each topic priority/rank value in ranks list&lt;br /&gt;
        if topic_set is false&lt;br /&gt;
           append topic_id to topic_list&lt;br /&gt;
        end if&lt;br /&gt;
        calculate percentage of the rank value in comparison to sum of rank values &lt;br /&gt;
        if sum is 0 &lt;br /&gt;
          change percentage to 1/length_of_rank_list&lt;br /&gt;
        end if&lt;br /&gt;
        score rank value by doing (percent_rank_values *(number_of_topics^2) + (number_of_topics^2) / length_of_rank_list)&lt;br /&gt;
        append [team_id, score] to team_scores dictionary with team_id as key&lt;br /&gt;
      end for&lt;br /&gt;
      set topic_set to true&lt;br /&gt;
    end for&lt;br /&gt;
    sort team_scores dictionary by values/scores in descending order&lt;br /&gt;
    for score in team_scores&lt;br /&gt;
      if team not in team_list or topic not in topic_list&lt;br /&gt;
        remove score&lt;br /&gt;
        continue to next iteration&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id to topic_assignment list&lt;br /&gt;
      if number of occurrences of current topic in topic_assignment is same as topic_per_team&lt;br /&gt;
        remove this topic_id from topic_list&lt;br /&gt;
      end if&lt;br /&gt;
      append team_id to team_assignment list&lt;br /&gt;
      if number of occurrences of current team in team_assignment is same as team_per_topic&lt;br /&gt;
        remove this team_id from team_list&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id and team_id pair to team_bids&lt;br /&gt;
    end for&lt;br /&gt;
    save sign up information stored in team_bids to database&lt;br /&gt;
  end def&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114042</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114042"/>
		<updated>2017-12-01T17:09:13Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Implementing the Project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Implementing the Project ==&lt;br /&gt;
&lt;br /&gt;
==== Existing Algorithm ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
assigns the topics to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here]. &lt;br /&gt;
** A short summary is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
**In the algorithm above,      C(i,j) = 1/N * &amp;amp;sum; [ M1 -S(i) ] where i varies from 1 to N&lt;br /&gt;
&lt;br /&gt;
**Using the weights obtained above, graphs are plotted for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M1 students per team;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Understanding the Requirements===&lt;br /&gt;
* Objects (being bid on) are often assigned by having the bidders providing a preference list of bids. &lt;br /&gt;
** Expertiza provides a way for students to bid on different assignment topics. This allows the fair topic assignment distribution among students, particularly when multiple students or groups (of students) are bidding on same topic or paper. &lt;br /&gt;
**This is very similar to the kind of bidding that a conference implements for reviewers (who bid for proposed papers)&lt;br /&gt;
* The other requirements are extending the above idea to get new features or an improved algorithm. We discuss these in more detail below. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Subsequent Discussion===&lt;br /&gt;
Because the two situations are similar, it was hoped that the conference bidding would call the code of the (existing) assignment bidding. It was also hoped that the conference bidding would be modified to make it more general.&lt;br /&gt;
&lt;br /&gt;
However, in a subsequent meeting with the mentor, it was found that the two bidding algorithms are incompatible.  The existing algorithm will not work for conference bidding are:&lt;br /&gt;
* Team based versus Individual based: The existing algoritm is designed to assign topics to teams, whereas we have to assign topics to individuals&lt;br /&gt;
* The current bidding implementation only returns one bidding result (per graph) each time, whereas expected bidding implementation must be able to return multiple bidding results every time.&lt;br /&gt;
* In the case of a priority tie, the current bidding algorithm assigns topic to bidding team that has most members whom have worked together in the past. This will not work for a conference bidding since now there is no collaboration in conference paper review.&lt;br /&gt;
&lt;br /&gt;
In addition since the existing algorithm is partly running on a web-service we cannot directly modify, it will be difficult to modify the code for the conference requirements and later integrate the two.&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
The changes in the first sub section below were prior to the mentor meeting, where we had a major change in our problem statement.&lt;br /&gt;
Earlier, we assumed that we only had to change the existing code, which is reflected above. &lt;br /&gt;
&lt;br /&gt;
However, with the new requirements, in addition we need to add completely new code.&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Changes ===&lt;br /&gt;
&lt;br /&gt;
To accommodate this code to fit our needs, we have proposed to add 3 new variable&lt;br /&gt;
&lt;br /&gt;
  bidding_for_reviews?&lt;br /&gt;
  topic_per_team&lt;br /&gt;
  team_per_topic&lt;br /&gt;
&lt;br /&gt;
new_intelligent_property will check if an assignment is using conference paper bidding or team assignment bidding, it will be true if bidding is on conference paper review and false if bidding is on team assignment; topic_per_team will record required number of topics that can be chosen per a team; and team_per_topic will record required number of teams that can be assigned to a topic.&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      if new_intelligent_property&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids }&lt;br /&gt;
      else&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if !new_intelligent_property&lt;br /&gt;
      data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
      url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
      begin&lt;br /&gt;
        response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
        # store each summary in a hashmap and use the question as the key&lt;br /&gt;
        teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
        create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid(teams, assignment, topic_per_team, team_per_topic)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Additional Changes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With this change, we will have to add a new function: run_conference_bid(teams, assignment), with pseudo-code as shown below:&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    set topic_set to false;&lt;br /&gt;
    for each team in teams&lt;br /&gt;
      append the team in team_list&lt;br /&gt;
      retrieve bidding ranks of each team&lt;br /&gt;
      sum all rank values in list&lt;br /&gt;
      for each topic priority/rank value in ranks list&lt;br /&gt;
        if topic_set is false&lt;br /&gt;
           append topic_id to topic_list&lt;br /&gt;
        end if&lt;br /&gt;
        calculate percentage of the rank value in comparison to sum of rank values &lt;br /&gt;
        if sum is 0 &lt;br /&gt;
          change percentage to 1/length_of_rank_list&lt;br /&gt;
        end if&lt;br /&gt;
        score rank value by doing (percent_rank_values *(number_of_topics^2) + (number_of_topics^2) / length_of_rank_list)&lt;br /&gt;
        append [team_id, score] to team_scores dictionary with team_id as key&lt;br /&gt;
      end for&lt;br /&gt;
      set topic_set to true&lt;br /&gt;
    end for&lt;br /&gt;
    sort team_scores dictionary by values/scores in descending order&lt;br /&gt;
    for score in team_scores&lt;br /&gt;
      if team not in team_list or topic not in topic_list&lt;br /&gt;
        remove score&lt;br /&gt;
        continue to next iteration&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id to topic_assignment list&lt;br /&gt;
      if number of occurrences of current topic in topic_assignment is same as topic_per_team&lt;br /&gt;
        remove this topic_id from topic_list&lt;br /&gt;
      end if&lt;br /&gt;
      append team_id to team_assignment list&lt;br /&gt;
      if number of occurrences of current team in team_assignment is same as team_per_topic&lt;br /&gt;
        remove this team_id from team_list&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id and team_id pair to team_bids&lt;br /&gt;
    end for&lt;br /&gt;
    save sign up information stored in team_bids to database&lt;br /&gt;
  end def&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114041</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114041"/>
		<updated>2017-12-01T17:08:47Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Implementing the Project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Implementing the Project ==&lt;br /&gt;
&lt;br /&gt;
==== Existing Algorithm ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
assigns the topics to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here]. &lt;br /&gt;
&lt;br /&gt;
**A short summary is as follows: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
**In the algorithm above,      C(i,j) = 1/N * &amp;amp;sum; [ M1 -S(i) ] where i varies from 1 to N&lt;br /&gt;
&lt;br /&gt;
**Using the weights obtained above, graphs are plotted for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M1 students per team;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Understanding the Requirements===&lt;br /&gt;
* Objects (being bid on) are often assigned by having the bidders providing a preference list of bids. &lt;br /&gt;
** Expertiza provides a way for students to bid on different assignment topics. This allows the fair topic assignment distribution among students, particularly when multiple students or groups (of students) are bidding on same topic or paper. &lt;br /&gt;
**This is very similar to the kind of bidding that a conference implements for reviewers (who bid for proposed papers)&lt;br /&gt;
* The other requirements are extending the above idea to get new features or an improved algorithm. We discuss these in more detail below. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Subsequent Discussion===&lt;br /&gt;
Because the two situations are similar, it was hoped that the conference bidding would call the code of the (existing) assignment bidding. It was also hoped that the conference bidding would be modified to make it more general.&lt;br /&gt;
&lt;br /&gt;
However, in a subsequent meeting with the mentor, it was found that the two bidding algorithms are incompatible.  The existing algorithm will not work for conference bidding are:&lt;br /&gt;
* Team based versus Individual based: The existing algoritm is designed to assign topics to teams, whereas we have to assign topics to individuals&lt;br /&gt;
* The current bidding implementation only returns one bidding result (per graph) each time, whereas expected bidding implementation must be able to return multiple bidding results every time.&lt;br /&gt;
* In the case of a priority tie, the current bidding algorithm assigns topic to bidding team that has most members whom have worked together in the past. This will not work for a conference bidding since now there is no collaboration in conference paper review.&lt;br /&gt;
&lt;br /&gt;
In addition since the existing algorithm is partly running on a web-service we cannot directly modify, it will be difficult to modify the code for the conference requirements and later integrate the two.&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
The changes in the first sub section below were prior to the mentor meeting, where we had a major change in our problem statement.&lt;br /&gt;
Earlier, we assumed that we only had to change the existing code, which is reflected above. &lt;br /&gt;
&lt;br /&gt;
However, with the new requirements, in addition we need to add completely new code.&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Changes ===&lt;br /&gt;
&lt;br /&gt;
To accommodate this code to fit our needs, we have proposed to add 3 new variable&lt;br /&gt;
&lt;br /&gt;
  bidding_for_reviews?&lt;br /&gt;
  topic_per_team&lt;br /&gt;
  team_per_topic&lt;br /&gt;
&lt;br /&gt;
new_intelligent_property will check if an assignment is using conference paper bidding or team assignment bidding, it will be true if bidding is on conference paper review and false if bidding is on team assignment; topic_per_team will record required number of topics that can be chosen per a team; and team_per_topic will record required number of teams that can be assigned to a topic.&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      if new_intelligent_property&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids }&lt;br /&gt;
      else&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if !new_intelligent_property&lt;br /&gt;
      data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
      url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
      begin&lt;br /&gt;
        response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
        # store each summary in a hashmap and use the question as the key&lt;br /&gt;
        teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
        create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid(teams, assignment, topic_per_team, team_per_topic)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Additional Changes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With this change, we will have to add a new function: run_conference_bid(teams, assignment), with pseudo-code as shown below:&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    set topic_set to false;&lt;br /&gt;
    for each team in teams&lt;br /&gt;
      append the team in team_list&lt;br /&gt;
      retrieve bidding ranks of each team&lt;br /&gt;
      sum all rank values in list&lt;br /&gt;
      for each topic priority/rank value in ranks list&lt;br /&gt;
        if topic_set is false&lt;br /&gt;
           append topic_id to topic_list&lt;br /&gt;
        end if&lt;br /&gt;
        calculate percentage of the rank value in comparison to sum of rank values &lt;br /&gt;
        if sum is 0 &lt;br /&gt;
          change percentage to 1/length_of_rank_list&lt;br /&gt;
        end if&lt;br /&gt;
        score rank value by doing (percent_rank_values *(number_of_topics^2) + (number_of_topics^2) / length_of_rank_list)&lt;br /&gt;
        append [team_id, score] to team_scores dictionary with team_id as key&lt;br /&gt;
      end for&lt;br /&gt;
      set topic_set to true&lt;br /&gt;
    end for&lt;br /&gt;
    sort team_scores dictionary by values/scores in descending order&lt;br /&gt;
    for score in team_scores&lt;br /&gt;
      if team not in team_list or topic not in topic_list&lt;br /&gt;
        remove score&lt;br /&gt;
        continue to next iteration&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id to topic_assignment list&lt;br /&gt;
      if number of occurrences of current topic in topic_assignment is same as topic_per_team&lt;br /&gt;
        remove this topic_id from topic_list&lt;br /&gt;
      end if&lt;br /&gt;
      append team_id to team_assignment list&lt;br /&gt;
      if number of occurrences of current team in team_assignment is same as team_per_topic&lt;br /&gt;
        remove this team_id from team_list&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id and team_id pair to team_bids&lt;br /&gt;
    end for&lt;br /&gt;
    save sign up information stored in team_bids to database&lt;br /&gt;
  end def&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114040</id>
		<title>CSC/ECE 517 Fall 2017/E17A7 Allow Reviewers to bid on what to review</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2017/E17A7_Allow_Reviewers_to_bid_on_what_to_review&amp;diff=114040"/>
		<updated>2017-12-01T17:07:51Z</updated>

		<summary type="html">&lt;p&gt;Bsingh8: /* Implementing the Project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes the the project E17A7 which is one of the several projects to allow Expertiza support (the currently unsupported) conference. Specifcally, it involves adding the ability of conference paper reviewers to bid for what they want to review. The members of this project are: &lt;br /&gt;
&lt;br /&gt;
Leiyang Guo (lguo7@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Bikram Singh (bsingh8@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Navin Venugopal (nvenugo2@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
Sathwick Goparapu (sgopara@ncsu.edu)&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Expertiza is an open source project created using Ruby on Rails. This project is an software primarily to create reusable learning objects through peer review and also supports team projects. Expertiza allows the creation of instructors and student accounts. This allows the instructors to post projects (student learning objects) which can be viewed and worked upon by students. These can also be peer reviewed by students later.&lt;br /&gt;
&lt;br /&gt;
====Background of the project====&lt;br /&gt;
In the existing Expertiza functionality, the bidding ability is only for bidding for a project topic for students in a course. This involves the instructor posting a list of project topics, and each student (or all students together as a team, if some students have already formed a team) then posts a preference list, listing topics (s)he wants to work on. Then the bidding algorithm assigns the topics, particularly with the following features: &lt;br /&gt;
* Students (not in at team) with close preferences are assigned into a project team, and the common preference is the project topic assigned to the team. Alternatively, for existing teams the project topic is assigned as per the common project topic preference list&lt;br /&gt;
* Each team is assigned only one topic&lt;br /&gt;
* Each topic (if assigned) is assigned to a maximum of one team&lt;br /&gt;
&lt;br /&gt;
====Description of project====&lt;br /&gt;
This project is not responsible for adding code so as to support a conference. Rather, we are interested in the bidding algorithm used in the conference, which is significantly different from the project bidding algorithm as explained above.&lt;br /&gt;
&lt;br /&gt;
For the purposes of the project, we assume that there are several reviewers in a conference who review papers which are proposed to be presented in the conference. Also, the entire list of papers proposed to be presented in the conference is also available.&lt;br /&gt;
&lt;br /&gt;
Then the basic working of the project assumes: &lt;br /&gt;
* Before the bidding close deadline, reviewers submit a list of papers they wish to review.&lt;br /&gt;
* After the bidding deadline, the algorithm assigns papers to reviewers to review, such that:&lt;br /&gt;
** Each paper (if assigned) is assigned to a maximum of R reviewers (here R represents some constant)&lt;br /&gt;
** Each reviewer is assigned a maximum of P papers to review (here P represents some constant)&lt;br /&gt;
** Assignment of papers is individual&lt;br /&gt;
&lt;br /&gt;
==Project Requirements==&lt;br /&gt;
&lt;br /&gt;
In this section we discuss the problem statement, then discuss the existing code and possible changes required. &lt;br /&gt;
&lt;br /&gt;
====Problem Statement====&lt;br /&gt;
* To take the existing bidding code in Expertiza (which is meant for students bidding for project topics) and make it callable either for bidding for topics or bidding for submissions to review. &lt;br /&gt;
* A possible extension is to add other methods, like a &amp;quot;late reviewer registration&amp;quot; method, in which each new reviewer is assigned one of the least-reviewed submissions so far. Methods like these require an extension of the basic working of the project.&lt;br /&gt;
* The matching algorithm is currently not very sophisticated.  Top trading cycles is implemented in the web service (though it is currently not used by bidding assignment), and could be adapted to this use. &lt;br /&gt;
&lt;br /&gt;
In the subsequent discussion with the mentor, it was concluded that the two bidding situations are very different hence it was decided to keep the two separate, at least initially. Also the third requirement was modified to first make the bidding for a conference using any algorithm and if time permits, to use a better algorithm like top trading cycles.&lt;br /&gt;
&lt;br /&gt;
====Current Project Aims====&lt;br /&gt;
* To develop code such that both applications (bidding for project teams and bidding for conference paper reviews) use the same code&lt;br /&gt;
* To improve the algorithm for calculating the score for a particular project topic/conference paper review assigned to a project team/conference reviewer&lt;br /&gt;
&lt;br /&gt;
We want to state here that we are not responsible for developing any conference features. Specifically, this means that we are not changing any UI features. We will be primarily relying on UI changes done by E17A5&lt;br /&gt;
&lt;br /&gt;
== Implementing the Project ==&lt;br /&gt;
&lt;br /&gt;
==== Existing Algorithm ====&lt;br /&gt;
The existing algorithm solves the following problem: &lt;br /&gt;
&lt;br /&gt;
To form teams of students of Maximum size M and then assign topics (there are N topics) based on preference lists submitted either by individual students or teams (complete or otherwise). Preference Lists can have minimum 1 topic and a maximum of L topics. &lt;br /&gt;
Then the topics are alloted to teams such that each team gets an unique topic and each topic is assigned only to one team. &lt;br /&gt;
&lt;br /&gt;
assigns the topics to project teams in 2 steps:&lt;br /&gt;
&lt;br /&gt;
* Making teams: This is done using a k-means clustering and a weighting formula that favors increasing overall student satisfaction and adding members until the maximum allowable team size is reached. You can read about it in detail [https://docs.google.com/document/d/1hyJjqfdSPi0NjzLFygUodVLVqABIE2Lu-RBDMkUDvUs/edit?usp=sharing| here]. **A short summary is as follows: &lt;br /&gt;
&lt;br /&gt;
   &amp;lt;nowiki&amp;gt;&lt;br /&gt;
      For every topic j :&lt;br /&gt;
         For every position i that topic j can be placed in (any) preference list:&lt;br /&gt;
              Let S(i) = number of students who selected topic j at position i of their (individual) preference list&lt;br /&gt;
              B(i) = 1/S(i)&lt;br /&gt;
              Calculate C(i,j)                &lt;br /&gt;
              Weight(i,j) = B(i) / C(i,j)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt; &lt;br /&gt;
     &lt;br /&gt;
&lt;br /&gt;
**In the algorithm above,      C(i,j) = 1/N * &amp;amp;sum; [ M1 -S(i) ] where i varies from 1 to N&lt;br /&gt;
&lt;br /&gt;
**Using the weights obtained above, graphs are plotted for each topic. It is as follows:&lt;br /&gt;
*** Draw a graph for every topic j with X axis as the priority position i and the Y axis as the Weights.&lt;br /&gt;
*** Hierarchical K means to select teams such that all students in a team are close to each other in the graph above, hopefully more towards the left of the graph, and also such that there are a minimum of 1 and a maximum of M1 students per team;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Understanding the Requirements===&lt;br /&gt;
* Objects (being bid on) are often assigned by having the bidders providing a preference list of bids. &lt;br /&gt;
** Expertiza provides a way for students to bid on different assignment topics. This allows the fair topic assignment distribution among students, particularly when multiple students or groups (of students) are bidding on same topic or paper. &lt;br /&gt;
**This is very similar to the kind of bidding that a conference implements for reviewers (who bid for proposed papers)&lt;br /&gt;
* The other requirements are extending the above idea to get new features or an improved algorithm. We discuss these in more detail below. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Subsequent Discussion===&lt;br /&gt;
Because the two situations are similar, it was hoped that the conference bidding would call the code of the (existing) assignment bidding. It was also hoped that the conference bidding would be modified to make it more general.&lt;br /&gt;
&lt;br /&gt;
However, in a subsequent meeting with the mentor, it was found that the two bidding algorithms are incompatible.  The existing algorithm will not work for conference bidding are:&lt;br /&gt;
* Team based versus Individual based: The existing algoritm is designed to assign topics to teams, whereas we have to assign topics to individuals&lt;br /&gt;
* The current bidding implementation only returns one bidding result (per graph) each time, whereas expected bidding implementation must be able to return multiple bidding results every time.&lt;br /&gt;
* In the case of a priority tie, the current bidding algorithm assigns topic to bidding team that has most members whom have worked together in the past. This will not work for a conference bidding since now there is no collaboration in conference paper review.&lt;br /&gt;
&lt;br /&gt;
In addition since the existing algorithm is partly running on a web-service we cannot directly modify, it will be difficult to modify the code for the conference requirements and later integrate the two.&lt;br /&gt;
&lt;br /&gt;
==Use Case Diagram==&lt;br /&gt;
&lt;br /&gt;
Actors: &lt;br /&gt;
* Conference Reviewer: Submits a preference list of papers and reviews assigned papers&lt;br /&gt;
* Conference Administrator: Responsible for the assignment of topics to the reviewers&lt;br /&gt;
&lt;br /&gt;
Scenario&lt;br /&gt;
&lt;br /&gt;
The case of reviewers submitting a list of preferred topics and the administrator running the assignment process. For our project, the main modification would be concentrating on Use Case 4 and 5.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
[[File:UML_01.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Choose and submit preference to be reviewed====&lt;br /&gt;
* Use Case Id: 1&lt;br /&gt;
* Use Case Description: Participants choose the preference for conference review topics and submit it&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
* Pre Conditions: Conference papers are presented and submitted, and the participants are eligible for reviewing&lt;br /&gt;
* Post Conditions: Conference committee members can view participants preference and run bidding algorithm on it&lt;br /&gt;
&lt;br /&gt;
====Saving bidder information into database====&lt;br /&gt;
* Use Case Id: 2&lt;br /&gt;
* Use Case Description: bidding preferences and related participants information are processed and saved to database&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 1&lt;br /&gt;
* Pre Conditions: participants preferences are submitted&lt;br /&gt;
* Post Conditions: information can be retrieved and used by bidding algorithm&lt;br /&gt;
&lt;br /&gt;
====View list of topics====&lt;br /&gt;
* Use Case Id: 3&lt;br /&gt;
* Use Case Description: participants can view list of topic available for conference paper topic&lt;br /&gt;
* Actors: Participants&lt;br /&gt;
&lt;br /&gt;
====Run bidding process====&lt;br /&gt;
* Use Case Id: 4&lt;br /&gt;
* Use Case Description: Committee members can run bidding algorithm on application to help assigning the conference paper topics to participants&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: preferences must be submitted by participants&lt;br /&gt;
* Post Conditions: the bidding result can be used for paper assignment&lt;br /&gt;
&lt;br /&gt;
====Choosing and assigning paper to bidders====&lt;br /&gt;
* Use Case Id: 5&lt;br /&gt;
* Use Case Description: System assigns participants to conference paper topics according to bidding result&lt;br /&gt;
* Actors: None&lt;br /&gt;
* Triggered by: Use Case 4&lt;br /&gt;
* Pre Conditions: bidding algorithm has run and result has been returned&lt;br /&gt;
* Post Conditions: Participants can view topics been assigned to them&lt;br /&gt;
&lt;br /&gt;
====Change assignment of review using CRUD actions====&lt;br /&gt;
* Use Case Id: 6&lt;br /&gt;
* Use Case Description: Conference committee members can change assignment result manually&lt;br /&gt;
* Actors: Conference Committee&lt;br /&gt;
* Pre Conditions: topic assignment has been done&lt;br /&gt;
* Post Conditions: changes on bidding result is visible to participants and other committee members&lt;br /&gt;
&lt;br /&gt;
== Data Flow Diagram ==&lt;br /&gt;
Below is the Data Flow Diagram for process flows of the project. The diagram shows the process of bidding algorithm that we proposed to use for conference paper review assignment.&lt;br /&gt;
[[File:Webp.net-resizeimage (1).png]]&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
The changes in the first sub section below were prior to the mentor meeting, where we had a major change in our problem statement.&lt;br /&gt;
Earlier, we assumed that we only had to change the existing code, which is reflected above. &lt;br /&gt;
&lt;br /&gt;
However, with the new requirements, in addition we need to add completely new code.&lt;br /&gt;
&lt;br /&gt;
== Changing Existing Files ==&lt;br /&gt;
This sub section details what is to be changed in the existing code.&lt;br /&gt;
=== Files to be changed === &lt;br /&gt;
*lottery_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Current Code ===&lt;br /&gt;
This is current code for bidding assignment. The code will basically get target assignment and then get all topics and teams for the assignment. Then it will assign priority of each team-topic pair according to user preference  for each user, and append it to priority information list. Afterward it sends priority information along with maximum team size information to web-server and rearranging the priority order according to top-trading cycle algorithm, and pass returned result to create_new_teams_for_bidding_response function for bidding handling on topics with preferences and run_intelligent_bid function for bidding handling for leftover assignment as well as cleaning up.&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
    end&lt;br /&gt;
    data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
    url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
    begin&lt;br /&gt;
      response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
      # store each summary in a hashmap and use the question as the key&lt;br /&gt;
      teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
      create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
      run_intelligent_bid(assignment)&lt;br /&gt;
    rescue =&amp;gt; err&lt;br /&gt;
      flash[:error] = err.message&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
=== Proposed Changes ===&lt;br /&gt;
&lt;br /&gt;
To accommodate this code to fit our needs, we have proposed to add 3 new variable&lt;br /&gt;
&lt;br /&gt;
  bidding_for_reviews?&lt;br /&gt;
  topic_per_team&lt;br /&gt;
  team_per_topic&lt;br /&gt;
&lt;br /&gt;
new_intelligent_property will check if an assignment is using conference paper bidding or team assignment bidding, it will be true if bidding is on conference paper review and false if bidding is on team assignment; topic_per_team will record required number of topics that can be chosen per a team; and team_per_topic will record required number of teams that can be assigned to a topic.&lt;br /&gt;
&lt;br /&gt;
=== Proposed Code ===&lt;br /&gt;
&lt;br /&gt;
Then we will change the run_intelligent_assignment function to implementation as below:&lt;br /&gt;
&lt;br /&gt;
  def run_intelligent_assignment&lt;br /&gt;
    priority_info = []&lt;br /&gt;
    assignment = Assignment.find_by(id: params[:id])&lt;br /&gt;
    topics = assignment.sign_up_topics&lt;br /&gt;
    teams = assignment.teams&lt;br /&gt;
    teams.each do |team|&lt;br /&gt;
      # grab student id and list of bids&lt;br /&gt;
      bids = []&lt;br /&gt;
      topics.each do |topic|&lt;br /&gt;
        bid_record = Bid.find_by(team_id: team.id, topic_id: topic.id)&lt;br /&gt;
        bids &amp;lt;&amp;lt; (bid_record.nil? ? 0 : bid_record.priority ||= 0)&lt;br /&gt;
      end&lt;br /&gt;
      if new_intelligent_property&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids }&lt;br /&gt;
      else&lt;br /&gt;
        team.users.each { |user| priority_info &amp;lt;&amp;lt; { pid: user.id, ranks: bids } if bids.uniq != [0] }&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    if !new_intelligent_property&lt;br /&gt;
      data = { users: priority_info, max_team_size: assignment.max_team_size }&lt;br /&gt;
      url = WEBSERVICE_CONFIG[&amp;quot;topic_bidding_webservice_url&amp;quot;]&lt;br /&gt;
      begin&lt;br /&gt;
        response = RestClient.post url, data.to_json, content_type: :json, accept: :json&lt;br /&gt;
        # store each summary in a hashmap and use the question as the key&lt;br /&gt;
        teams = JSON.parse(response)[&amp;quot;teams&amp;quot;]&lt;br /&gt;
        create_new_teams_for_bidding_response(teams, assignment)&lt;br /&gt;
        run_intelligent_bid(assignment)&lt;br /&gt;
      rescue =&amp;gt; err&lt;br /&gt;
        flash[:error] = err.message&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      run_conference_bid(teams, assignment, topic_per_team, team_per_topic)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to controller: 'tree_display', action: 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
== Additional Changes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With this change, we will have to add a new function: run_conference_bid(teams, assignment), with pseudo-code as shown below:&lt;br /&gt;
&lt;br /&gt;
  def run_conference_bid teams, assignment, topic_per_team, team_per_topic&lt;br /&gt;
    set topic_set to false;&lt;br /&gt;
    for each team in teams&lt;br /&gt;
      append the team in team_list&lt;br /&gt;
      retrieve bidding ranks of each team&lt;br /&gt;
      sum all rank values in list&lt;br /&gt;
      for each topic priority/rank value in ranks list&lt;br /&gt;
        if topic_set is false&lt;br /&gt;
           append topic_id to topic_list&lt;br /&gt;
        end if&lt;br /&gt;
        calculate percentage of the rank value in comparison to sum of rank values &lt;br /&gt;
        if sum is 0 &lt;br /&gt;
          change percentage to 1/length_of_rank_list&lt;br /&gt;
        end if&lt;br /&gt;
        score rank value by doing (percent_rank_values *(number_of_topics^2) + (number_of_topics^2) / length_of_rank_list)&lt;br /&gt;
        append [team_id, score] to team_scores dictionary with team_id as key&lt;br /&gt;
      end for&lt;br /&gt;
      set topic_set to true&lt;br /&gt;
    end for&lt;br /&gt;
    sort team_scores dictionary by values/scores in descending order&lt;br /&gt;
    for score in team_scores&lt;br /&gt;
      if team not in team_list or topic not in topic_list&lt;br /&gt;
        remove score&lt;br /&gt;
        continue to next iteration&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id to topic_assignment list&lt;br /&gt;
      if number of occurrences of current topic in topic_assignment is same as topic_per_team&lt;br /&gt;
        remove this topic_id from topic_list&lt;br /&gt;
      end if&lt;br /&gt;
      append team_id to team_assignment list&lt;br /&gt;
      if number of occurrences of current team in team_assignment is same as team_per_topic&lt;br /&gt;
        remove this team_id from team_list&lt;br /&gt;
      end if&lt;br /&gt;
      append topic_id and team_id pair to team_bids&lt;br /&gt;
    end for&lt;br /&gt;
    save sign up information stored in team_bids to database&lt;br /&gt;
  end def&lt;br /&gt;
&lt;br /&gt;
=Test Plan=&lt;br /&gt;
&lt;br /&gt;
===Manual Testing===&lt;br /&gt;
* UI testing of the implemented functionality to be done.&lt;br /&gt;
&lt;br /&gt;
    1. Log in as a participants/student&lt;br /&gt;
&lt;br /&gt;
    2. Go to Assignment&lt;br /&gt;
&lt;br /&gt;
    3. Go to Other's works and check preferred conference paper topics to bid on reviewing&lt;br /&gt;
&lt;br /&gt;
    4. Click submit and wait for bidding deadline&lt;br /&gt;
&lt;br /&gt;
    5. After deadline reaches, go back to assignment and click on Other's work to view topics assigned for reviewing&lt;br /&gt;
&lt;br /&gt;
===Automated Test Cases===&lt;br /&gt;
* TDD and Feature Test cases to be written. For instance we would do Rspec test on cases below:&lt;br /&gt;
** Test on score calculation, see if the calculation gives right scoring distribution when no preference is given, when one preference is given, and when multiple preferences are given;&lt;br /&gt;
** Test on preference levels matching, check if the algorithm is match first, second, third, and so on preferences and evaluating them correctly;&lt;br /&gt;
** Test if teams per topic or topics per team can exceed required number by assigning many team with same first preference and assigning many team with multiple preferences (preference number per team &amp;gt; number of topics/2);&lt;br /&gt;
* For the Rspec tests, we will have to create object of team, assignment, and ranks. A sample team object in JSON format would be:&lt;br /&gt;
  {&amp;quot;users&amp;quot;:[{&amp;quot;ranks&amp;quot;:[1,0,2,3], &amp;quot;pid&amp;quot;:1023}],&amp;quot;max_team_size&amp;quot;:1}&lt;br /&gt;
* The objects would be generated inside the spec file lottery_controller_spec.rb using model object initializer;&lt;br /&gt;
&lt;br /&gt;
===Edge cases===&lt;br /&gt;
&lt;br /&gt;
* Case 1: No reviewer submits a list of preferred topics to review&lt;br /&gt;
&lt;br /&gt;
* Case 2: All reviewers submits exactly the same list of topics to review.&lt;/div&gt;</summary>
		<author><name>Bsingh8</name></author>
	</entry>
</feed>