Create rarity levels for using up all likes

This commit is contained in:
Robin Ward 2016-03-16 12:31:26 -04:00
parent e84d5549ef
commit 25c26dcd51
2 changed files with 33 additions and 20 deletions

View file

@ -28,7 +28,9 @@ class Badge < ActiveRecord::Base
FamousLink = 30
Admired = 31
GivesBack = 32
Generous = 33
OutOfLove = 33
MyCupRunnethOver = 34
CrazyInLove = 35
# other consts
AutobiographerMinBioLength = 10
@ -220,14 +222,6 @@ SQL
HAVING us.likes_given::float / count(*) > 5.0
SQL
Generous = <<-SQL
SELECT uh.target_user_id AS user_id, MIN(uh.created_at) AS granted_at
FROM user_histories AS uh
WHERE uh.action = #{UserHistory.actions[:rate_limited_like]}
AND (:backfill OR uh.target_user_id IN (:user_ids))
GROUP BY uh.target_user_id
SQL
def self.invite_badge(count,trust_level)
"
SELECT u.id user_id, current_timestamp granted_at
@ -292,6 +286,17 @@ SQL
SQL
end
def self.like_rate_limit(count)
<<-SQL
SELECT uh.target_user_id AS user_id, MAX(uh.created_at) AS granted_at
FROM user_histories AS uh
WHERE uh.action = #{UserHistory.actions[:rate_limited_like]}
AND (:backfill OR uh.target_user_id IN (:user_ids))
GROUP BY uh.target_user_id
HAVING COUNT(*) >= #{count}
SQL
end
end
belongs_to :badge_type
@ -313,7 +318,6 @@ SQL
[:badge_type_id, :multiple_grant, :target_posts, :show_posts, :query, :trigger, :auto_revoke, :listable]
end
def self.trust_level_badge_ids
(1..4).to_a
end

View file

@ -316,17 +316,26 @@ Badge.seed do |b|
b.system = true
end
[
[Badge::OutOfLove, "Out of Love", BadgeType::Bronze, 1],
[Badge::MyCupRunnethOver, "My Cup Runneth Over", BadgeType::Silver, 5],
[Badge::CrazyInLove, "Crazy in Love", BadgeType::Gold, 20],
].each do |spec|
id, name, level, count = spec
Badge.seed do |b|
b.id = Badge::Generous
b.default_name = "Generous"
b.id = id
b.name = name
b.default_name = name
b.default_icon = "fa-heart"
b.badge_type_id = BadgeType::Silver
b.query = Badge::Queries::Generous
b.badge_type_id = level
b.query = Badge::Queries.like_rate_limit(count)
b.default_badge_grouping_id = BadgeGrouping::Community
b.trigger = Badge::Trigger::None
b.auto_revoke = false
b.system = true
end
end
Badge.where("NOT system AND id < 100").each do |badge|
new_id = [Badge.maximum(:id) + 1, 100].max