<?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=Sbekkem</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=Sbekkem"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Sbekkem"/>
	<updated>2026-10-02T04:32:15Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124663</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124663"/>
		<updated>2019-04-27T02:21:49Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Similarity to previous implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar review bidding feature was implemented in the previous semester, by making use of the '''Top Trading Cycles'''(TTC) algorithm. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, there were a few issues with that implementation, notably:&lt;br /&gt;
*The lack of color-coding feature.&lt;br /&gt;
Solution: We implmented the color coding feature in our bidding list and the selection list. Following is the screenshot for that implementation. &lt;br /&gt;
* Ordering was done by team IDs, which is not a reasonable ordering.&lt;br /&gt;
* The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
* The UI could have been cleaner.&lt;br /&gt;
Solution: Some of their existing code was not DRY and they had some smelly code in their implementation. We have tried to remove most of these inconsistencies in the code. &lt;br /&gt;
* There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
Solution: We have implemented the two lists as seen below:&lt;br /&gt;
[[File:sri4.JPG]]&lt;br /&gt;
[[File:sri5.JPG]]&lt;br /&gt;
&lt;br /&gt;
* There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
Solution: After much deliberation, this feature is not required.&lt;br /&gt;
* This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
Solution: The project required us to implement review_bids and student_review models, controllers and view for student_review. We also applied migrations to the existing database to incorporate this functionality.&lt;br /&gt;
* Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to &amp;quot;bid&amp;quot; for topics that they want to do as an assignment. We plan to implement the same bidding feature for reviewing others' work, which is currently assigned on a &amp;quot;first-come-first-serve&amp;quot; basis. &lt;br /&gt;
&lt;br /&gt;
The current first-come-first-serve approach to assigning reviews to students is not efficient since sometimes the same project is requested to be reviewed by multiple students, while other projects are not in demand. By letting the students bid on topics they're interested in, the reviews are assigned more efficiently based on user interest.&lt;br /&gt;
&lt;br /&gt;
In this project we will make use of the Top Trading Cycles algorithm on Expertiza, to implement the review-bidding feature.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Before talking about the functionality of review mapping, it's necessary to describe some of the related models and controllers in Expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding feature for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Use Case Diagram===&lt;br /&gt;
[[File:Review_use_case.PNG‎]]&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
Currently, Expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, the method &amp;quot;add_reviewer&amp;quot; is invoked when students try to request a peer review. When it's done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
To understand the basic workflow of bidding on topics, we can look at the LotteryController:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Firstly, teams have different preferences towards available topics. For example, let's say there are three topics within an assignment, namely A, B and C and there are 4 teams W, X, Y, Z. Let's assume each teams preferred order of topics is as follows:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to the back-end service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to let the teams have a fair bidding over the topics.&lt;br /&gt;
&lt;br /&gt;
Now, consider a similar bidding approach to peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to respond. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu, and Tayfun Sonmez have described Top Trading Cycles Mechanism. The intuition of the mechanism is students who have the highest priorities are allowed to trade the schools. Students who are assigned to schools are removed and other students who have the highest priority will compete for schools. The mechanism is as follows:&lt;br /&gt;
&lt;br /&gt;
Step1: Each school has a counter (No. of seats/ capacity). Each student has a priority list. Each school points to the student who has the highest priority to the school. A cycle is formed which is an ordered&lt;br /&gt;
list (s1, i1, s2, ...., sk,ik). Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
Step k: Remaining students point to their favorite school among the remaining schools and each remaining school points to the student with the highest priority among the remaining students. There is at least one student. Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
The algorithm terminates when all students are assigned a seat.&lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The following summary of how the algorithm works, is taken from the &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
Based on this approach, in the existing implementation of Expertiza, we have match_new_teams_to_topics method in the lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review.&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for the review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as inheritance. The Delegation pattern will help us reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled_Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us the demand density for each project to be reviewed, the list of all available topics to review and the list of topics selected already. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Color Coding Scheme:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The color coding scheme would range from Red for the most in-demand topics to green for the least contested topics. &amp;lt;br&amp;gt;&lt;br /&gt;
The top 10% of in-demand topics will be coded in Red, the next 30% of the topics will be in orange, the next 30% in yellow and the last 30% in the green. We are using percentages instead of hard-coding the color coding scheme so that it works dynamically with changing number of students. &amp;lt;br&amp;gt;&lt;br /&gt;
After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm.&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle bidding data called ReviewBid is created. ReviewBid contains bidding assignment information, its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participants bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
Allow Instructor to set review strategy to '''bidding''': &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:sri1.JPG]] &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After setting the review strategy to  '''bidding''', participants are assigned a default bidding list, ordered by topic's name.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Default_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Participants can drag the items up or down to alter the priority.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Altered_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instructors can start bidding by clicking the following icon.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:sri3.JPG]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the bidding is done, participants can login and see what they are assigned with.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_result.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Automated tests are to be written for model ReviewBid, controller ReviewBidController. We also plan to write basic tests to check the correctness of Gale Shapley algorithm.&lt;br /&gt;
&lt;br /&gt;
UI Tests:&lt;br /&gt;
&lt;br /&gt;
In addition to automated tests we will also perform manual testing of the newly added features which include the following:&lt;br /&gt;
&lt;br /&gt;
1. The student should be able to bid the reviews when Professor enables bid option for students on that particular assignment.&lt;br /&gt;
&lt;br /&gt;
2. The reviews prioritized by the student should show colors i.e. green, orange and red indicating how likely he is going to get the review that he bid.&lt;br /&gt;
&lt;br /&gt;
3. At maximum, a student should be able to four assignments.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents ]&lt;br /&gt;
# CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# Pull Request #1322 (E1856. Allow reviewers to bid on what to review) [https://github.com/expertiza/expertiza/pull/1322 ]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Sri5.JPG&amp;diff=124662</id>
		<title>File:Sri5.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Sri5.JPG&amp;diff=124662"/>
		<updated>2019-04-27T02:20:58Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Sri4.JPG&amp;diff=124661</id>
		<title>File:Sri4.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Sri4.JPG&amp;diff=124661"/>
		<updated>2019-04-27T02:20:47Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124657</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124657"/>
		<updated>2019-04-27T02:15:45Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar review bidding feature was implemented in the previous semester, by making use of the '''Top Trading Cycles'''(TTC) algorithm. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, there were a few issues with that implementation, notably:&lt;br /&gt;
*The lack of color-coding feature.&lt;br /&gt;
Solution: We implmented the color coding feature in our bidding list and the selection list. Following is the screenshot for that implementation. &lt;br /&gt;
* Ordering was done by team IDs, which is not a reasonable ordering.&lt;br /&gt;
* The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
* The UI could have been cleaner.&lt;br /&gt;
Solution: Some of their existing code was not DRY and they had some smelly code in their implementation. We have tried to remove most of these inconsistencies in the code. &lt;br /&gt;
* There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
Solution: We have implemented the two lists as seen below:&lt;br /&gt;
[[File:Dde1.png|thumb|center|400px]]&lt;br /&gt;
[[File:Dde2.png]]{ width: 100% !important; height: auto !important; }&lt;br /&gt;
&lt;br /&gt;
* There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
Solution: After much deliberation, this feature is not required.&lt;br /&gt;
* This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
Solution: The project required us to implement review_bids and student_review models, controllers and view for student_review. We also applied migrations to the existing database to incorporate this functionality.&lt;br /&gt;
* Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to &amp;quot;bid&amp;quot; for topics that they want to do as an assignment. We plan to implement the same bidding feature for reviewing others' work, which is currently assigned on a &amp;quot;first-come-first-serve&amp;quot; basis. &lt;br /&gt;
&lt;br /&gt;
The current first-come-first-serve approach to assigning reviews to students is not efficient since sometimes the same project is requested to be reviewed by multiple students, while other projects are not in demand. By letting the students bid on topics they're interested in, the reviews are assigned more efficiently based on user interest.&lt;br /&gt;
&lt;br /&gt;
In this project we will make use of the Top Trading Cycles algorithm on Expertiza, to implement the review-bidding feature.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Before talking about the functionality of review mapping, it's necessary to describe some of the related models and controllers in Expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding feature for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Use Case Diagram===&lt;br /&gt;
[[File:Review_use_case.PNG‎]]&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
Currently, Expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, the method &amp;quot;add_reviewer&amp;quot; is invoked when students try to request a peer review. When it's done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
To understand the basic workflow of bidding on topics, we can look at the LotteryController:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Firstly, teams have different preferences towards available topics. For example, let's say there are three topics within an assignment, namely A, B and C and there are 4 teams W, X, Y, Z. Let's assume each teams preferred order of topics is as follows:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to the back-end service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to let the teams have a fair bidding over the topics.&lt;br /&gt;
&lt;br /&gt;
Now, consider a similar bidding approach to peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to respond. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu, and Tayfun Sonmez have described Top Trading Cycles Mechanism. The intuition of the mechanism is students who have the highest priorities are allowed to trade the schools. Students who are assigned to schools are removed and other students who have the highest priority will compete for schools. The mechanism is as follows:&lt;br /&gt;
&lt;br /&gt;
Step1: Each school has a counter (No. of seats/ capacity). Each student has a priority list. Each school points to the student who has the highest priority to the school. A cycle is formed which is an ordered&lt;br /&gt;
list (s1, i1, s2, ...., sk,ik). Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
Step k: Remaining students point to their favorite school among the remaining schools and each remaining school points to the student with the highest priority among the remaining students. There is at least one student. Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
The algorithm terminates when all students are assigned a seat.&lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The following summary of how the algorithm works, is taken from the &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
Based on this approach, in the existing implementation of Expertiza, we have match_new_teams_to_topics method in the lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review.&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for the review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as inheritance. The Delegation pattern will help us reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled_Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us the demand density for each project to be reviewed, the list of all available topics to review and the list of topics selected already. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Color Coding Scheme:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The color coding scheme would range from Red for the most in-demand topics to green for the least contested topics. &amp;lt;br&amp;gt;&lt;br /&gt;
The top 10% of in-demand topics will be coded in Red, the next 30% of the topics will be in orange, the next 30% in yellow and the last 30% in the green. We are using percentages instead of hard-coding the color coding scheme so that it works dynamically with changing number of students. &amp;lt;br&amp;gt;&lt;br /&gt;
After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm.&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle bidding data called ReviewBid is created. ReviewBid contains bidding assignment information, its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participants bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
Allow Instructor to set review strategy to '''bidding''': &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:sri1.JPG]] &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After setting the review strategy to  '''bidding''', participants are assigned a default bidding list, ordered by topic's name.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Default_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Participants can drag the items up or down to alter the priority.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Altered_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instructors can start bidding by clicking the following icon.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:sri3.JPG]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the bidding is done, participants can login and see what they are assigned with.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_result.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Automated tests are to be written for model ReviewBid, controller ReviewBidController. We also plan to write basic tests to check the correctness of Gale Shapley algorithm.&lt;br /&gt;
&lt;br /&gt;
UI Tests:&lt;br /&gt;
&lt;br /&gt;
In addition to automated tests we will also perform manual testing of the newly added features which include the following:&lt;br /&gt;
&lt;br /&gt;
1. The student should be able to bid the reviews when Professor enables bid option for students on that particular assignment.&lt;br /&gt;
&lt;br /&gt;
2. The reviews prioritized by the student should show colors i.e. green, orange and red indicating how likely he is going to get the review that he bid.&lt;br /&gt;
&lt;br /&gt;
3. At maximum, a student should be able to four assignments.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents ]&lt;br /&gt;
# CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# Pull Request #1322 (E1856. Allow reviewers to bid on what to review) [https://github.com/expertiza/expertiza/pull/1322 ]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Sri3.JPG&amp;diff=124656</id>
		<title>File:Sri3.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Sri3.JPG&amp;diff=124656"/>
		<updated>2019-04-27T02:15:09Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124653</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124653"/>
		<updated>2019-04-27T02:13:23Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar review bidding feature was implemented in the previous semester, by making use of the '''Top Trading Cycles'''(TTC) algorithm. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, there were a few issues with that implementation, notably:&lt;br /&gt;
*The lack of color-coding feature.&lt;br /&gt;
Solution: We implmented the color coding feature in our bidding list and the selection list. Following is the screenshot for that implementation. &lt;br /&gt;
* Ordering was done by team IDs, which is not a reasonable ordering.&lt;br /&gt;
* The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
* The UI could have been cleaner.&lt;br /&gt;
Solution: Some of their existing code was not DRY and they had some smelly code in their implementation. We have tried to remove most of these inconsistencies in the code. &lt;br /&gt;
* There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
Solution: We have implemented the two lists as seen below:&lt;br /&gt;
[[File:Dde1.png|border]]&lt;br /&gt;
[[File:Dde2.png]]{ width: 100% !important; height: auto !important; }&lt;br /&gt;
&lt;br /&gt;
* There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
Solution: After much deliberation, this feature is not required.&lt;br /&gt;
* This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
Solution: The project required us to implement review_bids and student_review models, controllers and view for student_review. We also applied migrations to the existing database to incorporate this functionality.&lt;br /&gt;
* Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to &amp;quot;bid&amp;quot; for topics that they want to do as an assignment. We plan to implement the same bidding feature for reviewing others' work, which is currently assigned on a &amp;quot;first-come-first-serve&amp;quot; basis. &lt;br /&gt;
&lt;br /&gt;
The current first-come-first-serve approach to assigning reviews to students is not efficient since sometimes the same project is requested to be reviewed by multiple students, while other projects are not in demand. By letting the students bid on topics they're interested in, the reviews are assigned more efficiently based on user interest.&lt;br /&gt;
&lt;br /&gt;
In this project we will make use of the Top Trading Cycles algorithm on Expertiza, to implement the review-bidding feature.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Before talking about the functionality of review mapping, it's necessary to describe some of the related models and controllers in Expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding feature for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Use Case Diagram===&lt;br /&gt;
[[File:Review_use_case.PNG‎]]&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
Currently, Expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, the method &amp;quot;add_reviewer&amp;quot; is invoked when students try to request a peer review. When it's done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
To understand the basic workflow of bidding on topics, we can look at the LotteryController:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Firstly, teams have different preferences towards available topics. For example, let's say there are three topics within an assignment, namely A, B and C and there are 4 teams W, X, Y, Z. Let's assume each teams preferred order of topics is as follows:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to the back-end service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to let the teams have a fair bidding over the topics.&lt;br /&gt;
&lt;br /&gt;
Now, consider a similar bidding approach to peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to respond. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu, and Tayfun Sonmez have described Top Trading Cycles Mechanism. The intuition of the mechanism is students who have the highest priorities are allowed to trade the schools. Students who are assigned to schools are removed and other students who have the highest priority will compete for schools. The mechanism is as follows:&lt;br /&gt;
&lt;br /&gt;
Step1: Each school has a counter (No. of seats/ capacity). Each student has a priority list. Each school points to the student who has the highest priority to the school. A cycle is formed which is an ordered&lt;br /&gt;
list (s1, i1, s2, ...., sk,ik). Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
Step k: Remaining students point to their favorite school among the remaining schools and each remaining school points to the student with the highest priority among the remaining students. There is at least one student. Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
The algorithm terminates when all students are assigned a seat.&lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The following summary of how the algorithm works, is taken from the &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
Based on this approach, in the existing implementation of Expertiza, we have match_new_teams_to_topics method in the lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review.&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for the review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as inheritance. The Delegation pattern will help us reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled_Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us the demand density for each project to be reviewed, the list of all available topics to review and the list of topics selected already. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Color Coding Scheme:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The color coding scheme would range from Red for the most in-demand topics to green for the least contested topics. &amp;lt;br&amp;gt;&lt;br /&gt;
The top 10% of in-demand topics will be coded in Red, the next 30% of the topics will be in orange, the next 30% in yellow and the last 30% in the green. We are using percentages instead of hard-coding the color coding scheme so that it works dynamically with changing number of students. &amp;lt;br&amp;gt;&lt;br /&gt;
After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm.&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle bidding data called ReviewBid is created. ReviewBid contains bidding assignment information, its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participants bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
Allow Instructor to set review strategy to '''bidding''': &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:sri1.JPG]] &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After setting the review strategy to  '''bidding''', participants are assigned a default bidding list, ordered by topic's name.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Default_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Participants can drag the items up or down to alter the priority.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Altered_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instructors can start bidding by clicking the following icon.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_icon.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the bidding is done, participants can login and see what they are assigned with.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_result.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Automated tests are to be written for model ReviewBid, controller ReviewBidController. We also plan to write basic tests to check the correctness of Gale Shapley algorithm.&lt;br /&gt;
&lt;br /&gt;
UI Tests:&lt;br /&gt;
&lt;br /&gt;
In addition to automated tests we will also perform manual testing of the newly added features which include the following:&lt;br /&gt;
&lt;br /&gt;
1. The student should be able to bid the reviews when Professor enables bid option for students on that particular assignment.&lt;br /&gt;
&lt;br /&gt;
2. The reviews prioritized by the student should show colors i.e. green, orange and red indicating how likely he is going to get the review that he bid.&lt;br /&gt;
&lt;br /&gt;
3. At maximum, a student should be able to four assignments.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents ]&lt;br /&gt;
# CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# Pull Request #1322 (E1856. Allow reviewers to bid on what to review) [https://github.com/expertiza/expertiza/pull/1322 ]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124649</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124649"/>
		<updated>2019-04-27T02:11:41Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar review bidding feature was implemented in the previous semester, by making use of the '''Top Trading Cycles'''(TTC) algorithm. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, there were a few issues with that implementation, notably:&lt;br /&gt;
*The lack of color-coding feature.&lt;br /&gt;
Solution: We implmented the color coding feature in our bidding list and the selection list. Following is the screenshot for that implementation. &lt;br /&gt;
* Ordering was done by team IDs, which is not a reasonable ordering.&lt;br /&gt;
* The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
* The UI could have been cleaner.&lt;br /&gt;
Solution: Some of their existing code was not DRY and they had some smelly code in their implementation. We have tried to remove most of these inconsistencies in the code. &lt;br /&gt;
* There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
Solution: We have implemented the two lists as seen below:&lt;br /&gt;
[[File:Dde1.png]]{ width: 100% !important; height: auto !important; }&lt;br /&gt;
[[File:Dde2.png]]{ width: 100% !important; height: auto !important; }&lt;br /&gt;
&lt;br /&gt;
* There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
Solution: After much deliberation, this feature is not required.&lt;br /&gt;
* This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
Solution: The project required us to implement review_bids and student_review models, controllers and view for student_review. We also applied migrations to the existing database to incorporate this functionality.&lt;br /&gt;
* Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to &amp;quot;bid&amp;quot; for topics that they want to do as an assignment. We plan to implement the same bidding feature for reviewing others' work, which is currently assigned on a &amp;quot;first-come-first-serve&amp;quot; basis. &lt;br /&gt;
&lt;br /&gt;
The current first-come-first-serve approach to assigning reviews to students is not efficient since sometimes the same project is requested to be reviewed by multiple students, while other projects are not in demand. By letting the students bid on topics they're interested in, the reviews are assigned more efficiently based on user interest.&lt;br /&gt;
&lt;br /&gt;
In this project we will make use of the Top Trading Cycles algorithm on Expertiza, to implement the review-bidding feature.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Before talking about the functionality of review mapping, it's necessary to describe some of the related models and controllers in Expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding feature for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Use Case Diagram===&lt;br /&gt;
[[File:Review_use_case.PNG‎]]&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
Currently, Expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, the method &amp;quot;add_reviewer&amp;quot; is invoked when students try to request a peer review. When it's done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
To understand the basic workflow of bidding on topics, we can look at the LotteryController:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Firstly, teams have different preferences towards available topics. For example, let's say there are three topics within an assignment, namely A, B and C and there are 4 teams W, X, Y, Z. Let's assume each teams preferred order of topics is as follows:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to the back-end service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to let the teams have a fair bidding over the topics.&lt;br /&gt;
&lt;br /&gt;
Now, consider a similar bidding approach to peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to respond. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu, and Tayfun Sonmez have described Top Trading Cycles Mechanism. The intuition of the mechanism is students who have the highest priorities are allowed to trade the schools. Students who are assigned to schools are removed and other students who have the highest priority will compete for schools. The mechanism is as follows:&lt;br /&gt;
&lt;br /&gt;
Step1: Each school has a counter (No. of seats/ capacity). Each student has a priority list. Each school points to the student who has the highest priority to the school. A cycle is formed which is an ordered&lt;br /&gt;
list (s1, i1, s2, ...., sk,ik). Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
Step k: Remaining students point to their favorite school among the remaining schools and each remaining school points to the student with the highest priority among the remaining students. There is at least one student. Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
The algorithm terminates when all students are assigned a seat.&lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The following summary of how the algorithm works, is taken from the &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
Based on this approach, in the existing implementation of Expertiza, we have match_new_teams_to_topics method in the lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review.&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for the review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as inheritance. The Delegation pattern will help us reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled_Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us the demand density for each project to be reviewed, the list of all available topics to review and the list of topics selected already. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Color Coding Scheme:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The color coding scheme would range from Red for the most in-demand topics to green for the least contested topics. &amp;lt;br&amp;gt;&lt;br /&gt;
The top 10% of in-demand topics will be coded in Red, the next 30% of the topics will be in orange, the next 30% in yellow and the last 30% in the green. We are using percentages instead of hard-coding the color coding scheme so that it works dynamically with changing number of students. &amp;lt;br&amp;gt;&lt;br /&gt;
After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm.&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle bidding data called ReviewBid is created. ReviewBid contains bidding assignment information, its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participants bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
Allow Instructor to set review strategy to '''bidding''': &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:sri1.JPG]] &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After setting the review strategy to  '''bidding''', participants are assigned a default bidding list, ordered by topic's name.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Default_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Participants can drag the items up or down to alter the priority.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Altered_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instructors can start bidding by clicking the following icon.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:sri2.JPG]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the bidding is done, participants can login and see what they are assigned with.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_result.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Automated tests are to be written for model ReviewBid, controller ReviewBidController. We also plan to write basic tests to check the correctness of Gale Shapley algorithm.&lt;br /&gt;
&lt;br /&gt;
UI Tests:&lt;br /&gt;
&lt;br /&gt;
In addition to automated tests we will also perform manual testing of the newly added features which include the following:&lt;br /&gt;
&lt;br /&gt;
1. The student should be able to bid the reviews when Professor enables bid option for students on that particular assignment.&lt;br /&gt;
&lt;br /&gt;
2. The reviews prioritized by the student should show colors i.e. green, orange and red indicating how likely he is going to get the review that he bid.&lt;br /&gt;
&lt;br /&gt;
3. At maximum, a student should be able to four assignments.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents ]&lt;br /&gt;
# CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# Pull Request #1322 (E1856. Allow reviewers to bid on what to review) [https://github.com/expertiza/expertiza/pull/1322 ]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Sri2.JPG&amp;diff=124648</id>
		<title>File:Sri2.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Sri2.JPG&amp;diff=124648"/>
		<updated>2019-04-27T02:11:15Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124646</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124646"/>
		<updated>2019-04-27T02:09:03Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar review bidding feature was implemented in the previous semester, by making use of the '''Top Trading Cycles'''(TTC) algorithm. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, there were a few issues with that implementation, notably:&lt;br /&gt;
*The lack of color-coding feature.&lt;br /&gt;
Solution: We implmented the color coding feature in our bidding list and the selection list. Following is the screenshot for that implementation. &lt;br /&gt;
* Ordering was done by team IDs, which is not a reasonable ordering.&lt;br /&gt;
* The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
* The UI could have been cleaner.&lt;br /&gt;
Solution: Some of their existing code was not DRY and they had some smelly code in their implementation. We have tried to remove most of these inconsistencies in the code. &lt;br /&gt;
* There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
Solution: We have implemented the two lists as seen below:&lt;br /&gt;
[[File:Dde1.png|100px|Image: 100 pixels]]&lt;br /&gt;
[[File:Dde2.png|100px|Image: 100 pixels]]&lt;br /&gt;
&lt;br /&gt;
* There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
Solution: After much deliberation, this feature is not required.&lt;br /&gt;
* This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
Solution: The project required us to implement review_bids and student_review models, controllers and view for student_review. We also applied migrations to the existing database to incorporate this functionality.&lt;br /&gt;
* Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to &amp;quot;bid&amp;quot; for topics that they want to do as an assignment. We plan to implement the same bidding feature for reviewing others' work, which is currently assigned on a &amp;quot;first-come-first-serve&amp;quot; basis. &lt;br /&gt;
&lt;br /&gt;
The current first-come-first-serve approach to assigning reviews to students is not efficient since sometimes the same project is requested to be reviewed by multiple students, while other projects are not in demand. By letting the students bid on topics they're interested in, the reviews are assigned more efficiently based on user interest.&lt;br /&gt;
&lt;br /&gt;
In this project we will make use of the Top Trading Cycles algorithm on Expertiza, to implement the review-bidding feature.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Before talking about the functionality of review mapping, it's necessary to describe some of the related models and controllers in Expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding feature for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Use Case Diagram===&lt;br /&gt;
[[File:Review_use_case.PNG‎]]&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
Currently, Expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, the method &amp;quot;add_reviewer&amp;quot; is invoked when students try to request a peer review. When it's done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
To understand the basic workflow of bidding on topics, we can look at the LotteryController:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Firstly, teams have different preferences towards available topics. For example, let's say there are three topics within an assignment, namely A, B and C and there are 4 teams W, X, Y, Z. Let's assume each teams preferred order of topics is as follows:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to the back-end service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to let the teams have a fair bidding over the topics.&lt;br /&gt;
&lt;br /&gt;
Now, consider a similar bidding approach to peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to respond. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu, and Tayfun Sonmez have described Top Trading Cycles Mechanism. The intuition of the mechanism is students who have the highest priorities are allowed to trade the schools. Students who are assigned to schools are removed and other students who have the highest priority will compete for schools. The mechanism is as follows:&lt;br /&gt;
&lt;br /&gt;
Step1: Each school has a counter (No. of seats/ capacity). Each student has a priority list. Each school points to the student who has the highest priority to the school. A cycle is formed which is an ordered&lt;br /&gt;
list (s1, i1, s2, ...., sk,ik). Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
Step k: Remaining students point to their favorite school among the remaining schools and each remaining school points to the student with the highest priority among the remaining students. There is at least one student. Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
The algorithm terminates when all students are assigned a seat.&lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The following summary of how the algorithm works, is taken from the &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
Based on this approach, in the existing implementation of Expertiza, we have match_new_teams_to_topics method in the lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review.&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for the review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as inheritance. The Delegation pattern will help us reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled_Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us the demand density for each project to be reviewed, the list of all available topics to review and the list of topics selected already. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Color Coding Scheme:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The color coding scheme would range from Red for the most in-demand topics to green for the least contested topics. &amp;lt;br&amp;gt;&lt;br /&gt;
The top 10% of in-demand topics will be coded in Red, the next 30% of the topics will be in orange, the next 30% in yellow and the last 30% in the green. We are using percentages instead of hard-coding the color coding scheme so that it works dynamically with changing number of students. &amp;lt;br&amp;gt;&lt;br /&gt;
After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm.&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle bidding data called ReviewBid is created. ReviewBid contains bidding assignment information, its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participants bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
Allow Instructor to set review strategy to '''bidding''': &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:sri1.JPG]] &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After setting the review strategy to  '''bidding''', participants are assigned a default bidding list, ordered by topic's name.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Default_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Participants can drag the items up or down to alter the priority.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Altered_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instructors can start bidding by clicking the following icon.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_icon.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the bidding is done, participants can login and see what they are assigned with.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_result.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Automated tests are to be written for model ReviewBid, controller ReviewBidController. We also plan to write basic tests to check the correctness of Gale Shapley algorithm.&lt;br /&gt;
&lt;br /&gt;
UI Tests:&lt;br /&gt;
&lt;br /&gt;
In addition to automated tests we will also perform manual testing of the newly added features which include the following:&lt;br /&gt;
&lt;br /&gt;
1. The student should be able to bid the reviews when Professor enables bid option for students on that particular assignment.&lt;br /&gt;
&lt;br /&gt;
2. The reviews prioritized by the student should show colors i.e. green, orange and red indicating how likely he is going to get the review that he bid.&lt;br /&gt;
&lt;br /&gt;
3. At maximum, a student should be able to four assignments.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents ]&lt;br /&gt;
# CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# Pull Request #1322 (E1856. Allow reviewers to bid on what to review) [https://github.com/expertiza/expertiza/pull/1322 ]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Sri1.JPG&amp;diff=124645</id>
		<title>File:Sri1.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Sri1.JPG&amp;diff=124645"/>
		<updated>2019-04-27T02:07:18Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124643</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124643"/>
		<updated>2019-04-27T02:04:18Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar review bidding feature was implemented in the previous semester, by making use of the '''Top Trading Cycles'''(TTC) algorithm. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, there were a few issues with that implementation, notably:&lt;br /&gt;
