WeBWorK Problems

Issue with contextPercent.pl

Issue with contextPercent.pl

by Kyle Besing -
Number of replies: 2

After an update of the Ubuntu distribution running out WeBWorK server, I have encountered the following error for a few of our problems. I have tried making the change to the XMLRPC/Lite.pm file mentioned here to try to deal with a possible issue with UTF-8 to no avail. Does anyone know what might be causing this?


Thanks,

Kyle

WeBWorK Error

WeBWorK has encountered a software error while attempting to process this problem. It is likely that there is an error in the problem itself. If you are a student, report this error message to your professor to have it corrected. If you are a professor, please consult the error output below for more information.

Error messages

ERRORS from evaluating PG file:
Error detected while loading [PG]/macros/contextPercent.pl: PG_macro_file_eval detected error at line 124 of file [PG]/lib/PGloadfiles.pm Malformed UTF-8 character (fatal) at line 1 of (eval 8503), chunk 1. The calling package is PGloadfiles Died within PGloadfiles::compile_file called at line 172 of [PG]/lib/PGloadfiles.pm from within PGloadfiles::loadMacros called at line 581 of [PG]/macros/PG.pl from within main::loadMacros called at line 24 of (eval 8256)

Error details

        Problem2
1. ERROR caught by Translator while processing problem file:Library/PCC/BasicMath/MeanMedianMode/MeanMedianMode230.pg
****************
ERRORS from evaluating PG file: 
Error detected while loading [PG]/macros/contextPercent.pl: PG_macro_file_eval detected error at line 124 of file [PG]/lib/PGloadfiles.pm Malformed UTF-8 character (fatal) at line 1 of (eval 8503), chunk 1. The calling package is PGloadfiles Died within PGloadfiles::compile_file called at line 172 of [PG]/lib/PGloadfiles.pm from within PGloadfiles::loadMacros called at line 581 of [PG]/macros/PG.pl from within main::loadMacros called at line 24 of (eval 8256)
****************
------Input Read 1 # WeBWorK problem written by Carl Yao 2 # Portland Community College 3 # 4 # Given a bar graph with two colors of bars, find the mean of two groups of data. 5 # 6 # Last edited by Carl Yao on 12/20/13 7 # 8 # ENDDESCRIPTION 9 10 ## DBCCSS('6.SP') 11 ## DBsubject(Statistics) 12 ## DBchapter(Exploratory data analysis/descriptive statistics) 13 ## DBsection(Summary statistics) 14 ## Institution(PCC) 15 ## Author(Carl Yao) 16 ## Level(2) 17 ## MO(1) 18 ## KEYWORDS('mean','application','bar graph') 19 20 ############################################## 21 22 DOCUMENT(); 23 24 loadMacros( 25 "PGstandard.pl", 26 "PGgraphmacros.pl", 27 "MathObjects.pl", 28 "PGML.pl", 29 "contextPercent.pl", 30 "parserPopUp.pl", 31 "PCCmacros.pl", 32 "PGcourse.pl" 33 ); 34 35 ############################################## 36 37 sub drawSquare { 38 my ($x,$y,$color) = @_; 39 $xside = ($xmax-$xmin)/40; 40 $yside = ($ymax-$ymin)/40; 41 $picture->moveTo($x,$y); 42 $picture->lineTo($x, $y-$yside, $color, 1); 43 $picture->lineTo($x+$xside, $y-$yside, $color, 1); 44 $picture->lineTo($x+$xside, $y, $color, 1); 45 $picture->lineTo($x, $y, $color, 1); 46 $picture->fillRegion([ $x+$xside/2, $y-$yside/2, $color ]); 47 } 48 49 sub sortSB { 50 my $ref_array = shift; 51 my $num = @$ref_array; 52 for my $i (0..$num-2) { 53 for my $j ($i+1..$num-1) { 54 if (${$ref_array}[$i]>${$ref_array}[$j]) { 55 (${$ref_array}[$i],${$ref_array}[$j]) = (${$ref_array}[$j],${$ref_array}[$i]); 56 } 57 } 58 } 59 } 60 61 ############################################## 62 63 Context("LimitedNumeric"); 64 65 $numBars = 4; 66 $maxLimit = 30; 67 68 @terms = ("Fall","Winter","Spring","Summer"); 69 @numMale = (); 70 @numFemale = (); 71 72 do { 73 74 $totalMale = 0; 75 $totalFemale = 0; 76 77 for my $i (0..$numBars-1) { 78 $numMale[$i] = int($maxLimit/2)+random(-1,1,2)*random(1,int($maxLimit/3),1); 79 $numFemale[$i] = $maxLimit - $numMale[$i]; 80 81 $totalMale = $totalMale+$numMale[$i]; 82 $totalFemale = $totalFemale+$numFemale[$i]; 83 } 84 85 $meanMale = $totalMale/$numBars; 86 $meanFemale = $totalFemale/$numBars; 87 88 @numMaleSorted = @numMale; 89 sortSB(~~@numMaleSorted); 90 @numFemaleSorted = @numFemale; 91 sortSB(~~@numFemaleSorted); 92 93 $orderedMale = ""; 94 $orderedFemale = ""; 95 for my $i (0..$numBars-1) { 96 $orderedMale = $orderedMale."`$numMaleSorted[$i]`, "; 97 $orderedFemale = $orderedFemale."`$numFemaleSorted[$i]`, "; 98 } 99 chop($orderedMale);chop($orderedMale); 100 chop($orderedFemale);chop($orderedFemale); 101 102 $medianMale = 103 ($numMaleSorted[int($numBars/2)-1]+$numMaleSorted[int($numBars/2)])/2; 104 $medianFemale = 105 ($numFemaleSorted[int($numBars/2)-1]+$numFemaleSorted[int($numBars/2)])/2; 106 107 } until ( (($meanMale>$meanFemale) && ($medianMale<$medianFemale)) || (($meanMale<$meanFemale) && ($medianMale>$medianFemale)) ); 108 109 $popup = PopUp(["?", "mean", "median"], "mean"); 110 111 $yCover = $maxLimit; 112 $ystep = $yCover/6; 113 $xstep = 1; 114 115 $xmin = -$xstep; #The viewing window 116 $xmax = $numBars+2*$xstep; 117 $ymin = -$ystep; 118 $ymax = $yCover+$ystep; 119 120 $picture = init_graph($xmin,$ymin,$xmax,$ymax, 121 pixels=>[400,400]); 122 $picture->lb('reset'); 123 124 $picture->moveTo(0,0); 125 $picture->lineTo($xmax-$xstep/2, 0, 'black',3); 126 $picture->moveTo(0,0); 127 $picture->arrowTo(0, $ymax-$ystep/2, 'black',3); 128 129 for my $i (0..$yCover/$ystep) { 130 $picture->stamps( closed_circle(0,$i*$ystep,'blue') ); 131 $mark = $i*$ystep; 132 $picture->lb( new Label(-$xstep/2,$i*$ystep,"$mark",'black','center','middle')); 133 } 134 135 $picture->lb( new Label($xmax-$xstep/3,-$ystep/4,"terms",'black','right','middle')); 136 $picture->lb( new Label($xstep/4,$ymax-$ystep/3,"number of students",'black','left','middle')); 137 138 drawSquare($numBars-1,$ymax-$ystep/3,'red'); 139 $picture->lb( new Label($numBars-1+$xstep/3,$ymax-$ystep/3,"male students",'red','left','top')); 140 drawSquare($numBars-1,$ymax-$ystep*2/3,'green'); 141 $picture->lb( new Label($numBars-1+$xstep/3,$ymax-$ystep*2/3,"female students",'green','left','top')); 142 143 $alt = "This graph has two sets of bar graphs comparing male and female students in a certain class. "; 144 for my $i (0..$numBars-1) { 145 $picture->lb( new Label(($i+1)*$xstep,-$ystep/4, 146 $terms[$i],'black','center','middle')); 147 148 $picture->moveTo(($i+1-0.4)*$xstep,0); 149 $picture->lineTo(($i+1-0.4)*$xstep,$numMale[$i],'red',1); 150 $picture->lineTo(($i+1)*$xstep,$numMale[$i],'red',1); 151 $picture->lineTo(($i+1)*$xstep,0,'red',1); 152 $picture->fillRegion([ ($i+1-0.2)*$xstep,$numMale[$i]/2,'red' ]); 153 $picture->lb( new Label(($i+1-0.2)*$xstep,$numMale[$i]+$ystep/4, 154 "$numMale[$i]",'red','center','middle')); 155 156 $picture->moveTo(($i+1+0.4)*$xstep,0); 157 $picture->lineTo(($i+1+0.4)*$xstep,$numFemale[$i],'green',1); 158 $picture->lineTo(($i+1)*$xstep,$numFemale[$i],'green',1); 159 $picture->lineTo(($i+1)*$xstep,0,'green',1); 160 $picture->fillRegion([ ($i+1+0.2)*$xstep,$numFemale[$i]/2,'green' ]); 161 $picture->lb( new Label(($i+1+0.2)*$xstep,$numFemale[$i]+$ystep/4, 162 "$numFemale[$i]",'green','center','middle')); 163 164 $alt = $alt."In $terms[$i] Term, this class had $numMale[$i] male students and $numFemale[$i] female students. "; 165 } 166 chop($alt); 167 168 ############################################## 169 170 TEXT(beginproblem()); 171 $refreshCachedImages = 1; 172 173 BEGIN_TEXT 174 175 This bar graph compares male and female student enrollment in a certain class at a community college in a certain school year. $PAR 176 177 $BCENTER 178 \{ image(insertGraph( $picture ), tex_size=>400, height=>400, width=>400, extra_html_tags => 'alt = "$alt" title = "$alt"') \} 179 $ECENTER 180 $PAR 181 182 END_TEXT 183 BEGIN_PGML 184 185 Answer the following questions. 186 187 *Question 1:* In these [`4`] terms, the mean number of male students in this class was [__________]{$meanMale}. 188 189 *Question 2:* In these [`4`] terms, the mean number of female students in this class was [__________]{$meanFemale}. 190 191 *Question 3:* In these [`4`] terms, the median of male students in this class was [__________]{$medianMale}. 192 193 *Question 4:* In these [`4`] terms, the median of female students in this class was [__________]{$medianFemale}. 194 195 *Question 5:* If you want to know, in all [`4`] terms, there are more male or female students, should you compare the mean or median? 196 197 [@$popup->menu()@]* 198 199 END_PGML 200 201 ############################################## 202 203 ANS( $popup->cmp() ); 204 205 $midM1 = $numMaleSorted[$numBars/2-1]; 206 $midM2 = $numMaleSorted[$numBars/2]; 207 $outputM = "There are two numbers in the middle: `$midM1` and `$midM2`. The median is the mean of these two numbers: `\frac{$midM1+$midM2}{2}=$medianMale`."; 208 209 $midF1 = $numFemaleSorted[$numBars/2-1]; 210 $midF2 = $numFemaleSorted[$numBars/2]; 211 $outputF = "There are two numbers in the middle: `$midF1` and `$midF2`. The median is the mean of these two numbers: `\frac{$midF1+$midF2}{2}=$medianFemale`."; 212 213 if ($meanMale>$meanFemale) { 214 $output1 = "The mean of male students is bigger than that of female students, so more male students attended this class in all four terms. Notice that the median of female students is actually bigger than that of male students."; 215 } else { 216 $output1 = "The mean of female students is bigger than that of male students, so more female students attended this class in all four terms. Notice that the median of male students is actually bigger than that of female students."; 217 } 218 219 ############################################## 220 221 BEGIN_PGML_SOLUTION 222 223 ####Question 1 224 225 To find the mean number of male students in this class, we first add up the number of male students in all [`4`] terms: 226 227 [`` [@$numMale[0]@] + [@$numMale[1]@] + [@$numMale[2]@] + [@$numMale[3]@] = [$totalMale] ``] 228 229 Now we can find the mean by dividing the sum by the number of terms ([`4`]): 230 231 [`` \text{mean} = \frac{[$totalMale]}{4} = [$meanMale] ``] 232 233 *Solution:* In these [`4`] terms, the mean number of male students in this class was [`[$meanMale]`]. 234 235 ---- 236 237 ####Question 2 238 239 To find the mean number of female students in this class, we first add up the number of female students in all [`4`] terms: 240 241 [`` [@$numFemale[0]@] + [@$numFemale[1]@] + [@$numFemale[2]@] + [@$numFemale[3]@] = [$totalFemale] ``] 242 243 Now we can find the mean by dividing the sum by the number of terms ([`4`]): 244 245 [`` \text{mean} = \frac{[$totalFemale]}{4} = [$meanFemale] ``] 246 247 *Solution:* In these [`4`] terms, the mean number of female students in this class was [`[$meanFemale]`]. 248 249 ---- 250 251 ####Question 3 252 253 To find the median number of male students, we first need to order the number of male students in all [`4`] terms: 254 255 [$orderedMale] 256 257 [$outputM] 258 259 *Solution:* In these [`4`] terms, the median of male students in this class was [`[$medianMale]`]. 260 261 ---- 262 263 ####Question 4 264 265 To find the median number of female students, we first need to order the number of female students in all [`4`] terms: 266 267 [$orderedFemale] 268 269 [$outputF] 270 271 *Solution:* In these [`4`] terms, the median of female students in this class was [`[$medianFemale]`]. 272 273 ---- 274 275 ####Question 5 276 277 To compare the total number of male and female students in all [`4`] terms, we should compare the mean. The median is not accurate because some numbers were not considered; as a comparison, each number is used when the mean is calculated. 278 279 [$output1] 280 281 Don't think that the median is not useful. When there are outliers (very big or small numbers compared to most numbers in the group), the median is better than mean. That's why in newspapers, you will more than likely see "the median house price" than "the mean house price," etc. 282 283 END_PGML_SOLUTION 284 285 ENDDOCUMENT();

In reply to Kyle Besing

Re: Issue with contextPercent.pl

by Nathan Wallach -
Sorry, I have not had time to follow the forums recently, but did some catching up.

I think that the problem is with the file macros/contextPercent.pl in the main pg packages which still had a character which could not be read properly after the change to using UTF-8 encoding. It and several other files were updated in the develop branch by Glenn Rice to avoid using the ISO-8859-8 encoded copyright character which is apparently triggering the error message you got, but that fix is not in the current "master" (PG 2.15) branch.

The quick fix would be to manually edit the file on your server. Merging in the specific commit from Git would fix it also in several other files.
In reply to Nathan Wallach

Re: Issue with contextPercent.pl

by Bianca Sosnovski -

My colleague also encountered a similar issue with the macro contextPolynomialFactors.plĀ 

error