Devotee Badge and Timezones, relaxing requirements?

Thanks for looking and the response.

They want their badge to work regardless of their timezone. The long time users are the most passionate ones. :slight_smile:

We have a Data Explorer query like this, which helped figure out the issue:

-- [params]
-- user_list :users

WITH StartingPoints AS (
  SELECT user_id, visited_at, ROW_NUMBER() OVER(ORDER BY user_id, visited_at) AS rownum
  FROM user_visits AS A
  WHERE NOT EXISTS (
     SELECT 1
     FROM user_visits AS B
     WHERE B.visited_at = A.visited_at - INTERVAL '1 day' AND
     B.user_id = A.user_id
  ) AND user_id IN (:users)
),
EndingPoints AS (
  SELECT user_id, visited_at, ROW_NUMBER() OVER(ORDER BY user_id, visited_at) AS rownum
  FROM user_visits AS A
  WHERE NOT EXISTS (
     SELECT 1
     FROM user_visits AS B
     WHERE B.visited_at = A.visited_at + INTERVAL '1 day' AND
     B.user_id = A.user_id
  ) AND user_id IN (:users)
)
SELECT u.username, S.visited_at AS start_range, E.visited_at AS end_range, (E.visited_at - S.visited_at + 1) AS Days
FROM StartingPoints AS S
JOIN EndingPoints AS E ON E.rownum = S.rownum
JOIN users u ON u.id=S.user_id AND
u.id IN (:users)
ORDER BY u.id ASC, S.visited_at DESC 

..which gives the continuous segments listed. Because of the UTC part (or rather how the underlying date is stored rather than datetime?), it seems fair that we should award the badge, even if a ‘1 day gap’ exists I think.

We’ll look at trying to create another Devotee badge based off of changing this query, perhaps with a ‘2 day’ INTERVAL?

6 Likes