<?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=Aselvam</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=Aselvam"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Aselvam"/>
	<updated>2026-08-21T23:53:28Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Updated_Proposed_ERR_for_student_teams_E2243.png&amp;diff=145381</id>
		<title>File:Updated Proposed ERR for student teams E2243.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Updated_Proposed_ERR_for_student_teams_E2243.png&amp;diff=145381"/>
		<updated>2022-04-26T03:14:42Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: Aselvam uploaded a new version of File:Updated Proposed ERR for student teams E2243.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=144489</id>
		<title>CSC/ECE 517 Spring 2022 - E2243. Refactor student teams functionality</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=144489"/>
		<updated>2022-04-07T00:13:35Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: /* ER diagram for updated schema */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information about Expertiza Issue E2243. Refactor student teams functionality which was a project in CSC517 Spring 2022. &lt;br /&gt;
&lt;br /&gt;
Please see below for a description of the design of the project.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The Expertiza project is software to create reusable learning objects through peer review. It also supports team projects, and the submission of almost any document type, including URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
Users &amp;amp; Participants: Everyone who took the CSC517 OODD class at NC State is a user in Expertiza, and instructors can add users as participants in an assignment so that they can access it to contribute, make changes and submit their work to be graded.&lt;br /&gt;
&lt;br /&gt;
Almost all of the works within Assignments is done by participants, not users. All the tables use participant_id to track contributions to assignments, except teams_users. In the documentation, it can be noted that the team_users table references users instead of participants. This anomaly in the teams_users relation causes problems with how student teams are rendered in the UI, and it doesn’t mix well with the new functionality that was recently introduced.&lt;br /&gt;
&lt;br /&gt;
teams_users should be changed to teams_participants. the team_id, user_id mapping in this table should be changed to team_id, participant_id. All the references of user_id should be updated to use participant_id.&lt;br /&gt;
&lt;br /&gt;
== Given Requirements ==&lt;br /&gt;
&lt;br /&gt;
===Changing the schema ===&lt;br /&gt;
* We need to rename the table table teams_users to teams_participants.&lt;br /&gt;
* Create a column that would be called “participant_id”, which will be a foreign key that references the participants table.&lt;br /&gt;
* Create a migration that fetches the assignment_id for each tuple from the teams table. We would find the participant with the help of the assignment_id we just got from the teams table and the user_id that is already present in the current table, and store its “id” in the participant_id column we created in the last step.&lt;br /&gt;
* &amp;lt;s&amp;gt;Get rid of the user_id column.&amp;lt;/s&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactoring the teams rendering (/views/student_teams/view.html.erb) ===&lt;br /&gt;
The logic in the team's view (where participants can see their team members) that iterates and fetches information of all the team members and displays them would be refactored so that it matches our new design. &lt;br /&gt;
The view is quite bloated and has lots of functionalities written on it. We’ll be making partials and placing those functionality in their specific partials.&lt;br /&gt;
&lt;br /&gt;
=== Other Changes ===&lt;br /&gt;
&lt;br /&gt;
Update logic for all the crud functionalities in teams_users controller (wherever applicable).&lt;br /&gt;
Rename the teams_users_controller to teams_participants_controller (and all its references)&lt;br /&gt;
&lt;br /&gt;
== Schema Changes ==&lt;br /&gt;
&lt;br /&gt;
In teams_users table, we can add a new column '''participant_id''' which is a foreign key from participants table and remove the column '''user_id'''. We plan to remove the '''user_id''' column '''only after data migration''' since the user_id field is used predominantly in several other controllers in a variety of ways, and as such its removal must be done carefully.&lt;br /&gt;
&lt;br /&gt;
The participant_id field in the the teams_users relation is computed as follows:&lt;br /&gt;
&lt;br /&gt;
* Finding Assignment ID By Team ID&lt;br /&gt;
The teams_users table contains team_id, user_id and duty_id but not the participant_id. Since the same user_id can be associated with multiple participant_ids (since the same user can participate in multiple assignments and gets a unique participant_id in each assignment they take part in), we need to get the user_ids in the assignment for which we need the particular user's participant_id. For this reason, we need to first find the assignment_id.&lt;br /&gt;
&lt;br /&gt;
* Finding Participant ID By Assignment ID and User ID&lt;br /&gt;
With the assignment_id retrieved, we can find the list of participant_ids that participated in the assignment, and using the user_id, get the participant_id which is saved in the participants table. &lt;br /&gt;
&lt;br /&gt;
=== ER diagram for updated schema ===&lt;br /&gt;
[[File:Proposed_ERR_for_student_teams_E2243.png|900px]]&lt;br /&gt;
&lt;br /&gt;
== Data Migration ==&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
The Participants relation contains the user_id attribute which is a foreign key from users table. teams_users contains user_id which is also a foreign key from users table. Although the user_id field corresponds to same attribute, we cannot use this attribute alone to find the respective participant id because user_id is not a primary key in the participants table. i.e. same user_id can be associated with multiple participants. This is because in expertiza, all the users are stored in users table but, for each assignment, for each user, an entry is added in participants table. So, each user will have an entry in participants tables for all the assignments. &lt;br /&gt;
&lt;br /&gt;
An Assignment contains a list of participants (An Assignment has many Participants). Since a user can have only one entry in the participants table for each assignment, (assignment_id, user_id) pair will have only one participant id associated with it. &lt;br /&gt;
&lt;br /&gt;
== Proposed Implementation ==&lt;br /&gt;
&lt;br /&gt;
==== Finding Assignment ID By Team ID ====&lt;br /&gt;
&lt;br /&gt;
The teams_users table contains team_id, user_id and duty_id. Each team is associated with an assignment. The parent_id attribute in the teams table corresponds to assignment id. So, team_id in the teams_users table can be used to get the Team object using which we can fetch the assignment ID (parent_id).&lt;br /&gt;
&lt;br /&gt;
 # Code snippet to fetch assignment_id based on team_id&lt;br /&gt;
 assignment_id = Team.find(team_id).select(:parent_id)&lt;br /&gt;
&lt;br /&gt;
==== Finding Participant ID By Assignment ID and User ID ====&lt;br /&gt;
&lt;br /&gt;
The Assignment object can be fetched using the assignment ID. Each assignment contains a list of participants. The Participant object contains a user_id attribute. Since, a user can have only one entry in the Participants table for an assignment, we can use user_id to find the user's participant_id from this list.&lt;br /&gt;
&lt;br /&gt;
 # Code snippet to fetch participant_id based on assignment_id and user_id&lt;br /&gt;
 participant_id = Assignment.find(assignment_id).participants.find_by(:user_id user_id)&lt;br /&gt;
