Evenly redirect users to 18 different pages AND confirm submission

133 Views Asked by At

Have a design problem and would appreciate some advice.

I am expecting 540 participants to complete 18 surveys. Each survey should have exactly 30 participants (to COMPLETE/SUBMIT the survey - not to just VISIT the survey). The surveys are highly similar (structurally the same; only differ in some wording/images. Can be derived from the same html).

The way I used to do it is to host only one html, and have a random number generator in the html/JavaScript. When the page is requested, a random number between 1 to 18 will be generated, and according to that number, one of the 18 surveys is generated and returned to the participant. This is really convenient in the sense that I only need to maintain one html page, and worry about generating different surveys according to a given number. However I have noticed that the participants are not perfectly evenly distributed - I may have 25 participants in one survey, and 35 participants in another. This is possibly due to the randomness coming from the random number generator (and I assume there is nothing much I can do about it - correct me if I am wrong).

I am searching for a better solution. I thought about having a counter on the server side, and redirect participants according to the count (e.g. every 1st participants go to the 1st survey, every 2nd participants go to the 2nd survey... and every 18th participants go to the 18th survey). However this can only guarantee the participants evenly VISIT the surveys, not COMPLETE/SUBMIT the surveys - a participant can totally increase the count but do not finish the survey. If he doesn't submit the survey the count shouldn't be increased. But if the count doesn't increase he (and successive participants) cannot be assigned a survey. Putting a lock on the counter is unrealistic because there will be so many participants waiting to get a number and hence survey... ah I need some help @.@

Any solutions/suggestions?

Thanks in advance for any reply!

3

There are 3 best solutions below

1
On BEST ANSWER

How about this:

Create individual counters for each survey, and store them in a database. Every time a user requests a survey, fetch the counters from the database, iterate through them, and return the first survey whose count is < 30. Redirect the user to said survey, and increment that surveys counter.

To ensure the surveys are actually submitted, you can do as follows: Create another table in the database. Every time you serve a user a survey, insert a new record into the table containing: unique_id, survey_id, timestamp. Pass the unique_id along with the survey to the user, and upon submission, remove the associated entry from the database. Now prior to selecting a survey (as described above), you fetch this data, and for any entry whose timestamp is > 10 minutes ago, you can assume it was not submitted, and decrement that surveys counter.

1
On

Your server-side-counter idea is great. To solve the issue of people not completing the survey, use cookies or some sort of a login system where participants would need to identify themselves (I assume it's an anonymous survey, so cookies is better).

  1. Have a counter on server side.
  2. When user arrives set them a cookie with survey ID calculated off the counter (1 - 18) this way you remember which survey the user belongs to.
  3. When user arrives, check for cookies with ID - if they have a cookie, send them to appropriate survey without incrementing the counter. If they don't, increment the counter and set the user a cookie with the new ID.

Whatcha think? :)

1
On

Given that A:: You have 18 surveys that need to be filled out randomly by 540 participants divided perfectly into 30 submissions per survey B: you are hosting only one html file generating 1 of the 18 surveys via javascript based on a number sent from the server

Not knowing how you are storing survey results I'd say a good strategy might be: Persist a randomized array of the sequential numbers 1-540 on the BE (used as an id for each survey) and a pointer starting from 0. When a participant requests the page, assign them the next number in the array and increment the pointer. Persist that number with that user with a cookie so they always see the same number. Assign them a survey based on that number, 1-30 is survey 1 etc.

This would ensure that if you are expecting 540 visitors, each would get one of the 540 surveys randomly. If they revisit they would still receive the same survey.

If you wanted to handle additional users past the 540th requesting the page being able to receive a survey that an older user never submitted you could increment your pointer past 540 but use a modulo operator.

nextSurveyId = randomSurveyIDs[ surveyPointer%540 ]; surveyPointer++;

This would ensure the oldest assigned surveys are re-assigned first. You could also maintain a separate dictionary of completed surveys by number to check against when selecting the next random surveyId from the original array, incrementing the pointer until you identified the next oldest incomplete survey to re-assign. When both arrays have the same length all surveys have been submitted.