Forums
Search results: 169
I am not sure what you are talking about by clicking "get a new version"? Are you talking about about the problemRandomize.pl macro? It doesn't look like you are using that macro. Or do you load it via a custom PGcourse.pl macro?
You should consider switching to using webworks built in problem randomization instead if you are somehow using the problemRandomize.pl macro. That macro is deprecated, and will probably be eventually removed.
If you are using the built in problem randomization approach, that changes the actual seed of the problem and so when you get a new problem version you will see the new images. However, the problemRandomization.pl macro does not change the problem seed. It sets a new seed inside the problem by calling srand. This does not change the problem parameters that are used to generated the uuid for the image, and so you will not see images regenerated. However, setting $refreshCachedImages = 1 (do this before you even start defining the graphs in the problem) will regenerate the images. Now, this will not fix the browser caching issue. Although the images are regenerated, your browser sees the same resource name, and so it just loads from cache.
The problem here is that you are using deprecated code and features. Consider updating your approaches. Yes, I realize documentation on this is scarce at this point. Hopefully we get around to updating these things soon.
There are many ways how to change the seed. I work in Emacs editor on local file and refresh the web browser automatically when the file is saved. So for me the easiest way is to use SRAND in the pg file. If you edit the file in the web browser, you use probably another method to change the version of the problem. And as you wrote, this has to be removed in the final version.
Concerning Firefox, clicking refresh with shift button should reload the webpage and all its content. Without using the cache.
here is my current code
DOCUMENT();
loadMacros("PG.pl",
"PGstandard.pl",
"PGchoicemacros.pl",
"PGgraphmacros.pl",
"extraAnswerEvaluators.pl",
"MathObjects.pl",
"PGcourse.pl"
);
TEXT(beginproblem());
Context("Numeric");
Context("Numeric")->functions->add(
step => {
class => 'Parser::Legacy::Numeric',
perl => 'Parser::Legacy::Numeric::do_step'
},
);
$showPartialCorrectAnswers = 1;
$refreshCachedImages = 1;
#$a = 2;
#$b = 3;
Context()->variables->add(t=>'Real');
Context()->variables->add(F=>'Real');
$func = Formula("sin(2 pi F t)");
@eq = ("\( y=-2f(-t) \)",
"\( y=2f(-t) \)",
"\( y=-2f(t) \)",
"\( y=-f \left( - \frac{1}{2} t \right) \)",
"\( y=-\frac{1}{2} f(-t) \)",
"\( y=f \left( \frac{1}{2} t \right) \)" );
@descript = ("is a reflection about both the \(t\)-axis and \(y\)-axis as well as a vertical stretch by a factor of 2.",
"is a horizontal reflection about the \(y\)-axis as well as a vertical stretch by a factor of 2.",
"is a vertical reflection about the \(t\)-axis as well as a vertical stretch by a factor of 2.",
"is a reflection about both the \(t\)-axis and \(y\)-axis as well as a horizontal stretch by a factor of 2.");
$p1[0] = FEQ("step(t) - step(t-1) for t in <-1,10> using color:blue and weight:2");
$p2[0] = FEQ("step(t) - step(t-0.5) for t in <-1,10> using color:blue and weight:2");
$p3[0] = FEQ("step(t) - step(t-2) for t in <-1,10> using color:blue and weight:2");
$p4[0] = FEQ("step(t+1) - step(t) for t in <-1,10> using color:blue and weight:2");
$p1[1] = FEQ(qq! step(t) - step(t-0.5) + step(t) - step(t-2) for t in <-1,10> using color:blue and weight:2!);
##$graphf = init_graph(@opts);
## (plot_functions($graphf,"$f for x in <-$dom,$dom> using color:blue"))[0]->steps(250);
## $labelf = new Label(@gr_lab, 'y = f(x)', 'blue' , 'center', 'center');
## $graphf->lb($labelf);
$gr = init_graph(-2,-2,10,4,'axes'=>[0,0],'ticks'=>[6,6] );
$gr->lb('reset');
for ($i = -2; $i <= 4; $i++) { if ($i != 0) {
$gr->lb(new Label(-.1,$i,$i,'black','right','middle')) }};
for ($i = -1; $i <= 5; $i++) {
$gr->lb(new Label(2*$i,-.2,2*$i,'black','center','top')) };
$gr->lb(new Label(-.2,4.5,"y",'black','right','top'));
$gr->lb(new Label(9.5,-.2,"t",'black','right','top'));
$gr->lb(new Label(3.5,4,"s(t)",'black','left','bottom'));
## parentheses in ($fn1) are necessary
($f1n) = plot_functions( $gr, $p1[1] );
$f1n->steps(200);
$orig = image(insertGraph($gr),width => 400,height => 300,tex_size => 600);
$F = random(1,5,1);
$g[0] = "sin(2*pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$g[1] = "sin(2*pi*(-$F*t)) for t in <-1,1> using color:blue and weight:2";
$g[2] = "sin(pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$g[4] = "cos(2*pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$g[3] = "-cos(2*pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$g[5] = "sin(0.5*pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$graph[0] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[1] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[2] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[3] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[4] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[5] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
for ($j = 0; $j <=5; $j++) {
$graph[$j]->lb('reset');
$graph[$j]->lb(new Label(-.07,-1,-1,'black','right','middle'));
$graph[$j]->lb(new Label(-.07,1,1,'black','right','middle'));
for ($i = -3; $i <= 3; $i++) { if ($i != 0) {
$graph[$j]->lb(new Label(0.25*$i,-.2,0.25*$i,'black','center','top')) }};
$graph[$j]->lb(new Label(-.05,1.9,"y",'black','right','top'));
$graph[$j]->lb(new Label(0.95,0.1,"t",'black','right','bottom'));
plot_functions( $graph[$j], $g[$j]);
$fig[$j] = image(insertGraph($graph[$j]),width => 240,height => 180,tex_size => 200); };
# $pick = random(0,3,1);
# if ( $pick != 0 ) { $temp_eq = $eqn[0];
# $temp_gr = $fig[0];
# $eq[0] = $eq[$pick];
# $fig[0] = $fig[$pick];
# $eq[$pick] = $temp_eq;
# $fig[$pick] = $temp_gr};
$mc = new_multiple_choice();
$mc->qa('On a separate piece of paper, sketch an accurate graph of this function for \( F = $F \) and \( t \in [-1, 1] \). Which (if any) of the graphs below matches the graph you drew?','$fig[0]');
$mc->extra('$fig[1] $BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig[2] $BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig[3] $BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig[4] $BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig[5] $BR $BITALIC(click on image to enlarge)$EITALIC');
$mc->makeLast('None of the above');
Context()->texStrings;
BEGIN_TEXT
This problem reflects Problem 1.21a in the text
$PAR
Consider the function
$BR
$BR
\( y = $func \).
$BR
$BR
\{ $mc->print_q() \} $BR
\{ $mc->print_a() \}
END_TEXT
Context()->normalStrings;
ANS(radio_cmp($mc->correct_ans));
## force a refresh of the image after changes
Context()->texStrings;
SOLUTION(EV3(<<'END_SOLUTION'));
$PAR
$BBOLD SOLUTION $EBOLD
$PAR
Setting \( F = $F \) gives the function \( y = \sin(2 \pi $F t) \). This has $F cycles in one unit of time. It starts at zero at t = 0, since it is a sine and is positive for the first values greater than zero. Therefore the correct graph is
$PAR
$BCENTER
$fig[0]
$ECENTER
$BR
which is answer \{ $mc->correct_ans \}.
END_SOLUTION
Context()->normalStrings;
ENDDOCUMENT();
I don't understand. If you change the seed in the problem using SRAND then it generates a problem correctly for the seed in SRAND, but all versions of the problem obtained using the "get a new version" have exactly the same frequency. That doesn't give the student a new problem. Maybe I'm misinterpreting your method.
I've done the same thing by changing the seed in the webwork editor and using the "view" tab. That changes the images to agree with the frequency. But the student can't change the seed. The "get a new version" button in the displayed problem shows a new frequency but the same images as the original problem and original seed.
I tried clearing the cache in the browser using ctrl-shift-delete prior to hitting the "get a new version" button (without using SRAND) that still uses the same images even though the frequency F changes.
I've done all of these experiments on Firefox, Chrome and Edge.
Thanks for help.
Note that there is no need to set $refreshCachedImages = 1. Webwork will always generate a new image for different problem seeds (as well as different users, different problem set version numbers, different course IDs, different set numbers, different problem numbers, and different problem unique ids). It also takes into account the number of images in a problem and makes sure those are all generated. The only time that you need to set $refreshCachedImages = 1 is if you are testing things and want to force the image to be regenerated. Even then you usually don't need it because webwork also regenerates images if the source file has changed. In fact for a problem that is used in production, you should not set $refreshCachedImages = 1. Webwork will take care of ensuring that the images are generated differently when they should be as per above. Setting $refreshCachedImages = 1 will force images to always be regenerated, even when they should not be, and this results in extra load on the server.
I tried the problem with different seed (used SRAND(406); etc directly in the PG file) and the images behave as expected - they change when the seed changes. So you should probably look for the error outside the pg file.
I'm not discovering my error, so I'm asking for help. The problem generates a sinusoid with random frequency and asks students to identify the graph of the function. It works the first time, but fails to work when the student or prof uses get a new version of the problem. The frequency is changed in the question formulation, but the graphs are not changed. I've checked the macro files, set $refreshCachedImages = 1 in various places.
Here's the code, Thanks
DOCUMENT();
loadMacros("PG.pl",
"PGstandard.pl",
"PGchoicemacros.pl",
"PGgraphmacros.pl",
"extraAnswerEvaluators.pl",
"MathObjects.pl",
"PGcourse.pl"
);
TEXT(beginproblem());
Context("Numeric");
Context("Numeric")->functions->add(
step => {
class => 'Parser::Legacy::Numeric',
perl => 'Parser::Legacy::Numeric::do_step'
},
);
$showPartialCorrectAnswers = 1;
#$a = 2;
#$b = 3;
Context()->variables->add(t=>'Real');
Context()->variables->add(F=>'Real');
$func = Formula("sin(2 pi F t)");
@eq = ("\( y=-2f(-t) \)",
"\( y=2f(-t) \)",
"\( y=-2f(t) \)",
"\( y=-f \left( - \frac{1}{2} t \right) \)",
"\( y=-\frac{1}{2} f(-t) \)",
"\( y=f \left( \frac{1}{2} t \right) \)" );
@descript = ("is a reflection about both the \(t\)-axis and \(y\)-axis as well as a vertical stretch by a factor of 2.",
"is a horizontal reflection about the \(y\)-axis as well as a vertical stretch by a factor of 2.",
"is a vertical reflection about the \(t\)-axis as well as a vertical stretch by a factor of 2.",
"is a reflection about both the \(t\)-axis and \(y\)-axis as well as a horizontal stretch by a factor of 2.");
$p1[0] = FEQ("step(t) - step(t-1) for t in <-1,10> using color:blue and weight:2");
$p2[0] = FEQ("step(t) - step(t-0.5) for t in <-1,10> using color:blue and weight:2");
$p3[0] = FEQ("step(t) - step(t-2) for t in <-1,10> using color:blue and weight:2");
$p4[0] = FEQ("step(t+1) - step(t) for t in <-1,10> using color:blue and weight:2");
$p1[1] = FEQ(qq! step(t) - step(t-0.5) + step(t) - step(t-2) for t in <-1,10> using color:blue and weight:2!);
##$graphf = init_graph(@opts);
## (plot_functions($graphf,"$f for x in <-$dom,$dom> using color:blue"))[0]->steps(250);
## $labelf = new Label(@gr_lab, 'y = f(x)', 'blue' , 'center', 'center');
## $graphf->lb($labelf);
$gr = init_graph(-2,-2,10,4,'axes'=>[0,0],'ticks'=>[6,6] );
$gr->lb('reset');
for ($i = -2; $i <= 4; $i++) { if ($i != 0) {
$gr->lb(new Label(-.1,$i,$i,'black','right','middle')) }};
for ($i = -1; $i <= 5; $i++) {
$gr->lb(new Label(2*$i,-.2,2*$i,'black','center','top')) };
$gr->lb(new Label(-.2,4.5,"y",'black','right','top'));
$gr->lb(new Label(9.5,-.2,"t",'black','right','top'));
$gr->lb(new Label(3.5,4,"s(t)",'black','left','bottom'));
## parentheses in ($fn1) are necessary
($f1n) = plot_functions( $gr, $p1[1] );
$f1n->steps(200);
$orig = image(insertGraph($gr),width => 400,height => 300,tex_size => 600);
$F = random(1,5,1);
$g[0] = "sin(2*pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$g[1] = "sin(2*pi*(-$F*t)) for t in <-1,1> using color:blue and weight:2";
$g[2] = "sin(pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$g[4] = "cos(2*pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$g[3] = "-cos(2*pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$g[5] = "sin(0.5*pi*$F*t) for t in <-1,1> using color:blue and weight:2";
$graph[0] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[1] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[2] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[3] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[4] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
$graph[5] = init_graph(-1,-2,1,2,'axes'=>[0,0],'ticks'=>[8,8] );
for ($j = 0; $j <=5; $j++) {
$graph[$j]->lb('reset');
$graph[$j]->lb(new Label(-.07,-1,-1,'black','right','middle'));
$graph[$j]->lb(new Label(-.07,1,1,'black','right','middle'));
for ($i = -3; $i <= 3; $i++) { if ($i != 0) {
$graph[$j]->lb(new Label(0.25*$i,-.2,0.25*$i,'black','center','top')) }};
$graph[$j]->lb(new Label(-.05,1.9,"y",'black','right','top'));
$graph[$j]->lb(new Label(0.95,0.1,"t",'black','right','bottom'));
plot_functions( $graph[$j], $g[$j]);
$fig[$j] = image(insertGraph($graph[$j]),width => 240,height => 180,tex_size => 200); };
# $pick = random(0,3,1);
# if ( $pick != 0 ) { $temp_eq = $eqn[0];
# $temp_gr = $fig[0];
# $eq[0] = $eq[$pick];
# $fig[0] = $fig[$pick];
# $eq[$pick] = $temp_eq;
# $fig[$pick] = $temp_gr};
$mc = new_multiple_choice();
$mc->qa('On a separate piece of paper, sketch an accurate graph of this function for \( F = $F \) and \( t \in [-1, 1] \). Which (if any) of the graphs below matches the graph you drew?','$fig[0]');
$mc->extra('$fig[1] $BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig[2] $BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig[3] $BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig[4] $BR $BITALIC(click on image to enlarge)$EITALIC',
'$fig[5] $BR $BITALIC(click on image to enlarge)$EITALIC');
$mc->makeLast('None of the above');
## force a refresh of the image after changes
$refreshCachedImages = 1;
Context()->texStrings;
BEGIN_TEXT
This problem reflects Problem 1.21a in the text
$PAR
Consider the function
$BR
$BR
\( y = $func \).
$BR
$BR
\{ $mc->print_q() \} $BR
\{ $mc->print_a() \}
END_TEXT
Context()->normalStrings;
ANS(radio_cmp($mc->correct_ans));
## force a refresh of the image after changes
$refreshCachedImages = 1;
Context()->texStrings;
SOLUTION(EV3(<<'END_SOLUTION'));
$PAR
$BBOLD SOLUTION $EBOLD
$PAR
Setting \( F = $F \) gives the function \( y = \sin(2 \pi $F t) \). This has $F cycles in one unit of time. It starts at zero at t = 0, since it is a sine and is positive for the first values greater than zero. Therefore the correct graph is
$PAR
$BCENTER
$fig[0]
$ECENTER
$BR
which is answer \{ $mc->correct_ans \}.
END_SOLUTION
Context()->normalStrings;
ENDDOCUMENT();
Hmm, I guess the string method on a Formula like that must include wrap-around parentheses.
I don't see the behavior. Here is the problem with our server, with that seed:
https://webwork.pcc.edu/webwork2/html2xml?&problemSeed=1331&answersSubmitted=0&sourceFilePath=Library/CollegeOfIdaho/setAlgebra_06_02_AddSubRationalExpressions/62IntAlg_19_AddSubRatExp.pg&displayMode=MathJax&courseID=anonymous&userID=anonymous&course_password=open&outputformat=simple
For me it comes out as
3/(y - 4) + 2/(y + 2)
Are you viewing math in "images" mode? It's one thing that might explain it. Sometimes there is a malformed .png image, and it gets cached, and you keep seeing it. Try things like (1) viewing with MathJax (2) adding $refreshCachedImages=1; and (3) going into the server where these images are stored and clearing them (I forget right now exactly where that is). If this is the issue, I don't know what causes it. But these things should fix it. And in any case, I think it's not something other users see because I think the cached image is specific to the user.
Danny, thanks for your suggestion, but:
I cannot see what you say should be there... This is a
"Past Answers" page for one problem, for one student. There is no
way to select anything or anybody else here. I suppose I can type
another id, and refresh, which would be faster than clicking my
way back out and back into another user, but it's still a purely
manual process. I tried * as a widlcard, it did not produce a
valid selection, it treated it as a literal *.
Am I in a wrong place?
It seems the path is TRULY obscure.