*The lack of color-coding feature.&lt;br /&gt;
Solution: We implmented the color coding feature in our bidding list and the selection list. Following is the screenshot for that implementation. &lt;br /&gt;
* Ordering was done by team IDs, which is not a reasonable ordering.&lt;br /&gt;
* The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
* The UI could have been cleaner.&lt;br /&gt;
Solution: Some of their existing code was not DRY and they had some smelly code in their implementation. We have tried to remove most of these inconsistencies in the code. &lt;br /&gt;
* There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
Solution: We have implemented the two lists as seen below:&lt;br /&gt;
[[File:Dde1.png]]&lt;br /&gt;
[[File:Dde2.png]]&lt;br /&gt;
&lt;br /&gt;
* There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
Solution: After much deliberation, this feature is not required.&lt;br /&gt;
* This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
Solution: The project required us to implement review_bids and student_review models, controllers and view for student_review. We also applied migrations to the existing database to incorporate this functionality.&lt;br /&gt;
* Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to &amp;quot;bid&amp;quot; for topics that they want to do as an assignment. We plan to implement the same bidding feature for reviewing others' work, which is currently assigned on a &amp;quot;first-come-first-serve&amp;quot; basis. &lt;br /&gt;
&lt;br /&gt;
The current first-come-first-serve approach to assigning reviews to students is not efficient since sometimes the same project is requested to be reviewed by multiple students, while other projects are not in demand. By letting the students bid on topics they're interested in, the reviews are assigned more efficiently based on user interest.&lt;br /&gt;
&lt;br /&gt;
In this project we will make use of the Top Trading Cycles algorithm on Expertiza, to implement the review-bidding feature.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Before talking about the functionality of review mapping, it's necessary to describe some of the related models and controllers in Expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding feature for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Use Case Diagram===&lt;br /&gt;
[[File:Review_use_case.PNG‎]]&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
Currently, Expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, the method &amp;quot;add_reviewer&amp;quot; is invoked when students try to request a peer review. When it's done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
To understand the basic workflow of bidding on topics, we can look at the LotteryController:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Firstly, teams have different preferences towards available topics. For example, let's say there are three topics within an assignment, namely A, B and C and there are 4 teams W, X, Y, Z. Let's assume each teams preferred order of topics is as follows:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to the back-end service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to let the teams have a fair bidding over the topics.&lt;br /&gt;
&lt;br /&gt;
Now, consider a similar bidding approach to peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to respond. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu, and Tayfun Sonmez have described Top Trading Cycles Mechanism. The intuition of the mechanism is students who have the highest priorities are allowed to trade the schools. Students who are assigned to schools are removed and other students who have the highest priority will compete for schools. The mechanism is as follows:&lt;br /&gt;
&lt;br /&gt;
Step1: Each school has a counter (No. of seats/ capacity). Each student has a priority list. Each school points to the student who has the highest priority to the school. A cycle is formed which is an ordered&lt;br /&gt;
list (s1, i1, s2, ...., sk,ik). Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
Step k: Remaining students point to their favorite school among the remaining schools and each remaining school points to the student with the highest priority among the remaining students. There is at least one student. Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
The algorithm terminates when all students are assigned a seat.&lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The following summary of how the algorithm works, is taken from the &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
Based on this approach, in the existing implementation of Expertiza, we have match_new_teams_to_topics method in the lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review.&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for the review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as inheritance. The Delegation pattern will help us reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled_Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us the demand density for each project to be reviewed, the list of all available topics to review and the list of topics selected already. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Color Coding Scheme:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The color coding scheme would range from Red for the most in-demand topics to green for the least contested topics. &amp;lt;br&amp;gt;&lt;br /&gt;
The top 10% of in-demand topics will be coded in Red, the next 30% of the topics will be in orange, the next 30% in yellow and the last 30% in the green. We are using percentages instead of hard-coding the color coding scheme so that it works dynamically with changing number of students. &amp;lt;br&amp;gt;&lt;br /&gt;
After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm.&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle bidding data called ReviewBid is created. ReviewBid contains bidding assignment information, its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participants bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
Allow Instructor to set review strategy to '''bidding''': &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Sri_review.jpg]] &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After setting the review strategy to  '''bidding''', participants are assigned a default bidding list, ordered by topic's name.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Default_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Participants can drag the items up or down to alter the priority.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Altered_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instructors can start bidding by clicking the following icon.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_icon.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the bidding is done, participants can login and see what they are assigned with.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_result.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Automated tests are to be written for model ReviewBid, controller ReviewBidController. We also plan to write basic tests to check the correctness of Gale Shapley algorithm.&lt;br /&gt;
&lt;br /&gt;
UI Tests:&lt;br /&gt;
&lt;br /&gt;
In addition to automated tests we will also perform manual testing of the newly added features which include the following:&lt;br /&gt;
&lt;br /&gt;
1. The student should be able to bid the reviews when Professor enables bid option for students on that particular assignment.&lt;br /&gt;
&lt;br /&gt;
2. The reviews prioritized by the student should show colors i.e. green, orange and red indicating how likely he is going to get the review that he bid.&lt;br /&gt;
&lt;br /&gt;
3. At maximum, a student should be able to four assignments.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents ]&lt;br /&gt;
# CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# Pull Request #1322 (E1856. Allow reviewers to bid on what to review) [https://github.com/expertiza/expertiza/pull/1322 ]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124637</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124637"/>
		<updated>2019-04-27T01:59:09Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar review bidding feature was implemented in the previous semester, by making use of the '''Top Trading Cycles'''(TTC) algorithm. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, there were a few issues with that implementation, notably:&lt;br /&gt;
*The lack of color-coding feature.&lt;br /&gt;
Solution: We implmented the color coding feature in our bidding list and the selection list. Following is the screenshot for that implementation. &lt;br /&gt;
* Ordering was done by team IDs, which is not a reasonable ordering.&lt;br /&gt;
* The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
* The UI could have been cleaner.&lt;br /&gt;
Solution: Some of their existing code was not DRY and they had some smelly code in their implementation. We have tried to remove most of these inconsistencies in the code. &lt;br /&gt;
* There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
Solution: We have implemented the two lists as seen below:&lt;br /&gt;
[[File:Dde1.png|400px]]&lt;br /&gt;
[[File:Dde2.png|400px]]&lt;br /&gt;
&lt;br /&gt;
* There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
Solution: After much deliberation, this feature is not required.&lt;br /&gt;
* This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
Solution: The project required us to implement review_bids and student_review models, controllers and view for student_review. We also applied migrations to the existing database to incorporate this functionality.&lt;br /&gt;
* Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to &amp;quot;bid&amp;quot; for topics that they want to do as an assignment. We plan to implement the same bidding feature for reviewing others' work, which is currently assigned on a &amp;quot;first-come-first-serve&amp;quot; basis. &lt;br /&gt;
&lt;br /&gt;
The current first-come-first-serve approach to assigning reviews to students is not efficient since sometimes the same project is requested to be reviewed by multiple students, while other projects are not in demand. By letting the students bid on topics they're interested in, the reviews are assigned more efficiently based on user interest.&lt;br /&gt;
&lt;br /&gt;
In this project we will make use of the Top Trading Cycles algorithm on Expertiza, to implement the review-bidding feature.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Before talking about the functionality of review mapping, it's necessary to describe some of the related models and controllers in Expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding feature for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Use Case Diagram===&lt;br /&gt;
[[File:Review_use_case.PNG‎]]&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
Currently, Expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, the method &amp;quot;add_reviewer&amp;quot; is invoked when students try to request a peer review. When it's done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
To understand the basic workflow of bidding on topics, we can look at the LotteryController:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Firstly, teams have different preferences towards available topics. For example, let's say there are three topics within an assignment, namely A, B and C and there are 4 teams W, X, Y, Z. Let's assume each teams preferred order of topics is as follows:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to the back-end service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to let the teams have a fair bidding over the topics.&lt;br /&gt;
&lt;br /&gt;
Now, consider a similar bidding approach to peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to respond. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu, and Tayfun Sonmez have described Top Trading Cycles Mechanism. The intuition of the mechanism is students who have the highest priorities are allowed to trade the schools. Students who are assigned to schools are removed and other students who have the highest priority will compete for schools. The mechanism is as follows:&lt;br /&gt;
&lt;br /&gt;
Step1: Each school has a counter (No. of seats/ capacity). Each student has a priority list. Each school points to the student who has the highest priority to the school. A cycle is formed which is an ordered&lt;br /&gt;
list (s1, i1, s2, ...., sk,ik). Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
Step k: Remaining students point to their favorite school among the remaining schools and each remaining school points to the student with the highest priority among the remaining students. There is at least one student. Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
The algorithm terminates when all students are assigned a seat.&lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The following summary of how the algorithm works, is taken from the &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
Based on this approach, in the existing implementation of Expertiza, we have match_new_teams_to_topics method in the lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review.&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for the review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as inheritance. The Delegation pattern will help us reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled_Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us the demand density for each project to be reviewed, the list of all available topics to review and the list of topics selected already. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Color Coding Scheme:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The color coding scheme would range from Red for the most in-demand topics to green for the least contested topics. &amp;lt;br&amp;gt;&lt;br /&gt;
The top 10% of in-demand topics will be coded in Red, the next 30% of the topics will be in orange, the next 30% in yellow and the last 30% in the green. We are using percentages instead of hard-coding the color coding scheme so that it works dynamically with changing number of students. &amp;lt;br&amp;gt;&lt;br /&gt;
After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm.&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle bidding data called ReviewBid is created. ReviewBid contains bidding assignment information, its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participants bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
Allow Instructor to set review strategy to '''bidding''': &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:1.jpg]] &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After setting the review strategy to  '''bidding''', participants are assigned a default bidding list, ordered by topic's name.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Default_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Participants can drag the items up or down to alter the priority.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Altered_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instructors can start bidding by clicking the following icon.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_icon.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the bidding is done, participants can login and see what they are assigned with.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_result.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Automated tests are to be written for model ReviewBid, controller ReviewBidController. We also plan to write basic tests to check the correctness of Gale Shapley algorithm.&lt;br /&gt;
&lt;br /&gt;
UI Tests:&lt;br /&gt;
&lt;br /&gt;
In addition to automated tests we will also perform manual testing of the newly added features which include the following:&lt;br /&gt;
&lt;br /&gt;
1. The student should be able to bid the reviews when Professor enables bid option for students on that particular assignment.&lt;br /&gt;
&lt;br /&gt;
2. The reviews prioritized by the student should show colors i.e. green, orange and red indicating how likely he is going to get the review that he bid.&lt;br /&gt;
&lt;br /&gt;
3. At maximum, a student should be able to four assignments.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents ]&lt;br /&gt;
# CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# Pull Request #1322 (E1856. Allow reviewers to bid on what to review) [https://github.com/expertiza/expertiza/pull/1322 ]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:1.JPG&amp;diff=124635</id>
		<title>File:1.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:1.JPG&amp;diff=124635"/>
		<updated>2019-04-27T01:57:42Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: uploaded a new version of &amp;amp;quot;File:1.JPG&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:1.JPG&amp;diff=124634</id>
		<title>File:1.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:1.JPG&amp;diff=124634"/>
		<updated>2019-04-27T01:57:10Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: uploaded a new version of &amp;amp;quot;File:1.JPG&amp;amp;quot;: review_strategy&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124026</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124026"/>
		<updated>2019-04-13T02:30:20Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar review bidding feature was implemented in the previous semester, by making use of the '''Top Trading Cycles'''(TTC) algorithm. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, there were a few issues with that implementation, notably:&lt;br /&gt;
# The lack of color-coding feature.&lt;br /&gt;
# Ordering was done by team IDs, which is not a reasonable ordering.&lt;br /&gt;
# The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
# The UI could have been cleaner.&lt;br /&gt;
# There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
# There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
# This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
# Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to &amp;quot;bid&amp;quot; for topics that they want to do as an assignment. We plan to implement the same bidding feature for reviewing others' work, which is currently assigned on a &amp;quot;first-come-first-serve&amp;quot; basis. &lt;br /&gt;
&lt;br /&gt;
The current first-come-first-serve approach to assigning reviews to students is not efficient since sometimes the same project is requested to be reviewed by multiple students, while other projects are not in demand. By letting the students bid on topics they're interested in, the reviews are assigned more efficiently based on user interest.&lt;br /&gt;
&lt;br /&gt;
In this project we will make use of the Top Trading Cycles algorithm on Expertiza, to implement the review-bidding feature.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Before talking about the functionality of review mapping, it's necessary to describe some of the related models and controllers in Expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding feature for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Use Case Diagram===&lt;br /&gt;
[[File:Review_use_case.PNG‎]]&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
Currently, Expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, the method &amp;quot;add_reviewer&amp;quot; is invoked when students try to request a peer review. When it's done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
To understand the basic workflow of bidding on topics, we can look at the LotteryController:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Firstly, teams have different preferences towards available topics. For example, let's say there are three topics within an assignment, namely A, B and C and there are 4 teams W, X, Y, Z. Let's assume each teams preferred order of topics is as follows:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to the back-end service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to let the teams have a fair bidding over the topics.&lt;br /&gt;
&lt;br /&gt;
Now, consider a similar bidding approach to peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to respond. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu, and Tayfun Sonmez have described Top Trading Cycles Mechanism. The intuition of the mechanism is students who have the highest priorities are allowed to trade the schools. Students who are assigned to schools are removed and other students who have the highest priority will compete for schools. The mechanism is as follows:&lt;br /&gt;
&lt;br /&gt;
Step1: Each school has a counter (No. of seats/ capacity). Each student has a priority list. Each school points to the student who has the highest priority to the school. A cycle is formed which is an ordered&lt;br /&gt;
list (s1, i1, s2, ...., sk,ik). Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
Step k: Remaining students point to their favorite school among the remaining schools and each remaining school points to the student with the highest priority among the remaining students. There is at least one student. Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
The algorithm terminates when all students are assigned a seat.&lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The following summary of how the algorithm works, is taken from the &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
Based on this approach, in the existing implementation of Expertiza, we have match_new_teams_to_topics method in the lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review.&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for the review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as inheritance. The Delegation pattern will help us reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled_Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us the demand density for each project to be reviewed, the list of all available topics to review and the list of topics selected already. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Color Coding Scheme:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The color coding scheme would range from Red for the most in-demand topics to green for the least contested topics. &amp;lt;br&amp;gt;&lt;br /&gt;
The top 10% of in-demand topics will be coded in Red, the next 30% of the topics will be in orange, the next 30% in yellow and the last 30% in the green. We are using percentages instead of hard-coding the color coding scheme so that it works dynamically with changing number of students. &amp;lt;br&amp;gt;&lt;br /&gt;
After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm.&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle bidding data called ReviewBid is created. ReviewBid contains bidding assignment information, its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participants bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
Allow Instructor to set review strategy to '''bidding''': &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Review_strategy.png]] &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After setting the review strategy to  '''bidding''', participants are assigned a default bidding list, ordered by topic's name.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Default_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Participants can drag the items up or down to alter the priority.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Altered_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instructors can start bidding by clicking the following icon.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_icon.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the bidding is done, participants can login and see what they are assigned with.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_result.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Automated tests are to be written for model ReviewBid, controller ReviewBidController. We also plan to write basic tests to check the correctness of Gale Shapley algorithm.&lt;br /&gt;
&lt;br /&gt;
UI Tests:&lt;br /&gt;
&lt;br /&gt;
In addition to automated tests we will also perform manual testing of the newly added features which include the following:&lt;br /&gt;
&lt;br /&gt;
1. The student should be able to bid the reviews when Professor enables bid option for students on that particular assignment.&lt;br /&gt;
&lt;br /&gt;
2. The reviews prioritized by the student should show colors i.e. green, orange and red indicating how likely he is going to get the review that he bid.&lt;br /&gt;
&lt;br /&gt;
3. At maximum, a student should be able to four assignments.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents ]&lt;br /&gt;
# CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# Pull Request #1322 (E1856. Allow reviewers to bid on what to review) [https://github.com/expertiza/expertiza/pull/1322 ]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124024</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124024"/>
		<updated>2019-04-13T02:28:29Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Test Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar review bidding feature was implemented in the previous semester, by making use of the '''Top Trading Cycles'''(TTC) algorithm. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, there were a few issues with that implementation, notably:&lt;br /&gt;
# The lack of color-coding feature.&lt;br /&gt;
# Ordering was done by team IDs, which is not a reasonable ordering.&lt;br /&gt;
# The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
# The UI could have been cleaner.&lt;br /&gt;
# There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
# There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
# This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
# Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to &amp;quot;bid&amp;quot; for topics that they want to do as an assignment. We plan to implement the same bidding feature for reviewing others' work, which is currently assigned on a &amp;quot;first-come-first-serve&amp;quot; basis. &lt;br /&gt;
&lt;br /&gt;
The current first-come-first-serve approach to assigning reviews to students is not efficient since sometimes the same project is requested to be reviewed by multiple students, while other projects are not in demand. By letting the students bid on topics they're interested in, the reviews are assigned more efficiently based on user interest.&lt;br /&gt;
&lt;br /&gt;
In this project we will make use of the Top Trading Cycles algorithm on Expertiza, to implement the review-bidding feature.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Before talking about the functionality of review mapping, it's necessary to describe some of the related models and controllers in Expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding feature for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Use Case Diagram===&lt;br /&gt;
[[File:Review_use_case.PNG‎]]&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
Currently, Expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, the method &amp;quot;add_reviewer&amp;quot; is invoked when students try to request a peer review. When it's done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
To understand the basic workflow of bidding on topics, we can look at the LotteryController:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Firstly, teams have different preferences towards available topics. For example, let's say there are three topics within an assignment, namely A, B and C and there are 4 teams W, X, Y, Z. Let's assume each teams preferred order of topics is as follows:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to the back-end service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to let the teams have a fair bidding over the topics.&lt;br /&gt;
&lt;br /&gt;
Now, consider a similar bidding approach to peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to respond. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu, and Tayfun Sonmez have described Top Trading Cycles Mechanism. The intuition of the mechanism is students who have the highest priorities are allowed to trade the schools. Students who are assigned to schools are removed and other students who have the highest priority will compete for schools. The mechanism is as follows:&lt;br /&gt;
&lt;br /&gt;
Step1: Each school has a counter (No. of seats/ capacity). Each student has a priority list. Each school points to the student who has the highest priority to the school. A cycle is formed which is an ordered&lt;br /&gt;
list (s1, i1, s2, ...., sk,ik). Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
Step k: Remaining students point to their favorite school among the remaining schools and each remaining school points to the student with the highest priority among the remaining students. There is at least one student. Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
The algorithm terminates when all students are assigned a seat.&lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The following summary of how the algorithm works, is taken from the &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
Based on this approach, in the existing implementation of Expertiza, we have match_new_teams_to_topics method in the lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review.&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for the review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as inheritance. The Delegation pattern will help us reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled_Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us the demand density for each project to be reviewed, the list of all available topics to review and the list of topics selected already. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Color Coding Scheme:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The color coding scheme would range from Red for the most in-demand topics to green for the least contested topics. &amp;lt;br&amp;gt;&lt;br /&gt;
The top 10% of in-demand topics will be coded in Red, the next 30% of the topics will be in orange, the next 30% in yellow and the last 30% in the green. We are using percentages instead of hard-coding the color coding scheme so that it works dynamically with changing number of students. &amp;lt;br&amp;gt;&lt;br /&gt;
After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm.&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle bidding data called ReviewBid is created. ReviewBid contains bidding assignment information, its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participants bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
Allow Instructor to set review strategy to '''bidding''': &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Review_strategy.png]] &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After setting the review strategy to  '''bidding''', participants are assigned a default bidding list, ordered by topic's name.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Default_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Participants can drag the items up or down to alter the priority.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Altered_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instructors can start bidding by clicking the following icon.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_icon.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the bidding is done, participants can login and see what they are assigned with.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_result.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Automated tests are to be written for model ReviewBid, controller ReviewBidController. We also plan to write basic tests to check the correctness of Gale Shapley algorithm.&lt;br /&gt;
&lt;br /&gt;
UI Tests:&lt;br /&gt;
&lt;br /&gt;
In addition to automated tests we will also perform manual testing of the newly added features which include the following:&lt;br /&gt;
&lt;br /&gt;
1. The student should be able to bid the reviews when Professor enables bid option for students on that particular assignment.&lt;br /&gt;
&lt;br /&gt;
2. The reviews prioritized by the student should show colors i.e. green, orange and red indicating how likely he is going to get the review that he bid.&lt;br /&gt;
&lt;br /&gt;
3. When bidding ends, students will be given two reviews to review.&lt;br /&gt;
&lt;br /&gt;
4. When done with two reviews, he/she can ask for more assignments to review.&lt;br /&gt;
&lt;br /&gt;
5. At maximum, a student should be able to four assignments.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents ]&lt;br /&gt;
# CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# Pull Request #1322 (E1856. Allow reviewers to bid on what to review) [https://github.com/expertiza/expertiza/pull/1322 ]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124023</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=124023"/>
		<updated>2019-04-13T02:27:56Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar review bidding feature was implemented in the previous semester, by making use of the '''Top Trading Cycles'''(TTC) algorithm. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, there were a few issues with that implementation, notably:&lt;br /&gt;
