When the original least-full cells are not available
This topic explains how you can choose other cells to pend when the cells that were originally pended as being the least full are no longer available. This may be because one or more of those cells has been filled during the period that the current interview has been stopped, or it may be because the respondent has snapped back and changed the answers to the quota-controlled question so that none of the original responses is now chosen.
The script asks respondents which brands of ice cream they buy and then, for the two brands whose quotas are least full, asks which is the favorite flavor in each brand. The number of cells to pend (two) is set in the QUOTA_Matrix table. The metadata for the example is:
Brands define
{
Alpine,
HelenB "Helen Bradley's",
DFresh "Dairy Fresh",
Kentish "Kentish Farm",
Finborough,
Alsace
};
IceCream "Which brands of ice cream do you buy?" categorical [1..]
{use Brands};
PendedBrands "" categorical [1..]
{use Brands};
FlavorGrid "Which are your favorite flavors in the following brands
of ice cream?" loop
{use Brands} fields
(
Flavor "" categorical [1..1]
{
Chocolate, Mint,
Toffee "Toffee crunch",
Raspberry "Raspberry ripple",
Strawberry "Strawberry",
Vanilla "Vanilla",
OtherFlavor "Other"
};
) column expand grid;
AllFull "All our interviewing targets have been met. I'm sorry to
have troubled you." info;
In this section, the CellsPended question is designed to store the names of the brands that were pended because their cells were the least full so that this information is readily available when interviews are restarted.
The routing section of the script is:
IceCream.Ask()
'Terminate interviews where no cells can be pended
If Not _
(PendQuotas(IceCream,PendedBrands, QuotaEngine.QuotaGroups["IceCream"])) Then
IOM.Texts.InterviewStopped= AllFull.Label
IOM.Terminate(Signals.sigOverQuota)
End If
FlavorGrid.QuestionFilter = PendedBrands.Response
FlavorGrid.Ask()
' Pend quotas and return names of pended brands
Function PendQuotas(QuotaQuestion, CellsPended, QuotaGroupToPend)
Dim pend_result, orig_answers
PendQuotas = False
' A new interview so pend brands and set question filter
If (CellsPended.Info.OffPathResponse Is Null) Then
pend_result = QuotaGroupToPend.Pend()
If (IsSet(pend_result,QuotaResultConstants.qrWasPended)) Then
' Save the pended cell information
CellsPended.Response = _
CreateFilter(CellsPended.Categories, QuotaGroupToPend.Quotas)
PendQuotas = True
End If
Exit Function
End If
' A snapback that replaces/deletes the answers whose quotas were previously
' pended, so pend new cells based on current answers.
If Not (QuotaQuestion.ContainsAny(CellsPended.Info.OffPathResponse)) Then
pend_result = QuotaGroupToPend.Pend()
If (IsSet(pend_result,QuotaResultConstants.qrWasPended)) Then
CellsPended.Response.Value = _
CreateFilter(CellsPended.Categories, QuotaGroupToPend.Quotas)
PendQuotas = True
Exit Function
End If
End If
' A restarted interview, or a snapback that retains some of the previously
' pended answers. Pend the cells that were previously pended if they are
' still open. If some cells are now full or the responses are no longer
' chosen, ignore them.
If (QuotaQuestion.ContainsAny(CellsPended.Info.OffPathResponse)) Then
orig_answers = QuotaQuestion.Response.Value
QuotaQuestion.Response.Value = _
QuotaQuestion.Response.Value * CellsPended.Info.OffPathResponse
pend_result = QuotaGroupToPend.Pend()
QuotaQuestion.Response.Value = orig_answers
If (IsSet(pend_result,QuotaResultConstants.qrWasPended)) Then
CellsPended.Response.Value = _
CreateFilter(CellsPended.Categories, QuotaGroupToPend.Quotas)
PendQuotas = True
Exit Function
End If
End If
' A restarted interview or a snapback that that retains some of the
' previously pended answers, but where the originally pended cells are now
' full. If there are other answers that can be pended, do so.
If (QuotaQuestion.Response.Value > CellsPended.Info.OffPathResponse) Then
pend_result = QuotaGroupToPend.Pend()
If (IsSet(pend_result,QuotaResultConstants.qrWasPended)) Then
' Save the pended cell information
CellsPended.Response = _
CreateFilter(CellsPended.Categories, QuotaGroupToPend.Quotas)
PendQuotas = True
End If
Exit Function
End If
' Cannot pend any cells so terminate interview.
PendQuotas = False
End Function
' Build list of names of pended brands
Function CreateFilter(Categories, Quotas)
Dim pended_quota, filter
For Each pended_quota In Quotas.WasPendedList
filter = filter + GetCategoryFromQuota(Categories,pended_quota)
Next
CreateFilter = filter
End Function
' Get category names of pended brands
Function GetCategoryFromQuota(Categories, Quota)
Dim category
GetCategoryFromQuota = "{}"
For Each category in Categories
If (Find(Quota.Expression, "{" + category.Name + "}") >= 0) Then
GetCategoryFromQuota = CCategorical(category)
Exit Function
End If
Next
End Function
The comments in the script summarize the key steps in the script. As you can see, the PendQuotas function has five possible course of action.
▪If this is a new interview (that is, the CellsPended question has no value) then pend the two cells with the least full quotas.
▪If the current response to the quota-controlled question does not contain either of the cells that were previously pended, pend new cells based on the current answers to the question. Since a restarted interview retrieves the answers to questions from the case data in the value cache, you would expect the current answer to match the previous one, so this situation applies only to snapbacks where the answer to the question has been manually changed.
▪If the current response to the quota-controlled question contains at least one of the previously pended cells, test whether these cells can be repended. If so, repend them even if this means that fewer cells are pended than would normally be the case. This situation applies to restarts from sample management and also to snapbacks where the answer to the question has been changed but still includes some of the previously pended responses. If the cells cannot be repended, see whether there are other cells that can be pended instead.
▪If the previously pended cells are a subset of the current response to the quota-controlled question (that is, the current question contains all the pended cells and more) and the previously pended cells are now full, try pending other answers that were selected at the time the cells were originally pended.
▪If no cells can be pended, set a flag for terminating the interview.
The following table shows four interviews that illustrate these actions taking place. The target for each brand of ice cream is two interviews and the two least full cells can be pended each time. These interviews were the first that took place on a new project. They were run consecutively in the order shown and no other interviews took place during this period.
Interview ID
|
IceCream
|
PendedBrands
|
FlavorGrid
|
1
|
Alpine, Helen Bradley’s, Dairy Fresh
|
Helen Bradley’s, Dairy Fresh
|
Answered
|
2
|
Alpine, Helen Bradley’s, Dairy Fresh
|
Alpine, Helen Bradley’s
|
Click Stop
|
3
|
Alpine, Helen Bradley’s
|
Alpine, Helen Bradley’s
|
Answered
|
2 (Restarted)
|
Alpine, Helen Bradley’s, Dairy Fresh
|
Alpine
|
Answered
|
4
|
Alpine, Kentish Farm, Alsace
|
Kentish Farm, Alsace
|
Click Previous to go back to IceCream
|
4 (Snapback)
|
Helen Bradley’s, Finborough
|
Finborough
|
Answered
|
5
|
Helen Bradley’s, Kentish Farm, Alsace
|
Kentish Farm, Alsace
|
Click Previous to go back to IceCream
|
5 (Snapback)
|
Alpine, Finborough, Alsace
|
Alsace
|
Answered
|
Interviews 1 to 3 show the effect of stopping an interview and then restarting it after some of the quotas that were originally pended for that interview have been filled. When interview 2 is stopped, the pend counts for Alpine and Helen Bradley’s are rolled back so that there are still two interviews possible for Alpine and one interview possible for Helen Bradley’s. At the end of interview 3 the quota for Helen Bradley’s has been filled, so when interview 2 restarts only Alpine is repended. The script does not attempt to pend additional responses (in this case, Dairy Fresh which was originally chosen but not pended) because this may have mean that some questions may be unnecessarily repeated if they are based on the pended brands.
For example, suppose that, in the original position of the interview, the respondent answered nine out of ten questions about Alpine and Helen Bradley’s yogurts and then stopped the interview. On the restart, Helen Bradley’s in no longer pended so the questions for that brand are ignored and the replay runs all the way to the tenth question about Alpine yogurt. If the script had pended Dairy Fresh as part of the replay, the replay could stop at the first question for Dairy Fresh and the interview would runs in the normal way from there. The questions about Alpine would be displayed with their existing answers while the questions about Dairy Fresh would be displayed with no answers selected.
Note If you want the script to behave in this way (that is, to pend additional answers to try to ensure that two brands are always pended), remove the Exit Function statement from the code section that starts:
If (QuotaQuestion.ContainsAny(CellsPended.Info.OffPathResponse)) Then
so that the script continues with the test for other cells to pend.
Interview 4 starts. It shows the result of snapping back and completely changing the brands used. Helen Bradley’s is already full, but Finborough is not so it is pended.
Interview 5 starts. It shows the result of snapping back, deleting one of the pended brands and choosing another in its place. At first, Kentish Farm and Alsace are pended, but the respondent snaps back, deletes Helen Bradley’s and Kentish Farm, and chooses Alpine and Finborough in their place. Neither of these cells is full, but Finborough is pended because it is less full than Alpine, which already has one interview. Alsace remains pended because it was one of the originally pended cells.
See also