From a9a078a7f4a7a0a9c4e57c02f66722f4d6c1cec6 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 21 Oct 2023 16:22:01 -0400 Subject: Added quotes stats page --- app/controllers/quotes_controller.rb | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'app/controllers/quotes_controller.rb') diff --git a/app/controllers/quotes_controller.rb b/app/controllers/quotes_controller.rb index be931a0..92a424e 100644 --- a/app/controllers/quotes_controller.rb +++ b/app/controllers/quotes_controller.rb @@ -47,6 +47,82 @@ class QuotesController < ApplicationController end end + def stats + @months = [] + 0.upto(11) do |i| + month = i.months.ago.month + year = i.months.ago.year + beginning = i.months.ago.beginning_of_month.beginning_of_day + endtime = i.months.ago.end_of_month.end_of_day + quotes = Quote.where("created_at >= :start_date AND created_at <= :end_date", { :start_date => beginning, :end_date => endtime }).all + @months[11-i] = { :name => Date::MONTHNAMES[month], :number => quotes.count } + end + + #@months2 = [] + #i = 0 + #while true + # month = i.months.ago.month + # year = i.months.ago.year + # beginning = i.months.ago.beginning_of_month.beginning_of_day + # endtime = i.months.ago.end_of_month.end_of_day + # quotes = Quote.where("created_at <= :end_date", { :end_date => endtime }).all + # @months2[i] = { :name => i.months.ago.strftime("%Y-%m"), :number => quotes.count } + # + # break if month == 4 and year == 2008 + # + # i=i+1 + #end + # + #@months2.reverse! + # + #@upvotes = Vote.where(upvote: 1, votable_type: :quote).count + #@downvotes = Vote.where(upvote: 0, votable_type: :quote).count + + hardcoded_aliases = { + "hatkirby": "Hatkirby", + "Gryphic": "Drifty", + "DriftyBeyond": "Drifty", + "Starla": "Hatkirby", + "BleuM937": "Bluemonkey", + "BlueM937": "Bluemonkey", + "Drifty1": "Drifty", + "Starla Insigna": "Hatkirby", + "Starla Alice Insigna": "Hatkirby", + "tamasys": "Tamasys", + "Student 2": "Student", + "Старла Эппрет": "Hatkirby", + "Girl Without Slipper": "Hatkirby", + "Actias": "Drifty", + "Salaboy123": "Tamasys", + "TaMACsys": "Tamasys", + "RealityCheck": "Drifty", + "Student 3": "Student" + } + + person_count = {} + Quote.all.each do |quote| + person_in_quote = {} + + quote.content.split("\n").each do |line| + check = line.chomp + hi = /([\(\[][^\]\)]*[\]\)] )?([^:]*): /.match(check) + if hi and hi[2] then + person = hi[2] + if hardcoded_aliases.has_key? person.intern + person = hardcoded_aliases[person.intern] + end + unless person_in_quote.has_key? person + person_count[person] ||= 0 + person_count[person] += 1 + person_in_quote[person] = 1 + end + end + end + end + + @by_speaker = person_count.to_a.sort_by {|hi| hi[1]}.reverse.take(20) + end + def show @quote = Quote.published.find(params[:id]) -- cgit 1.4.1