WeBWorK Problems

Popups not working within column displays?

Popups not working within column displays?

by tim Payer -
Number of replies: 2
Forgive me for posting this issue again but it has been over 5 weeks from my initial post without a reply and I suspect that my replies to my own post were construed as "solutions".

Could you please help with this problem?

I am unable to use Popups within columns displays.

I am unclear as to why it wont work.

Is there another context that needs to be used? Or is it something that webwork can not manage?


I changed the Context to Strings for a specific popup variable that is being used in a column format.


Context()->strings->add(A => {}, B => {}, C => {}, D => {}, E => {}, F => {}, G => {}, H => {}, I => {}, J => {}, K => {}, L => {});

$pop1 = PopUp(
["choose", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"],"c");

This will permit the correct answer, "c", to be submitted by the student, but the student will not see the choices afforded by the popup menu because the popup display does NOT "pop-up", rather it is an empty display cell.

Can anyone determine what the issue might be here? 
Or is it the case that "popups" can not be used within columns?

Any insight would be most appreciated:

Below is a recent revised code block showing the glitch.

Thanks, Tim

# DESCRIPTION   
# Data type identification
# WeBWorK problem written by TimPayer <tsp1@humboldt.edu>
# ENDDESCRIPTION

## DBsubject(Statistics)
## DBchapter(Exploratory data analysis/descriptive statistics)
## DBsection(Summary statistics)
## Institution(Humboldt State University)
## Author(Tim Payer)
## KEYWORDS(summations, mean, sd)

DOCUMENT();
loadMacros(
"PGstandard.pl",
"niceTables.pl",
"unionTables.pl",
"PGunion.pl",
"MathObjects.pl",
"PGML.pl",
"parserPopUp.pl",
"parserFormulaUpToConstant.pl"
);


Context("Numeric");
install_problem_grader(~~&std_problem_grader);
$showPartialCorrectAnswers = 1;

Context()->flags->set(
  tolerance => 0.0001,
  tolType => "absolute",
);

$spotn = random(2,7,1);

do { $nospotn = random(1, 6); } until (($nospotn != $spotn) and (gcd($nospotn,$spotn) == 1));

#$spot = list_random('two', 'three', 'four', 'five', 'six', 'seven');

if($spotn == 2 )
{
$spot ='two'; 
} elsif ($spotn == 3)
{
$spot ='three'; 
} elsif ($spotn == 4)
{
$spot ='four'; 
} elsif ($spotn == 5)
{
$spot ='five'; 
} elsif ($spotn == 6)
{
$spot ='six'; 
} else
{
$spot ='seven';
}

if($nospotn == 1 )
{
$nospot ='one'; 
} elsif ($nospotn == 2)
{
$nospot ='two'; 
} elsif ($nospotn == 3)
{
$nospot ='three'; 
} elsif ($nospotn == 4)
{
$nospot ='four'; 
} elsif ($nospotn == 5)
{
$nospot ='five'; 
} else
{
$nospot ='six';
}

$p = $spotn/($spotn + $nospotn);

## Until the error that results from a display of Popup answers within columns
## can be resolved, single lettered entries will used.

Context()->strings->add(A => {}, B => {}, C => {}, D => {}, E => {}, F => {}, G => {}, H => {}, I => {}, J => {}, K => {}, L => {});

$pop1 = PopUp(
["choose", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"],"c");


#$pop1 = "c";

$p0 = random(0.02, 0.13, 0.01);
$p1 = random(0.38, 0.48, 0.01);
$p3 = random(0.07, 0.21, 0.01);
$p2 = 1-$p0-$p1-$p3;
$mean = 0*$p0+1*$p1 +2*$p2+3*$p3;
$sd = sqrt(0**2*$p0 +1**2*$p1 +2**2*$p2 +3**2*$p3 -$mean**2);
$lb = $mean -$sd;
$ub = $mean +$sd;

##$column2 =$BCENTER.image($graph, width=>789, height=>793, tex_size=>500).$BR." ".$ECENTER;



$column1 = PGML::Format(<<END_PGML);

 
*Drawn From Lecture Notes: Week 4 Day 2.*

*6.1)* The body of the Pacific banana slug, _Ariolimax columbianus_, comes in a variety of color and spot displays. Unlike its bright yellow relative, the California banana slug, the Pacific banana slug can be seen with yellow, green, black, brown, or even white bodies. Dark spots often, but not always, cover much of its skin. The coloration and spots are thought to be dependent upon the slugs diet and local micro-climate.  
 
*6.1a)*   Given that there are [``$spot``] spotted Pacific banana slugs for every [``$nospot``] non spotted Pacific banana slug(s) in Arcata's community forest, let [`x`] represent the probability of drawing a single spotted Pacific banana slug from a single draw of both varieties of spotted and non spotted slugs.  
 
   Find the probability:  P(x) = [_____]{$p}  

*6.1b - 6.1e)*  Use the following declared variable within probability notation to answer the following questions about random draws of the Pacific banana slug from the community forest:  
 
Let [`Y`] = The number of spotted Pacific banana slugs in a random draw of four slugs.

*6.1b)*  Find the probability that three slugs are spotted and one is not from four random draws of the Pacific banana slug. Use the letter from the table below to indicate the correct probability notation for the left side of the equation and then enter the correct probability with accuracy to the fourth decimal.  
 
