Rudimentary export
This commit is contained in:
parent
5cc4a043aa
commit
420a42bdb1
|
@ -1,3 +1,5 @@
|
|||
require 'csv'
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
class HomeController < ApplicationController
|
||||
def index
|
||||
end
|
||||
|
||||
def ratings
|
||||
@talks = Talk.ordered_by_rating
|
||||
@ratings = Ratings.new
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
class Ratings
|
||||
@ratings = Hash.new(0)
|
||||
|
||||
def initialize
|
||||
ratings = TalkPreference.all.pluck(:talks).reduce(Hash.new(0)) do |result, talks|
|
||||
talks.map(&:to_i).each { |talk| result[talk] += 1 }
|
||||
result
|
||||
end.to_h
|
||||
|
||||
@ratings = Hash.new(0).merge!(ratings)
|
||||
end
|
||||
|
||||
def [](id)
|
||||
@ratings[id]
|
||||
end
|
||||
end
|
|
@ -1,4 +1,9 @@
|
|||
class Talk < ActiveResource::Base
|
||||
self.site = "https://cfp.openfest.org/api/conferences/2"
|
||||
self.element_name = "event"
|
||||
|
||||
def self.ordered_by_rating
|
||||
ratings = Ratings.new
|
||||
all.sort { |left, right| ratings[right.id] <=> ratings[left.id] }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<%= CSV.generate_line([talk.id, talk.event_type.name, talk.title, talk.subtitle, @ratings[talk.id]]).html_safe -%>
|
|
@ -0,0 +1,3 @@
|
|||
<%- headers = ['ID', 'Type', 'Title', 'Subtitle', 'Votes'] -%>
|
||||
<%= CSV.generate_line headers -%>
|
||||
<%= render partial: 'talk', collection: @talks %>
|
|
@ -1,4 +1,5 @@
|
|||
Rails.application.routes.draw do
|
||||
resources :talk_preferences, only: [:index, :show, :create, :update]
|
||||
root to: 'home#index'
|
||||
get 'ratings' => 'home#ratings'
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue