Skip to content

Instantly share code, notes, and snippets.

@ArcticEcho
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArcticEcho/c0be89467b86fafea4eb to your computer and use it in GitHub Desktop.
Save ArcticEcho/c0be89467b86fafea4eb to your computer and use it in GitHub Desktop.
// Copyright (C) 2014 S.Kamber.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
(
function currentRate(seconds)
{
var limit = 0.0;
var a = seconds.length - 1;
var b = 0;
var throttled = false;
for (var i = seconds.length - 1; i > 0; i--)
{
limit = rateLimit(a - i);
if (seconds[a] - seconds[i] < limit && !throttled)
{
throttled = true;
b = limit - (seconds[a] - seconds[i]);
continue;
}
if (b - (seconds[a] - seconds[i]) < 0)
{
throttled = false;
a = i;
}
if (seconds[a] - seconds[i] > limit && !throttled)
{
thorttled = false;
}
if (seconds[a] - seconds[i] > limit * 2)
{
a = i;
throttled = false;
}
}
limit = rateLimit(a);
if (seconds[a] - seconds[0] < limit)
{
console.log('limit'); // You're still throttled.
}
else
{
console.log('ok'); // It's ok to post a new message.
}
function rateLimit(x)
{
return Math.min((4.1484 * Math.log(x) + 1.02242), 20).toFixed(1);
}
}
)
([1, 1, 2, 3, 7, 7, 7, 7])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment