Author Topic: Viewing Dormant Players  (Read 2397 times)

Offline dbest

  • Game Owner
  • Level 20
  • *
  • Posts: 210
  • Reputation: +3/-0
    • View Profile
    • Tennis Masters
Viewing Dormant Players
« on: November 22, 2009, 09:33:16 AM »
I had to struggle yesterday to figure out how to find dormant players in the game. Dormant players are those who have not logged in for a certain period of days, 30 days in my case. Decided to make a post so that it may help someone in the future and also so that anyone can improve upon my implementation.


Every time a user logins to the game, the userid & the time of login is stored in a table called "logins", as such:

Code: [Select]
INSERT INTO logins(id_user,time_login) VALUES ('$user_id',NOW())
The userid & other user details are stored in a table called "users".

To view all users who have not logged during the past 30 days, the following query can be used:

Code: [Select]
SELECT user_id FROM users WHERE user_id NOT IN (SELECT id_user FROM logins WHERE DATEDIFF(CURDATE(), time_login) < 30)
This may not be the best way to do it, so anyone with a better way of doing this, please feel free to post their implementation.


Offline saljutin

  • Level 22
  • *
  • Posts: 260
  • Reputation: +6/-0
    • View Profile
Re: Viewing Dormant Players
« Reply #1 on: November 22, 2009, 09:49:19 AM »
why do you store every login? do you need to know times for every user for last week?

Offline dbest

  • Game Owner
  • Level 20
  • *
  • Posts: 210
  • Reputation: +3/-0
    • View Profile
    • Tennis Masters
Re: Viewing Dormant Players
« Reply #2 on: November 22, 2009, 09:55:58 AM »
good question. main reason is to get rid of dormant users.

Offline jannesiera

  • Level 35
  • **
  • Posts: 1,026
  • Reputation: +6/-1
    • View Profile
    • BBGameDesign
Re: Viewing Dormant Players
« Reply #3 on: November 22, 2009, 10:04:19 AM »
why do you store every login? do you need to know times for every user for last week?

It can be handy for statistics :).

Offline Nox

  • Level 35
  • **
  • Posts: 738
  • Reputation: +12/-2
    • View Profile
Re: Viewing Dormant Players
« Reply #4 on: November 22, 2009, 10:29:40 AM »
nice... I see it mostly as security-related feature :) so many ways to percieve it

I too have login log and beside that I also have lastclick entry so it's possible just
Code: [Select]
select * from users where lastclick < NOW() - interval 30 day
edit: of course, ip there, didn't want to get into details
« Last Edit: November 22, 2009, 11:02:28 AM by Nox »
Meet us at an IRC irc.freenode.net #bbg as well
Enjoy http://spiritbeacon.noxart.cz/ !

Offline saljutin

  • Level 22
  • *
  • Posts: 260
  • Reputation: +6/-0
    • View Profile
Re: Viewing Dormant Players
« Reply #5 on: November 22, 2009, 10:49:44 AM »
well for security u should add some IP as well :)

but why dont you use something like:

SELECT id_user,MAX(time_login) FROM logins GROUP BY id_user

and then use that in php to compare that time of last login to the one now (time())
I think above query should work, but I didnt test it :)

Offline dbest

  • Game Owner
  • Level 20
  • *
  • Posts: 210
  • Reputation: +3/-0
    • View Profile
    • Tennis Masters
Re: Viewing Dormant Players
« Reply #6 on: November 22, 2009, 10:59:11 AM »
i have the IP address in my table too, but didnt mention it, as it was not the focus.. ;)


ST-Mike

  • Guest
Re: Viewing Dormant Players
« Reply #7 on: November 22, 2009, 12:06:33 PM »
Admins have ignored my deletion request - if you're not going to delete my account then don't have the option there please.
« Last Edit: March 15, 2011, 08:00:38 PM by None »

Offline die4me

  • Level 16
  • *
  • Posts: 137
  • Reputation: +0/-0
  • When life gives you lemons throw them at people
    • View Profile
    • Hostworks free hosting
Re: Viewing Dormant Players
« Reply #8 on: November 22, 2009, 12:34:06 PM »
That is a good idea i used that and put a last date active on there profile

Offline dbest

  • Game Owner
  • Level 20
  • *
  • Posts: 210
  • Reputation: +3/-0
    • View Profile
    • Tennis Masters
Re: Viewing Dormant Players
« Reply #9 on: November 22, 2009, 12:45:49 PM »
Could do that too ST-Mike. But as you mentioned there are other reasons to create a separate logins table.

Offline Harkins

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-2
  • Coder, blogger, entrepreneur.
    • View Profile
    • Push CX - Blog
Re: Viewing Dormant Players
« Reply #10 on: November 22, 2009, 01:30:45 PM »
Ignoring the other reasons to have a seperate login table, to find out which users are dormant why not just store UNIX_TIMESTAMP() into whatever main users table every time they login (or are active?) and then do a search on that (SELECT `id`,`username` FROM `users` WHERE `time_login/time_activity` < UNIX_TIMESTAMP()-(86400*30);). I would have thought that's the best way to find dormant users.

No need deal with unix timestamps and multiplication, the standard date and time functions are easier and clearer:

Code: [Select]
select id, username from users where last_activity_at >= date_sub(now(), interval 30 day);


Visit #bbg on irc.freenode.net to talk browser games anytime.

ST-Mike

  • Guest
Re: Viewing Dormant Players
« Reply #11 on: November 22, 2009, 03:04:54 PM »
Admins have ignored my deletion request - if you're not going to delete my account then don't have the option there please.
« Last Edit: March 15, 2011, 07:59:41 PM by None »

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal