Skip to main content

Kinesis Support

All the topics, resources needed for Kinesis.

FocusVision Knowledge Base

Quota Examples

The information contained within this page is specific to Kinesis Survey and may be out of date. For information regarding building quotas in Decipher, click here.

This article focuses on specific code examples for building quotas using Kinesis Survey. For more information on using quotas in Kinesis Survey, see Quota Manager

1:  Standard Least-Filled Quota

least-filled quota is an assignment method that allows you to place respondents in the qualification bucket with the fewest responses among various quota groups. This method ensures equal distribution of assignments and allows the most diversity in your data. Therefore least filled quotas are preferred over completely random assignment methods that can not guarantee equal distribution.

  1. Create a hidden radio question with each possible quota selection as its choices
  2. Create a separate advanced quota filter for each choice selection within the radio question in the Quota Manager
    • Set the quota limits to be however many completes you need to cap for each assignment. If there is no limit, just set the limit to some unobtainable value, such as 999999.
    • Quota conditions should be set based on the hidden radio answers (e.g. $QLFQ==1 for the first quota, $QLFQ==2 for the second, etc.)
  3. Now place the default answer logic in the hidden radio question that will make the assignment.
    • The logic below is the most basic template, for picking 1 out of 3 choices.
    • Any question labels and quota filter id's will need to be updated depending on where this is programmed.


Basic default answer logic (radio):

$USER_quotas = array();
 
if (!$F1) $USER_quotas['1'] = $FV1;
if (!$F2) $USER_quotas['2'] = $FV2;
if (!$F3) $USER_quotas['3'] = $FV3;
 
if (asort($USER_quotas)) {
    return array_shift(array_keys($USER_quotas));
} 
else {
    return false;
}

1.1:  How it Works

The first line of the logic is creating an empty array which will be used to hold all of the qualified choices for the assignment. The syntax $USER_x is used to create custom variables in the logic, where "x" is any custom name you wish to use.

$USER_quotas = array();

The following line is repeated for each assignment choice. This statement is saying, "if the first quota filter has not yet been filled, place a value of 1 within the array $USER_quotas that is equal to the current quota count."

Checking whether a quota filter limit has been met in conditional logic uses the syntax $Fx, where "x" is the quota filter ID. If the filter limit has been exceeded, this will return a TRUE value. If it has not be exceeded and is still open, it will return a FALSE value. So the syntax, "!$F1" is checking if quota filter 1 is FALSE, or still open. This could also be written as "$F1==false".

The current quota filter count is checked in the logic by using the syntax $FVx, where "x" is the quota filter ID.

if (!$F1) $USER_quotas['1'] = $FV1;

The next line will attempt to sort the array in order from smallest to largest based on the quota counts. If it can perform this sort, meaning there is at least one assignment available, then it will return the first value in the array, which is the lowest quota count.

if (asort($USER_quotas)) {
    return array_shift(array_keys($USER_quotas));
} 

Lastly, if there was nothing to return, meaning the respondent did not qualify for any assingments or none are open, then it will return a false, or blank value. If you need to terminate anyone that does not get assigned anything here, this would need to be handled within separate programming logic.

else {
    return false;
}

1.2:  Conditional Quota Assignment

You can add any number of conditional statements within the “if” statements in each line to expand the requirements for assigning each group. For example, if you are needing to assign the item based on a previous selection in the survey.

$USER_quotas = array();
 
if ($Q1[1]==1 AND !$F1) $USER_quotas['1'] = $FV1;
if ($Q1[2]==1 AND !$F2) $USER_quotas['2'] = $FV2;
if ($Q1[3]==1 AND !$F3) $USER_quotas['3'] = $FV3;
 
if (asort($USER_quotas)) {
    return array_shift(array_keys($USER_quotas));
} 
else {
    return false;
}

1.3:  Return Single Quota (Radio Question)

When returning a response for a radio question you will need to use the following lines at the end of the code. This is used in the examples above.

if (asort($USER_quotas)) {
    return array_shift(array_keys($USER_quotas));
} 
else {
    return false;
}

1.4:  Return Multiple Quotas (Checkbox Question)

When returning multiple assignments (ie. 2 out of 5) you will need to use the following lines at the end of the code. The example below will return the lowest 2 items. You can update the number “2” below to any number of items.

if (asort($USER_quotas)) {
    return array_slice(array_keys($USER_quotas),0,2);
} 
else {
    return false;
}

1.5:  Prioritize a Specific Quota

