From 717b54d64bb1d62a32bd31dc04e5cedbfb2787ea Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 22 Mar 2016 10:51:42 -0400 Subject: [PATCH] Adjust badges to match descriptions cc @coding-horror --- app/models/badge.rb | 15 ++++++--------- db/fixtures/006_badges.rb | 6 +++--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/models/badge.rb b/app/models/badge.rb index 8baf6180ed4..95f2b0daa45 100644 --- a/app/models/badge.rb +++ b/app/models/badge.rb @@ -295,16 +295,13 @@ SQL SQL end - def self.liked_back(min_posts, ratio) + def self.liked_back(likes_received, likes_given) <<-SQL - SELECT p.user_id, current_timestamp AS granted_at - FROM posts AS p - INNER JOIN user_stats AS us ON us.user_id = p.user_id - WHERE p.like_count > 0 - AND (:backfill OR p.user_id IN (:user_ids)) - GROUP BY p.user_id, us.likes_given - HAVING count(*) > #{min_posts} - AND (us.likes_given / count(*)::float) > #{ratio} + SELECT us.user_id, current_timestamp AS granted_at + FROM user_stats AS us + WHERE us.likes_received >= #{likes_received} + AND us.likes_given >= #{likes_given} + AND (:backfill OR us.user_id IN (:user_ids)) SQL end end diff --git a/db/fixtures/006_badges.rb b/db/fixtures/006_badges.rb index c8c30236e41..5d594a2f011 100644 --- a/db/fixtures/006_badges.rb +++ b/db/fixtures/006_badges.rb @@ -314,9 +314,9 @@ end [ - [Badge::ThankYou, "Thank You", BadgeType::Bronze, 20, 0.00], - [Badge::GivesBack, "Gives Back", BadgeType::Silver, 100, 1.0], - [Badge::Empathetic, "Empathetic", BadgeType::Gold, 500, 2.0], + [Badge::ThankYou, "Thank You", BadgeType::Bronze, 20, 10], + [Badge::GivesBack, "Gives Back", BadgeType::Silver, 100, 100], + [Badge::Empathetic, "Empathetic", BadgeType::Gold, 500, 1000] ].each do |spec| id, name, level, count, ratio = spec Badge.seed do |b|