# The lack of color-coding feature.&lt;br /&gt;
# Ordering was done by team IDs, which is not a reasonable ordering.&lt;br /&gt;
# The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
# The UI could have been cleaner.&lt;br /&gt;
# There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
# There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
# This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
# Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to &amp;quot;bid&amp;quot; for topics that they want to do as an assignment. We plan to implement the same bidding feature for reviewing others' work, which is currently assigned on a &amp;quot;first-come-first-serve&amp;quot; basis. &lt;br /&gt;
&lt;br /&gt;
The current first-come-first-serve approach to assigning reviews to students is not efficient since sometimes the same project is requested to be reviewed by multiple students, while other projects are not in demand. By letting the students bid on topics they're interested in, the reviews are assigned more efficiently based on user interest.&lt;br /&gt;
&lt;br /&gt;
In this project we will make use of the Top Trading Cycles algorithm on Expertiza, to implement the review-bidding feature.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Before talking about the functionality of review mapping, it's necessary to describe some of the related models and controllers in Expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding feature for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Use Case Diagram===&lt;br /&gt;
[[File:Review_use_case.PNG‎]]&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
Currently, Expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, the method &amp;quot;add_reviewer&amp;quot; is invoked when students try to request a peer review. When it's done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
To understand the basic workflow of bidding on topics, we can look at the LotteryController:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Firstly, teams have different preferences towards available topics. For example, let's say there are three topics within an assignment, namely A, B and C and there are 4 teams W, X, Y, Z. Let's assume each teams preferred order of topics is as follows:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to the back-end service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to let the teams have a fair bidding over the topics.&lt;br /&gt;
&lt;br /&gt;
Now, consider a similar bidding approach to peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to respond. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu, and Tayfun Sonmez have described Top Trading Cycles Mechanism. The intuition of the mechanism is students who have the highest priorities are allowed to trade the schools. Students who are assigned to schools are removed and other students who have the highest priority will compete for schools. The mechanism is as follows:&lt;br /&gt;
&lt;br /&gt;
Step1: Each school has a counter (No. of seats/ capacity). Each student has a priority list. Each school points to the student who has the highest priority to the school. A cycle is formed which is an ordered&lt;br /&gt;
list (s1, i1, s2, ...., sk,ik). Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
Step k: Remaining students point to their favorite school among the remaining schools and each remaining school points to the student with the highest priority among the remaining students. There is at least one student. Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
The algorithm terminates when all students are assigned a seat.&lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The following summary of how the algorithm works, is taken from the &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
Based on this approach, in the existing implementation of Expertiza, we have match_new_teams_to_topics method in the lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review.&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for the review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as inheritance. The Delegation pattern will help us reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
[[File:Untitled_Diagram.png]]&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us the demand density for each project to be reviewed, the list of all available topics to review and the list of topics selected already. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Color Coding Scheme:''' &amp;lt;br&amp;gt;&lt;br /&gt;
The color coding scheme would range from Red for the most in-demand topics to green for the least contested topics. &amp;lt;br&amp;gt;&lt;br /&gt;
The top 10% of in-demand topics will be coded in Red, the next 30% of the topics will be in orange, the next 30% in yellow and the last 30% in the green. We are using percentages instead of hard-coding the color coding scheme so that it works dynamically with changing number of students. &amp;lt;br&amp;gt;&lt;br /&gt;
After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm.&lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle bidding data called ReviewBid is created. ReviewBid contains bidding assignment information, its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participants bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
Allow Instructor to set review strategy to '''bidding''': &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Review_strategy.png]] &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After setting the review strategy to  '''bidding''', participants are assigned a default bidding list, ordered by topic's name.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Default_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Participants can drag the items up or down to alter the priority.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Altered_bidding_list.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instructors can start bidding by clicking the following icon.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_icon.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the bidding is done, participants can login and see what they are assigned with.&amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
[[File:Bidding_result.png]]&amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
== Test Plan ==&lt;br /&gt;
&lt;br /&gt;
Automated tests are to be written for model ReviewBid, controller ReviewBidController. We also plan to write basic tests to check the correctness of Gale Shapley algorithm.&lt;br /&gt;
&lt;br /&gt;
UI Tests:&lt;br /&gt;
&lt;br /&gt;
In addition to automated tests we will also perform manual testing of the newly added features which include the following:&lt;br /&gt;
&lt;br /&gt;
1. Student should be able to bid the reviews when Professor enables bid option for students on that particular assignment.&lt;br /&gt;
2. The reviews prioritized by the student should show colors i.e. green, orange and red indicating how likely he is going to get the review that he bid.&lt;br /&gt;
3. When bidding ends, students will be given two reviews to review&lt;br /&gt;
4. When done with two reviews, he/she can ask for more assignments to review.&lt;br /&gt;
5. At maximum, a student should be able to four assignments.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents ]&lt;br /&gt;
# CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# Pull Request #1322 (E1856. Allow reviewers to bid on what to review) [https://github.com/expertiza/expertiza/pull/1322 ]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123322</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123322"/>
		<updated>2019-04-06T16:55:41Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Top Trading Cycles Mechanism */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar implementation was provided in the last semester was by a team who had implemented the TTC and the required review bidding functionality. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, their implementation had a few problems, notably:&lt;br /&gt;
# The color-coding feature was not implemented.&lt;br /&gt;
# The implementation entailed ordering by IDs of teams who did the topics (not a reasonable ordering).&lt;br /&gt;
# The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
# The UI was not clean, it appeared to be disarrayed.&lt;br /&gt;
# There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
# There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
# This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
# Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to “bid” for the projects that they want to do as an assignment. On the other hand, for reviewing others’ work, the policy that’s currently in use is  “first-come-first-serve”. We would try to implement the Top Trading Cycles algorithm that assigns review topics to students in a priority. &lt;br /&gt;
&lt;br /&gt;
The bidding policy for project topics that students want to work on is already implemented. Students can currently bid on project topics for their team assignment. This reduces the conflicts in assigning topics to each team. But to contradict the desired implementation, we will make use of student user instead of teams, since a single student bids on a multiple topics.&lt;br /&gt;
&lt;br /&gt;
There’s also reviewing work for each assignment. Currently, the policy to assign the project to the reviewer is “first-come-first-serve”. Student who chooses to review a project, will get the same project based on priority.&lt;br /&gt;
&lt;br /&gt;
However, this policy creates an issue — while reviewing a student's work, sometimes the same project is requested to be reviewed by many students, while some other projects are not in demand. A similar bidding policy for assigning projects to reviewers can help students who want to review a project the most to be most likely to receive that project. The completion of this project will allow students to also bid on what projects they are interested in reviewing.&lt;br /&gt;
&lt;br /&gt;
The project includes implementation of the top trading cycles algorithm on Expertiza.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Regarding to the functionality of review mapping, it's necessary to describe some of the related models and controllers in expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
For now, expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, method &amp;quot;add_reviewer&amp;quot; is invoked when students are trying to request a peer review. When it is done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
If reviewers are allowed to bid on what to review, the procedure of topics bidding implemented by LotteryController is a good reference. Here is the basic workflow of topics bidding:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First of all, teams have different preference towards the topics. For example, there are three topics within an assignment, namely A, B and C. Therefore 4 teams W, X, Y, Z. Teams would have their own preference towards different topics:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to backend service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to have a fair bidding over the topics and teams.&lt;br /&gt;
&lt;br /&gt;
A similar bid can take place on peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to response. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu, and Tayfun Sonmez have described Top Trading Cycles Mechanism. The intuition of the mechanism is students who have the highest priorities are allowed to trade the schools. Students who are assigned to schools are removed and other students who have the highest priority will compete for schools. The mechanism is as follows:&lt;br /&gt;
&lt;br /&gt;
step1: Each school has a counter (no of seats/ capacity). Each student has a priority list. Each school points to the student who has the highest priority to the school. A cycle is formed which is an ordered&lt;br /&gt;
list (s1, i1, s2, ...., sk,ik). Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
step k: Remaining students point to their favorite school among the remaining schools and each remaining school points to the student with the highest priority among the remaining students. There is at least one student. Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
The algorithm terminates when all students are assigned a seat.&lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The explanation for this algorithm is as follows which as been taken from &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
In the existing implementation, we have match_new_teams_to_topics method in lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as an inheritance. Delegation pattern will help us to reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us demand density for each project to be reviewed and list of all available topics to review and selected topics. After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm. &lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle the data of the bidding called ReviewBid is created. ReviewBid contains the information of bidding assignment and its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participant to bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley]&lt;br /&gt;
# [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/1322 Pull Request #1322 (E1856. Allow reviewers to bid on what to review)]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123321</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123321"/>
		<updated>2019-04-06T16:55:30Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Top Trading Cycles Mechanism */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar implementation was provided in the last semester was by a team who had implemented the TTC and the required review bidding functionality. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, their implementation had a few problems, notably:&lt;br /&gt;
# The color-coding feature was not implemented.&lt;br /&gt;
# The implementation entailed ordering by IDs of teams who did the topics (not a reasonable ordering).&lt;br /&gt;
# The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
# The UI was not clean, it appeared to be disarrayed.&lt;br /&gt;
# There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
# There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
# This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
# Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to “bid” for the projects that they want to do as an assignment. On the other hand, for reviewing others’ work, the policy that’s currently in use is  “first-come-first-serve”. We would try to implement the Top Trading Cycles algorithm that assigns review topics to students in a priority. &lt;br /&gt;
&lt;br /&gt;
The bidding policy for project topics that students want to work on is already implemented. Students can currently bid on project topics for their team assignment. This reduces the conflicts in assigning topics to each team. But to contradict the desired implementation, we will make use of student user instead of teams, since a single student bids on a multiple topics.&lt;br /&gt;
&lt;br /&gt;
There’s also reviewing work for each assignment. Currently, the policy to assign the project to the reviewer is “first-come-first-serve”. Student who chooses to review a project, will get the same project based on priority.&lt;br /&gt;
&lt;br /&gt;
However, this policy creates an issue — while reviewing a student's work, sometimes the same project is requested to be reviewed by many students, while some other projects are not in demand. A similar bidding policy for assigning projects to reviewers can help students who want to review a project the most to be most likely to receive that project. The completion of this project will allow students to also bid on what projects they are interested in reviewing.&lt;br /&gt;
&lt;br /&gt;
The project includes implementation of the top trading cycles algorithm on Expertiza.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Regarding to the functionality of review mapping, it's necessary to describe some of the related models and controllers in expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
For now, expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, method &amp;quot;add_reviewer&amp;quot; is invoked when students are trying to request a peer review. When it is done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
If reviewers are allowed to bid on what to review, the procedure of topics bidding implemented by LotteryController is a good reference. Here is the basic workflow of topics bidding:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First of all, teams have different preference towards the topics. For example, there are three topics within an assignment, namely A, B and C. Therefore 4 teams W, X, Y, Z. Teams would have their own preference towards different topics:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to backend service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to have a fair bidding over the topics and teams.&lt;br /&gt;
&lt;br /&gt;
A similar bid can take place on peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to response. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu, and Tayfun Sonmez have described Top Trading Cycles Mechanism. The intuition of the mechanism is students who have the highest priorities are allowed to trade the schools. Students who are assigned to schools are removed and other students who have the highest priority will compete for schools. The mechanism is as follows:&lt;br /&gt;
&lt;br /&gt;
step1: Each school has a counter (no of seats/ capacity). Each student has a priority list. Each school points to the student who has the highest priority to the school. A cycle is formed which is an ordered&lt;br /&gt;
list (s1, i1, s2, ...., sk,ik). Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
step k: Remaining students point to their favorite school among the remaining schools and each remaining school points to the student with the highest priority among the remaining students. There is at least one student. Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list.&lt;br /&gt;
&lt;br /&gt;
The algorithm terminates when all students are assigned a seat.&lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The explanation for this algorithm is as follows which as been taken from &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
In the existing implementation, we have match_new_teams_to_topics method in lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as an inheritance. Delegation pattern will help us to reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us demand density for each project to be reviewed and list of all available topics to review and selected topics. After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm. &lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle the data of the bidding called ReviewBid is created. ReviewBid contains the information of bidding assignment and its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participant to bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley]&lt;br /&gt;
# [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/1322 Pull Request #1322 (E1856. Allow reviewers to bid on what to review)]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123320</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123320"/>
		<updated>2019-04-06T16:48:24Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Top Trading Cycles Mechanism */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar implementation was provided in the last semester was by a team who had implemented the TTC and the required review bidding functionality. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, their implementation had a few problems, notably:&lt;br /&gt;
# The color-coding feature was not implemented.&lt;br /&gt;
# The implementation entailed ordering by IDs of teams who did the topics (not a reasonable ordering).&lt;br /&gt;
# The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
# The UI was not clean, it appeared to be disarrayed.&lt;br /&gt;
# There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
# There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
# This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
# Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to “bid” for the projects that they want to do as an assignment. On the other hand, for reviewing others’ work, the policy that’s currently in use is  “first-come-first-serve”. We would try to implement the Top Trading Cycles algorithm that assigns review topics to students in a priority. &lt;br /&gt;
&lt;br /&gt;
The bidding policy for project topics that students want to work on is already implemented. Students can currently bid on project topics for their team assignment. This reduces the conflicts in assigning topics to each team. But to contradict the desired implementation, we will make use of student user instead of teams, since a single student bids on a multiple topics.&lt;br /&gt;
&lt;br /&gt;
There’s also reviewing work for each assignment. Currently, the policy to assign the project to the reviewer is “first-come-first-serve”. Student who chooses to review a project, will get the same project based on priority.&lt;br /&gt;
&lt;br /&gt;
However, this policy creates an issue — while reviewing a student's work, sometimes the same project is requested to be reviewed by many students, while some other projects are not in demand. A similar bidding policy for assigning projects to reviewers can help students who want to review a project the most to be most likely to receive that project. The completion of this project will allow students to also bid on what projects they are interested in reviewing.&lt;br /&gt;
&lt;br /&gt;
The project includes implementation of the top trading cycles algorithm on Expertiza.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Regarding to the functionality of review mapping, it's necessary to describe some of the related models and controllers in expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
For now, expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, method &amp;quot;add_reviewer&amp;quot; is invoked when students are trying to request a peer review. When it is done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
If reviewers are allowed to bid on what to review, the procedure of topics bidding implemented by LotteryController is a good reference. Here is the basic workflow of topics bidding:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First of all, teams have different preference towards the topics. For example, there are three topics within an assignment, namely A, B and C. Therefore 4 teams W, X, Y, Z. Teams would have their own preference towards different topics:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to backend service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to have a fair bidding over the topics and teams.&lt;br /&gt;
&lt;br /&gt;
A similar bid can take place on peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to response. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu, and Tayfun Sonmez have described Top Trading Cycles Mechanism. The intuition of the mechanism is students who have the highest priorities are allowed to trade the schools. Students who are assigned to schools are removed and other students who have the highest priority will compete for schools. The mechanism is as follows:&lt;br /&gt;
step1: Each school has a counter (no of seats/ capacity). Each student has a priority list. Each school points to the student who has the highest priority to the school. A cycle is formed which is an ordered&lt;br /&gt;
list (s1, i1, s2, ...., sk,ik). Every student in the cycle points to the school he/she is admitted and removed from the list. The counter of school is reduced by one and when it becomes zero it is removed from the list. This is repeated and the algorithm terminates when all students are assigned a seat.&lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The explanation for this algorithm is as follows which as been taken from &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
In the existing implementation, we have match_new_teams_to_topics method in lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as an inheritance. Delegation pattern will help us to reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us demand density for each project to be reviewed and list of all available topics to review and selected topics. After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm. &lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle the data of the bidding called ReviewBid is created. ReviewBid contains the information of bidding assignment and its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participant to bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley]&lt;br /&gt;
# [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/1322 Pull Request #1322 (E1856. Allow reviewers to bid on what to review)]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123319</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123319"/>
		<updated>2019-04-06T16:11:46Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar implementation was provided in the last semester was by a team who had implemented the TTC and the required review bidding functionality. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, their implementation had a few problems, notably:&lt;br /&gt;
# The color-coding feature was not implemented.&lt;br /&gt;
# The implementation entailed ordering by IDs of teams who did the topics (not a reasonable ordering).&lt;br /&gt;
# The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
# The UI was not clean, it appeared to be disarrayed.&lt;br /&gt;
# There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
# There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
# This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
# Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to “bid” for the projects that they want to do as an assignment. On the other hand, for reviewing others’ work, the policy that’s currently in use is  “first-come-first-serve”. We would try to implement the Top Trading Cycles algorithm that assigns review topics to students in a priority. &lt;br /&gt;
&lt;br /&gt;
The bidding policy for project topics that students want to work on is already implemented. Students can currently bid on project topics for their team assignment. This reduces the conflicts in assigning topics to each team. But to contradict the desired implementation, we will make use of student user instead of teams, since a single student bids on a multiple topics.&lt;br /&gt;
&lt;br /&gt;
There’s also reviewing work for each assignment. Currently, the policy to assign the project to the reviewer is “first-come-first-serve”. Student who chooses to review a project, will get the same project based on priority.&lt;br /&gt;
&lt;br /&gt;
However, this policy creates an issue — while reviewing a student's work, sometimes the same project is requested to be reviewed by many students, while some other projects are not in demand. A similar bidding policy for assigning projects to reviewers can help students who want to review a project the most to be most likely to receive that project. The completion of this project will allow students to also bid on what projects they are interested in reviewing.&lt;br /&gt;
&lt;br /&gt;
The project includes implementation of the top trading cycles algorithm on Expertiza.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Regarding to the functionality of review mapping, it's necessary to describe some of the related models and controllers in expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
For now, expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, method &amp;quot;add_reviewer&amp;quot; is invoked when students are trying to request a peer review. When it is done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
If reviewers are allowed to bid on what to review, the procedure of topics bidding implemented by LotteryController is a good reference. Here is the basic workflow of topics bidding:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First of all, teams have different preference towards the topics. For example, there are three topics within an assignment, namely A, B and C. Therefore 4 teams W, X, Y, Z. Teams would have their own preference towards different topics:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to backend service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to have a fair bidding over the topics and teams.&lt;br /&gt;
&lt;br /&gt;
A similar bid can take place on peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to response. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu and Tayfun Sonmez have described Top &lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The explanation for this algorithm is as follows which as been taken from &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
In the existing implementation, we have match_new_teams_to_topics method in lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as an inheritance. Delegation pattern will help us to reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us demand density for each project to be reviewed and list of all available topics to review and selected topics. After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm. &lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle the data of the bidding called ReviewBid is created. ReviewBid contains the information of bidding assignment and its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participant to bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley]&lt;br /&gt;
# [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/1322 Pull Request #1322 (E1856. Allow reviewers to bid on what to review)]&lt;br /&gt;
# Top Trading Cycles Algorithm[https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123318</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123318"/>
		<updated>2019-04-06T16:10:28Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Top Trading Cycles Mechanism */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar implementation was provided in the last semester was by a team who had implemented the TTC and the required review bidding functionality. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, their implementation had a few problems, notably:&lt;br /&gt;
# The color-coding feature was not implemented.&lt;br /&gt;
# The implementation entailed ordering by IDs of teams who did the topics (not a reasonable ordering).&lt;br /&gt;
# The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
# The UI was not clean, it appeared to be disarrayed.&lt;br /&gt;
# There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
# There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
# This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
# Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to “bid” for the projects that they want to do as an assignment. On the other hand, for reviewing others’ work, the policy that’s currently in use is  “first-come-first-serve”. We would try to implement the Top Trading Cycles algorithm that assigns review topics to students in a priority. &lt;br /&gt;
&lt;br /&gt;
The bidding policy for project topics that students want to work on is already implemented. Students can currently bid on project topics for their team assignment. This reduces the conflicts in assigning topics to each team. But to contradict the desired implementation, we will make use of student user instead of teams, since a single student bids on a multiple topics.&lt;br /&gt;
&lt;br /&gt;
There’s also reviewing work for each assignment. Currently, the policy to assign the project to the reviewer is “first-come-first-serve”. Student who chooses to review a project, will get the same project based on priority.&lt;br /&gt;
&lt;br /&gt;
However, this policy creates an issue — while reviewing a student's work, sometimes the same project is requested to be reviewed by many students, while some other projects are not in demand. A similar bidding policy for assigning projects to reviewers can help students who want to review a project the most to be most likely to receive that project. The completion of this project will allow students to also bid on what projects they are interested in reviewing.&lt;br /&gt;
&lt;br /&gt;
The project includes implementation of the top trading cycles algorithm on Expertiza.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Regarding to the functionality of review mapping, it's necessary to describe some of the related models and controllers in expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
For now, expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, method &amp;quot;add_reviewer&amp;quot; is invoked when students are trying to request a peer review. When it is done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
If reviewers are allowed to bid on what to review, the procedure of topics bidding implemented by LotteryController is a good reference. Here is the basic workflow of topics bidding:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First of all, teams have different preference towards the topics. For example, there are three topics within an assignment, namely A, B and C. Therefore 4 teams W, X, Y, Z. Teams would have their own preference towards different topics:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to backend service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to have a fair bidding over the topics and teams.&lt;br /&gt;
&lt;br /&gt;
A similar bid can take place on peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to response. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu and Tayfun Sonmez have described Top &lt;br /&gt;
&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The explanation for this algorithm is as follows which as been taken from &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
In the existing implementation, we have match_new_teams_to_topics method in lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as an inheritance. Delegation pattern will help us to reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us demand density for each project to be reviewed and list of all available topics to review and selected topics. After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm. &lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle the data of the bidding called ReviewBid is created. ReviewBid contains the information of bidding assignment and its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participant to bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley]&lt;br /&gt;
# [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/1322 Pull Request #1322 (E1856. Allow reviewers to bid on what to review)]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123317</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123317"/>
		<updated>2019-04-06T16:09:56Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Top Trading Cycles Mechanism */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar implementation was provided in the last semester was by a team who had implemented the TTC and the required review bidding functionality. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, their implementation had a few problems, notably:&lt;br /&gt;
# The color-coding feature was not implemented.&lt;br /&gt;
# The implementation entailed ordering by IDs of teams who did the topics (not a reasonable ordering).&lt;br /&gt;
# The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
# The UI was not clean, it appeared to be disarrayed.&lt;br /&gt;
# There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
# There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
# This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
# Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to “bid” for the projects that they want to do as an assignment. On the other hand, for reviewing others’ work, the policy that’s currently in use is  “first-come-first-serve”. We would try to implement the Top Trading Cycles algorithm that assigns review topics to students in a priority. &lt;br /&gt;
&lt;br /&gt;
The bidding policy for project topics that students want to work on is already implemented. Students can currently bid on project topics for their team assignment. This reduces the conflicts in assigning topics to each team. But to contradict the desired implementation, we will make use of student user instead of teams, since a single student bids on a multiple topics.&lt;br /&gt;
&lt;br /&gt;
There’s also reviewing work for each assignment. Currently, the policy to assign the project to the reviewer is “first-come-first-serve”. Student who chooses to review a project, will get the same project based on priority.&lt;br /&gt;
&lt;br /&gt;
However, this policy creates an issue — while reviewing a student's work, sometimes the same project is requested to be reviewed by many students, while some other projects are not in demand. A similar bidding policy for assigning projects to reviewers can help students who want to review a project the most to be most likely to receive that project. The completion of this project will allow students to also bid on what projects they are interested in reviewing.&lt;br /&gt;
&lt;br /&gt;
The project includes implementation of the top trading cycles algorithm on Expertiza.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Regarding to the functionality of review mapping, it's necessary to describe some of the related models and controllers in expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
For now, expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, method &amp;quot;add_reviewer&amp;quot; is invoked when students are trying to request a peer review. When it is done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
If reviewers are allowed to bid on what to review, the procedure of topics bidding implemented by LotteryController is a good reference. Here is the basic workflow of topics bidding:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First of all, teams have different preference towards the topics. For example, there are three topics within an assignment, namely A, B and C. Therefore 4 teams W, X, Y, Z. Teams would have their own preference towards different topics:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to backend service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to have a fair bidding over the topics and teams.&lt;br /&gt;
&lt;br /&gt;
A similar bid can take place on peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to response. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
In the paper School Choice: A Mechanism Design Approach, author Atila Abdulkadiroglu and Tayfun Sonmez have described Top &lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The explanation for this algorithm is as follows which as been taken from &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
In the existing implementation, we have match_new_teams_to_topics method in lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as an inheritance. Delegation pattern will help us to reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us demand density for each project to be reviewed and list of all available topics to review and selected topics. After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm. &lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, a new model to handle the data of the bidding called ReviewBid is created. ReviewBid contains the information of bidding assignment and its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participant to bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley]&lt;br /&gt;
# [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/1322 Pull Request #1322 (E1856. Allow reviewers to bid on what to review)]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123315</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123315"/>
		<updated>2019-04-06T16:06:48Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Top Trading Cycles Mechanism */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar implementation was provided in the last semester was by a team who had implemented the TTC and the required review bidding functionality. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, their implementation had a few problems, notably:&lt;br /&gt;
# The color-coding feature was not implemented.&lt;br /&gt;
# The implementation entailed ordering by IDs of teams who did the topics (not a reasonable ordering).&lt;br /&gt;
# The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
# The UI was not clean, it appeared to be disarrayed.&lt;br /&gt;
# There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
# There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
# This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
# Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to “bid” for the projects that they want to do as an assignment. On the other hand, for reviewing others’ work, the policy that’s currently in use is  “first-come-first-serve”. We would try to implement the Top Trading Cycles algorithm that assigns review topics to students in a priority. &lt;br /&gt;
&lt;br /&gt;
The bidding policy for project topics that students want to work on is already implemented. Students can currently bid on project topics for their team assignment. This reduces the conflicts in assigning topics to each team. But to contradict the desired implementation, we will make use of student user instead of teams, since a single student bids on a multiple topics.&lt;br /&gt;
&lt;br /&gt;
There’s also reviewing work for each assignment. Currently, the policy to assign the project to the reviewer is “first-come-first-serve”. Student who chooses to review a project, will get the same project based on priority.&lt;br /&gt;
&lt;br /&gt;
However, this policy creates an issue — while reviewing a student's work, sometimes the same project is requested to be reviewed by many students, while some other projects are not in demand. A similar bidding policy for assigning projects to reviewers can help students who want to review a project the most to be most likely to receive that project. The completion of this project will allow students to also bid on what projects they are interested in reviewing.&lt;br /&gt;
&lt;br /&gt;
The project includes implementation of the top trading cycles algorithm on Expertiza.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Regarding to the functionality of review mapping, it's necessary to describe some of the related models and controllers in expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
For now, expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, method &amp;quot;add_reviewer&amp;quot; is invoked when students are trying to request a peer review. When it is done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
If reviewers are allowed to bid on what to review, the procedure of topics bidding implemented by LotteryController is a good reference. Here is the basic workflow of topics bidding:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First of all, teams have different preference towards the topics. For example, there are three topics within an assignment, namely A, B and C. Therefore 4 teams W, X, Y, Z. Teams would have their own preference towards different topics:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to backend service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to have a fair bidding over the topics and teams.&lt;br /&gt;
&lt;br /&gt;
A similar bid can take place on peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to response. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The explanation for this algorithm is as follows which as been taken from &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
In the existing implementation, we have match_new_teams_to_topics method in lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as an inheritance. Delegation pattern will help us to reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us demand density for each project to be reviewed and list of all available topics to review and selected topics. After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm. &lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, we decide to add a new model to handle the data of the bidding. Let's call it ReviewBid. ReviewBid contains the information of bidding assignment and its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participant to bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley]&lt;br /&gt;
# [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/1322 Pull Request #1322 (E1856. Allow reviewers to bid on what to review)]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123314</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123314"/>
		<updated>2019-04-06T16:05:59Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Top Trading Cycles Mechanism */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar implementation was provided in the last semester was by a team who had implemented the TTC and the required review bidding functionality. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, their implementation had a few problems, notably:&lt;br /&gt;
# The color-coding feature was not implemented.&lt;br /&gt;
# The implementation entailed ordering by IDs of teams who did the topics (not a reasonable ordering).&lt;br /&gt;
# The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
# The UI was not clean, it appeared to be disarrayed.&lt;br /&gt;
# There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
# There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
# This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
# Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to “bid” for the projects that they want to do as an assignment. On the other hand, for reviewing others’ work, the policy that’s currently in use is  “first-come-first-serve”. We would try to implement the Top Trading Cycles algorithm that assigns review topics to students in a priority. &lt;br /&gt;
&lt;br /&gt;
The bidding policy for project topics that students want to work on is already implemented. Students can currently bid on project topics for their team assignment. This reduces the conflicts in assigning topics to each team. But to contradict the desired implementation, we will make use of student user instead of teams, since a single student bids on a multiple topics.&lt;br /&gt;
&lt;br /&gt;
There’s also reviewing work for each assignment. Currently, the policy to assign the project to the reviewer is “first-come-first-serve”. Student who chooses to review a project, will get the same project based on priority.&lt;br /&gt;
&lt;br /&gt;
However, this policy creates an issue — while reviewing a student's work, sometimes the same project is requested to be reviewed by many students, while some other projects are not in demand. A similar bidding policy for assigning projects to reviewers can help students who want to review a project the most to be most likely to receive that project. The completion of this project will allow students to also bid on what projects they are interested in reviewing.&lt;br /&gt;
&lt;br /&gt;
The project includes implementation of the top trading cycles algorithm on Expertiza.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Regarding to the functionality of review mapping, it's necessary to describe some of the related models and controllers in expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
For now, expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, method &amp;quot;add_reviewer&amp;quot; is invoked when students are trying to request a peer review. When it is done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
If reviewers are allowed to bid on what to review, the procedure of topics bidding implemented by LotteryController is a good reference. Here is the basic workflow of topics bidding:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First of all, teams have different preference towards the topics. For example, there are three topics within an assignment, namely A, B and C. Therefore 4 teams W, X, Y, Z. Teams would have their own preference towards different topics:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to backend service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to have a fair bidding over the topics and teams.&lt;br /&gt;
&lt;br /&gt;
A similar bid can take place on peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to response. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
1.  Top Trading Cycles algorithm: [https://www.jstor.org/stable/pdf/3132114.pdf?casa_token=Bp8Syf8Q0yYAAAAA:f7zDJdWurp5cYlHtSHaUxRbDc1o4sL0Qx8UTnk7C5eeXPhgyiTOaWqgftX-nNJ48s6SGyPBzH3_U3Yv6Pfapo1OJaj-estvNyRl60LNQi5QgGW3LmAW8pQ]&lt;br /&gt;
&lt;br /&gt;
2. Top Trading Cycles implementation: [https://github.com/peerlogic/IntelligentAssignment/blob/master/app/top_tra&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The explanation for this algorithm is as follows which as been taken from &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
In the existing implementation, we have match_new_teams_to_topics method in lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as an inheritance. Delegation pattern will help us to reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us demand density for each project to be reviewed and list of all available topics to review and selected topics. After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm. &lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, we decide to add a new model to handle the data of the bidding. Let's call it ReviewBid. ReviewBid contains the information of bidding assignment and its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participant to bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley]&lt;br /&gt;
# [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/1322 Pull Request #1322 (E1856. Allow reviewers to bid on what to review)]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123313</id>
		<title>CSC/ECE 517 Spring 2019 - Project E1928. 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_Spring_2019_-_Project_E1928._Allow_reviewers_to_bid_on_what_to_review&amp;diff=123313"/>
		<updated>2019-04-06T16:05:19Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza ==&lt;br /&gt;
Expertiza is a web application through which students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation. It is used in select courses at NC State and by professors at several other colleges and universities.&lt;br /&gt;
&lt;br /&gt;
== Similarity to previous implementation ==&lt;br /&gt;
A similar implementation was provided in the last semester was by a team who had implemented the TTC and the required review bidding functionality. &amp;lt;br&amp;gt;&lt;br /&gt;
Link: [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review] &amp;lt;br&amp;gt;&lt;br /&gt;
However, their implementation had a few problems, notably:&lt;br /&gt;
# The color-coding feature was not implemented.&lt;br /&gt;
# The implementation entailed ordering by IDs of teams who did the topics (not a reasonable ordering).&lt;br /&gt;
# The content of some newly-added file are very similar with existing ones.&lt;br /&gt;
# The UI was not clean, it appeared to be disarrayed.&lt;br /&gt;
# There is only one list while topic bidding interface has two lists, one for the the available list of topics and the other list for topics that are selected for the bidding. &lt;br /&gt;
# There was no &amp;quot;add link to submission&amp;quot; in the bidding list.&lt;br /&gt;
# This implementation altered too many lines of existing Expertiza code.&lt;br /&gt;
# Many irrelevant tests were included.&lt;br /&gt;
&lt;br /&gt;
While we would not be writing this implementation from scratch, we would instead be using their [https://github.com/expertiza/expertiza/pull/1322 Pull Request] and remove the possible defects that they had.&lt;br /&gt;
&lt;br /&gt;
== Problem statement ==&lt;br /&gt;
Students currently are able to “bid” for the projects that they want to do as an assignment. On the other hand, for reviewing others’ work, the policy that’s currently in use is  “first-come-first-serve”. We would try to implement the Top Trading Cycles algorithm that assigns review topics to students in a priority. &lt;br /&gt;
&lt;br /&gt;
The bidding policy for project topics that students want to work on is already implemented. Students can currently bid on project topics for their team assignment. This reduces the conflicts in assigning topics to each team. But to contradict the desired implementation, we will make use of student user instead of teams, since a single student bids on a multiple topics.&lt;br /&gt;
&lt;br /&gt;
There’s also reviewing work for each assignment. Currently, the policy to assign the project to the reviewer is “first-come-first-serve”. Student who chooses to review a project, will get the same project based on priority.&lt;br /&gt;
&lt;br /&gt;
However, this policy creates an issue — while reviewing a student's work, sometimes the same project is requested to be reviewed by many students, while some other projects are not in demand. A similar bidding policy for assigning projects to reviewers can help students who want to review a project the most to be most likely to receive that project. The completion of this project will allow students to also bid on what projects they are interested in reviewing.&lt;br /&gt;
&lt;br /&gt;
The project includes implementation of the top trading cycles algorithm on Expertiza.&lt;br /&gt;
&lt;br /&gt;
== Current Implementation of the bidding ==&lt;br /&gt;
Regarding to the functionality of review mapping, it's necessary to describe some of the related models and controllers in expertiza and how they are organized to fully implement the functionality. It should be noted here that this is an implementation of the bidding for assignment topics.&lt;br /&gt;
&lt;br /&gt;
===Models===&lt;br /&gt;
&lt;br /&gt;
[[File:Current_design_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. When an assignment is released, an instance of Assignment is created and corresponding topic instances of SignUpTopics are also imported, indicating that different topics are available for students to choose from within this assignment.&lt;br /&gt;
&lt;br /&gt;
2. Students are assigned as instances of AssignmentParticipant to this assignment and form up their teams(Model Team).&lt;br /&gt;
&lt;br /&gt;
3. Each team registers for several topics and becomes a candidate instance of SignUpTeam. After topics bidding, some of the candidate teams become an official signed-up team of a particular topic.&lt;br /&gt;
&lt;br /&gt;
4. After assignment submission, participants choose their preferred topics and response mappings between assignment(reviewed object), assignment team(reviewee) and assignment participant(reviewer) are created.&lt;br /&gt;
&lt;br /&gt;
5. After the mapping, participants can submit their response and the afterwards is out of discussion range of this document.&lt;br /&gt;
&lt;br /&gt;
===Workflow===&lt;br /&gt;
&lt;br /&gt;
For now, expertiza employs FIFO strategy on review assignment.  In the ReviewMappingController, method &amp;quot;add_reviewer&amp;quot; is invoked when students are trying to request a peer review. When it is done, a new mapping is created, that is why review assignment is in FIFO style.&lt;br /&gt;
&lt;br /&gt;
If reviewers are allowed to bid on what to review, the procedure of topics bidding implemented by LotteryController is a good reference. Here is the basic workflow of topics bidding:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First of all, teams have different preference towards the topics. For example, there are three topics within an assignment, namely A, B and C. Therefore 4 teams W, X, Y, Z. Teams would have their own preference towards different topics:&lt;br /&gt;
&lt;br /&gt;
W: B, A, C  |  X:  B, C  |   Y:  C, A, B | Z:  A, B, C&lt;br /&gt;
&lt;br /&gt;
This data structure is passed to backend service http://peerlogic.csc.ncsu.edu/intelligent_assignment/merge_teams by method &amp;quot;run_intelligent_assignment&amp;quot; of LotteryController.  The peerlogic service runs top_trading_cycles algorithm to have a fair bidding over the topics and teams.&lt;br /&gt;
&lt;br /&gt;
A similar bid can take place on peer review assignment. Why is it workable? The following diagram illustrates the similarity of the two bidding model. &lt;br /&gt;
[[File:Contrast_topic_review_bidding.jpg]]&lt;br /&gt;
&lt;br /&gt;
As for topics bidding, a few available slots of a particular topic are open for teams contending. In the left part of the diagram, there are 4 slots so only 4 teams can successfully contend for it. Slot is described as &amp;quot;max_choosers&amp;quot; of a sign_up topic in Expertiza. Consequently, there will be 4 different responses after the submission, and this time it is the participants that contend for the responses. &lt;br /&gt;
&lt;br /&gt;
Some discrepancies need additional attention.&lt;br /&gt;
&lt;br /&gt;
1. Slots can be left unoccupied if no team is willing to response. However, every response needs to have at least some reviewers. &lt;br /&gt;
&lt;br /&gt;
2. The size of bidding data is different, since the number of teams are usually 1/2, 1/3 or 1/4 of the participants. &lt;br /&gt;
&lt;br /&gt;
3. The policy of bidding may be slightly different. Participants are not allowed to review a response submitted by themselves.  However, the topic bidding doesn't have this constraint.&lt;br /&gt;
&lt;br /&gt;
== Top Trading Cycles Mechanism ==&lt;br /&gt;
&lt;br /&gt;
== Bidding policy (Stable marriage problem) ==&lt;br /&gt;
As part of this assignment, we have to analyse the implementation of the stable marriage problem which is a stable sorting algorithm. The explanation for this algorithm is as follows which as been taken from &amp;quot;College Admissions and the Stability of Marriage (1962)&amp;quot; by D. Gale and L. S. Shapley. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
A certain community consists of n men and n women. Each person ranks those of the opposite sex in accordance with his or her preferences for a marriage partner. We&lt;br /&gt;
seek a satisfactory way of marrying off all members of the community. Imitating our earlier deﬁnition, we call a set of marriages unstable (and here the suitability of the&lt;br /&gt;
term is quite clear) if under it there are a man and a woman who are not married to each other but prefer each other to their actual mates.&lt;br /&gt;
&lt;br /&gt;
'''Deﬁnition:''' An assignment of couples will be called unstable if there are two men α and β who are married to women A and B, respectively, although β prefers A to B and A prefers β to α.&lt;br /&gt;
&lt;br /&gt;
So, we can ask the question: For any pattern of preferences is it possible to ﬁnd a stable set of marriages?&lt;br /&gt;
&lt;br /&gt;
Before giving the answer let us look at some examples.&lt;br /&gt;
&lt;br /&gt;
Example 1. The following is the “ranking matrix” of three men, α, β, and γ , and three women, A, B, and C.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Man\Woman !! A !! B !! C&lt;br /&gt;
|-&lt;br /&gt;
| α || 1,3      || 2,2     || 3,1&lt;br /&gt;
|-&lt;br /&gt;
| β || 3,1      || 1,3     || 2,2&lt;br /&gt;
|-&lt;br /&gt;
| γ || 2,2      || 3,1     || 1,3&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ﬁrst number of each pair in the matrix gives the ranking of women by the men, the second number is the ranking of the men by the women. Thus, α ranks A ﬁrst, B second, C third, while A ranks β ﬁrst, γ second, and α third, etc.&lt;br /&gt;
&lt;br /&gt;
There are six possible sets of marriages; of these, three are stable. One of these is realized by giving each man his ﬁrst choice, thus α marries A, β marries B, and γ marries C. Note that although each woman gets her last choice, the arrangement is nevertheless stable. Alternatively one may let the women have their ﬁrst choices and marry α to C, β to A, and γ to B. The third stable arrangement is to give everyone his or her second choice and have α marry B, β marry C, and γ marry A. The reader will easily verify that all other arrangements are unstable.&lt;br /&gt;
&lt;br /&gt;
In the existing implementation, we have match_new_teams_to_topics method in lottery_controller that performs this stable sorting algorithm for teams that have bid for an assignment. Our objective would be to implement a similar strategy, but we would use students instead of teams since there are no &amp;quot;team reviews&amp;quot;. Every student selects their own assignment to review&lt;br /&gt;
&lt;br /&gt;
== Design strategy ==&lt;br /&gt;
Almost all of the functionality for our project has already been implemented in the review portion of the Expertiza system - where the teams are allowed to bid on topics they want to work for their project. We plan to reuse the code to keep the implementation DRY but we need to add some additional features to make it work for review bidding functionality. '''Delegation''' is a way to make composition as powerful for reuse as an inheritance. Delegation pattern will help us to reduce the coupling of methods to their original class as we have components that seem to behave identically, but we realize that this situation can change in the future.&lt;br /&gt;
&lt;br /&gt;
====Controller====&lt;br /&gt;
Because of this, we plan to approach this project by first using delegation pattern to add biding capability to the [https://github.com/expertiza/expertiza/blob/master/app/controllers/review_mapping_controller.rb review mapping controller] for choosing topics. Apart from this, a new controller,[https://github.com/expertiza/expertiza/pull/1322/files#diff-e064188effa2297543b98ac353bba4e3 review bids controller] is implemented to handle interactions similar to the one done in [https://github.com/expertiza/expertiza/blob/master/app/controllers/lottery_controller.rb lottery controller]. It handles the following implementations. &lt;br /&gt;
&lt;br /&gt;
1. Trigger the bidding by sending a request to PeerLogic backend with proper parameters retrieved from ReviewBid records. &lt;br /&gt;
&lt;br /&gt;
2. Process the response from PeerLogic and transform it into records of ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====View====&lt;br /&gt;
The bidding interface for reviews is followed from [https://github.com/expertiza/expertiza/pull/778/commits similar] implementation for topic bidding. We need to modify the ''code'' to implement the heat-map showing us demand density for each project to be reviewed and list of all available topics to review and selected topics. After we allow the student users to bid for their topic of interest we need to provide access to instructors to start the bidding algorithm. &lt;br /&gt;
&lt;br /&gt;
====Model====&lt;br /&gt;
To maintain the original functionality of Expertiza as well as to add review bidding, we decide to add a new model to handle the data of the bidding. Let's call it ReviewBid. ReviewBid contains the information of bidding assignment and its biddable topics as well as the  participants' preference. ReviewBid is served as the input of the bidding algorithm. We decided to let participant to bid on assignment teams rather than topics for simplicity.&lt;br /&gt;
&lt;br /&gt;
Here is the definition of ReviewBid:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
!Field Name !!Type !!Description &lt;br /&gt;
|-&lt;br /&gt;
!id &lt;br /&gt;
|int(11)  &lt;br /&gt;
|unique identifier for the record&lt;br /&gt;
|- &lt;br /&gt;
!team_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|the work of team to be bid on&lt;br /&gt;
|- &lt;br /&gt;
!participant_id   &lt;br /&gt;
|int(11)  &lt;br /&gt;
|participant id&lt;br /&gt;
|- &lt;br /&gt;
!priority   &lt;br /&gt;
|text&lt;br /&gt;
|participant's preference towards the team&lt;br /&gt;
|-&lt;br /&gt;
!created_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
!updated_at&lt;br /&gt;
|timestamp&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
 &lt;br /&gt;
# [https://www-jstor-org.prox.lib.ncsu.edu/stable/2312726?Search=yes&amp;amp;resultItemClick=true&amp;amp;searchText=College&amp;amp;searchText=Admissions&amp;amp;searchText=and&amp;amp;searchText=the&amp;amp;searchText=Stability&amp;amp;searchText=of&amp;amp;searchText=Marriage&amp;amp;searchUri=%2Faction%2FdoBasicSearch%3Fgroup%3Dnone%26amp%3Bfc%3Doff%26amp%3BQuery%3DCollege%2BAdmissions%2Band%2Bthe%2BStability%2Bof%2BMarriage%26amp%3Bwc%3Don%26amp%3Bacc%3Don&amp;amp;ab_segments=0%2Fdefault-2%2Fcontrol&amp;amp;refreqid=search%3A6c17f9ae92b22bc404fc3b7641ac908a&amp;amp;seq=1#metadata_info_tab_contents College Admissions and the Stability of Marriage (1962), D. Gale and L. S. Shapley]&lt;br /&gt;
# [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review CSC/ECE_517_Fall_2018/E1856_Allow_reviewers_to_bid_on_what_to_review]&lt;br /&gt;
# [https://github.com/expertiza/expertiza/pull/1322 Pull Request #1322 (E1856. Allow reviewers to bid on what to review)]&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122929</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122929"/>
		<updated>2019-04-01T23:13:16Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Affected View Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. There are many other types of question objects like dropdown that have the implementation of similar methods. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The pull request===&lt;br /&gt;
https://github.com/expertiza/expertiza/pull/1407&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details. This method is called only from two view files - one for creating (_questionnaire.html.erb partial file) and another for editing (edit.html.erb). Both these files are in questionnaires view. Verified this using both RubyMine and the grep command. Another interesting thing to note is the use of &amp;quot;self.&amp;quot; to get the attributes associated with question object. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
This method has the same explanation as the edit method except the fact that this method is called only during viewing of questionnaires by an instructor. We observed that this method is also called by in student_quiz view. On further analysis, we found that the student_quiz does not use criterion object and has only three options: TrueFalse, MultipleChoiceRadio and MultipleChoiceCheckbox. So no refactoring is required here. Verified this method isn't called anywhere else using RubyMine and grep command. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic in this method and is completely html code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def view_question_text&lt;br /&gt;
    html = '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt; ' + self.txt + ' &amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt;' + self.type + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;' + self.weight.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    questionnaire = self.questionnaire&lt;br /&gt;
    if !self.max_label.nil? &amp;amp;&amp;amp; !self.min_label.nil?&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt; (' + self.min_label + ') ' + questionnaire.min_question_score.to_s&lt;br /&gt;
      html += ' to ' + questionnaire.max_question_score.to_s + ' (' + self.max_label + ')&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    else&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt;' + questionnaire.min_question_score.to_s + ' to ' + questionnaire.max_question_score.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;TR&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/TR&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the user responds to the question being created in the respective model. In the case of this problem, which deals with criterion type question responses, the complete method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to respond to the criterion question and enter the necessary details. This method is called only from one view file i.e. response.html.erb. This file is in response view. Verified this using both RubyMine and the grep command. Unlike edit or view_question_text the self object does not refer to a global object instead it refers to a copy of the local object. So, we had passed the required object as locals to the partial, along with the parameters required by the method namely question, count, answer, questionnaire_min, questionnaire_max, dropdown_or_scale. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def complete(count, answer = nil, questionnaire_min, questionnaire_max, dropdown_or_scale)&lt;br /&gt;
    if self.size.nil?&lt;br /&gt;
      cols = '70'&lt;br /&gt;
      rows = '1'&lt;br /&gt;
    else&lt;br /&gt;
      cols = self.size.split(',')[0]&lt;br /&gt;
      rows = self.size.split(',')[1]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    html = '&amp;lt;div&amp;gt;&amp;lt;label for=&amp;quot;responses_' + count.to_s + '&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/label&amp;gt;&amp;lt;/div&amp;gt;'&lt;br /&gt;
    # show advice for each criterion question&lt;br /&gt;
    question_advices = QuestionAdvice.where(question_id: self.id).sort_by(&amp;amp;:id)&lt;br /&gt;
    advice_total_length = 0&lt;br /&gt;
&lt;br /&gt;
    question_advices.each do |question_advice|&lt;br /&gt;
      advice_total_length += question_advice.advice.length if question_advice.advice &amp;amp;&amp;amp; question_advice.advice != &amp;quot;&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if !question_advices.empty? and advice_total_length &amp;gt; 0&lt;br /&gt;
      html += '&amp;lt;a id=&amp;quot;showAdivce_' + self.id.to_s + '&amp;quot; onclick=&amp;quot;showAdvice(' + self.id.to_s + ')&amp;quot;&amp;gt;Show advice&amp;lt;/a&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;script&amp;gt;'&lt;br /&gt;
      html += 'function showAdvice(i){'&lt;br /&gt;
      html += 'var element = document.getElementById(&amp;quot;showAdivce_&amp;quot; + i.toString());'&lt;br /&gt;
      html += 'var show = element.innerHTML == &amp;quot;Hide advice&amp;quot;;'&lt;br /&gt;
      html += 'if (show){'&lt;br /&gt;
      html += 'element.innerHTML=&amp;quot;Show advice&amp;quot;;'&lt;br /&gt;
      html += '}else{'&lt;br /&gt;
      html += 'element.innerHTML=&amp;quot;Hide advice&amp;quot;;}'&lt;br /&gt;
      html += 'toggleAdvice(i);}'&lt;br /&gt;
&lt;br /&gt;
      html += 'function toggleAdvice(i) {'&lt;br /&gt;
      html += 'var elem = document.getElementById(i.toString() + &amp;quot;_myDiv&amp;quot;);'&lt;br /&gt;
      html += 'if (elem.style.display == &amp;quot;none&amp;quot;) {'&lt;br /&gt;
      html += 'elem.style.display = &amp;quot;&amp;quot;;'&lt;br /&gt;
      html += '} else {'&lt;br /&gt;
      html += 'elem.style.display = &amp;quot;none&amp;quot;;}}'&lt;br /&gt;
      html += '&amp;lt;/script&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;div id=&amp;quot;' + self.id.to_s + '_myDiv&amp;quot; style=&amp;quot;display: none;&amp;quot;&amp;gt;'&lt;br /&gt;
      # [2015-10-26] Zhewei:&lt;br /&gt;
      # best to order advices high to low, e.g., 5 to 1&lt;br /&gt;
      # each level used to be a link;&lt;br /&gt;
      # clicking on the link caused the dropbox to be filled in with the corresponding number&lt;br /&gt;
      question_advices.reverse.each_with_index do |question_advice, index|&lt;br /&gt;
        html += '&amp;lt;a id=&amp;quot;changeScore_&amp;gt;' + self.id.to_s + '&amp;quot; onclick=&amp;quot;changeScore(' + count.to_s + ',' + index.to_s + ')&amp;quot;&amp;gt;'&lt;br /&gt;
        html += (self.questionnaire.max_question_score - index).to_s + ' - ' + question_advice.advice + '&amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;'&lt;br /&gt;
        html += '&amp;lt;script&amp;gt;'&lt;br /&gt;
        html += 'function changeScore(i, j) {'&lt;br /&gt;
        html += 'var elem = jQuery(&amp;quot;#responses_&amp;quot; + i.toString() + &amp;quot;_score&amp;quot;);'&lt;br /&gt;
        html += 'var opts = elem.children(&amp;quot;option&amp;quot;).length;'&lt;br /&gt;
        html += 'elem.val((' + self.questionnaire.max_question_score.to_s + ' - j).toString());}'&lt;br /&gt;
        html += '&amp;lt;/script&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;/div&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if dropdown_or_scale == 'dropdown'&lt;br /&gt;
      current_value = &amp;quot;&amp;quot;&lt;br /&gt;
      current_value += 'data-current-rating =' + answer.answer.to_s if !answer.nil?&lt;br /&gt;
      html += '&amp;lt;div&amp;gt;&amp;lt;select id=&amp;quot;responses_' + count.to_s + '_score&amp;quot; name=&amp;quot;responses[' + count.to_s + '][score]&amp;quot; class=&amp;quot;review-rating&amp;quot; ' + current_value + '&amp;gt;'&lt;br /&gt;
      html += &amp;quot;&amp;lt;option value = ''&amp;gt;--&amp;lt;/option&amp;gt;&amp;quot;&lt;br /&gt;
      questionnaire_min.upto(questionnaire_max).each do |j|&lt;br /&gt;
        html += if !answer.nil? and j == answer.answer&lt;br /&gt;
                  '&amp;lt;option value=' + j.to_s + ' selected=&amp;quot;selected&amp;quot;&amp;gt;'&lt;br /&gt;
                else&lt;br /&gt;
                  '&amp;lt;option value=' + j.to_s + '&amp;gt;'&lt;br /&gt;
                end&lt;br /&gt;
&lt;br /&gt;
        html += j.to_s&lt;br /&gt;
        if j == questionnaire_min&lt;br /&gt;
          html += &amp;quot;-&amp;quot; + self.min_label if self.min_label.present?&lt;br /&gt;
        elsif j == questionnaire_max&lt;br /&gt;
          html += &amp;quot;-&amp;quot; + self.max_label if self.max_label.present?&lt;br /&gt;
        end&lt;br /&gt;
        html += &amp;quot;&amp;lt;/option&amp;gt;&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      html += &amp;quot;&amp;lt;/select&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;quot;&lt;br /&gt;
      html += '&amp;lt;textarea' + ' id=&amp;quot;responses_' + count.to_s + '_comments&amp;quot;' \&lt;br /&gt;
       ' name=&amp;quot;responses[' + count.to_s + '][comment]&amp;quot; class=&amp;quot;tinymce&amp;quot;&amp;gt;'&lt;br /&gt;
      html += answer.comments unless answer.nil?&lt;br /&gt;
      html += '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
    elsif dropdown_or_scale == 'scale'&lt;br /&gt;
      html += '&amp;lt;input id=&amp;quot;responses_' + count.to_s + '_score&amp;quot; name=&amp;quot;responses[' + count.to_s + '][score]&amp;quot; type=&amp;quot;hidden&amp;quot;'&lt;br /&gt;
      html += 'value=&amp;quot;' + answer.answer.to_s + '&amp;quot;' unless answer.nil?&lt;br /&gt;
      html += '&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;table&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;tr&amp;gt;&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      (questionnaire_min..questionnaire_max).each do |j|&lt;br /&gt;
        html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;label&amp;gt;' + j.to_s + '&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += if !self.min_label.nil?&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;' + self.min_label + '&amp;lt;/td&amp;gt;'&lt;br /&gt;
              else&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
              end&lt;br /&gt;
      (questionnaire_min..questionnaire_max).each do |j|&lt;br /&gt;
        html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;input type=&amp;quot;radio&amp;quot; id=&amp;quot;' + j.to_s + '&amp;quot; value=&amp;quot;' + j.to_s + '&amp;quot; name=&amp;quot;Radio_' + self.id.to_s + '&amp;quot;'&lt;br /&gt;
        html += 'checked=&amp;quot;checked&amp;quot;' if (!answer.nil? and answer.answer == j) or (answer.nil? and questionnaire_min == j)&lt;br /&gt;
        html += '&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;script&amp;gt;jQuery(&amp;quot;input[name=Radio_' + self.id.to_s + ']:radio&amp;quot;).change(function() {'&lt;br /&gt;
      html += 'var response_score = jQuery(&amp;quot;#responses_' + count.to_s + '_score&amp;quot;);'&lt;br /&gt;
      html += 'var checked_value = jQuery(&amp;quot;input[name=Radio_' + self.id.to_s + ']:checked&amp;quot;).val();'&lt;br /&gt;
      html += 'response_score.val(checked_value);});&amp;lt;/script&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += if !self.max_label.nil?&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;' + self.max_label + '&amp;lt;/td&amp;gt;'&lt;br /&gt;
              else&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;textarea cols=' + cols + ' rows=' + rows + ' id=&amp;quot;responses_' + count.to_s + '_comments&amp;quot;' \&lt;br /&gt;
        ' name=&amp;quot;responses[' + count.to_s + '][comment]&amp;quot; class=&amp;quot;tinymce&amp;quot;&amp;gt;'&lt;br /&gt;
      html += answer.comments unless answer.nil?&lt;br /&gt;
      html += '&amp;lt;/textarea&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
    safe_join([&amp;quot;&amp;quot;.html_safe, &amp;quot;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Proposed Solution==&lt;br /&gt;
All these methods contain HTML text. What we propose to do is to pick these lines of code and move them into an appropriate partial, in the required format. The next task is to find out where in the entire application do these methods get called. The multiple overriding of the method calls in this poorly structured application makes it a challenging task. These method-calls then have to be replaced with the appropriate rendering of a partial in the views. This would make the structure more MVC oriented, and help keep it clean and understandable for the next developer who accesses this file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The changes proposed above were implemented as described below.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text Method===&lt;br /&gt;
This method did not contain any business logic and thus all code was formatted and moved to a new partial file (views/questionnaires/_criterion_view.html.erb). Again, no comments were required due to complete html code and a comment describing the partial was added in addition to other necessary comments in other files.&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/view.html.erb -''' Modified to invoke the partial if question is of type Criterion only. Also changed the question variable to a instance variable (question =&amp;gt; @question) to extend it's scope to the partial. This view is invoked during the view of questions in a questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- &amp;lt;%questions.each do |question| %&amp;gt;&lt;br /&gt;
-   &amp;lt;%if question.is_a? Question%&amp;gt;&lt;br /&gt;
-     &amp;lt;%=question.view_question_text.html_safe%&amp;gt;&lt;br /&gt;
+ &amp;lt;% for @question in questions %&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_view partial if question is of type Criterion %&amp;gt;&lt;br /&gt;
+   &amp;lt;%if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+         &amp;lt;%= render :partial =&amp;gt; 'criterion_view' %&amp;gt;&lt;br /&gt;
+     &amp;lt;%elsif @question.is_a? Question%&amp;gt;&lt;br /&gt;
+         &amp;lt;%= @question.view_question_text.html_safe %&amp;gt;&lt;br /&gt;
    &amp;lt;%end%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_criterion_view.html.erb -''' This partial file has the moved html code from view_question_text. Note that the &amp;quot;self.xxx&amp;quot; have been updated to &amp;quot;@question.xxx&amp;quot; as self referred to question object discussed in 1. Comment added to describe the partial file. Refer the pull request to look at the code.&lt;br /&gt;
&lt;br /&gt;
===The complete Method===&lt;br /&gt;
All the code in the model included html thus was completely removed from there. It was moved to the partial file (app/views/response/_criterion_complete.html.erb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/repsonse/response.html.erb -''' This file calls the complete method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of the complete method only for Criterion type of question objects. This view is invoked during user responds to the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% elsif question.instance_of? Scale %&amp;gt;&lt;br /&gt;
&amp;lt;!--E1911: Replaced the call to criterion.complete method with the newly refactored partial--&amp;gt;&lt;br /&gt;
&amp;lt;%= render partial: 'criterion_complete', :locals =&amp;gt; {:question =&amp;gt; question, :count =&amp;gt; i, :answer =&amp;gt; answer, :questionnaire_min =&amp;gt; @questionnaire.min_question_score, :questionnaire_max =&amp;gt; @questionnaire.max_question_score, &lt;br /&gt;
:dropdown_or_scale =&amp;gt; @dropdown_or_scale} %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;% elsif question.instance_of? Scale %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/response/_criterion_complete.html.erb -''' This file has all the html code that was earlier in the complete method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;question.xxx&amp;quot; because self was referring to copy of question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question Method===&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1.&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122928</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122928"/>
		<updated>2019-04-01T23:12:20Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Affected View Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. There are many other types of question objects like dropdown that have the implementation of similar methods. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The pull request===&lt;br /&gt;
https://github.com/expertiza/expertiza/pull/1407&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details. This method is called only from two view files - one for creating (_questionnaire.html.erb partial file) and another for editing (edit.html.erb). Both these files are in questionnaires view. Verified this using both RubyMine and the grep command. Another interesting thing to note is the use of &amp;quot;self.&amp;quot; to get the attributes associated with question object. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
This method has the same explanation as the edit method except the fact that this method is called only during viewing of questionnaires by an instructor. We observed that this method is also called by in student_quiz view. On further analysis, we found that the student_quiz does not use criterion object and has only three options: TrueFalse, MultipleChoiceRadio and MultipleChoiceCheckbox. So no refactoring is required here. Verified this method isn't called anywhere else using RubyMine and grep command. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic in this method and is completely html code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def view_question_text&lt;br /&gt;
    html = '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt; ' + self.txt + ' &amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt;' + self.type + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;' + self.weight.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    questionnaire = self.questionnaire&lt;br /&gt;
    if !self.max_label.nil? &amp;amp;&amp;amp; !self.min_label.nil?&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt; (' + self.min_label + ') ' + questionnaire.min_question_score.to_s&lt;br /&gt;
      html += ' to ' + questionnaire.max_question_score.to_s + ' (' + self.max_label + ')&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    else&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt;' + questionnaire.min_question_score.to_s + ' to ' + questionnaire.max_question_score.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;TR&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/TR&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the user responds to the question being created in the respective model. In the case of this problem, which deals with criterion type question responses, the complete method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to respond to the criterion question and enter the necessary details. This method is called only from one view file i.e. response.html.erb. This file is in response view. Verified this using both RubyMine and the grep command. Unlike edit or view_question_text the self object does not refer to a global object instead it refers to a copy of the local object. So, we had passed the required object as locals to the partial, along with the parameters required by the method namely question, count, answer, questionnaire_min, questionnaire_max, dropdown_or_scale. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def complete(count, answer = nil, questionnaire_min, questionnaire_max, dropdown_or_scale)&lt;br /&gt;
    if self.size.nil?&lt;br /&gt;
      cols = '70'&lt;br /&gt;
      rows = '1'&lt;br /&gt;
    else&lt;br /&gt;
      cols = self.size.split(',')[0]&lt;br /&gt;
      rows = self.size.split(',')[1]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    html = '&amp;lt;div&amp;gt;&amp;lt;label for=&amp;quot;responses_' + count.to_s + '&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/label&amp;gt;&amp;lt;/div&amp;gt;'&lt;br /&gt;
    # show advice for each criterion question&lt;br /&gt;
    question_advices = QuestionAdvice.where(question_id: self.id).sort_by(&amp;amp;:id)&lt;br /&gt;
    advice_total_length = 0&lt;br /&gt;
&lt;br /&gt;
    question_advices.each do |question_advice|&lt;br /&gt;
      advice_total_length += question_advice.advice.length if question_advice.advice &amp;amp;&amp;amp; question_advice.advice != &amp;quot;&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if !question_advices.empty? and advice_total_length &amp;gt; 0&lt;br /&gt;
      html += '&amp;lt;a id=&amp;quot;showAdivce_' + self.id.to_s + '&amp;quot; onclick=&amp;quot;showAdvice(' + self.id.to_s + ')&amp;quot;&amp;gt;Show advice&amp;lt;/a&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;script&amp;gt;'&lt;br /&gt;
      html += 'function showAdvice(i){'&lt;br /&gt;
      html += 'var element = document.getElementById(&amp;quot;showAdivce_&amp;quot; + i.toString());'&lt;br /&gt;
      html += 'var show = element.innerHTML == &amp;quot;Hide advice&amp;quot;;'&lt;br /&gt;
      html += 'if (show){'&lt;br /&gt;
      html += 'element.innerHTML=&amp;quot;Show advice&amp;quot;;'&lt;br /&gt;
      html += '}else{'&lt;br /&gt;
      html += 'element.innerHTML=&amp;quot;Hide advice&amp;quot;;}'&lt;br /&gt;
      html += 'toggleAdvice(i);}'&lt;br /&gt;
&lt;br /&gt;
      html += 'function toggleAdvice(i) {'&lt;br /&gt;
      html += 'var elem = document.getElementById(i.toString() + &amp;quot;_myDiv&amp;quot;);'&lt;br /&gt;
      html += 'if (elem.style.display == &amp;quot;none&amp;quot;) {'&lt;br /&gt;
      html += 'elem.style.display = &amp;quot;&amp;quot;;'&lt;br /&gt;
      html += '} else {'&lt;br /&gt;
      html += 'elem.style.display = &amp;quot;none&amp;quot;;}}'&lt;br /&gt;
      html += '&amp;lt;/script&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;div id=&amp;quot;' + self.id.to_s + '_myDiv&amp;quot; style=&amp;quot;display: none;&amp;quot;&amp;gt;'&lt;br /&gt;
      # [2015-10-26] Zhewei:&lt;br /&gt;
      # best to order advices high to low, e.g., 5 to 1&lt;br /&gt;
      # each level used to be a link;&lt;br /&gt;
      # clicking on the link caused the dropbox to be filled in with the corresponding number&lt;br /&gt;
      question_advices.reverse.each_with_index do |question_advice, index|&lt;br /&gt;
        html += '&amp;lt;a id=&amp;quot;changeScore_&amp;gt;' + self.id.to_s + '&amp;quot; onclick=&amp;quot;changeScore(' + count.to_s + ',' + index.to_s + ')&amp;quot;&amp;gt;'&lt;br /&gt;
        html += (self.questionnaire.max_question_score - index).to_s + ' - ' + question_advice.advice + '&amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;'&lt;br /&gt;
        html += '&amp;lt;script&amp;gt;'&lt;br /&gt;
        html += 'function changeScore(i, j) {'&lt;br /&gt;
        html += 'var elem = jQuery(&amp;quot;#responses_&amp;quot; + i.toString() + &amp;quot;_score&amp;quot;);'&lt;br /&gt;
        html += 'var opts = elem.children(&amp;quot;option&amp;quot;).length;'&lt;br /&gt;
        html += 'elem.val((' + self.questionnaire.max_question_score.to_s + ' - j).toString());}'&lt;br /&gt;
        html += '&amp;lt;/script&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;/div&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if dropdown_or_scale == 'dropdown'&lt;br /&gt;
      current_value = &amp;quot;&amp;quot;&lt;br /&gt;
      current_value += 'data-current-rating =' + answer.answer.to_s if !answer.nil?&lt;br /&gt;
      html += '&amp;lt;div&amp;gt;&amp;lt;select id=&amp;quot;responses_' + count.to_s + '_score&amp;quot; name=&amp;quot;responses[' + count.to_s + '][score]&amp;quot; class=&amp;quot;review-rating&amp;quot; ' + current_value + '&amp;gt;'&lt;br /&gt;
      html += &amp;quot;&amp;lt;option value = ''&amp;gt;--&amp;lt;/option&amp;gt;&amp;quot;&lt;br /&gt;
      questionnaire_min.upto(questionnaire_max).each do |j|&lt;br /&gt;
        html += if !answer.nil? and j == answer.answer&lt;br /&gt;
                  '&amp;lt;option value=' + j.to_s + ' selected=&amp;quot;selected&amp;quot;&amp;gt;'&lt;br /&gt;
                else&lt;br /&gt;
                  '&amp;lt;option value=' + j.to_s + '&amp;gt;'&lt;br /&gt;
                end&lt;br /&gt;
&lt;br /&gt;
        html += j.to_s&lt;br /&gt;
        if j == questionnaire_min&lt;br /&gt;
          html += &amp;quot;-&amp;quot; + self.min_label if self.min_label.present?&lt;br /&gt;
        elsif j == questionnaire_max&lt;br /&gt;
          html += &amp;quot;-&amp;quot; + self.max_label if self.max_label.present?&lt;br /&gt;
        end&lt;br /&gt;
        html += &amp;quot;&amp;lt;/option&amp;gt;&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      html += &amp;quot;&amp;lt;/select&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;quot;&lt;br /&gt;
      html += '&amp;lt;textarea' + ' id=&amp;quot;responses_' + count.to_s + '_comments&amp;quot;' \&lt;br /&gt;
       ' name=&amp;quot;responses[' + count.to_s + '][comment]&amp;quot; class=&amp;quot;tinymce&amp;quot;&amp;gt;'&lt;br /&gt;
      html += answer.comments unless answer.nil?&lt;br /&gt;
      html += '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
    elsif dropdown_or_scale == 'scale'&lt;br /&gt;
      html += '&amp;lt;input id=&amp;quot;responses_' + count.to_s + '_score&amp;quot; name=&amp;quot;responses[' + count.to_s + '][score]&amp;quot; type=&amp;quot;hidden&amp;quot;'&lt;br /&gt;
      html += 'value=&amp;quot;' + answer.answer.to_s + '&amp;quot;' unless answer.nil?&lt;br /&gt;
      html += '&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;table&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;tr&amp;gt;&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      (questionnaire_min..questionnaire_max).each do |j|&lt;br /&gt;
        html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;label&amp;gt;' + j.to_s + '&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += if !self.min_label.nil?&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;' + self.min_label + '&amp;lt;/td&amp;gt;'&lt;br /&gt;
              else&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
              end&lt;br /&gt;
      (questionnaire_min..questionnaire_max).each do |j|&lt;br /&gt;
        html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;input type=&amp;quot;radio&amp;quot; id=&amp;quot;' + j.to_s + '&amp;quot; value=&amp;quot;' + j.to_s + '&amp;quot; name=&amp;quot;Radio_' + self.id.to_s + '&amp;quot;'&lt;br /&gt;
        html += 'checked=&amp;quot;checked&amp;quot;' if (!answer.nil? and answer.answer == j) or (answer.nil? and questionnaire_min == j)&lt;br /&gt;
        html += '&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;script&amp;gt;jQuery(&amp;quot;input[name=Radio_' + self.id.to_s + ']:radio&amp;quot;).change(function() {'&lt;br /&gt;
      html += 'var response_score = jQuery(&amp;quot;#responses_' + count.to_s + '_score&amp;quot;);'&lt;br /&gt;
      html += 'var checked_value = jQuery(&amp;quot;input[name=Radio_' + self.id.to_s + ']:checked&amp;quot;).val();'&lt;br /&gt;
      html += 'response_score.val(checked_value);});&amp;lt;/script&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += if !self.max_label.nil?&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;' + self.max_label + '&amp;lt;/td&amp;gt;'&lt;br /&gt;
              else&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;textarea cols=' + cols + ' rows=' + rows + ' id=&amp;quot;responses_' + count.to_s + '_comments&amp;quot;' \&lt;br /&gt;
        ' name=&amp;quot;responses[' + count.to_s + '][comment]&amp;quot; class=&amp;quot;tinymce&amp;quot;&amp;gt;'&lt;br /&gt;
      html += answer.comments unless answer.nil?&lt;br /&gt;
      html += '&amp;lt;/textarea&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
    safe_join([&amp;quot;&amp;quot;.html_safe, &amp;quot;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Proposed Solution==&lt;br /&gt;
All these methods contain HTML text. What we propose to do is to pick these lines of code and move them into an appropriate partial, in the required format. The next task is to find out where in the entire application do these methods get called. The multiple overriding of the method calls in this poorly structured application makes it a challenging task. These method-calls then have to be replaced with the appropriate rendering of a partial in the views. This would make the structure more MVC oriented, and help keep it clean and understandable for the next developer who accesses this file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The changes proposed above were implemented as described below.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text Method===&lt;br /&gt;
This method did not contain any business logic and thus all code was formatted and moved to a new partial file (views/questionnaires/_criterion_view.html.erb). Again, no comments were required due to complete html code and a comment describing the partial was added in addition to other necessary comments in other files.&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/view.html.erb -''' Modified to invoke the partial if question is of type Criterion only. Also changed the question variable to a instance variable (question =&amp;gt; @question) to extend it's scope to the partial. This view is invoked during the view of questions in a questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- &amp;lt;%questions.each do |question| %&amp;gt;&lt;br /&gt;
-   &amp;lt;%if question.is_a? Question%&amp;gt;&lt;br /&gt;
-     &amp;lt;%=question.view_question_text.html_safe%&amp;gt;&lt;br /&gt;
+ &amp;lt;% for @question in questions %&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_view partial if question is of type Criterion %&amp;gt;&lt;br /&gt;
+   &amp;lt;%if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+         &amp;lt;%= render :partial =&amp;gt; 'criterion_view' %&amp;gt;&lt;br /&gt;
+     &amp;lt;%elsif @question.is_a? Question%&amp;gt;&lt;br /&gt;
+         &amp;lt;%= @question.view_question_text.html_safe %&amp;gt;&lt;br /&gt;
    &amp;lt;%end%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_criterion_view.html.erb -''' This partial file has the moved html code from view_question_text. Note that the &amp;quot;self.xxx&amp;quot; have been updated to &amp;quot;@question.xxx&amp;quot; as self referred to question object discussed in 1. Comment added to describe the partial file. Refer the pull request to look at the code.&lt;br /&gt;
&lt;br /&gt;
===The complete Method===&lt;br /&gt;
All the code in the model included html thus was completely removed from there. It was moved to the partial file (app/views/response/_criterion_complete.html.erb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/repsonse/response.html.erb -''' This file calls the complete method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of the complete method only for Criterion type of question objects. This view is invoked during user responds to the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% elsif question.instance_of? Scale %&amp;gt;&lt;br /&gt;
&amp;lt;!--E1911: Replaced the call to criterion.complete method with the newly refactored partial--&amp;gt;&lt;br /&gt;
&amp;lt;%= render partial: 'criterion_complete', :locals =&amp;gt; {:question =&amp;gt; question, :count =&amp;gt; i, :answer =&amp;gt; answer, :questionnaire_min =&amp;gt; @questionnaire.min_question_score, :questionnaire_max =&amp;gt; @questionnaire.max_question_score, :dropdown_or_scale =&amp;gt; @dropdown_or_scale} %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;% elsif question.instance_of? Scale %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/response/_criterion_complete.html.erb -''' This file has all the html code that was earlier in the complete method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;question.xxx&amp;quot; because self was referring to copy of question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question Method===&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1.&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122927</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122927"/>
		<updated>2019-04-01T23:09:24Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Affected View Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. There are many other types of question objects like dropdown that have the implementation of similar methods. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The pull request===&lt;br /&gt;
https://github.com/expertiza/expertiza/pull/1407&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details. This method is called only from two view files - one for creating (_questionnaire.html.erb partial file) and another for editing (edit.html.erb). Both these files are in questionnaires view. Verified this using both RubyMine and the grep command. Another interesting thing to note is the use of &amp;quot;self.&amp;quot; to get the attributes associated with question object. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
This method has the same explanation as the edit method except the fact that this method is called only during viewing of questionnaires by an instructor. We observed that this method is also called by in student_quiz view. On further analysis, we found that the student_quiz does not use criterion object and has only three options: TrueFalse, MultipleChoiceRadio and MultipleChoiceCheckbox. So no refactoring is required here. Verified this method isn't called anywhere else using RubyMine and grep command. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic in this method and is completely html code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def view_question_text&lt;br /&gt;
    html = '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt; ' + self.txt + ' &amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt;' + self.type + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;' + self.weight.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    questionnaire = self.questionnaire&lt;br /&gt;
    if !self.max_label.nil? &amp;amp;&amp;amp; !self.min_label.nil?&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt; (' + self.min_label + ') ' + questionnaire.min_question_score.to_s&lt;br /&gt;
      html += ' to ' + questionnaire.max_question_score.to_s + ' (' + self.max_label + ')&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    else&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt;' + questionnaire.min_question_score.to_s + ' to ' + questionnaire.max_question_score.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;TR&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/TR&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the user responds to the question being created in the respective model. In the case of this problem, which deals with criterion type question responses, the complete method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to respond to the criterion question and enter the necessary details. This method is called only from one view file i.e. response.html.erb. This file is in response view. Verified this using both RubyMine and the grep command. Unlike edit or view_question_text the self object does not refer to a global object instead it refers to a copy of the local object. So, we had passed the required object as locals to the partial, along with the parameters required by the method namely question, count, answer, questionnaire_min, questionnaire_max, dropdown_or_scale. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def complete(count, answer = nil, questionnaire_min, questionnaire_max, dropdown_or_scale)&lt;br /&gt;
    if self.size.nil?&lt;br /&gt;
      cols = '70'&lt;br /&gt;
      rows = '1'&lt;br /&gt;
    else&lt;br /&gt;
      cols = self.size.split(',')[0]&lt;br /&gt;
      rows = self.size.split(',')[1]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    html = '&amp;lt;div&amp;gt;&amp;lt;label for=&amp;quot;responses_' + count.to_s + '&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/label&amp;gt;&amp;lt;/div&amp;gt;'&lt;br /&gt;
    # show advice for each criterion question&lt;br /&gt;
    question_advices = QuestionAdvice.where(question_id: self.id).sort_by(&amp;amp;:id)&lt;br /&gt;
    advice_total_length = 0&lt;br /&gt;
&lt;br /&gt;
    question_advices.each do |question_advice|&lt;br /&gt;
      advice_total_length += question_advice.advice.length if question_advice.advice &amp;amp;&amp;amp; question_advice.advice != &amp;quot;&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if !question_advices.empty? and advice_total_length &amp;gt; 0&lt;br /&gt;
      html += '&amp;lt;a id=&amp;quot;showAdivce_' + self.id.to_s + '&amp;quot; onclick=&amp;quot;showAdvice(' + self.id.to_s + ')&amp;quot;&amp;gt;Show advice&amp;lt;/a&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;script&amp;gt;'&lt;br /&gt;
      html += 'function showAdvice(i){'&lt;br /&gt;
      html += 'var element = document.getElementById(&amp;quot;showAdivce_&amp;quot; + i.toString());'&lt;br /&gt;
      html += 'var show = element.innerHTML == &amp;quot;Hide advice&amp;quot;;'&lt;br /&gt;
      html += 'if (show){'&lt;br /&gt;
      html += 'element.innerHTML=&amp;quot;Show advice&amp;quot;;'&lt;br /&gt;
      html += '}else{'&lt;br /&gt;
      html += 'element.innerHTML=&amp;quot;Hide advice&amp;quot;;}'&lt;br /&gt;
      html += 'toggleAdvice(i);}'&lt;br /&gt;
&lt;br /&gt;
      html += 'function toggleAdvice(i) {'&lt;br /&gt;
      html += 'var elem = document.getElementById(i.toString() + &amp;quot;_myDiv&amp;quot;);'&lt;br /&gt;
      html += 'if (elem.style.display == &amp;quot;none&amp;quot;) {'&lt;br /&gt;
      html += 'elem.style.display = &amp;quot;&amp;quot;;'&lt;br /&gt;
      html += '} else {'&lt;br /&gt;
      html += 'elem.style.display = &amp;quot;none&amp;quot;;}}'&lt;br /&gt;
      html += '&amp;lt;/script&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;div id=&amp;quot;' + self.id.to_s + '_myDiv&amp;quot; style=&amp;quot;display: none;&amp;quot;&amp;gt;'&lt;br /&gt;
      # [2015-10-26] Zhewei:&lt;br /&gt;
      # best to order advices high to low, e.g., 5 to 1&lt;br /&gt;
      # each level used to be a link;&lt;br /&gt;
      # clicking on the link caused the dropbox to be filled in with the corresponding number&lt;br /&gt;
      question_advices.reverse.each_with_index do |question_advice, index|&lt;br /&gt;
        html += '&amp;lt;a id=&amp;quot;changeScore_&amp;gt;' + self.id.to_s + '&amp;quot; onclick=&amp;quot;changeScore(' + count.to_s + ',' + index.to_s + ')&amp;quot;&amp;gt;'&lt;br /&gt;
        html += (self.questionnaire.max_question_score - index).to_s + ' - ' + question_advice.advice + '&amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;'&lt;br /&gt;
        html += '&amp;lt;script&amp;gt;'&lt;br /&gt;
        html += 'function changeScore(i, j) {'&lt;br /&gt;
        html += 'var elem = jQuery(&amp;quot;#responses_&amp;quot; + i.toString() + &amp;quot;_score&amp;quot;);'&lt;br /&gt;
        html += 'var opts = elem.children(&amp;quot;option&amp;quot;).length;'&lt;br /&gt;
        html += 'elem.val((' + self.questionnaire.max_question_score.to_s + ' - j).toString());}'&lt;br /&gt;
        html += '&amp;lt;/script&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;/div&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if dropdown_or_scale == 'dropdown'&lt;br /&gt;
      current_value = &amp;quot;&amp;quot;&lt;br /&gt;
      current_value += 'data-current-rating =' + answer.answer.to_s if !answer.nil?&lt;br /&gt;
      html += '&amp;lt;div&amp;gt;&amp;lt;select id=&amp;quot;responses_' + count.to_s + '_score&amp;quot; name=&amp;quot;responses[' + count.to_s + '][score]&amp;quot; class=&amp;quot;review-rating&amp;quot; ' + current_value + '&amp;gt;'&lt;br /&gt;
      html += &amp;quot;&amp;lt;option value = ''&amp;gt;--&amp;lt;/option&amp;gt;&amp;quot;&lt;br /&gt;
      questionnaire_min.upto(questionnaire_max).each do |j|&lt;br /&gt;
        html += if !answer.nil? and j == answer.answer&lt;br /&gt;
                  '&amp;lt;option value=' + j.to_s + ' selected=&amp;quot;selected&amp;quot;&amp;gt;'&lt;br /&gt;
                else&lt;br /&gt;
                  '&amp;lt;option value=' + j.to_s + '&amp;gt;'&lt;br /&gt;
                end&lt;br /&gt;
&lt;br /&gt;
        html += j.to_s&lt;br /&gt;
        if j == questionnaire_min&lt;br /&gt;
          html += &amp;quot;-&amp;quot; + self.min_label if self.min_label.present?&lt;br /&gt;
        elsif j == questionnaire_max&lt;br /&gt;
          html += &amp;quot;-&amp;quot; + self.max_label if self.max_label.present?&lt;br /&gt;
        end&lt;br /&gt;
        html += &amp;quot;&amp;lt;/option&amp;gt;&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      html += &amp;quot;&amp;lt;/select&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;quot;&lt;br /&gt;
      html += '&amp;lt;textarea' + ' id=&amp;quot;responses_' + count.to_s + '_comments&amp;quot;' \&lt;br /&gt;
       ' name=&amp;quot;responses[' + count.to_s + '][comment]&amp;quot; class=&amp;quot;tinymce&amp;quot;&amp;gt;'&lt;br /&gt;
      html += answer.comments unless answer.nil?&lt;br /&gt;
      html += '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
    elsif dropdown_or_scale == 'scale'&lt;br /&gt;
      html += '&amp;lt;input id=&amp;quot;responses_' + count.to_s + '_score&amp;quot; name=&amp;quot;responses[' + count.to_s + '][score]&amp;quot; type=&amp;quot;hidden&amp;quot;'&lt;br /&gt;
      html += 'value=&amp;quot;' + answer.answer.to_s + '&amp;quot;' unless answer.nil?&lt;br /&gt;
      html += '&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;table&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;tr&amp;gt;&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      (questionnaire_min..questionnaire_max).each do |j|&lt;br /&gt;
        html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;label&amp;gt;' + j.to_s + '&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += if !self.min_label.nil?&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;' + self.min_label + '&amp;lt;/td&amp;gt;'&lt;br /&gt;
              else&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
              end&lt;br /&gt;
      (questionnaire_min..questionnaire_max).each do |j|&lt;br /&gt;
        html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;input type=&amp;quot;radio&amp;quot; id=&amp;quot;' + j.to_s + '&amp;quot; value=&amp;quot;' + j.to_s + '&amp;quot; name=&amp;quot;Radio_' + self.id.to_s + '&amp;quot;'&lt;br /&gt;
        html += 'checked=&amp;quot;checked&amp;quot;' if (!answer.nil? and answer.answer == j) or (answer.nil? and questionnaire_min == j)&lt;br /&gt;
        html += '&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;script&amp;gt;jQuery(&amp;quot;input[name=Radio_' + self.id.to_s + ']:radio&amp;quot;).change(function() {'&lt;br /&gt;
      html += 'var response_score = jQuery(&amp;quot;#responses_' + count.to_s + '_score&amp;quot;);'&lt;br /&gt;
      html += 'var checked_value = jQuery(&amp;quot;input[name=Radio_' + self.id.to_s + ']:checked&amp;quot;).val();'&lt;br /&gt;
      html += 'response_score.val(checked_value);});&amp;lt;/script&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += if !self.max_label.nil?&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;' + self.max_label + '&amp;lt;/td&amp;gt;'&lt;br /&gt;
              else&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;textarea cols=' + cols + ' rows=' + rows + ' id=&amp;quot;responses_' + count.to_s + '_comments&amp;quot;' \&lt;br /&gt;
        ' name=&amp;quot;responses[' + count.to_s + '][comment]&amp;quot; class=&amp;quot;tinymce&amp;quot;&amp;gt;'&lt;br /&gt;
      html += answer.comments unless answer.nil?&lt;br /&gt;
      html += '&amp;lt;/textarea&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
    safe_join([&amp;quot;&amp;quot;.html_safe, &amp;quot;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Proposed Solution==&lt;br /&gt;
All these methods contain HTML text. What we propose to do is to pick these lines of code and move them into an appropriate partial, in the required format. The next task is to find out where in the entire application do these methods get called. The multiple overriding of the method calls in this poorly structured application makes it a challenging task. These method-calls then have to be replaced with the appropriate rendering of a partial in the views. This would make the structure more MVC oriented, and help keep it clean and understandable for the next developer who accesses this file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The changes proposed above were implemented as described below.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text Method===&lt;br /&gt;
This method did not contain any business logic and thus all code was formatted and moved to a new partial file (views/questionnaires/_criterion_view.html.erb). Again, no comments were required due to complete html code and a comment describing the partial was added in addition to other necessary comments in other files.&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/view.html.erb -''' Modified to invoke the partial if question is of type Criterion only. Also changed the question variable to a instance variable (question =&amp;gt; @question) to extend it's scope to the partial. This view is invoked during the view of questions in a questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- &amp;lt;%questions.each do |question| %&amp;gt;&lt;br /&gt;
-   &amp;lt;%if question.is_a? Question%&amp;gt;&lt;br /&gt;
-     &amp;lt;%=question.view_question_text.html_safe%&amp;gt;&lt;br /&gt;
+ &amp;lt;% for @question in questions %&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_view partial if question is of type Criterion %&amp;gt;&lt;br /&gt;
+   &amp;lt;%if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+         &amp;lt;%= render :partial =&amp;gt; 'criterion_view' %&amp;gt;&lt;br /&gt;
+     &amp;lt;%elsif @question.is_a? Question%&amp;gt;&lt;br /&gt;
+         &amp;lt;%= @question.view_question_text.html_safe %&amp;gt;&lt;br /&gt;
    &amp;lt;%end%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_criterion_view.html.erb -''' This partial file has the moved html code from view_question_text. Note that the &amp;quot;self.xxx&amp;quot; have been updated to &amp;quot;@question.xxx&amp;quot; as self referred to question object discussed in 1. Comment added to describe the partial file. Refer the pull request to look at the code.&lt;br /&gt;
&lt;br /&gt;
===The complete Method===&lt;br /&gt;
All the code in the model included html thus was completely removed from there. It was moved to the partial file (app/views/response/_criterion_complete.html.erb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/repsonse/response.html.erb -''' This file calls the complete method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of the complete method only for Criterion type of question objects. This view is invoked during user responds to the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% elsif question.instance_of? Scale %&amp;gt;&lt;br /&gt;
&amp;lt;!--E1911: Replaced the call to criterion.complete method with the newly refactored partial--&amp;gt;&lt;br /&gt;
&amp;lt;%= render partial: 'criterion_complete', :locals =&amp;gt; {:question =&amp;gt; question, :count =&amp;gt; i, :answer =&amp;gt; answer, :questionnaire_min =&amp;gt; @questionnaire.min_question_score, :questionnaire_max =&amp;gt; @questionnaire.max_question_score, :dropdown_or_scale =&amp;gt; @dropdown_or_scale} %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;% elsif question.instance_of? Scale %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question Method===&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1.&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122926</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122926"/>
		<updated>2019-04-01T23:08:22Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* The complete Method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. There are many other types of question objects like dropdown that have the implementation of similar methods. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The pull request===&lt;br /&gt;
