Time Decay Algorithm

An algorithm for decaying points when you're inactive for so long.

Page 1 of 1

8 Replies - 7663 Views - Last Post: 17 April 2010 - 09:47 AM

#1 ShaneK  Icon User is offline

  • require_once("brain.php"); //Fatal error :/
  • member icon

Reputation: 240
  • View blog
  • Posts: 1,224
  • Joined: 10-May 09

Time Decay Algorithm

Posted 15 April 2010 - 11:59 AM

Greetings!

I was wondering if anyone knew where I could find such an algorithm or even have any tips on how to start one. I really haven't a clue. I'm just looking for a way to encourage people to be more active in the game because the way it is now they can do something and wait and have a pretty good shot of being the winner...

Look, it's a forum game for an MMORPG called Tibia and it's really not fair that some people can post once and never again and win (or have a good shot at winning), while others post hundreds of times...

Well, you can find the game here (http://forum.tibia.com/forum/?action=thread&threadid=3013453&pagenumber=1 ) to see what I mean and this person as an example (http://tibialottery.com/event/player/Celaya )

Any advice?

Yours,
Shane~

Is This A Good Question/Topic? 0
  • +

Replies To: Time Decay Algorithm

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10568
  • View blog
  • Posts: 39,131
  • Joined: 27-December 08

Re: Time Decay Algorithm

Posted 15 April 2010 - 12:08 PM

So if inactivity for say 3 hours dictates a loss of a point, then check once every 3 hours for each player/member and compare the current against the time of their last activity or post.
Was This Post Helpful? 1
  • +
  • -

#3 rmccarter721  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 139
  • Joined: 10-September 07

Re: Time Decay Algorithm

Posted 15 April 2010 - 02:23 PM

If you dont have cron jobs available, set up a function that runs on each page reload that checks when they were lsat active/had points removed and then remove the needed points..

You can probably set it so it only does so many on each reload so it doesn't slow it too much
Was This Post Helpful? 1
  • +
  • -

#4 ShaneK  Icon User is offline

  • require_once("brain.php"); //Fatal error :/
  • member icon

Reputation: 240
  • View blog
  • Posts: 1,224
  • Joined: 10-May 09

Re: Time Decay Algorithm

Posted 16 April 2010 - 11:23 AM

Meh, I was thinking about decaying over time, not just emptying, but thanks for your help. I'll figure something out.

Yours,
Shane~
Was This Post Helpful? 0
  • +
  • -

#5 rmccarter721  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 139
  • Joined: 10-September 07

Re: Time Decay Algorithm

Posted 16 April 2010 - 12:46 PM

Explain what sorta system you have in mind, like what would teh variables be/example values, like time, decay rate etc.
Was This Post Helpful? 0
  • +
  • -

#6 rmccarter721  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 139
  • Joined: 10-September 07

Re: Time Decay Algorithm

Posted 16 April 2010 - 01:15 PM

Untested
function decay(){
	/*
	 * Table Structure
	 * user_id - int eg. 1
	 * last_check - datetime eg. 2010-04-12 21:34:20
	 * points - int. eg. 50
	 */
	
	//Define Variables
	$TimeFrame = 2; //Every 2 Hours remove $decay % of the value
	$decay = 0.5; //Must be less than 1
	$number = 10; //Number of emtries to check per function call
	
	//Calculate date to decay from
	
	$date = strtotime(date('Y-m-d').date('G')-$$TimeFrame.date(':i:s'));
	
	$result = mysql_query("SELECT * FROM `table` ORDER BY `last_check` DESC LIMIT  0, 10")
			or die(mysql_error());
		while($UserDetails = mysql_fetch_array($result)){
			if(strtotime($UserDetails['last_check']) > $date){
				$points =  $UserDetails['points'] - ($UserDetails['points']*$decay);
				mysql_query("UPDATE `table` SET `points` WHERE `user_id` = '$UserDetails['points']'")
					or die(mysql_error());
			}
	}
}


That is the sort of thing I was thinking, you would call the function on page load, well you would need to check there is results, but still, that is the basic idea.

Was that the sort of thing you had in mind?

This post has been edited by Furnfield: 16 April 2010 - 01:28 PM

Was This Post Helpful? 1
  • +
  • -

#7 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2992
  • Posts: 10,337
  • Joined: 08-August 08

Re: Time Decay Algorithm

Posted 16 April 2010 - 07:10 PM

I would use something like this:

$score /= $time;

where $time would need to be >= 1

If it drops too quickly in the beginning for you, you could force time to be larger and multiply by a constant.

$score *= 5/($time+5);

Attached image(s)

  • Attached Image

Was This Post Helpful? 1
  • +
  • -

#8 ShaneK  Icon User is offline

  • require_once("brain.php"); //Fatal error :/
  • member icon

Reputation: 240
  • View blog
  • Posts: 1,224
  • Joined: 10-May 09

Re: Time Decay Algorithm

Posted 16 April 2010 - 07:13 PM

View PostFurnfield, on 16 April 2010 - 01:15 PM, said:

Untested
function decay(){
	/*
	 * Table Structure
	 * user_id - int eg. 1
	 * last_check - datetime eg. 2010-04-12 21:34:20
	 * points - int. eg. 50
	 */
	
	//Define Variables
	$TimeFrame = 2; //Every 2 Hours remove $decay % of the value
	$decay = 0.5; //Must be less than 1
	$number = 10; //Number of emtries to check per function call
	
	//Calculate date to decay from
	
	$date = strtotime(date('Y-m-d').date('G')-$$TimeFrame.date(':i:s'));
	
	$result = mysql_query("SELECT * FROM `table` ORDER BY `last_check` DESC LIMIT  0, 10")
			or die(mysql_error());
		while($UserDetails = mysql_fetch_array($result)){
			if(strtotime($UserDetails['last_check']) > $date){
				$points =  $UserDetails['points'] - ($UserDetails['points']*$decay);
				mysql_query("UPDATE `table` SET `points` WHERE `user_id` = '$UserDetails['points']'")
					or die(mysql_error());
			}
	}
}


That is the sort of thing I was thinking, you would call the function on page load, well you would need to check there is results, but still, that is the basic idea.

Was that the sort of thing you had in mind?


Not really doing this out of a database or anything, was kinda gonna go with posts in between... (Not to say I couldn't adapt to this, but I don't really record time)


View PostCTphpnwb, on 16 April 2010 - 07:10 PM, said:

I would use something like this:

$score /= $time;

where $time would need to be >= 1

If it drops too quickly in the beginning for you, you could force time to be larger and multiply by a constant.

$score *= 5/($time+5);


I can adapt to this with posts better, thanks a lot :) The chart looks perfect...

Yours,
Shane~

This post has been edited by ShaneK: 16 April 2010 - 07:14 PM

Was This Post Helpful? 0
  • +
  • -

#9 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2992
  • Posts: 10,337
  • Joined: 08-August 08

Re: Time Decay Algorithm

Posted 17 April 2010 - 09:47 AM

I hope it helps.

I forgot to mention that the curve I showed was calculated by multiplying the original score (in this case: 2000) for each point. You would get different results if you reset the score every time you multiplied, so you'd want to keep the current score for anyone who hasn't had activity and calculate the effective score for any point in time that some one checks it. Then you'd calculate it one last time and save it when the user has new activity.

Hope that makes sense!

This post has been edited by CTphpnwb: 17 April 2010 - 09:48 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1