-
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 all 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 |
---|---|---|
|
@@ -211,4 +211,4 @@ pg_data | |
.ruby-version | ||
mysql2psql.yml | ||
*.pem | ||
t.csv | ||
t.csv |
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 |
---|---|---|
|
@@ -665,4 +665,4 @@ DEPENDENCIES | |
zip-zip | ||
|
||
BUNDLED WITH | ||
1.16.2 | ||
2.1.4 |
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 = {} | ||
|
@@ -43,37 +40,44 @@ def all_students_all_reviews | |
next if assignment_participant.nil? | ||
teammate_reviews = assignment_participant.teammate_reviews | ||
meta_reviews = assignment_participant.metareviews | ||
populate_hash_for_all_students_all_reviews(assignment, | ||
cp, | ||
teammate_reviews, | ||
@teammate_review, | ||
@overall_teammate_review_grades, | ||
@overall_teammate_review_count, | ||
@teammate_review_info_per_stu) | ||
populate_hash_for_all_students_all_reviews(assignment, | ||
cp, | ||
meta_reviews, | ||
@meta_review, | ||
@overall_meta_review_grades, | ||
@overall_meta_review_count, | ||
@meta_review_info_per_stu) | ||
calc_overall_review_info(assignment, | ||
cp, | ||
teammate_reviews, | ||
@teammate_review, | ||
@overall_teammate_review_grades, | ||
@overall_teammate_review_count, | ||
@teammate_review_info_per_stu) | ||
calc_overall_review_info(assignment, | ||
cp, | ||
meta_reviews, | ||
@meta_review, | ||
@overall_meta_review_grades, | ||
@overall_meta_review_count, | ||
@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[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? | ||
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 | ||
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,67 +90,74 @@ 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? | ||
|
||
# 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) | ||
# break out of the loop if the participant has no team | ||
next if TeamsUser.team_id(assignment_id, user_id).nil? | ||
# pull information about the student's grades for particular assignment | ||
assignment_grade_summary(cp, assignment_id) | ||
peer_review_score = find_peer_review_score(user_id, assignment_id) | ||
next if (peer_review_score[:review] && peer_review_score[:review][:scores] && peer_review_score[: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 | ||
# 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 | ||
|
||
def populate_hash_for_all_students_all_reviews(assignment, | ||
course_participant, | ||
reviews, | ||
hash_per_stu, | ||
overall_review_grade_hash, | ||
overall_review_count_hash, | ||
review_info_per_stu) | ||
# The function populates the hash value for all students for all the reviews that they have gotten. | ||
# I.e., Teammate and Meta for each of the assignments that they have taken | ||
# This value is then used to display the overall teammate_review and meta_review grade in the view | ||
def calc_overall_review_info(assignment, | ||
course_participant, | ||
reviews, | ||
hash_per_stu, | ||
overall_review_grade_hash, | ||
overall_review_count_hash, | ||
review_info_per_stu) | ||
# If a student has not taken an assignment or if they have not received any grade for the same, | ||
# assign it as 0 instead of leaving it blank. This helps in easier calculation of overall grade | ||
overall_review_grade_hash[assignment.id] = 0 unless overall_review_grade_hash.key?(assignment.id) | ||
overall_review_count_hash[assignment.id] = 0 unless overall_review_count_hash.key?(assignment.id) | ||
grades = 0 | ||
# Check if they person has gotten any review for the assignment | ||
if reviews.count > 0 | ||
reviews.each {|review| grades += review.average_score.to_i } | ||
avg_grades = (grades * 1.0 / reviews.count).round | ||
hash_per_stu[course_participant.id][assignment.id] = avg_grades.to_s + '%' | ||
end | ||
# Calculate sum of averages to get student's overall grade | ||
if avg_grades and grades > 0 | ||
# for each assignment | ||
review_info_per_stu[0] += avg_grades | ||
|
@@ -162,7 +173,6 @@ def find_peer_review_score(user_id, assignment_id) | |
participant = AssignmentParticipant.find_by(user_id: user_id, parent_id: assignment_id) | ||
assignment = participant.assignment | ||
questions = retrieve_questions assignment.questionnaires, assignment_id | ||
|
||
participant.scores(questions) | ||
end | ||
|
||
|
@@ -176,4 +186,4 @@ def format_score(score) | |
|
||
helper_method :format_score | ||
helper_method :format_topic | ||
end | ||
end |
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
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.