api stint

This commit is contained in:
Petko Bordjukov 2016-10-10 20:20:56 +03:00
parent 59046a7b2b
commit 98395a4fbe
8 changed files with 53 additions and 2 deletions

View File

@ -26,3 +26,7 @@
.friend:hover {
background: #AFDDFF !important;
}
tr.rating:hover {
background-color: green;
}

View File

@ -2,4 +2,12 @@ class ConflictsController < ApplicationController
def index
@talks = Talk.ordered_by_rating
end
def show
end
def pivot
@talks = Talk.ordered_by_id
@conflict_coefficients = ConflictCoefficient.all
end
end

View File

@ -0,0 +1,17 @@
class ConferenceSummary
def initialize(params = {})
@talk_ids = params[:talk_ids]
end
def number_of_ballots
TalkPreference.joins(:selected_talks)
.where(selected_talks: {
talk_id: @talk_ids
})
.uniq.count
end
def ratings
end
end

View File

@ -18,6 +18,6 @@ class Summary
def conflicts
@other_talk_ids.map do |right|
[right, ConflictCoefficient.new(@talk_id, right).conflicts]
end.to_h
end.sort_by(&:last).to_h
end
end

View File

@ -4,6 +4,10 @@ class Talk < ActiveResource::Base
self.site = "https://cfp.openfest.org/api/conferences/3"
self.element_name = "event"
def self.ordered_by_id
find(:all, from: :halfnarp_friendly).sort_by(&:id)
end
def self.ordered_by_rating
ratings = Ratings.new
find(:all, from: :halfnarp_friendly).sort { |left, right| ratings[right.id] <=> ratings[left.id] }

View File

@ -0,0 +1,5 @@
<%- headers = ['left', 'right', 'conflicts', '%'] -%>
<%= CSV.generate_line headers -%>
<%- @conflict_coefficients.each do |conflict_coefficient| -%>
<%= CSV.generate_line([conflict_coefficient.left, conflict_coefficient.right, conflict_coefficient.conflicts, conflict_coefficient.per_cent]).html_safe -%>
<%- end -%>

View File

@ -0,0 +1,13 @@
<table>
<thead>
<tr>
<th>Event</th>
<% @talks.each |talk| do %>
<th><%= talk.title %> (<%= talk.id %>)</th>
<% end %>
</tr>
</thead>
<tbody>
<%= render partial: 'conflict_coefficient', collection: @conflict_coefficients %>
</tbody>
</table>

View File

@ -11,7 +11,7 @@
</thead>
<tbody>
<% @talks.each do |talk| %>
<tr>
<tr class="rating">
<td><%= talk.id %></td>
<td><%= talk.event_type.name %></td>
<td><%= talk.title %></td>