&lt;br /&gt;
=== Brute Force Data Migration ===&lt;br /&gt;
&lt;br /&gt;
The above mentioned code snippets can be used for each tuple in the teams_users table.&lt;br /&gt;
&lt;br /&gt;
 # Brute Force Code Snippet&lt;br /&gt;
 TeamsUser.all.each do |teamsUser|&lt;br /&gt;
     assignment_id = Team.find(teamsUser.team_id).select(:parent_id)&lt;br /&gt;
     participant_id = Assignment.find(assignment_id).participants.find_by(:user_id teamsUser.user_id)&lt;br /&gt;
     teamsUser.update_attribute(:participant_id, participant_id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=== Efficient Data Migration ===&lt;br /&gt;
In the brute force approach, database calls are made multiple times inside the loop. Moving the database calls out of the loop will give us a more efficient solution.&lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
&lt;br /&gt;
# Load all the TeamUser objects.&lt;br /&gt;
# Load all the Team objects for all the team_ids in TeamUser object&lt;br /&gt;
# Create a map with team_id as key and assignment_id as value. The resultant map usage: map[team_id] = assignment_id&lt;br /&gt;
# Load all the Assignment objects for all the assignment_ids from the map in the previous step. Also eager fetch participants along with the assignments.&lt;br /&gt;
# Create a nested map with assignment_id and user_id as key and participant_id as value. The resultant map usage: map[assignment_id][user_id] = participant_id&lt;br /&gt;
# For all TeamUser objects, find the participant_id from the maps generated from the previous steps and update the participant_id attribute.&lt;br /&gt;
&lt;br /&gt;
In this approach,  we make a total of 3 database calls which is considerably better than the previous brute-force approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Code Changes ==&lt;br /&gt;
The user_id attribute is used in multiple places within the application. Since, the new schema changes do not include user_id attribute in teams_users table, all the references of user_id must be updated to use participant_id, which is its new equivalent instead.&lt;br /&gt;
&lt;br /&gt;
=== Impacted Files ===&lt;br /&gt;
&lt;br /&gt;
# teams_users_controller&lt;br /&gt;
# suggestion_controller&lt;br /&gt;
# assessment360_controller&lt;br /&gt;
# grades_controller&lt;br /&gt;
# join_team_requests_controller&lt;br /&gt;
# review_mapping_controller&lt;br /&gt;
# student_teams_controller&lt;br /&gt;
&lt;br /&gt;
The respective test cases associated with these files must be fixed before fixing the code so that we can make sure that the proposed refactoring does not raise any new bugs.&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Proposed_ERR_for_student_teams_E2243.png&amp;diff=144482</id>
		<title>File:Proposed ERR for student teams E2243.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Proposed_ERR_for_student_teams_E2243.png&amp;diff=144482"/>
		<updated>2022-04-07T00:10:52Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: Aselvam uploaded a new version of File:Proposed ERR for student teams E2243.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143897</id>
		<title>CSC/ECE 517 Spring 2022 - E2243. Refactor student teams functionality</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143897"/>
		<updated>2022-04-01T09:25:49Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: /* Schema Changes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information about Expertiza Issue E2243. Refactor student teams functionality which was a project in CSC517 Spring 2022. &lt;br /&gt;
&lt;br /&gt;
Please see below for a description of the project.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
Users &amp;amp; Participants: Everyone who took the OODD class is a user in expertiza, and instructors can add users as participants in an assignment so that they can access it.&lt;br /&gt;
Almost everything within Assignments is done by participants, not users. That is, everything except teams_users. In the documentation, it can be noted that the team_users table references users instead of participants.&lt;br /&gt;
This anomaly causes problems with how student teams are rendered in the UI, and it doesn’t go well with the new functionality that were recently introduced.&lt;br /&gt;
&lt;br /&gt;
teams_users should be changed to teams_participants. the team_id, user_id mapping in this table should be changed to team_id, participant_id. All the references of user_id should be updated to use participant_id.&lt;br /&gt;
&lt;br /&gt;
== Schema Changes ==&lt;br /&gt;
&lt;br /&gt;
In teams_users table add new column '''participant_id''' which is a foreign key from participants table and remove column '''user_id'''. Remove the '''user_id''' column '''only after data migration'''&lt;br /&gt;
&lt;br /&gt;
=== ER diagram for updated schema ===&lt;br /&gt;
[[File:Proposed_ERR_for_student_teams_E2243.png|800px]]&lt;br /&gt;
&lt;br /&gt;
== Data Migration ==&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
Participants contains user_id attribute which is a foreign key from users table. teams_users contains user_id which is also a foreign key from users table. Although the user_id field corresponds to same attribute, we cannot use this attribute alone to find the respective participant id because user_id is not a primary key in the participants table. i.e. same user_id can be associated with multiple participants. This is because in expertiza, all the users are stored in users table but, for each assignment, for each user, an entry is added in participants table. So, each user will have an entry in participants tables for all the assignments. &lt;br /&gt;
&lt;br /&gt;
Assignment contains participants list (Assignment has_many Participant). Since a user can have only one entry in the participants table for each assignment, (assignment_id, user_id) pair will have only one participant id associated with it. &lt;br /&gt;
&lt;br /&gt;
==== Finding Assignment ID By Team ID ====&lt;br /&gt;
&lt;br /&gt;
teams_users table contains team_id, user_id and duty_id. Each team is associated with an assignment. parent_id attribute in the teams table corresponds to assignment id. So, team_id in the teams_users table can be used to get the Team object from which we can fetch the assignment ID (parent_id).&lt;br /&gt;
&lt;br /&gt;
 # Code snippet to fetch assignment_id based on team_id&lt;br /&gt;
 assignment_id = Team.find(team_id).select(:parent_id)&lt;br /&gt;
&lt;br /&gt;
==== Finding Participant ID By Assignment ID and User ID ====&lt;br /&gt;
&lt;br /&gt;
Assignment object can be fetched using the assignment ID. Each assignment contains participants list. Participant object contains user_id attribute. Since, a user can have only one entry in participants table for an assignment, we can use user_id to find the user's participant_id from this list.&lt;br /&gt;
&lt;br /&gt;
 # Code snippet to fetch participant_id based on assignment_id and user_id&lt;br /&gt;
 participant_id = Assignment.find(assignment_id).participants.find_by(:user_id user_id)&lt;br /&gt;
&lt;br /&gt;
=== Brute Force Data Migration ===&lt;br /&gt;
&lt;br /&gt;
The above mentioned code snippets can be used for each tuple  in the teams_users table.&lt;br /&gt;
&lt;br /&gt;
 # Brute Force Code Snippet&lt;br /&gt;
 TeamsUser.all.each do |teamsUser|&lt;br /&gt;
     assignment_id = Team.find(teamsUser.team_id).select(:parent_id)&lt;br /&gt;
     participant_id = Assignment.find(assignment_id).participants.find_by(:user_id teamsUser.user_id)&lt;br /&gt;
     teamsUser.update_attribute(:participant_id, participant_id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=== Efficient Data Migration ===&lt;br /&gt;
In the brute force approach, db calls are made multiple times inside the loop. Moving the db calls out of the loop will give us a more efficient solution.&lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
&lt;br /&gt;
# Load all the TeamUser objects.&lt;br /&gt;
# Load all the Team objects for all the team_ids in TeamUser object&lt;br /&gt;
# Create a map with team_id as key and assignment_id as value. The resultant map usage: map[team_id] = assignment_id&lt;br /&gt;
# Load all the Assignment objects for all the assignment_ids from the map in the previous step. Also eager fetch participants along with the assignments.&lt;br /&gt;
# Create a nested map with assignment_id and user_id as key and participant_id as value. The resultant map usage: map[assignment_id][user_id] = participant_id&lt;br /&gt;
# For all TeamUser objects, find the participant_id from the maps generated from the previous steps and update the participant_id attribute.&lt;br /&gt;
&lt;br /&gt;
In this approach,  we make a total of 3 db calls which is way better than the previous approach.&lt;br /&gt;
&lt;br /&gt;
== Code Changes ==&lt;br /&gt;
user_id attribute is used in multiple places within the application. Since, the new schema changes does not include user_id attribute in teams_users table, all the references of user_id must be updated to use participant_id equivalent instead.&lt;br /&gt;
&lt;br /&gt;
=== Impacted Files ===&lt;br /&gt;
&lt;br /&gt;
# teams_users_controller&lt;br /&gt;
# suggestion_controller&lt;br /&gt;
# assessment360_controller&lt;br /&gt;
# grades_controller&lt;br /&gt;
# join_team_requests_controller&lt;br /&gt;
# review_mapping_controller&lt;br /&gt;
# student_teams_controller&lt;br /&gt;
&lt;br /&gt;
The respective test cases associated with these files must be fixed before fixing the code so that we can make sure that the proposed refactoring does not raise any new bugs.&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143896</id>
		<title>CSC/ECE 517 Spring 2022 - E2243. Refactor student teams functionality</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143896"/>
		<updated>2022-04-01T09:23:06Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: /* Finding Participant ID By Assignment ID and User ID */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information about Expertiza Issue E2243. Refactor student teams functionality which was a project in CSC517 Spring 2022. &lt;br /&gt;
&lt;br /&gt;
Please see below for a description of the project.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
Users &amp;amp; Participants: Everyone who took the OODD class is a user in expertiza, and instructors can add users as participants in an assignment so that they can access it.&lt;br /&gt;
Almost everything within Assignments is done by participants, not users. That is, everything except teams_users. In the documentation, it can be noted that the team_users table references users instead of participants.&lt;br /&gt;
This anomaly causes problems with how student teams are rendered in the UI, and it doesn’t go well with the new functionality that were recently introduced.&lt;br /&gt;
&lt;br /&gt;
teams_users should be changed to teams_participants. the team_id, user_id mapping in this table should be changed to team_id, participant_id. All the references of user_id should be updated to use participant_id.&lt;br /&gt;
&lt;br /&gt;
== Schema Changes ==&lt;br /&gt;
&lt;br /&gt;
=== ER diagram for updated schema ===&lt;br /&gt;
[[File:Proposed_ERR_for_student_teams_E2243.png|800px]]&lt;br /&gt;
&lt;br /&gt;
== Data Migration ==&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
Participants contains user_id attribute which is a foreign key from users table. teams_users contains user_id which is also a foreign key from users table. Although the user_id field corresponds to same attribute, we cannot use this attribute alone to find the respective participant id because user_id is not a primary key in the participants table. i.e. same user_id can be associated with multiple participants. This is because in expertiza, all the users are stored in users table but, for each assignment, for each user, an entry is added in participants table. So, each user will have an entry in participants tables for all the assignments. &lt;br /&gt;
&lt;br /&gt;
Assignment contains participants list (Assignment has_many Participant). Since a user can have only one entry in the participants table for each assignment, (assignment_id, user_id) pair will have only one participant id associated with it. &lt;br /&gt;
&lt;br /&gt;
==== Finding Assignment ID By Team ID ====&lt;br /&gt;
&lt;br /&gt;
teams_users table contains team_id, user_id and duty_id. Each team is associated with an assignment. parent_id attribute in the teams table corresponds to assignment id. So, team_id in the teams_users table can be used to get the Team object from which we can fetch the assignment ID (parent_id).&lt;br /&gt;
&lt;br /&gt;
 # Code snippet to fetch assignment_id based on team_id&lt;br /&gt;
 assignment_id = Team.find(team_id).select(:parent_id)&lt;br /&gt;
&lt;br /&gt;
==== Finding Participant ID By Assignment ID and User ID ====&lt;br /&gt;
&lt;br /&gt;
Assignment object can be fetched using the assignment ID. Each assignment contains participants list. Participant object contains user_id attribute. Since, a user can have only one entry in participants table for an assignment, we can use user_id to find the user's participant_id from this list.&lt;br /&gt;
&lt;br /&gt;
 # Code snippet to fetch participant_id based on assignment_id and user_id&lt;br /&gt;
 participant_id = Assignment.find(assignment_id).participants.find_by(:user_id user_id)&lt;br /&gt;
&lt;br /&gt;
=== Brute Force Data Migration ===&lt;br /&gt;
&lt;br /&gt;
The above mentioned code snippets can be used for each tuple  in the teams_users table.&lt;br /&gt;
&lt;br /&gt;
 # Brute Force Code Snippet&lt;br /&gt;
 TeamsUser.all.each do |teamsUser|&lt;br /&gt;
     assignment_id = Team.find(teamsUser.team_id).select(:parent_id)&lt;br /&gt;
     participant_id = Assignment.find(assignment_id).participants.find_by(:user_id teamsUser.user_id)&lt;br /&gt;
     teamsUser.update_attribute(:participant_id, participant_id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=== Efficient Data Migration ===&lt;br /&gt;
In the brute force approach, db calls are made multiple times inside the loop. Moving the db calls out of the loop will give us a more efficient solution.&lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
&lt;br /&gt;
# Load all the TeamUser objects.&lt;br /&gt;
# Load all the Team objects for all the team_ids in TeamUser object&lt;br /&gt;
# Create a map with team_id as key and assignment_id as value. The resultant map usage: map[team_id] = assignment_id&lt;br /&gt;
# Load all the Assignment objects for all the assignment_ids from the map in the previous step. Also eager fetch participants along with the assignments.&lt;br /&gt;
# Create a nested map with assignment_id and user_id as key and participant_id as value. The resultant map usage: map[assignment_id][user_id] = participant_id&lt;br /&gt;
# For all TeamUser objects, find the participant_id from the maps generated from the previous steps and update the participant_id attribute.&lt;br /&gt;
&lt;br /&gt;
In this approach,  we make a total of 3 db calls which is way better than the previous approach.&lt;br /&gt;
&lt;br /&gt;
== Code Changes ==&lt;br /&gt;
user_id attribute is used in multiple places within the application. Since, the new schema changes does not include user_id attribute in teams_users table, all the references of user_id must be updated to use participant_id equivalent instead.&lt;br /&gt;
&lt;br /&gt;
=== Impacted Files ===&lt;br /&gt;
&lt;br /&gt;
# teams_users_controller&lt;br /&gt;
# suggestion_controller&lt;br /&gt;
# assessment360_controller&lt;br /&gt;
# grades_controller&lt;br /&gt;
# join_team_requests_controller&lt;br /&gt;
# review_mapping_controller&lt;br /&gt;
# student_teams_controller&lt;br /&gt;
&lt;br /&gt;
The respective test cases associated with these files must be fixed before fixing the code so that we can make sure that the proposed refactoring does not raise any new bugs.&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143895</id>
		<title>CSC/ECE 517 Spring 2022 - E2243. Refactor student teams functionality</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143895"/>
		<updated>2022-04-01T09:22:49Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: /* Finding Assignment ID By Team ID */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information about Expertiza Issue E2243. Refactor student teams functionality which was a project in CSC517 Spring 2022. &lt;br /&gt;
&lt;br /&gt;
Please see below for a description of the project.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
Users &amp;amp; Participants: Everyone who took the OODD class is a user in expertiza, and instructors can add users as participants in an assignment so that they can access it.&lt;br /&gt;
Almost everything within Assignments is done by participants, not users. That is, everything except teams_users. In the documentation, it can be noted that the team_users table references users instead of participants.&lt;br /&gt;
This anomaly causes problems with how student teams are rendered in the UI, and it doesn’t go well with the new functionality that were recently introduced.&lt;br /&gt;
&lt;br /&gt;
teams_users should be changed to teams_participants. the team_id, user_id mapping in this table should be changed to team_id, participant_id. All the references of user_id should be updated to use participant_id.&lt;br /&gt;
&lt;br /&gt;
== Schema Changes ==&lt;br /&gt;
&lt;br /&gt;
=== ER diagram for updated schema ===&lt;br /&gt;
[[File:Proposed_ERR_for_student_teams_E2243.png|800px]]&lt;br /&gt;
&lt;br /&gt;
== Data Migration ==&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
Participants contains user_id attribute which is a foreign key from users table. teams_users contains user_id which is also a foreign key from users table. Although the user_id field corresponds to same attribute, we cannot use this attribute alone to find the respective participant id because user_id is not a primary key in the participants table. i.e. same user_id can be associated with multiple participants. This is because in expertiza, all the users are stored in users table but, for each assignment, for each user, an entry is added in participants table. So, each user will have an entry in participants tables for all the assignments. &lt;br /&gt;
&lt;br /&gt;
Assignment contains participants list (Assignment has_many Participant). Since a user can have only one entry in the participants table for each assignment, (assignment_id, user_id) pair will have only one participant id associated with it. &lt;br /&gt;
&lt;br /&gt;
==== Finding Assignment ID By Team ID ====&lt;br /&gt;
&lt;br /&gt;
teams_users table contains team_id, user_id and duty_id. Each team is associated with an assignment. parent_id attribute in the teams table corresponds to assignment id. So, team_id in the teams_users table can be used to get the Team object from which we can fetch the assignment ID (parent_id).&lt;br /&gt;
&lt;br /&gt;
 # Code snippet to fetch assignment_id based on team_id&lt;br /&gt;
 assignment_id = Team.find(team_id).select(:parent_id)&lt;br /&gt;
&lt;br /&gt;
==== Finding Participant ID By Assignment ID and User ID ====&lt;br /&gt;
&lt;br /&gt;
Assignment object can be fetched using the assignment ID. Each assignment contains participants list. Participant object contains user_id attribute. Since, a user can have only one entry in participants table for an assignment, we can use user_id to find the user's participant_id from this list.&lt;br /&gt;
&lt;br /&gt;
Code snippet to fetch participant_id based on assignment_id and user_id&lt;br /&gt;
participant_id = Assignment.find(assignment_id).participants.find_by(:user_id user_id)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Brute Force Data Migration ===&lt;br /&gt;
&lt;br /&gt;
The above mentioned code snippets can be used for each tuple  in the teams_users table.&lt;br /&gt;
&lt;br /&gt;
 # Brute Force Code Snippet&lt;br /&gt;
 TeamsUser.all.each do |teamsUser|&lt;br /&gt;
     assignment_id = Team.find(teamsUser.team_id).select(:parent_id)&lt;br /&gt;
     participant_id = Assignment.find(assignment_id).participants.find_by(:user_id teamsUser.user_id)&lt;br /&gt;
     teamsUser.update_attribute(:participant_id, participant_id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=== Efficient Data Migration ===&lt;br /&gt;
In the brute force approach, db calls are made multiple times inside the loop. Moving the db calls out of the loop will give us a more efficient solution.&lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
&lt;br /&gt;
# Load all the TeamUser objects.&lt;br /&gt;
# Load all the Team objects for all the team_ids in TeamUser object&lt;br /&gt;
# Create a map with team_id as key and assignment_id as value. The resultant map usage: map[team_id] = assignment_id&lt;br /&gt;
# Load all the Assignment objects for all the assignment_ids from the map in the previous step. Also eager fetch participants along with the assignments.&lt;br /&gt;
# Create a nested map with assignment_id and user_id as key and participant_id as value. The resultant map usage: map[assignment_id][user_id] = participant_id&lt;br /&gt;
# For all TeamUser objects, find the participant_id from the maps generated from the previous steps and update the participant_id attribute.&lt;br /&gt;
&lt;br /&gt;
In this approach,  we make a total of 3 db calls which is way better than the previous approach.&lt;br /&gt;
&lt;br /&gt;
== Code Changes ==&lt;br /&gt;
user_id attribute is used in multiple places within the application. Since, the new schema changes does not include user_id attribute in teams_users table, all the references of user_id must be updated to use participant_id equivalent instead.&lt;br /&gt;
&lt;br /&gt;
=== Impacted Files ===&lt;br /&gt;
&lt;br /&gt;
# teams_users_controller&lt;br /&gt;
# suggestion_controller&lt;br /&gt;
# assessment360_controller&lt;br /&gt;
# grades_controller&lt;br /&gt;
# join_team_requests_controller&lt;br /&gt;
# review_mapping_controller&lt;br /&gt;
# student_teams_controller&lt;br /&gt;
&lt;br /&gt;
The respective test cases associated with these files must be fixed before fixing the code so that we can make sure that the proposed refactoring does not raise any new bugs.&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143894</id>
		<title>CSC/ECE 517 Spring 2022 - E2243. Refactor student teams functionality</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143894"/>
		<updated>2022-04-01T09:22:27Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: /* Brute Force Data Migration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information about Expertiza Issue E2243. Refactor student teams functionality which was a project in CSC517 Spring 2022. &lt;br /&gt;
&lt;br /&gt;
Please see below for a description of the project.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
Users &amp;amp; Participants: Everyone who took the OODD class is a user in expertiza, and instructors can add users as participants in an assignment so that they can access it.&lt;br /&gt;
Almost everything within Assignments is done by participants, not users. That is, everything except teams_users. In the documentation, it can be noted that the team_users table references users instead of participants.&lt;br /&gt;
This anomaly causes problems with how student teams are rendered in the UI, and it doesn’t go well with the new functionality that were recently introduced.&lt;br /&gt;
&lt;br /&gt;
teams_users should be changed to teams_participants. the team_id, user_id mapping in this table should be changed to team_id, participant_id. All the references of user_id should be updated to use participant_id.&lt;br /&gt;
&lt;br /&gt;
== Schema Changes ==&lt;br /&gt;
&lt;br /&gt;
=== ER diagram for updated schema ===&lt;br /&gt;
[[File:Proposed_ERR_for_student_teams_E2243.png|800px]]&lt;br /&gt;
&lt;br /&gt;
== Data Migration ==&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
Participants contains user_id attribute which is a foreign key from users table. teams_users contains user_id which is also a foreign key from users table. Although the user_id field corresponds to same attribute, we cannot use this attribute alone to find the respective participant id because user_id is not a primary key in the participants table. i.e. same user_id can be associated with multiple participants. This is because in expertiza, all the users are stored in users table but, for each assignment, for each user, an entry is added in participants table. So, each user will have an entry in participants tables for all the assignments. &lt;br /&gt;
&lt;br /&gt;
Assignment contains participants list (Assignment has_many Participant). Since a user can have only one entry in the participants table for each assignment, (assignment_id, user_id) pair will have only one participant id associated with it. &lt;br /&gt;
&lt;br /&gt;
==== Finding Assignment ID By Team ID ====&lt;br /&gt;
&lt;br /&gt;
teams_users table contains team_id, user_id and duty_id. Each team is associated with an assignment. parent_id attribute in the teams table corresponds to assignment id. So, team_id in the teams_users table can be used to get the Team object from which we can fetch the assignment ID (parent_id).&lt;br /&gt;
&lt;br /&gt;
Code snippet to fetch assignment_id based on team_id&lt;br /&gt;
assignment_id = Team.find(team_id).select(:parent_id)&lt;br /&gt;
&lt;br /&gt;
==== Finding Participant ID By Assignment ID and User ID ====&lt;br /&gt;
&lt;br /&gt;
Assignment object can be fetched using the assignment ID. Each assignment contains participants list. Participant object contains user_id attribute. Since, a user can have only one entry in participants table for an assignment, we can use user_id to find the user's participant_id from this list.&lt;br /&gt;
&lt;br /&gt;
Code snippet to fetch participant_id based on assignment_id and user_id&lt;br /&gt;
participant_id = Assignment.find(assignment_id).participants.find_by(:user_id user_id)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Brute Force Data Migration ===&lt;br /&gt;
&lt;br /&gt;
The above mentioned code snippets can be used for each tuple  in the teams_users table.&lt;br /&gt;
&lt;br /&gt;
 # Brute Force Code Snippet&lt;br /&gt;
 TeamsUser.all.each do |teamsUser|&lt;br /&gt;
     assignment_id = Team.find(teamsUser.team_id).select(:parent_id)&lt;br /&gt;
     participant_id = Assignment.find(assignment_id).participants.find_by(:user_id teamsUser.user_id)&lt;br /&gt;
     teamsUser.update_attribute(:participant_id, participant_id)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=== Efficient Data Migration ===&lt;br /&gt;
In the brute force approach, db calls are made multiple times inside the loop. Moving the db calls out of the loop will give us a more efficient solution.&lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
&lt;br /&gt;
# Load all the TeamUser objects.&lt;br /&gt;
# Load all the Team objects for all the team_ids in TeamUser object&lt;br /&gt;
# Create a map with team_id as key and assignment_id as value. The resultant map usage: map[team_id] = assignment_id&lt;br /&gt;
# Load all the Assignment objects for all the assignment_ids from the map in the previous step. Also eager fetch participants along with the assignments.&lt;br /&gt;
# Create a nested map with assignment_id and user_id as key and participant_id as value. The resultant map usage: map[assignment_id][user_id] = participant_id&lt;br /&gt;
# For all TeamUser objects, find the participant_id from the maps generated from the previous steps and update the participant_id attribute.&lt;br /&gt;
&lt;br /&gt;
In this approach,  we make a total of 3 db calls which is way better than the previous approach.&lt;br /&gt;
&lt;br /&gt;
== Code Changes ==&lt;br /&gt;
user_id attribute is used in multiple places within the application. Since, the new schema changes does not include user_id attribute in teams_users table, all the references of user_id must be updated to use participant_id equivalent instead.&lt;br /&gt;
&lt;br /&gt;
=== Impacted Files ===&lt;br /&gt;
&lt;br /&gt;
# teams_users_controller&lt;br /&gt;
# suggestion_controller&lt;br /&gt;
# assessment360_controller&lt;br /&gt;
# grades_controller&lt;br /&gt;
# join_team_requests_controller&lt;br /&gt;
# review_mapping_controller&lt;br /&gt;
# student_teams_controller&lt;br /&gt;
&lt;br /&gt;
The respective test cases associated with these files must be fixed before fixing the code so that we can make sure that the proposed refactoring does not raise any new bugs.&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143893</id>
		<title>CSC/ECE 517 Spring 2022 - E2243. Refactor student teams functionality</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143893"/>
		<updated>2022-04-01T09:20:39Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: Impacted files&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information about Expertiza Issue E2243. Refactor student teams functionality which was a project in CSC517 Spring 2022. &lt;br /&gt;
&lt;br /&gt;
Please see below for a description of the project.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
Users &amp;amp; Participants: Everyone who took the OODD class is a user in expertiza, and instructors can add users as participants in an assignment so that they can access it.&lt;br /&gt;
Almost everything within Assignments is done by participants, not users. That is, everything except teams_users. In the documentation, it can be noted that the team_users table references users instead of participants.&lt;br /&gt;
This anomaly causes problems with how student teams are rendered in the UI, and it doesn’t go well with the new functionality that were recently introduced.&lt;br /&gt;
&lt;br /&gt;
teams_users should be changed to teams_participants. the team_id, user_id mapping in this table should be changed to team_id, participant_id. All the references of user_id should be updated to use participant_id.&lt;br /&gt;
&lt;br /&gt;
== Schema Changes ==&lt;br /&gt;
&lt;br /&gt;
=== ER diagram for updated schema ===&lt;br /&gt;
[[File:Proposed_ERR_for_student_teams_E2243.png|800px]]&lt;br /&gt;
&lt;br /&gt;
== Data Migration ==&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
Participants contains user_id attribute which is a foreign key from users table. teams_users contains user_id which is also a foreign key from users table. Although the user_id field corresponds to same attribute, we cannot use this attribute alone to find the respective participant id because user_id is not a primary key in the participants table. i.e. same user_id can be associated with multiple participants. This is because in expertiza, all the users are stored in users table but, for each assignment, for each user, an entry is added in participants table. So, each user will have an entry in participants tables for all the assignments. &lt;br /&gt;
&lt;br /&gt;
Assignment contains participants list (Assignment has_many Participant). Since a user can have only one entry in the participants table for each assignment, (assignment_id, user_id) pair will have only one participant id associated with it. &lt;br /&gt;
&lt;br /&gt;
==== Finding Assignment ID By Team ID ====&lt;br /&gt;
&lt;br /&gt;
teams_users table contains team_id, user_id and duty_id. Each team is associated with an assignment. parent_id attribute in the teams table corresponds to assignment id. So, team_id in the teams_users table can be used to get the Team object from which we can fetch the assignment ID (parent_id).&lt;br /&gt;
&lt;br /&gt;
Code snippet to fetch assignment_id based on team_id&lt;br /&gt;
assignment_id = Team.find(team_id).select(:parent_id)&lt;br /&gt;
&lt;br /&gt;
==== Finding Participant ID By Assignment ID and User ID ====&lt;br /&gt;
&lt;br /&gt;
Assignment object can be fetched using the assignment ID. Each assignment contains participants list. Participant object contains user_id attribute. Since, a user can have only one entry in participants table for an assignment, we can use user_id to find the user's participant_id from this list.&lt;br /&gt;
&lt;br /&gt;
Code snippet to fetch participant_id based on assignment_id and user_id&lt;br /&gt;
participant_id = Assignment.find(assignment_id).participants.find_by(:user_id user_id)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Brute Force Data Migration ===&lt;br /&gt;
&lt;br /&gt;
The above mentioned code snippets can be used for each tuple  in the teams_users table.&lt;br /&gt;
&lt;br /&gt;
Brute Force Code Snippet&lt;br /&gt;
TeamsUser.all.each do |teamsUser|&lt;br /&gt;
    assignment_id = Team.find(teamsUser.team_id).select(:parent_id)&lt;br /&gt;
    participant_id = Assignment.find(assignment_id).participants.find_by(:user_id teamsUser.user_id)&lt;br /&gt;
    teamsUser.update_attribute(:participant_id, participant_id)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Efficient Data Migration ===&lt;br /&gt;
In the brute force approach, db calls are made multiple times inside the loop. Moving the db calls out of the loop will give us a more efficient solution.&lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
&lt;br /&gt;
# Load all the TeamUser objects.&lt;br /&gt;
# Load all the Team objects for all the team_ids in TeamUser object&lt;br /&gt;
# Create a map with team_id as key and assignment_id as value. The resultant map usage: map[team_id] = assignment_id&lt;br /&gt;
# Load all the Assignment objects for all the assignment_ids from the map in the previous step. Also eager fetch participants along with the assignments.&lt;br /&gt;
# Create a nested map with assignment_id and user_id as key and participant_id as value. The resultant map usage: map[assignment_id][user_id] = participant_id&lt;br /&gt;
# For all TeamUser objects, find the participant_id from the maps generated from the previous steps and update the participant_id attribute.&lt;br /&gt;
&lt;br /&gt;
In this approach,  we make a total of 3 db calls which is way better than the previous approach.&lt;br /&gt;
&lt;br /&gt;
== Code Changes ==&lt;br /&gt;
user_id attribute is used in multiple places within the application. Since, the new schema changes does not include user_id attribute in teams_users table, all the references of user_id must be updated to use participant_id equivalent instead.&lt;br /&gt;
&lt;br /&gt;
=== Impacted Files ===&lt;br /&gt;
&lt;br /&gt;
# teams_users_controller&lt;br /&gt;
# suggestion_controller&lt;br /&gt;
# assessment360_controller&lt;br /&gt;
# grades_controller&lt;br /&gt;
# join_team_requests_controller&lt;br /&gt;
# review_mapping_controller&lt;br /&gt;
# student_teams_controller&lt;br /&gt;
&lt;br /&gt;
The respective test cases associated with these files must be fixed before fixing the code so that we can make sure that the proposed refactoring does not raise any new bugs.&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143892</id>
		<title>CSC/ECE 517 Spring 2022 - E2243. Refactor student teams functionality</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143892"/>
		<updated>2022-04-01T08:56:16Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: Data migration proposal&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information about Expertiza Issue E2243. Refactor student teams functionality which was a project in CSC517 Spring 2022. &lt;br /&gt;
&lt;br /&gt;
Please see below for a description of the project.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
Users &amp;amp; Participants: Everyone who took the OODD class is a user in expertiza, and instructors can add users as participants in an assignment so that they can access it.&lt;br /&gt;
Almost everything within Assignments is done by participants, not users. That is, everything except teams_users. In the documentation, it can be noted that the team_users table references users instead of participants.&lt;br /&gt;
This anomaly causes problems with how student teams are rendered in the UI, and it doesn’t go well with the new functionality that were recently introduced.&lt;br /&gt;
&lt;br /&gt;
teams_users should be changed to teams_participants. the team_id, user_id mapping in this table should be changed to team_id, participant_id. All the references of user_id should be updated to use participant_id.&lt;br /&gt;
&lt;br /&gt;
== Schema Changes ==&lt;br /&gt;
&lt;br /&gt;
=== ER diagram for updated schema ===&lt;br /&gt;
[[File:Proposed_ERR_for_student_teams_E2243.png|800px]]&lt;br /&gt;
&lt;br /&gt;
== Data Migration ==&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
Participants contains user_id attribute which is a foreign key from users table. teams_users contains user_id which is also a foreign key from users table. Although the user_id field corresponds to same attribute, we cannot use this attribute alone to find the respective participant id because user_id is not a primary key in the participants table. i.e. same user_id can be associated with multiple participants. This is because in expertiza, all the users are stored in users table but, for each assignment, for each user, an entry is added in participants table. So, each user will have an entry in participants tables for all the assignments. &lt;br /&gt;
&lt;br /&gt;
Assignment contains participants list (Assignment has_many Participant). Since a user can have only one entry in the participants table for each assignment, (assignment_id, user_id) pair will have only one participant id associated with it. &lt;br /&gt;
&lt;br /&gt;
==== Finding Assignment ID By Team ID ====&lt;br /&gt;
&lt;br /&gt;
teams_users table contains team_id, user_id and duty_id. Each team is associated with an assignment. parent_id attribute in the teams table corresponds to assignment id. So, team_id in the teams_users table can be used to get the Team object from which we can fetch the assignment ID (parent_id).&lt;br /&gt;
&lt;br /&gt;
Code snippet to fetch assignment_id based on team_id&lt;br /&gt;
assignment_id = Team.find(team_id).select(:parent_id)&lt;br /&gt;
&lt;br /&gt;
==== Finding Participant ID By Assignment ID and User ID ====&lt;br /&gt;
&lt;br /&gt;
Assignment object can be fetched using the assignment ID. Each assignment contains participants list. Participant object contains user_id attribute. Since, a user can have only one entry in participants table for an assignment, we can use user_id to find the user's participant_id from this list.&lt;br /&gt;
&lt;br /&gt;
Code snippet to fetch participant_id based on assignment_id and user_id&lt;br /&gt;
participant_id = Assignment.find(assignment_id).participants.find_by(:user_id user_id)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Brute Force Data Migration ===&lt;br /&gt;
&lt;br /&gt;
The above mentioned code snippets can be used for each tuple  in the teams_users table.&lt;br /&gt;
&lt;br /&gt;
Brute Force Code Snippet&lt;br /&gt;
TeamsUser.all.each do |teamsUser|&lt;br /&gt;
    assignment_id = Team.find(teamsUser.team_id).select(:parent_id)&lt;br /&gt;
    participant_id = Assignment.find(assignment_id).participants.find_by(:user_id teamsUser.user_id)&lt;br /&gt;
    teamsUser.update_attribute(:participant_id, participant_id)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Efficient Data Migration ===&lt;br /&gt;
In the brute force approach, db calls are made multiple times inside the loop. Moving the db calls out of the loop will give us a more efficient solution.&lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
&lt;br /&gt;
# Load all the TeamUser objects.&lt;br /&gt;
# Load all the Team objects for all the team_ids in TeamUser object&lt;br /&gt;
# Create a map with team_id as key and assignment_id as value. The resultant map usage: map[team_id] = assignment_id&lt;br /&gt;
# Load all the Assignment objects for all the assignment_ids from the map in the previous step. Also eager fetch participants along with the assignments.&lt;br /&gt;
# Create a nested map with assignment_id and user_id as key and participant_id as value. The resultant map usage: map[assignment_id][user_id] = participant_id&lt;br /&gt;
# For all TeamUser objects, find the participant_id from the maps generated from the previous steps and update the participant_id attribute.&lt;br /&gt;
&lt;br /&gt;
In this approach,  we make a total of 3 db calls which is way better than the previous approach.&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Proposed_ERR_for_student_teams_E2243.png&amp;diff=143891</id>
		<title>File:Proposed ERR for student teams E2243.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Proposed_ERR_for_student_teams_E2243.png&amp;diff=143891"/>
		<updated>2022-04-01T07:43:07Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: Aselvam uploaded a new version of File:Proposed ERR for student teams E2243.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Proposed_ERR_for_student_teams_E2243.png&amp;diff=143890</id>
		<title>File:Proposed ERR for student teams E2243.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Proposed_ERR_for_student_teams_E2243.png&amp;diff=143890"/>
		<updated>2022-04-01T07:38:10Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143858</id>
		<title>CSC/ECE 517 Spring 2022 - E2243. Refactor student teams functionality</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2243._Refactor_student_teams_functionality&amp;diff=143858"/>
		<updated>2022-03-31T18:50:34Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information about Expertiza Issue E2243. Refactor student teams functionality which was a project in CSC517 Spring 2022. &lt;br /&gt;
&lt;br /&gt;
Please see below for a description of the project.&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
Users &amp;amp; Participants: Everyone who took the OODD class is a user in expertiza, and instructors can add users as participants in an assignment so that they can access it.&lt;br /&gt;
Almost everything within Assignments is done by participants, not users. That is, everything except teams_users. In the documentation, it can be noted that the team_users table references users instead of participants.&lt;br /&gt;
This anomaly causes problems with how student teams are rendered in the UI, and it doesn’t go well with the new functionality that were recently introduced.&lt;br /&gt;
&lt;br /&gt;
teams_users should be changed to teams_participants. the team_id, user_id mapping in this table should be changed to team_id, participant_id. All the references of user_id should be updated to use participant_id.&lt;br /&gt;
&lt;br /&gt;
== Analysis ==&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2219:_Improve_assessment360_controller.rb&amp;diff=143806</id>
		<title>CSC/ECE 517 Spring 2022 - E2219: Improve assessment360 controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2022_-_E2219:_Improve_assessment360_controller.rb&amp;diff=143806"/>
		<updated>2022-03-28T06:07:05Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains information about Expertiza Issue E2219 Improve assessment360_controller.rb which was a project in CSC517 Spring 2022. Please see below for a description of the improvements made, issues fixed, code changed, testing information, details required to peer-review the project, and future improvements.&lt;br /&gt;
&lt;br /&gt;
== Peer Review Information ==&lt;br /&gt;
&lt;br /&gt;
For users who would like to view and test the assessment 360 feature, the deployed Expertiza application can be found at the URL mentioned below and can be access using the credentials below: &lt;br /&gt;
&lt;br /&gt;
URL: http://152.7.99.75:8080&lt;br /&gt;
&lt;br /&gt;
Instructor login: &lt;br /&gt;
&lt;br /&gt;
Username: '''instructor6'''&lt;br /&gt;
&lt;br /&gt;
Password: '''password'''&lt;br /&gt;
&lt;br /&gt;
Click on courses and then click on the icon on any one course to go to the assessment 360 page, or log in and paste this URL into the browser: http://152.7.99.75:8080/assessment360/index?course_id=184&lt;br /&gt;
The course ID here is an example, you can add the course ID of your choice.&lt;br /&gt;
&lt;br /&gt;
[[File:E2219 Navigation.jpeg|800px]]&lt;br /&gt;
&lt;br /&gt;
Please note that due to VCL constraints, the page will take few mins to load and render the data. Please wait for the page to '''load completely''' before starting the peer review. &lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The Expertiza project is software to create reusable learning objects through peer review. It also supports team projects, and the submission of almost any document type, including URLs and wiki pages.&lt;br /&gt;
The Expertiza project contains a feature that allows instructors to get a full or 360-degree view of a course they teach that includes all students in the course, all assignments, and the scores of each student in each assignment, averages, and final scores as well. This feature, called assessment 360, was written in a previous year, and due to issues identified with the code such as variable names, redundancy, code smells etc, a need for improvement of the same was identified. &lt;br /&gt;
&lt;br /&gt;
== Issues and Description of Fixes ==&lt;br /&gt;
In our work on improving this feature, we have handled the following issues and made the following improvements:&lt;br /&gt;
&lt;br /&gt;
=== Refactoring ===&lt;br /&gt;
&lt;br /&gt;
The previous implementation of the controller made a number of database calls, several of which were extraneous and not required. We have refactored the functions pertaining to these calls so that the number of unneeded calls to the database is reduced for loading teammate and metareviews. &lt;br /&gt;
&lt;br /&gt;
The older implementation of the computation for class averages, and students average scores incorrectly factored in students who had not received grades for an assignment or who had not taken part in an assignment. &lt;br /&gt;
In addition to correcting this, we also simplified the process by refactoring the code(please see the next section for the code).&lt;br /&gt;
&lt;br /&gt;
The past implementation of the controller was unclear and non-Rubyistic in naming conventions, function names, and implementation in the code. We have refactored the controller to make it more Rubyistic overall and also re-written parts of the code to make it more understandable, as well as more CRUD-like. Additionally, we made several methods whose functionality was required and used only inside this controller private.&lt;br /&gt;
&lt;br /&gt;
=== UI changes ===&lt;br /&gt;
The previous implementation had 2 views – all_students_all_reviews and course_student_grade_summary. Both of these views cover some of the data required for a 360-degree view of the course. &lt;br /&gt;
We have combined these pages together into a single page that contains checkboxes which allow the user to select what data they would like to view and shows only those columns they would like to see. This both simplifies and enhances the functioning of the feature.&lt;br /&gt;
&lt;br /&gt;
=== Variable Names, Cosmetic Issues, Comments ===&lt;br /&gt;
&lt;br /&gt;
In the older implementation, there were some unclear variable names such as teamed_count, and some other minor cosmetic issues such as a hyphen being displayed for empty fields where a dash would more visible and clearer. These have been fixed in both the code and the UI of the application to be user-friendly and developer friendly.&lt;br /&gt;
Additionally, comments have been added everywhere to make the code easier to understand and modify for future improvements.&lt;br /&gt;
&lt;br /&gt;
== Fix details and Code Explanation ==&lt;br /&gt;
&lt;br /&gt;
=== Files Changed ===&lt;br /&gt;
The following files were altered and edited in the course of our work on this feature:&lt;br /&gt;
Assessment360_Controller.rb (under app/controller)&lt;br /&gt;
This file contains the controller for the assessment 360 feature which we have improved in our work. The code has been refactored to be cleaner, modular,  easier to understand and also to incorporate DRY. &lt;br /&gt;
&lt;br /&gt;
Index.html.erb (under app/views/assessment360)&lt;br /&gt;
The view for the assessment 360 feature have been combined as stated in the requirements and all the data is now viewable from the index.html.erb page. This page also features checkboxes so the user can view only the data they are interested in without cluttering caused by unneeded data.&lt;br /&gt;
&lt;br /&gt;
=== Issue Fix Details ===&lt;br /&gt;
&lt;br /&gt;
1) '''app/controllers/assessment360_controller.rb'''&lt;br /&gt;
&lt;br /&gt;
[[File:E2219 assessment360 controller 1.png|800px]]&lt;br /&gt;
&lt;br /&gt;
[[File:E2219 assessment360 controller 2.png|800px]]&lt;br /&gt;
&lt;br /&gt;
[[File:E2219 assessment360 controller 3.png|800px]]&lt;br /&gt;
&lt;br /&gt;
[[File:E2219 assessment360 controller 4.png|800px]]&lt;br /&gt;
&lt;br /&gt;
'''Code changes'''&lt;br /&gt;
&lt;br /&gt;
1. In all_student_all_reviews function, the DB calls are by creating init_data function.&lt;br /&gt;
&lt;br /&gt;
2. The init_data function, removes DB calls inside nested for-loops (look for old code, below) which makes db call for every iteration, the code has been refactored in such a way that it preloads the required data using assignments.includes([:participants]) (look for new code, below). This way, instead of making multiple db calls across diff functions, we load the required data and thereby reduce the processing time.&lt;br /&gt;
&lt;br /&gt;
3. The major change, which we've incorporated here is moving the functions which weren't used in other modules into private. Moving excess functions to private, helps keep the controller more CRUD-like and differentiates to the developer which functions are used by the controller to work, and which ones are the functions of the controller.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Old Code (with complex for loops and more db calls)'''&lt;br /&gt;
&lt;br /&gt;
 @course_participants.each do |cp|&lt;br /&gt;
      # for each assignment&lt;br /&gt;
      # [aggregrate_review_grades_per_stu, review_count_per_stu] --&amp;gt; [0, 0]&lt;br /&gt;
      %w[teammate meta].each { |type| instance_variable_set(&amp;quot;@#{type}_review_info_per_stu&amp;quot;, [0, 0]) }&lt;br /&gt;
      students_teamed = StudentTask.teamed_students(cp.user)&lt;br /&gt;
      @teamed_count[cp.id] = students_teamed[course.id].try(:size).to_i&lt;br /&gt;
      @assignments.each do |assignment|&lt;br /&gt;
        @meta_review[cp.id] = {} unless @meta_review.key?(cp.id)&lt;br /&gt;
        @teammate_review[cp.id] = {} unless @teammate_review.key?(cp.id)&lt;br /&gt;
        assignment_participant = assignment.participants.find_by(user_id: cp.user_id)&lt;br /&gt;
        next if assignment_participant.nil?&lt;br /&gt;
        teammate_reviews = assignment_participant.teammate_reviews&lt;br /&gt;
        meta_reviews = assignment_participant.metareviews&lt;br /&gt;
        calc_overall_review_info(assignment,&lt;br /&gt;
                                 cp,&lt;br /&gt;
                                 teammate_reviews,&lt;br /&gt;
                                 @teammate_review,&lt;br /&gt;
                                 @overall_teammate_review_grades,&lt;br /&gt;
                                 @overall_teammate_review_count,&lt;br /&gt;
                                 @teammate_review_info_per_stu)&lt;br /&gt;
        calc_overall_review_info(assignment,&lt;br /&gt;
                                 cp,&lt;br /&gt;
                                 meta_reviews,&lt;br /&gt;
                                 @meta_review,&lt;br /&gt;
                                 @overall_meta_review_grades,&lt;br /&gt;
                                 @overall_meta_review_count,&lt;br /&gt;
                                 @meta_review_info_per_stu)&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Refactored Code (with limited iteration and db calls)'''&lt;br /&gt;
    @assignments.each do |assignment|&lt;br /&gt;
      assignment.participants.each do |assignment_participant|&lt;br /&gt;
        reviews[assignment_participant.user_id] = {} unless reviews.key?(assignment_participant.user_id)&lt;br /&gt;
        assignment_reviews = assignment_participant.public_send(reviews_type) if assignment_participant.respond_to? reviews_type&lt;br /&gt;
        # If a student has not taken an assignment or if they have not received any grade for the same,&lt;br /&gt;
        # assign it as nil(not returning anything). This helps in easier calculation of overall grade&lt;br /&gt;
        score = calc_avg_score(assignment_reviews)&lt;br /&gt;
        reviews[assignment_participant.user_id][assignment.id] = score unless score.nil?&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2) '''app/views/assessment360/index.html.erb'''&lt;br /&gt;
&lt;br /&gt;
[[File:E2219 indexhtmlerb 1.png|800px]]&lt;br /&gt;
&lt;br /&gt;
[[File:E2219 indexhtmlerb 2.png|800px]]&lt;br /&gt;
&lt;br /&gt;
[[File:E2219 indexhtmlerb 3.png|800px]]&lt;br /&gt;
&lt;br /&gt;
1. We've created a new file called ''index.html.erb''. This file contains all the logic for the frontend of this module.&lt;br /&gt;
&lt;br /&gt;
2. Major change that has been made is the addition of checkboxes. This way, users can filter the data that they view and view the data efficiently. &lt;br /&gt;
&lt;br /&gt;
3. This page loads all the assignment data, and their metadata like - meta reviews, teammate reviews, peer score, topic and instructor grade. The table also contains Aggregate score and Total grade.&lt;br /&gt;
&lt;br /&gt;
4. The checkboxes have been programmed in a way that whenever a checkbox is disabled, the corresponding column gets removed and the colspan rendering gets adjusted. Along with that, when all assignment parameters are unchecked, the assignment columns disappear completely. Same applies for aggregate score and Total Instructor Grade.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3) '''config/routes.rb'''&lt;br /&gt;
&lt;br /&gt;
[[File:E2219 routes 1.png|800px]]&lt;br /&gt;
&lt;br /&gt;
Removed old route to this page and pointed it to the newly created index page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can check all the issues fixed here - https://github.com/expertiza/expertiza/pull/2337&lt;br /&gt;
&lt;br /&gt;
== Test Plan==&lt;br /&gt;
&lt;br /&gt;
=== Automated Testing using RSPEC ===&lt;br /&gt;
Please note that we have removed several older tests which tested functions that are now private and inaccessible outside the controller class itself. However, the methods that call these private functions are still tested and tests are passing successfully.&lt;br /&gt;
&lt;br /&gt;
1. After refactoring, most of our new test cases focus on functions which are the core of the controller - covering important aspects like who accesses the page, checking permissions for the page, how the page behaves on edge cases etc.&lt;br /&gt;
&lt;br /&gt;
2. Using RSpec, the test cases cover various scenarios and tests each scenario in depth. &lt;br /&gt;
Eg, for access control, we check the access for all roles for a user comprehensively to ensure that only people with permissions can view the page. &lt;br /&gt;
&lt;br /&gt;
3. Since most of the work in this module is computations in the back and rendering data in the frontend, we've ensured that the computations happen in their specific order and enough test cases are present for edge cases. &lt;br /&gt;
&lt;br /&gt;
4. For backend computations, we've covered lot of edge cases like no participants to a course, when there are no reviews made by a participant, when assignment doesn't exists, insure existence_of being called before executing index page etc. &lt;br /&gt;
&lt;br /&gt;
5. For frontend, we've covered cases like formatting of the data in the page, null dataset, score being int, float, null, displaying percentages when data is int, float, null etc.&lt;br /&gt;
&lt;br /&gt;
Even though we've moved most of the code into private functions, the core functionalities of the controller are refactored and appropriate test cases are written to ensure high coverage. &lt;br /&gt;
&lt;br /&gt;
Please run the following command to execute the tests:&lt;br /&gt;
&lt;br /&gt;
 rspec spec/controllers/assessment360_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Testing from UI ===&lt;br /&gt;
The following steps needs to be performed to test this code from UI:&lt;br /&gt;
&lt;br /&gt;
1.	Login as instructor(username: instructor6 , password: password). Please either do step 2 or 3, as both are not required.&lt;br /&gt;
&lt;br /&gt;
2.	Select Courses, and the page will show a list of courses. Please select the rightmost icons for any course (we recommend CSC517 Fall 2017, CSC517 Fall 2011 so there’s more data, but it can take some time for it load since there’s a lot of pre-loaded data in the VCL)&lt;br /&gt;
&lt;br /&gt;
3.	Alternatively, you can login and go to this URL: http://152.7.99.75:8080/assessment360/index?course_id=184&lt;br /&gt;
&lt;br /&gt;
4.	You should be able to see a webpage with a table and checkboxes at the top. This table is an instructor’s 360-degree view of a course, containing the scores of each students in the course for every assignment the instructor has added to Expertiza. &lt;br /&gt;
&lt;br /&gt;
5.	Unchecking some or all of the checkboxes removes and brings back various columns from/to the page. Please feel free to test this out.&lt;br /&gt;
&lt;br /&gt;
=== Code Coverage ===&lt;br /&gt;
&lt;br /&gt;
[[File:E2219_codecov.png|800px]]&lt;br /&gt;
&lt;br /&gt;
== Scope for future improvement ==&lt;br /&gt;
&lt;br /&gt;
The UI of the index page which shows all of the data can be improved to make it look neater and more aesthetically pleasing. The table’s positioning and centering can be improved for a more convenient experience overall.&lt;br /&gt;
&lt;br /&gt;
The user’s preferred (checked on the UI checkboxes) can be saved to either the Database or a cache, and on subsequent reloads be the fields loaded on the page for a particular. We suggest using the database for this rather than a cache. &lt;br /&gt;
&lt;br /&gt;
Lazy loading can be implemented for the columns the user last chose(assuming these are stored in the DB) and other columns can lazy-loaded if the user clicks on the checkboxes on the screen.&lt;br /&gt;
&lt;br /&gt;
'''''course_student_grade_summary''''' function inside the assessment360_controller.rb contains few unnecessary db calls which can be refactored further to increase the efficiency and reduce the processing time of the module.&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E2219_codecov.png&amp;diff=143805</id>
		<title>File:E2219 codecov.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E2219_codecov.png&amp;diff=143805"/>
		<updated>2022-03-28T06:02:27Z</updated>

		<summary type="html">&lt;p&gt;Aselvam: Code coverage for assessment360 controller&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Code coverage for assessment360 controller&lt;/div&gt;</summary>
		<author><name>Aselvam</name></author>
	</entry>
</feed>