https://github.com/expertiza/expertiza/pull/1407&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details. This method is called only from two view files - one for creating (_questionnaire.html.erb partial file) and another for editing (edit.html.erb). Both these files are in questionnaires view. Verified this using both RubyMine and the grep command. Another interesting thing to note is the use of &amp;quot;self.&amp;quot; to get the attributes associated with question object. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
This method has the same explanation as the edit method except the fact that this method is called only during viewing of questionnaires by an instructor. We observed that this method is also called by in student_quiz view. On further analysis, we found that the student_quiz does not use criterion object and has only three options: TrueFalse, MultipleChoiceRadio and MultipleChoiceCheckbox. So no refactoring is required here. Verified this method isn't called anywhere else using RubyMine and grep command. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic in this method and is completely html code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def view_question_text&lt;br /&gt;
    html = '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt; ' + self.txt + ' &amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt;' + self.type + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;' + self.weight.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    questionnaire = self.questionnaire&lt;br /&gt;
    if !self.max_label.nil? &amp;amp;&amp;amp; !self.min_label.nil?&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt; (' + self.min_label + ') ' + questionnaire.min_question_score.to_s&lt;br /&gt;
      html += ' to ' + questionnaire.max_question_score.to_s + ' (' + self.max_label + ')&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    else&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt;' + questionnaire.min_question_score.to_s + ' to ' + questionnaire.max_question_score.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;TR&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/TR&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the user responds to the question being created in the respective model. In the case of this problem, which deals with criterion type question responses, the complete method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to respond to the criterion question and enter the necessary details. This method is called only from one view file i.e. response.html.erb. This file is in response view. Verified this using both RubyMine and the grep command. Unlike edit or view_question_text the self object does not refer to a global object instead it refers to a copy of the local object. So, we had passed the required object as locals to the partial, along with the parameters required by the method namely question, count, answer, questionnaire_min, questionnaire_max, dropdown_or_scale. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def complete(count, answer = nil, questionnaire_min, questionnaire_max, dropdown_or_scale)&lt;br /&gt;
    if self.size.nil?&lt;br /&gt;
      cols = '70'&lt;br /&gt;
      rows = '1'&lt;br /&gt;
    else&lt;br /&gt;
      cols = self.size.split(',')[0]&lt;br /&gt;
      rows = self.size.split(',')[1]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    html = '&amp;lt;div&amp;gt;&amp;lt;label for=&amp;quot;responses_' + count.to_s + '&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/label&amp;gt;&amp;lt;/div&amp;gt;'&lt;br /&gt;
    # show advice for each criterion question&lt;br /&gt;
    question_advices = QuestionAdvice.where(question_id: self.id).sort_by(&amp;amp;:id)&lt;br /&gt;
    advice_total_length = 0&lt;br /&gt;
