about summary refs log tree commit diff stats
path: root/app/controllers/quotes_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/quotes_controller.rb')
-rw-r--r--app/controllers/quotes_controller.rb76
1 files changed, 76 insertions, 0 deletions
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
47 end 47 end
48 end 48 end
49 49
50 def stats
51 @months = []
52 0.upto(11) do |i|
53 month = i.months.ago.month
54 year = i.months.ago.year
55 beginning = i.months.ago.beginning_of_month.beginning_of_day
56 endtime = i.months.ago.end_of_month.end_of_day
57 quotes = Quote.where("created_at >= :start_date AND created_at <= :end_date", { :start_date => beginning, :end_date => endtime }).all
58 @months[11-i] = { :name => Date::MONTHNAMES[month], :number => quotes.count }
59 end
60
61 #@months2 = []
62 #i = 0
63 #while true
64 # month = i.months.ago.month
65 # year = i.months.ago.year
66 # beginning = i.months.ago.beginning_of_month.beginning_of_day
67 # endtime = i.months.ago.end_of_month.end_of_day
68 # quotes = Quote.where("created_at <= :end_date", { :end_date => endtime }).all
69 # @months2[i] = { :name => i.months.ago.strftime("%Y-%m"), :number => quotes.count }
70 #
71 # break if month == 4 and year == 2008
72 #
73 # i=i+1
74 #end
75 #
76 #@months2.reverse!
77 #
78 #@upvotes = Vote.where(upvote: 1, votable_type: :quote).count
79 #@downvotes = Vote.where(upvote: 0, votable_type: :quote).count
80
81 hardcoded_aliases = {
82 "hatkirby": "Hatkirby",
83 "Gryphic": "Drifty",
84 "DriftyBeyond": "Drifty",
85 "Starla": "Hatkirby",
86 "BleuM937": "Bluemonkey",
87 "BlueM937": "Bluemonkey",
88 "Drifty1": "Drifty",
89 "Starla Insigna": "Hatkirby",
90 "Starla Alice Insigna": "Hatkirby",
91 "tamasys": "Tamasys",
92 "Student 2": "Student",
93 "Старла Эппрет": "Hatkirby",
94 "Girl Without Slipper": "Hatkirby",
95 "Actias": "Drifty",
96 "Salaboy123": "Tamasys",
97 "TaMACsys": "Tamasys",
98 "RealityCheck": "Drifty",
99 "Student 3": "Student"
100 }
101
102 person_count = {}
103 Quote.all.each do |quote|
104 person_in_quote = {}
105
106 quote.content.split("\n").each do |line|
107 check = line.chomp
108 hi = /([\(\[][^\]\)]*[\]\)] )?([^:]*): /.match(check)
109 if hi and hi[2] then
110 person = hi[2]
111 if hardcoded_aliases.has_key? person.intern
112 person = hardcoded_aliases[person.intern]
113 end
114 unless person_in_quote.has_key? person
115 person_count[person] ||= 0
116 person_count[person] += 1
117 person_in_quote[person] = 1
118 end
119 end
120 end
121 end
122
123 @by_speaker = person_count.to_a.sort_by {|hi| hi[1]}.reverse.take(20)
124 end
125
50 def show 126 def show
51 @quote = Quote.published.find(params[:id]) 127 @quote = Quote.published.find(params[:id])
52 128