By always assigning a value of -1 to an item, you are ensuring that it is always selected because it will always have the lowest quota value. In the example below, the first item has priority over the others. Meaning, if the first items conditions are true, then it will always be selected no matter what.

$USER_quotas = array();
 
if ($Q1[1]==1 AND !$F1) $USER_quotas['1'] = -1;
if ($Q1[2]==1 AND !$F2) $USER_quotas['2'] = $FV2;
if ($Q1[3]==1 AND !$F3) $USER_quotas['3'] = $FV3;
 
if (asort($USER_quotas)) {
    return array_shift(array_keys($USER_quotas));
} 
else {
    return false;
}

1.6:  Prioritizing a Group of Quotas

In the example below, priority is placed on the first two items. If they qualify for one of the priority items it will pick the one that is least-filled. If they don’t qualify for either of those the logic then checks for the remaining items and picks the least-filled.

$USER_quotas = array();
 
if ($Q1[1]==1 AND !$F1) $USER_quotas['1'] = $FV1;
if ($Q1[2]==1 AND !$F2) $USER_quotas['2'] = $FV2;

if (count($USER_quotas)==0) {
	if ($Q1[3]==1 AND !$F3) $USER_quotas['3'] = $FV3;
	if ($Q1[4]==1 AND !$F4) $USER_quotas['4'] = $FV4;
	if ($Q1[5]==1 AND !$F5) $USER_quotas['5'] = $FV5;
}
 
if (asort($USER_quotas)) {
    return array_shift(array_keys($USER_quotas));
} 
else {
    return false;
}

2:  Demos

2.1:  Least-Filled Quota with Priority Item

Least filled quotas are the best way to ensure that all concepts within a survey are getting shown an equal amount of times. Sometimes however, it is necessary to have one or more concepts have priority over others. These concepts always get shown and all others get shown an equal amount of times based on least filled quotas.

In this demo the concepts to be selected from are based on a preliminary checkbox question.

 

DEMO QUESTIONNAIRE

Qcomp. Hidden copy of Q1. Will contain the logic below to make the selection.

Q1. Please select which vegetables you buy. (select all that apply)

  1. Lettuce (priority)
  2. Tomatoes
  3. Corn
  4. Squash
  5. Beets

Q2. Which of these two do you prefer? [Only show 2 concepts using least filled quotas giving priority to Lettuce]

  1. Lettuce (priority)
  2. Tomatoes
  3. Corn
  4. Squash
  5. Beets


DEMO LOGIC

Since the quotas and the logic need to reference each other, first create a hidden checkbox copied from Q1. Then you can create quota filters for each concept based on the hidden checkbox (Qcomp).

Example: Quota Filter condition - Lettuce: $Qcomp[1]==1

Now that your quotas are created you can place the following logic into the default answer condition of the hidden checkbox. Now you will be able to reference this hidden checkbox within questions/groups later in the survey to determine what gets shown.

$USER_quotas=array();

if ($Q1[1]==1) $USER_quotas['1']=-1;
if ($Q1[2]==1) $USER_quotas['2']=$FV2;
if ($Q1[3]==1) $USER_quotas['3']=$FV3;
if ($Q1[4]==1) $USER_quotas['4']=$FV4;
if ($Q1[5]==1) $USER_quotas['5']=$FV5;

if (count($USER_quotas)>0) {

asort($USER_quotas);

$USER_selection=array_slice(array_keys($USER_quotas),0,2);

return $USER_selection;
}

else return false;

2.2:  Least-Filled Quota with Priority Groups Demo

It is sometimes necessary to have different groups of options that are weighted more than others within a single list of options.

 

DEMO QUESTIONNAIRE

First we will need to create a checkbox question that has all the possible options available. These options could be in any necessary order, but for simplicity, we have arranged by highest to lowest priority group for our least filled quotas.

Q1. Please select the vegetables you buy. (select all that apply)

  1. Lettuce (part of Highest Priority group)
  2. Tomatoes (part of Highest Priority group)
  3. Corn (part of Highest Priority group)
  4. Squash (part of Second Highest Priority group)
  5. Beets (part of Second Highest Priority group)
  6. Potatoes (part of Second Highest Priority group)
  7. Peppers (part of Third Highest Priority group)
  8. Sprouts (part of Third Hightest Priority group)
  9. Celery (part of Third Highest Priority group)


In this example, we have 3 separate priority groups, so we will need to create 3 hidden checkbox questions -- one for each priority group. Each of these 3 checkbox questions will contain the logic below to make the selection.

QPriorityOne. Priority One.

  1. Lettuce
  2. Tomatoes
  3. Corn