&lt;br /&gt;
    question_advices.each do |question_advice|&lt;br /&gt;
      advice_total_length += question_advice.advice.length if question_advice.advice &amp;amp;&amp;amp; question_advice.advice != &amp;quot;&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if !question_advices.empty? and advice_total_length &amp;gt; 0&lt;br /&gt;
      html += '&amp;lt;a id=&amp;quot;showAdivce_' + self.id.to_s + '&amp;quot; onclick=&amp;quot;showAdvice(' + self.id.to_s + ')&amp;quot;&amp;gt;Show advice&amp;lt;/a&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;script&amp;gt;'&lt;br /&gt;
      html += 'function showAdvice(i){'&lt;br /&gt;
      html += 'var element = document.getElementById(&amp;quot;showAdivce_&amp;quot; + i.toString());'&lt;br /&gt;
      html += 'var show = element.innerHTML == &amp;quot;Hide advice&amp;quot;;'&lt;br /&gt;
      html += 'if (show){'&lt;br /&gt;
      html += 'element.innerHTML=&amp;quot;Show advice&amp;quot;;'&lt;br /&gt;
      html += '}else{'&lt;br /&gt;
      html += 'element.innerHTML=&amp;quot;Hide advice&amp;quot;;}'&lt;br /&gt;
      html += 'toggleAdvice(i);}'&lt;br /&gt;
