Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2003, Refactor Assessment 360 Controller #1691

Closed
wants to merge 20 commits into from
Closed
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ba12c91
fixed course student grade summary
ramyananth Mar 19, 2020
829d37f
refactored similar blocks, reduced cyclomatic and perceived complexit…
ramyananth Mar 22, 2020
b47c529
refactored similar blocks, reduced cyclomatic and perceived complexit…
ramyananth Mar 22, 2020
dd5994b
added space after comma, removed extra space
ramyananth Mar 22, 2020
c7d3b67
removed trailing white spaces
ramyananth Mar 22, 2020
48ecd75
using guard clause instead of wrapping code
ramyananth Mar 23, 2020
a732509
fixed non-local exit from iterator
ramyananth Mar 23, 2020
3dbf320
changed function names to more meaningful ones
ramyananth Mar 23, 2020
326a7ae
rename review_info_per_stu to avg_review_calc_per_stu
ramyananth Mar 23, 2020
1df1e0e
reduced number of parameters being passed
ramyananth Mar 23, 2020
4dc72f3
added comments for all functions - easier understanding_
ramyananth Mar 23, 2020
192a957
removed trailing whitespaces from comments
ramyananth Mar 23, 2020
2b00478
Renamed populate_hash_function,fixed the overal_review_count_hash
ushvarma Mar 24, 2020
a4345fa
Replace dig function with a hash check
ushvarma Mar 24, 2020
56ecccc
Delete Gemfile.lock
ramyananth Mar 31, 2020
0527b89
modify to not push gemfile.lock
ramyananth Mar 31, 2020
c05bd4c
push gemfile.lock
ramyananth Mar 31, 2020
6273bb2
uncommit to avoid bundle failure
ramyananth Mar 31, 2020
49d37a4
Merge branch 'master' of https://github.com/ramyananth/expertiza
ramyananth Mar 31, 2020
a6044f8
removed empty line
ramyananth Mar 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
90 changes: 47 additions & 43 deletions app/controllers/assessment360_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ def all_students_all_reviews
course = Course.find(params[:course_id])
@assignments = course.assignments.reject(&:is_calibrated).reject {|a| a.participants.empty? }
@course_participants = course.get_participants
if @course_participants.empty?
flash[:error] = "There is no course participant in course #{course.name}"
redirect_to(:back)
end
insure_existence_of(@course_participants)
# hashes for view
@meta_review = {}
@teammate_review = {}
Expand Down Expand Up @@ -59,21 +56,28 @@ def all_students_all_reviews
@meta_review_info_per_stu)
end
# calculate average grade for each student on all assignments in this course
if @teammate_review_info_per_stu[1] > 0
temp_avg_grade = @teammate_review_info_per_stu[0] * 1.0 / @teammate_review_info_per_stu[1]
@teammate_review[cp.id][:avg_grade_for_assgt] = temp_avg_grade.round.to_s + '%'
end
if @meta_review_info_per_stu[1] > 0
temp_avg_grade = @meta_review_info_per_stu[0] * 1.0 / @meta_review_info_per_stu[1]
@meta_review[cp.id][:avg_grade_for_assgt] = temp_avg_grade.round.to_s + '%'
end
avg_review_calc_per_student(cp, @teammate_review_info_per_stu, @teammate_review)
avg_review_calc_per_student(cp, @meta_review_info_per_stu, @meta_review)
end
# avoid divide by zero error
@assignments.each do |assignment|
temp_count = @overall_teammate_review_count[assignment.id]
@overall_teammate_review_count[assignment.id] = 1 if temp_count.nil? or temp_count.zero?
temp_count = @overall_meta_review_count[assignment.id]
@overall_meta_review_count[assignment.id] = 1 if temp_count.nil? or temp_count.zero?
overall_review_count(@assignments, @overall_teammate_review_count, @overall_meta_review_count)
end

def overall_review_count(assignments, overall_teammate_review_count, overall_meta_review_count)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method overall_review_count has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

assignments.each do |assignment|
temp_count = overall_teammate_review_count[assignment.id]
overall_review_count_hash = 1 if temp_count.nil? or temp_count.zero?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless assignment to variable - overall_review_count_hash.

