Randomly select active user?


(Hadley Wickham) #1

Is it possible to randomly select one (or more) users who have been active in the last week? To help get our forum up and going, we’d like to offer some weekly “door” prizes.


(Joshua Rosenfeld) #2

There is not a feature built into Discourse to do this. Your best bet is to run a Data Explorer query for active users, then use a random number generator to select someone.

There’s also the Weekly or monthly “best new user” badge - it’s currently monthly.


(Steve Combs) #3

Here are the steps to create the random number with Excel after you have exported the data.

  • Insert column with title “RandomID” or whatever you like
  • Insert Excel function “=RAND()”
  • Make sure no blank rows
  • Copy the formula down the column
  • Select and copy the entire column with the random values
  • Paste special the entire column as values (so the numbers don’t change when you save the file)
  • Sort lowest to highest
  • Lowest number wins

(Hadley Wickham) #4

Unfortunately I can’t use the data explorer because we’re only on the basic plan, but it looks like I can get similar information by using the latest posts API.


(Dean Taylor) #5

Obviously you could use the /u users page API endpoint:
/directory_items?period=weekly&order=likes_received
and then get additional pages with repeated calls similar to:
/directory_items?period=weekly&order=likes_received&page=1

Be aware the /u page and /directory_items content is cached.


(Hadley Wickham) #6

Thanks - I also discovered that yesterday when I learned that discourse front end uses the API so I can look for xhr requests.