&lt;br /&gt;
      html += 'function toggleAdvice(i) {'&lt;br /&gt;
      html += 'var elem = document.getElementById(i.toString() + &amp;quot;_myDiv&amp;quot;);'&lt;br /&gt;
      html += 'if (elem.style.display == &amp;quot;none&amp;quot;) {'&lt;br /&gt;
      html += 'elem.style.display = &amp;quot;&amp;quot;;'&lt;br /&gt;
      html += '} else {'&lt;br /&gt;
      html += 'elem.style.display = &amp;quot;none&amp;quot;;}}'&lt;br /&gt;
      html += '&amp;lt;/script&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;div id=&amp;quot;' + self.id.to_s + '_myDiv&amp;quot; style=&amp;quot;display: none;&amp;quot;&amp;gt;'&lt;br /&gt;
      # [2015-10-26] Zhewei:&lt;br /&gt;
      # best to order advices high to low, e.g., 5 to 1&lt;br /&gt;
      # each level used to be a link;&lt;br /&gt;
      # clicking on the link caused the dropbox to be filled in with the corresponding number&lt;br /&gt;
      question_advices.reverse.each_with_index do |question_advice, index|&lt;br /&gt;
        html += '&amp;lt;a id=&amp;quot;changeScore_&amp;gt;' + self.id.to_s + '&amp;quot; onclick=&amp;quot;changeScore(' + count.to_s + ',' + index.to_s + ')&amp;quot;&amp;gt;'&lt;br /&gt;
        html += (self.questionnaire.max_question_score - index).to_s + ' - ' + question_advice.advice + '&amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;'&lt;br /&gt;
        html += '&amp;lt;script&amp;gt;'&lt;br /&gt;
        html += 'function changeScore(i, j) {'&lt;br /&gt;
        html += 'var elem = jQuery(&amp;quot;#responses_&amp;quot; + i.toString() + &amp;quot;_score&amp;quot;);'&lt;br /&gt;
        html += 'var opts = elem.children(&amp;quot;option&amp;quot;).length;'&lt;br /&gt;
        html += 'elem.val((' + self.questionnaire.max_question_score.to_s + ' - j).toString());}'&lt;br /&gt;
        html += '&amp;lt;/script&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;/div&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if dropdown_or_scale == 'dropdown'&lt;br /&gt;
      current_value = &amp;quot;&amp;quot;&lt;br /&gt;
      current_value += 'data-current-rating =' + answer.answer.to_s if !answer.nil?&lt;br /&gt;
      html += '&amp;lt;div&amp;gt;&amp;lt;select id=&amp;quot;responses_' + count.to_s + '_score&amp;quot; name=&amp;quot;responses[' + count.to_s + '][score]&amp;quot; class=&amp;quot;review-rating&amp;quot; ' + current_value + '&amp;gt;'&lt;br /&gt;
      html += &amp;quot;&amp;lt;option value = ''&amp;gt;--&amp;lt;/option&amp;gt;&amp;quot;&lt;br /&gt;
      questionnaire_min.upto(questionnaire_max).each do |j|&lt;br /&gt;
        html += if !answer.nil? and j == answer.answer&lt;br /&gt;
                  '&amp;lt;option value=' + j.to_s + ' selected=&amp;quot;selected&amp;quot;&amp;gt;'&lt;br /&gt;
                else&lt;br /&gt;
                  '&amp;lt;option value=' + j.to_s + '&amp;gt;'&lt;br /&gt;
                end&lt;br /&gt;
