Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

List of Lowest Rated items with a least fill logic

I have  a 10 point rating grid question that has 8 items.  I need to select the lowest rated items for follow up questions.  The follow up is to be a max of 5 items and if there are 'ties' for the 5 lowest rated items it should prioritize based on a least fill.  I am going to set up 8 quota questions for each of the items that have been rated.  I can get a list of the items rated from lowest to highest.  I can get an ordered list based on least fill, but can't figure how to incorporate that with my lowest rated items.  I'm having a hard time getting my head around how to configure it to those parameters.
asked Jul 28 by Jay Rutherford Platinum (50,795 points)

1 Answer

0 votes
Quite the tricky situation, but I think we can work our way out of it.  For starters, we'll want two constructed lists based off the list of eight items.  Their instructions should be:

Begin Unverified Perl
# Settings
my $gridQ = 'GridQ';
my $count = 5;

# Run
my $resps;
my $len = LISTLENGTH(PARENTLISTNAME());
for (my $i = 1; $i <= $len; $i++) {
    my $resp = GETVALUE($gridQ . '_r' . $i);
    push (@{$resps->{$resp}}, $i);
}

my $added = 0;
foreach my $key (sort { $b <=> $a } keys(%{$resps})) {
    my $itemCount = scalar(@{$resps->{$key}});
    if ($itemCount + $added <= $count) {
        for (my $i = 0; $i < $itemCount; $i++) {
            ADD(PARENTLISTNAME(), $resps->{$key}->[$i]);
        }
        $added += $itemCount;
    }
    else {
        last;
    }
}
End Unverified


Begin Unverified Perl
# Settings
my $gridQ = 'GridQ';
my $count = 5;

# Run
my $resps;
my $len = LISTLENGTH(PARENTLISTNAME());
for (my $i = 1; $i <= $len; $i++) {
    my $resp = GETVALUE($gridQ . '_r' . $i);
    push (@{$resps->{$resp}}, $i);
}

my $added = 0;
foreach my $key (sort { $b <=> $a } keys(%{$resps})) {
    my $itemCount = scalar(@{$resps->{$key}});
    if ($itemCount + $added > $count) {
        for (my $i = 0; $i < $itemCount; $i++) {
            ADD(PARENTLISTNAME(), $resps->{$key}->[$i]);
        }
        last;
    }
    $added += $itemCount;
    if ($added == $count) {
        last;
    }
}
End Unverified


"GridQ" being the name of the grid question, naturally.

Then we can add a copy of "Multi-Select Quota" to the survey:

https://sawtoothsoftware.com/resources/question-library/multi-select-quota

We'll need five quota questions with eight cells each.  Be sure to set "$numberOfQuotas" and "$numberOfChoices" to 5.  Each cell's qualification logic should look something like this:

return LISTHASPARENTMEMBER('list1', 1) || LISTHASPARENTMEMBER('list2', 1);


Finally, add this script after the "Membership is randomize" code block:

# Prioritize cells
my $clist = 'list1';
my $len = LISTLENGTH($clist);
for (my $i = 1; $i <= $len; $i++) {
    my $item = LISTVALUE($clist, $i);
    for (my $j = 0; $j < scalar(@options); $j++) {
        if ($options[$j] == $item) {
            splice(@options, $j, 1);
            last;
        }
    }
    unshift(@options, $item);
}


"list1" and "list2" being the two constructed lists.
answered Jul 29 by Zachary Platinum Sawtooth Software, Inc. (207,300 points)
Thanks Zach.  Not sure what I did there, clearly was not paying attention.  I'll give that a whirl.
Zach, the lowest rating portion doesn't seem to be working.  I checked that the 2 lists reference Q20 and the survey went to the sections that matched the quota questions, so that works.  However, my 5 lowest ratings were not the ones selected.  I gave each of the 8 items a rating of 1-8 and it selected rating 4, 5, 6, 7 and 8.
So it looks like we are selecting the 5 highest instead of the 5 lowest ratings.
Should just require swapping the "a" and "b" in the two of these:

$b <=> $a
Zach you are LEGEND!  This is quite a piece of code and works great.  Thanks for working through the details with me.  Definitely a challenging request and as always, you came through in a pinch.  Thanks again mate!
...