Forums

Search results: 163

The "built in" randomization that I meant is the "Enable periodic re-randomization of problems" option. With this the students are only allowed a limited number of attempts (the default is 5, but you can change that either course wide or per problem), and then the students are given a new version of the problem with a new seed. This eliminates guessing, as the student is given a new version of the problem with different random parameters after the limited number of attempts are used up.

The same as with the problemRandomization.pl macro. Your PGcourse.pl allows you to do this only after the set due date because it only activates the macro at that time. This is currently not an option with the built in randomization.

After doing some testing I see that the PGalias is initialized before the problem code is run. So my suggestion of adding $envir{problemSeed} = $main::problemSeed won't work. Unfortunately, that means there is no work around to the limitations of the problemRandomization.pl macro in this situation.

You could generate static images of all of the possible graphs (there are only 30 of them), and then just load those. That would work since each file would have its own file name.

I added  $envir{problemSeed} = $main::problemSeed  after the load macros - no change

I thought "Enable periodic re-randomization of problems"  rerandomized after a selected number of attempts determined by the next setting:

The default number of attempts between re-randomization of the problems ( 0 => never)

This was to prevent students from guessing and eliminating possible answers to initial parameters of the problem.

I don't understand what you mean with a "built in" randomization. I want a new random set of parameters only after the student has been graded on the problem, and every time s/he hits the get a new version.  Can you tell me  what code to insert? I've been coding Webwork problems for 7 years now, for 10 different ECE courses. And I'm really not understanding the solution that you propose.

If a phone call or a zoom session would be better, I'm fine with that.

I am not sure what you mean by being on different wavelengths. You are using many things here that are outdated, and I am just advising that you update some things.

I know what you are using problemRandomize.pl for.  The point is that most of what is offered by that macro is done better by the built in problem randomization.  This is available from the course configuration options.  Under "Optional Modules", set "Enable periodic re-randomization of problems" to be True.

In any case, the answer to my question as to whether or not you are using problemRandomization.pl is macro via PGcourse.pl is yes.

Did you try adding

$envir{problemSeed} = $main::problemSeed

to the beginning of your problem? Add that right after the loadMacros(...) call.

Wow! We're on different wavelengths. In order to allow the students to get a new version of the problem for practice after the problem set has closed, I use the PGcourse.pl, which I believed was standard. That produces a button on the problem page that says "Get a new version of this problem" I'm not testing my own code. I want to give the student a chance to work a different version of the same problem. In this case, the student should identify a simply sine wave from a collection of graphs.

I checked the PGcourse,pl macro that I have been using for a long time, but never looked at because it did what I wanted. I'm clearly out of my league on coding this myself, but it looks like it is supposed to do what I wanted. There are two calls to problemRandomize. The last appears to be what I've been getting and was happy with, except for the graphics. Any help is appreciated. Here is my PGcourse.pl

##  PGcourse.pl Dick Lane, mildly revised with Davide Cervone's help 2011-06-23

##  Put into templates/macros folder for a course (upload using File Manager).
##  Use by having last item of loadMacros be 'PGcourse.pl' (after a comma).

##  Note: usual path for loading macro files includes an identically-named file
##  which does nothing; problem files which explicitly load PGcourse.pl will be
##  usable by any course, independent of the course having its own version.

sub _PGcourse_init {};		####	Don't reload this file.

$guest   = ($effectivePermissionLevel == -5) ;	####	practice user

####	Presume that faculty observers are given TA status (permission 5).
$observe = ($effectivePermissionLevel >=  5) ;	## TA or Professor (perm = 10)

loadMacros( "problemRandomize.pl" ) ;

####	Allow a Guest or Observer to always get a new version of problem.
ProblemRandomize( when => "Always", onlyAfterDue => 0, style => "Button" )
	if	($guest or $observe) ;

##  Allow everybody else (e.g., a student) to get a new version after correct
##  answer(s) to first (scored) version OR after the assignment's due date
$when = (time >= $main::dueDate ? "Always" : "Correct");
ProblemRandomize( when => $when, onlyAfterDue => 0, style => "Button" )
	if	not ($guest or $observe) ;

####	Note: those two uses of ProblemRandomize reflect choices
####	which can be made independently, e.g., this file can be changed so that
####	a course invokes one while the other is commented-out (or zapped).

####	Always allow observer or teacher to View Source Code for problem.
####			loadMacros( "source.pl" )	if	$observe ;
####	commented-out because extra setup needed by an admin with shell access

####	Note: PREP-2011 participants have professor status for each PREP course
####	and can always read a problem's code by invoking Edit Source.

1;

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.

Thanks - moving the $refreshCachedImages to before the generation of graphs "helps" - but only if I manually clear the cache (ctrl-shift-delete) between using "get a new version" If I simply hit "get a new version" without the manual clear cache, I see the same images as the original seed. How about trying the sequence generate original problem (I use update tab, view tab will use old images) with seed 323 you should get F=4 and consistent graphs. Now repeatedly hit "get a new version" and check the graphs. I get the same graphs but in different order. The right answer is always the graph with the correct answer for F=4. Now try, with the graphs for F=4, clear cache(ctrl-shift-delete) and get new version, check the graphs and repeat.

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.

The images are being generated when the seed changes for me as well.

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.

Now, with all of that said, I have noticed when testing things, for example after changing the source code, that even though webwork does regenerate the image, what you see in the browser is the same.  The reason for this is something that webwork has no control over.  That is your browser's network caching.  When you change the source file resulting in webwork regenerating the image, the url with the filename is still the same (because the discussed things above are still the same in this case).  So your browser believes this is the same resource, and loads from cache.  Of course that results in you seeing the unchanged former image.  So do a hard refresh on your browser (ctrl-f5) and you will get the changed image.

One last thing.  $refreshCachedImages does not work the way you seem to think according to your comments.  Setting the value to 1 does not force a refresh of the image after you make changes to it.  $refreshCachedImages is used in the insertGraph method.  If it is 1 at the time that method is called, then the image will be regenerated.  Now in your problem you set $refreshCachedImages after you call insertImage.  The effect is that it is not used at all.