File:  [LON-CAPA] / loncom / interface / spreadsheet / classcalc.pm
Revision 1.5: download - view: text, annotated - select for diffs
Tue May 27 14:52:45 2003 UTC (20 years, 11 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Use lonstatistics to retrieve the list of students.   Added output of
the section selector dialog.  Seems to work.

    1: #
    2: # $Id: classcalc.pm,v 1.5 2003/05/27 14:52:45 matthew Exp $
    3: #
    4: # Copyright Michigan State University Board of Trustees
    5: #
    6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    7: #
    8: # LON-CAPA is free software; you can redistribute it and/or modify
    9: # it under the terms of the GNU General Public License as published by
   10: # the Free Software Foundation; either version 2 of the License, or
   11: # (at your option) any later version.
   12: #
   13: # LON-CAPA is distributed in the hope that it will be useful,
   14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16: # GNU General Public License for more details.
   17: #
   18: # You should have received a copy of the GNU General Public License
   19: # along with LON-CAPA; if not, write to the Free Software
   20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21: #
   22: # /home/httpd/html/adm/gpl.txt
   23: #
   24: # http://www.lon-capa.org/
   25: #
   26: # The LearningOnline Network with CAPA
   27: # Spreadsheet/Grades Display Handler
   28: #
   29: # POD required stuff:
   30: 
   31: =head1 NAME
   32: 
   33: classcalc
   34: 
   35: =head1 SYNOPSIS
   36: 
   37: =head1 DESCRIPTION
   38: 
   39: =over 4
   40: 
   41: =cut
   42: 
   43: ###################################################
   44: ###                 CourseSheet                 ###
   45: ###################################################
   46: package Apache::classcalc;
   47: 
   48: use strict;
   49: use Apache::Constants qw(:common :http);
   50: use Apache::loncoursedata();
   51: use Apache::lonhtmlcommon();
   52: use Apache::Spreadsheet;
   53: use Apache::studentcalc;
   54: use Apache::lonstatistics();
   55: use HTML::Entities();
   56: use Spreadsheet::WriteExcel;
   57: use Apache::lonnet;
   58: use Time::HiRes;
   59: 
   60: @Apache::classcalc::ISA = ('Apache::Spreadsheet');
   61: 
   62: sub html_header {
   63:     my $self = shift;
   64:     my ($toprow,$bottomrow);
   65:     &Apache::lonstatistics::clear_classlist_variables();
   66:     foreach (['Sections',&Apache::lonstatistics::SectionSelect('Section','multpile',3)],
   67:              ['Enrollment Status',&Apache::lonhtmlcommon::StatusOptions(undef,undef,3)],
   68:              ['Output Format',&Apache::Spreadsheet::output_selector()]) {
   69:         my ($name,$selector) = @{$_};
   70:         $toprow .= '<th align="center"><b>'.$name.'</b></th>';
   71:         $bottomrow .= '<td>'.$selector.'</td>';
   72:     }
   73:     return "<p>\n<table>\n".
   74:         "<tr>".$toprow."</tr>\n".
   75:         "<tr>".$bottomrow."</tr>\n".
   76:         "</table>\n</p>";
   77: }
   78: 
   79: sub get_classlist {
   80:     my $self = shift;
   81:     # Retrieve the classlist and return it 
   82:     return &Apache::lonstatistics::get_students();
   83: }
   84: 
   85: sub get_title {
   86:     my $self = shift;
   87:     # Section info should be included
   88:     my @title = ($self->{'coursedesc'}, scalar(localtime(time)) );
   89:     return @title;
   90: }
   91: 
   92: sub get_html_title {
   93:     my $self = shift;
   94:     my ($classcalc_title,$time) = $self->get_title();
   95:     my $title = '<h1>'.$classcalc_title."</h1>\n".'<h3>'.$time."</h3>\n";
   96:     return $title;
   97: }
   98: 
   99: sub parent_link {
  100:     return '';
  101: }
  102: 
  103: sub outsheet_html {
  104:     my $self = shift;
  105:     my ($r) = @_;
  106:     ###################################
  107:     # Determine table structure
  108:     ###################################
  109:     my $num_uneditable = 26;
  110:     my $num_left = 52-$num_uneditable;
  111:     my $tableheader =<<"END";
  112: <p>
  113: <table border="2">
  114: <tr>
  115:   <th colspan="2" rowspan="2"><font size="+2">Course</font></th>
  116:   <td bgcolor="#FFDDDD" colspan="$num_uneditable">
  117:       <b><font size="+1">Import</font></b></td>
  118:   <td colspan="$num_left">
  119:       <b><font size="+1">Calculations</font></b></td>
  120: </tr><tr>
  121: END
  122:     my $label_num = 0;
  123:     foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
  124:         if ($label_num<$num_uneditable) { 
  125:             $tableheader.='<th bgcolor="#FFDDDD">';
  126:         } else {
  127:             $tableheader.='<th>';
  128:         }
  129:         $tableheader.="<b><font size=+1>$_</font></b></th>";
  130:         $label_num++;
  131:     }
  132:     $tableheader.="</tr>\n";
  133:     #
  134:     $r->print($tableheader);
  135:     #
  136:     # Print out template row
  137:     $r->print('<tr><td>Template</td><td>&nbsp;</td>'.
  138: 	      $self->html_template_row($num_uneditable)."</tr>\n");
  139:     #
  140:     # Print out summary/export row
  141:     $r->print('<tr><td>Summary</td><td>0</td>'.
  142: 	      $self->html_export_row()."</tr>\n");
  143:     #
  144:     # Prepare to output rows
  145:     $tableheader =<<"END";
  146: </p><p>
  147: <table border="2">
  148: <tr><th>Row</th>
  149:   <th>student</th><th>username</th><th>domain</th>
  150:   <th>section</th><th>status</th>
  151: END
  152:     foreach (split(//,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')){
  153: 	if ($label_num<$num_uneditable) { 
  154:             $tableheader.='<th bgcolor="#FFDDDD">';
  155:         } else {
  156:             $tableheader.='<th>';
  157:         }
  158:         $tableheader.="<b><font size=+1>$_</font></b></th>";
  159:     }
  160:     #
  161:     my $num_output = 0;
  162:     foreach my $student ($self->get_classlist()) {
  163: 	if ($num_output++ % 50 == 0) {
  164: 	    $r->print("</table>\n".$tableheader);
  165: 	}
  166: 	my $rownum = $self->get_row_number_from_key
  167: 	    ($student->{'username'}.':'.$student->{'domain'});
  168:         my $link = '<a href="/adm/studentcalc?sname='.$student->{'username'}.
  169:             '&sdomain='.$student->{'domain'}.'">';
  170:         $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
  171: 	$r->print('<tr>'.'<td>'.$rownum.'</td>'.
  172: 		  '<td>'.$link.$student->{'fullname'}.'</a></td>'.
  173: 		  '<td>'.$student->{'username'}.'</td>'.
  174: 		  '<td>'.$student->{'domain'}  .'</td>'.
  175: 		  '<td>'.$student->{'section'} .'</td>'.
  176: 		  '<td>'.$student->{'status'}  .'</td>'.
  177: 		  $self->html_row($num_uneditable,$rownum)."</tr>\n");
  178:     }
  179:     $r->print("</table></p>\n");
  180:     return;
  181: }
  182: 
  183: sub excel_rows {
  184:     # writes the meat of the spreadsheet to an excel worksheet.  Called
  185:     # by Spreadsheet::outsheet_excel;
  186:     my $self = shift;
  187:     my ($worksheet,$cols_output,$rows_output) = @_;
  188:     #
  189:     # Write a header row
  190:     $cols_output = 0;
  191:     foreach my $value ('fullname','username','domain','section','status') {
  192:         $worksheet->write($rows_output,$cols_output++,$value);
  193:     }
  194:     $rows_output++;    
  195:     #
  196:     # Write each students row
  197:     foreach my $student ($self->get_classlist()) {
  198:         $cols_output = 0;
  199: 	my $rownum = $self->get_row_number_from_key
  200: 	    ($student->{'username'}.':'.$student->{'domain'});
  201:         $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
  202:         my @studentdata = ($student->{'fullname'},
  203:                            $student->{'username'},
  204:                            $student->{'domain'},
  205:                            $student->{'section'},
  206:                            $student->{'status'});
  207:         $self->excel_output_row($worksheet,$rownum,$rows_output++,
  208:                                 @studentdata);
  209:     }
  210:     return;
  211: }
  212: 
  213: sub csv_rows {
  214:     # writes the meat of the spreadsheet to an excel worksheet.  Called
  215:     # by Spreadsheet::outsheet_excel;
  216:     my $self = shift;
  217:     my ($filehandle) = @_;
  218:     #
  219:     # Write a header row
  220: 
  221:     $self->csv_output_row($filehandle,undef,
  222:                           ('fullname','username','domain','section','status'));
  223:     #
  224:     # Write each students row
  225:     foreach my $student ($self->get_classlist()) {
  226: 	my $rownum = $self->get_row_number_from_key
  227: 	    ($student->{'username'}.':'.$student->{'domain'});
  228:         $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
  229:         my @studentdata = ($student->{'fullname'},
  230:                            $student->{'username'},
  231:                            $student->{'domain'},
  232:                            $student->{'section'},
  233:                            $student->{'status'});
  234:         $self->csv_output_row($filehandle,$rownum,@studentdata);
  235:     }
  236:     return;
  237: }
  238: 
  239: sub outsheet_recursive_excel {
  240:     my $self = shift;
  241:     my ($r) = @_;
  242: } 
  243: 
  244: sub compute {
  245:     my $self = shift;
  246:     my ($r) = @_;
  247:     $self->initialize_safe_space();
  248:     my %c = $self->constants();
  249:     my %f = $self->formulas();
  250:     my @Students = $self->get_classlist();
  251:     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
  252:         ($r,'Spreadsheet Computation Status',
  253:          'Spreadsheet Computation', scalar(@Students));
  254:     &Apache::studentcalc::initialize_package();
  255:     foreach my $student ($self->get_classlist()) {
  256:         my $sname = $student->{'username'}.':'.$student->{'domain'};
  257: 	my $studentsheet = Apache::studentcalc->new
  258: 	    ($student->{'username'},$student->{'domain'},undef);
  259: 	my @exportdata = $studentsheet->export_data();
  260: 	my $rownum = $self->get_row_number_from_key($sname);
  261:         $f{'A'.$rownum} = $sname;
  262:         $self->{'row_source'}->{$rownum} = $sname;
  263:         $c{'A'.$rownum} = shift(@exportdata);
  264: 	foreach (split(//,'BCDEFGHIJKLMNOPQRSTUVWXYZ')) {
  265:             my $cell = $_.$rownum;
  266:             my $data = shift(@exportdata);
  267:             if (defined($data)) {
  268:                 $f{$cell} = 'import';
  269:                 $c{$cell} = $data;
  270:             }
  271: 	}
  272:         &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
  273:                                                  'last student');
  274:     }
  275:     &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  276:     $r->rflush();
  277:     $self->constants(\%c);
  278:     $self->formulas(\%f);
  279:     $self->calcsheet();
  280: }
  281: 
  282: 1;
  283: 
  284: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>