Annotation of loncom/interface/statistics/lonstudentsubmissions.pm, revision 1.1
1.1 ! matthew 1: # The LearningOnline Network with CAPA
! 2: #
! 3: # $Id: lonproblemanalysis.pm,v 1.70 2004/02/18 19:16:55 matthew Exp $
! 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: package Apache::lonstudentsubmissions;
! 28:
! 29: use strict;
! 30: use Apache::lonnet();
! 31: use Apache::loncommon();
! 32: use Apache::lonhtmlcommon();
! 33: use Apache::loncoursedata();
! 34: use Apache::lonstatistics;
! 35: use Apache::lonlocal;
! 36: use Apache::lonstathelpers;
! 37: use HTML::Entities();
! 38: use Time::Local();
! 39: use Spreadsheet::WriteExcel();
! 40:
! 41: my @SubmitButtons = ({ name => 'PrevProblem',
! 42: text => 'Previous Problem' },
! 43: { name => 'NextProblem',
! 44: text => 'Next Problem' },
! 45: { name => 'break'},
! 46: { name => 'ClearCache',
! 47: text => 'Clear Caches' },
! 48: { name => 'updatecaches',
! 49: text => 'Update Student Data' },
! 50: { name => 'SelectAnother',
! 51: text => 'Choose a different Problem' },
! 52: { name => 'Generate',
! 53: text => 'Generate Spreadsheet'},
! 54: );
! 55:
! 56: sub BuildStudentSubmissionsPage {
! 57: my ($r,$c)=@_;
! 58: #
! 59: my %Saveable_Parameters = ('Status' => 'scalar',
! 60: 'Section' => 'array',
! 61: 'NumPlots' => 'scalar',
! 62: );
! 63: &Apache::loncommon::store_course_settings('student_submissions',
! 64: \%Saveable_Parameters);
! 65: &Apache::loncommon::restore_course_settings('student_submissions',
! 66: \%Saveable_Parameters);
! 67: #
! 68: &Apache::lonstatistics::PrepareClasslist();
! 69: #
! 70: $r->print('<h2>'.&mt('Student Submissions Report').'</h2>');
! 71: $r->print(&CreateInterface());
! 72: #
! 73: my @Students = @Apache::lonstatistics::Students;
! 74: #
! 75: if (@Students < 1) {
! 76: $r->print('<h2>There are no students in the sections selected</h2>');
! 77: }
! 78: #
! 79: &Apache::loncoursedata::clear_internal_caches();
! 80: if (exists($ENV{'form.ClearCache'}) ||
! 81: exists($ENV{'form.updatecaches'}) ||
! 82: (exists($ENV{'form.firstanalysis'}) &&
! 83: $ENV{'form.firstanalysis'} ne 'no')) {
! 84: &Apache::lonstatistics::Gather_Full_Student_Data($r);
! 85: }
! 86: if (! exists($ENV{'form.firstanalysis'})) {
! 87: $r->print('<input type="hidden" name="firstanalysis" value="yes" />');
! 88: } else {
! 89: $r->print('<input type="hidden" name="firstanalysis" value="no" />');
! 90: }
! 91: $r->rflush();
! 92: #
! 93: if (exists($ENV{'form.problemchoice'}) &&
! 94: ! exists($ENV{'form.SelectAnother'})) {
! 95: foreach my $button (@SubmitButtons) {
! 96: if ($button->{'name'} eq 'break') {
! 97: $r->print("<br />\n");
! 98: } else {
! 99: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
! 100: 'value="'.&mt($button->{'text'}).'" />');
! 101: $r->print(' 'x5);
! 102: }
! 103: }
! 104: #
! 105: $r->print('<hr />');
! 106: $r->rflush();
! 107: #
! 108: # Determine which problem we are to analyze
! 109: my $current_problem = &Apache::lonstathelpers::get_target_from_id
! 110: ($ENV{'form.problemchoice'});
! 111: #
! 112: my ($prev,$curr,$next) =
! 113: &Apache::lonstathelpers::get_prev_curr_next($current_problem,
! 114: '.',
! 115: 'response',
! 116: );
! 117: if (exists($ENV{'form.PrevProblem'}) && defined($prev)) {
! 118: $current_problem = $prev;
! 119: } elsif (exists($ENV{'form.NextProblem'}) && defined($next)) {
! 120: $current_problem = $next;
! 121: } else {
! 122: $current_problem = $curr;
! 123: }
! 124: #
! 125: # Store the current problem choice and send it out in the form
! 126: $ENV{'form.problemchoice'} =
! 127: &Apache::lonstathelpers::make_target_id($current_problem);
! 128: $r->print('<input type="hidden" name="problemchoice" value="'.
! 129: $ENV{'form.problemchoice'}.'" />');
! 130: #
! 131: if (! defined($current_problem->{'resource'})) {
! 132: $r->print('resource is undefined');
! 133: } else {
! 134: my $resource = $current_problem->{'resource'};
! 135: $r->print('<h1>'.$resource->{'title'}.'</h1>');
! 136: $r->print('<h3>'.$resource->{'src'}.'</h3>');
! 137: $r->print(&Apache::lonstathelpers::render_resource($resource));
! 138: $r->rflush();
! 139: my %Data = &Apache::lonstathelpers::get_problem_data
! 140: ($resource->{'src'});
! 141: my $ProblemData = $Data{$current_problem->{'part'}.
! 142: '.'.
! 143: $current_problem->{'respid'}};
! 144: &prepare_excel_output($r,$current_problem,
! 145: $ProblemData,\@Students);
! 146: }
! 147: $r->print('<hr />');
! 148: } else {
! 149: $r->print('<input type="submit" name="Generate" value="'.
! 150: &mt('Generate Spreadsheet').'" />');
! 151: $r->print(' 'x5);
! 152: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
! 153: $r->print(&Apache::lonstathelpers::ProblemSelector('.'));
! 154: }
! 155: }
! 156:
! 157:
! 158: #########################################################
! 159: #########################################################
! 160: ##
! 161: ## Excel output of student answers and correct answers
! 162: ##
! 163: #########################################################
! 164: #########################################################
! 165: sub prepare_excel_output {
! 166: my ($r,$problem,$ProblemData,$Students) = @_;
! 167: my ($resource,$respid,$partid) = ($problem->{'resource'},
! 168: $problem->{'respid'},
! 169: $problem->{'part'});
! 170: $r->print('<h2>'.
! 171: &mt('Preparing Excel spreadsheet of student responses').
! 172: '</h2>');
! 173: #
! 174: &GetStudentAnswers($r,$problem,$Students);
! 175: #
! 176: my @Columns = ( 'username','domain','attempt','time',
! 177: 'submission','correct', 'grading','awarded','weight',
! 178: 'score');
! 179: my $awarded_col = 7;
! 180: my $weight_col = 8;
! 181: #
! 182: # Create excel worksheet
! 183: my $filename = '/prtspool/'.
! 184: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
! 185: time.'_'.rand(1000000000).'.xls';
! 186: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
! 187: if (! defined($workbook)) {
! 188: $r->log_error("Error creating excel spreadsheet $filename: $!");
! 189: $r->print('<p>'.&mt("Unable to create new Excel file. ".
! 190: "This error has been logged. ".
! 191: "Please alert your LON-CAPA administrator").
! 192: '</p>');
! 193: return undef;
! 194: }
! 195: #
! 196: $workbook->set_tempdir('/home/httpd/perl/tmp');
! 197: #
! 198: my $format = &Apache::loncommon::define_excel_formats($workbook);
! 199: my $worksheet = $workbook->addworksheet('Student Submission Data');
! 200: #
! 201: # Make sure we get new weight data instead of data on a 10 minute delay
! 202: &Apache::lonnet::clear_EXT_cache_status();
! 203: #
! 204: # Put on the standard headers and whatnot
! 205: my $rows_output=0;
! 206: $worksheet->write($rows_output++,0,$resource->{'title'},$format->{'h1'});
! 207: $worksheet->write($rows_output++,0,$resource->{'src'},$format->{'h3'});
! 208: $rows_output++;
! 209: $worksheet->write_row($rows_output++,0,\@Columns,$format->{'bold'});
! 210: #
! 211: # Populate the worksheet with the student data
! 212: foreach my $student (@$Students) {
! 213: my $results = &Apache::loncoursedata::get_response_data_by_student
! 214: ($student,$resource->{'symb'},$respid);
! 215: my %row;
! 216: $row{'username'} = $student->{'username'};
! 217: $row{'domain'} = $student->{'domain'};
! 218: $row{'correct'} = $student->{'answer'};
! 219: $row{'weight'} = &Apache::lonnet::EXT
! 220: ('resource.'.$partid.'.weight',$resource->{'symb'},
! 221: undef,undef,undef);
! 222: if (! defined($results) || ref($results) ne 'ARRAY') {
! 223: $row{'score'} = '='.
! 224: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
! 225: ($rows_output,$awarded_col)
! 226: .'*'.
! 227: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
! 228: ($rows_output,$weight_col);
! 229: my $cols_output = 0;
! 230: foreach my $col (@Columns) {
! 231: if (! exists($row{$col})) {
! 232: $cols_output++;
! 233: next;
! 234: }
! 235: $worksheet->write($rows_output,$cols_output++,$row{$col});
! 236: }
! 237: $rows_output++;
! 238: } else {
! 239: foreach my $response (@$results) {
! 240: delete($row{'time'});
! 241: delete($row{'attempt'});
! 242: delete($row{'submission'});
! 243: delete($row{'awarded'});
! 244: delete($row{'grading'});
! 245: delete($row{'score'});
! 246: my %row_format;
! 247: #
! 248: # Time is handled differently
! 249: $row{'time'} = &Apache::lonstathelpers::calc_serial
! 250: ($response->[&Apache::loncoursedata::RDs_timestamp()]);
! 251: $row_format{'time'}=$format->{'date'};
! 252: #
! 253: $row{'attempt'} = $response->[
! 254: &Apache::loncoursedata::RDs_tries()];
! 255: $row{'submission'} = $response->[
! 256: &Apache::loncoursedata::RDs_submission()];
! 257: if ($row{'submission'} =~ m/^=/) {
! 258: # This will be interpreted as a formula. That is bad!
! 259: $row{'submission'} = " ".$row{'submission'};
! 260: }
! 261: $row{'grading'} = $response->[
! 262: &Apache::loncoursedata::RDs_awarddetail()];
! 263: $row{'awarded'} = $response->[
! 264: &Apache::loncoursedata::RDs_awarded()];
! 265: $row{'score'} = '='.
! 266: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
! 267: ($rows_output,$awarded_col)
! 268: .'*'.
! 269: &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
! 270: ($rows_output,$weight_col);
! 271: my $cols_output = 0;
! 272: foreach my $col (@Columns) {
! 273: $worksheet->write($rows_output,$cols_output++,$row{$col},
! 274: $row_format{$col});
! 275: }
! 276: $rows_output++;
! 277: }
! 278: } # End of else clause on if (! defined($results) ....
! 279: }
! 280: #
! 281: # Close the excel file
! 282: $workbook->close();
! 283: #
! 284: # Write a link to allow them to download it
! 285: $r->print('<p><a href="'.$filename.'">'.
! 286: &mt('Your Excel spreadsheet.').
! 287: '</a></p>'."\n");
! 288: }
! 289:
! 290: sub GetStudentAnswers {
! 291: my ($r,$problem,$Students) = @_;
! 292: my %Answers;
! 293: my ($resource,$partid,$respid) = ($problem->{'resource'},
! 294: $problem->{'part'},
! 295: $problem->{'respid'});
! 296: # Open progress window
! 297: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
! 298: ($r,'Student Answer Compilation Status',
! 299: 'Student Answer Compilation Progress', scalar(@$Students));
! 300: $r->print("<table>\n");
! 301: $r->rflush();
! 302: foreach my $student (@$Students) {
! 303: my $sname = $student->{'username'};
! 304: my $sdom = $student->{'domain'};
! 305: my $answer = &Apache::lonstathelpers::analyze_problem_as_student
! 306: ($resource,$sname,$sdom,$partid,$respid);
! 307: &Apache::lonnet::logthis('answer = "'.$answer.'"');
! 308: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
! 309: &mt('last student'));
! 310: $student->{'answer'} = $answer;
! 311: }
! 312: $r->print("</table>\n");
! 313: $r->rflush();
! 314: # close progress window
! 315: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
! 316: return;
! 317: }
! 318:
! 319:
! 320: #########################################################
! 321: #########################################################
! 322: ##
! 323: ## Generic Interface Routines
! 324: ##
! 325: #########################################################
! 326: #########################################################
! 327: sub CreateInterface {
! 328: ##
! 329: ## Environment variable initialization
! 330: my $Str = '';
! 331: $Str .= '<table cellspacing="5">'."\n";
! 332: $Str .= '<tr>';
! 333: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
! 334: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
! 335: $Str .= '<td align="center"> </td>';
! 336: $Str .= '</tr>'."\n";
! 337: ##
! 338: ##
! 339: $Str .= '<tr><td align="center">'."\n";
! 340: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
! 341: $Str .= '</td>';
! 342: #
! 343: $Str .= '<td align="center">';
! 344: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
! 345: $Str .= '</td>';
! 346: #
! 347: my $only_seq_with_assessments = sub {
! 348: my $s=shift;
! 349: if ($s->{'num_assess'} < 1) {
! 350: return 0;
! 351: } else {
! 352: return 1;
! 353: }
! 354: };
! 355: ##
! 356: ##
! 357: $Str .= '</tr>'."\n";
! 358: $Str .= '</table>'."\n";
! 359: #
! 360: # We do this to make sure the sequence information is initialized
! 361: &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
! 362: $only_seq_with_assessments);
! 363:
! 364: #
! 365: return $Str;
! 366: }
! 367:
! 368:
! 369:
! 370: 1;
! 371:
! 372: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>