Scoring system like stackoverflow

I am trying to create a point system in my program like a stack overflow, i.e. when a user does some good action (activity) his / her points increase. I am wondering what is the best way to implement this in terms of db + logic schema.

I can imagine three options:

  • Add an extra field called dots in the users table and every time the user does something add it to that field (but that won't be able to show sort of activity)
  • Create a function that will run every time a user does a good deed and calculates a value from scratch and updates the dot field.
  • Calculate each time using a function without a dot field.

What's the best way to do this? Thank you for your time.

+2


source to share


6 answers


Personally, I would use the second option to solve this problem.

The first parameter is limiting the functionality, so I'll fix that right away.

The third option is inefficient from a performance standpoint - it is likely that you will get this number a lot , and if your program is like stackoverflow, perhaps showing (calculating) this number many times per pageview / action.



For me, the second option is a decent hybrid solution. I usually hate duplicating data in my system (actions and dots, not one or the other), but in this case the integer field represents a fairly small amount of space for the user, which saves you a lot of time when recalculating the value unnecessarily.

We have to trade datastore from time to time for performance or vice versa, and I would say # 2 is a tradeoff that greatly benefits the application.

+2


source


I would go for 1 and 2 (run cron every minute or so).

So what: - the additional field will act as a cache for the number of points. - Function to calculate points can be one sql query that will recalculate points for all users at the same time to get some speed.



I think that re-calculating the field every time a point is obtained would be overkill.

0


source


It depends a lot on the amount of expected computation you are going to face. In fact, SO seems to use a method that is similar to your 1) approach, for performance reasons, which I am assuming.

It also prevents jumps in the numbers if factors change (e.g. deleted items that have been credited with points, or here on SO answers that become community wikis, changes to dot rules, external actions like merging another account here on SO etc. )

If recalc (2) solution is what you want, you can implement smart caching by clearing the value (setting it to NULL, which would mean dirty) every time a point change might occur - compute it. when it is NULL, otherwise the cache is used. You can also (as a self-correcting measure when implicit things happened) clear the values ​​after an hour, a day, or whatever you think you were eating, so that a callback is forced after a certain amount of time, regardless of the dirty state.

0


source


Personally, I would go with the first parameter and add an Actions table to keep track of your activity history.

When the user does something good, he gets an entry in the "Actions" table with an action and some point value. The dot value can be obtained from another table or some configuration file. The same value is added to the user's record.

At any given time, you can summarize the activities and get the total number of users, but for performance, just updating when adding an activity record will be easy enough.

0


source


How simple is your scoring system? I believe some kind of logging / logging is good so that you can track daily / weekly / monthly activity for all users.

0


source


Check out http://code.google.com/p/userinfuser/

Open source and allows you to add points and badges to the app. It has Java, Python, PHP and Ruby bindings.

0


source







All Articles