Add a simple summary export

This commit is contained in:
Petko Bordjukov 2016-10-10 00:20:20 +03:00
parent b9ad36fa6b
commit 03dfaadb82
4 changed files with 34 additions and 1 deletions

View File

@ -11,4 +11,8 @@ class HomeController < ApplicationController
def export
@talk_preferences = TalkPreference.this_years.eager_load(:selected_talks)
end
def summary
@summary = Summary.new params[:summary]
end
end

23
app/models/summary.rb Normal file
View File

@ -0,0 +1,23 @@
class Summary
def initialize(params = {})
@talk_id, @other_talk_ids = params[:talk_id], params[:other_talk_ids]
@votes_count = SelectedTalk.where(talk_id: @talk_id).count
@all_votes_count = TalkPreference.joins(:selected_talks).where(selected_talks: {talk_id: @other_talk_ids << @talk_id}).count
end
def summary
{
talk_id: @talk_id,
votes: @votes_count,
all_votes: @all_votes_count,
per_cent: Rational(@votes_count, @all_votes_count).to_f,
conflicts: conflicts
}
end
def conflicts
@other_talk_ids.map do |right|
[right, ConflictCoefficient.new(@talk_id, right).conflicts]
end.to_h
end
end

View File

@ -0,0 +1 @@
json.merge! @summary.summary

View File

@ -3,6 +3,11 @@ Rails.application.routes.draw do
root to: 'home#index'
get 'ratings' => 'home#ratings'
get 'export' => 'home#export'
resources :conflicts
get 'summary' => 'home#summary'
resources :conflicts do
collection do
get 'pivot'
end
end
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end