<?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=Aaserdan</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=Aaserdan"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Aaserdan"/>
	<updated>2026-05-11T01:50:38Z</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_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165128</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165128"/>
		<updated>2025-04-23T03:28:49Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: /* System Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:UPADTED_E2542_context_diagram_spring_25.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;User Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:E2542_User_flow_diagram.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService&lt;br /&gt;
*** BidsBiddingService&lt;br /&gt;
*** BidsPriorityService&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt; Frontend View in Expertiza&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers have been refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
** The service objects listed above have been utilized in the review_bids_controller to shorten methods and keep them more concise.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Methods have been refactored to use ServiceObjects which have been listed above&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** The code tests all the service objects and the controller thoroughly and we have also expanded the tests in the Python web service.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** We employed consistent naming structure throughout all the updates and code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Component Design: ReviewBidsController ===&lt;br /&gt;
&lt;br /&gt;
The ReviewBidsController manages the full lifecycle of the review bidding process for an assignment in Expertiza. It provides functionality for both privileged users (e.g., instructors, administrators) and students, handling permissions, view rendering, bid creation and update, and review topic assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Fetches the AssignmentParticipant record from the params[:id]. Redirects to the home page if the participant is not found.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_assignment (Private) ======&lt;br /&gt;
&lt;br /&gt;
Sets the @assignment instance variable based on the current participant’s associated assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: authorize_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Verifies that the logged-in user matches the participant’s user ID. If not, redirects to the home page.&lt;br /&gt;
&lt;br /&gt;
====== Method: delete_all_bids_and_redirect (Private) ======&lt;br /&gt;
&lt;br /&gt;
Helper used when a participant deselects all topics. It deletes all current bids for the participant and redirects them to the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== API/Webservice Sample Throughput ==&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Response'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout expertiza and the Python Webservice&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;br /&gt;
* [https://youtu.be/vKfQzZXQuDo Video]&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E2542_User_flow_diagram.drawio.png&amp;diff=165127</id>
		<title>File:E2542 User flow diagram.drawio.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E2542_User_flow_diagram.drawio.png&amp;diff=165127"/>
		<updated>2025-04-23T03:27:38Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165101</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165101"/>
		<updated>2025-04-23T03:08:23Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:UPADTED_E2542_context_diagram_spring_25.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService&lt;br /&gt;
*** BidsBiddingService&lt;br /&gt;
*** BidsPriorityService&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt; Frontend View in Expertiza&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers have been refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
** The service objects listed above have been utilized in the review_bids_controller to shorten methods and keep them more concise.&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService, AssignBiddingService, CompletedReviewCounterService, BidsPriorityService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Methods have been refactored to use ServiceObjects which have been listed above&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** The code tests all the service objects and the controller thoroughly and we have also expanded the tests in the Python web service.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** We employed consistent naming structure throughout all the updates and code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Component Design: ReviewBidsController ===&lt;br /&gt;
&lt;br /&gt;
The ReviewBidsController manages the full lifecycle of the review bidding process for an assignment in Expertiza. It provides functionality for both privileged users (e.g., instructors, administrators) and students, handling permissions, view rendering, bid creation and update, and review topic assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Fetches the AssignmentParticipant record from the params[:id]. Redirects to the home page if the participant is not found.&lt;br /&gt;
&lt;br /&gt;
====== Method: set_assignment (Private) ======&lt;br /&gt;
&lt;br /&gt;
Sets the @assignment instance variable based on the current participant’s associated assignment.&lt;br /&gt;
&lt;br /&gt;
====== Method: authorize_participant (Private) ======&lt;br /&gt;
&lt;br /&gt;
Verifies that the logged-in user matches the participant’s user ID. If not, redirects to the home page.&lt;br /&gt;
&lt;br /&gt;
====== Method: delete_all_bids_and_redirect (Private) ======&lt;br /&gt;
&lt;br /&gt;
Helper used when a participant deselects all topics. It deletes all current bids for the participant and redirects them to the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165061</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165061"/>
		<updated>2025-04-23T02:54:29Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:UPADTED_E2542_context_diagram_spring_25.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService&lt;br /&gt;
*** BidsBiddingService&lt;br /&gt;
*** BidsPriorityService&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt; Frontend View in Expertiza&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165049</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=165049"/>
		<updated>2025-04-23T02:52:04Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* &amp;lt;strong&amp;gt;Data Flow Diagram&amp;lt;/strong&amp;gt;&lt;br /&gt;
[[File:UPADTED_E2542_context_diagram_spring_25.drawio.png|1000px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
* &amp;lt;strong&amp;gt; Review_Bids_Controller Overview &amp;lt;/strong&amp;gt;&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice. We have implemented a timeout and better responses from the Service Object employed by the controller.&lt;br /&gt;
** In the case of failure, the controller will use a fallback algorithm (implemented as a round-robin method, which will still assign students topics)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounterService:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
** AssignBiddingService&lt;br /&gt;
*** Isolates the logic for the process of assigning bidding to students&lt;br /&gt;
**  BidsPriorityService&lt;br /&gt;
*** Sets the priority of topic bids&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;The data flow of our application is highlighted in the above diagram!&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;strong&amp;gt; Frontend View in Expertiza&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* Plan:&lt;br /&gt;
** We implemented a 10 second timeout to the RestClient post request. This gives us a certain threshold to wait if the webservice is unresponsive.&lt;br /&gt;
** If the primary webservice fails, a fallback &amp;quot;round robin&amp;quot; algorithm was implemented in the previous OSS project as a way for students to still be assigned topics.&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
= Testing Plan =&lt;br /&gt;
&lt;br /&gt;
==== Review Bids Controller ====&lt;br /&gt;
* TC1 - action_allowed? method - Passed&lt;br /&gt;
** Tests if certain user roles are authorized to run certain actions.&lt;br /&gt;
&lt;br /&gt;
* TC2 - index method - Passed&lt;br /&gt;
** Ensures the others_view page is rendered when the index method is called&lt;br /&gt;
&lt;br /&gt;
* TC3 - show method - Passed&lt;br /&gt;
** Ensures the bidding page is rendered when the show method is called&lt;br /&gt;
&lt;br /&gt;
* TC4 - set_priority method - Passed&lt;br /&gt;
** Tests when topics are selected&lt;br /&gt;
** Tests when no topics are selected&lt;br /&gt;
** Checks the response redirects to root_path&lt;br /&gt;
&lt;br /&gt;
* TC5 - assign_bidding method - Passed&lt;br /&gt;
** Tests that the user gets redirected based on success or fail of bidding assignment&lt;br /&gt;
&lt;br /&gt;
* TC6 - Authorization issues - Passed&lt;br /&gt;
** Tests participant not found and when user is not authorized&lt;br /&gt;
** Expects a redirect to the root path&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== AssignBiddingService ====&lt;br /&gt;
&lt;br /&gt;
* TC7 - call_by_assignment method - Passed:&lt;br /&gt;
** Tests when the external service succeeds&lt;br /&gt;
** Tests when the external webservice fails and the fallback algorithm is used&lt;br /&gt;
** Tests when a reviewer has no topics assigned&lt;br /&gt;
** Tests when unexpected exceptions occur&lt;br /&gt;
&lt;br /&gt;
==== BidsAlgorithmService ====&lt;br /&gt;
&lt;br /&gt;
* TC8 - run_bidding_algorithm method - Passed:&lt;br /&gt;
** Tests when the web service is available and tests the timeout&lt;br /&gt;
** Tests when the webservice is unavailable&lt;br /&gt;
&lt;br /&gt;
* TC9 - process_bidding method - Passed:&lt;br /&gt;
** Tests when web service succeeds and passes sample data&lt;br /&gt;
** Tests when fallback is used and provides sample data.&lt;br /&gt;
&lt;br /&gt;
==== BidsPriorityService ====&lt;br /&gt;
&lt;br /&gt;
* TC10 - process_bids method - Passed:&lt;br /&gt;
** Tests the action of processing bids&lt;br /&gt;
** Tests when no topics are selected or removed&lt;br /&gt;
&lt;br /&gt;
==== CompletedReviewsCounterService ====&lt;br /&gt;
* TC11 - .count_reviews method - Passed&lt;br /&gt;
** Tests when all reviews are submitted&lt;br /&gt;
** Tests when some are not submitted&lt;br /&gt;
** Tests when some have empty responses&lt;br /&gt;
&lt;br /&gt;
==== External Webservice ====&lt;br /&gt;
&amp;lt;strong&amp;gt;This was tested via pytest in its own repository&amp;lt;/strong&amp;gt;&lt;br /&gt;
* TC12 - BiddingAlgorithm Webservice - Passed&lt;br /&gt;
** Tests a valid POST request&lt;br /&gt;
** Tests an invalid POST Request&lt;br /&gt;
** Tests when all users choose the same topic and same priority&lt;br /&gt;
** Tests when users bid more than is allowed&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2952 Pull Request]&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:UPADTED_E2542_context_diagram_spring_25.drawio.png&amp;diff=165036</id>
		<title>File:UPADTED E2542 context diagram spring 25.drawio.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:UPADTED_E2542_context_diagram_spring_25.drawio.png&amp;diff=165036"/>
		<updated>2025-04-23T02:49:24Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163552</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163552"/>
		<updated>2025-04-08T01:02:05Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;E2542 - Reimplement Review Bidding Controller&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&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 reviews 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;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
=== Purpose ===&lt;br /&gt;
The purpose of the Review Bids Controller is to create review bids on reviews, send HTTP requests to an outside webservice (hosted on a VCL), and handle the overall review biddings the students intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
&lt;br /&gt;
=== Scope ===&lt;br /&gt;
The Review Bids Controller handles the review biddings, processes the review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
== System Overview ==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* Data flow is further illustrated above with our context diagram.&lt;br /&gt;
&lt;br /&gt;
== Specific Objectives ==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce database calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* BidsAlgorithmService - encapsulates the logic to call the WebService to run the bidding algorithm.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
== Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects (BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects - BidsAlgorithmService)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services.&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService).&lt;br /&gt;
** Standardize response formats and error handling in service methods.&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing.&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases.&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service (BidsAlgorithmService). It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class BidsAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Implementation Plan =&lt;br /&gt;
 &lt;br /&gt;
==== Affected Repositories ====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring action_allowed? method ====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
==== Refactoring index method ====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
==== Refactoring set_priority method ====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Additional Changes ====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
==== esting Plan ====&lt;br /&gt;
* Unit Tests&lt;br /&gt;
** Unit tests will be written for each model, ensuring validations, associations, and business logic are correct&lt;br /&gt;
** Unit tests will also be written for service objects with mocked external calls&lt;br /&gt;
&lt;br /&gt;
* Each controller will also be tested that it sets correct instance variables, renders correct views, and handles redirection correctly&lt;br /&gt;
&lt;br /&gt;
* The system will also be end to end tested from bid submission to processing including a fallback scenario&lt;br /&gt;
&lt;br /&gt;
* Edge cases will be handled appropriately (error responses) in testing the service models&lt;br /&gt;
&lt;br /&gt;
* We will monitor code coverage targets and ensure all conditional logic is exercised.&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163379</id>
		<title>CSC/ECE 517 Spring 2025 - E2542. Refactor review bids controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2542._Refactor_review_bids_controller.rb&amp;diff=163379"/>
		<updated>2025-04-07T02:39:00Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;E2542 - Reimplement Review Bidding Controller&lt;br /&gt;
&lt;br /&gt;
== Expertiza ==&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 reviews 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;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
===Purpose===&lt;br /&gt;
The purpose of the review bids controller is to create review bids on reviews, send HTTP requests to an outside hosted webservice (on VCL), and handle overall bidding on what reviewsstudents intend to interact with.&lt;br /&gt;
This project is intended to expand on our own previous implementation of the OSS project, which includes cleaning up functions, increasing maintainability, and reducing repeated code, and eliminating single responsibility principle violations.&lt;br /&gt;
===Scope===&lt;br /&gt;
The Review Bidding controller handles review bidding, processes review selections as they are returned from the python webservice, whether in a valid or invalid response state (handled by fallback algorithm) and handles serving responses to the views.&lt;br /&gt;
&lt;br /&gt;
==System Overview==&lt;br /&gt;
* Context Diagram&lt;br /&gt;
[[File:E2542_context_diagram_spring_25.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note: Service Objects were not shown, assumed to be integrated with controllers.&amp;lt;/b&amp;gt;&lt;br /&gt;
* Key Components&lt;br /&gt;
** Controllers:&lt;br /&gt;
*** ReviewBidsController&lt;br /&gt;
*** SignUpSheetController&lt;br /&gt;
** Models:&lt;br /&gt;
*** AssignmentParticipant&lt;br /&gt;
*** Assignment&lt;br /&gt;
*** ReviewResponseMap&lt;br /&gt;
*** SignUpTopic&lt;br /&gt;
*** SignedUpTeam&lt;br /&gt;
*** ReviewBid&lt;br /&gt;
** ServiceObjects:&lt;br /&gt;
*** BidsAlgorithmService (proposed rename)&lt;br /&gt;
*** CompletedReviewsCounter&lt;br /&gt;
* Functionality Summary&lt;br /&gt;
** Bid creation is done by users through expertiza UI - Users drag and drop reviews, organizing them according to how their specific priority aligns with what want to work on&lt;br /&gt;
** Updating bid priorities is done through a similar view and can be done by rearranging the table&lt;br /&gt;
** Review sign up&lt;br /&gt;
&lt;br /&gt;
==Architecture and Design==&lt;br /&gt;
*MVC Architecture&lt;br /&gt;
&lt;br /&gt;
* Controller&lt;br /&gt;
** Acts as intermediary between UI and webservice we use to run the bidding algorithm on our python module.&lt;br /&gt;
** Receives processed input from the webservice which comes from our views&lt;br /&gt;
** Validates and processes incoming data&lt;br /&gt;
** Handles success / error responses from the webservice accordingly (implements fallback algorithm)&lt;br /&gt;
* Service Object Integration&lt;br /&gt;
** BidsAlgorithmService&lt;br /&gt;
*** Encapsulates bidding logic, processes review bids, and supports a fallback algorithm&lt;br /&gt;
** CompletedReviewsCounter:&lt;br /&gt;
*** Isolates business logic for counting completed reviews&lt;br /&gt;
&lt;br /&gt;
* Data flow is further illustrated above with our context diagram.&lt;br /&gt;
&lt;br /&gt;
==Specific Objectives==&lt;br /&gt;
* General Code Refactoring and Readability improvements - simplifying logic, variable naming, improving documentation&lt;br /&gt;
* Method Specific improvements - validations, role checks, caching repeated queries to reduce db calls&lt;br /&gt;
** e.g. action_allowed?, index, etc.&lt;br /&gt;
* WebService and UI Enhancements - documentation, refactoring tables that users bid with&lt;br /&gt;
&lt;br /&gt;
==Design Principles and Refactoring Goals ==&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle&lt;br /&gt;
** Controllers will be refactored to be kept thin by moving business logic into service objects&lt;br /&gt;
&lt;br /&gt;
* Separation of Concerns&lt;br /&gt;
** We will distinguish between HTTP request handling (controllers) and business logic (service objects)&lt;br /&gt;
&lt;br /&gt;
* DRY (Don't repeat yourself)&lt;br /&gt;
** We will consolidate duplicated logic like bid processing into reusable modules and services&lt;br /&gt;
&lt;br /&gt;
* Consistency&lt;br /&gt;
** Update naming conventions (BidsAlgorithmService)&lt;br /&gt;
** Standardize response formats and error handling in service methods&lt;br /&gt;
&lt;br /&gt;
* Modularity&lt;br /&gt;
** Break down complex methods into smaller, self contained functions for better readability and easier testing&lt;br /&gt;
&lt;br /&gt;
* Testability&lt;br /&gt;
** Code should be able to facilitate unit and integration testing, ensuring all branches are covered, including error cases&lt;br /&gt;
&lt;br /&gt;
* Reusability&lt;br /&gt;
** Employ consistent naming and clear structure and purpose allows easy reuse across the expertiza environment&lt;br /&gt;
&lt;br /&gt;
=== Component Design ===&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service. It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class ReviewBiddingAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
=== API/Webservice Integration ===&lt;br /&gt;
&lt;br /&gt;
Sample case:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Request:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
The webservice algorithm reflects the conflicts of topics and assigns the users who bid first the topic correctly.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Timeout and Retry Policies===&lt;br /&gt;
* To be implemented after full implementation&lt;br /&gt;
** Plan:&lt;br /&gt;
*** Document timeout configurations for external calls&lt;br /&gt;
*** Outline fallback strategies when the primary service is unavailable&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Implementation Plan=&lt;br /&gt;
 &lt;br /&gt;
====Affected Repositories====&lt;br /&gt;
* The changes will be made on the expertiza/expertiza repository&lt;br /&gt;
* Changes will be made using ruby and python - Python for WebService, Ruby for expertiza.&lt;br /&gt;
&lt;br /&gt;
====Refactoring action_allowed? method====&lt;br /&gt;
* Move the arrays of roles into constants so they are easier to manage&lt;br /&gt;
* Use if/else statements instead of a ternary statement to increase readability&lt;br /&gt;
* Find opportunities to return early if a condition is not met. e.g. if a user's role is not part of allowed roles&lt;br /&gt;
* Add comments for each conditional branch&lt;br /&gt;
* Use one method (params[:action] or action_name) to check current action for clarity.&lt;br /&gt;
&lt;br /&gt;
====Refactoring index method====&lt;br /&gt;
* Move the logic for counting completed reviews into a service object called CompletedReviewCounter. (Violates SRP)&lt;br /&gt;
* Use before_action filters to laod participant and assignment and check auth to align to DRY principle.&lt;br /&gt;
* Refactor variable names (num_reviews_completed -&amp;gt; completed_reviews_count)&lt;br /&gt;
* Include error handling for cases where participant cannot be found&lt;br /&gt;
&lt;br /&gt;
====Refactoring set_priority method====&lt;br /&gt;
* Move bid processing logic into a dedicated service object to thin out controller&lt;br /&gt;
* Assign repeated queries like fetching review bids or assignment id's to local variables to avoid multiple database calls&lt;br /&gt;
* Rename variables to closer reflect their intended purpose (params[:topic] -&amp;gt; selected_topic_ids)&lt;br /&gt;
* Utilize early returns to simplify conditional logic and reduce nesting in method&lt;br /&gt;
* Move logic for removing unselected bids, creating new bids, updating existing bids to a service object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Additional Changes====&lt;br /&gt;
* Rename bidding service to better reflect its purpose&lt;br /&gt;
* Consistency in response structure in send_bidding_request&lt;br /&gt;
* Add timeout parameter to prevent indefinite waits if external service becomes unresponsive&lt;br /&gt;
* Improve comments and documentation throughout&lt;br /&gt;
* Expand test coverage to include additional branches of conditional logic&lt;br /&gt;
* Ensure error-handling paths are exercised to verify failures are managed correctly&lt;br /&gt;
* Increase comments / documentation in the webservice repository.&lt;br /&gt;
&lt;br /&gt;
====Testing Plan====&lt;br /&gt;
* Unit Tests&lt;br /&gt;
** Unit tests will be written for each model, ensuring validations, associations, and business logic are correct&lt;br /&gt;
** Unit tests will also be written for service objects with mocked external calls&lt;br /&gt;
&lt;br /&gt;
* Each controller will also be tested that it sets correct instance variables, renders correct views, and handles redirection correctly&lt;br /&gt;
&lt;br /&gt;
* The system will also be end to end tested from bid submission to processing including a fallback scenario&lt;br /&gt;
&lt;br /&gt;
* Edge cases will be handled appropriately (error responses) in testing the service models&lt;br /&gt;
&lt;br /&gt;
* We will monitor code coverage targets and ensure all conditional logic is exercised.&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E2542_context_diagram_spring_25.png&amp;diff=163378</id>
		<title>File:E2542 context diagram spring 25.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E2542_context_diagram_spring_25.png&amp;diff=163378"/>
		<updated>2025-04-07T02:34:14Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: Aaserdan uploaded a new version of File:E2542 context diagram spring 25.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E2542_context_diagram_spring_25.png&amp;diff=163377</id>
		<title>File:E2542 context diagram spring 25.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E2542_context_diagram_spring_25.png&amp;diff=163377"/>
		<updated>2025-04-07T01:31:21Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2508._Reimplement_bidding-algorithm_web_service&amp;diff=162582</id>
		<title>CSC/ECE 517 Spring 2025 - E2508. Reimplement bidding-algorithm web service</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2508._Reimplement_bidding-algorithm_web_service&amp;diff=162582"/>
		<updated>2025-03-25T01:12:14Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Project Overview==&lt;br /&gt;
===   ''Background''   ===&lt;br /&gt;
The previous implementation of the bidding service was hosted on peerlogic by a former student. The University no longer has access to this hosting service, and  is requiring a new solution. It is also asked that the webservice accept a better and cleaner json format which is easier to interpret and read.&lt;br /&gt;
&lt;br /&gt;
===   ''Objectives''   ===&lt;br /&gt;
# Reimplement trading cycles on a webservice&lt;br /&gt;
# Figure out a new hosting solution for the BiddingService web service. (VCL)&lt;br /&gt;
# Host the webservice on VCL&lt;br /&gt;
# Using tmux, figure out a way to keep the process running with a production wsgi service compatible with Flask.&lt;br /&gt;
# Create new tests for the repository&lt;br /&gt;
# Create a list of required packages that future maintainers can install easily&lt;br /&gt;
# Create a tests directory that users can test the functionality of the code with&lt;br /&gt;
# Modularize the code further, eliminate code smells.&lt;br /&gt;
# Refactor existing backend logic to account for the new json format&lt;br /&gt;
# Refactor existing backend code to send HTTP requests to the correct IP address&lt;br /&gt;
# Refactor existing frontend code to provide a list for users to select multiple topics on the frontend&lt;br /&gt;
# Allow users to prioritize their topic selection on the frontend&lt;br /&gt;
# Users should not be allowed to bid on their review topics on the frontend&lt;br /&gt;
# Display the results of the matched topics on the frontend&lt;br /&gt;
&lt;br /&gt;
===   ''Previous Work''   ===&lt;br /&gt;
There have been three previous implementations: &amp;lt;br&amp;gt;&lt;br /&gt;
Fall 2019 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1986._Allow_reviewers_to_bid_on_what_to_review here]&amp;lt;br&amp;gt;&lt;br /&gt;
Spring 2020 [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Spring_2020_-_E2021._Allow_reviewers_to_bid_on_what_to_review here]&amp;lt;br&amp;gt;&lt;br /&gt;
Fall 2020 [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2020_-_E2085._Allow_reviewers_to_bid_on_what_to_review here]&amp;lt;br&amp;gt;&lt;br /&gt;
Fall 2024 [https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2024_-_E2508._Reimplement_bidding-algorithm_web_service here]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===   ''Relevant Links''   ===&lt;br /&gt;
''Github Repository for Expertiza'': https://github.com/ncsu-ngw/expertiza/tree/e2508-reimplement-bidding-algorithm-web-service &amp;lt;br&amp;gt;&lt;br /&gt;
''Github Repository for Web service'': https://github.com/ncsu-ngw/BiddingService &amp;lt;br&amp;gt;&lt;br /&gt;
''Pull Request'': https://github.com/expertiza/expertiza/pull/2931 &amp;lt;br&amp;gt;&lt;br /&gt;
''Web Service Server'': 152.7.178.10:8080/match_topics &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===   ''Files Modified''   ===&lt;br /&gt;
This is a list of all the files added or changed in completing this project. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
''Changed'': &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*app/app.py - accomodated for changes in JsonParser&lt;br /&gt;
*app/json_parser.py - moved functions out due to SRP&lt;br /&gt;
*app/topics_matcher.py&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
''Added'': &amp;lt;br&amp;gt;&lt;br /&gt;
*app/tests/sample.json &amp;lt;br&amp;gt; - Sample input for the tests.&lt;br /&gt;
&lt;br /&gt;
*app/tests/test_assignment.py &amp;lt;br&amp;gt; Test File to test forms of input - tests both a successful and unsuccessful input&lt;br /&gt;
&lt;br /&gt;
*app/utils/popular_topics.py &amp;lt;br&amp;gt; - Json Parser SRP violation - moved to own file&lt;br /&gt;
*app/utils/student_priorities.py &amp;lt;br&amp;gt; - Json Parser SRP violation - moved to own file&lt;br /&gt;
*app/utils/topic_priorities.py &amp;lt;br&amp;gt; - Json Parser SRP violation - moved to own file&lt;br /&gt;
&lt;br /&gt;
*setup.py - required for wsgi&lt;br /&gt;
*wsgi.py - for hosting the server via gunicorn on VCL.&lt;br /&gt;
*.gitignore - to ignore anything that we may not want pushed (mostly for venv)&lt;br /&gt;
*requirements.txt - a list of requirements made easy for future maintainers&lt;br /&gt;
&lt;br /&gt;
=== ''Webservice'' ===&lt;br /&gt;
===== ''app'' =====&lt;br /&gt;
&lt;br /&gt;
The entry point to the Web service is the app.py file where we have the POST Method match_topics.&lt;br /&gt;
This receives the input in a json format from Expertiza. The input will contain a list of task ids, and then an Object of users, which each contain their student id and correlated bids that they made. Each bid contains a task id, a priority, and a timestamp. The input format was reworked to align to this style since it made more sense to have each student have a list of bids instead of the previous implementation which did not have this case. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:App2508.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''json parser'' =====&lt;br /&gt;
The json parser converts the json into a Dictionary. The previous implementation also had the parser create a preferences dictionary for the Student to store their topic preferences and one for Topics to store list of topics which have been selected by students and also the priority for the selection using the Timestamps. However, this was removed due to the Single Responsibility Principle. We felt the json parser was doing too much and should only be parsing the json!&lt;br /&gt;
&lt;br /&gt;
[[File:init_parser.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The student priorities function in its own file, moved due to SRP.&lt;br /&gt;
&lt;br /&gt;
[[File:student_prio.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The topic priorities function in its own file, moved due to SRP.&lt;br /&gt;
&lt;br /&gt;
[[File:topic_priorities.png|700px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== ''Test Input'' =====&lt;br /&gt;
&lt;br /&gt;
Sample Test case:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Case:&amp;lt;/b&amp;gt; There are a few very popular topics and the students who bid for them and bid early should receive it.&lt;br /&gt;
Popular Topics: 3969, 3971, 3972&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;tid&amp;quot;: [4427, 4428, 4429, 4430],&lt;br /&gt;
    &amp;quot;users&amp;quot;: {&lt;br /&gt;
      &amp;quot;40763&amp;quot;: {&lt;br /&gt;
          &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4429&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40764&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:34 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4430, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:35 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:16:37 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4427&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;40765&amp;quot;: {&lt;br /&gt;
        &amp;quot;bids&amp;quot;: [&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4427, &amp;quot;priority&amp;quot;: 3, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:15 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4428, &amp;quot;priority&amp;quot;: 1, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:16 EST -05:00&amp;quot; },&lt;br /&gt;
          { &amp;quot;tid&amp;quot;: 4429, &amp;quot;priority&amp;quot;: 2, &amp;quot;timestamp&amp;quot;: &amp;quot;Sun, 15 Nov 2020 17:17:17 EST -05:00&amp;quot; }&lt;br /&gt;
        ],&lt;br /&gt;
        &amp;quot;otid&amp;quot;: 4428&lt;br /&gt;
      }&lt;br /&gt;
    },&lt;br /&gt;
    &amp;quot;max_accepted_proposals&amp;quot;: 3&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== ''Output'' =====&lt;br /&gt;
&lt;br /&gt;
 Since there is competition for these topics, the algorithm recognizes this and makes sure to assign them only to the students who bid for it.&lt;br /&gt;
		Other students who picked other topics or did not pick anything are assigned different topics.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;40763&amp;quot;: [&lt;br /&gt;
        4427,&lt;br /&gt;
        4428,&lt;br /&gt;
        4430&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40764&amp;quot;: [&lt;br /&gt;
        4428,&lt;br /&gt;
        4430,&lt;br /&gt;
        4429&lt;br /&gt;
    ],&lt;br /&gt;
    &amp;quot;40765&amp;quot;: [&lt;br /&gt;
        4429,&lt;br /&gt;
        4427,&lt;br /&gt;
        4430&lt;br /&gt;
    ]&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== ''Controller'' ===&lt;br /&gt;
&lt;br /&gt;
The controller includes 8 methods that handle the review bidding process. The public methods cover authorization, rendering views, saving user bids, and coordinating review assignment. The private methods support these functions by abstracting data gathering and algorithm coordination logic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====== Method: action_allowed? ======&lt;br /&gt;
&lt;br /&gt;
This method controls user access to controller actions. It allows 'Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', and 'Student' roles to access show, set_priority, and index. Other actions are restricted to non-student roles. It ensures proper permissions for accessing review bidding features.&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_action_allowed.JPG]]&lt;br /&gt;
&lt;br /&gt;
====== Method: index ======&lt;br /&gt;
&lt;br /&gt;
This method gathers information for the &amp;quot;Your Work&amp;quot; page, where users can view their assigned reviews. It checks user identity, retrieves associated reviews, and counts completed reviews. The view rendered is sign_up_sheet/review_bids_others_work.View: others_work.html.erb&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_controller_index.JPG]]&lt;br /&gt;
&lt;br /&gt;
====== Method: show ======&lt;br /&gt;
&lt;br /&gt;
This method renders the bidding page where users select topics they'd prefer to review. It fetches the assignment, available topics, and any existing bids. Already assigned or signed-up topics are excluded. The page also lists any assigned reviews.View: show.html.erb&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_controller_show.JPG]]&lt;br /&gt;
&lt;br /&gt;
====== Method: set_priority ======&lt;br /&gt;
&lt;br /&gt;
This method stores or updates a participant's topic preferences. It removes old bids not in the current selection and creates or updates the remaining bids with new priorities. This method is triggered when users submit their topic rankings on the bidding page.&lt;br /&gt;
&lt;br /&gt;
[[File:Updated_controller_set_priority.JPG]]&lt;br /&gt;
&lt;br /&gt;
====== Method: assign_bidding ======&lt;br /&gt;
&lt;br /&gt;
This method coordinates the assignment of review topics. It gathers reviewer IDs and invokes the bidding algorithm using a service. It validates the output and uses ReviewBid.assign_review_topics to perform the actual assignment. Bidding is then disabled.&lt;br /&gt;
&lt;br /&gt;
[[File:Assign_bidding.JPG]]&lt;br /&gt;
&lt;br /&gt;
====== Method: fetch_reviewer_ids (Private) ======&lt;br /&gt;
&lt;br /&gt;
This helper method retrieves all AssignmentParticipant IDs for a given assignment. These IDs represent the reviewers participating in the bidding process.&lt;br /&gt;
&lt;br /&gt;
====== Method: process_bidding (Private) ======&lt;br /&gt;
This helper method delegates the logic for running the bidding algorithm to the service class ReviewBiddingAlgorithmService. It takes the assignment ID and list of reviewers as input and returns matched topic assignments.&lt;br /&gt;
&lt;br /&gt;
====== Method: ensure_valid_topics (Private) ======&lt;br /&gt;
This method ensures that all reviewers have valid topic assignment entries, even if the algorithm returns nothing (e.g., due to web service failure). It initializes empty topic arrays for any missing reviewers.&lt;br /&gt;
&lt;br /&gt;
[[File:Controller_private_methods.JPG]]&lt;br /&gt;
&lt;br /&gt;
=== ''Service'' ===&lt;br /&gt;
&lt;br /&gt;
The ReviewBiddingAlgorithmService is a service object responsible for handling communication between the application and the external web service that executes the review bidding algorithm. It prepares bidding data, sends it to the web service, processes the response, and provides a fallback mechanism in case of failure.&lt;br /&gt;
&lt;br /&gt;
This service allows to encapsulate all logic required to interact with the external topic-matching web service. It separates the algorithm execution concerns from the controller, improving modularity, testability, and maintainability of the code.&lt;br /&gt;
&lt;br /&gt;
====== Method: self.process_bidding ======&lt;br /&gt;
&lt;br /&gt;
This is the primary entry point for the controller. It accepts the assignment_id and a list of reviewer_ids, then prepares the bidding data by calling ReviewBid.bidding_data(...). It passes the data to the web service by calling run_bidding_algorithm. If the web service is unavailable or fails, the method logs an error and falls back to an internal method: ReviewBid.fallback_algorithm. The result is returned as a hash mapping reviewer IDs to arrays of assigned topic IDs.&lt;br /&gt;
&lt;br /&gt;
====== Method: self.run_bidding_algorithm ======&lt;br /&gt;
&lt;br /&gt;
This method retrieves the review bidding web service URL from the app configuration (config/webservices.yml) and calls the internal send_bidding_request method to make the actual request.It logs the outgoing URL for debugging and delegates the response parsing.&lt;br /&gt;
&lt;br /&gt;
====== Private Method: send_bidding_request ======&lt;br /&gt;
&lt;br /&gt;
This private class method handles the HTTP POST request using RestClient. It sends the bidding data as JSON and expects a JSON response. If the request fails due to a connection error, server error, or timeout, the method logs the exception and returns false, allowing the caller to trigger a fallback.&lt;br /&gt;
&lt;br /&gt;
[[File:Review_bidding_algorithm_service.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fallback Algorithm ===&lt;br /&gt;
=====   ''Introduction''   =====&lt;br /&gt;
&lt;br /&gt;
The Fallback Algorithm in Expertiza is designed to ensure automatic topic assignment when the primary Bidding Algorithm fails due to Web Service unavailability.  &lt;br /&gt;
&lt;br /&gt;
Normally, Expertiza allows reviewers to bid on topics, and the ''ReviewBiddingAlgorithmService'' processes these bids to assign topics. However, when this web service ''fails'' (due to API downtime, server issues, or unexpected errors), the system must switch to fallback and automatically assign topics to reviewers.  &lt;br /&gt;
&lt;br /&gt;
=====   ''Solution''   =====&lt;br /&gt;
It is triggered when the web service is unavailable. It ensures fair topic assignment by:  &lt;br /&gt;
* Prioritizing topics with the largest teams.  &lt;br /&gt;
* Using a round-robin approach to distribute topics among reviewers.  &lt;br /&gt;
* Ensuring reviewers do not get their own team’s topic.  &lt;br /&gt;
&lt;br /&gt;
=====   ''When is this Used?''  ===== &lt;br /&gt;
* The ReviewBiddingAlgorithmService fails due to an API issue.  &lt;br /&gt;
* The web service times out or returns an error.  &lt;br /&gt;
* Unexpected exceptions occur in the bidding process.  &lt;br /&gt;
&lt;br /&gt;
Instead of stopping the review process, the system automatically falls-back to an internal algorithm to distribute topics.  &lt;br /&gt;
&lt;br /&gt;
=====   ''How Does the Fallback Algorithm Work?''   ===== &lt;br /&gt;
The algorithm follows these **four main steps:  &lt;br /&gt;
* Fetch available topics – Retrieves all topics for the given assignment.  &lt;br /&gt;
* Sort topics by team size – Topics with more members are given priority.  &lt;br /&gt;
* Create a topic queue – Topics are arranged in descending order of team size.  &lt;br /&gt;
* Assign topics in a round-robin manner – Reviewers are assigned topics while avoiding their own team's topic.  &lt;br /&gt;
&lt;br /&gt;
This ensures ''fair and balanced'' distribution of topics.&lt;br /&gt;
  &lt;br /&gt;
=====   ''Implementation - Controller Code (Triggering the Fallback)''   =====&lt;br /&gt;
If the primary bidding service fails, the system catches the error and calls the Fallback Algorithm.&lt;br /&gt;
&lt;br /&gt;
[[File:Controller-code.png|700px]]&lt;br /&gt;
&lt;br /&gt;
Key Takeaway: If ''ReviewBiddingAlgorithmService'' fails, the system automatically calls fallback_algorithm.  &lt;br /&gt;
&lt;br /&gt;
=====   ''Implementation - Model Code (Fallback Algorithm)''   =====&lt;br /&gt;
This method ensures fair topic assignment when the bidding system fails.&lt;br /&gt;
&lt;br /&gt;
[[File:Model-code.png|700px]]&lt;br /&gt;
&lt;br /&gt;
Key Takeaway: This function ensures every reviewer receives a topic without requiring manual intervention.&lt;br /&gt;
&lt;br /&gt;
=====   ''RSpec Testing of Fallback Algorithm''   =====&lt;br /&gt;
To verify correctness, we use unit tests in ''review_bid_spec.rb''&lt;br /&gt;
&lt;br /&gt;
The Fallback Algorithm ensures that ''topics are assigned fairly'' even when the primary bidding service fails. By prioritizing ''larger teams'', ''avoiding self-review'', and using a ''round-robin strategy'', the fallback mechanism keeps the review process smooth and automatic.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
This section outlines the test plan for this project including testing scenarios/edge cases, the manual testing plan, and the automatic/RSpec testing plan.&lt;br /&gt;
&lt;br /&gt;
=== ''Testing Scenarios'' ===&lt;br /&gt;
This section outlines the various bidding scenarios that could occur. These scenarios should be tested in either '''Manual Testing''' or '''Automatic Testing'''.&lt;br /&gt;
&lt;br /&gt;
==== Basic Bidding Scenario ====&lt;br /&gt;
*Reviewers bid on multiple projects at different times&lt;br /&gt;
** Bidding algorithm should give priority to reviewers that bid first and should assign based on reviewers ranking&lt;br /&gt;
&lt;br /&gt;
====   Edge Cases   ====&lt;br /&gt;
* All reviewers bid on the same project&lt;br /&gt;
** If different time stamps: bidding algorithm should give priority to reviewers that bid first&lt;br /&gt;
** If same time stamps: bidding algorithm should assign reviews randomly&lt;br /&gt;
* None of the reviews bid on any projects&lt;br /&gt;
** Bidding algorithm should assign reviews randomly&lt;br /&gt;
* Reviewer bids on their own project&lt;br /&gt;
** Bidding algorithm should not allow a reviewer to bid on their own project and should have validation to prevent assigning a reviewer their own project&lt;br /&gt;
* None of the reviewers bid on a specific project&lt;br /&gt;
** Bidding algorithm should still assign reviewers to this project&lt;br /&gt;
&lt;br /&gt;
===   ''Manual Testing''   ===&lt;br /&gt;
Manual testing should be preformed on an Expertiza server and webserver platform &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Manual Testing Plan for Expertiza Server ====&lt;br /&gt;
* test that an instructor can allow review bidding for an assignment&lt;br /&gt;
* test that server routes correctly when review bidding is allowed&lt;br /&gt;
** test that task box links to bidding page before algorithm is run&lt;br /&gt;
** test that assignment-&amp;gt;others work links to bidding page before algorithm is run&lt;br /&gt;
** test that task box links to review page with bidding information after algorithm is run&lt;br /&gt;
** test that assignment-&amp;gt;others work links to review page with bidding information after algorithm is run&lt;br /&gt;
* test that the bidding UI is implemented as expected&lt;br /&gt;
* test that a participant can bid on projects to review&lt;br /&gt;
** test that a participant can move projects into the bidding column&lt;br /&gt;
** test that a participant can reorder projects in the bidding column&lt;br /&gt;
** test that a participant's bidding preferences save&lt;br /&gt;
** test that a participant can't bid for their own topic&lt;br /&gt;
* test that run algorithm button calls webserver with correct information and returns review assignments for each user&lt;br /&gt;
&lt;br /&gt;
==== Directions for Manual Testing of Expertiza Server ====&lt;br /&gt;
1. Go to [http://152.7.99.70:8081/ testing server] &amp;lt;br&amp;gt;&lt;br /&gt;
2. Log in as username: '''instructor6''' password: '''password''' &amp;lt;br&amp;gt;&lt;br /&gt;
3. Go to '''Manage''' -&amp;gt; '''Assignments''' -&amp;gt; '''E2085 Manual Testing''' -&amp;gt; '''edit''' (pencil symbol)&lt;br /&gt;
:# In the '''General''' tab make sure '''Has teams?''' and '''Has topics?''' are checked&lt;br /&gt;
:# In the '''Topics''' tab check '''Allow review to choose which topic to review?''' then click '''save'''&lt;br /&gt;
:# In the '''Topics''' tab select '''Bidding''' then click '''save'''&lt;br /&gt;
4. Go to '''Assignments''' &lt;br /&gt;
:# '''E2085 Manual Testing review''' task should be listed in the main assignments box&lt;br /&gt;
::# This UI is based on '''instructor6''' being a '''participant''' assigned to topic '''Topic4'''&lt;br /&gt;
::# The UI blocks user from bidding on their own project &lt;br /&gt;
::# Check that user can bid on topics and reorder bids&lt;br /&gt;
::# Check that users topic preferences save on page refresh&lt;br /&gt;
::# Impersonate other participants and repeat bidding UI tests ('''student7601''', '''student7602''', '''student7603''', '''student7604''', '''student7605''', '''student7606''', '''student7607''', '''student7608''', '''student7609'')&lt;br /&gt;
5. Go to '''Manage''' -&amp;gt; '''Assignments''' -&amp;gt; '''E2085 Manual Testing''' -&amp;gt; '''edit''' (pencil symbol)&lt;br /&gt;
:# In the '''Topics''' tab click '''Run Review Algorithm''' button&lt;br /&gt;
6. Go to '''Assignments''' &lt;br /&gt;
:# '''E2085 Manual Testing review''' task should be listed in the main assignments box&lt;br /&gt;
::# '''E2085 Manual Testing review''' should now link to the reviewing page&lt;br /&gt;
::# The number of required reviews should already be displayed&lt;br /&gt;
::# A '''Request Another Review''' button should be present unless reviews listed is equal to the number of reviews allowed&lt;br /&gt;
::# '''Begin''' a review and test '''save''' and '''submit'''&lt;br /&gt;
&lt;br /&gt;
==== Manual Testing Demo Video for Expertiza Server ====&lt;br /&gt;
Video demonstration of manual testing: [https://www.screencast.com/t/0rSg1zDW here]&lt;br /&gt;
&lt;br /&gt;
=== ''Automatic/PyTest Testing '' ===&lt;br /&gt;
Pytest tests are written for the webservice to test a well formed and a malformed request.&lt;br /&gt;
&lt;br /&gt;
===   ''Automatic/RSpec Testing ''   ===&lt;br /&gt;
RSpec tests will need to be refactored according to the changes that we make in the expertiza repository. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RSpec Testing Plan ====&lt;br /&gt;
These RSpec tests will need to:&lt;br /&gt;
* test basic functionality of review bids controller&lt;br /&gt;
* test basic functionality of review bid model&lt;br /&gt;
&lt;br /&gt;
==== Directions for RSpec Testing ====&lt;br /&gt;
:# on personal device using [https://github.com/ncsu-ngw/expertiza forked repo]&lt;br /&gt;
:# Run the following commands:&lt;br /&gt;
&lt;br /&gt;
 # review bids controller: &lt;br /&gt;
 bundle exec rspec spec/controllers/review_bids_controller_spec.rb&lt;br /&gt;
 &lt;br /&gt;
 # review bidding algorithm service:&lt;br /&gt;
 bundle exec rspec spec/services/review_bidding_algorithm_service_spec.rb&lt;br /&gt;
&lt;br /&gt;
 # review bid model: &lt;br /&gt;
 bundle exec rspec spec/models/review_bid_spec.rb&lt;br /&gt;
&lt;br /&gt;
==== RSpec Testing Demo Video ====&lt;br /&gt;
Video demonstration of RSpec tests passing: [https://www.screencast.com/t/uSWZHSX8s here]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Test Coverage==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team==&lt;br /&gt;
&lt;br /&gt;
'''Mentor:''' Janice Uwujaren (juwujar) &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ashwin Muniswamy (akumarm) &amp;lt;br&amp;gt;&lt;br /&gt;
Arturo Serdan (aaserdan) &amp;lt;br&amp;gt;&lt;br /&gt;
Nicholas Winsen (nwinsen) &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
''Previous Implementations'': &lt;br /&gt;
[[https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2020_-_E2085._Allow_reviewers_to_bid_on_what_to_review#Objectives]],&amp;lt;br&amp;gt;&lt;br /&gt;
[[http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Fall_2019_-_E1986._Allow_reviewers_to_bid_on_what_to_review 1]],&amp;lt;br&amp;gt;[[https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Spring_2020_-_E2021._Allow_reviewers_to_bid_on_what_to_review 2]]&amp;lt;br&amp;gt;&lt;br /&gt;
''Bidding Interface Implementation Pull Request'': [[https://github.com/expertiza/expertiza/pull/778 3]]&lt;br /&gt;
&lt;br /&gt;
===   ''Relevant Links''   ===&lt;br /&gt;
''Github Repository for Expertiza'': https://github.com/ncsu-ngw/expertiza/tree/e2508-reimplement-bidding-algorithm-web-service &amp;lt;br&amp;gt;&lt;br /&gt;
''Github Repository for Web service'': https://github.com/ncsu-ngw/BiddingService &amp;lt;br&amp;gt;&lt;br /&gt;
''Pull Request'':  &amp;lt;br&amp;gt;&lt;br /&gt;
''Expertiza Server'': &amp;lt;br&amp;gt;&lt;br /&gt;
''Web Service Server'': 152.7.178.10:8080/match_topics &amp;lt;br&amp;gt;&lt;br /&gt;
''Video Demo'': https://app.screencast.com/vaiJnWpHf0r07&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Review_bidding_algorithm_service.JPG&amp;diff=162565</id>
		<title>File:Review bidding algorithm service.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Review_bidding_algorithm_service.JPG&amp;diff=162565"/>
		<updated>2025-03-25T00:57:30Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Controller_private_methods.JPG&amp;diff=162561</id>
		<title>File:Controller private methods.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Controller_private_methods.JPG&amp;diff=162561"/>
		<updated>2025-03-25T00:55:43Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Updated_controller_show.JPG&amp;diff=162560</id>
		<title>File:Updated controller show.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Updated_controller_show.JPG&amp;diff=162560"/>
		<updated>2025-03-25T00:55:18Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Updated_controller_set_priority.JPG&amp;diff=162558</id>
		<title>File:Updated controller set priority.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Updated_controller_set_priority.JPG&amp;diff=162558"/>
		<updated>2025-03-25T00:55:00Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Updated_controller_index.JPG&amp;diff=162557</id>
		<title>File:Updated controller index.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Updated_controller_index.JPG&amp;diff=162557"/>
		<updated>2025-03-25T00:54:30Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Assign_bidding.JPG&amp;diff=162555</id>
		<title>File:Assign bidding.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Assign_bidding.JPG&amp;diff=162555"/>
		<updated>2025-03-25T00:54:10Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Updated_action_allowed.JPG&amp;diff=162553</id>
		<title>File:Updated action allowed.JPG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Updated_action_allowed.JPG&amp;diff=162553"/>
		<updated>2025-03-25T00:53:49Z</updated>

		<summary type="html">&lt;p&gt;Aaserdan: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aaserdan</name></author>
	</entry>
</feed>