&lt;br /&gt;
        html += j.to_s&lt;br /&gt;
        if j == questionnaire_min&lt;br /&gt;
          html += &amp;quot;-&amp;quot; + self.min_label if self.min_label.present?&lt;br /&gt;
        elsif j == questionnaire_max&lt;br /&gt;
          html += &amp;quot;-&amp;quot; + self.max_label if self.max_label.present?&lt;br /&gt;
        end&lt;br /&gt;
        html += &amp;quot;&amp;lt;/option&amp;gt;&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      html += &amp;quot;&amp;lt;/select&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;quot;&lt;br /&gt;
      html += '&amp;lt;textarea' + ' id=&amp;quot;responses_' + count.to_s + '_comments&amp;quot;' \&lt;br /&gt;
       ' name=&amp;quot;responses[' + count.to_s + '][comment]&amp;quot; class=&amp;quot;tinymce&amp;quot;&amp;gt;'&lt;br /&gt;
      html += answer.comments unless answer.nil?&lt;br /&gt;
      html += '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
    elsif dropdown_or_scale == 'scale'&lt;br /&gt;
      html += '&amp;lt;input id=&amp;quot;responses_' + count.to_s + '_score&amp;quot; name=&amp;quot;responses[' + count.to_s + '][score]&amp;quot; type=&amp;quot;hidden&amp;quot;'&lt;br /&gt;
      html += 'value=&amp;quot;' + answer.answer.to_s + '&amp;quot;' unless answer.nil?&lt;br /&gt;
      html += '&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;table&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;tr&amp;gt;&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      (questionnaire_min..questionnaire_max).each do |j|&lt;br /&gt;
        html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;label&amp;gt;' + j.to_s + '&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += if !self.min_label.nil?&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;' + self.min_label + '&amp;lt;/td&amp;gt;'&lt;br /&gt;
              else&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
              end&lt;br /&gt;
      (questionnaire_min..questionnaire_max).each do |j|&lt;br /&gt;
        html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;input type=&amp;quot;radio&amp;quot; id=&amp;quot;' + j.to_s + '&amp;quot; value=&amp;quot;' + j.to_s + '&amp;quot; name=&amp;quot;Radio_' + self.id.to_s + '&amp;quot;'&lt;br /&gt;
        html += 'checked=&amp;quot;checked&amp;quot;' if (!answer.nil? and answer.answer == j) or (answer.nil? and questionnaire_min == j)&lt;br /&gt;
        html += '&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;script&amp;gt;jQuery(&amp;quot;input[name=Radio_' + self.id.to_s + ']:radio&amp;quot;).change(function() {'&lt;br /&gt;
      html += 'var response_score = jQuery(&amp;quot;#responses_' + count.to_s + '_score&amp;quot;);'&lt;br /&gt;
      html += 'var checked_value = jQuery(&amp;quot;input[name=Radio_' + self.id.to_s + ']:checked&amp;quot;).val();'&lt;br /&gt;
      html += 'response_score.val(checked_value);});&amp;lt;/script&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += if !self.max_label.nil?&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;' + self.max_label + '&amp;lt;/td&amp;gt;'&lt;br /&gt;
              else&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;textarea cols=' + cols + ' rows=' + rows + ' id=&amp;quot;responses_' + count.to_s + '_comments&amp;quot;' \&lt;br /&gt;
        ' name=&amp;quot;responses[' + count.to_s + '][comment]&amp;quot; class=&amp;quot;tinymce&amp;quot;&amp;gt;'&lt;br /&gt;
      html += answer.comments unless answer.nil?&lt;br /&gt;
      html += '&amp;lt;/textarea&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
    safe_join([&amp;quot;&amp;quot;.html_safe, &amp;quot;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Proposed Solution==&lt;br /&gt;
All these methods contain HTML text. What we propose to do is to pick these lines of code and move them into an appropriate partial, in the required format. The next task is to find out where in the entire application do these methods get called. The multiple overriding of the method calls in this poorly structured application makes it a challenging task. These method-calls then have to be replaced with the appropriate rendering of a partial in the views. This would make the structure more MVC oriented, and help keep it clean and understandable for the next developer who accesses this file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The changes proposed above were implemented as described below.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_question_text Method===&lt;br /&gt;
This method did not contain any business logic and thus all code was formatted and moved to a new partial file (views/questionnaires/_criterion_view.html.erb). Again, no comments were required due to complete html code and a comment describing the partial was added in addition to other necessary comments in other files.&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/view.html.erb -''' Modified to invoke the partial if question is of type Criterion only. Also changed the question variable to a instance variable (question =&amp;gt; @question) to extend it's scope to the partial. This view is invoked during the view of questions in a questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- &amp;lt;%questions.each do |question| %&amp;gt;&lt;br /&gt;
-   &amp;lt;%if question.is_a? Question%&amp;gt;&lt;br /&gt;
-     &amp;lt;%=question.view_question_text.html_safe%&amp;gt;&lt;br /&gt;
+ &amp;lt;% for @question in questions %&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_view partial if question is of type Criterion %&amp;gt;&lt;br /&gt;
+   &amp;lt;%if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+         &amp;lt;%= render :partial =&amp;gt; 'criterion_view' %&amp;gt;&lt;br /&gt;
+     &amp;lt;%elsif @question.is_a? Question%&amp;gt;&lt;br /&gt;
+         &amp;lt;%= @question.view_question_text.html_safe %&amp;gt;&lt;br /&gt;
    &amp;lt;%end%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_criterion_view.html.erb -''' This partial file has the moved html code from view_question_text. Note that the &amp;quot;self.xxx&amp;quot; have been updated to &amp;quot;@question.xxx&amp;quot; as self referred to question object discussed in 1. Comment added to describe the partial file. Refer the pull request to look at the code.&lt;br /&gt;
&lt;br /&gt;
===The complete Method===&lt;br /&gt;
All the code in the model included html thus was completely removed from there. It was moved to the partial file (app/views/response/_criterion_complete.html.erb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/repsonse/response.html.erb -''' This file calls the complete method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of the complete method only for Criterion type of question objects. This view is invoked during user responds to the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% elsif question.instance_of? Scale %&amp;gt;&lt;br /&gt;
&amp;lt;!--E1911: Replaced the call to criterion.complete method with the newly refactored partial--&amp;gt;&lt;br /&gt;
&amp;lt;%= render partial: 'criterion_complete', :locals =&amp;gt; {:question =&amp;gt; question, :count =&amp;gt; i, :answer =&amp;gt; answer, :questionnaire_min =&amp;gt; @questionnaire.min_question_score, :questionnaire_max =&amp;gt; @questionnaire.max_question_score, :dropdown_or_scale =&amp;gt; @dropdown_or_scale} %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;% elsif question.instance_of? Scale %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question Method===&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1.&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122924</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122924"/>
		<updated>2019-04-01T23:01:05Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. There are many other types of question objects like dropdown that have the implementation of similar methods. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The pull request===&lt;br /&gt;
https://github.com/expertiza/expertiza/pull/1407&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details. This method is called only from two view files - one for creating (_questionnaire.html.erb partial file) and another for editing (edit.html.erb). Both these files are in questionnaires view. Verified this using both RubyMine and the grep command. Another interesting thing to note is the use of &amp;quot;self.&amp;quot; to get the attributes associated with question object. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
This method has the same explanation as the edit method except the fact that this method is called only during viewing of questionnaires by an instructor. We observed that this method is also called by in student_quiz view. On further analysis, we found that the student_quiz does not use criterion object and has only three options: TrueFalse, MultipleChoiceRadio and MultipleChoiceCheckbox. So no refactoring is required here. Verified this method isn't called anywhere else using RubyMine and grep command. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic in this method and is completely html code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def view_question_text&lt;br /&gt;
    html = '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt; ' + self.txt + ' &amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt;' + self.type + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;' + self.weight.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    questionnaire = self.questionnaire&lt;br /&gt;
    if !self.max_label.nil? &amp;amp;&amp;amp; !self.min_label.nil?&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt; (' + self.min_label + ') ' + questionnaire.min_question_score.to_s&lt;br /&gt;
      html += ' to ' + questionnaire.max_question_score.to_s + ' (' + self.max_label + ')&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    else&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt;' + questionnaire.min_question_score.to_s + ' to ' + questionnaire.max_question_score.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;TR&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/TR&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the user responds to the question being created in the respective model. In the case of this problem, which deals with criterion type question responses, the complete method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to respond to the criterion question and enter the necessary details. This method is called only from one view file i.e. response.html.erb. This file is in response view. Verified this using both RubyMine and the grep command. Unlike edit or view_question_text the self object does not refer to a global object instead it refers to a copy of the local object. So, we had passed the required object as locals to the partial, along with the parameters required by the method namely question, count, answer, questionnaire_min, questionnaire_max, dropdown_or_scale. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def complete(count, answer = nil, questionnaire_min, questionnaire_max, dropdown_or_scale)&lt;br /&gt;
    if self.size.nil?&lt;br /&gt;
      cols = '70'&lt;br /&gt;
      rows = '1'&lt;br /&gt;
    else&lt;br /&gt;
      cols = self.size.split(',')[0]&lt;br /&gt;
      rows = self.size.split(',')[1]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    html = '&amp;lt;div&amp;gt;&amp;lt;label for=&amp;quot;responses_' + count.to_s + '&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/label&amp;gt;&amp;lt;/div&amp;gt;'&lt;br /&gt;
    # show advice for each criterion question&lt;br /&gt;
    question_advices = QuestionAdvice.where(question_id: self.id).sort_by(&amp;amp;:id)&lt;br /&gt;
    advice_total_length = 0&lt;br /&gt;
&lt;br /&gt;
    question_advices.each do |question_advice|&lt;br /&gt;
      advice_total_length += question_advice.advice.length if question_advice.advice &amp;amp;&amp;amp; question_advice.advice != &amp;quot;&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if !question_advices.empty? and advice_total_length &amp;gt; 0&lt;br /&gt;
      html += '&amp;lt;a id=&amp;quot;showAdivce_' + self.id.to_s + '&amp;quot; onclick=&amp;quot;showAdvice(' + self.id.to_s + ')&amp;quot;&amp;gt;Show advice&amp;lt;/a&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;script&amp;gt;'&lt;br /&gt;
      html += 'function showAdvice(i){'&lt;br /&gt;
      html += 'var element = document.getElementById(&amp;quot;showAdivce_&amp;quot; + i.toString());'&lt;br /&gt;
      html += 'var show = element.innerHTML == &amp;quot;Hide advice&amp;quot;;'&lt;br /&gt;
      html += 'if (show){'&lt;br /&gt;
      html += 'element.innerHTML=&amp;quot;Show advice&amp;quot;;'&lt;br /&gt;
      html += '}else{'&lt;br /&gt;
      html += 'element.innerHTML=&amp;quot;Hide advice&amp;quot;;}'&lt;br /&gt;
      html += 'toggleAdvice(i);}'&lt;br /&gt;
&lt;br /&gt;
      html += 'function toggleAdvice(i) {'&lt;br /&gt;
      html += 'var elem = document.getElementById(i.toString() + &amp;quot;_myDiv&amp;quot;);'&lt;br /&gt;
      html += 'if (elem.style.display == &amp;quot;none&amp;quot;) {'&lt;br /&gt;
      html += 'elem.style.display = &amp;quot;&amp;quot;;'&lt;br /&gt;
      html += '} else {'&lt;br /&gt;
      html += 'elem.style.display = &amp;quot;none&amp;quot;;}}'&lt;br /&gt;
      html += '&amp;lt;/script&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;div id=&amp;quot;' + self.id.to_s + '_myDiv&amp;quot; style=&amp;quot;display: none;&amp;quot;&amp;gt;'&lt;br /&gt;
      # [2015-10-26] Zhewei:&lt;br /&gt;
      # best to order advices high to low, e.g., 5 to 1&lt;br /&gt;
      # each level used to be a link;&lt;br /&gt;
      # clicking on the link caused the dropbox to be filled in with the corresponding number&lt;br /&gt;
      question_advices.reverse.each_with_index do |question_advice, index|&lt;br /&gt;
        html += '&amp;lt;a id=&amp;quot;changeScore_&amp;gt;' + self.id.to_s + '&amp;quot; onclick=&amp;quot;changeScore(' + count.to_s + ',' + index.to_s + ')&amp;quot;&amp;gt;'&lt;br /&gt;
        html += (self.questionnaire.max_question_score - index).to_s + ' - ' + question_advice.advice + '&amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;'&lt;br /&gt;
        html += '&amp;lt;script&amp;gt;'&lt;br /&gt;
        html += 'function changeScore(i, j) {'&lt;br /&gt;
        html += 'var elem = jQuery(&amp;quot;#responses_&amp;quot; + i.toString() + &amp;quot;_score&amp;quot;);'&lt;br /&gt;
        html += 'var opts = elem.children(&amp;quot;option&amp;quot;).length;'&lt;br /&gt;
        html += 'elem.val((' + self.questionnaire.max_question_score.to_s + ' - j).toString());}'&lt;br /&gt;
        html += '&amp;lt;/script&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;/div&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if dropdown_or_scale == 'dropdown'&lt;br /&gt;
      current_value = &amp;quot;&amp;quot;&lt;br /&gt;
      current_value += 'data-current-rating =' + answer.answer.to_s if !answer.nil?&lt;br /&gt;
      html += '&amp;lt;div&amp;gt;&amp;lt;select id=&amp;quot;responses_' + count.to_s + '_score&amp;quot; name=&amp;quot;responses[' + count.to_s + '][score]&amp;quot; class=&amp;quot;review-rating&amp;quot; ' + current_value + '&amp;gt;'&lt;br /&gt;
      html += &amp;quot;&amp;lt;option value = ''&amp;gt;--&amp;lt;/option&amp;gt;&amp;quot;&lt;br /&gt;
      questionnaire_min.upto(questionnaire_max).each do |j|&lt;br /&gt;
        html += if !answer.nil? and j == answer.answer&lt;br /&gt;
                  '&amp;lt;option value=' + j.to_s + ' selected=&amp;quot;selected&amp;quot;&amp;gt;'&lt;br /&gt;
                else&lt;br /&gt;
                  '&amp;lt;option value=' + j.to_s + '&amp;gt;'&lt;br /&gt;
                end&lt;br /&gt;
&lt;br /&gt;
        html += j.to_s&lt;br /&gt;
        if j == questionnaire_min&lt;br /&gt;
          html += &amp;quot;-&amp;quot; + self.min_label if self.min_label.present?&lt;br /&gt;
        elsif j == questionnaire_max&lt;br /&gt;
          html += &amp;quot;-&amp;quot; + self.max_label if self.max_label.present?&lt;br /&gt;
        end&lt;br /&gt;
        html += &amp;quot;&amp;lt;/option&amp;gt;&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      html += &amp;quot;&amp;lt;/select&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;quot;&lt;br /&gt;
      html += '&amp;lt;textarea' + ' id=&amp;quot;responses_' + count.to_s + '_comments&amp;quot;' \&lt;br /&gt;
       ' name=&amp;quot;responses[' + count.to_s + '][comment]&amp;quot; class=&amp;quot;tinymce&amp;quot;&amp;gt;'&lt;br /&gt;
      html += answer.comments unless answer.nil?&lt;br /&gt;
      html += '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
    elsif dropdown_or_scale == 'scale'&lt;br /&gt;
      html += '&amp;lt;input id=&amp;quot;responses_' + count.to_s + '_score&amp;quot; name=&amp;quot;responses[' + count.to_s + '][score]&amp;quot; type=&amp;quot;hidden&amp;quot;'&lt;br /&gt;
      html += 'value=&amp;quot;' + answer.answer.to_s + '&amp;quot;' unless answer.nil?&lt;br /&gt;
      html += '&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;table&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;tr&amp;gt;&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      (questionnaire_min..questionnaire_max).each do |j|&lt;br /&gt;
        html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;label&amp;gt;' + j.to_s + '&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += if !self.min_label.nil?&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;' + self.min_label + '&amp;lt;/td&amp;gt;'&lt;br /&gt;
              else&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
              end&lt;br /&gt;
      (questionnaire_min..questionnaire_max).each do |j|&lt;br /&gt;
        html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;input type=&amp;quot;radio&amp;quot; id=&amp;quot;' + j.to_s + '&amp;quot; value=&amp;quot;' + j.to_s + '&amp;quot; name=&amp;quot;Radio_' + self.id.to_s + '&amp;quot;'&lt;br /&gt;
        html += 'checked=&amp;quot;checked&amp;quot;' if (!answer.nil? and answer.answer == j) or (answer.nil? and questionnaire_min == j)&lt;br /&gt;
        html += '&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;script&amp;gt;jQuery(&amp;quot;input[name=Radio_' + self.id.to_s + ']:radio&amp;quot;).change(function() {'&lt;br /&gt;
      html += 'var response_score = jQuery(&amp;quot;#responses_' + count.to_s + '_score&amp;quot;);'&lt;br /&gt;
      html += 'var checked_value = jQuery(&amp;quot;input[name=Radio_' + self.id.to_s + ']:checked&amp;quot;).val();'&lt;br /&gt;
      html += 'response_score.val(checked_value);});&amp;lt;/script&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += if !self.max_label.nil?&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;' + self.max_label + '&amp;lt;/td&amp;gt;'&lt;br /&gt;
              else&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;textarea cols=' + cols + ' rows=' + rows + ' id=&amp;quot;responses_' + count.to_s + '_comments&amp;quot;' \&lt;br /&gt;
        ' name=&amp;quot;responses[' + count.to_s + '][comment]&amp;quot; class=&amp;quot;tinymce&amp;quot;&amp;gt;'&lt;br /&gt;
      html += answer.comments unless answer.nil?&lt;br /&gt;
      html += '&amp;lt;/textarea&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
    safe_join([&amp;quot;&amp;quot;.html_safe, &amp;quot;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Proposed Solution==&lt;br /&gt;
All these methods contain HTML text. What we propose to do is to pick these lines of code and move them into an appropriate partial, in the required format. The next task is to find out where in the entire application do these methods get called. The multiple overriding of the method calls in this poorly structured application makes it a challenging task. These method-calls then have to be replaced with the appropriate rendering of a partial in the views. This would make the structure more MVC oriented, and help keep it clean and understandable for the next developer who accesses this file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The changes proposed above were implemented as described below.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_question_text Method===&lt;br /&gt;
This method did not contain any business logic and thus all code was formatted and moved to a new partial file (views/questionnaires/_criterion_view.html.erb). Again, no comments were required due to complete html code and a comment describing the partial was added in addition to other necessary comments in other files.&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/view.html.erb -''' Modified to invoke the partial if question is of type Criterion only. Also changed the question variable to a instance variable (question =&amp;gt; @question) to extend it's scope to the partial. This view is invoked during the view of questions in a questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- &amp;lt;%questions.each do |question| %&amp;gt;&lt;br /&gt;
-   &amp;lt;%if question.is_a? Question%&amp;gt;&lt;br /&gt;
-     &amp;lt;%=question.view_question_text.html_safe%&amp;gt;&lt;br /&gt;
+ &amp;lt;% for @question in questions %&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_view partial if question is of type Criterion %&amp;gt;&lt;br /&gt;
+   &amp;lt;%if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+         &amp;lt;%= render :partial =&amp;gt; 'criterion_view' %&amp;gt;&lt;br /&gt;
+     &amp;lt;%elsif @question.is_a? Question%&amp;gt;&lt;br /&gt;
+         &amp;lt;%= @question.view_question_text.html_safe %&amp;gt;&lt;br /&gt;
    &amp;lt;%end%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_criterion_view.html.erb -''' This partial file has the moved html code from view_question_text. Note that the &amp;quot;self.xxx&amp;quot; have been updated to &amp;quot;@question.xxx&amp;quot; as self referred to question object discussed in 1. Comment added to describe the partial file. Refer the pull request to look at the code.&lt;br /&gt;
&lt;br /&gt;
===The complete Method===&lt;br /&gt;
All the code in the model included html thus was completely removed from there. It was moved to the partial file (app/views/questionnaires/_criterion_edit.html.erb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question Method===&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1.&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122921</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122921"/>
		<updated>2019-04-01T22:53:19Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. There are many other types of question objects like dropdown that have the implementation of similar methods. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The pull request===&lt;br /&gt;
https://github.com/expertiza/expertiza/pull/1407&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details. This method is called only from two view files - one for creating (_questionnaire.html.erb partial file) and another for editing (edit.html.erb). Both these files are in questionnaires view. Verified this using both RubyMine and the grep command. Another interesting thing to note is the use of &amp;quot;self.&amp;quot; to get the attributes associated with question object. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
This method has the same explanation as the edit method except the fact that this method is called only during viewing of questionnaires by an instructor. We observed that this method is also called by in student_quiz view. On further analysis, we found that the student_quiz does not use criterion object and has only three options: TrueFalse, MultipleChoiceRadio and MultipleChoiceCheckbox. So no refactoring is required here. Verified this method isn't called anywhere else using RubyMine and grep command. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic in this method and is completely html code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def view_question_text&lt;br /&gt;
    html = '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt; ' + self.txt + ' &amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt;' + self.type + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;' + self.weight.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    questionnaire = self.questionnaire&lt;br /&gt;
    if !self.max_label.nil? &amp;amp;&amp;amp; !self.min_label.nil?&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt; (' + self.min_label + ') ' + questionnaire.min_question_score.to_s&lt;br /&gt;
      html += ' to ' + questionnaire.max_question_score.to_s + ' (' + self.max_label + ')&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    else&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt;' + questionnaire.min_question_score.to_s + ' to ' + questionnaire.max_question_score.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;TR&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/TR&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the user responds to the question being created in the respective model. In the case of this problem, which deals with criterion type question responses, the complete method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to respond to the criterion question and enter the necessary details. This method is called only from one view file i.e. response.html.erb. This file is in response view. Verified this using both RubyMine and the grep command. Another interesting thing to note is the use of &amp;quot;self.&amp;quot; to get the attributes associated with question object. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def complete(count, answer = nil, questionnaire_min, questionnaire_max, dropdown_or_scale)&lt;br /&gt;
    if self.size.nil?&lt;br /&gt;
      cols = '70'&lt;br /&gt;
      rows = '1'&lt;br /&gt;
    else&lt;br /&gt;
      cols = self.size.split(',')[0]&lt;br /&gt;
      rows = self.size.split(',')[1]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    html = '&amp;lt;div&amp;gt;&amp;lt;label for=&amp;quot;responses_' + count.to_s + '&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/label&amp;gt;&amp;lt;/div&amp;gt;'&lt;br /&gt;
    # show advice for each criterion question&lt;br /&gt;
    question_advices = QuestionAdvice.where(question_id: self.id).sort_by(&amp;amp;:id)&lt;br /&gt;
    advice_total_length = 0&lt;br /&gt;
&lt;br /&gt;
    question_advices.each do |question_advice|&lt;br /&gt;
      advice_total_length += question_advice.advice.length if question_advice.advice &amp;amp;&amp;amp; question_advice.advice != &amp;quot;&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if !question_advices.empty? and advice_total_length &amp;gt; 0&lt;br /&gt;
      html += '&amp;lt;a id=&amp;quot;showAdivce_' + self.id.to_s + '&amp;quot; onclick=&amp;quot;showAdvice(' + self.id.to_s + ')&amp;quot;&amp;gt;Show advice&amp;lt;/a&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;script&amp;gt;'&lt;br /&gt;
      html += 'function showAdvice(i){'&lt;br /&gt;
      html += 'var element = document.getElementById(&amp;quot;showAdivce_&amp;quot; + i.toString());'&lt;br /&gt;
      html += 'var show = element.innerHTML == &amp;quot;Hide advice&amp;quot;;'&lt;br /&gt;
      html += 'if (show){'&lt;br /&gt;
      html += 'element.innerHTML=&amp;quot;Show advice&amp;quot;;'&lt;br /&gt;
      html += '}else{'&lt;br /&gt;
      html += 'element.innerHTML=&amp;quot;Hide advice&amp;quot;;}'&lt;br /&gt;
      html += 'toggleAdvice(i);}'&lt;br /&gt;
&lt;br /&gt;
      html += 'function toggleAdvice(i) {'&lt;br /&gt;
      html += 'var elem = document.getElementById(i.toString() + &amp;quot;_myDiv&amp;quot;);'&lt;br /&gt;
      html += 'if (elem.style.display == &amp;quot;none&amp;quot;) {'&lt;br /&gt;
      html += 'elem.style.display = &amp;quot;&amp;quot;;'&lt;br /&gt;
      html += '} else {'&lt;br /&gt;
      html += 'elem.style.display = &amp;quot;none&amp;quot;;}}'&lt;br /&gt;
      html += '&amp;lt;/script&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;div id=&amp;quot;' + self.id.to_s + '_myDiv&amp;quot; style=&amp;quot;display: none;&amp;quot;&amp;gt;'&lt;br /&gt;
      # [2015-10-26] Zhewei:&lt;br /&gt;
      # best to order advices high to low, e.g., 5 to 1&lt;br /&gt;
      # each level used to be a link;&lt;br /&gt;
      # clicking on the link caused the dropbox to be filled in with the corresponding number&lt;br /&gt;
      question_advices.reverse.each_with_index do |question_advice, index|&lt;br /&gt;
        html += '&amp;lt;a id=&amp;quot;changeScore_&amp;gt;' + self.id.to_s + '&amp;quot; onclick=&amp;quot;changeScore(' + count.to_s + ',' + index.to_s + ')&amp;quot;&amp;gt;'&lt;br /&gt;
        html += (self.questionnaire.max_question_score - index).to_s + ' - ' + question_advice.advice + '&amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;'&lt;br /&gt;
        html += '&amp;lt;script&amp;gt;'&lt;br /&gt;
        html += 'function changeScore(i, j) {'&lt;br /&gt;
        html += 'var elem = jQuery(&amp;quot;#responses_&amp;quot; + i.toString() + &amp;quot;_score&amp;quot;);'&lt;br /&gt;
        html += 'var opts = elem.children(&amp;quot;option&amp;quot;).length;'&lt;br /&gt;
        html += 'elem.val((' + self.questionnaire.max_question_score.to_s + ' - j).toString());}'&lt;br /&gt;
        html += '&amp;lt;/script&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;/div&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if dropdown_or_scale == 'dropdown'&lt;br /&gt;
      current_value = &amp;quot;&amp;quot;&lt;br /&gt;
      current_value += 'data-current-rating =' + answer.answer.to_s if !answer.nil?&lt;br /&gt;
      html += '&amp;lt;div&amp;gt;&amp;lt;select id=&amp;quot;responses_' + count.to_s + '_score&amp;quot; name=&amp;quot;responses[' + count.to_s + '][score]&amp;quot; class=&amp;quot;review-rating&amp;quot; ' + current_value + '&amp;gt;'&lt;br /&gt;
      html += &amp;quot;&amp;lt;option value = ''&amp;gt;--&amp;lt;/option&amp;gt;&amp;quot;&lt;br /&gt;
      questionnaire_min.upto(questionnaire_max).each do |j|&lt;br /&gt;
        html += if !answer.nil? and j == answer.answer&lt;br /&gt;
                  '&amp;lt;option value=' + j.to_s + ' selected=&amp;quot;selected&amp;quot;&amp;gt;'&lt;br /&gt;
                else&lt;br /&gt;
                  '&amp;lt;option value=' + j.to_s + '&amp;gt;'&lt;br /&gt;
                end&lt;br /&gt;
&lt;br /&gt;
        html += j.to_s&lt;br /&gt;
        if j == questionnaire_min&lt;br /&gt;
          html += &amp;quot;-&amp;quot; + self.min_label if self.min_label.present?&lt;br /&gt;
        elsif j == questionnaire_max&lt;br /&gt;
          html += &amp;quot;-&amp;quot; + self.max_label if self.max_label.present?&lt;br /&gt;
        end&lt;br /&gt;
        html += &amp;quot;&amp;lt;/option&amp;gt;&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      html += &amp;quot;&amp;lt;/select&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;quot;&lt;br /&gt;
      html += '&amp;lt;textarea' + ' id=&amp;quot;responses_' + count.to_s + '_comments&amp;quot;' \&lt;br /&gt;
       ' name=&amp;quot;responses[' + count.to_s + '][comment]&amp;quot; class=&amp;quot;tinymce&amp;quot;&amp;gt;'&lt;br /&gt;
      html += answer.comments unless answer.nil?&lt;br /&gt;
      html += '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
    elsif dropdown_or_scale == 'scale'&lt;br /&gt;
      html += '&amp;lt;input id=&amp;quot;responses_' + count.to_s + '_score&amp;quot; name=&amp;quot;responses[' + count.to_s + '][score]&amp;quot; type=&amp;quot;hidden&amp;quot;'&lt;br /&gt;
      html += 'value=&amp;quot;' + answer.answer.to_s + '&amp;quot;' unless answer.nil?&lt;br /&gt;
      html += '&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;table&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;tr&amp;gt;&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      (questionnaire_min..questionnaire_max).each do |j|&lt;br /&gt;
        html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;label&amp;gt;' + j.to_s + '&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += if !self.min_label.nil?&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;' + self.min_label + '&amp;lt;/td&amp;gt;'&lt;br /&gt;
              else&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
              end&lt;br /&gt;
      (questionnaire_min..questionnaire_max).each do |j|&lt;br /&gt;
        html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;input type=&amp;quot;radio&amp;quot; id=&amp;quot;' + j.to_s + '&amp;quot; value=&amp;quot;' + j.to_s + '&amp;quot; name=&amp;quot;Radio_' + self.id.to_s + '&amp;quot;'&lt;br /&gt;
        html += 'checked=&amp;quot;checked&amp;quot;' if (!answer.nil? and answer.answer == j) or (answer.nil? and questionnaire_min == j)&lt;br /&gt;
        html += '&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
      end&lt;br /&gt;
      html += '&amp;lt;script&amp;gt;jQuery(&amp;quot;input[name=Radio_' + self.id.to_s + ']:radio&amp;quot;).change(function() {'&lt;br /&gt;
      html += 'var response_score = jQuery(&amp;quot;#responses_' + count.to_s + '_score&amp;quot;);'&lt;br /&gt;
      html += 'var checked_value = jQuery(&amp;quot;input[name=Radio_' + self.id.to_s + ']:checked&amp;quot;).val();'&lt;br /&gt;
      html += 'response_score.val(checked_value);});&amp;lt;/script&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
      html += if !self.max_label.nil?&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;' + self.max_label + '&amp;lt;/td&amp;gt;'&lt;br /&gt;
              else&lt;br /&gt;
                '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
              end&lt;br /&gt;
&lt;br /&gt;
      html += '&amp;lt;td width=&amp;quot;10%&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;'&lt;br /&gt;
      html += '&amp;lt;textarea cols=' + cols + ' rows=' + rows + ' id=&amp;quot;responses_' + count.to_s + '_comments&amp;quot;' \&lt;br /&gt;
        ' name=&amp;quot;responses[' + count.to_s + '][comment]&amp;quot; class=&amp;quot;tinymce&amp;quot;&amp;gt;'&lt;br /&gt;
      html += answer.comments unless answer.nil?&lt;br /&gt;
      html += '&amp;lt;/textarea&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
    safe_join([&amp;quot;&amp;quot;.html_safe, &amp;quot;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Proposed Solution==&lt;br /&gt;
All these methods contain HTML text. What we propose to do is to pick these lines of code and move them into an appropriate partial, in the required format. The next task is to find out where in the entire application do these methods get called. The multiple overriding of the method calls in this poorly structured application makes it a challenging task. These method-calls then have to be replaced with the appropriate rendering of a partial in the views. This would make the structure more MVC oriented, and help keep it clean and understandable for the next developer who accesses this file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The changes proposed above were implemented as described below.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_question_text Method===&lt;br /&gt;
This method did not contain any business logic and thus all code was formatted and moved to a new partial file (views/questionnaires/_criterion_view.html.erb). Again, no comments were required due to complete html code and a comment describing the partial was added in addition to other necessary comments in other files.&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/view.html.erb -''' Modified to invoke the partial if question is of type Criterion only. Also changed the question variable to a instance variable (question =&amp;gt; @question) to extend it's scope to the partial. This view is invoked during the view of questions in a questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- &amp;lt;%questions.each do |question| %&amp;gt;&lt;br /&gt;
-   &amp;lt;%if question.is_a? Question%&amp;gt;&lt;br /&gt;
-     &amp;lt;%=question.view_question_text.html_safe%&amp;gt;&lt;br /&gt;
+ &amp;lt;% for @question in questions %&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_view partial if question is of type Criterion %&amp;gt;&lt;br /&gt;
+   &amp;lt;%if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+         &amp;lt;%= render :partial =&amp;gt; 'criterion_view' %&amp;gt;&lt;br /&gt;
+     &amp;lt;%elsif @question.is_a? Question%&amp;gt;&lt;br /&gt;
+         &amp;lt;%= @question.view_question_text.html_safe %&amp;gt;&lt;br /&gt;
    &amp;lt;%end%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_criterion_view.html.erb -''' This partial file has the moved html code from view_question_text. Note that the &amp;quot;self.xxx&amp;quot; have been updated to &amp;quot;@question.xxx&amp;quot; as self referred to question object discussed in 1. Comment added to describe the partial file. Refer the pull request to look at the code.&lt;br /&gt;
&lt;br /&gt;
===The complete Method===&lt;br /&gt;
All the code in the model included html thus was completely removed from there. It was moved to the partial file (app/views/questionnaires/_criterion_edit.html.erb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question Method===&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1.&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122885</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122885"/>
		<updated>2019-04-01T21:42:47Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. There are many other types of question objects like dropdown that have the implementation of similar methods. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The pull request===&lt;br /&gt;
https://github.com/expertiza/expertiza/pull/1407&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details. This method is called only from two view files - one for creating (_questionnaire.html.erb partial file) and another for editing (edit.html.erb). Both these files are in questionnaires view. Verified this using both RubyMine and the grep command. Another interesting thing to note is the use of &amp;quot;self.&amp;quot; to get the attributes associated with question object. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
This method has the same explanation as the edit method except the fact that this method is called only during viewing of questionnaires by an instructor. We observed that this method is also called by in student_quiz view. On further analysis, we found that the student_quiz does not use criterion object and has only three options: TrueFalse, MultipleChoiceRadio and MultipleChoiceCheckbox. So no refactoring is required here. Verified this method isn't called anywhere else using RubyMine and grep command. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic in this method and is completely html code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def view_question_text&lt;br /&gt;
    html = '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt; ' + self.txt + ' &amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt;' + self.type + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;' + self.weight.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    questionnaire = self.questionnaire&lt;br /&gt;
    if !self.max_label.nil? &amp;amp;&amp;amp; !self.min_label.nil?&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt; (' + self.min_label + ') ' + questionnaire.min_question_score.to_s&lt;br /&gt;
      html += ' to ' + questionnaire.max_question_score.to_s + ' (' + self.max_label + ')&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    else&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt;' + questionnaire.min_question_score.to_s + ' to ' + questionnaire.max_question_score.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;TR&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/TR&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Proposed Solution==&lt;br /&gt;
All these methods contain HTML text. What we propose to do is to pick these lines of code and move them into an appropriate partial, in the required format. The next task is to find out where in the entire application do these methods get called. The multiple overriding of the method calls in this poorly structured application makes it a challenging task. These method-calls then have to be replaced with the appropriate rendering of a partial in the views. This would make the structure more MVC oriented, and help keep it clean and understandable for the next developer who accesses this file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The changes proposed above were implemented as described below.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_question_text Method===&lt;br /&gt;
This method did not contain any business logic and thus all code was formatted and moved to a new partial file (views/questionnaires/_criterion_view.html.erb). Again, no comments were required due to complete html code and a comment describing the partial was added in addition to other necessary comments in other files.&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/view.html.erb -''' Modified to invoke the partial if question is of type Criterion only. Also changed the question variable to a instance variable (question =&amp;gt; @question) to extend it's scope to the partial. This view is invoked during the view of questions in a questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- &amp;lt;%questions.each do |question| %&amp;gt;&lt;br /&gt;
-   &amp;lt;%if question.is_a? Question%&amp;gt;&lt;br /&gt;
-     &amp;lt;%=question.view_question_text.html_safe%&amp;gt;&lt;br /&gt;
+ &amp;lt;% for @question in questions %&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_view partial if question is of type Criterion %&amp;gt;&lt;br /&gt;
+   &amp;lt;%if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+         &amp;lt;%= render :partial =&amp;gt; 'criterion_view' %&amp;gt;&lt;br /&gt;
+     &amp;lt;%elsif @question.is_a? Question%&amp;gt;&lt;br /&gt;
+         &amp;lt;%= @question.view_question_text.html_safe %&amp;gt;&lt;br /&gt;
    &amp;lt;%end%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_criterion_view.html.erb -''' This partial file has the moved html code from view_question_text. Note that the &amp;quot;self.xxx&amp;quot; have been updated to &amp;quot;@question.xxx&amp;quot; as self referred to question object discussed in 1. Comment added to describe the partial file. Refer the pull request to look at the code.&lt;br /&gt;
&lt;br /&gt;
===The complete Method===&lt;br /&gt;
All the code in the model included html thus was completely removed from there. It was moved to the partial file (app/views/questionnaires/_criterion_edit.html.erb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question Method===&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1.&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122879</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122879"/>
		<updated>2019-04-01T21:28:51Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. There are many other types of question objects like dropdown that have the implementation of similar methods. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The pull request===&lt;br /&gt;
https://github.com/expertiza/expertiza/pull/1407&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details. This method is called only from two view files - one for creating (_questionnaire.html.erb partial file) and another for editing (edit.html.erb). Both these files are in questionnaires view. Verified this using both RubyMine and the grep command. Another interesting thing to note is the use of &amp;quot;self.&amp;quot; to get the attributes associated with question object. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
This method has the same explanation as the edit method except the fact that this method is called only during viewing of questionnaires by an instructor. We observed that this method is also called by in student_quiz view. On further analysis, we found that the student_quiz does not use criterion object and has only three options: TrueFalse, MultipleChoiceRadio and MultipleChoiceCheckbox. So no refactoring is required here. Verified this method isn't called anywhere else using RubyMine and grep command. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic in this method and is completely html code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def view_question_text&lt;br /&gt;
    html = '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt; ' + self.txt + ' &amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt;' + self.type + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;' + self.weight.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    questionnaire = self.questionnaire&lt;br /&gt;
    if !self.max_label.nil? &amp;amp;&amp;amp; !self.min_label.nil?&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt; (' + self.min_label + ') ' + questionnaire.min_question_score.to_s&lt;br /&gt;
      html += ' to ' + questionnaire.max_question_score.to_s + ' (' + self.max_label + ')&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    else&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt;' + questionnaire.min_question_score.to_s + ' to ' + questionnaire.max_question_score.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;TR&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/TR&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Proposed Solution==&lt;br /&gt;
All these methods contain HTML text. What we propose to do is to pick these lines of code and move them into an appropriate partial, in the required format. The next task is to find out where in the entire application do these methods get called. The multiple overriding of the method calls in this poorly structured application makes it a challenging task. These method-calls then have to be replaced with the appropriate rendering of a partial in the views. This would make the structure more MVC oriented, and help keep it clean and understandable for the next developer who accesses this file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The changes proposed above were implemented as described below.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_question_text Method===&lt;br /&gt;
This method did not contain any business logic and thus all code was formatted and moved to a new partial file (views/questionnaires/_criterion_view.html.erb). Again, no comments were required due to complete html code and a comment describing the partial was added in addition to other necessary comments in other files.&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/view.html.erb -''' Modified to invoke the partial if question is of type Criterion only. Also changed the question variable to a instance variable (question =&amp;gt; @question) to extend it's scope to the partial. This view is invoked during the view of questions in a questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- &amp;lt;%questions.each do |question| %&amp;gt;&lt;br /&gt;
-   &amp;lt;%if question.is_a? Question%&amp;gt;&lt;br /&gt;
-     &amp;lt;%=question.view_question_text.html_safe%&amp;gt;&lt;br /&gt;
+ &amp;lt;% for @question in questions %&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_view partial if question is of type Criterion %&amp;gt;&lt;br /&gt;
+   &amp;lt;%if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+         &amp;lt;%= render :partial =&amp;gt; 'criterion_view' %&amp;gt;&lt;br /&gt;
+     &amp;lt;%elsif @question.is_a? Question%&amp;gt;&lt;br /&gt;
+         &amp;lt;%= @question.view_question_text.html_safe %&amp;gt;&lt;br /&gt;
    &amp;lt;%end%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_criterion_view.html.erb -''' This partial file has the moved html code from view_question_text. Note that the &amp;quot;self.xxx&amp;quot; have been updated to &amp;quot;@question.xxx&amp;quot; as self referred to question object discussed in 1. Comment added to describe the partial file. Refer the pull request to look at the code.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question Method===&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1.&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122878</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122878"/>
		<updated>2019-04-01T21:26:38Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. There are many other types of question objects like dropdown that have the implementation of similar methods. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The pull request===&lt;br /&gt;
https://github.com/expertiza/expertiza/pull/1407&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details. This method is called only from two view files - one for creating (_questionnaire.html.erb partial file) and another for editing (edit.html.erb). Both these files are in questionnaires view. Verified this using both RubyMine and the grep command. Another interesting thing to note is the use of &amp;quot;self.&amp;quot; to get the attributes associated with question object. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
This method has the same explanation as the edit method except the fact that this method is called only during viewing of questionnaires by an instructor. We observed that this method is also called by in student_quiz view. On further analysis, we found that the student_quiz does not use criterion object and has only three options: TrueFalse, MultipleChoiceRadio and MultipleChoiceCheckbox. So no refactoring is required here. Verified this method isn't called anywhere else using RubyMine and grep command. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic in this method and is completely html code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def view_question_text&lt;br /&gt;
    html = '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt; ' + self.txt + ' &amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt;' + self.type + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;' + self.weight.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    questionnaire = self.questionnaire&lt;br /&gt;
    if !self.max_label.nil? &amp;amp;&amp;amp; !self.min_label.nil?&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt; (' + self.min_label + ') ' + questionnaire.min_question_score.to_s&lt;br /&gt;
      html += ' to ' + questionnaire.max_question_score.to_s + ' (' + self.max_label + ')&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    else&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt;' + questionnaire.min_question_score.to_s + ' to ' + questionnaire.max_question_score.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;TR&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/TR&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Proposed Solution==&lt;br /&gt;
All these methods contain HTML text. What we propose to do is to pick these lines of code and move them into an appropriate partial, in the required format. The next task is to find out where in the entire application do these methods get called. The multiple overriding of the method calls in this poorly structured application makes it a challenging task. These method-calls then have to be replaced with the appropriate rendering of a partial in the views. This would make the structure more MVC oriented, and help keep it clean and understandable for the next developer who accesses this file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The changes proposed above were implemented as described below.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_question_text Method===&lt;br /&gt;
This method did not contain any business logic and thus all code was formatted and moved to a new partial file (views/questionnaires/_criterion_view.html.erb). Again, no comments were required due to complete html code and a comment describing the partial was added in addition to other necessary comments in other files.&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/view.html.erb -''' Modified to invoke the partial if question is of type Criterion only. Also changed the question variable to a instance variable (question =&amp;gt; @question) to extend it's scope to the partial. This view is invoked during the view of questions in a questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- &amp;lt;%questions.each do |question| %&amp;gt;&lt;br /&gt;
-   &amp;lt;%if question.is_a? Question%&amp;gt;&lt;br /&gt;
-     &amp;lt;%=question.view_question_text.html_safe%&amp;gt;&lt;br /&gt;
+ &amp;lt;% for @question in questions %&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_view partial if question is of type Criterion %&amp;gt;&lt;br /&gt;
+   &amp;lt;%if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+         &amp;lt;%= render :partial =&amp;gt; 'criterion_view' %&amp;gt;&lt;br /&gt;
+     &amp;lt;%elsif @question.is_a? Question%&amp;gt;&lt;br /&gt;
+         &amp;lt;%= @question.view_question_text.html_safe %&amp;gt;&lt;br /&gt;
    &amp;lt;%end%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_criterion_view.html.erb -''' This partial file has the moved html code from view_question_text. Note that the &amp;quot;self.xxx&amp;quot; have been updated to &amp;quot;@question.xxx&amp;quot; as self referred to question object discussed in 1. Comment added to describe the partial file. Refer the pull request to look at the code.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122877</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122877"/>
		<updated>2019-04-01T21:26:06Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. There are many other types of question objects like dropdown that have the implementation of similar methods. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The pull request===&lt;br /&gt;
https://github.com/expertiza/expertiza/pull/1407&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details. This method is called only from two view files - one for creating (_questionnaire.html.erb partial file) and another for editing (edit.html.erb). Both these files are in questionnaires view. Verified this using both RubyMine and the grep command. Another interesting thing to note is the use of &amp;quot;self.&amp;quot; to get the attributes associated with question object. When we move this code to a partial, we need to change this in the erb file. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic involved here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
This method has the same explanation as the edit method except the fact that this method is called only during viewing of questionnaires by an instructor. We observed that this method is also called by in student_quiz view. On further analysis, we found that the student_quiz does not use criterion object and has only three options: TrueFalse, MultipleChoiceRadio and MultipleChoiceCheckbox. So no refactoring is required here. Verified this method isn't called anywhere else using RubyMine and grep command. The outcome of this method's refactoring will completely remove this method from the model file criterion.rb as there is no business logic in this method and is completely html code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def view_question_text&lt;br /&gt;
    html = '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt; ' + self.txt + ' &amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt;' + self.type + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;' + self.weight.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    questionnaire = self.questionnaire&lt;br /&gt;
    if !self.max_label.nil? &amp;amp;&amp;amp; !self.min_label.nil?&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt; (' + self.min_label + ') ' + questionnaire.min_question_score.to_s&lt;br /&gt;
      html += ' to ' + questionnaire.max_question_score.to_s + ' (' + self.max_label + ')&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    else&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt;' + questionnaire.min_question_score.to_s + ' to ' + questionnaire.max_question_score.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;TR&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/TR&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Proposed Solution==&lt;br /&gt;
All these methods contain HTML text. What we propose to do is to pick these lines of code and move them into an appropriate partial, in the required format. The next task is to find out where in the entire application do these methods get called. The multiple overriding of the method calls in this poorly structured application makes it a challenging task. These method-calls then have to be replaced with the appropriate rendering of a partial in the views. This would make the structure more MVC oriented, and help keep it clean and understandable for the next developer who accesses this file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The changes proposed above were implemented as described below.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_question_text Method===&lt;br /&gt;
This method did not contain any business logic and thus all code was formatted and moved to a new partial file (views/questionnaires/_criterion_view.html.erb). Again, no comments were required due to complete html code and a comment describing the partial was added in addition to other necessary comments in other files.&lt;br /&gt;
&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/view.html.erb -''' Modified to invoke the partial if question is of type Criterion only. Also changed the question variable to a instance variable (question =&amp;gt; @question) to extend it's scope to the partial. This view is invoked during the view of questions in a questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
- &amp;lt;%questions.each do |question| %&amp;gt;&lt;br /&gt;
-   &amp;lt;%if question.is_a? Question%&amp;gt;&lt;br /&gt;
-     &amp;lt;%=question.view_question_text.html_safe%&amp;gt;&lt;br /&gt;
+ &amp;lt;% for @question in questions %&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_view partial if question is of type Criterion %&amp;gt;&lt;br /&gt;
+   &amp;lt;%if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+         &amp;lt;%= render :partial =&amp;gt; 'criterion_view' %&amp;gt;&lt;br /&gt;
+     &amp;lt;%elsif @question.is_a? Question%&amp;gt;&lt;br /&gt;
+         &amp;lt;%= @question.view_question_text.html_safe %&amp;gt;&lt;br /&gt;
    &amp;lt;%end%&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_criterion_view.html.erb -''' This partial file has the moved html code from view_question_text. Note that the &amp;quot;self.xxx&amp;quot; have been updated to &amp;quot;@question.xxx&amp;quot; as self referred to question object discussed in 1. Comment added to describe the partial file. Refer the pull request to look at the code.&lt;br /&gt;
&lt;br /&gt;
===The Edit Method===&lt;br /&gt;
All the code in the model was just html and thus was completely removed from there. It was moved to the partial file (views/questionnaires/_criterion_edit.html.rb) and the necessary changes were made. Since it was all HTML code, no comments were actually required. However, we still added comments describing the partial file itself. Other comments were added whenever changes were made.&lt;br /&gt;
====Affected View Files====&lt;br /&gt;
'''1. views/questionnaires/edit.html.erb -''' This file calls the edit method for all types of question objects and the object type takes care of invoking the right overridden method. We modified this file to call the partial instead of edit method only for Criterion type of question objects. This view is invoked during edit on the questionnaire. Here are the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;% for @question in @questionnaire.questions %&amp;gt;&lt;br /&gt;
-   &amp;lt;%-# The following line call certain method of the object, which returns html string-%&amp;gt;&lt;br /&gt;
+   &amp;lt;%# E1911: Call the criterion_edit partial if question is of type Criterion -%&amp;gt;&lt;br /&gt;
+   &amp;lt;% if @question.is_a? Criterion %&amp;gt;&lt;br /&gt;
+     &amp;lt;%= render :partial =&amp;gt; 'criterion_edit' %&amp;gt;&lt;br /&gt;
+   &amp;lt;% else %&amp;gt;&lt;br /&gt;
      &amp;lt;%=@question.edit%&amp;gt;&lt;br /&gt;
+ &amp;lt;% end %&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''2. views/questionnaires/_questionnaire.html.erb -''' This partial file is called by new.html.erb when anew question is created. Same logic and changes as above.&lt;br /&gt;
'''3. views/questionnaires/_criterion_edit.html.erb -''' This file has all the html code that was earlier in the edit method of the criterion model. We changed the variables from &amp;quot;self.xxx&amp;quot; to &amp;quot;@question.xxx&amp;quot; because self was referring to question object in this context. Apart from this we changed the code to erb format. No more changes were deemed necessary. Please refer to the pull request to refer to the changes in this file as they are pure html and really long to be put in this wiki.&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122515</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122515"/>
		<updated>2019-03-26T03:56:12Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* The view_question_text method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
This method has the same explanation as the edit method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def view_question_text&lt;br /&gt;
    html = '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt; ' + self.txt + ' &amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;TD align=&amp;quot;left&amp;quot;&amp;gt;' + self.type + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    html += '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;' + self.weight.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    questionnaire = self.questionnaire&lt;br /&gt;
    if !self.max_label.nil? &amp;amp;&amp;amp; !self.min_label.nil?&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt; (' + self.min_label + ') ' + questionnaire.min_question_score.to_s&lt;br /&gt;
      html += ' to ' + questionnaire.max_question_score.to_s + ' (' + self.max_label + ')&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    else&lt;br /&gt;
      html += '&amp;lt;TD align=&amp;quot;center&amp;quot;&amp;gt;' + questionnaire.min_question_score.to_s + ' to ' + questionnaire.max_question_score.to_s + '&amp;lt;/TD&amp;gt;'&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;TR&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/TR&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Proposed Solution==&lt;br /&gt;
All these methods contain HTML text. What we propose to do is to pick these lines of code and move them into an appropriate partial, in the required format. The next task is to find out where in the entire application do these methods get called. The multiple overriding of the method calls in this poorly structured application makes it a challenging task. These method-calls then have to be replaced with the appropriate rendering of a partial in the views. This would make the structure more MVC oriented, and help keep it clean and understandable for the next developer who accesses this file.&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122514</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122514"/>
		<updated>2019-03-26T03:53:45Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* Proposed Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Proposed Solution==&lt;br /&gt;
All these methods contain HTML text. What we propose to do is to pick these lines of code and move them into an appropriate partial, in the required format. The next task is to find out where in the entire application do these methods get called. The multiple overriding of the method calls in this poorly structured application makes it a challenging task. These method-calls then have to be replaced with the appropriate rendering of a partial in the views. This would make the structure more MVC oriented, and help keep it clean and understandable for the next developer who accesses this file.&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122504</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122504"/>
		<updated>2019-03-26T03:43:47Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Proposed Solution==&lt;br /&gt;
The edit method of C&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122480</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122480"/>
		<updated>2019-03-26T02:58:21Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: /* The edit method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The safe_join is later used to return the HTML string to the calling view.&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122464</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122464"/>
		<updated>2019-03-26T02:35:13Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122459</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122459"/>
		<updated>2019-03-26T02:31:39Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def edit(_count)&lt;br /&gt;
    html = '&amp;lt;td align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;a rel=&amp;quot;nofollow&amp;quot; data-method=&amp;quot;delete&amp;quot; href=&amp;quot;/questions/' + self.id.to_s + '&amp;quot;&amp;gt;Remove&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;6&amp;quot; value=&amp;quot;' + self.seq.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][seq]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_seq&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;textarea cols=&amp;quot;50&amp;quot; rows=&amp;quot;1&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][txt]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_txt&amp;quot; placeholder=&amp;quot;Edit question content here&amp;quot;&amp;gt;' + self.txt + '&amp;lt;/textarea&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;10&amp;quot; disabled=&amp;quot;disabled&amp;quot; value=&amp;quot;' + self.type + '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][type]&amp;quot;'&lt;br /&gt;
    html += ' id=&amp;quot;question_' + self.id.to_s + '_type&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;&amp;lt;input size=&amp;quot;2&amp;quot; value=&amp;quot;' + self.weight.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][weight]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_weight&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt;text area size &amp;lt;input size=&amp;quot;3&amp;quot; value=&amp;quot;' + self.size.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][size]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_size&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    html += '&amp;lt;td&amp;gt; max_label &amp;lt;input size=&amp;quot;10&amp;quot; value=&amp;quot;' + self.max_label.to_s + '&amp;quot; name=&amp;quot;question[' + self.id.to_s&lt;br /&gt;
    html += '][max_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_max_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;  min_label &amp;lt;input size=&amp;quot;12&amp;quot; value=&amp;quot;' + self.min_label.to_s&lt;br /&gt;
    html += '&amp;quot; name=&amp;quot;question[' + self.id.to_s + '][min_label]&amp;quot; id=&amp;quot;question_' + self.id.to_s + '_min_label&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;'&lt;br /&gt;
&lt;br /&gt;
    safe_join([&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;.html_safe, &amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;.html_safe], html.html_safe)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122453</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122453"/>
		<updated>2019-03-26T02:24:36Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
This method is one of the several other methods in other files like criterion.rb which gets called when the type of the question being created in the respective model. In the case of this problem, which deals with criterion type questions, the edit method defined in criterion.rb is called when the question.type is equal to &amp;quot;Criterion&amp;quot;. This method allows for a user to create the criterion question and enter the necessary details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_question_text method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The complete method===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===The view_completed_question method===&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122448</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122448"/>
		<updated>2019-03-26T02:15:50Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
==About Criterion.rb==&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
===The edit method===&lt;br /&gt;
asd&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122447</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122447"/>
		<updated>2019-03-26T02:15:14Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=E1911 Refactoring criterion.rb=&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
===About Criterion.rb===&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
#====The edit method====&lt;br /&gt;
asd&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122446</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122446"/>
		<updated>2019-03-26T02:13:09Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1911 Refactoring criterion.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
===About Criterion.rb===&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
#====The edit method====&lt;br /&gt;
asd&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122445</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122445"/>
		<updated>2019-03-26T02:12:40Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1911 Refactoring criterion.rb==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The bulk of the code in criterion is HTML. It is the violation of MVC architecture - Model should not concern itself with how the data is displayed. This code needs to be moved to a partial file, and the partial file needs to be called in all appropriate places which call the criterion’s model methods. Once the logic for the view is moved out of the model, the model should only be left with business logic. This business logic code can also be refactored. Plus there are virtually no comments, properly comment the code.&lt;br /&gt;
&lt;br /&gt;
===About Criterion.rb===&lt;br /&gt;
Criterion is one of the types of questions that can be added to a questionnaire. As of now, the criterion model holds 4 methods that are called from different places in the application. Each of these methods is storing a string value which contains the necessary HTML lines to display the required functionalities to the user. This string value is then returned to the calling methods from the respective views. This HTML string is then entered wherever necessary. This is ideally the exact function of a partial, and this page needs to be heavily reformatted to use partials instead of returning a string containing html code.&lt;br /&gt;
&lt;br /&gt;
====The edit method====&lt;br /&gt;
asd&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122179</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122179"/>
		<updated>2019-03-25T19:54:58Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==E1553. Refactoring the Versions Controller==&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===About Expertiza===&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
===Problem Statement===&lt;br /&gt;
The following tasks were accomplished in this project:&lt;br /&gt;
&lt;br /&gt;
* Improved the clarity of code by improving the variable and parameter names.&lt;br /&gt;
* Long character strings were taken and given appropriate names.&lt;br /&gt;
* Handled pagination by a separate helper module, which can be used by multiple controllers.&lt;br /&gt;
* Implemented action_allowed for access_control to prevent unauthorized access of methods.&lt;br /&gt;
* Prevented displaying of all versions for all users and tables when a user views the index page.&lt;br /&gt;
* Added missing CRUD methods to Versions Controller&lt;br /&gt;
* Added RSPEC testcases for testing changes done in Versions Controller&lt;br /&gt;
&lt;br /&gt;
===About Versions Controller===&lt;br /&gt;
This class manages different versions of reviews. If a reviewer reviews a submission, and after that, the author revises the submission, the next time the reviewer does a review (s)he will create a new version. Sometimes it’s necessary to find the current version of a review; sometimes it’s necessary to find all versions. Similarly, a user may want to delete the current version of a review, or all versions of a review. Pagination of versions helps the user to view a subset of versions at a time. Considering the huge number of versions in the system, it is very useful to have a pagination mechanism and a filtering mechanism which can be applied on the whole set of versions. The idea is to display the versions in an ordered, comprehensible and logical manner. In Expertiza the gem ‘will_paginate’ is used to achieve pagination.&lt;br /&gt;
&lt;br /&gt;
===Current Implementation===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Functionality=====&lt;br /&gt;
* Any user irrespective of his/ her privileges can view all the versions.&lt;br /&gt;
::The versions which a particular user can view should be restricted based on the privileges of the user. For instance, only a user with Administrator privileges should be able to view all the versions in the system. However, that is not the case now. Every user can view all the versions irrespective of whether the user is a student or an administrator.&lt;br /&gt;
* Any user can delete any version&lt;br /&gt;
::The versions which a particular user can delete should be restricted based on the privileges of the user. For instance, a student should not be allowed to delete any version. According to the current implementation any user can delete any version in the system.&lt;br /&gt;
* Filtering of versions were restricted to the current user&lt;br /&gt;
::The filtering options on versions were restricted to the current user. Sometimes a user might want to view versions associated with other users. For instance, an instructor might want to view the list of versions created by a particular student. This is not possible with the current implementation.&lt;br /&gt;
&lt;br /&gt;
=====Drawbacks and Solutions=====&lt;br /&gt;
* '''Problem 1''': The method paginate_list is doing more than one thing.&lt;br /&gt;
::The method paginate_list was building a complex search criteria based on the input params, getting the list of versions from the Database matching this search criteria and then calling the Page API. All these tasks in a single method made it difficult to understand.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# For filtering the versions list with proper search and pagination.&lt;br /&gt;
  def paginate_list(id, user_id, item_type, event, datetime)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    criteria = ''&lt;br /&gt;
    criteria = criteria + &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      criteria = criteria + &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
    end&lt;br /&gt;
    criteria = criteria + &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
    criteria = criteria + &amp;quot;item_type = '#{item_type}' AND &amp;quot; if item_type &amp;amp;&amp;amp; !(item_type.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot;&lt;br /&gt;
    criteria = criteria + &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}' AND &amp;quot;&lt;br /&gt;
&lt;br /&gt;
    if current_role == 'Instructor' || current_role == 'Administrator'&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # Remove the last ' AND '&lt;br /&gt;
    criteria = criteria[0..-5]&lt;br /&gt;
&lt;br /&gt;
    versions = Version.page(params[:page]).order('id').per_page(25).where(criteria)&lt;br /&gt;
    versions&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* '''Solution''': The implementation has been changed in such a way that the versions which a user is allowed to see depends on the privileges of the user. The approach we have taken is as follows:&lt;br /&gt;
**An administrator can see all the versions&lt;br /&gt;
**An instructor can see all the versions created by him and other users who are in his course or are participants in the assignments he creates.&lt;br /&gt;
**A TA can see all the versions created by him and other users who are in the course for which he/ she assists.&lt;br /&gt;
**A Student can see all the versions created by him/ her.&lt;br /&gt;
* '''Problem 2''': The search criteria created in the method paginate_list was difficult to comprehend.&lt;br /&gt;
::The code which builds the search criteria in the method paginate_list uses many string literals and conditions and is hardly intuitive. The programmer will have to spend some time to understand what the code is really doing.&lt;br /&gt;
* '''Solution''': The implementation has been changed. A student is not allowed to delete any versions now. Other types of users, for instance administrators, instructors and TAs are allowed to delete only the versions they are authorized to view.&lt;br /&gt;
* '''Problem 3''': The paginate method can be moved to a helper class.&lt;br /&gt;
::VersionsController is not the only component which require to paginate items. There are other components too. For instance, the UsersController has to paginate the list of users. Hence the Paginate method can be moved to a helper class which can be accessed by other components as well.&lt;br /&gt;
* '''Solution''': The filtering options has also been enhanced. The current user can now choose as part of the version search filter any user from a list of users if the current user is authorized to see the versions created by that user.&lt;br /&gt;
&lt;br /&gt;
===New Implementation===&lt;br /&gt;
*The method paginate_list has been split into 2 methods now. &lt;br /&gt;
** BuildSearchCriteria – as the name suggests the sole purpose of this method is to build a search criteria based on the input search filters when the current user initiates a search in versions.&lt;br /&gt;
** paginate_list – this method will call the paginate API.&lt;br /&gt;
:First the search criteria is built, then the criteria is applied to versions in the database to get all versions which matches the criteria and then the retrieved versions are paginated.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # pagination.&lt;br /&gt;
  def paginate_list(versions)&lt;br /&gt;
    paginate(versions, VERSIONS_PER_PAGE);&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def BuildSearchCriteria(id, user_id, item_type, event)&lt;br /&gt;
    # Set up the search criteria&lt;br /&gt;
    search_criteria = ''&lt;br /&gt;
    search_criteria = search_criteria + add_id_filter_if_valid(id).to_s&lt;br /&gt;
    if current_user_role? == 'Super-Administrator'&lt;br /&gt;
      search_criteria = search_criteria + add_user_filter_for_super_admin(user_id).to_s&lt;br /&gt;
    end&lt;br /&gt;
    search_criteria = search_criteria + add_user_filter&lt;br /&gt;
    search_criteria = search_criteria + add_version_type_filter(item_type).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_event_filter(event).to_s&lt;br /&gt;
    search_criteria = search_criteria + add_date_time_filter&lt;br /&gt;
    search_criteria&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The string literals and conditions in the method paginate_list were replaced with methods with intuitive names so that the programmer can understand the code more easily. We also removed an empty if clause and a redundant statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def add_id_filter_if_valid (id)&lt;br /&gt;
    &amp;quot;id = #{id} AND &amp;quot; if id &amp;amp;&amp;amp; id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter_for_super_admin (user_id)&lt;br /&gt;
    &amp;quot;whodunnit = #{user_id} AND &amp;quot; if user_id &amp;amp;&amp;amp; user_id.to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_user_filter&lt;br /&gt;
    &amp;quot;whodunnit = #{current_user.try(:id)} AND &amp;quot; if current_user.try(:id) &amp;amp;&amp;amp; current_user.try(:id).to_i &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_event_filter (event)&lt;br /&gt;
    &amp;quot;event = '#{event}' AND &amp;quot; if event &amp;amp;&amp;amp; !(event.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_date_time_filter&lt;br /&gt;
    &amp;quot;created_at &amp;gt;= '#{time_to_string(params[:start_time])}' AND &amp;quot; +&lt;br /&gt;
        &amp;quot;created_at &amp;lt;= '#{time_to_string(params[:end_time])}'&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def add_version_type_filter (version_type)&lt;br /&gt;
    &amp;quot;item_type = '#{version_type}' AND &amp;quot; if version_type &amp;amp;&amp;amp; !(version_type.eql? 'Any')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* The paginate method has been moved to the helper class Pagination_Helper. This new method can be now reused by the different components like UsersController etc. The method receives two parameters, first the list to paginate and second the number of items to be displayed in a page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module PaginationHelper&lt;br /&gt;
&lt;br /&gt;
  def paginate (items, number_of_items_per_page)&lt;br /&gt;
    items.page(params[:page]).per_page(number_of_items_per_page)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Code improvements===&lt;br /&gt;
* Introduced a constant VERSIONS_PER_PAGE and assigned the value 25 to it. The pagination algorithm for VersionsController displays at most 25 versions in a page. The existing implementation uses the value 25 straight in the code and there are few problems associated with such an approach.&lt;br /&gt;
** It is not easy to understand what 25 is unless the programmer takes a close look at the code.&lt;br /&gt;
** In case if the value 25 is used at more than one places and in future a new requirement comes to show at most 30 versions in a page, all the values will have to be modified. It is not very DRY.&lt;br /&gt;
* The VersionsController was overriding AccessHelper - action_allowed? method to return true in all the cases. This was violating the whole purpose of the method action_allowed?. The purpose of this method is to determine whether the user who is triggering a CRUD operation is allowed to do so. So when the current user invokes a CRUD operation, the action_allowed? method is invoked first and if the method returns true the CRUD operation is triggered or else the user is intimated with a message and gracefully exited. Hence, when the action_allowed? method is overridden to return true always, it results in providing unauthorized access to certain users.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:With the new implementation the AccessHelper - action_allowed? method has been modified in such a way that unauthorized access is prevented. As per the new algorithm, 'new', 'create', 'edit', 'update' cannot be invoked by any user. These operations can be accessed only by ‘papertrail’ gem. Only an ‘Administrator’ or ‘Super-Administrator’ can call 'destroy_all' method. All the other methods are accessible to ‘Administrator’,  ‘Super-Administrator’, ‘Instructor’, ‘Teaching Assistant’ and ‘Student’.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'new', 'create', 'edit', 'update'&lt;br /&gt;
    #Modifications can only be done by papertrail&lt;br /&gt;
      return false&lt;br /&gt;
    when 'destroy_all'&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator'].include? current_role_name&lt;br /&gt;
    else&lt;br /&gt;
      #Allow all others&lt;br /&gt;
      ['Super-Administrator',&lt;br /&gt;
       'Administrator',&lt;br /&gt;
       'Instructor',&lt;br /&gt;
       'Teaching Assistant',&lt;br /&gt;
       'Student'].include? current_role_name&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Automated Testing using RSPEC===&lt;br /&gt;
The current version of expertiza did not have any test for VersionsController. Using the test driven development(TDD) approach, we have added an exhaustive set of RSPEC tests for VersionsController, to test all the modifications we have done to the code of the controller class. The tests use double and stub features of rspec-rails gem, to fake the log in by different users - Administrator, Instructor, Student etc. The tests can be executed &amp;quot;rpec spec&amp;quot; command as shown below.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
user-expertiza $rspec spec&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
Finished in 5.39 seconds (files took 25.33 seconds to load)&lt;br /&gt;
66 examples, 0 failures&lt;br /&gt;
&lt;br /&gt;
Randomized with seed 19254&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing from UI===&lt;br /&gt;
Following are a few testcases with respectto our code changes that can be tried from UI:&lt;br /&gt;
1. To go to versions index page, type in the following url after logging in:&lt;br /&gt;
   http://152.46.16.81:3000/versions&lt;br /&gt;
&lt;br /&gt;
2. After logging in as student/instructor or admin : Try accessing the  new, create, edit, update actions. These actions are not allowed to any of the users.&lt;br /&gt;
   http://152.46.16.81:3000/versions/new&lt;br /&gt;
   This calls the new action. In the current production version of expertiza, it is unhandled and application gives a default 404 page.&lt;br /&gt;
&lt;br /&gt;
3. Another feature that can be tested from UI is Pagination. Try searching for a user's versions and see if the results are paginated or not. Search here:&lt;br /&gt;
   http://152.46.16.81:3000/versions/search&lt;br /&gt;
&lt;br /&gt;
4. Visit the same URL as step 3, you should see only the students under that instructor in the users dropdown.&lt;br /&gt;
&lt;br /&gt;
===References===&lt;br /&gt;
&lt;br /&gt;
#[https://github.com/expertiza/expertiza Expertiza on GitHub]&lt;br /&gt;
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]&lt;br /&gt;
#[http://expertiza.ncsu.edu/ The live Expertiza website]&lt;br /&gt;
#[http://bit.ly/myexpertiza  Demo link] &lt;br /&gt;
#[http://wikis.lib.ncsu.edu/index.php/Expertiza Expertiza project documentation wiki]&lt;br /&gt;
#[https://relishapp.com/rspec Rspec Documentation]&lt;br /&gt;
#Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122178</id>
		<title>E1911 Refactor Criterion</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=E1911_Refactor_Criterion&amp;diff=122178"/>
		<updated>2019-03-25T19:54:11Z</updated>

		<summary type="html">&lt;p&gt;Sbekkem: Created page with &amp;quot;efewkflewk&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;efewkflewk&lt;/div&gt;</summary>
		<author><name>Sbekkem</name></author>
	</entry>
</feed>