CSC/ECE 517 Fall 2014/OSS E1461 knn: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 51: Line 51:
*config/routes.rb
*config/routes.rb
===Style Changes Based on Current Conventions===
===Style Changes Based on Current Conventions===
===="Where" Method Calls====
All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where ".where" was being used to find just one instance, it was instead changed to "find_by". The changes made are shown below:
Old Where Method Calls
<pre>
#view
@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = "W"', @student.user.id, @student.assignment.id])
#create
check = AssignmentTeam.where( ["name =? and parent_id =?", params[:team][:name], @student.parent_id])
#update
check = AssignmentTeam.where( ["name =? and parent_id =?", params[:team][:name], @team.parent_id])
#leave
user = TeamsUser.where(["team_id =? and user_id =?", params[:team_id], @student.user_id]).first
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])
signups = SignedUpUser.where( {:creator_id => params[:team_id]})
non_waitlisted_users = SignedUpUser.where( {:topic_id => signup_topic_id, :is_waitlisted => false})
max_choosers = SignUpTopic.where( {:id => signup_topic_id}).first.max_choosers
first_waitlisted_user = SignedUpUser.where( {:topic_id => signup_topic_id, :is_waitlisted => true}).first
waitlisted_team_user = TeamsUser.where( {:team_id => first_waitlisted_user.creator_id}).first
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])
</pre>
Refactored Where Method Calls
<pre>
#view
@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'
#create
existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id
#update
matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id
#remove_participant (renamed method - was #leave)
team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id
old_team = AssignmentTeam.find params[:team_id]
sign_ups = SignedUpUser.where creator_id: params[:team_id]
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#<order?
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id

Revision as of 21:29, 28 October 2014

'Expertiza - Refactoring StudentTeamController'

Introduction

Expertiza is an open source web application created by NCSU give a interface for team learning and peer review. Expertiza allows students to create and communicate with teams as well as an easy platform for online assignment submission. Another feature of Expertiza is its framework for allowing a peer review system on assignments, creating an easy way to give and receive feedback on assignments, allowing for improvement and re-submission based on classmates constructive feedback.

One part of the OSS project for Fall 2014 was refactoring of different sections of Expertiza. Our team was tasked with refactoring of the StudentTeamController.

StudentTeamController

StudentTeamController is responsible for the methods creation and joining of teams for group projects on Expertiza. Specifically, this controller allows the user to:

  • Create, edit or delete a team (name)
  • Add a teamate to the team
  • Leave a team if they want to move to a new team
  • View received and sent invitations

This controller also provides the student and team instance variables to the corresponding student_team views.

We were tasked with refactoring this controller using DRY principles and more RESTful actions as well as updating our sections using the most current excepted ruby and rails style guidelines. In addition, 6 specific tasks were given:

Refactoring of Old Code

Using Routing Helpers

Modifications were made to routes pointing to student_teams views by adding helpers as well as changing to new bracket initializers and removed unnecessary parens. Changes were made inside StudentTeamsController.rb as well as anywhere that used routes pointing to StudentTeamsController which consisted of:

  • advertise_for_partner_controller.rb
  • invitation_controller.rb
  • join_team_requests_controller.rb
  • reports_controller.rb
  • response_controller.rb
  • app\views\advertise_for_partner\show.html.erb
  • app\views\student_task\view.html.erb
  • app\views\student_teams\view.html.erb

The routes changed were as follows:

Before Refactoring:

redirect_to :controller => 'student_team', :action => 'view' , :id=> @student.id
redirect_to :controller =>'student_team', :action => 'edit', :team_id =>params[:team_id], :student_id => params[:student_id]

After Refactoring:

redirect_to view_student_teams_path student_id: student.id
redirect_to edit_student_teams_path team_id: params[:team_id], student_id: params[:student_id]

Pluralize StudentTeamController Class Name

StudentTeamController was changed to StudentTeamsController in accordance to current Rails convention. This required the pluralizing of any references to the class in other files in the project, specifically in all the files listed that were changed for routing helpers as well as:

  • submitted_content_controller.rb
  • config/routes.rb

Style Changes Based on Current Conventions

"Where" Method Calls

All where method calls in the controller were refactored to reflect current style guidelines. These calls were changed from the older style more closely resembling a sql WHERE statement to the more conventional style. In addition, the check variables used in the create and update methods were changed to existing_assignment and matching_teams to better reflect what they represent. Finally, in places where ".where" was being used to find just one instance, it was instead changed to "find_by". The changes made are shown below: Old Where Method Calls

#view

@send_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user.id, @student.assignment.id])
@received_invs = Invitation.where( ['to_id = ? and assignment_id = ? and reply_status = "W"', @student.user.id, @student.assignment.id])

#create

check = AssignmentTeam.where( ["name =? and parent_id =?", params[:team][:name], @student.parent_id])

#update

check = AssignmentTeam.where( ["name =? and parent_id =?", params[:team][:name], @team.parent_id])

#leave

user = TeamsUser.where(["team_id =? and user_id =?", params[:team_id], @student.user_id]).first
other_members = TeamsUser.where( ['team_id = ?', params[:team_id]])
old_team = AssignmentTeam.where( ['id = ?', params[:team_id]])
signups = SignedUpUser.where( {:creator_id => params[:team_id]})
non_waitlisted_users = SignedUpUser.where( {:topic_id => signup_topic_id, :is_waitlisted => false})
max_choosers = SignUpTopic.where( {:id => signup_topic_id}).first.max_choosers
first_waitlisted_user = SignedUpUser.where( {:topic_id => signup_topic_id, :is_waitlisted => true}).first
waitlisted_team_user = TeamsUser.where( {:team_id => first_waitlisted_user.creator_id}).first
old_invs = Invitation.where( ['from_id = ? and assignment_id = ?', @student.user_id, @student.parent_id])

Refactored Where Method Calls

#view

@send_invs = Invitation.where from_id: student.user.id, assignment_id: student.assignment.id
@received_invs = Invitation.where to_id: student.user.id, assignment_id: student.assignment.id, reply_status: 'W'

#create

existing_assignments = AssignmentTeam.where name: params[:team][:name], parent_id: student.parent_id

#update

matching_teams = AssignmentTeam.where name: params[:team][:name], parent_id: team.parent_id

#remove_participant (renamed method - was #leave)

team_user = TeamsUser.find_by team_id: params[:team_id], user_id: student.user_id
old_team = AssignmentTeam.find params[:team_id]
sign_ups = SignedUpUser.where creator_id: params[:team_id]
non_waitlisted_users = SignedUpUser.where topic_id: sign_up_topic_id, is_waitlisted: false
max_choosers = SignUpTopic.find(sign_up_topic_id).max_choosers
first_waitlisted_user = SignedUpUser.find_by topic_id: sign_up_topic_id, is_waitlisted: true#<order?
waitlisted_team_user = TeamsUser.find_by team_id: first_waitlisted_user.creator_id 
old_invites = Invitation.where from_id: student.user_id, assignment_id: student.parent_id