[system] / trunk / webwork / system / scripts / proceduresForBuildProbSetDB.pl Repository:
ViewVC logotype

View of /trunk/webwork/system/scripts/proceduresForBuildProbSetDB.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (download) (as text) (annotate)
Mon Jun 18 15:21:51 2001 UTC (18 years, 5 months ago) by sam
File size: 13943 byte(s)
another setup script test (changed #! lines)

    1 #!/usr/local/bin/webwork-perl
    2 
    3 ## $Id$
    4 
    5 
    6 ####################################################################
    7 # Copyright @ 1995-1998 University of Rochester
    8 # All Rights Reserved
    9 ####################################################################
   10 
   11 
   12 
   13 # This file is proceduresForBuildProbSetDB.pl
   14 # Call with command arguments of the form:  set5.def  classl.gp
   15 # This file loads the database from the class list and the set definition
   16 ###################################################################
   17 
   18 use strict;
   19 
   20 #$method ='readFromLogFile';  ## or 'createNewPSVNs'
   21 #$method ='createNewPSVNs';
   22 #$logFileName = "sampleCourse_set:3_bak3.psvnlog";
   23 
   24 
   25 #########################
   26 
   27 sub buildProbSetDB  ## builds the problem set and returns a message
   28   {
   29   my ($classID,$setDefFilename,$method,$logFileName,$outputFormat) = @_;
   30   my $scriptDirectory   = $Global::scriptDirectory;
   31   &Global::getCourseEnvironment("$classID");
   32   my $databaseDirectory = $Global::databaseDirectory;
   33   my $templateDirectory = $Global::templateDirectory;
   34   my $logsDirectory = getCourseLogsDirectory();
   35 
   36   require "${scriptDirectory}$Global::DBglue_pl";
   37   require "${scriptDirectory}$Global::classlist_DBglue_pl";
   38   require "${scriptDirectory}$Global::FILE_pl";
   39 
   40 
   41        # Get data from set definition
   42 
   43   my $fileName="${templateDirectory}$setDefFilename";  ## e.g. $fileName=set5.def
   44   my $PIN;
   45   my $message = '';
   46   $message .= "\nGetting set definition from file: $fileName\n";
   47    # print  "Getting set definition from file: $fileName\n";
   48 
   49   my ($setNumber,$setHeaderFileName,$probHeaderFileName,$dueDate,$openDate,$answerDate,$problemListref,$problemValueListref,$problemAttemptLimitListref)
   50     = &readSetDef($fileName);
   51   my @problemList = @$problemListref;
   52   my @problemValueList = @$problemValueListref;
   53   my @problemAttemptLimitList = @$problemAttemptLimitListref;
   54   $message .= "  set Name or Number: $setNumber\n  openDate: $openDate\n  dueDate: $dueDate\n  answerDate: $answerDate\n\n";
   55 
   56 
   57   ## put dates into standard perl format, i.e. seconds since 1980
   58 
   59   $openDate = &unformatDateAndTime($openDate);
   60   $dueDate = &unformatDateAndTime($dueDate);
   61   $answerDate = &unformatDateAndTime($answerDate);
   62 
   63 
   64   #get data from class list.
   65   #  $fileName="${templateDirectory}$classlistFilename";  ## e.g. fileName=m161.lst
   66   #  print "Getting class list from $fileName\n";
   67 # checkClasslistFile($Global::noOfFieldsInClasslist,$fileName);
   68  #   open(FILE, "$fileName") || wwerror($0, "Can't open $fileName");
   69  #   my @classList=<FILE>;
   70  #   close(FILE);
   71   ###################################
   72   #  Before building the database we pause to check that the database file exists
   73   # (if not we create it).
   74   ###################################
   75   if ( -e "${databaseDirectory}$Global::database" ) {
   76 
   77   my @data = stat("${databaseDirectory}$Global::database");
   78   ## This statement is a hack.  When using Berkeley DB 1.85 on a FreeBSD system
   79   ## sometimes this test returns true even when the database file does not exist.
   80   ## We have never seen this happen with the stat statement. Very strange indeed.
   81 
   82  #   $message .= "data base file statistics: @data\n\n";
   83 
   84   $message .= "Loading WeBWorK database: ${databaseDirectory}$Global::database\n";
   85   }
   86   else {
   87      # print "Data base ${databaseDirectory}$Global::database does not exist.\n\n";
   88      $message .=   "Data base ${databaseDirectory}$Global::database does not exist.\n\n";
   89  #       print "Create new database?(y or n)";
   90  #       my $tempinput = <STDIN>;
   91     my $tempinput = 'y';       ## always create a new database
   92     if ($tempinput =~ /y|Y/) {
   93      #     print "Creating new data base ${databaseDirectory}$Global::database.\n";
   94       $message .= "Creating new data base ${databaseDirectory}$Global::database.\n";
   95       create_db("${databaseDirectory}$Global::database", $Global::webwork_database_permission);
   96       if ( -e "${databaseDirectory}$Global::database" ) {
   97       chmod($Global::webwork_database_permission,"${databaseDirectory}$Global::database") ||
   98                wwerror($0, "Can't do chmod($Global::webwork_database_permission,${databaseDirectory}$Global::database)");
   99       chown(-1,$Global::numericalGroupID,"${databaseDirectory}$Global::database")  ||
  100                wwerror($0,"Can't do chown(-1,$Global::numericalGroupID,${databaseDirectory}$Global::database)");
  101        # print "New data base created\n";
  102       $message .=   "New data base created\n";
  103       }
  104       else {
  105        #   print "New data base could not be created\n";
  106         $message .=   "New data base could not be created\n";
  107       }
  108     }
  109     else {
  110 
  111       print "Abort buildProbSetDB.pl\n\n";
  112       exit;
  113       }
  114     }
  115 
  116   ## Create a logfile in which we will save the following data for each new psvn created
  117   ## $login_name $PIN seedForProb1 seedForProb2 seedForProb3 ...
  118 
  119   ##don't overwrite existing backups
  120   my $i=1;
  121   while(-e "${logsDirectory}${classID}_set:${setNumber}_bak${i}.psvnlog") {$i++;}
  122   my $fullLogFileName ="${logsDirectory}${classID}_set:${setNumber}_bak${i}.psvnlog";
  123   &createFile($fullLogFileName, 0660, $Global::numericalGroupID);
  124   open(LOGFILE,">$fullLogFileName")  or  wwerror($0, "Can't open $fullLogFileName");
  125 
  126   ## two hashes which are used in 'readFromLogFile' mode
  127   my (%psvnsHash,%seedsHash,@seedsArrayFromLogFile);
  128 
  129   if ($method eq 'readFromLogFile') {
  130     my (@lineArray, $loginID, $seedString);
  131     $logFileName = "${logsDirectory}${logFileName}";
  132      # print "Getting psvn's and problem seeds from $logFileName\n\n";
  133     $message .= "Getting psvn's and problem seeds from $logFileName\n\n";
  134     open(BAKLOGFILE,"$logFileName")  or wwerror($0, "Can't open $logFileName");
  135     while (<BAKLOGFILE>)
  136       {
  137       @lineArray = split;
  138       $loginID= shift(@lineArray);
  139       $psvnsHash{$loginID} = shift(@lineArray);
  140       $seedString = join ':', @lineArray;
  141       $seedsHash{$loginID} = $seedString;
  142     }
  143   close(BAKLOGFILE);
  144   }
  145 
  146 
  147   ## get a hash of all loginID's for set if set is already defined
  148 
  149   my %loginHashForSet =();
  150   if (&probSetExists($setNumber)) {%loginHashForSet = %{getLoginHashForSet($setNumber)};}
  151   my $new_student_count = 0;
  152   my $existing_student_count = 0;
  153 
  154   my $login_name;
  155 
  156   $message .= "Loading classlist database: ${databaseDirectory}$Global::CL_Database\n\n";
  157   my @classList = @{getAllLoginNamesSortedByName()};
  158 
  159   foreach $login_name (@classList)   {                  ## read through classlist database and create
  160                            ## problems for all active students
  161                            ## except if problems already exist for
  162     attachCLRecord($login_name);
  163                          ## student
  164     my $lastName    = CL_getStudentLastName($login_name);
  165     my $firstName   = CL_getStudentFirstName($login_name);
  166     my $status      = CL_getStudentStatus($login_name);
  167     my $comment     = CL_getComment($login_name);
  168     my $section     = CL_getClassSection($login_name);
  169     my $recitation    = CL_getClassRecitation($login_name);
  170     my $email_address = CL_getStudentEmailAddress($login_name);
  171     my $studentID   = CL_getStudentID($login_name);
  172 
  173 
  174 
  175     unless (&dropStatus($status))                   ## skip students who have dropped the course
  176       {
  177       if (defined $loginHashForSet{$login_name}) {
  178         $existing_student_count++;
  179         if (((defined $outputFormat) and ($outputFormat eq 'all_students')) or ($method eq 'readFromLogFile')){
  180           $message .= "   Problems for $firstName $lastName (login $login_name) already exist.  \n";
  181           $message .= "      Retaining probsetkey $loginHashForSet{$login_name} and data.  \n";
  182         }
  183       }
  184       elsif (($method eq 'readFromLogFile') and !(defined($psvnsHash{$login_name})))
  185         {
  186       #      print "$firstName $lastName (login $login_name) is not in the logfile $logFileName.  \n";
  187         $message .= "   $firstName $lastName (login $login_name) is not in the logfile $logFileName.  \n";
  188       #      print "      Problems for $firstName $lastName (login $login_name) not added.\n";
  189         $message .= "      Problems for $firstName $lastName (login $login_name) not added.\n";
  190         }
  191       elsif (($method eq 'readFromLogFile') and (&attachProbSetRecord($psvnsHash{$login_name}) ))
  192         {
  193         $PIN = $psvnsHash{$login_name};
  194         my $oldLogin = &getStudentLogin($PIN);
  195         attachCLRecord($oldLogin);
  196 
  197         my $oldFN = &CL_getStudentFirstName($oldLogin);
  198         my $oldLN =  &CL_getStudentLastName($oldLogin);
  199 
  200 #                print "ERROR, ERROR, ERROR\n";
  201 #                print "         The psvn $PIN already exists. It is assigned to $oldFN $oldLN  ($oldLogin).\n";
  202 #                print "         A new problem set must have been created after the psvn $PIN for \n";
  203 #                print "         $firstName $lastName (login $login_name) was deleted.\n";
  204 #        print "         Problems for $firstName $lastName (login $login_name) have not been added.\n";
  205 #                print "         After restoring all other psvn's for this set from the psvnlog(s),\n";
  206 #                print "         run buildProbSetDB.pl.  This will create a new psvn for  $login_name.\n";
  207 #                print "         Then use the dataMonger to restore the original problem seeds for\n";
  208 #                print "         $login_name.  The seeds for  $login_name  are listed in order in the file\n";
  209 #                print "         $logFileName, on the line begining: $login_name $PIN .\n";
  210         $message .=
  211         "ERROR, ERROR, ERROR\n
  212      The psvn $PIN already exists. It is assigned to $oldFN $oldLN  ($oldLogin).\n
  213      A new problem set must have been created after the psvn $PIN for \n
  214      $firstName $lastName (login $login_name) was deleted.\n
  215      Problems for $firstName $lastName (login $login_name) have not been added.\n
  216      After restoring all other psvn's for this set from the psvnlog(s), use \n
  217      Build problem sets from the Professor's page to build this set again.  This \n
  218      will create a new psvn for  $login_name.\n
  219      Then use Examine or modify data from the Professor's page to restore the original \n
  220      problem seeds for $login_name.  The seeds for  $login_name  are listed in order in \n
  221      the file $logFileName, on the line begining: $login_name $PIN .\n";
  222 
  223         }
  224       else
  225         {
  226         if ($method eq 'readFromLogFile')
  227           {
  228           $PIN = $psvnsHash{$login_name};
  229           }
  230         else
  231           {
  232           # Create a new unique pin number;
  233           my $min_psnv = 10**($Global::psvn_digits - 1);
  234           my $big_psvn = 10**$Global::psvn_digits - $min_psnv - 1;
  235           $PIN = int (  rand($big_psvn)+$min_psnv ); ##eg rand(8999)+1000
  236           $i=0;
  237           # Try for up to 200 times to create a pin number which hasn't been used.
  238           while ( &attachProbSetRecord($PIN)   ) {
  239              # print "psvn Number $PIN already taken\n" if $i>0 ;
  240             $message .= "psvn Number $PIN already taken\n" if $i>0 ;
  241             $PIN = int (  rand($big_psvn)+$min_psnv );
  242             ++$i;
  243             if ($i>200) { wwerror($0, 'Tried 200 times and could not find an unused psvn number.
  244               You have run out of psvn numbers.  In Global.pm, increase the variable \$psvn_digits')};
  245             }#end while loop
  246           } ##end of if ($method eq 'readFromLogFile')
  247         #       Store the record of pin numbers in @pinNumbersArray
  248         #       This can be used to delete pin numbers in case of a failure.
  249 
  250         #       push(@pinNumbersArray, $PIN);
  251 
  252         #       Create a random security number
  253         #               $securityNumber=int rand(99999);
  254         #               print "security number is $securityNumber\n";
  255 
  256         #       Install the necessary variables into pinRecord
  257 
  258   #     &putStudentLastName     ($lastName, $PIN);
  259   #     &putStudentFirstName    ($firstName, $PIN);
  260   #     &putStudentID           ($studentID, $PIN);
  261         &putStudentLogin        ($login_name,$PIN);
  262   #     &putStudentStatus       ($status,$PIN);
  263   #     &putClassSection        ($section,$PIN);
  264   #     &putClassRecitation     ($recitation,$PIN);
  265         &putSetNumber           ($setNumber, $PIN);
  266         &putSetHeaderFileName   ($setHeaderFileName, $PIN);
  267         &putProbHeaderFileName   ($probHeaderFileName, $PIN);
  268         &putDueDate             ($dueDate, $PIN);
  269         &putOpenDate            ($openDate, $PIN);
  270         &putAnswerDate          ($answerDate, $PIN);
  271   #     &putStudentEmailAddress ($email_address, $PIN);
  272 
  273         my @seedList =();
  274         my ($probNumber,$probSeed);
  275         #       Generate the problems
  276         if ($method eq 'readFromLogFile')   {@seedsArrayFromLogFile = split /:/,$seedsHash{$login_name};}
  277         for($i=0; $i<@problemList; ++$i) {
  278           $probNumber=$i+1;
  279           &putProblemFileName     ($problemList[$i],$probNumber, $PIN);
  280 
  281           if ($method eq 'readFromLogFile')   {$probSeed = shift @seedsArrayFromLogFile;}
  282           else {$probSeed = int( rand(5000) );}
  283 
  284           push (@seedList,$probSeed);  ## put seed in array to be saved later in log file
  285           &putProblemSeed         ($probSeed,$probNumber, $PIN);
  286           &putProblemValue        ($problemValueList[$i],$probNumber, $PIN);
  287           &putProblemMaxNumOfIncorrectAttemps       ($problemAttemptLimitList[$i],$probNumber, $PIN);
  288           &putProblemAttempted(0,$probNumber, $PIN);
  289           &putProblemStatus(0,$probNumber, $PIN);
  290           &putProblemNumOfCorrectAns       (0,$probNumber, $PIN);
  291           &putProblemNumOfIncorrectAns     (0,$probNumber, $PIN);
  292         }
  293 
  294 
  295         if (&detachProbSetRecord($PIN) )  {
  296          # print "probSetKey $PIN for $firstName $lastName (login $login_name) inserted succesfully\n";
  297 
  298         if (
  299           ((defined $outputFormat) and ($outputFormat ne 'no_students')) or
  300           ($method eq 'readFromLogFile')
  301         )  {
  302           $message .= "probSetKey $PIN for $firstName $lastName (login $login_name) inserted succesfully\n";
  303         }
  304           $new_student_count++;
  305           #         print "$login_name $PIN @seedList \n";
  306           print LOGFILE "$login_name $PIN @seedList \n";
  307           }
  308         else {
  309          # print "Couldn't insert probSetKey $PIN\n";
  310           $message .= "Couldn't insert probSetKey $PIN\n";
  311           }#endif
  312         } # end if else
  313       }#end unless
  314     }#endforeachLoop
  315    # print "\n";
  316   close(LOGFILE);
  317    # print "DONE\n";
  318   $message .= "\nData entered for $new_student_count new student(s) in set $setNumber.\n";
  319   $message .= "Data left unchanged for $existing_student_count existing student(s) in set $setNumber.\n";
  320   $message .= "\nFINISHED BUILDING PROBLEM SET\n\n";
  321   $message;
  322 } ### end of sub buildProbSetDB
  323 
  324 1;
  325 

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9