优点宝石能否重新评估声誉并重新评估徽章和等级? [英] Can the merit gem recalculate reputation and re-evaluate badges and ranks?

查看:144
本文介绍了优点宝石能否重新评估声誉并重新评估徽章和等级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Rails应用程序中添加点数,排名和徽章系统。 merit 宝石看起来很酷,但我想确保在使用它之前它是如何工作的。



定义徽章

 #app / models / merit / badge_rules.rb 
grant_on'comments#vote',:badge = > 'relevant-commenter',:to => :用户do | comment |
comment.votes.count == 5
结束

和分数



 #app / models / merit / point_rules.rb 
得分10,:to => :post_creator,:on => '评论#创建'do | comment |
comment.title.present?
end

表明动作是作为一个钩子完成的, code> comments#vote 或 comments#create )。我没有看到徽章和积分的计算/归属如何工作,所以我不确定。



由于我的应用会随着时间的推移而发展,所以我希望成为能够改变点和徽章规则并重新评估它们。例如:假设我首先决定授予帐户激活10分。我希望能够将其更改为20,然后重新评估所有激活的配置文件并获得+10点增加。同样的事情徽章。



这个宝石是否支持?

解决方案

有可能在具有优点的应用程序中重新计算声誉。优点保持在 Merit :: Action 模型中映射到 merit_actions 的哪个点/徽章授予哪个动作的历史记录> table。



以下脚本应该可以工作(首先备份,因为我还没有在生产环境中这样做):

 #1.重设所有徽章/得分
优点:: BadgesSash.delete_all
优点::得分:: Point.delete_all

#1.1可选择重置活动日志(直到现在授予/移除的徽章/积分)
优点:: ActivityLog.delete_all

#2.将所有`merit_actions`标记为未处理的
优点:: Action.all.map {| a | a.update_attribute:processed,false}

#3.重新计算信誉规则
Merit :: Action.check_unprocessed
Merit :: RankRules.new.check_rank_rules

关于优秀内部说明(总体功绩工作流程wiki页面)

I would like to add a system of points, ranks and badges in my rails app.

The merit gem looks cool, but I want to make sure how it works before using it.

The way you define badges

# app/models/merit/badge_rules.rb
grant_on 'comments#vote', :badge => 'relevant-commenter', :to => :user do |comment|
  comment.votes.count == 5
end

and points

# app/models/merit/point_rules.rb
score 10, :to => :post_creator, :on => 'comments#create' do |comment|
  comment.title.present?
end

suggest that the action is done as a hook, just after the action (comments#vote or comments#create) in those cases. I havn't looked how the calculation/attribution of badges and points work yet so I am not sure.

As my app will evolve over time, I would like to be able to change the point and badges rules and re-evaluate them. Eg: Say I first decide to grant 10 points on account activation. I would like to be able to change it to 20 and then all activated profiles are re-evaluated and get a +10 point increase. Same thing for badges.

Does this gem support that ?

解决方案

It is possible to recompute reputation in an app with merit gem. Merit keeps the history of which actions triggered which point/badge granting in Merit::Action model, which is mapped to merit_actions table.

Following script should work (do a back up first, as I didn't do this in production yet):

# 1. Reset all badges/points granting
Merit::BadgesSash.delete_all
Merit::Score::Point.delete_all

# 1.1 Optionally reset activity log (badges/points granted/removed until now)
Merit::ActivityLog.delete_all

# 2. Mark all `merit_actions` as unprocessed
Merit::Action.all.map{|a| a.update_attribute :processed, false }

# 3. Recompute reputation rules
Merit::Action.check_unprocessed
Merit::RankRules.new.check_rank_rules

Notes on merit internals ("General merit workflow" wiki page).

这篇关于优点宝石能否重新评估声誉并重新评估徽章和等级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