QPriorityTwo. Priority Two.

  1. Squash
  2. Beets
  3. Potatoes

QPriorityThree. Priority Three.

  1. Peppers
  2. Sprouts
  3. Celery


Finally, we are able to reference the results of the 3 hidden checkboxes to determine what is shown later in the survey.

Q2. Which of these would you like to answer additional questions for? [Only show 4 concepts using least filled quotas giving priority to the groups as indicated in parentheses at Q1 above.]

  1. Lettuce (part of Highest Priority group)
  2. Tomatoes (part of Highest Priority group)
  3. Corn (part of Highest Priority group)
  4. Squash (part of Second Highest Priority group)
  5. Beets (part of Second Highest Priority group)
  6. Potatoes (part of Second Highest Priority group)
  7. Peppers (part of Third Highest Priority group)
  8. Sprouts (part of Third Hightest Priority group)
  9. Celery (part of Third Highest Priority group)


DEMO LOGIC

You will now need to setup a quota for each option in Q1.

Example: Quota Filter condition - Highest Priority One: $Q1[1]==1

Now that your quotas are created, you can place the following logic examples into the respective default answer condition of each hidden priority question. Specify the maximum number of options you want to return, in this case 4 (since we will only be returning a max of 4 options at Q2). The 4 will need to be changed in the other 2 priority questions as well.

Priority One:

$USER_count = 4;
$USER_quotas=array();

$USER_selection = array();
if ($Q1[1]==1) $USER_quotas['1']=$FV1;
if ($Q1[2]==1) $USER_quotas['2']=$FV2;
if ($Q1[3]==1) $USER_quotas['3']=$FV3;

if (count($USER_quotas)>0 AND $USER_count>0){

asort($USER_quotas);

$USER_selection=array_slice(array_keys($USER_quotas),0,$USER_count);

return $USER_selection;
}

else return false;


Priority Two:

$USER_count = 4 - (count(array_keys($QPriorityOne,1)));
$USER_quotas=array();

$USER_selection = array();
if ($Q1[4]==1) $USER_quotas['1']=$FV4;
if ($Q1[5]==1) $USER_quotas['2']=$FV5;
if ($Q1[6]==1) $USER_quotas['3']=$FV6;

if (count($USER_quotas)>0 AND $USER_count>0){

asort($USER_quotas);

$USER_selection=array_slice(array_keys($USER_quotas),0,$USER_count);

return $USER_selection;
}

else return false;


Priority Three:

$USER_count = 4 - (count(array_keys($QPriorityOne,1)) + count(array_keys($QPriorityTwo,1)));
$USER_quotas=array();

$USER_selection = array();
if ($Q1[7]==1) $USER_quotas['1']=$FV7;
if ($Q1[8]==1) $USER_quotas['2']=$FV8;
if ($Q1[9]==1) $USER_quotas['3']=$FV9;

if (count($USER_quotas)>0 AND $USER_count>0){

asort($USER_quotas);

$USER_selection=array_slice(array_keys($USER_quotas),0,$USER_count);

return $USER_selection;
}

else return false;


Now you will be able to reference these hidden checkboxes within questions later in the survey (such as Q2 above) to determine what gets shown.

Logic for Q2

$USER_selection = array();

if ($QPriorityOne[1]==1) $USER_selection['1']=1;
if ($QPriorityOne[2]==1) $USER_selection['2']=2;
if ($QPriorityOne[3]==1) $USER_selection['3']=3;

if ($QPriorityTwo[1]==1) $USER_selection['4']=4;
if ($QPriorityTwo[2]==1) $USER_selection['5']=5;
if ($QPriorityTwo[3]==1) $USER_selection['6']=6;

if ($QPriorityThree[1]==1) $USER_selection['7']=7;
if ($QPriorityThree[2]==1) $USER_selection['8']=8;
if ($QPriorityThree[3]==1) $USER_selection['9']=9;

return $USER_selection;

2.3:  Least-Filled Quota with Nested Groups

For many surveys it's necessary to display a certain amount of concepts across different groups, usually based on demographic assignments. In the following demo there are 3 concepts (A,B,C) that need to get displayed equally across three different age groups where each respondent only sees one concept.

Total Completes: 900 (n=900) split evenly across 3 concepts and 3 age groups.

Age Concept # of completes
Under 35 Concept A 100
 
  Concept B 100
  Concept C 100
35-59 Concept A 100
  Concept B 100
  Concept C 100
60 and over Concept A 100
  Concept B 100
  Concept C 100
  Total(n) 900


