Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebalance func getUsernameAvailableAt #4256

Merged
merged 29 commits into from Jul 17, 2019
Merged
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c784aa6
rebalance func getUsernameAvailableAt
InvisibleSymbol Mar 12, 2019
ea4bb68
Fix wrong variable used in calculation
samuelhklumpers Mar 12, 2019
c648307
Fix spacing according styleci
samuelhklumpers Mar 12, 2019
3d7ab38
Merge branch 'master' of https://github.com/ppy/osu-web into fair_ina…
InvisibleSymbol Mar 13, 2019
c6a2458
Own Calculations for restricted users
InvisibleSymbol Mar 14, 2019
693efd7
styleci update
InvisibleSymbol Mar 14, 2019
e450b1b
styleci update
InvisibleSymbol Mar 14, 2019
8b2a650
Merge branch 'master' into fair_inactive
InvisibleSymbol Mar 15, 2019
0f13120
Merge branch 'master' into fair_inactive
InvisibleSymbol Mar 28, 2019
13f0126
adjust function curve
InvisibleSymbol Mar 28, 2019
d58ff95
styleci update
InvisibleSymbol Mar 28, 2019
33f3631
syntax fix
InvisibleSymbol Mar 28, 2019
3c9ffa7
styleci update
InvisibleSymbol Mar 28, 2019
36eb097
remove unnecessary if statment
InvisibleSymbol Mar 28, 2019
8271950
Merge branch 'master' into fair_inactive
InvisibleSymbol Apr 17, 2019
d3b9095
Merge branch 'master' into fair_inactive
InvisibleSymbol Jun 5, 2019
4096c58
update function curve
InvisibleSymbol Jun 5, 2019
bb598b7
fix restricted user formula
InvisibleSymbol Jun 13, 2019
e839550
Merge branch 'master' into fair_inactive
InvisibleSymbol Jun 13, 2019
9279c49
attempt to write comments
InvisibleSymbol Jun 13, 2019
4ca40bd
remove trailing space
InvisibleSymbol Jun 14, 2019
14955ac
fix typo
InvisibleSymbol Jun 15, 2019
61330dc
Merge branch 'master' into fair_inactive
InvisibleSymbol Jul 15, 2019
fd68f98
combine functions
InvisibleSymbol Jul 15, 2019
27046e8
Merge branch 'fair_inactive' of https://github.com/InvisibleSymbol/os…
InvisibleSymbol Jul 15, 2019
4f83217
remove trailing space
InvisibleSymbol Jul 15, 2019
30ced7b
use function instead
InvisibleSymbol Jul 16, 2019
0d4c3f6
reword documentation
InvisibleSymbol Jul 16, 2019
ece78bf
Merge branch 'master' into fair_inactive
nanaya Jul 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 27 additions & 4 deletions app/Models/User.php
Expand Up @@ -388,14 +388,37 @@ public static function checkWhenUsernameAvailable($username) : Carbon

public function getUsernameAvailableAt() : Carbon
{
if ($this->group_id !== 2 || $this->user_type === 1) {
$playCount = array_reduce(array_keys(Beatmap::MODES), function ($result, $mode) {
InvisibleSymbol marked this conversation as resolved.
Show resolved Hide resolved
return $result + $this->statistics($mode, true)->value('playcount');
}, 0);

if ($this->group_id !== 2) {
//reserved usernames
return Carbon::now()->addYears(10);
return Carbon::now()->addYears(10); //This will always be in the future, which is wanted
}

if ($this->user_type === 1) {
$minDays = 0;
$expMod = 0.35;
$linMod = 0.75;
} else {
$minDays = static::INACTIVE_DAYS;
$expMod = 1;
$linMod = 1;
}

// This is a exponential decay function with the identity 1-e^{-$playCount}.
// The constant multiplier of 1580 causes the formula to flatten out at around 1580 days (~4.3 years).
// $playCount is then divided by the constant value 5900 causing it to flatten out at about 40,000 plays.
// Furthermore, when the user is restricted, the formula has a 0.35 multiplier on $playCount,
// causing it to flatten out more slowly and a linear bonus of 0.75 to reward long-term players.
nanaya marked this conversation as resolved.
Show resolved Hide resolved
// An interactive graph of the formula can be found at https://www.desmos.com/calculator/s7bxytxbbt

return $this->user_lastvisit
->addDays(static::INACTIVE_DAYS) //base inactivity period for all accounts
->addDays($this->playCount() * 0.75); //bonus based on playcount
->addDays(intval(
$minDays +
1580 * (1 - pow(M_E, $playCount * $expMod * -1 / 5900)) +
($playCount * $linMod * 8 / 5900)));
}

public function validateChangeUsername(string $username, string $type = 'paid')
Expand Down