screenshot of visited days calendar

How do Stack Exchange sites track visited and consecutive days? I would like to know how you would go about designing something like this.


There is a log stored in the database that keeps track of the days you visit the site (probably with some other information, too). I believe diamond mods have read-only access to the log data for each user account.

Once you have a set of data that represents the days you've visited, then it's trivial to derive statistics about that data set, such as the longest streak you've visited consecutively, or how many days you've visited in total.

In the case of this site, these derived statistics are most likely denormalized to a user account field for performance reasons. You may not necessarily have to go that far in your application.

| improve this answer | |
  • Thanks for the answer. Im curious to know what you mean when say these statistics are denormalized to a user account? I probably am not going to do that whatever it is but i'd like to know what you mean by it so i can further by understanding incase i ever want to do that sometime in the future. Thanks – Jonathan Nov 9 '10 at 19:47
  • @Jonny: Denormalization means that computations take place periodically, with the result stored elsewhere. Basically, instead of calculating a total every time the user accesses a page, only the result gets used on the assumption that the underlying data changes infrequently. In the case of visited days, this is a property of an individual user account (the numbers appear on our profile page), so from an object-oriented perspective, that's where the denormalized values would be stored. – Jon Seigel Nov 9 '10 at 23:03
  • Great answer - we store a daily UserHistory record when you access the site. As you've said, it's easy to aggregate and denormalize the total/consecutive days from these records. – Jarrod Dixon Nov 9 '10 at 23:34

Maybe just with a database table like

last seen (date) ; current consecutive days ; total days

and it's easy to update each of the three fields when a user logs in.

EDIT: (last seen seems to actually be stored in another table, as they're able to draw a calendar with the visited days.)

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .