Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 237487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:25:45+00:00 2026-05-11T20:25:45+00:00

There is a new badge on Stack Overflow. The woot badge is awarded to

  • 0

There is a new badge on Stack Overflow. The “woot” badge is awarded to users visited the site each day for 30 days. How can you implement a feature like this? How can you track that a user visited the site each day for X days in the simplest way?

I thought of having two fields–one for the timestamp of the last login, and another to count the days on user continuously visited the site. The logic is to first set the counter to 1, and store the time of login as well. On the very next login, check if since the last login no more than one day past, and increment the counter, or set it back to 1. And then update the timestamp field to the current date.

Can you do it simpler?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:25:45+00:00Added an answer on May 11, 2026 at 8:25 pm

    You do need to have a cookie, since people might not log in every day — for example because they are logged in automatically for 2 weeks, or because they are on your site doing things non-stop without sleep and lunch for 50 hours 🙂 You probably actually want to count when user accesses the site.

    Now, one could theoretically record every access and perform database queries, as was suggested above, but you might think (as I do) that it strikes the wrong balance between usefulness and privacy+simplicity.

    The algorithm you specified is deficient in an obvious way: since you store only whole number of days, you miss the user who logs in and out every 12 hours (your algorithm would keep the count of days as 1)

    Here’s the solution that I find to be cleanest with two date fields per user, in a kind of self-explanatory non-object oriented Python:

    # user.beginStreak----user.lastStreak is the last interval when 
    # user accessed the site continuously without breaks for more than 25h 
    
    def onRegister (user):
        ...
        user.beginStreak = user.endStreak = time() # current time in seconds 
        ...
    
    def onAccess (user): 
        ...
        if user.endStreak + 25*60*60 < time():
            user.beginStreak = time()
        user.endStreak = time()
        user.wootBadge = ( user.endStreak-user.beginStreak > 30*24*60*60 )
        ...
    

    (Please forgive my Pythonic skills, I’m an academic and first-time site user)

    You cannot do this task with one variable. I’m sure somebody can write a clean argument proving this fact.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a new instance of Spring HandlerInterceptors for each request? I have an
Is there a new version of XML out? If so when was it released
Is there a new way to connect to MySQL from Python with Mac OS
Does anyone know if there are new binaries for the castle logging facility using
In android 4.0 resource there are new drawable ,layout ,value folder for example drawable-sw600dp,layout-sw600dp,value-sw600dp.
In Windows Server 2008 and Windows 7 there are new Events categorized under Applications
I use the rails 3.0.0.beta Is there any new syntax to write RJS, here
I know this is the list of permissions in android Is there any new
There is a new style of implemention menues which I see around stylish web
Hello there I am new to php and want to learn to write reusable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.