temp_count = overall_meta_review_count[assignment.id]
overall_meta_review_count[assignment.id] = 1 if temp_count.nil? or temp_count.zero?
end
end

# Calculate the overall average review grade that a student has gotten from their teammate(s) and instructor(s)
def avg_review_calc_per_student(cp, review_info_per_stu, review)
# Check to see if the student has been given a review
ramyananth marked this conversation as resolved.
Show resolved Hide resolved
if review_info_per_stu[1] > 0
temp_avg_grade = review_info_per_stu[0] * 1.0 / review_info_per_stu[1]
review[cp.id][:avg_grade_for_assgt] = temp_avg_grade.round.to_s + '%'
end
end

Expand All @@ -86,49 +90,49 @@ def course_student_grade_summary
@assignment_grades = {}
@peer_review_scores = {}
@final_grades = {}

course = Course.find(params[:course_id])
@assignments = course.assignments.reject(&:is_calibrated).reject {|a| a.participants.empty? }
@course_participants = course.get_participants
if @course_participants.empty?
flash[:error] = "There is no course participant in course #{course.name}"
redirect_to(:back)
end

insure_existence_of(@course_participants)
@course_participants.each do |cp|
@topics[cp.id] = {}
@assignment_grades[cp.id] = {}
@peer_review_scores[cp.id] = {}
@final_grades[cp.id] = 0

@assignments.each do |assignment|
user_id = cp.user_id
assignment_id = assignment.id

assignment_participant = assignment.participants.find_by(user_id: user_id)
ramyananth marked this conversation as resolved.
Show resolved Hide resolved
# Break out of the loop if there are no participants in the assignment
next if assignment.participants.find_by(user_id: user_id).nil?
# Break out of the loop if the participant has no team
next if TeamsUser.team_id(assignment_id, user_id).nil?
assignment_grade_summary(cp, assignment_id)

# A topic exists if a team signed up for a topic, which can be found via the user and the assignment
topic_id = SignedUpTeam.topic_id(assignment_id, user_id)
@topics[cp.id][assignment_id] = SignUpTopic.find_by(id: topic_id)

# Instructor grade is stored in the team model, which is found by finding the user's team for the assignment
team_id = TeamsUser.team_id(assignment_id, user_id)
next if team_id.nil?

team = Team.find(team_id)
peer_review_score = find_peer_review_score(user_id, assignment_id)
next if peer_review_score.dig(:review, :scores, :avg).nil?
@peer_review_scores[cp.id][assignment_id] = peer_review_score[:review][:scores][:avg].round(2)
end
end
end

# Set the assignment grade, peer review score, and sum for the final student summary
@assignment_grades[cp.id][assignment_id] = team[:grade_for_submission]
unless @assignment_grades[cp.id][assignment_id].nil?
@final_grades[cp.id] += @assignment_grades[cp.id][assignment_id]
end
def assignment_grade_summary(cp, assignment_id)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment Branch Condition size for assignment_grade_summary is too high. [20.27/15]

user_id = cp.user_id
# A topic exists if a team signed up for a topic, which can be found via the user and the assignment
topic_id = SignedUpTeam.topic_id(assignment_id, user_id)
@topics[cp.id][assignment_id] = SignUpTopic.find_by(id: topic_id)
# Instructor grade is stored in the team model, which is found by finding the user's team for the assignment
team_id = TeamsUser.team_id(assignment_id, user_id)
team = Team.find(team_id)
@assignment_grades[cp.id][assignment_id] = team[:grade_for_submission]
return if @assignment_grades[cp.id][assignment_id].nil?
@final_grades[cp.id] += @assignment_grades[cp.id][assignment_id]
end

unless (peer_review_score.nil? || peer_review_score[:review][:scores][:avg].nil?)
@peer_review_scores[cp.id][assignment_id] = peer_review_score[:review][:scores][:avg].round(2)
end
end
def insure_existence_of(course_participants)
if course_participants.empty?
flash[:error] = "There is no course participant in course #{course.name}"
redirect_to(:back)
end
end

Expand Down