Annotation of loncom/interface/statistics/lonproblemstatistics.pm, revision 1.44
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: #
1.44 ! matthew 3: # $Id: lonproblemstatistics.pm,v 1.43 2003/03/26 16:26:35 matthew Exp $
1.1 stredwic 4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: # (Navigate problems for statistical reports
28: #
29: ###
30:
1.36 minaeibi 31: package Apache::lonproblemstatistics;
1.1 stredwic 32:
33: use strict;
34: use Apache::lonnet();
35: use Apache::lonhtmlcommon;
36: use Apache::loncoursedata;
1.41 matthew 37: use Apache::lonstatistics;
1.44 ! matthew 38: use Spreadsheet::WriteExcel;
1.1 stredwic 39:
1.41 matthew 40: #######################################################
41: #######################################################
1.1 stredwic 42:
1.41 matthew 43: sub CreateInterface {
44: my $Str = '';
45: $Str .= '<table cellspacing="5">'."\n";
46: $Str .= '<tr>';
47: $Str .= '<td align="center"><b>Sections</b></td>';
48: $Str .= '<td align="center"><b>Sequences and Folders</b></td>';
49: $Str .= '<td align="center"><b>Output</b></td>';
50: $Str .= '</tr>'."\n";
51: #
52: $Str .= '<tr><td align="center">'."\n";
53: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
54: $Str .= '</td><td align="center">';
55: #
56: my $only_seq_with_assessments = sub {
57: my $s=shift;
58: if ($s->{'num_assess'} < 1) {
59: return 0;
60: } else {
61: return 1;
62: }
63: };
64: $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
65: $only_seq_with_assessments);
66: $Str .= '</td><td>'."\n";
67: $Str .= &CreateAndParseOutputSelector();
68: $Str .= '</td></tr>'."\n";
69: $Str .= '</table>'."\n";
70: return $Str;
71: }
72:
73: #######################################################
74: #######################################################
75:
76: =pod
77:
78: =item &CreateAndParseOutputSelector()
79:
80: =cut
1.16 minaeibi 81:
1.41 matthew 82: #######################################################
83: #######################################################
84: my $output_mode;
85: my $show;
86:
87: my @OutputOptions =
88: (
89: { name => 'problem statistics grouped by sequence',
90: value => 'HTML problem statistics grouped',
91: description => 'Output statistics for the problem parts.',
92: mode => 'html',
93: show => 'grouped',
94: },
95: { name => 'problem statistics ungrouped',
96: value => 'HTML problem statistics ungrouped',
97: description => 'Output statistics for the problem parts.',
98: mode => 'html',
99: show => 'ungrouped',
100: },
101: { name => 'problem statistics, Excel',
102: value => 'Excel problem statistics',
103: description => 'Output statistics for the problem parts '.
104: 'in an Excel workbook',
105: mode => 'excel',
106: show => 'all',
107: },
108: { name => 'Degree of Difficulty Plot',
109: value => 'plot deg diff',
110: description => 'Generate a plot of the degree of difficulty of each '.
111: 'problem part.',
112: mode => 'plot',
113: show => 'deg of diff',
114: },
115: { name => 'Percent Wrong Plot',
116: value => 'plot per wrong',
117: description => 'Generate a plot showing the percent of students who '.
118: 'were unable to complete each problem part',
119: mode => 'plot',
120: show => 'per wrong',
121: },
122: );
123:
124: sub OutputDescriptions {
125: my $Str = '';
126: $Str .= "<h2>Output Modes</h2>\n";
127: $Str .= "<dl>\n";
128: foreach my $outputmode (@OutputOptions) {
129: $Str .=" <dt>".$outputmode->{'name'}."</dt>\n";
130: $Str .=" <dd>".$outputmode->{'description'}."</dd>\n";
1.1 stredwic 131: }
1.41 matthew 132: $Str .= "</dl>\n";
133: return $Str;
134: }
1.1 stredwic 135:
1.41 matthew 136: sub CreateAndParseOutputSelector {
137: my $Str = '';
138: my $elementname = 'outputmode';
139: #
140: # Format for output options is 'mode, restrictions';
141: my $selected = 'html, with links';
142: if (exists($ENV{'form.'.$elementname})) {
143: if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) {
144: $selected = $ENV{'form.'.$elementname}->[0];
145: } else {
146: $selected = $ENV{'form.'.$elementname};
1.25 stredwic 147: }
148: }
1.41 matthew 149: #
150: # Set package variables describing output mode
151: $output_mode = 'html';
152: $show = 'all';
153: foreach my $option (@OutputOptions) {
154: next if ($option->{'value'} ne $selected);
155: $output_mode = $option->{'mode'};
156: $show = $option->{'show'};
157: }
158: #
159: # Build the form element
160: $Str = qq/<select size="5" name="$elementname">/;
161: foreach my $option (@OutputOptions) {
162: $Str .= "\n".' <option value="'.$option->{'value'}.'"';
163: $Str .= " selected " if ($option->{'value'} eq $selected);
164: $Str .= ">".$option->{'name'}."<\/option>";
165: }
166: $Str .= "\n</select>";
167: return $Str;
168: }
1.25 stredwic 169:
1.41 matthew 170: ###############################################
171: ###############################################
1.28 stredwic 172:
1.41 matthew 173: ###############################################
174: ###############################################
175: sub Gather_Student_Data {
176: my ($r) = @_;
177: my $c = $r->connection();
178: #
179: my @Sequences = &Apache::lonstatistics::Sequences_with_Assess();
180: #
181: my @Students = @Apache::lonstatistics::Students;
182: #
183: # Open the progress window
184: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
185: ($r,'Statistics Compilation Status',
186: 'Statistics Compilation Progress', scalar(@Students));
187: #
188: while (my $student = shift @Students) {
189: return if ($c->aborted());
190: my ($status,undef) = &Apache::loncoursedata::ensure_current_data
191: ($student->{'username'},$student->{'domain'},
192: $ENV{'request.course.id'});
193: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
194: 'last student');
1.28 stredwic 195: }
1.41 matthew 196: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
197: $r->rflush();
198: }
1.28 stredwic 199:
1.41 matthew 200: ###############################################
201: ###############################################
1.21 stredwic 202:
1.41 matthew 203: ###############################################
204: ###############################################
205: sub BuildProblemStatisticsPage {
206: my ($r,$c)=@_;
207: #
208: $output_mode = 'html';
209: $show = 'grouped';
210: #
211: $r->print(&CreateInterface());
212: $r->print('<input type="hidden" name="statsfirstcall" value="no" />');
213: $r->print('<input type="hidden" name="sortby" value="'.$ENV{'form.sortby'}.
214: '" />');
215: if (! exists($ENV{'form.statsfirstcall'})) {
216: return;
1.28 stredwic 217: }
1.41 matthew 218: #
219: &Gather_Student_Data($r);
220: #
221: #
222: if ($output_mode eq 'html') {
223: $r->print("<h2>".
224: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.
225: "</h2>\n");
226: $r->print("<h3>".localtime(time)."</h3>");
227: $r->rflush();
228: if ($show eq 'grouped') {
229: &output_html_grouped_by_sequence($r);
230: } elsif ($show eq 'ungrouped') {
231: &output_html_ungrouped($r);
232: }
1.44 ! matthew 233: } elsif ($output_mode eq 'excel') {
! 234: $r->print("<h2>Preparing Excel Spreadsheet</h2>");
! 235: &output_excel($r);
1.41 matthew 236: } else {
237: $r->print("<h1>Not implemented</h1>");
1.28 stredwic 238: }
1.41 matthew 239: return;
240: }
1.21 stredwic 241:
1.44 ! matthew 242: ###############################################
! 243: ###############################################
! 244:
! 245: ###############################################
! 246: ###############################################
1.41 matthew 247: sub output_html_grouped_by_sequence {
248: my ($r) = @_;
249: #$r->print(&ProblemStatisticsLegend());
250: my @Header = ("Title","Part","#Stdnts","Tries","Mod",
251: "Mean","#YES","#yes","%Wrng","DoDiff",
252: "S.D.","Skew.");#,"D.F.1st","D.F.2nd");
253: # #FFFFE6 #EEFFCC #DDFFFF FFDDDD #DDFFDD #FFDDFF
254: foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()) {
1.43 matthew 255: my $show_part = 0;
1.41 matthew 256: next if ($sequence->{'num_assess'}<1);
257: $r->print("<h3>".$sequence->{'title'}."</h3>");
258: $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
259: $r->print('<table border="0" cellpadding="3">'."\n");
260: $r->print('<tr bgcolor="#FFFFE6"><th>'.
261: join("</th><th>",@Header)."</th></tr>\n");
262: foreach my $resource (@{$sequence->{'contents'}}) {
263: next if ($resource->{'type'} ne 'assessment');
264: foreach my $part (@{$resource->{'parts'}}) {
265: my ($num,$tries,$mod,$mean,$Solved,$solved,$DegOfDiff,$STD,
266: $SKEW) = &Apache::loncoursedata::get_problem_statistics
267: (undef,$resource->{'symb'},$part,
268: $ENV{'request.course.id'});
1.43 matthew 269: #
270: $show_part = 1 if ($part ne '0');
271: $part = ' ' if ($part == 0);
272: #
1.41 matthew 273: my $wrongpercent = 0;
274: if (defined($num) && $num > 0) {
275: $wrongpercent=int(10*100*($num-$Solved+$solved)/$num)/10;
276: }
277: $r->print('<tr>'.&statistics_html_table_data
278: ($resource,$part,$num,$tries,$mod,$mean,$Solved,
1.43 matthew 279: $solved,$wrongpercent,$DegOfDiff,$STD,$SKEW,
280: $show_part).
1.41 matthew 281: "</tr>\n");
282: }
283: }
284: $r->print("</table>\n");
285: $r->print("</td></tr></table>\n");
286: $r->rflush();
1.21 stredwic 287: }
1.41 matthew 288: #
289: return;
290: }
1.25 stredwic 291:
1.41 matthew 292: ###############################################
293: ###############################################
1.26 stredwic 294:
1.41 matthew 295: ###############################################
296: ###############################################
297: sub output_html_ungrouped {
298: my ($r) = @_;
299: #
300: my $show_container = 0;
1.43 matthew 301: my $show_part = 0;
1.41 matthew 302: #$r->print(&ProblemStatisticsLegend());
303: my @Header = ("Title","Part","#Stdnts","Tries","Mod",
1.26 stredwic 304: "Mean","#YES","#yes","%Wrng","DoDiff",
1.43 matthew 305: "S.D.","Skew");#,"D.F.1st","D.F.2nd");
1.42 matthew 306: #
307: my $sortby = undef;
308: foreach (@Header) {
309: if ($ENV{'form.sortby'} eq $_) {
310: $sortby = $_;
311: }
312: }
313: if (! defined($sortby) || $sortby eq '') {
314: $sortby = 'Container';
315: }
1.41 matthew 316: # #FFFFE6 #EEFFCC #DDFFFF FFDDDD #DDFFDD #FFDDFF
317: my @Sequences = &Apache::lonstatistics::Sequences_with_Assess();
318: if (@Sequences > 1) {
319: unshift(@Header,"Container");
320: $show_container = 1;
321: }
322: #
323: $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
324: $r->rflush();
325: #
1.42 matthew 326: # Compile the data
327: my @Statsarray;
1.41 matthew 328: foreach my $sequence (@Sequences) {
329: next if ($sequence->{'num_assess'}<1);
330: foreach my $resource (@{$sequence->{'contents'}}) {
331: next if ($resource->{'type'} ne 'assessment');
332: foreach my $part (@{$resource->{'parts'}}) {
333: my ($num,$tries,$mod,$mean,$Solved,$solved,$DegOfDiff,$STD,
334: $SKEW) = &Apache::loncoursedata::get_problem_statistics
335: (undef,$resource->{'symb'},$part,
336: $ENV{'request.course.id'});
1.43 matthew 337: #
338: $show_part = 1 if ($part ne '0');
339: $part = ' ' if ($part == 0);
340: #
1.41 matthew 341: my $wrongpercent = 0;
342: if (defined($num) && $num > 0) {
343: $wrongpercent=int(10*100*($num-$Solved+$solved)/$num)/10;
344: }
1.43 matthew 345: push (@Statsarray,
346: { 'sequence' => $sequence,
1.42 matthew 347: 'resource' => $resource,
348: 'Title' => $resource->{'title'},
349: 'Part' => $part,
350: '#Stdnts' => $num,
351: 'Tries' => $tries,
352: 'Mod' => $mod,
353: 'Mean' => $mean,
354: '#YES' => $Solved,
355: '#yes' => $solved,
356: '%Wrng' => $wrongpercent,
357: 'DoDiff' => $DegOfDiff,
358: 'S.D.' => $STD,
359: 'Skew' => $SKEW,
1.43 matthew 360: });
1.42 matthew 361: }
362: }
363: }
364: #
1.43 matthew 365: # Table Headers
366: $r->print('<table border="0" cellpadding="3">'."\n");
367: my $Str = '';
368: foreach (@Header) {
369: next if ($_ eq 'Part' && !$show_part);
370: # Do not allow sorting on some fields
371: if ($_ eq $sortby || /^(Part)$/) {
372: $Str .= '<th>'.$_.'</th>';
373: } else {
374: $Str .= '<th>'.
375: '<a href="javascript:document.Statistics.sortby.value='."'$_'".
376: ';document.Statistics.submit();">'.
377: $_.'</a></th>';
378: }
379: }
380: $r->print('<tr bgcolor="#FFFFE6">'.$Str."</tr>\n");
381: #
1.42 matthew 382: # Sort the data
1.43 matthew 383: my @OutputOrder;
1.42 matthew 384: if ($sortby eq 'Container') {
1.43 matthew 385: @OutputOrder = @Statsarray;
1.42 matthew 386: } else {
387: # $sortby is already defined, so we can charge ahead
388: if ($sortby =~ /^(title|part)$/i) {
389: # Alpha comparison
390: @OutputOrder = sort {
1.43 matthew 391: lc($a->{$sortby}) cmp lc($b->{$sortby}) ||
392: lc($a->{'Title'}) cmp lc($b->{'Title'}) ||
393: lc($a->{'Part'}) cmp lc($b->{'Part'});
1.42 matthew 394: } @Statsarray;
395: } else {
396: # Numerical comparison
397: @OutputOrder = sort {
398: my $retvalue = 0;
399: if ($b->{$sortby} eq 'nan') {
400: if ($a->{$sortby} ne 'nan') {
401: $retvalue = -1;
402: } else {
403: $retvalue = 0;
404: }
405: }
406: if ($a->{$sortby} eq 'nan') {
407: if ($b->{$sortby} ne 'nan') {
408: $retvalue = 1;
409: }
410: }
411: if ($retvalue eq '0') {
412: $retvalue = $b->{$sortby} <=> $a->{$sortby} ||
1.43 matthew 413: lc($a->{'Title'}) <=> lc($b->{'Title'}) ||
414: lc($a->{'Part'}) <=> lc($b->{'Part'});
1.41 matthew 415: }
1.42 matthew 416: $retvalue;
417: } @Statsarray;
418: }
1.43 matthew 419: }
420: foreach my $row (@OutputOrder) {
421: $r->print('<tr>');
422: if ($show_container) {
423: $r->print('<td bgcolor="#FFFFE6">'
424: .$row->{'sequence'}->{'title'}.'</td>');
1.41 matthew 425: }
1.43 matthew 426: $r->print(&stats_row_from_hash($row,$show_part));
427: $r->print("</tr>\n");
1.26 stredwic 428: }
1.41 matthew 429: $r->print("</table>\n");
430: $r->print("</td></tr></table>\n");
1.26 stredwic 431: $r->rflush();
1.41 matthew 432: #
433: return;
1.42 matthew 434: }
435:
436: sub stats_row_from_hash {
1.43 matthew 437: my ($data,$show_part) = @_;
1.42 matthew 438: return &statistics_html_table_data($data->{'resource'},$data->{'Part'},
439: $data->{'#Stdnts'}, $data->{'Tries'},
440: $data->{'Mod'}, $data->{'Mean'},
441: $data->{'#YES'}, $data->{'#yes'},
442: $data->{"\%Wrng"}, $data->{'DoDiff'},
1.43 matthew 443: $data->{'S.D.'}, $data->{'Skew'},
444: $show_part);
1.41 matthew 445: }
446:
447: ###############################################
448: ###############################################
1.26 stredwic 449:
1.41 matthew 450: ###############################################
451: ###############################################
1.44 ! matthew 452: sub output_excel {
! 453: my ($r) = @_;
! 454: my $filename = '/prtspool/'.
! 455: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
! 456: time.'_'.rand(1000000000).'.xls';
! 457: #
! 458: my $excel_workbook = undef;
! 459: my $excel_sheet = undef;
! 460: #
! 461: my $rows_output = 0;
! 462: my $cols_output = 0;
! 463: #
! 464: # Create sheet
! 465: $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
! 466: #
! 467: # Check for errors
! 468: if (! defined($excel_workbook)) {
! 469: $r->log_error("Error creating excel spreadsheet $filename: $!");
! 470: $r->print("Problems creating new Excel file. ".
! 471: "This error has been logged. ".
! 472: "Please alert your LON-CAPA administrator");
! 473: return ;
! 474: }
! 475: #
! 476: # The excel spreadsheet stores temporary data in files, then put them
! 477: # together. If needed we should be able to disable this (memory only).
! 478: # The temporary directory must be specified before calling 'addworksheet'.
! 479: # File::Temp is used to determine the temporary directory.
! 480: $excel_workbook->set_tempdir($Apache::lonnet::tmpdir);
! 481: #
! 482: # Add a worksheet
! 483: my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
! 484: if (length($sheetname) > 31) {
! 485: $sheetname = substr($sheetname,0,31);
! 486: }
! 487: $excel_sheet = $excel_workbook->addworksheet($sheetname);
! 488: #
! 489: # Put the course description in the header
! 490: $excel_sheet->write($rows_output,$cols_output++,
! 491: $ENV{'course.'.$ENV{'request.course.id'}.'.description'});
! 492: $cols_output += 3;
! 493: #
! 494: # Put a description of the sections listed
! 495: my $sectionstring = '';
! 496: my @Sections = @Apache::lonstatistics::SelectedSections;
! 497: if (scalar(@Sections) > 1) {
! 498: if (scalar(@Sections) > 2) {
! 499: my $last = pop(@Sections);
! 500: $sectionstring = "Sections ".join(', ',@Sections).', and '.$last;
! 501: } else {
! 502: $sectionstring = "Sections ".join(' and ',@Sections);
! 503: }
! 504: } else {
! 505: if ($Sections[0] eq 'all') {
! 506: $sectionstring = "All sections";
! 507: } else {
! 508: $sectionstring = "Section ".$Sections[0];
! 509: }
! 510: }
! 511: $excel_sheet->write($rows_output,$cols_output++,$sectionstring);
! 512: $cols_output += scalar(@Sections);
! 513: #
! 514: # Put the date in there too
! 515: $excel_sheet->write($rows_output,$cols_output++,
! 516: 'Compiled on '.localtime(time));
! 517: #
! 518: $rows_output++;
! 519: $cols_output=0;
! 520: #
! 521: # Add the headers
! 522: my @Header = ("Container","Title","Part","#Stdnts","Tries","Mod",
! 523: "Mean","#YES","#yes","%Wrng","DoDiff",
! 524: "S.D.","Skew.");#,"D.F.1st","D.F.2nd");
! 525: foreach (@Header) {
! 526: $excel_sheet->write($rows_output,$cols_output++,$_);
! 527: }
! 528: $rows_output++;
! 529: #
! 530: # Write the data
! 531: foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()) {
! 532: next if ($sequence->{'num_assess'}<1);
! 533: foreach my $resource (@{$sequence->{'contents'}}) {
! 534: next if ($resource->{'type'} ne 'assessment');
! 535: foreach my $part (@{$resource->{'parts'}}) {
! 536: $cols_output=0;
! 537: my ($num,$tries,$mod,$mean,$Solved,$solved,$DegOfDiff,$STD,
! 538: $SKEW) = &Apache::loncoursedata::get_problem_statistics
! 539: (undef,$resource->{'symb'},$part,
! 540: $ENV{'request.course.id'});
! 541: #
! 542: if (!defined($part) || $part eq '') {
! 543: $part = ' ';
! 544: }
! 545: my $wrongpercent = 0;
! 546: if (defined($num) && $num > 0) {
! 547: $wrongpercent=int(10*100*($num-$Solved+$solved)/$num)/10;
! 548: }
! 549: foreach ($sequence->{'title'},$resource->{'title'},$part,
! 550: $num,$tries,$mod,$mean,$Solved,$solved,$wrongpercent,
! 551: $DegOfDiff,$STD,$SKEW) {
! 552: $excel_sheet->write($rows_output,$cols_output++,$_);
! 553: }
! 554: $rows_output++;
! 555: }
! 556: }
! 557: }
! 558: #
! 559: # Write the excel file
! 560: $excel_workbook->close();
! 561: # Tell the user where to get their excel file
! 562: $r->print('<br />'.
! 563: '<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n");
! 564: $r->rflush();
! 565: return;
! 566: }
! 567:
! 568:
! 569:
1.41 matthew 570: sub statistics_html_table_data {
571: my ($resource,$part,$num,$tries,$mod,$mean,$Solved,$solved,$wrongpercent,
1.43 matthew 572: $DegOfDiff,$STD,$SKEW,$show_part) = @_;
1.41 matthew 573: my $row = '';
574: $row .= '<td bgcolor="#FFFFE6">'.
575: '<a href="'.$resource->{'src'}.'" target="_blank" >'.
576: $resource->{'title'}.'</a>'.
577: '</td>';
1.43 matthew 578: $row .= '<td bgcolor="#FFFFE6">'.$part.'</td>' if ($show_part);
1.41 matthew 579: foreach ($num,$tries) {
580: $row .= '<td bgcolor="#EEFFCC" align="right">'.$_.'</td>';
581: }
582: foreach ($mod,$mean) {
583: $row .= '<td bgcolor="#DDFFFF" align="right">'.
584: sprintf("%5.2f",$_).'</td>';
585: }
586: foreach ($Solved,$solved) {
587: $row .= '<td bgcolor="#DDFFFF" align="right">'.$_.'</td>';
588: }
589: foreach ($wrongpercent) {
590: $row .= '<td bgcolor="#DDFFFF" align="right">'.
591: sprintf("%5.1f",$_).'</td>';
592: }
593: foreach ($DegOfDiff,$STD,$SKEW) {
594: $row .= '<td bgcolor="#FFDDDD" align="right">'.
595: sprintf("%5.2f",$_).'</td>';
1.26 stredwic 596: }
1.41 matthew 597: return $row;
598: }
1.26 stredwic 599:
1.12 minaeibi 600:
1.41 matthew 601: ###############################################
602: ###############################################
1.1 stredwic 603:
1.24 stredwic 604: sub BuildGraphicChart {
1.26 stredwic 605: my ($graph,$cacheDB,$courseDescription,$students,$courseID,$r,$c)=@_;
1.24 stredwic 606: my %cache;
1.36 minaeibi 607: my $max;
1.34 minaeibi 608: my $title = '';
609: if($graph eq 'DoDiffGraph') {
610: $title = 'Degree-of-Difficulty';
611: } else {
612: $title = 'Wrong-Percentage';
613: }
614: my $currentSequence = -1;
615: my $sortProblems = 'Sort Within Sequence';
616: my ($result, $orderedProblems) =
1.26 stredwic 617: &InitializeProblemStatistics($cacheDB, $students, $courseID, $c, $r);
618: if($result ne 'OK') {
619: return;
620: }
1.24 stredwic 621: my @values = ();
1.38 albertel 622: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
623: return 'Unable to tie database.7';
624: }
1.34 minaeibi 625: foreach(@$orderedProblems) {
626: my ($sequence,$problem,$part)=split(':', $_);
627: if($cache{'StatisticsMaps'} ne 'All Maps' &&
628: $cache{'StatisticsMaps'} ne $cache{$sequence.':title'}) {
1.35 minaeibi 629: next;
1.34 minaeibi 630: }
1.35 minaeibi 631: if( $currentSequence == -1 ||
632: ($sortProblems eq 'Sort Within Sequence' &&
1.34 minaeibi 633: $currentSequence != $sequence)) {
1.35 minaeibi 634: if($currentSequence != -1) {
635: &DrawGraph(\@values,$courseDescription,$title,$max,$r);
636: }
1.34 minaeibi 637: if($sortProblems eq 'Sort Within Sequence') {
1.36 minaeibi 638: $r->print('<br><b>'.$cache{$sequence.':title'}.'</b>'."\n");
1.34 minaeibi 639: }
640: $currentSequence = $sequence;
641: @values = ();
1.36 minaeibi 642: $max=0;
1.34 minaeibi 643: }
1.24 stredwic 644: my $data = 0;
645: if($graph eq 'DoDiffGraph') {
646: $data = sprintf("%.2f", $cache{$_.':degreeOfDifficulty'}),
647: } else {
648: $data = sprintf("%.1f", $cache{$_.':percentWrong'}),
649: }
650: if($max < $data) {
651: $max = $data;
652: }
653: push(@values, $data);
654: }
1.35 minaeibi 655: untie(%cache);
656: &DrawGraph(\@values,$courseDescription,$title,$max,$r);
1.24 stredwic 657: return;
658: }
1.1 stredwic 659:
1.35 minaeibi 660: sub DrawGraph {
661: my ($values,$courseDescription,$title,$Max,$r)=@_;
662: my $sendValues = join(',', @$values);
663: my $sendCount = scalar(@$values);
1.36 minaeibi 664: $r->print("<br>The Maximum Value is: $Max");
1.35 minaeibi 665: if ( $Max > 1 ) {
666: if ($Max % 10) {
1.36 minaeibi 667: if ( int($Max) < $Max ) {
668: $Max++;
669: $Max = int($Max);
670: }
1.35 minaeibi 671: }
1.36 minaeibi 672: #(10 - $Max % 10);
1.35 minaeibi 673: } else { $Max = 1; }
1.36 minaeibi 674: my @GData = ('','Problem_number',$title,$Max,$sendCount,$sendValues);
675: # $r->print('</form>'."\n");
676: $r->print('<br>'."\n");
1.39 albertel 677: $r->print('<IMG src="/cgi-bin/graph.png?'.
1.35 minaeibi 678: (join('&', @GData)).'" border="1" />');
1.36 minaeibi 679: # $r->print('<form>'."\n");
680: $r->print('<br>'."\n");
1.35 minaeibi 681: }
682:
1.1 stredwic 683: #---- Problem Statistics Web Page ---------------------------------------
684: sub CreateProblemStatisticsTableHeading {
1.19 stredwic 685: my ($headings,$r)=@_;
686: my $Str='';
687: $Str .= '<tr>'."\n";
688: $Str .= '<th bgcolor="#ffffe6">P#</th>'."\n";
689: foreach(@$headings) {
1.27 stredwic 690: $Str .= '<th bgcolor="#ffffe6">';
691: $Str .= '<a href="/adm/statistics?reportSelected=';
1.19 stredwic 692: $Str .= &Apache::lonnet::escape('Problem Statistics');
693: $Str .= '&ProblemStatisticsSort=';
694: $Str .= &Apache::lonnet::escape($_).'">'.$_.'</a> </th>'."\n";
1.1 stredwic 695: }
1.34 minaeibi 696: $Str .= "\n".'</tr>'."\n";
1.19 stredwic 697: return $Str;
1.1 stredwic 698: }
1.12 minaeibi 699:
1.1 stredwic 700: sub BuildStatisticsTable {
1.26 stredwic 701: my ($cache,$displayFormat,$sortProblems,$orderedProblems,$headings,
702: $r,$color)=@_;
1.19 stredwic 703: my $count = 1;
1.26 stredwic 704: my $currentSequence = -1;
1.21 stredwic 705: foreach(@$orderedProblems) {
1.36 minaeibi 706: my ($sequence,$problem,$part)=split(':', $_);
1.25 stredwic 707: if($cache->{'StatisticsMaps'} ne 'All Maps' &&
708: $cache->{'StatisticsMaps'} ne $cache->{$sequence.':title'}) {
1.23 stredwic 709: next;
710: }
1.34 minaeibi 711: if($currentSequence == -1 ||
712: ($sortProblems eq 'Sort Within Sequence' &&
1.26 stredwic 713: $currentSequence != $sequence)) {
714: if($displayFormat ne 'Display CSV Format') {
715: if($currentSequence ne -1) {
716: $r->print('</table>');
717: $r->print('</td></tr></table><br>');
718: }
719: if($sortProblems eq 'Sort Within Sequence') {
720: $r->print('<b>'.$cache->{$sequence.':title'}.'</b>');
721: }
722: $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
723: $r->print('<table border="0" cellpadding="3">'."\n");
724: $r->print(&CreateProblemStatisticsTableHeading($headings, $r));
725: } else {
726: if($sortProblems eq 'Sort Within Sequence') {
727: $r->print('"'.$cache->{$sequence.':title'}.'"');
728: }
729: $r->print('<br>');
730: }
731: $currentSequence = $sequence;
732: }
1.21 stredwic 733: my $ref = '<a href="'.$cache->{$problem.':source'}.
734: '" target="_blank">'.$cache->{$problem.':title'}.'</a>';
1.19 stredwic 735: my $title = $cache->{$problem.':title'};
1.27 stredwic 736: if($part != 0) {
737: $title .= ' Part '.$part;
738: }
1.26 stredwic 739: my $source = $cache->{$problem.':source'};
1.19 stredwic 740: my $tableData = join('&', $ref, $title, $source,
1.21 stredwic 741: $cache->{$_.':studentCount'},
742: $cache->{$_.':totalTries'},
743: $cache->{$_.':maxTries'},
1.27 stredwic 744: $cache->{$_.':mean'},
1.21 stredwic 745: $cache->{$_.':correct'},
746: $cache->{$_.':correctByOverride'},
1.27 stredwic 747: $cache->{$_.':percentWrong'},
748: $cache->{$_.':degreeOfDifficulty'},
749: $cache->{$_.':standardDeviation'},
750: $cache->{$_.':skewness'},
751: $cache->{$_.':discriminationFactor1'},
752: $cache->{$_.':discriminationFactor2'});
1.19 stredwic 753: &TableRow($displayFormat,$tableData,$count,$r,$color);
754: $count++;
755: }
1.26 stredwic 756: if($displayFormat ne 'Display CSV Format') {
1.19 stredwic 757: $r->print('</table>'."\n");
1.26 stredwic 758: $r->print('</td></tr></table>');
759: } else {
760: $r->print('<br>');
1.1 stredwic 761: }
1.21 stredwic 762: return;
1.1 stredwic 763: }
764:
765: sub TableRow {
1.19 stredwic 766: my ($displayFormat,$Str,$RealIdx,$r,$color)=@_;
767: my($ref,$title,$source,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
1.27 stredwic 768: $Wrng,$DoD,$SD,$Sk,$_D1,$_D2)=split(/\&/,$Str);
1.8 minaeibi 769: my $Ptr;
1.19 stredwic 770: if($displayFormat eq 'Display CSV Format') {
1.26 stredwic 771: $Ptr='"'.$RealIdx.'",'."\n".
772: '"'.$title.'",'."\n".
773: '"'.$source.'",'."\n".
774: '"'.$StdNo.'",'."\n".
775: '"'.$TotalTries.'",'."\n".
776: '"'.$MxTries.'",'."\n".
777: '"'.$Avg.'",'."\n".
778: '"'.$YES.'",'."\n".
779: '"'.$Override.'",'."\n".
780: '"'.$Wrng.'",'."\n".
781: '"'.$DoD.'",'."\n".
782: '"'.$SD.'",'."\n".
783: '"'.$Sk.'",'."\n".
784: '"'.$_D1.'",'."\n".
785: '"'.$_D2.'"'."\n".
786: "<br>\n";
1.1 stredwic 787: $r->print("\n".$Ptr);
1.8 minaeibi 788: } else {
1.26 stredwic 789: $Ptr='<tr>'."\n".
790: '<td bgcolor="#ffffe6">'.$RealIdx.'</td>'."\n".
791: '<td bgcolor="#ffffe6">'.$ref.'</td>'."\n".
792: '<td bgcolor='.$color->{"yellow"}.'> '.$StdNo.'</td>'."\n".
793: '<td bgcolor='.$color->{"yellow"}.'>'.$TotalTries.'</td>'."\n".
794: '<td bgcolor='.$color->{"yellow"}.'>'.$MxTries.'</td>'."\n".
795: '<td bgcolor='.$color->{"gb"}.'>'.$Avg.'</td>'."\n".
796: '<td bgcolor='.$color->{"gb"}.'> '.$YES.'</td>'."\n".
797: '<td bgcolor='.$color->{"gb"}.'> '.$Override.'</td>'."\n".
798: '<td bgcolor='.$color->{"red"}.'> '.$Wrng.'</td>'."\n".
799: '<td bgcolor='.$color->{"red"}.'> '.$DoD.'</td>'."\n".
800: '<td bgcolor='.$color->{"green"}.'> '.$SD.'</td>'."\n".
801: '<td bgcolor='.$color->{"green"}.'> '.$Sk.'</td>'."\n".
802: '<td bgcolor='.$color->{"purple"}.'> '.$_D1.'</td>'."\n".
1.27 stredwic 803: '<td bgcolor='.$color->{"purple"}.'> '.$_D2.'</td>'."\n";
1.26 stredwic 804: $r->print($Ptr.'</tr>'."\n");
1.1 stredwic 805: }
1.19 stredwic 806: return;
1.1 stredwic 807: }
1.5 minaeibi 808:
809: # For loading the colored table for display or un-colored for print
810: sub setbgcolor {
811: my $PrintTable=shift;
812: my %color;
813: if ($PrintTable){
814: $color{"gb"}="#FFFFFF";
815: $color{"red"}="#FFFFFF";
816: $color{"yellow"}="#FFFFFF";
817: $color{"green"}="#FFFFFF";
818: $color{"purple"}="#FFFFFF";
819: } else {
820: $color{"gb"}="#DDFFFF";
821: $color{"red"}="#FFDDDD";
822: $color{"yellow"}="#EEFFCC";
823: $color{"green"}="#DDFFDD";
824: $color{"purple"}="#FFDDFF";
825: }
826: return \%color;
827: }
828:
1.1 stredwic 829: sub ProblemStatisticsButtons {
1.26 stredwic 830: my ($displayFormat, $displayLegend, $sortProblems)=@_;
1.1 stredwic 831: my $Ptr = '<tr><td></td><td align="left">';
832: $Ptr .= '<input type="submit" name="DoDiffGraph" ';
1.33 minaeibi 833: $Ptr .= 'value="Plot Degree of Difficulty" />'."\n";
1.27 stredwic 834: $Ptr .= '</td><td align="left">';
1.1 stredwic 835: $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
1.33 minaeibi 836: $Ptr .= 'value="Plot Percent Wrong" />'."\n";
1.20 stredwic 837: $Ptr .= '</td></tr><tr><td></td><td>'."\n";
1.26 stredwic 838: $Ptr .= '<input type="submit" name="SortProblems" ';
839: if($sortProblems eq 'Sort All Problems') {
840: $Ptr .= 'value="Sort Within Sequence" />'."\n";
841: } else {
842: $Ptr .= 'value="Sort All Problems" />'."\n";
843: }
1.27 stredwic 844: $Ptr .= '</td><td align="left">';
1.20 stredwic 845: $Ptr .= '<input type="submit" name="DisplayLegend" ';
846: if($displayLegend eq 'Show Legend') {
847: $Ptr .= 'value="Hide Legend" />'."\n";
848: } else {
849: $Ptr .= 'value="Show Legend" />'."\n";
850: }
1.27 stredwic 851: $Ptr .= '</td><td align="left">';
1.1 stredwic 852: $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
853: if($displayFormat eq 'Display CSV Format') {
1.9 stredwic 854: $Ptr .= 'value="Display Table Format" />'."\n";
855: } else {
1.1 stredwic 856: $Ptr .= 'value="Display CSV Format" />'."\n";
857: }
858: $Ptr .= '</td></tr>';
859: return $Ptr;
860: }
861:
862: sub ProblemStatisticsLegend {
863: my $Ptr = '';
864: $Ptr = '<table border="0">';
865: $Ptr .= '<tr><td>';
1.6 minaeibi 866: $Ptr .= '<b>#Stdnts</b></td>';
1.19 stredwic 867: $Ptr .= '<td>Total number of students attempted the problem.';
1.1 stredwic 868: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 869: $Ptr .= '<b>Tries</b></td>';
1.19 stredwic 870: $Ptr .= '<td>Total number of tries for solving the problem.';
1.1 stredwic 871: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 872: $Ptr .= '<b>Mod</b></td>';
1.19 stredwic 873: $Ptr .= '<td>Largest number of tries for solving the problem by a student.';
1.1 stredwic 874: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 875: $Ptr .= '<b>Mean</b></td>';
1.19 stredwic 876: $Ptr .= '<td>Average number of tries. [ Tries / #Stdnts ]';
1.1 stredwic 877: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 878: $Ptr .= '<b>#YES</b></td>';
1.1 stredwic 879: $Ptr .= '<td>Number of students solved the problem correctly.';
880: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 881: $Ptr .= '<b>#yes</b></td>';
1.1 stredwic 882: $Ptr .= '<td>Number of students solved the problem by override.';
883: $Ptr .= '</td></tr><tr><td>';
1.19 stredwic 884: $Ptr .= '<b>%Wrong</b></td>';
885: $Ptr .= '<td>Percentage of students who tried to solve the problem ';
886: $Ptr .= 'but is still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
1.1 stredwic 887: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 888: $Ptr .= '<b>DoDiff</b></td>';
1.1 stredwic 889: $Ptr .= '<td>Degree of Difficulty of the problem. ';
890: $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
891: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 892: $Ptr .= '<b>S.D.</b></td>';
1.1 stredwic 893: $Ptr .= '<td>Standard Deviation of the tries. ';
894: $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
895: $Ptr .= 'where Xi denotes every student\'s tries ]';
896: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 897: $Ptr .= '<b>Skew.</b></td>';
1.1 stredwic 898: $Ptr .= '<td>Skewness of the students tries.';
899: $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
900: $Ptr .= '</td></tr><tr><td>';
1.6 minaeibi 901: $Ptr .= '<b>Dis.F.</b></td>';
1.1 stredwic 902: $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
903: $Ptr .= 'problem according to a Criterion<br>';
1.31 stredwic 904: $Ptr .= '<b>[Criterion to group students into %27 Upper Students - ';
905: $Ptr .= 'and %27 Lower Students]</b><br>';
1.1 stredwic 906: $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
907: $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
908: $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
909: $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
910: $Ptr .= '</td></tr>';
911: $Ptr .= '<tr><td><b>Disc.</b></td>';
912: $Ptr .= '<td>Number of Students had at least one discussion.';
913: $Ptr .= '</td></tr></table>';
914: return $Ptr;
915: }
1.24 stredwic 916:
917: #---- END Problem Statistics Web Page ----------------------------------------
1.4 minaeibi 918:
1.1 stredwic 919: 1;
920: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>