Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several things that were broken in recent revisions. #19

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions doc/css/sample-problem.css
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
pre.CodeMirror {
background-color: #fcfaf1;
background-color: #fcfaf1;
}
.explanation {
--bs-code-color: #971556;
--bs-code-color: #971556;
}
.preamble {
background-color: lightblue;
background-color: lightblue;
}
.setup {
background-color: #ddffdd;
background-color: #ddffdd;
}
.statement {
background-color: #eeb08199;
background-color: #eeb08199;
}
.answer {
background-color: #ffffdd;
background-color: #ffffdd;
}
.solution {
background-color: #ffb6c199;
background-color: #ffb6c199;
}
.hint {
background-color: rgb(239, 207, 251);
background-color: rgb(239, 207, 251);
}
.perl {
color: darkred;
color: darkred;
}
9 changes: 5 additions & 4 deletions doc/sample-problems/Algebra/GraphToolCircle.pg
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ loadMacros('PGstandard.pl', 'PGML.pl', 'parserGraphTool.pl', 'PGcourse.pl');
#: The `->with` method is then used to set options for the `GraphTool` object.
#: In this case the options that are set are:
#:
#: * `bbox`: this is an array reference of four values xmin, ymax, xmax, ymin
#: * `bBox`: This is an array reference of four values xmin, ymax, xmax, ymin
#: indicating the upper left and lower right corners of the visible graph.
#:
#: There is a default checker for the GraphTool that will mark correct a
#: student answer that 'looks' like the correct one. This means that if
#: student answer that 'looks' like the correct one. This means that if
#: a student adds two circles that are equivalent with one solid and one
#: dashed, that if the solid one is plotted second, credit will be given.
#: For simple graphs, the default should be sufficient. If not see
#: XXXX for an example with a custom answer checker.
#: For simple graphs, the default should be sufficient. See
#: PROBLINK('GraphToolCustomChecker.pg') for an example of how to use a custom
#: checker.
#:
#: For more details, see the PODLINK('POD documentation','parserGraphTool.pl')
$h = non_zero_random(-5, 5);
Expand Down
47 changes: 27 additions & 20 deletions doc/sample-problems/Algebra/GraphToolCubic.pg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## DESCRIPTION
## Interactive graphing tool problem that asks the student to plot a circle.
## Interactive graphing tool problem that asks the student to plot a cubic.
## ENDDESCRIPTION

## DBsubject(WeBWorK)
Expand All @@ -16,13 +16,16 @@
#:% categories = [graph]

#:% section = preamble
#: This example shows how to get student input in the form of a graph (a circle)
#: This example shows how to get student input in the form of a graph (a cubic)
#: by using interactive graphing tools. Load the parserGraphTool.pl macro for
#: this.
DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'parserGraphTool.pl',
'contextFraction.pl','PGcourse.pl');
loadMacros(
'PGstandard.pl', 'PGML.pl',
'parserGraphTool.pl', 'contextFraction.pl',
'PGcourse.pl'
);

