Creating an equation that will return a linear result

37 Views Asked by At

I am a web developer and I need to create a multiplier between 1 & 10 or as close as possible. I have a variable value that is essentially a date range in days (1 day ago = 1, 10 days ago is 10... 1000 days ago is 1000). I need to create an equation that will convert this date range into a suitable multiplier for my sorting algorithm, decimals allowed. My best attempts so far:

1 + (365 / $diffdays);
1 + (365 / 1) = 366;
1 + (365 / 10) = 37.5;
1 + (365 / 100) = 4.65;
1 + (365 / 365) = 2;

1 + (10 / $diffdays);
1 + (10 / 1) = 11;
1 + (10 / 10) = 2;
1 + (10 / 100) = 1.1;
1 + (10 / 365) = 1.027; 

1 + (1 / $diffdays);
1 + (1 / 1) = 2;
1 + (1 / 10) = 1.1;
1 + (1 / 100) = 1.01;
1 + (1 / 365) = 1.0027; 

The first provides too large or a multiplier at the top end. The other is not large enough.

The middle equation is pretty close however it is an exponential curve that is created, is there a way to convert it into a linear result by modifying the equation?

Please can someone apply their wizardry to help create an equation that is in between the two attempts provided?

EDIT:

I plan to use the multiplier within my relevance calculator for articles, in which if the title of the article matches it will receive a boost, if the words in the content of an article it receives a boost but less so than the title hits.

I then need to provide a boost based on when the article was posted. However, an exponential curve is providing too large of a gap between dates. It very quickly goes from being a 100 x multiplier down to 1.027 multiplier which is not fair.

The code that applies this to the articles weight is:

$sameDay = 10;
$dateMatch = $diffDaysAsPercentage * $sameDay;
$weight *= $dateMatch;

Where $diffDaysAsPercentage is the result of the equation we are working on.

EDIT 2: It might also be worth mentioning that articles can date back further than 365 days, they can be multiple years old too (e.g 1000 days = 1000).

EDIT 3: Using log seems like the right way to solve the problem, there does seem to be a value quickly similar problem, the answer quickly slips into the 0.x values. * attached image *

Examples of log()