DEMO QUESTIONNAIRE

Qcomp. Hidden Radio, makes least filled quota selection based on Qage answer.

  1. Under 35 - Concept A
  2. Under 35 - Concept B
  3. Under 35 - Concept C
  4. 35-59 - Concept A
  5. 35-59 - Concept B
  6. 35-59 - Concept C
  7. 60 and over- Concept A
  8. 60 and over - Concept B
  9. 60 and over - Concept C

Qage. Which age group do you belong to?

  1. Under 35
  2. 35-59
  3. 60 and over

[PAGEBREAK]

Repeat question groups for each concept (A,B,C), condition based on Qcomp least filled quota selection.


DEMO LOGIC:

Since the quotas and the logic need to reference each other, first create the hidden radio, Qcomp. Then you can create quota filters for each concept based on this hidden radio. Your quotas can be set for each concept group's limit, in this case 100. Since the logic checks whether or not the filter is full before assigning that concept, they can have different limits (ex. 50% Concept A, 25% Concept B, 25% Concept C.) The variables with syntax $F1 reference the quota limit and can be either true or false and the variables with syntax $FV1 reference the actual count number. In both the ending number represents the quota filter id and may need to be adjusted if there are any preexisting quota filters.

Example Quota Filter condition: Under 35-ConceptA: $Qcomp==1

Now that your quotas are created you can place the following logic into the default answer condition of the hidden radio. Now you will be able to reference this hidden radio within questions/groups later in the survey to determine what gets shown.

Note: Using a hidden radio and the logic below is specifically for scenarios when you need to select one individual concept. See 'Multiple Concepts' for returning multiple concept selections.

$USER_quotas=array();
$USER_selection=array();

if ($Qage==1)
{
	if($F1==false) $USER_quotas['1']=$FV1;
	if($F2==false) $USER_quotas['2']=$FV2;
	if($F3==false) $USER_quotas['3']=$FV3;
}

if ($Qage==2)
{
	if($F4==false) $USER_quotas['4']=$FV4;
	if($F5==false) $USER_quotas['5']=$FV5;
	if($F6==false) $USER_quotas['6']=$FV6;
}

if ($Qage==3)
{
	if($F7==false) $USER_quotas['7']=$FV7;
	if($F8==false) $USER_quotas['8']=$FV8;
	if($F9==false) $USER_quotas['9']=$FV9;
}

if (count($USER_quotas)>0){

	asort($USER_quotas);

	$USER_keys=array_keys($USER_quotas);
	array_push($USER_selection, $USER_keys[0]);

return $USER_selection[0];
}

else return false;


Multiple Concepts

The scenario above is only returning one selection per respondent. If you need to select multiple concepts use the logic below placed in the default answer condition of a hidden checkbox instead of a radio. A radio is preferred for one selection since you can use standard piping.

In the logic below, the line: $USER_selection=array_slice(array_keys($USER_quotas),0,2);, determines how many elements are returned. Change the number '2' to however many elements needed.

$USER_quotas=array();
$USER_selection=array();

if ($Qage==1)
{
	if($F1==false) $USER_quotas['1']=$FV1;
	if($F2==false) $USER_quotas['2']=$FV2;
	if($F3==false) $USER_quotas['3']=$FV3;
}

if ($Qage==2)
{
	if($F4==false) $USER_quotas['4']=$FV4;
	if($F5==false) $USER_quotas['5']=$FV5;
	if($F6==false) $USER_quotas['6']=$FV6;
}

if ($Qage==3)
{
	if($F7==false) $USER_quotas['7']=$FV7;
	if($F8==false) $USER_quotas['8']=$FV8;
	if($F9==false) $USER_quotas['9']=$FV9;
}

if (count($USER_quotas)>0){

	asort($USER_quotas);

	$USER_selection=array_slice(array_keys($USER_quotas),0,2);

	return $USER_selection;
}

else return false;


Modifications

The demo above may not be sufficient for every situation but can be a great starting point to build more complex logic statements.

  • You can attach negative values to any elements if more than one take priority in the logic. For example, -2 could be attached to the first priority group, and -1 could be used for the second priority group.
  • The number '2' in the line of code: $USER_selection=array_slice(array_keys($USER_quotas),0,2); determines how many elements are selected. This can be changed or conditioned within the logic like so:
if ($Q1[1]==1) {
	$USER_selection=array_slice(array_keys($USER_quotas),0,4);
}
else {
	$USER_selection=array_slice(array_keys($USER_quotas),0,2);
}
  • Was this article helpful?