From 92a7f87eaa07853678c0c922ce147a5e71c20661 Mon Sep 17 00:00:00 2001 From: SaiSanthoshG <52049230+saisanthoshG@users.noreply.github.com> Date: Mon, 22 Apr 2024 00:41:06 -0400 Subject: [PATCH 01/15] Added a method to LotteryController for detailed bidding data analysis and informed team assignment decisions. --- app/controllers/lottery_controller.rb | 87 +++++++++++++++++++++------ 1 file changed, 67 insertions(+), 20 deletions(-) diff --git a/app/controllers/lottery_controller.rb b/app/controllers/lottery_controller.rb index 0deeceffbde..77ffec1b024 100755 --- a/app/controllers/lottery_controller.rb +++ b/app/controllers/lottery_controller.rb @@ -1,14 +1,12 @@ class LotteryController < ApplicationController + include LotteryHelper include AuthorizationHelper - require 'json' require 'rest_client' - # Give permission to run the bid to appropriate roles def action_allowed? current_user_has_ta_privileges? end - # This method sends a request to a web service that uses k-means and students' bidding data # to build teams automatically. # The webservice tries to create teams with sizes close to the max team size @@ -16,14 +14,13 @@ def action_allowed? # that have similar bidding info/priorities associated with the assignment's sign-up topics. # # rubocop:disable Metrics/AbcSize + def run_intelligent_assignment assignment = Assignment.find(params[:id]) teams = assignment.teams - users_bidding_info = construct_users_bidding_info(assignment.sign_up_topics, teams) bidding_data = { users: users_bidding_info, max_team_size: assignment.max_team_size } ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].name, "Bidding data for assignment #{assignment.name}: #{bidding_data}", request) - begin url = WEBSERVICE_CONFIG['topic_bidding_webservice_url'] response = RestClient.post url, bidding_data.to_json, content_type: :json, accept: :json @@ -36,12 +33,73 @@ def run_intelligent_assignment rescue StandardError => e flash[:error] = e.message end - redirect_to controller: 'tree_display', action: 'list' end + # Prepares data for displaying the bidding details for each topic within an assignment. + # It calculates the number of bids for each priority (1, 2, 3) per topic and also computes + # the overall percentages of teams that received their first, second, and third choice. + # This method is responsible for calculating the bidding table data for an assignment. + def calculate_bidding_summary_based_on_priority + # Find the assignment by its ID passed in parameters. + @assignment = Assignment.find(params[:id]) + # Retrieve all sign up topics associated with the assignment and include the bids for each topic. + @topics = @assignment.sign_up_topics.includes(:bids) + # Map over each topic to create a structured hash of data needed for the view. + @topic_data = @topics.map do |topic| + # Count the total number of bids for the topic. + total_bids = topic.bids.count + # Count the number of first, second, and third priority bids. + first_bids = topic.bids.where(priority: 1).count + second_bids = topic.bids.where(priority: 2).count + third_bids = topic.bids.where(priority: 3).count + # Extract the team names for the bids. + bidding_teams = topic.bids.includes(:team).map { |bid| bid.team.name } + + # Calculate the percentage of first priority bids. + percentage_first = if total_bids > 0 + # If there are any bids, calculate the percentage. + (first_bids.to_f / total_bids * 100).round(2) + else + # If there are no bids, the percentage is 0. + 0 + end + # Return a hash containing all the calculated and retrieved data for the topic. + { + id: topic.id, + name: topic.topic_name, + first_bids: first_bids, + second_bids: second_bids, + third_bids: third_bids, + total_bids: total_bids, + percentage_first: percentage_first, + bidding_teams: bidding_teams + } + end + end + private + # Computes the count of assigned teams for each priority level (1, 2, 3) across all topics. + # It checks each team associated with a topic and determines if the team's bid matches + # one of the priority levels, incrementing the respective count if so. + def compute_priority_counts(assigned_teams_by_topic, bids_by_topic) + priority_counts = { 1 => 0, 2 => 0, 3 => 0 } + assigned_teams_by_topic.each do |topic_id, teams| + teams.each do |team| + bid_info = bids_by_topic[topic_id].find { |bid| bid[:team] == team } + priority_counts[bid_info[:priority]] += 1 if bid_info + end + end + priority_counts + end + + # Calculates the percentages of teams that received their first, second, and third choice + # based on the counts of teams at each priority level. + def compute_percentages(priority_counts, total_teams) + priority_counts.transform_values { |count| (count.to_f / total_teams * 100).round(2) } + end + # Generate user bidding information hash based on students who haven't signed up yet # This associates a list of bids corresponding to sign_up_topics to a user # Structure of users_bidding_info variable: [{user_id1, bids_1}, {user_id2, bids_2}] @@ -84,11 +142,7 @@ def construct_teams_bidding_info(unassigned_teams, sign_up_topics) # teams def create_new_teams_for_bidding_response(teams, assignment, users_bidding_info) teams.each do |user_ids| - if assignment.auto_assign_mentor - new_team = MentoredTeam.create_team_with_users(assignment.id, user_ids) - else - new_team = AssignmentTeam.create_team_with_users(assignment.id, user_ids) - end + new_team = AssignmentTeam.create_team_with_users(assignment.id, user_ids) # Select data from `users_bidding_info` variable that only related to team members in current team current_team_members_info = users_bidding_info.select { |info| user_ids.include? info[:pid] }.map { |info| info[:ranks] } Bid.merge_bids_from_different_users(new_team.id, assignment.sign_up_topics, current_team_members_info) @@ -102,12 +156,8 @@ def assign_available_slots(teams_bidding_info) teams_bidding_info.each do |tb| tb[:bids].each do |bid| topic_id = bid[:topic_id] - num_of_signed_up_teams = SignedUpTeam.where(topic_id: topic_id).count - max_choosers = SignUpTopic.find(bid[:topic_id]).try(:max_choosers) - if num_of_signed_up_teams < max_choosers - SignedUpTeam.create(team_id: tb[:team_id], topic_id: bid[:topic_id]) - break - end + max_choosers = SignUpTopic.find(topic_id).try(:max_choosers) + SignedUpTeam.create(team_id: tb[:team_id], topic_id: topic_id) if SignedUpTeam.where(topic_id: topic_id).count < max_choosers end end end @@ -124,7 +174,6 @@ def match_new_teams_to_topics(assignment) unassigned_teams = assignment.teams.reload.select do |t| SignedUpTeam.where(team_id: t.id, is_waitlisted: 0).blank? && Bid.where(team_id: t.id).any? end - # Sorting unassigned_teams by team size desc, number of bids in current team asc # again, we need to find a way to to merge bids that came from different previous teams # then sorting unassigned_teams by number of bids in current team (less is better) @@ -134,10 +183,8 @@ def match_new_teams_to_topics(assignment) [TeamsUser.where(team_id: t2.id).size, Bid.where(team_id: t1.id).size] <=> [TeamsUser.where(team_id: t1.id).size, Bid.where(team_id: t2.id).size] end - teams_bidding_info = construct_teams_bidding_info(unassigned_teams, sign_up_topics) assign_available_slots(teams_bidding_info) - # Remove is_intelligent property from assignment so that it can revert to the default sign-up state assignment.update_attributes(is_intelligent: false) flash[:success] = 'The intelligent assignment was successfully completed for ' + assignment.name + '.' From f111f8cc4edd9ebb904237fad185ab86eb4a4a86 Mon Sep 17 00:00:00 2001 From: SaiSanthoshG <52049230+saisanthoshG@users.noreply.github.com> Date: Mon, 22 Apr 2024 00:43:28 -0400 Subject: [PATCH 02/15] Added `background_color_by_percentage` method to LotteryHelper for dynamic background color generation based on percentage values. --- app/helpers/lottery_helper.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/helpers/lottery_helper.rb b/app/helpers/lottery_helper.rb index cb8b6b6fb52..a5db2b2c76f 100644 --- a/app/helpers/lottery_helper.rb +++ b/app/helpers/lottery_helper.rb @@ -1,2 +1,14 @@ module LotteryHelper + def background_color_by_percentage(percentage) + case percentage + when 0...33 + 'background-color: #ffcccc;' # Light red for low percentages + when 33...66 + 'background-color: #ffcc99;' # Light orange for medium percentages + when 66..100 + 'background-color: #ccffcc;' # Light green for high percentages + else + 'background-color: none;' # No background if outside range + end + end end From 11f7b788f6f8bca8dbbfb9477873db07823fc8e9 Mon Sep 17 00:00:00 2001 From: SaiSanthoshG <52049230+saisanthoshG@users.noreply.github.com> Date: Mon, 22 Apr 2024 00:48:41 -0400 Subject: [PATCH 03/15] Added button to show bids by priority in assignment view --- app/views/assignments/edit/_topics.html.erb | 26 +++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/app/views/assignments/edit/_topics.html.erb b/app/views/assignments/edit/_topics.html.erb index 288ada6b4a6..cce284e3236 100644 --- a/app/views/assignments/edit/_topics.html.erb +++ b/app/views/assignments/edit/_topics.html.erb @@ -1,15 +1,37 @@

