Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You do need to have a cookie, since people might not <i>log in</i> 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.</p> <p>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.</p> <p>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)</p> <p>Here's the solution that I find to be cleanest with <b>two</b> date fields per user, in a kind of self-explanatory non-object oriented Python:</p> <pre><code># 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 &lt; time(): user.beginStreak = time() user.endStreak = time() user.wootBadge = ( user.endStreak-user.beginStreak &gt; 30*24*60*60 ) ... </code></pre> <p>(Please forgive my Pythonic skills, I'm an academic and first-time site user)</p> <p>You cannot do this task with <b>one</b> variable. I'm sure somebody can write a clean argument proving this fact.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload