O
O
olezhenka2017-04-29 22:34:37
PHP
olezhenka, 2017-04-29 22:34:37

How to make smaller numbers give more points?

I subtract the posting time for the present (example: 1493490780-1493487180) and I need to sort by the most relevant posts, I can do this, but I need to make points according to the "less is better" algorithm,
subtraction gives equality, for example ,
up to 3600 then points will be 50000
from 3601 to 7200 points 25000
from 7201 to 10800 points 10000

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2017-04-29
@olezhenka

Literally, your rules are implemented by similar JavaScript code - with conditions:

function getPostScore(time) {
  var diff = Math.floor((new Date()).getTime()/1000) - time;
  if( diff <= 3600) return 50000;
  else if( diff <= 7200) return 25000;
  else if( diff <= 10800) return 10000;
  else return 0;
}

getPostScore(1493487180); // 10000

But the stepping of values ​​is probably not fully justified and it would be better to have some kind of smooth function. For example, of the type y = k / x
With a coefficient k = 50000 * 3600, it successfully captures the second point as well. But it is bad because closer to zero it goes off scale to + infinity.
Probably, for your task, an S-shaped curve is more appropriate - sigmoid , given by a formula like y \u003d 1 / (1 + e -x ) Approximately picked up the coefficients:
ecd0f96a15224fe2ac9fb125e7305b8f.png
function getPostSigma(time){
  var diff = Math.floor((new Date()).getTime()/1000) - time;
  return Math.round( 10000 + 40000 / (1 + Math.exp((diff-6800)/700)));
}

getPostSigma(1493531780); // 49998
getPostSigma(1493522780); // 11545

A
Andrew, 2017-04-30
@OLS

HIGHEST*exp(-diff/SPEED)
where
HIGHEST is the maximum points value constant (for placement 0 seconds ago)
SPEED is the rate of decrease constant
e.g.
50000*exp(-diff/4500)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question