From d603ff818cfab39ab32ec6ab244c9ea513b5136c Mon Sep 17 00:00:00 2001 From: Jannik Streek Date: Thu, 20 Feb 2014 21:55:01 +0100 Subject: [PATCH] added comment count to statistic to calculate posts/comments ratios fixeds tests for comment count in statistics added changelog entry and default entry --- Changelog.md | 1 + app/presenters/statistics_presenter.rb | 7 +++++++ config/defaults.yml | 1 + config/diaspora.yml.example | 1 + spec/presenters/statistics_presenter_spec.rb | 7 +++++-- 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index ee95b50dc..8f797bc7d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -17,6 +17,7 @@ * Do not add a space after adding a mention [#4767](https://github.com/diaspora/diaspora/issues/4767) ## Features +* Added comment count to statistic to enable calculations of posts/comments ratios [#4799](https://github.com/diaspora/diaspora/pull/4799) * You can report a single post by clicking the correct icon in the controler section [#4517](https://github.com/diaspora/diaspora/pull/4517) * Add permalinks for comments [#4577](https://github.com/diaspora/diaspora/pull/4577) * New menu for the mobile version [#4673](https://github.com/diaspora/diaspora/pull/4673) diff --git a/app/presenters/statistics_presenter.rb b/app/presenters/statistics_presenter.rb index b39e07768..88f378c78 100644 --- a/app/presenters/statistics_presenter.rb +++ b/app/presenters/statistics_presenter.rb @@ -14,11 +14,18 @@ class StatisticsPresenter if AppConfig.privacy.statistics.post_counts? result['local_posts'] = self.local_posts end + if AppConfig.privacy.statistics.comment_counts? + result['local_comments'] = self.local_comments + end result end def local_posts Post.where(:type => "StatusMessage").joins(:author).where("owner_id IS NOT null").count end + + def local_comments + Comment.joins(:author).where("owner_id IS NOT null").count + end end diff --git a/config/defaults.yml b/config/defaults.yml index 42a890b3d..ccfd26341 100644 --- a/config/defaults.yml +++ b/config/defaults.yml @@ -52,6 +52,7 @@ defaults: statistics: user_counts: false post_counts: false + comment_counts: false settings: pod_name: 'diaspora*' enable_registrations: true diff --git a/config/diaspora.yml.example b/config/diaspora.yml.example index 0abb50fa3..74066d09e 100644 --- a/config/diaspora.yml.example +++ b/config/diaspora.yml.example @@ -200,6 +200,7 @@ configuration: ## Section #user_counts: true ## Local post total count #post_counts: true + #comment_counts: true ## General settings settings: ## Section diff --git a/spec/presenters/statistics_presenter_spec.rb b/spec/presenters/statistics_presenter_spec.rb index 5811b91c1..786b0750c 100644 --- a/spec/presenters/statistics_presenter_spec.rb +++ b/spec/presenters/statistics_presenter_spec.rb @@ -17,6 +17,7 @@ describe StatisticsPresenter do it 'provides generic pod data in json' do AppConfig.privacy.statistics.user_counts = false AppConfig.privacy.statistics.post_counts = false + AppConfig.privacy.statistics.comment_counts = false @presenter.as_json.should == { "name" => AppConfig.settings.pod_name, "version" => AppConfig.version_string, @@ -27,7 +28,8 @@ describe StatisticsPresenter do it 'provides generic pod data and counts in json' do AppConfig.privacy.statistics.user_counts = true AppConfig.privacy.statistics.post_counts = true - + AppConfig.privacy.statistics.comment_counts = true + @presenter.as_json.should == { "name" => AppConfig.settings.pod_name, "version" => AppConfig.version_string, @@ -35,7 +37,8 @@ describe StatisticsPresenter do "total_users" => User.count, "active_users_halfyear" => User.halfyear_actives.count, "active_users_monthly" => User.monthly_actives.count, - "local_posts" => @presenter.local_posts + "local_posts" => @presenter.local_posts, + "local_comments" => @presenter.local_comments } end