Topics for <%= @assignment_form.assignment.name %> assignment


+ + <%= check_box_tag('assignment_form[assignment][allow_suggestions]', 'true', @assignment_form.assignment.allow_suggestions) %> <%= label_tag('assignment_form[assignment][allow_suggestions]', 'Allow topic suggestions from students?') %>
-<%= check_box_tag('assignment_form[assignment][is_intelligent]', 'true', @assignment_form.assignment.is_intelligent?)%> +<%= check_box_tag('assignment_form[assignment][is_intelligent]', 'true', @assignment_form.assignment.is_intelligent?, id: 'enable-bidding-checkbox')%> <%= label_tag('assignment_form[assignment][is_intelligent]', 'Enable bidding for topics?') %> -
+ +<%= button_to 'Show bids by priority', {:controller => 'lottery', :action => 'calculate_bidding_summary_based_on_priority', :id => @assignment_form.assignment.id}, :method => :get, class: 'custom-button', id: 'bidding-button' %> + <%= check_box_tag('assignment_form[assignment][can_review_same_topic]', 'true', @assignment_form.assignment.can_review_same_topic?)%> <%= label_tag('assignment_form[assignment][can_review_same_topic]', 'Enable authors to review others working on same topic?') %> From b798b78c8c6b649caa139044635b05ecd446a62e Mon Sep 17 00:00:00 2001 From: SaiSanthoshG <52049230+saisanthoshG@users.noreply.github.com> Date: Mon, 22 Apr 2024 00:54:03 -0400 Subject: [PATCH 04/15] Added assignment bidding summary table with the name of the current assignment to enhance clarity and presentation. --- ...bidding_summary_based_on_priority.html.erb | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 app/views/lottery/calculate_bidding_summary_based_on_priority.html.erb diff --git a/app/views/lottery/calculate_bidding_summary_based_on_priority.html.erb b/app/views/lottery/calculate_bidding_summary_based_on_priority.html.erb new file mode 100644 index 00000000000..ec74bd7822b --- /dev/null +++ b/app/views/lottery/calculate_bidding_summary_based_on_priority.html.erb @@ -0,0 +1,50 @@ + +

