“徽章”的数据库体系结构系统与任意条件(MySQL / PHP) [英] Database Architecture for "Badge" System & Arbitrary Criteria (MySQL/PHP)

查看:207
本文介绍了“徽章”的数据库体系结构系统与任意条件(MySQL / PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总结一下,总结一下,我如何设计这样一个数据库,使得无限制的徽章规则创建不需要结构,我就有些困惑更改数据库中以前存在的用户表。



存储徽章标题,标准等。该表将是什么样的?




  • badge_id(1)

  • badge_title(10K徽章)

  • badge_image(10k.jpg )

  • badge_criteria([posts]> = 10000)

    ...



有风 - 问题:



我想在自己的个人身上实施徽章系统项目,但是正在寻求一个关于如何最好地做这样的事情的建议。我一直在阅读有关徽章系统的一些问题,但是看不到数据库架构受到关注。



基于用户界面的徽章,点(假设的10k徽章)看起来很简单。任何影响用户声誉的事件(upvote,downvote,answer-accepted等)都会调用一种方法来检查用户的新声誉,并可能会颁发徽章。



那个系统听起来很简单,但是呢,像管理员那样想要创建无数量的徽章的数据库呢,这些数据库在路上的努力不大,其中一些可能是基于不同的标准,而不是简单的用户



用户信誉可能是用户记录本身的一个值。但是,理想情况下,您是否希望在创建新的徽章时避免在用户表中添加新字段?例如编辑的100条目徽章 - 您不会在用户表中创建一个新的entries_edited列,是吗?然后在每个条目编辑后增加...



任何提示?



Stackoverflow存档: p>






注意:我不是问如何将徽章与用户关联。我不是问如何颁发徽章(将以编程方式完成)

解决方案

鉴于徽章标准可以任意复杂,我不认为你可以把它存储在数据库表中,分解成简单的数据元素。尝试编写一个可以处理任意复杂标准的规则引擎将会让您沿用基本上重写您在编程语言中的所有工具的路径。



如果您提前知道您希望徽章仅限于某些领域(即徽章仅基于声誉或编辑次数或某些东西),那么您可以将它们存储在简单的表格中,例如:

  ReputationBadgeCriteria 
BadgeId
BadgeName
MinReputation

或者,您可以使用某种DSL来编写规则,但是您最终还需要创建一个解析器来解析规则,当您阅读它们以及某些东西执行这些规则。根据您在DSL中所需的复杂性,这可能不是一件简单的工作。这看起来像您在问题中的路径,具有标准列(大概是纯文本),其中包含[声誉]> 1000或[帖子]> 5。您仍然必须解析并执行这些规则,并且编写某些操作的复杂性取决于您希望这些规则的复杂程度。



我建议您阅读这些每日WTF 文章,了解为什么这种方法会导致痛苦。


Quickie-Question:

To summarize, I'm a little confused as to how I would design such a database that allows indefinite badge-rule creation without requiring structural changes to the previously existing user-tables in the database.

Storing Badge Title, Criteria, etc. What would that Table look like?

  • badge_id (1)
  • badge_title (10K Badge)
  • badge_image (10k.jpg)
  • badge_criteria ([posts] >= 10000)
    ...

Winded-Question:

I would like to implement a badge-system on my own personal projects, but am seeking a bit of advice as to how one would best do such a thing. I've been reading some of the questions here about badge-systems, but don't see the database-architecture getting much attention.

Badges that are based on user-points (Hypothetical "10k Badge") would seem pretty straight forward. Any event that affects the users reputation (upvotes, downvotes, answer-accepted, etc) would invoke a method to review the users new reputation, and potentially award a badge.

That system sounds pretty straight forward, but what does that look like as a database for the administrator who wants to create innumerable amounts of badges with little-effort down the road - some of which may be based on different criteria, and not simply the user reputation.

User-reputation is likely a value within the user-record itself. But ideally, wouldn't you want to avoid having to add new fields to the user table when you create new badges? For instance the "Edited 100 Entries" badge - you wouldn't create a new column "entries_edited" within the Users Table, would you? And then increment that after each entry-edited...

Any hints?

Stackoverflow Archive:


Note: I'm NOT asking how to associate badges with users. I'm NOT asking how to award badges (that will be done programmatically)

解决方案

Given that the badge criteria can be arbitrarily complex, I don't think you can store it in a database table broken down into "simple" data elements. Trying to write a "rules engine" that can handle arbitrarily complex criteria is going to take you down the path of basically re-writing all the tools that you have in your programming language.

If you know in advance you want the badges limited to only certain fields (i.e. badges are only based off reputation or number of edits or something), then you can store those in a simple table like:

ReputationBadgeCriteria
  BadgeId
  BadgeName
  MinReputation

Alternatively, you could use some kind of DSL to write your "rules" but you end up having to also create a parser to parse the rules when you read them as well as something to execute these rules. Depending on the complexity you want in your DSL, this may not be a trivial task. This looks like the path you are going in your question with having a Criteria column (presumably plain text) that has something like "[Reputation] > 1000" or "[Posts] > 5" in it. You still have to parse and execute those rules and the complexity of writing something to do so is dependent on how complex you want those rules to be.

I would recommend you read these Daily WTF articles for information on why this approach leads to pain.

这篇关于“徽章”的数据库体系结构系统与任意条件(MySQL / PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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