CSC/ECE 517 Fall 2023 - E2360. View for Results of Bidding (Phase2)

From Expertiza_Wiki
Revision as of 06:40, 5 December 2023 by Schen76 (talk | contribs)
Jump to navigation Jump to search

Motivation

The bidding view is needed because we don’t have a way of finding out whether the bidding algorithm is running correctly. This project is to add a bidding view to show how the topics are assigned to those teams who bid.


Work Plan

Based on the project's objectives and feedback received from our mentor, we have identified specific areas for improvement:

1) Refactor variable names within methods such as "bidding_details" and variables like "Topic name" and "Bidding teams" to enhance clarity and specificity.

2) Adjust capitalization for certain components, ensuring that only the first word is capitalized for consistency.

3) Introduce calculations to determine percentages based on additional data, such as the total number of teams and the number of teams for each priority, within the "lottery_controller."

4) Conduct thorough testing of the modified controller and view to ensure optimal functionality.


Design

To add functionality for showing the percentages of the number of teams that got their #1, #2, and #3 choices. We can follow these high-level steps:

Lottery_Controller:

i) Calculate the Total Number of Teams: Before we can calculate percentages, we need to know the total number of teams that participated in the bidding process. This will be our denominator in the percentage calculation.

ii) Calculate the Number of Teams for Each Priority: From our `bidding_details` method, we already have counts for how many teams bid on each topic as their #1, #2, and #3 choice (`@count1`, `@count2`, `@count3`). However, these counts are currently organized by topic. We would need to modify this to count how many teams got their #1, #2, and #3 choices as their assigned topic.

iii) Calculate Percentages: Once we have the number of teams that got their #1, #2, and #3 choices, we can calculate the percentages by dividing these numbers by the total number of teams and multiplying by 100.

Bidding_detail view:

i) Update the View and Display Percentages: Above the table in our previous view, we can add a section to display these percentages.

ii) Format the Display: We will use a bold heading for each percentage type and format the number to a fixed number of decimal places.

iii) Ensure Responsiveness: Make sure the display of these percentages adjusts well to different screen sizes, maintaining readability and layout consistency.


Code Effort

Change in lottery_controller.rb

method 1: bidding_table_for_each_topic

# 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.
  def bidding_table_for_each_topic
    @assignment = Assignment.find(params[:id])

    # Fetch all topics for the assignment
    @topics = @assignment.sign_up_topics
  
    @count1 = Hash.new(0)
    @count2 = Hash.new(0)
    @count3 = Hash.new(0)
    # Fetch all bids for these topics
    @bids_by_topic = {}
    @assigned_teams_by_topic = {}  # This will store the assigned teams for each topic
    @topics.each do |topic|
      # Assuming bids are stored with a topic_id, and each bid has a team associated with it
      @bids_by_topic[topic.id] = Bid.where(topic_id: topic.id).map do |bid|
        { team: bid.team, priority: bid.priority }
      end
      # Fetch teams that are not waitlisted for this topic
      @assigned_teams_by_topic[topic.id] = SignedUpTeam.where(topic_id: topic.id, is_waitlisted: false).map(&:team)
      @count1[topic.id] += @bids_by_topic[topic.id].count { |bid| bid[:priority] == 1 }
      @count2[topic.id] += @bids_by_topic[topic.id].count { |bid| bid[:priority] == 2 }
      @count3[topic.id] += @bids_by_topic[topic.id].count { |bid| bid[:priority] == 3 }       

    end
    # Calculate the total number of teams and percentages after fetching bid details
    topic_ids = SignUpTopic.where(assignment_id: @assignment.id).pluck(:id)
    @total_teams = SignedUpTeam.where(topic_id: topic_ids).distinct.count(:team_id)
    @priority_counts = calculate_priority_counts(@assigned_teams_by_topic, @bids_by_topic)
    @percentages = calculate_percentages(@priority_counts, @total_teams)

  end


method 2: calculate_priority_counts

# Calculates 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 calculate_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

method 3: calculate_percentages

# Calculates the percentages of teams that received their first, second, and third choice
  # based on the counts of teams at each priority level.
  def calculate_percentages(priority_counts, total_teams)
    priority_counts.transform_values { |count| (count.to_f / total_teams * 100).round(2) }
  end



Test Plan

According to the given test skeleton and the features we've implemented and to be implemented. Here are the testing ideas:


Context 1: When There Are No Bids or Assigned Teams

Test 1: Check if we get empty arrays for bids and assigned teams after running the "bidding_details" method.

Test 2: Check if the percentage of teams getting their #1, #2, and #3 choices are all 0.


Context 2: When There Are Bids and Assigned Teams for the Assignment

Test 3: We would first set up a known distribution of bids across different priority levels. After executing the "bidding_details" method, the test verifies that the returned count of bids for each priority level matches the expected distribution set up in the test environment.

Test 4: Ensure that the method correctly identifies and returns the assigned teams for each topic. In this test, the setup would include an assignment with pre-assigned teams to various topics. The "bidding_details" method is then called, and the test checks whether the method accurately returns the list of assigned teams for each topic, as per the test setup.

Test 5: Check if all teams bidding on a different topic, they all get the topic they want, and the percentage of #1 is 100%, while #2 and #3 are 0s.

Test 6: Check if all teams bidding on the same topic, only one team gets the topic they want, and the percentage of #1 is (1/teams)%, while #2 and #3 are 0s.

Test 7: Check if a team is a first/second/third team to bid on some topic, that topic is finally assigned to this team. In this case, #1, #2, or #3 is a non-zero value.

Test 8: Provide mocking data and we pre-calculate the percentage value of #1, #2 and #3, check if the calculated values are the same as ours.

Relevant Links

Github Repository: https://github.com/Shreshth-Malik/expertiza

Team

Mentor

Edward F. Gehringer (efg ncsu.edu)

Members

Richard Li (rli14@ncsu.edu)

Shreshth Malik (smalik4@ncsu.edu)

Shuai Chen (schen76@ncsu.edu)