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
Show file tree
Hide file tree
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 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,4 @@ pg_data
.ruby-version
mysql2psql.yml
*.pem
t.csv
t.csv
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,4 @@ DEPENDENCIES
zip-zip

BUNDLED WITH
1.16.2
2.1.4
144 changes: 77 additions & 67 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 All @@ -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)
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[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

Expand All @@ -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)
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
# 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
Expand All @@ -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

Expand All @@ -176,4 +186,4 @@ def format_score(score)

helper_method :format_score
helper_method :format_topic
end
end
12 changes: 7 additions & 5 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -715,14 +715,14 @@
add_index "teams_users", ["user_id"], name: "fk_teams_users", using: :btree

create_table "track_notifications", force: :cascade do |t|
t.integer "notification_id", limit: 4
t.integer "user_id", limit: 4
t.datetime "created_at"
t.datetime "updated_at"
t.integer "notification_id", limit: 4, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "track_notifications", ["notification_id"], name: "notification_id", using: :btree
add_index "track_notifications", ["user_id"], name: "user_id", using: :btree
add_index "track_notifications", ["notification_id"], name: "index_track_notifications_on_notification_id", using: :btree
add_index "track_notifications", ["user_id"], name: "index_track_notifications_on_user_id", using: :btree

create_table "tree_folders", force: :cascade do |t|
t.string "name", limit: 255
Expand Down Expand Up @@ -816,4 +816,6 @@
add_foreign_key "tag_prompt_deployments", "tag_prompts"
add_foreign_key "teams_users", "teams", name: "fk_users_teams"
add_foreign_key "teams_users", "users", name: "fk_teams_users"
add_foreign_key "track_notifications", "notifications"
add_foreign_key "track_notifications", "users"
end