4

I want to implement gamification in my education mobile application. I have a database with user activity and I want to analyze it and give badges to a user. There will be many badges with totally different conditions. Some badges will be given once, others repeatedly.

My current approach:

  1. badges_awarded table that contains a badge, timestamp and string argument holding id of data that were used for this award
  2. badges_evaluation table holding last invocation of each badge algorithm and date when it shall be executed again
  3. when user finishes some game I run a script in background that will perform awarding rules. Evaluation table is used to skip some algorithms that have next run time in future.
  4. if game produced some conditions that invalidates rules of some badges I will updated their next run time in badges_evaluation table (e.g. a badge that user makes no mistake 5 times in a row can start counting again when a user did mistake in the game).

This tactics reduces some evaluations and database queries. The game runs on a mobile device so I must reduce complexity as much as possible. I would like to read some tips and strategies. It is critical to design this feature efficiently.

Another approach represents Fitbit: upload data to server and receive badges back. But I prefer to award kid even when offline.

Badges example:

  1. user played 3 consequitive days for silver and 7 days for gold badge
  2. user made no error 10x, 25x or 100 times in a row (bronze, silver, gold)
  3. user finished a game under X, Y or Z seconds (bronze, silver, gold)
6
  • Downvote? I thought that this is the place I can ask such questions. – Leos Literak May 14 '16 at 6:48
  • 1
    Look at one of the many open-source projects that implement a badge system...? And no, there is no SE site where you can just ask people to give you the design. If you had a prototype, this might be a decent place to ask for architectural feedback, but I have a feeling that Code Review.SE would be a better place for such a question. – Chris Cirefice May 14 '16 at 7:03
  • 3
    But this is a question about sw architecture. I do not expect to receive complete code. – Leos Literak May 14 '16 at 7:11
  • 2
    You are basically asking for the code though. You have no prototype, no possible solutions. You have essentially just said "I want a badge system". I would just search on Github for "badge" and filter on the language you're using. You will find existing implementations. – Chris Cirefice May 14 '16 at 7:13
  • 1
    @LeosLiterak I think the main reason you're being downvoted is that your question is too broad: It has way too many possible (and equally valid) answers. You could make it less broad by explaining your current architecture and implementation approaches you've considered. Without additional specifics like those, any of the possible answers would have to be very long to explain everything thoroughly. – MetaFight May 14 '16 at 10:12
4

Your approach will work, and is probably the most common way of achieving this. If you've benchmarked it and it's too slow, there is a more efficient way, but it's much harder to implement.

What you can do is to transform each rule into a finite state automaton with transitions when relevant events occur. For example, say you have a badge "complete both task A and task B within 1 hour". You might translate this to an FSA with the following state transitions:

state 0
  - if task A completed, go to 1
  - if task B competed, go to 2

State 1
  - if task B completed go to 3
  - if 1 hour elapsed, go to 0

State2
  - if task A completed go to 3
  - if 1 hour elapsed, go to 0

State 3
  - award badge

You can then maintain a list of active events that can cause a transition, and update the state when the event occurs, without needing any background task or database queries. The only problem with this is that each badge becomes much harder to implement. If you have a lot of them it might even be worth designing a simple DSL that compiles down to the appropriate transition lists.

2
  • I updated my question with some badges example. I expect to have tens of different badges, each in three variant (bronze, silver, gold). I have the worse fear of database - it is simple now with 3 badges and small data, but it can fail later as it grows. – Leos Literak May 14 '16 at 13:23
  • Can you elaborate on DSL little more? It would be great as a user could propose their own badges - less implementation for me. Thanks. – Leos Literak May 14 '16 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.