Use notation first then the numeric answer:  [_____]{$pop1} = [_____]{$p}  
 
 
*6.1c)*  Find the probability that all four slugs are spotted from four random draws of the Pacific banana slug. Use the letter from the table below to indicate the correct probability notation for the left side of the equation and then enter the correct probability with accuracy to the fourth decimal.  
 
*6.1d)*  Find the probability that all four slugs are all the same type. That is all four are spotted or all four are not spotted from four random draws of the Pacific banana slug. Use the letter from the table below to indicate the correct probability notation for the left side of the equation and then enter the correct probability with accuracy to the fourth decimal.  
 
*6.1e)*  Find the typical range for the number of spotted slugs drawn from a four slug draw of the Pacific banana slug. Express this range as a first standard deviation window.  
Lower sd window bound = [_____]{$lb}  
Upper sd window bound = [_____]{$ub}  

spotn = [``$spotn``]  
nospotn = [``$nospotn``] 

spot = [``$spot``]  
nospot = [``$nospot``] 
p = [``$p``]  


END_PGML




$column2 =$BCENTER."The Pacific banana slugs with and without spots: ".image("P_slug_Stephanie_Marsh.png", width=>373, height=>497, tex_size=>700).$BR."photo by Stephanie Marsh ".$BR.image("P_slug_Kelly_Fretwell.png", width=>396, height=>429, tex_size=>700).$BR."photo by Kelly Fretwell".$BR.$ECENTER;

TEXT(ColumnTable($column1,$column2));


BEGIN_TEXT
\[
\begin{array}{|c|c|c|}
\hline
\text{a.)   } P(Y < 3) & \text{e.)   } P(Y  \ge   3) &  \text{i.)   } P(Y \le 4) \\
\text{b.)   } P(Y > 3) & \text{f.)   } P(Y  <  4) &  \text{j.)   } P(Y \ge 4) \\
\text{c.)   } P(Y = 3) & \text{g.)   } P(Y  >  4) &  \text{k.)   } P(Y = 4) \cap P(Y = 4) \\
\text{d.)   } P(Y \le 3) & \text{h.)   } P(Y  =  4) &  \text{l.)   } P(Y = 4) \cup P(Y = 4) \\
\hline
\end{array}
\]


\( \ge \)
$BR
END_TEXT

BEGIN_PGML

*5.1a)*    Find the expected number of buttercups per quadrant: [``\Large{\mu_x}``] = [_____]{$mean}  


*5.1b)*    Find the expected standard deviation of buttercups per quadrant using fourth decimal accuracy: [``\Large{\sigma_x}``] = [_____]{$sd}  
 
*5.1c)*    Determine the first standard deviation window for a count of buttercups per quadrant using fourth decimal accuracy:  
Lower sd window bound = [_____]{$lb}  
Upper sd window bound = [_____]{$ub}  
 



END_PGML


BEGIN_PGML_SOLUTION
*SOLUTION*

Solution coming in 2017...
 

END_PGML_SOLUTION

ENDDOCUMENT();
In reply to tim Payer

Re: Popups not working within column displays?

by Davide Cervone -
There problem is with the "here document" that you use for your column 1. Because you use <<END_PGML, that means that variable substitution is performed by perl before PGML::Format() is called. So the popup object is stringified before the PGML is processed, and so it is no longer a PopUp object when PGML creates the answer blank for it.

Instead, you should use

$column1 = PGML::Format2(<<'END_PGML');
The quotation marks will prevent perl's variable substation on the content of the here document, and so the variable references will be properly interpreted by PGML. Also, you should use PGML::Format2() rather than PGML::Format() since that will properly handle backslashes that have been doubled automatically by PG before the problem is processed.

One you make this change, however, you will have to use the PGML means of inserting variables, so you would need to use

Given that there are [``[$spot]``] spotted Pacific banana slugs
with [``[$spot]``] rather than [``$spot``].

Try that and see if that works better for you.

Davide

In reply to Davide Cervone

Re: Popups not working within column displays?

by tim Payer -
Thank you Davide!

That worked out great.

Thanks for explaining about "Format2()" in PGML column displays.

It makes a big difference.

Tim