Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

GH#6 number of shows data point limits only apply on the main page graph

  • Loading branch information...
commit 4758b9fa69a69545936c2373dd097e7477618003 1 parent 176eff6
@tardate authored
View
3  app/controllers/memes_controller.rb
@@ -6,7 +6,8 @@ class MemesController < InheritedResources::Base
include Navd::Chartable
def stats
- render :json => to_chartable_structure(Meme.stats_over_time,Meme::STAT_CHART_TEMPLATE).to_json
+ over_all_time = !(params[:over_all_time] && params[:over_all_time] =~ /^f/i)
+ render :json => to_chartable_structure(Meme.stats_over_time(nil,over_all_time),Meme::STAT_CHART_TEMPLATE).to_json
end
def stat
View
15 app/models/meme.rb
@@ -10,14 +10,13 @@ class Meme < ActiveRecord::Base
unscoped.where(Meme.arel_table[:id].in(topn_arel(limit)))
}
- scope :stats_over_time, lambda { |meme_id=nil|
- unscoped.
- select("memes.name AS meme_name, shows.number as number, count(notes.id) as note_count").
- joins(:shows).
- where(Meme.arel_table[:id].in((meme_id ? meme_id : topn_arel))).
- where(Show.arel_table[:id].in(Show.shows_for_trending_history_arel)).
- group(:"memes.name", :"shows.number").
- reorder('memes.name, shows.number')
+ scope :stats_over_time, lambda { |meme_id=nil,over_all_time=true|
+ query = unscoped.
+ select("memes.name AS meme_name, shows.number as number, count(notes.id) as note_count").
+ joins(:shows).
+ where(Meme.arel_table[:id].in((meme_id ? meme_id : topn_arel)))
+ query = query.where(Show.arel_table[:id].in(Show.shows_for_trending_history_arel)) unless over_all_time
+ query.group(:"memes.name", :"shows.number").reorder('memes.name, shows.number')
}
# Gets the stats over time for the current meme
View
2  app/views/memes/_top.html.haml
@@ -1,3 +1,3 @@
.chart-container.main
%h2= t('stats.top_memes.title', :n => AppConstants.number_of_trending_memes)
- .chart{ 'data-url' => stats_memes_url(:format => 'json'), 'data-template' => 'line_basic_with_legend' }
+ .chart{ 'data-url' => stats_memes_url(:format => 'json',:over_all_time=>'false'), 'data-template' => 'line_basic_with_legend' }
View
2  spec/models/meme/stats_spec.rb
@@ -57,7 +57,7 @@
context "with trending history limit" do
let(:trending_history_limit) { AppConstants.number_of_shows_for_trending_history || 10 }
- subject { Meme.stats_over_time }
+ subject { Meme.stats_over_time(nil,false) }
its(:to_sql) { should include( %("shows"."id" IN (SELECT "shows"."id" FROM "shows" ORDER BY "shows"."number" DESC LIMIT #{trending_history_limit})) ) }
end
Please sign in to comment.
Something went wrong with that request. Please try again.