about summary refs log tree commit diff stats
path: root/app
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-10-21 16:22:01 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-10-21 16:22:01 -0400
commita9a078a7f4a7a0a9c4e57c02f66722f4d6c1cec6 (patch)
treeca97ab63790afd99bd5f24da4e3aa2fe026a0a6f /app
parent491783a28a26739062f5cda29a028bd1166617cb (diff)
downloadthoughts-a9a078a7f4a7a0a9c4e57c02f66722f4d6c1cec6.tar.gz
thoughts-a9a078a7f4a7a0a9c4e57c02f66722f4d6c1cec6.tar.bz2
thoughts-a9a078a7f4a7a0a9c4e57c02f66722f4d6c1cec6.zip
Added quotes stats page
Diffstat (limited to 'app')
-rw-r--r--app/controllers/quotes_controller.rb76
-rw-r--r--app/views/layouts/quotes.html.haml1
-rw-r--r--app/views/quotes/stats.html.haml41
3 files changed, 118 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
diff --git a/app/views/layouts/quotes.html.haml b/app/views/layouts/quotes.html.haml index 68607f6..f42eee0 100644 --- a/app/views/layouts/quotes.html.haml +++ b/app/views/layouts/quotes.html.haml
@@ -23,6 +23,7 @@
23 - if user_signed_in? 23 - if user_signed_in?
24 %li= link_to_unless_current "Submit", new_quote_url 24 %li= link_to_unless_current "Submit", new_quote_url
25 %li= link_to_unless_current "Tags", tags_quotes_url 25 %li= link_to_unless_current "Tags", tags_quotes_url
26 %li= link_to_unless_current "Stats", stats_quotes_url
26 %li= link_to_unless_current "Feed", latest_quotes_url(:atom) 27 %li= link_to_unless_current "Feed", latest_quotes_url(:atom)
27 .cleardiv 28 .cleardiv
28 #page-body 29 #page-body
diff --git a/app/views/quotes/stats.html.haml b/app/views/quotes/stats.html.haml new file mode 100644 index 0000000..d7a8140 --- /dev/null +++ b/app/views/quotes/stats.html.haml
@@ -0,0 +1,41 @@
1%script{ :type => "text/javascript", :src => "https://www.gstatic.com/charts/loader.js" }
2%script{ :type => "text/javascript" }
3 google.charts.load('visualization', '1.0', {'packages':['corechart']});
4 google.charts.setOnLoadCallback(drawChart);
5 function drawChart()
6 {
7 var data = new google.visualization.DataTable();
8 data.addColumn('string', 'Month');
9 data.addColumn('number', 'Quotes Submitted');
10 data.addRows([
11 - @months.each do |month|
12 ['#{month[:name]}', #{month[:number]}],
13 ]);
14 var options = {'title':'Quotes Submitted in the Last 12 Months', 'width':1000, 'height':500, 'legend':'none', 'hAxis.maxAlternation':1};
15 var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
16 chart.draw(data, options);
17 //var data2 = new google.visualization.DataTable();
18 //data2.addColumn('string', 'Month');
19 //data2.addColumn('number', 'Quotes');
20 //data2.addRows([
21 //- @months2.each do |month|
22 // ['\#{month[:name]}', \#{month[:number]}],
23 //]);
24 //var options2 = {'title':'Number of Quotes', 'width':1000, 'height':500, 'legend':'none', 'hAxis.maxAlternation':1};
25 //var chart2 = new google.visualization.AreaChart(document.getElementById('chart2_div'));
26 //chart2.draw(data2, options2);
27 var data3 = new google.visualization.DataTable();
28 data3.addColumn('string', 'Speaker');
29 data3.addColumn('number', 'Quotes');
30 data3.addRows([
31 - @by_speaker.each do |speaker|
32 ['#{speaker[0]}', #{speaker[1]}],
33 ]);
34 var options3 = {'title':'Number of Quotes per Speaker', 'width':1000, 'height':500};
35 var chart3 = new google.visualization.ColumnChart(document.getElementById('chart3_div'));
36 chart3.draw(data3, options3);
37 }
38%p.normal Because charts are fun, we've compiled a few charts here containing statistics about the Four Island Quotes DB.
39#chart2_div
40#chart_div
41#chart3_div