Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

badges / achievements [closed]

Tags:

c#

sql-server

i'm looking to implement a similar thing to stackoverflow badges. you could also equate them to achievements in games.

but am not sure how to design the database/code/tracking for them.

i get what i should do for badges such as:

Altruist × 1456 First bounty you manually awarded on another person's question

because they are a one time event, but how to handle others such as:

Analytical × 16389 Visited every section of the FAQ
Electorate × 1783 Voted on 600 questions and 25% or more of total votes are on questions Outspoken × 188 Posted 10 messages in chat that were starred by 10 different users

etc...

how to handle them, how to keep track of progress for each, etc... is there a tutorial or something that can help me figure out a design pattern for them?

like image 645
b0x0rz Avatar asked Apr 05 '12 12:04

b0x0rz


1 Answers

For the given examples, there are essentially two mechanisms you are going to need.

I don't know how it's done on SO, this is just a suggestion of a solution.

Let's look at 'Analytical' first. You are going to have to record by means of a simple flag when a user visits a particular area in the FAQ. Let's envisage a DB table with a field for each FAQ section and a user ID. This starts off as "N" (or 0, or however you want to represent your flag). When a user visits that area, you call code to flip that field to "Y". When all fields are "Y" then you can award that badge.

As for 'electorate' and 'Outspoken', you can retrieve this information by means of a query on your existing data, assuming the queries themseves are not too burdensome. You are going to need to consider when to run these checks. This essentially boils down to two options.

1) When the an action is performed that might get a badge awarded (i.e. visit section of FAQ, Vote on a Question, Question starred by someone else)

2) Periodically (hourly, daily, etc) run a check for all your badges against current data.

Bear in mind that badges are one-way in Stackoverflow, so if you are wanting to be equivalent then you don't have to consider logic to 'un-award' badges.

like image 111
James Wiseman Avatar answered Sep 29 '22 20:09

James Wiseman