#:% section = setup
#: A cubic is created with 3 random zeros and a random y-intercept.
Expand All @@ -33,38 +36,42 @@ loadMacros('PGstandard.pl', 'PGML.pl', 'parserGraphTool.pl',
#: of the attributes of the object. The first attribute in each list is the
#: type of object to be graphed, `cubic` in this case. What the remaining
#: attributes are depend on the type. For a cubic the second attribute is
#: whether the object is to be `solid` or `dashed`, the remaining arguments
#: are the 4 points of the cubic.
#: whether the object is to be `solid` or `dashed`, the remaining attributes
#: are four distinct points of the cubic.
#:
#: The `->with` method is then used to set options for the `GraphTool` object.
#: In this case the options that are set are:
#:
#: * bbox: this is an array reference of four values xmin, ymax, xmax, ymin
#: * `bBox`: This is an array reference of four values xmin, ymax, xmax, ymin
#: indicating the upper left and lower right corners of the visible graph.
# * availableTools: this determines which tools should be shown on the
#: graph tool.
#: * `availableTools`: This determines which tools will be available for the
#: student to use.
#:
#: There is a default checker for the GraphTool that will mark correct a
#: student answer that 'looks' like the correct one. For simple graphs,
#: the default should be sufficient. If not see
#: XXXX for an example with a custom answer checker.
#: student answer that 'looks' like the correct one. For simple graphs,
#: the default should be sufficient. See PROBLINK('GraphToolCustomChecker.pg')
#: for an example of how to use a custom checker.

Context('Fraction');

$x1 = random(-8, -4);
$x2 = non_zero_random(-3, -3);
$x3 = random(4, 8);

$y0 = non_zero_random(-3,3);

$k = Fraction($y0,-$x1*$x2*$x3);
$y0 = non_zero_random(-3, 3);

$k = Fraction($y0, -$x1 * $x2 * $x3);

$gt = GraphTool("{cubic, solid, ($x1, 0), ($x2, 0), ($x3, 0), (0, $y0)}")->with(
bBox => [ -11, 11, 11, -11 ],
availableTools =>
[ 'PointTool', 'LineTool', 'CircleTool', 'QuadraticTool', 'CubicTool', 'FillTool', 'SolidDashTool' ],
);
$gt =
GraphTool("{cubic, solid, ($x1, 0), ($x2, 0), ($x3, 0), (0, $y0)}")->with(
bBox => [ -11, 11, 11, -11 ],
availableTools => [
'PointTool', 'LineTool',
'CircleTool', 'QuadraticTool',
'CubicTool', 'FillTool',
'SolidDashTool'
],
);

#:% section = statement
#: This asks to graph the cubic throw the given points. The code
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## DESCRIPTION
## Interactive graphing tool problems.
## Interactive graphing tool problem with a custom checker.
## ENDDESCRIPTION

## DBsubject(WeBWorK)
Expand All @@ -10,15 +10,15 @@
## Author(Glenn Rice)
## KEYWORDS('graphs', 'circles')

#:% name = Interactive graphing tool problems
#:% name = Graph Tool, custom checker
#:% type = [Sample, technique]
#:% subject = [algebra, precalculus]
#:% categories = [graph]

#:% section = preamble
#: This example shows how to get student input in the form of a graph (a circle)
#: by using interactive graphing tools. Load the parserGraphTool.pl macro for
#: this.
#: by using interactive graphing tools, and demonstrates the usage of a custom
#: checker. Load the parserGraphTool.pl macro for this.
DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'parserGraphTool.pl', 'PGcourse.pl');
Expand All @@ -28,10 +28,10 @@ loadMacros('PGstandard.pl', 'PGML.pl', 'parserGraphTool.pl', 'PGcourse.pl');
#:
#: The lines
#:
#:```{#equation .perl}
#: ```{#equation .perl}
#: Context()->variables->add(y => 'Real');
#: $circle_eq_lhs = Formula("(x - $h)^2 + (y - $k)^2")->reduce;
#:```
#: ```
#:
#: define the equation of the circle that is shown in the problem and solution.
#:
Expand All @@ -47,16 +47,16 @@ loadMacros('PGstandard.pl', 'PGML.pl', 'parserGraphTool.pl', 'PGcourse.pl');
#: The `->with` method is then used to set options for the `GraphTool` object.
#: In this case the options that are set are:
#:
#: * bbox: this is an array reference of four values xmin, ymax, xmax, ymin
#: * `bBox`: this is an array reference of four values xmin, ymax, xmax, ymin
#: indicating the upper left and lower right corners of the visible graph.
#: * cmpOptions: this is a hash of options passed to the cmp method for checking
#: * `cmpOptions`: this is a hash of options passed to the cmp method for checking
#: the answer.
#:
#: The option
#:
#:```{#cmp-options .perl}
#: ```{#cmp-options .perl}
#: cmpOptions => { list_checker => sub { ... } }
#:```
#: ```
#:
#: defines a list checker. The list checker is passed the `$correct` answer
#: which will be a MathObject list of lists containing the attributes of the
Expand All @@ -75,68 +75,68 @@ Context()->variables->add(y => 'Real');
$circle_eq_lhs = Formula("(x - $h)^2 + (y - $k)^2")->reduce;

