-
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
Refactor on_the_fly_calc #2039
Refactor on_the_fly_calc #2039
Changes from 5 commits
d1d6cb7
9124fdf
3ea9c48
edf17fb
e73e5d4
6a195c7
9f18f67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,4 +99,103 @@ def get_team_name_color_in_list_submission(team) | |
end | ||
end | ||
|
||
# Compute total score for this assignment by summing the scores given on all questionnaires. | ||
# Only scores passed in are included in this sum. | ||
def compute_total_score(scores) | ||
total = 0 | ||
self.questionnaires.each {|questionnaire| total += questionnaire.get_weighted_score(self, scores) } | ||
total | ||
end | ||
|
||
def compute_reviews_hash | ||
@review_scores = {} | ||
@response_type = 'ReviewResponseMap' | ||
@response_maps = ResponseMap.where(reviewed_object_id: self.id, type: @response_type) | ||
if self.vary_by_round | ||
scores_varying_rubrics | ||
else | ||
scores_non_varying_rubrics | ||
end | ||
@review_scores | ||
end | ||
|
||
# calculate the avg score and score range for each reviewee(team), only for peer-review | ||
def compute_avg_and_ranges_hash | ||
scores = {} | ||
contributors = self.contributors # assignment_teams | ||
if self.vary_by_round | ||
rounds = self.rounds_of_reviews | ||
(1..rounds).each do |round| | ||
contributors.each do |contributor| | ||
questions = peer_review_questions_for_team(contributor, round) | ||
assessments = ReviewResponseMap.assessments_for(contributor) | ||
assessments = assessments.select {|assessment| assessment.round == round } | ||
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. use select!{ |assessment| assessment.round == round} |
||
scores[contributor.id] = {} if round == 1 | ||
scores[contributor.id][round] = {} | ||
scores[contributor.id][round] = Response.compute_scores(assessments, questions) | ||
end | ||
end | ||
else | ||
contributors.each do |contributor| | ||
questions = peer_review_questions_for_team(contributor) | ||
assessments = ReviewResponseMap.assessments_for(contributor) | ||
scores[contributor.id] = {} | ||
scores[contributor.id] = Response.compute_scores(assessments, questions) | ||
end | ||
end | ||
scores | ||
end | ||
|
||
end | ||
|
||
private | ||
|
||
# Get all of the questions asked during peer review for the given team's work | ||
def peer_review_questions_for_team(team, round_number = nil) | ||
topic_id = SignedUpTeam.find_by(team_id: team.id).topic_id unless team.nil? or SignedUpTeam.find_by(team_id: team.id).nil? | ||
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. these are literally the same checks so just clean this up |
||
review_questionnaire_id = review_questionnaire_id(round_number, topic_id) unless team.nil? or SignedUpTeam.find_by(team_id: team.id).nil? | ||
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. use || instead of or |
||
Question.where(questionnaire_id: review_questionnaire_id) unless team.nil? or SignedUpTeam.find_by(team_id: team.id).nil? | ||
end | ||
|
||
def calc_review_score | ||
unless @corresponding_response.empty? | ||
@this_review_score_raw = Response.assessment_score(response: @corresponding_response, questions: @questions) | ||
if @this_review_score_raw | ||
@this_review_score = ((@this_review_score_raw * 100) / 100.0).round if @this_review_score_raw >= 0.0 | ||
end | ||
else | ||
@this_review_score = -1.0 | ||
johnbumgardner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end | ||
|
||
def scores_varying_rubrics | ||
rounds = self.rounds_of_reviews | ||
(1..rounds).each do |round| | ||
@response_maps.each do |response_map| | ||
@questions = peer_review_questions_for_team(response_map.reviewee, round) | ||
reviewer = @review_scores[response_map.reviewer_id] | ||
@corresponding_response = Response.where('map_id = ?', response_map.id) | ||
@corresponding_response = @corresponding_response.select {|response| response.round == round } unless @corresponding_response.empty? | ||
@respective_scores = {} | ||
@respective_scores = reviewer[round] unless reviewer.nil? || reviewer[round].nil? | ||
calc_review_score | ||
@respective_scores[response_map.reviewee_id] = @this_review_score | ||
reviewer = {} if reviewer.nil? | ||
reviewer[round] = {} if reviewer[round].nil? | ||
reviewer[round] = @respective_scores | ||
end | ||
end | ||
end | ||
|
||
def scores_non_varying_rubrics | ||
@response_maps.each do |response_map| | ||
@questions = peer_review_questions_for_team(response_map.reviewee) | ||
reviewer = @review_scores[response_map.reviewer_id] | ||
@corresponding_response = Response.where('map_id = ?', response_map.id) | ||
@respective_scores = {} | ||
@respective_scores = reviewer unless reviewer.nil? | ||
calc_review_score | ||
@respective_scores[response_map.reviewee_id] = @this_review_score | ||
@review_scores[response_map.reviewer_id] = @respective_scores | ||
end | ||
end |
This file was deleted.
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.
why are these being passed as instance variables, can you refactor all of this into using parameters