lib/papercall/analysis.rb in papercall-0.15.2 vs lib/papercall/analysis.rb in papercall-1.0.0

- old
+ new

@@ -1,103 +1,142 @@ module Papercall class Analysis + attr_reader :submissions, + :reviewers, + :talks_without_reviews, + :talks_missing_reviews, + :talks_with_many_reviews, + :talks_without_feedback, + :highly_rated, + :low_rated, + :maybe, + :accepted, + :waitlisted, + :rejected, + :confirmed, + :summary + def initialize submissions - @analysis = {} - @analysis['submissions'] = submissions - @analysis['reviewers'] = {} - @analysis['talksWithoutReviews'] = [] - @analysis['talksWithLessThanThreeReviews'] = [] - @analysis['talksWithFourOrMoreReviews'] = [] - @analysis['talksWithoutFeedback'] = [] - @analysis['highlyRated'] = [] - @analysis['lowRated'] = [] - @analysis['maybe'] = [] - @analysis['accepted'] = [] - @analysis['waitlist'] = [] - @analysis['rejected'] = [] - @analysis['confirmed'] = [] + @output = Papercall.configuration.output + @submissions = submissions + @reviewers = {} + @talks_without_reviews = [] + @talks_missing_reviews = [] + @talks_with_many_reviews = [] + @talks_without_feedback = [] + @highly_rated = [] + @low_rated = [] + @maybe = [] + @accepted = [] + @waitlisted = [] + @rejected = [] + @confirmed = [] + analyze end - def analyze - start_time = Time.now - print 'Performing analysis...' - @analysis['submissions'].each do |submission| - submission['ratings'].each do |rating| - if !(@analysis['reviewers'].include? rating['user']['name']) - @analysis['reviewers'][rating['user']['name']] = [{ id: rating['submission_id'] }] - else - @analysis['reviewers'][rating['user']['name']] << { id: rating['submission_id'] } - end - end - @analysis['talksWithoutReviews'] << { id: submission['id'], submission: submission } if submission['ratings'].empty? - @analysis['talksWithFourOrMoreReviews'] << { id: submission['id'], submission: submission } if submission['ratings'].size >= 4 - @analysis['talksWithLessThanThreeReviews'] << { id: submission['id'], submission: submission } if submission['ratings'].size < 3 - @analysis['talksWithoutFeedback'] << { id: submission['id'], submission: submission } if submission['feedback'].empty? - @analysis['highlyRated'] << { id: submission['id'], submission: submission } if highly_rated? submission - @analysis['lowRated'] << { id: submission['id'], submission: submission } if low_rated? submission - @analysis['maybe'] << { id: submission['id'], submission: submission } if maybe? submission - @analysis['accepted'] << { id: submission['id'], submission: submission } if accepted? submission - @analysis['waitlist'] << { id: submission['id'], submission: submission } if waitlisted? submission - @analysis['rejected'] << { id: submission['id'], submission: submission } if rejected? submission - @analysis['confirmed'] << { id: submission['id'], submission: submission } if confirmed? submission - end - @analysis['summary'] = summary - puts "finished in #{Time.now - start_time} seconds." - @analysis + def number_of_submissions + @submissions.size end - private + def number_of_active_reviewers + @reviewers.size + end - def highly_rated?(submission) - submission['rating'] >= 75 && review_complete?(submission) + def number_without_feedback + @talks_without_feedback.size end - def low_rated?(submission) - submission['rating'] <= 25 && review_complete?(submission) + def number_completed + @submissions.size - @talks_missing_reviews.size end - def maybe?(submission) - !accepted?(submission) && - !rejected?(submission) && - review_complete?(submission) + def number_of_highly_rated + @highly_rated.size end - def review_complete?(submission) - submission['ratings'].size >= 3 + def number_of_low_rated + @low_rated.size end - def accepted?(submission) - submission['state'] == 'accepted' + def number_of_maybes + @maybe.size end - def rejected?(submission) - submission['state'] == 'rejected' + def number_with_few_reviews + @talks_missing_reviews.size end - def waitlisted?(submission) - submission['state'] == 'waitlist' + def number_with_many_reviews + @talks_with_many_reviews.size end - def confirmed?(submission) - accepted?(submission) && submission['confirmed'] == true + def number_without_reviews + @talks_without_reviews.size end - def summary + def number_accepted + @accepted.size + end + + def number_of_waitlisted + @waitlisted.size + end + + def number_rejected + @rejected.size + end + + def number_confirmed + @confirmed.size + end + + + private + + def analyze + start_time = Time.now + print 'Performing analysis...' if @output + @submissions.each do |submission| + submission.ratings.each do |rating| + if !(@reviewers.include? rating.user.name) + @reviewers[rating.user.name] = [{ id: rating.submission_id }] + else + @reviewers[rating.user.name] << { id: rating.submission_id } + end + end + @talks_without_reviews << { id: submission.id, submission: submission } if submission.no_reviews? + @talks_with_many_reviews << { id: submission.id, submission: submission } if submission.too_many_reviews? + @talks_missing_reviews << {id: submission.id, submission: submission} unless submission.enough_reviews? + @talks_without_feedback << { id: submission.id, submission: submission } if submission.no_feedback? + @highly_rated << { id: submission.id, submission: submission } if submission.highly_rated? + @low_rated << { id: submission.id, submission: submission } if submission.low_rated? + @maybe << { id: submission.id, submission: submission } if submission.maybe? + @accepted << { id: submission.id, submission: submission } if submission.accepted? + @waitlisted << { id: submission.id, submission: submission } if submission.waitlisted? + @rejected << { id: submission.id, submission: submission } if submission.rejected? + @confirmed << { id: submission.id, submission: submission } if submission.confirmed? + end + @summary = build_summary + puts "finished in #{Time.now - start_time} seconds." if @output + end + + def build_summary summary = {} - summary['numSubmissions'] = @analysis['submissions'].size - summary['numActiveReviewers'] = @analysis['reviewers'].size - summary['numWithoutFeedback'] = @analysis['talksWithoutFeedback'].size - summary['numCompleted'] = @analysis['submissions'].size - @analysis['talksWithLessThanThreeReviews'].size - summary['numHighlyRated'] = @analysis['highlyRated'].size - summary['numLowRated'] = @analysis['lowRated'].size - summary['numMaybe'] = @analysis['maybe'].size - summary['numLessThanThreeReviews'] = @analysis['talksWithLessThanThreeReviews'].size - summary['numWithFourOrMoreReviews'] = @analysis['talksWithFourOrMoreReviews'].size - summary['numWithoutReviews'] = @analysis['talksWithoutReviews'].size - summary['numAccepted'] = @analysis['accepted'].size - summary['numWaitlisted'] = @analysis['waitlist'].size - summary['numRejected'] = @analysis['rejected'].size - summary['numConfirmed'] = @analysis['confirmed'].size + summary['numSubmissions'] = @submissions.size + summary['numActiveReviewers'] = @reviewers.size + summary['numWithoutFeedback'] = @talks_without_feedback.size + summary['numCompleted'] = @submissions.size - @talks_missing_reviews.size + summary['numHighlyRated'] = @highly_rated.size + summary['numLowRated'] = @low_rated.size + summary['numMaybe'] = @maybe.size + summary['numLessThanThreeReviews'] = @talks_missing_reviews.size + summary['numWithFourOrMoreReviews'] = @talks_with_many_reviews.size + summary['numWithoutReviews'] = @talks_without_reviews.size + summary['numAccepted'] = @accepted.size + summary['numWaitlisted'] = @waitlisted.size + summary['numRejected'] = @rejected.size + summary['numConfirmed'] = @confirmed.size summary end + end end