$gt = GraphTool("{circle, solid, ($h, $k), ($h + $r, $k)}")->with(
bBox => [ -11, 11, 11, -11 ],
cmpOptions => {
list_checker => sub {
my ($correct, $student, $ans, $value) = @_;
return 0 if $ans->{isPreview};

my $score = 0;
my @errors;
my $count = 1;

# Get the center and point that define the correct circle and
# compute the square of the radius.
my ($cx, $cy) = $correct->[0]->extract(3)->value;
my ($px, $py) = $correct->[0]->extract(4)->value;
my $r_squared = ($cx - $px)**2 + ($cy - $py)**2;

my $pointOnCircle = sub {
my $point = shift;
my ($x, $y) = $point->value;
return ($x - $cx)**2 + ($y - $cy)**2 == $r_squared;
};

# Iterate through the objects the student graphed and check to
# see if each is the correct circle.
for (@$student) {
my $nth = Value::List->NameForNumber($count++);

# This checks if the object graphed by the student is the same
# type as the correct object type (a circle in this case),
# has the same solid or dashed status, has the same center, and
# if the other point graphed is on the circle.
if ($_->extract(1) eq $correct->[0]->extract(1)
&& $_->extract(2) eq $correct->[0]->extract(2)
&& $_->extract(3) == $correct->[0]->extract(3)
&& $pointOnCircle->($_->extract(4)))
{
$score += 1;
next;
}

# Add messages for incorrect answers.

if ($_->extract(1) ne $correct->[0]->extract(1)) {
push(@errors,
"The $nth object graphed is not a circle");
next;
}

if ($_->extract(2) ne $correct->[0]->extract(2)) {
push(@errors,
"The $nth object graphed should be a "
. $correct->[0]->extract(2)
. " circle.");
next;
}

push(@errors, "The $nth object graphed is incorrect.");
}

return ($score, @errors);
}
}
bBox => [ -11, 11, 11, -11 ],
cmpOptions => {
list_checker => sub {
my ($correct, $student, $ans, $value) = @_;
return 0 if $ans->{isPreview};

my $score = 0;
my @errors;
my $count = 1;

# Get the center and point that define the correct circle and
# compute the square of the radius.
my ($cx, $cy) = $correct->[0]->extract(3)->value;
my ($px, $py) = $correct->[0]->extract(4)->value;
my $r_squared = ($cx - $px)**2 + ($cy - $py)**2;

my $pointOnCircle = sub {
my $point = shift;
my ($x, $y) = $point->value;
return ($x - $cx)**2 + ($y - $cy)**2 == $r_squared;
};

# Iterate through the objects the student graphed and check to
# see if each is the correct circle.
for (@$student) {
my $nth = Value::List->NameForNumber($count++);

# This checks if the object graphed by the student is the same
# type as the correct object type (a circle in this case),
# has the same solid or dashed status, has the same center, and
# if the other point graphed is on the circle.
if ($_->extract(1) eq $correct->[0]->extract(1)
&& $_->extract(2) eq $correct->[0]->extract(2)
&& $_->extract(3) == $correct->[0]->extract(3)
&& $pointOnCircle->($_->extract(4)))
{
$score += 1;
next;
}

# Add messages for incorrect answers.

if ($_->extract(1) ne $correct->[0]->extract(1)) {
push(@errors,
"The $nth object graphed is not a circle");
next;
}

if ($_->extract(2) ne $correct->[0]->extract(2)) {
push(@errors,
"The $nth object graphed should be a "
. $correct->[0]->extract(2)
. " circle.");
next;
}

push(@errors, "The $nth object graphed is incorrect.");
}

return ($score, @errors);
}
}
);

#:% section = statement
Expand Down
Loading