The realization of infinite level of the user profile?

Opensource projects I found to see how is doing, I want to ask for advice from you dear readers of the question. How?

I imagine so, in the table users has columns: level, current_experience , next_level_experience . Consider the scenario, user 2 level posted an article, he gave 50 exp. To the next level need 25exp. The table will be like this: level = 2, current_experience = 0, next_level_experience = 25 . After laid out post, make an account and around the following:
- get exp per action and if exp >= 25, level ++
- now increase the next_level_experience + 15%, before was 25, I add a +20% next level now when you next_level_experience = 30
- we've still got 25 exp from the last operation, so if exp > 0 another sql query, where it is recorded that the user has received +25 current_experience .

After all, we have a table in this situation:
level = 3, current_expierence = 25, next_level_experience = 30

I wonder if it is? If it is correct? Will there be any future problems with this algorithm? Maybe someone will find tips or ready-made groundwork open source projects?
August 19th 19 at 23:44
4 answers
August 19th 19 at 23:46
I wonder if it is? If it is correct? Will there be any future problems with this algorithm? Maybe someone will find tips or ready narabotki, open source projects?

A cursory examination - I think so. I wouldn't complicate the logic so. Way easier in my opinion:
1. Is the exp value of the current user
2. Have either levels table (1=20, 2=30, 3=40 etc.) or algorithm that calculates this level on the count of experience.

This probably all. Further, the user got exp he added ACC. Qty.

I imagine so, in the users table has columns: level, current_expierence, next_level_expierence.
next_level_expierence is only needed if all users number exp. to the next level different, i.e., one for level 5 you need 100exp, the other to level 5 you need 200ехри etc., resp., for column level - about the same, with respect, it is necessary only in case if we don't hand calculate that number for the current user-specific.
August 19th 19 at 23:48
You can't reset experience a record as it is a level considered by some formula. Be like
$user->experience += 25;
$user->level = $this->getLevel($user->experience);

private function getLevel($experience)
 // Computed and returned (int)

PS spell experience and not expierence.
experience TRU not have noticed, corrected, thanks. - Adalberto.Blick commented on August 19th 19 at 23:51
August 19th 19 at 23:50
The initial values in the database:
level: 1, current: 0, next: 25

The algorithm after step (received: exp)
1) Query: select level, current, next ...
2) Add the received points: current += next
3) Check that you did the job: current >= next ???
- If less: update in database
- If more than : go ahead
4) Increase level level ++
5) Deduct points from job points: current: = next
6) Expect new job (+20%): next = next + next * 0.2
The last points (3 - 6) out to a function and after 6 item requested again. As it is likely performing several tasks in a row.

In the end we get just 2.
August 19th 19 at 23:52
The diagonal reading of the thought one entity lives in two places, and there is a risk of mismatch values...

By the way, I would be looking at something like:

accumulating points

+ separately:
grid levels
periodic procedure of "recount"

i.e. the transition from level to level will be "late" from the points for example in frequency conversion, but the mesh levels can develop and add a bunch of rules and conditions.

Find more questions by tags DatabasesMySQL