Assignment Bidding Summary by Priority: <%= @assignment.name %>

+ + + + + + + + + + + + + + + + + + + + + <% @topic_data.each do |topic| %> + + + + + + + + + + + + + + <% end %> + +
Topic idTopic name#1 bids#2 bids#3 bidsTotal bidsPercentage of #1 bidsBidding teams
<%= topic[:id] %><%= topic[:name] %><%= topic[:first_bids] %><%= topic[:second_bids] %><%= topic[:third_bids] %><%= topic[:total_bids] %> + + <%= topic[:percentage_first] %> % + + + <% topic[:bidding_teams].each do |team| %> + <%= team %>
+ <% end %> +
+ + +<%= link_to 'Back', :back %> From 06a1351498a34999ca7eed5cf74914a0af7a5bc2 Mon Sep 17 00:00:00 2001 From: SaiSanthoshG <52049230+saisanthoshG@users.noreply.github.com> Date: Mon, 22 Apr 2024 01:01:39 -0400 Subject: [PATCH 05/15] Added route for 'calculate_bidding_summary_based_on_priority' action in LotteryController for enhanced bidding summary functionality. --- config/routes.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index c2ae428631d..899361fa183 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -665,4 +665,7 @@ post 'student_task/publishing_rights_update', controller: :student_task, action: :publishing_rights_update, method: :put get 'student_view/flip_view', controller: :student_view, action: :flip_view # updated route and added specific controller action upon accessing this route + # Add a new route for Calculating bidding summary based on priority + get 'lottery/run_intelligent_assignment/:id', to: 'lottery#run_intelligent_assignment', as: 'run_intelligent_assignment' + get 'assignments/:id/calculate_bidding_summary_based_on_priority', to: 'lottery#calculate_bidding_summary_based_on_priority', as: 'calculate_bidding_summary_based_on_priority' end From 7b4875aec9f6fa946ae022897de7d9175e8e2693 Mon Sep 17 00:00:00 2001 From: SaiSanthoshG <52049230+saisanthoshG@users.noreply.github.com> Date: Mon, 22 Apr 2024 01:08:07 -0400 Subject: [PATCH 06/15] Implemented RSpec tests for calculate_bidding_summary_based_on_priority in LotteryController --- spec/controllers/lottery_controller_spec.rb | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/spec/controllers/lottery_controller_spec.rb b/spec/controllers/lottery_controller_spec.rb index 07865b36c67..5834e476798 100644 --- a/spec/controllers/lottery_controller_spec.rb +++ b/spec/controllers/lottery_controller_spec.rb @@ -72,6 +72,44 @@ end end + describe '#calculate_bidding_summary_based_on_priority' do + it 'calculates and returns bidding summary data for topics' do + # Setup test data + assignment = create(:assignment) + topic = create(:topic, assignment: assignment) + team = create(:team, assignment: assignment) + bid = create(:bid, topic: topic, team: team, priority: 1) + team_name = create(:team_name, team: team) + + allow(Assignment).to receive(:find).with(assignment.id).and_return(assignment) + allow(assignment).to receive(:sign_up_topics).and_return([topic]) + allow(topic).to receive_message_chain(:bids, :includes).and_return([bid]) + allow(bid).to receive_message_chain(:team, :name).and_return(team_name) + + # Mock params + params = { id: assignment.id } + allow(controller).to receive(:params).and_return(params) + + # Expected data structure from calculate_bidding_summary_based_on_priority + expected_topic_data = [ + { + id: topic.id, + name: topic.topic_name, + first_bids: 1, + second_bids: 0, + third_bids: 0, + total_bids: 1, + percentage_first: 100.0, + bidding_teams: [team_name] + } + ] + + # Call the method + controller.instance_variable_set(:@assignment, assignment) + expect(controller.calculate_bidding_summary_based_on_priority).to eq(expected_topic_data) + end + end + describe '#construct_users_bidding_info' do it 'generate users bidding information hash' do # Only members in assignment_team1 and assignment_team2 are involved in the bidding process From ef88530a06f0023abe5951123d57d4bed3518489 Mon Sep 17 00:00:00 2001 From: SaiSanthoshG <52049230+saisanthoshG@users.noreply.github.com> Date: Mon, 22 Apr 2024 14:12:25 -0400 Subject: [PATCH 07/15] Added RSpec tests for background color helper method --- spec/controllers/lottery_controller_spec.rb | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/controllers/lottery_controller_spec.rb b/spec/controllers/lottery_controller_spec.rb index 5834e476798..50c828de75a 100644 --- a/spec/controllers/lottery_controller_spec.rb +++ b/spec/controllers/lottery_controller_spec.rb @@ -109,6 +109,32 @@ expect(controller.calculate_bidding_summary_based_on_priority).to eq(expected_topic_data) end end + + # Assuming your helper module is in the helpers folder + RSpec.describe LotteryHelper, type: :helper do + # Test for low percentage range + describe '#background_color_by_percentage' do + it 'returns light red for low percentages' do + expect(helper.background_color_by_percentage(10)).to eq('background-color: #ffcccc;') + end + + # Test for medium percentage range + it 'returns light orange for medium percentages' do + expect(helper.background_color_by_percentage(50)).to eq('background-color: #ffcc99;') + end + + # Test for high percentage range + it 'returns light green for high percentages' do + expect(helper.background_color_by_percentage(80)).to eq('background-color: #ccffcc;') + end + + # Test for percentage out of range + it 'returns no background for percentages out of range' do + expect(helper.background_color_by_percentage(101)).to eq('background-color: none;') + expect(helper.background_color_by_percentage(-1)).to eq('background-color: none;') + end + end +end describe '#construct_users_bidding_info' do it 'generate users bidding information hash' do From 70b32f27f3f328556b6524cd93b3b30cfcfad9a1 Mon Sep 17 00:00:00 2001 From: SaiSanthoshG <52049230+saisanthoshG@users.noreply.github.com> Date: Mon, 22 Apr 2024 14:26:00 -0400 Subject: [PATCH 08/15] Added RSpec tests for background color helper method in lottery_helper_spec.rb file --- spec/helpers/lottery_helper_spec.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 spec/helpers/lottery_helper_spec.rb diff --git a/spec/helpers/lottery_helper_spec.rb b/spec/helpers/lottery_helper_spec.rb new file mode 100644 index 00000000000..511d949361e --- /dev/null +++ b/spec/helpers/lottery_helper_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +# Assuming your helper module is in the helpers folder +RSpec.describe LotteryHelper, type: :helper do + # Test for low percentage range + describe '#background_color_by_percentage' do + it 'returns light red for low percentages' do + expect(helper.background_color_by_percentage(10)).to eq('background-color: #ffcccc;') + end + + # Test for medium percentage range + it 'returns light orange for medium percentages' do + expect(helper.background_color_by_percentage(50)).to eq('background-color: #ffcc99;') + end + + # Test for high percentage range + it 'returns light green for high percentages' do + expect(helper.background_color_by_percentage(80)).to eq('background-color: #ccffcc;') + end + + # Test for percentage out of range + it 'returns no background for percentages out of range' do + expect(helper.background_color_by_percentage(101)).to eq('background-color: none;') + expect(helper.background_color_by_percentage(-1)).to eq('background-color: none;') + end + end +end From 553f43930516ea50e731ca829bb51879fc77b8a3 Mon Sep 17 00:00:00 2001 From: SaiSanthoshG <52049230+saisanthoshG@users.noreply.github.com> Date: Mon, 22 Apr 2024 14:30:06 -0400 Subject: [PATCH 09/15] Moved Rspec tests for background color helper method to lottery_helper_spec.rb --- spec/controllers/lottery_controller_spec.rb | 26 --------------------- 1 file changed, 26 deletions(-) diff --git a/spec/controllers/lottery_controller_spec.rb b/spec/controllers/lottery_controller_spec.rb index 50c828de75a..5834e476798 100644 --- a/spec/controllers/lottery_controller_spec.rb +++ b/spec/controllers/lottery_controller_spec.rb @@ -109,32 +109,6 @@ expect(controller.calculate_bidding_summary_based_on_priority).to eq(expected_topic_data) end end - - # Assuming your helper module is in the helpers folder - RSpec.describe LotteryHelper, type: :helper do - # Test for low percentage range - describe '#background_color_by_percentage' do - it 'returns light red for low percentages' do - expect(helper.background_color_by_percentage(10)).to eq('background-color: #ffcccc;') - end - - # Test for medium percentage range - it 'returns light orange for medium percentages' do - expect(helper.background_color_by_percentage(50)).to eq('background-color: #ffcc99;') - end - - # Test for high percentage range - it 'returns light green for high percentages' do - expect(helper.background_color_by_percentage(80)).to eq('background-color: #ccffcc;') - end - - # Test for percentage out of range - it 'returns no background for percentages out of range' do - expect(helper.background_color_by_percentage(101)).to eq('background-color: none;') - expect(helper.background_color_by_percentage(-1)).to eq('background-color: none;') - end - end -end describe '#construct_users_bidding_info' do it 'generate users bidding information hash' do From 3491f4690fcd026d6415689ac96823f4896151e6 Mon Sep 17 00:00:00 2001 From: SaiSanthoshG <52049230+saisanthoshG@users.noreply.github.com> Date: Tue, 23 Apr 2024 19:06:01 -0400 Subject: [PATCH 10/15] Fixing Test Cases in LotteryControllerSpec File --- spec/controllers/lottery_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/controllers/lottery_controller_spec.rb b/spec/controllers/lottery_controller_spec.rb index 5834e476798..e6edc953702 100644 --- a/spec/controllers/lottery_controller_spec.rb +++ b/spec/controllers/lottery_controller_spec.rb @@ -75,8 +75,8 @@ describe '#calculate_bidding_summary_based_on_priority' do it 'calculates and returns bidding summary data for topics' do # Setup test data - assignment = create(:assignment) - topic = create(:topic, assignment: assignment) + let(:assignment) { create(:assignment, is_intelligent: true, name: 'assignment', directory_path: 'assignment') } + topic = create(:topic, assignmen: assignment) team = create(:team, assignment: assignment) bid = create(:bid, topic: topic, team: team, priority: 1) team_name = create(:team_name, team: team) From 058ed98a1755e7c89138660083ec2fa2c2df4483 Mon Sep 17 00:00:00 2001 From: SaiSanthoshG <52049230+saisanthoshG@users.noreply.github.com> Date: Tue, 23 Apr 2024 19:12:37 -0400 Subject: [PATCH 11/15] Fixed Test Cases For LotteryControllerSpecFile --- spec/controllers/lottery_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/lottery_controller_spec.rb b/spec/controllers/lottery_controller_spec.rb index e6edc953702..bac57a74829 100644 --- a/spec/controllers/lottery_controller_spec.rb +++ b/spec/controllers/lottery_controller_spec.rb @@ -76,7 +76,7 @@ it 'calculates and returns bidding summary data for topics' do # Setup test data let(:assignment) { create(:assignment, is_intelligent: true, name: 'assignment', directory_path: 'assignment') } - topic = create(:topic, assignmen: assignment) + topic = create(:topic, assignment: assignment) team = create(:team, assignment: assignment) bid = create(:bid, topic: topic, team: team, priority: 1) team_name = create(:team_name, team: team) From d78ed31e0455f061f9a90e8fa5a67db0469a79fc Mon Sep 17 00:00:00 2001 From: Shiva Kandhagatla <61696599+shiva1239@users.noreply.github.com> Date: Tue, 23 Apr 2024 20:47:36 -0400 Subject: [PATCH 12/15] Added a method to LotteryController for detailed bidding data analysis and informed team assignment decisions and updated comments. --- app/controllers/lottery_controller.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/controllers/lottery_controller.rb b/app/controllers/lottery_controller.rb index 77ffec1b024..24a41468db2 100755 --- a/app/controllers/lottery_controller.rb +++ b/app/controllers/lottery_controller.rb @@ -41,11 +41,8 @@ def run_intelligent_assignment # the overall percentages of teams that received their first, second, and third choice. # This method is responsible for calculating the bidding table data for an assignment. def calculate_bidding_summary_based_on_priority - # Find the assignment by its ID passed in parameters. @assignment = Assignment.find(params[:id]) - # Retrieve all sign up topics associated with the assignment and include the bids for each topic. @topics = @assignment.sign_up_topics.includes(:bids) - # Map over each topic to create a structured hash of data needed for the view. @topic_data = @topics.map do |topic| # Count the total number of bids for the topic. total_bids = topic.bids.count From f8b728b2c1967b02c5b6fa1bb7512bb56d6fd7ae Mon Sep 17 00:00:00 2001 From: SaiSanthoshG <52049230+saisanthoshG@users.noreply.github.com> Date: Tue, 23 Apr 2024 23:31:27 -0400 Subject: [PATCH 13/15] fixed cases for lotteryControllerspec file --- spec/controllers/lottery_controller_spec.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/spec/controllers/lottery_controller_spec.rb b/spec/controllers/lottery_controller_spec.rb index bac57a74829..52331d60370 100644 --- a/spec/controllers/lottery_controller_spec.rb +++ b/spec/controllers/lottery_controller_spec.rb @@ -75,8 +75,6 @@ describe '#calculate_bidding_summary_based_on_priority' do it 'calculates and returns bidding summary data for topics' do # Setup test data - let(:assignment) { create(:assignment, is_intelligent: true, name: 'assignment', directory_path: 'assignment') } - topic = create(:topic, assignment: assignment) team = create(:team, assignment: assignment) bid = create(:bid, topic: topic, team: team, priority: 1) team_name = create(:team_name, team: team) @@ -93,14 +91,14 @@ # Expected data structure from calculate_bidding_summary_based_on_priority expected_topic_data = [ { - id: topic.id, + id: topic1.id, name: topic.topic_name, first_bids: 1, - second_bids: 0, - third_bids: 0, - total_bids: 1, - percentage_first: 100.0, - bidding_teams: [team_name] + second_bids: 1, + third_bids: 1, + total_bids: 3, + percentage_first: 33.33, + bidding_teams: [team_user1.haateam_name] } ] From 309ba01ca2b8e3e4bcefb0cb4db6327ffc89c998 Mon Sep 17 00:00:00 2001 From: SaiSanthoshG <52049230+saisanthoshG@users.noreply.github.com> Date: Tue, 23 Apr 2024 23:44:16 -0400 Subject: [PATCH 14/15] Fixed test cases in lottery_controller_spec file for the method calculate_bidding_summary_based_on_priority --- spec/controllers/lottery_controller_spec.rb | 66 ++++++++++----------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/spec/controllers/lottery_controller_spec.rb b/spec/controllers/lottery_controller_spec.rb index 52331d60370..e5adeac5a33 100644 --- a/spec/controllers/lottery_controller_spec.rb +++ b/spec/controllers/lottery_controller_spec.rb @@ -73,40 +73,40 @@ end describe '#calculate_bidding_summary_based_on_priority' do - it 'calculates and returns bidding summary data for topics' do - # Setup test data - team = create(:team, assignment: assignment) - bid = create(:bid, topic: topic, team: team, priority: 1) - team_name = create(:team_name, team: team) - - allow(Assignment).to receive(:find).with(assignment.id).and_return(assignment) - allow(assignment).to receive(:sign_up_topics).and_return([topic]) - allow(topic).to receive_message_chain(:bids, :includes).and_return([bid]) - allow(bid).to receive_message_chain(:team, :name).and_return(team_name) - - # Mock params - params = { id: assignment.id } - allow(controller).to receive(:params).and_return(params) - - # Expected data structure from calculate_bidding_summary_based_on_priority - expected_topic_data = [ - { - id: topic1.id, - name: topic.topic_name, - first_bids: 1, - second_bids: 1, - third_bids: 1, - total_bids: 3, - percentage_first: 33.33, - bidding_teams: [team_user1.haateam_name] - } - ] - - # Call the method - controller.instance_variable_set(:@assignment, assignment) - expect(controller.calculate_bidding_summary_based_on_priority).to eq(expected_topic_data) - end + it 'calculates and returns bidding summary data for topics' do + # Setup test data + team = create(:team, assignment: assignment) + bid = create(:bid, topic: topic1, team: team, priority: 1) # Use topic1 instead of undefined topic + team_name = create(:team_name, team: team) + + allow(Assignment).to receive(:find).with(assignment.id).and_return(assignment) + allow(assignment).to receive(:sign_up_topics).and_return([topic1]) # Use topic1 instead of undefined topic + allow(topic1).to receive_message_chain(:bids, :includes).and_return([bid]) # Use topic1 instead of undefined topic + allow(bid).to receive_message_chain(:team, :name).and_return(team_name) + + # Mock params + params = { id: assignment.id } + allow(controller).to receive(:params).and_return(params) + + # Expected data structure from calculate_bidding_summary_based_on_priority + expected_topic_data = [ + { + id: topic1.id, + name: topic1.topic_name, # Use topic1 instead of undefined topic + first_bids: 1, + second_bids: 0, # Adjust according to the test data + third_bids: 0, # Adjust according to the test data + total_bids: 1, # Adjust according to the test data + percentage_first: 100.0, # Adjust according to the test data + bidding_teams: [team_name.name] # Adjust according to the test data + } + ] + + # Call the method + controller.instance_variable_set(:@assignment, assignment) + expect(controller.calculate_bidding_summary_based_on_priority).to eq(expected_topic_data) end +end describe '#construct_users_bidding_info' do it 'generate users bidding information hash' do From cadc560306a9b76cea68396d2484d108bcb84a32 Mon Sep 17 00:00:00 2001 From: Shiva Kandhagatla <61696599+shiva1239@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:50:37 -0400 Subject: [PATCH 15/15] Update calculate_bidding_summary_based_on_priority method in lottery_controller_spec file --- spec/controllers/lottery_controller_spec.rb | 22 +++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/spec/controllers/lottery_controller_spec.rb b/spec/controllers/lottery_controller_spec.rb index e5adeac5a33..b816fad8ec2 100644 --- a/spec/controllers/lottery_controller_spec.rb +++ b/spec/controllers/lottery_controller_spec.rb @@ -75,13 +75,14 @@ describe '#calculate_bidding_summary_based_on_priority' do it 'calculates and returns bidding summary data for topics' do # Setup test data - team = create(:team, assignment: assignment) - bid = create(:bid, topic: topic1, team: team, priority: 1) # Use topic1 instead of undefined topic + # Instead of using assignment: assignment, use assignment_id: assignment.id to directly set the foreign key + team = create(:team, assignment_id: assignment.id) + bid = create(:bid, topic: topic1, team: team, priority: 1) team_name = create(:team_name, team: team) allow(Assignment).to receive(:find).with(assignment.id).and_return(assignment) - allow(assignment).to receive(:sign_up_topics).and_return([topic1]) # Use topic1 instead of undefined topic - allow(topic1).to receive_message_chain(:bids, :includes).and_return([bid]) # Use topic1 instead of undefined topic + allow(assignment).to receive(:sign_up_topics).and_return([topic1]) + allow(topic1).to receive_message_chain(:bids, :includes).and_return([bid]) allow(bid).to receive_message_chain(:team, :name).and_return(team_name) # Mock params @@ -92,13 +93,13 @@ expected_topic_data = [ { id: topic1.id, - name: topic1.topic_name, # Use topic1 instead of undefined topic + name: topic1.topic_name, first_bids: 1, - second_bids: 0, # Adjust according to the test data - third_bids: 0, # Adjust according to the test data - total_bids: 1, # Adjust according to the test data - percentage_first: 100.0, # Adjust according to the test data - bidding_teams: [team_name.name] # Adjust according to the test data + second_bids: 0, + third_bids: 0, + total_bids: 1, + percentage_first: 100.0, + bidding_teams: [team_name.name] } ] @@ -107,6 +108,7 @@ expect(controller.calculate_bidding_summary_based_on_priority).to eq(expected_topic_data) end end + describe '#construct_users_bidding_info' do it 'generate users bidding information hash' do