-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
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 829d37f
refactored similar blocks, reduced cyclomatic and perceived complexit…
ramyananth b47c529
refactored similar blocks, reduced cyclomatic and perceived complexit…
ramyananth dd5994b
added space after comma, removed extra space
ramyananth c7d3b67
removed trailing white spaces
ramyananth 48ecd75
using guard clause instead of wrapping code
ramyananth a732509
fixed non-local exit from iterator
ramyananth 3dbf320
changed function names to more meaningful ones
ramyananth 326a7ae
rename review_info_per_stu to avg_review_calc_per_stu
ramyananth 1df1e0e
reduced number of parameters being passed
ramyananth 4dc72f3
added comments for all functions - easier understanding_
ramyananth 192a957
removed trailing whitespaces from comments
ramyananth 2b00478
Renamed populate_hash_function,fixed the overal_review_count_hash
ushvarma a4345fa
Replace dig function with a hash check
ushvarma 56ecccc
Delete Gemfile.lock
ramyananth 0527b89
modify to not push gemfile.lock
ramyananth c05bd4c
push gemfile.lock
ramyananth 6273bb2
uncommit to avoid bundle failure
ramyananth 49d37a4
Merge branch 'master' of https://github.com/ramyananth/expertiza
ramyananth a6044f8
removed empty line
ramyananth File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = {} | ||
|
@@ -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) | ||
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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useless assignment to variable - |
||
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 | ||
|
||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.