Annotation of loncom/interface/loncoursedata.pm, revision 1.27
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.27 ! stredwic 4: # $Id: loncoursedata.pm,v 1.26 2002/08/30 17:11:43 stredwic Exp $
1.1 stredwic 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: =pod
31:
32: =head1 NAME
33:
34: loncoursedata
35:
36: =head1 SYNOPSIS
37:
1.22 stredwic 38: Set of functions that download and process student and course information.
1.1 stredwic 39:
40: =head1 PACKAGES USED
41:
42: Apache::Constants qw(:common :http)
43: Apache::lonnet()
1.22 stredwic 44: Apache::lonhtmlcommon
1.1 stredwic 45: HTML::TokeParser
46: GDBM_File
47:
48: =cut
49:
50: package Apache::loncoursedata;
51:
52: use strict;
53: use Apache::Constants qw(:common :http);
54: use Apache::lonnet();
1.13 stredwic 55: use Apache::lonhtmlcommon;
1.1 stredwic 56: use HTML::TokeParser;
57: use GDBM_File;
58:
59: =pod
60:
61: =head1 DOWNLOAD INFORMATION
62:
1.22 stredwic 63: This section contains all the functions that get data from other servers
64: and/or itself.
1.1 stredwic 65:
66: =cut
67:
68: # ----- DOWNLOAD INFORMATION -------------------------------------------
69:
70: =pod
71:
1.3 stredwic 72: =item &DownloadClasslist()
1.1 stredwic 73:
74: Collects lastname, generation, middlename, firstname, PID, and section for each
1.22 stredwic 75: student from their environment database. The section data is also download, though
76: it is in a rough format, and is processed later. The list of students is built from
77: collecting a classlist for the course that is to be displayed. Once the classlist
78: has been downloaded, its date stamp is recorded. Unless the datestamp for the
79: class database is reset or is modified, this data will not be downloaded again.
80: Also, there was talk about putting the fullname and section
81: and perhaps other pieces of data into the classlist file. This would
82: reduce the number of different file accesses and reduce the amount of
83: processing on this side.
1.1 stredwic 84:
85: =over 4
86:
1.21 matthew 87: Input: $courseID, $lastDownloadTime, $c
1.1 stredwic 88:
89: $courseID: The id of the course
90:
1.22 stredwic 91: $lastDownloadTime: This is the date stamp for when this information was
1.23 stredwic 92: last gathered. If it is set to Not downloaded, it will gather the data
1.22 stredwic 93: again, though it currently does not remove the old data.
1.21 matthew 94:
1.1 stredwic 95: $c: The connection class that can determine if the browser has aborted. It
1.21 matthew 96: is used to short circuit this function so that it does not continue to
1.1 stredwic 97: get information when there is no need.
98:
99: Output: \%classlist
100:
101: \%classlist: A pointer to a hash containing the following data:
102:
103: -A list of student name:domain (as keys) (known below as $name)
104:
105: -A hash pointer for each student containing lastname, generation, firstname,
1.23 stredwic 106: middlename, and PID : Key is $name.studentInformation
1.1 stredwic 107:
108: -A hash pointer to each students section data : Key is $name.section
109:
1.22 stredwic 110: -If there was an error in dump, it will be returned in the hash. See
111: the error codes for dump in lonnet. Also, an error key will be
112: generated if an abort occurs.
113:
1.1 stredwic 114: =back
115:
116: =cut
117:
1.3 stredwic 118: sub DownloadClasslist {
119: my ($courseID, $lastDownloadTime, $c)=@_;
1.1 stredwic 120: my ($courseDomain,$courseNumber)=split(/\_/,$courseID);
1.3 stredwic 121: my %classlist;
1.1 stredwic 122:
1.22 stredwic 123: my $modifiedTime = &Apache::lonnet::GetFileTimestamp($courseDomain, $courseNumber,
124: 'classlist.db',
125: $Apache::lonnet::perlvar{'lonUsersDir'});
126:
127: # Always download the information if lastDownloadTime is set to
1.23 stredwic 128: # Not downloaded, otherwise it is only downloaded if the file
1.22 stredwic 129: # has been updated and has a more recent date stamp
1.7 stredwic 130: if($lastDownloadTime ne 'Not downloaded' &&
131: $lastDownloadTime >= $modifiedTime && $modifiedTime >= 0) {
1.22 stredwic 132: # Data is not gathered so return UpToDate as true. This
133: # will be interpreted in ProcessClasslist
1.7 stredwic 134: $classlist{'lastDownloadTime'}=time;
135: $classlist{'UpToDate'} = 'true';
136: return \%classlist;
137: }
1.3 stredwic 138:
139: %classlist=&Apache::lonnet::dump('classlist',$courseDomain, $courseNumber);
1.20 stredwic 140: foreach(keys (%classlist)) {
141: if(/^(con_lost|error|no_such_host)/i) {
142: return \%classlist;
143: }
1.1 stredwic 144: }
145:
146: foreach my $name (keys(%classlist)) {
1.22 stredwic 147: if(defined($c) && ($c->aborted())) {
1.1 stredwic 148: $classlist{'error'}='aborted';
149: return \%classlist;
150: }
151:
152: my ($studentName,$studentDomain) = split(/\:/,$name);
153: # Download student environment data, specifically the full name and id.
154: my %studentInformation=&Apache::lonnet::get('environment',
155: ['lastname','generation',
156: 'firstname','middlename',
157: 'id'],
158: $studentDomain,
159: $studentName);
160: $classlist{$name.':studentInformation'}=\%studentInformation;
161:
162: if($c->aborted()) {
163: $classlist{'error'}='aborted';
164: return \%classlist;
165: }
166:
167: #Section
168: my %section=&Apache::lonnet::dump('roles',$studentDomain,$studentName);
1.3 stredwic 169: $classlist{$name.':sections'}=\%section;
1.1 stredwic 170: }
171:
1.3 stredwic 172: $classlist{'UpToDate'} = 'false';
173: $classlist{'lastDownloadTime'}=time;
174:
1.1 stredwic 175: return \%classlist;
176: }
177:
178: =pod
179:
1.4 stredwic 180: =item &DownloadCourseInformation()
1.1 stredwic 181:
1.22 stredwic 182: Dump of all the course information for a single student. The data can be
183: pruned by making use of dumps regular expression arguement. This function
184: also takes a regular expression which it passes straight through to dump.
185: The data is no escaped, because it is done elsewhere. It also
1.3 stredwic 186: checks the timestamp of the students course database file and only downloads
187: if it has been modified since the last download.
1.1 stredwic 188:
189: =over 4
190:
1.22 stredwic 191: Input: $namedata, $courseID, $lastDownloadTime, $WhatIWant
1.1 stredwic 192:
1.22 stredwic 193: $namedata: student name:domain
1.1 stredwic 194:
195: $courseID: The id of the course
196:
1.22 stredwic 197: $lastDownloadTime: This is the date stamp for when this information was
1.23 stredwic 198: last gathered. If it is set to Not downloaded, it will gather the data
1.22 stredwic 199: again, though it currently does not remove the old data.
200:
201: $WhatIWant: Regular expression used to get selected data with dump
202:
1.1 stredwic 203: Output: \%courseData
204:
1.23 stredwic 205: \%courseData: A hash pointer to the raw data from the students course
1.1 stredwic 206: database.
207:
208: =back
209:
210: =cut
211:
1.4 stredwic 212: sub DownloadCourseInformation {
1.12 stredwic 213: my ($namedata,$courseID,$lastDownloadTime,$WhatIWant)=@_;
1.3 stredwic 214: my %courseData;
1.4 stredwic 215: my ($name,$domain) = split(/\:/,$namedata);
1.1 stredwic 216:
1.22 stredwic 217: my $modifiedTime = &Apache::lonnet::GetFileTimestamp($domain, $name,
1.7 stredwic 218: $courseID.'.db',
219: $Apache::lonnet::perlvar{'lonUsersDir'});
220:
1.13 stredwic 221: if($lastDownloadTime >= $modifiedTime && $modifiedTime >= 0) {
1.22 stredwic 222: # Data is not gathered so return UpToDate as true. This
223: # will be interpreted in ProcessClasslist
1.13 stredwic 224: $courseData{$namedata.':lastDownloadTime'}=time;
225: $courseData{$namedata.':UpToDate'} = 'true';
1.7 stredwic 226: return \%courseData;
227: }
1.3 stredwic 228:
1.4 stredwic 229: # Download course data
1.12 stredwic 230: if(!defined($WhatIWant)) {
1.22 stredwic 231: # set the regular expression to everything by setting it to period
1.12 stredwic 232: $WhatIWant = '.';
233: }
234: %courseData=&Apache::lonnet::dump($courseID, $domain, $name, $WhatIWant);
1.3 stredwic 235: $courseData{'UpToDate'} = 'false';
236: $courseData{'lastDownloadTime'}=time;
1.13 stredwic 237:
238: my %newData;
239: foreach (keys(%courseData)) {
1.22 stredwic 240: # need to have the keys to be prepended with the name:domain of the
241: # student to reduce data collision later.
1.13 stredwic 242: $newData{$namedata.':'.$_} = $courseData{$_};
243: }
244:
245: return \%newData;
1.1 stredwic 246: }
247:
248: # ----- END DOWNLOAD INFORMATION ---------------------------------------
249:
250: =pod
251:
252: =head1 PROCESSING FUNCTIONS
253:
254: These functions process all the data for all the students. Also, they
1.22 stredwic 255: are the functions that access the cache database for writing the majority of
256: the time. The downloading and caching were separated to reduce problems
1.23 stredwic 257: with stopping downloading then can not tie hash to database later.
1.1 stredwic 258:
259: =cut
260:
261: # ----- PROCESSING FUNCTIONS ---------------------------------------
262:
263: =pod
264:
265: =item &ProcessTopResourceMap()
266:
267: Trace through the "big hash" created in rat/lonuserstate.pm::loadmap.
268: Basically, this function organizes a subset of the data and stores it in
269: cached data. The data stored is the problems, sequences, sequence titles,
270: parts of problems, and their ordering. Column width information is also
271: partially handled here on a per sequence basis.
272:
273: =over 4
274:
275: Input: $cache, $c
276:
277: $cache: A pointer to a hash to store the information
278:
279: $c: The connection class used to determine if an abort has been sent to the
280: browser
281:
282: Output: A string that contains an error message or "OK" if everything went
283: smoothly.
284:
285: =back
286:
287: =cut
288:
289: sub ProcessTopResourceMap {
1.11 stredwic 290: my ($cache,$c)=@_;
1.1 stredwic 291: my %hash;
292: my $fn=$ENV{'request.course.fn'};
293: if(-e "$fn.db") {
294: my $tieTries=0;
295: while($tieTries < 3) {
296: if($c->aborted()) {
297: return;
298: }
1.10 stredwic 299: if(tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) {
1.1 stredwic 300: last;
301: }
302: $tieTries++;
303: sleep 1;
304: }
305: if($tieTries >= 3) {
306: return 'Coursemap undefined.';
307: }
308: } else {
309: return 'Can not open Coursemap.';
310: }
311:
312: # Initialize state machine. Set information pointing to top level map.
313: my (@sequences, @currentResource, @finishResource);
314: my ($currentSequence, $currentResourceID, $lastResourceID);
315:
316: $currentResourceID=$hash{'ids_/res/'.$ENV{'request.course.uri'}};
317: push(@currentResource, $currentResourceID);
318: $lastResourceID=-1;
319: $currentSequence=-1;
320: my $topLevelSequenceNumber = $currentSequence;
321:
1.11 stredwic 322: my %sequenceRecord;
1.1 stredwic 323: while(1) {
324: if($c->aborted()) {
325: last;
326: }
327: # HANDLE NEW SEQUENCE!
328: #if page || sequence
1.11 stredwic 329: if(defined($hash{'map_pc_'.$hash{'src_'.$currentResourceID}}) &&
330: !defined($sequenceRecord{$currentResourceID})) {
331: $sequenceRecord{$currentResourceID}++;
1.1 stredwic 332: push(@sequences, $currentSequence);
333: push(@currentResource, $currentResourceID);
334: push(@finishResource, $lastResourceID);
335:
336: $currentSequence=$hash{'map_pc_'.$hash{'src_'.$currentResourceID}};
337:
338: # Mark sequence as containing problems. If it doesn't, then
339: # it will be removed when processing for this sequence is
340: # complete. This allows the problems in a sequence
341: # to be outputed before problems in the subsequences
342: if(!defined($cache->{'orderedSequences'})) {
343: $cache->{'orderedSequences'}=$currentSequence;
344: } else {
345: $cache->{'orderedSequences'}.=':'.$currentSequence;
346: }
347:
348: $lastResourceID=$hash{'map_finish_'.
349: $hash{'src_'.$currentResourceID}};
350: $currentResourceID=$hash{'map_start_'.
351: $hash{'src_'.$currentResourceID}};
352:
353: if(!($currentResourceID) || !($lastResourceID)) {
354: $currentSequence=pop(@sequences);
355: $currentResourceID=pop(@currentResource);
356: $lastResourceID=pop(@finishResource);
357: if($currentSequence eq $topLevelSequenceNumber) {
358: last;
359: }
360: }
1.12 stredwic 361: next;
1.1 stredwic 362: }
363:
364: # Handle gradable resources: exams, problems, etc
365: $currentResourceID=~/(\d+)\.(\d+)/;
366: my $partA=$1;
367: my $partB=$2;
368: if($hash{'src_'.$currentResourceID}=~
369: /\.(problem|exam|quiz|assess|survey|form)$/ &&
1.11 stredwic 370: $partA eq $currentSequence &&
371: !defined($sequenceRecord{$currentSequence.':'.
372: $currentResourceID})) {
373: $sequenceRecord{$currentSequence.':'.$currentResourceID}++;
1.1 stredwic 374: my $Problem = &Apache::lonnet::symbclean(
375: &Apache::lonnet::declutter($hash{'map_id_'.$partA}).
376: '___'.$partB.'___'.
377: &Apache::lonnet::declutter($hash{'src_'.
378: $currentResourceID}));
379:
380: $cache->{$currentResourceID.':problem'}=$Problem;
381: if(!defined($cache->{$currentSequence.':problems'})) {
382: $cache->{$currentSequence.':problems'}=$currentResourceID;
383: } else {
384: $cache->{$currentSequence.':problems'}.=
385: ':'.$currentResourceID;
386: }
387:
1.2 stredwic 388: my $meta=$hash{'src_'.$currentResourceID};
389: # $cache->{$currentResourceID.':title'}=
390: # &Apache::lonnet::metdata($meta,'title');
391: $cache->{$currentResourceID.':title'}=
392: $hash{'title_'.$currentResourceID};
1.9 minaeibi 393: $cache->{$currentResourceID.':source'}=
394: $hash{'src_'.$currentResourceID};
1.2 stredwic 395:
1.1 stredwic 396: # Get Parts for problem
1.8 stredwic 397: my %beenHere;
398: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'packages'))) {
399: if(/^\w+response_\d+.*/) {
400: my (undef, $partId, $responseId) = split(/_/,$_);
401: if($beenHere{'p:'.$partId} == 0) {
402: $beenHere{'p:'.$partId}++;
403: if(!defined($cache->{$currentSequence.':'.
404: $currentResourceID.':parts'})) {
405: $cache->{$currentSequence.':'.$currentResourceID.
406: ':parts'}=$partId;
407: } else {
408: $cache->{$currentSequence.':'.$currentResourceID.
409: ':parts'}.=':'.$partId;
410: }
411: }
412: if($beenHere{'r:'.$partId.':'.$responseId} == 0) {
413: $beenHere{'r:'.$partId.':'.$responseId}++;
414: if(!defined($cache->{$currentSequence.':'.
415: $currentResourceID.':'.$partId.
416: ':responseIDs'})) {
417: $cache->{$currentSequence.':'.$currentResourceID.
418: ':'.$partId.':responseIDs'}=$responseId;
419: } else {
420: $cache->{$currentSequence.':'.$currentResourceID.
421: ':'.$partId.':responseIDs'}.=':'.
422: $responseId;
423: }
1.1 stredwic 424: }
1.8 stredwic 425: if(/^optionresponse/ &&
426: $beenHere{'o:'.$partId.':'.$currentResourceID} == 0) {
427: $beenHere{'o:'.$partId.$currentResourceID}++;
428: if(defined($cache->{'OptionResponses'})) {
429: $cache->{'OptionResponses'}.= ':::'.
1.16 stredwic 430: $currentSequence.':'.$currentResourceID.':'.
431: $partId.':'.$responseId;
432: } else {
433: $cache->{'OptionResponses'}= $currentSequence.':'.
1.8 stredwic 434: $currentResourceID.':'.
435: $partId.':'.$responseId;
1.2 stredwic 436: }
437: }
438: }
1.8 stredwic 439: }
440: }
1.1 stredwic 441:
442: # if resource == finish resource, then it is the end of a sequence/page
443: if($currentResourceID eq $lastResourceID) {
444: # pop off last resource of sequence
445: $currentResourceID=pop(@currentResource);
446: $lastResourceID=pop(@finishResource);
447:
448: if(defined($cache->{$currentSequence.':problems'})) {
449: # Capture sequence information here
450: $cache->{$currentSequence.':title'}=
451: $hash{'title_'.$currentResourceID};
1.2 stredwic 452: $cache->{$currentSequence.':source'}=
453: $hash{'src_'.$currentResourceID};
1.1 stredwic 454:
455: my $totalProblems=0;
456: foreach my $currentProblem (split(/\:/,
457: $cache->{$currentSequence.
458: ':problems'})) {
459: foreach (split(/\:/,$cache->{$currentSequence.':'.
460: $currentProblem.
461: ':parts'})) {
462: $totalProblems++;
463: }
464: }
465: my @titleLength=split(//,$cache->{$currentSequence.
466: ':title'});
467: # $extra is 3 for problems correct and 3 for space
468: # between problems correct and problem output
469: my $extra = 6;
470: if(($totalProblems + $extra) > (scalar @titleLength)) {
471: $cache->{$currentSequence.':columnWidth'}=
472: $totalProblems + $extra;
473: } else {
474: $cache->{$currentSequence.':columnWidth'}=
475: (scalar @titleLength);
476: }
477: } else {
478: # Remove sequence from list, if it contains no problems to
479: # display.
480: $cache->{'orderedSequences'}=~s/$currentSequence//;
481: $cache->{'orderedSequences'}=~s/::/:/g;
482: $cache->{'orderedSequences'}=~s/^:|:$//g;
483: }
484:
485: $currentSequence=pop(@sequences);
486: if($currentSequence eq $topLevelSequenceNumber) {
487: last;
488: }
1.11 stredwic 489: }
1.1 stredwic 490:
491: # MOVE!!!
492: # move to next resource
493: unless(defined($hash{'to_'.$currentResourceID})) {
494: # big problem, need to handle. Next is probably wrong
1.11 stredwic 495: my $errorMessage = 'Big problem in ';
496: $errorMessage .= 'loncoursedata::ProcessTopLevelMap.';
497: $errorMessage .= ' bighash to_$currentResourceID not defined!';
498: &Apache::lonnet::logthis($errorMessage);
1.1 stredwic 499: last;
500: }
501: my @nextResources=();
502: foreach (split(/\,/,$hash{'to_'.$currentResourceID})) {
1.11 stredwic 503: if(!defined($sequenceRecord{$currentSequence.':'.
504: $hash{'goesto_'.$_}})) {
505: push(@nextResources, $hash{'goesto_'.$_});
506: }
1.1 stredwic 507: }
508: push(@currentResource, @nextResources);
509: # Set the next resource to be processed
510: $currentResourceID=pop(@currentResource);
511: }
512:
513: unless (untie(%hash)) {
514: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
515: "Could not untie coursemap $fn (browse)".
516: ".</font>");
517: }
518:
519: return 'OK';
520: }
521:
522: =pod
523:
1.3 stredwic 524: =item &ProcessClasslist()
1.1 stredwic 525:
1.3 stredwic 526: Taking the class list dumped from &DownloadClasslist(), all the
1.1 stredwic 527: students and their non-class information is processed using the
528: &ProcessStudentInformation() function. A date stamp is also recorded for
529: when the data was processed.
530:
1.3 stredwic 531: Takes data downloaded for a student and breaks it up into managable pieces and
532: stored in cache data. The username, domain, class related date, PID,
533: full name, and section are all processed here.
534:
1.1 stredwic 535: =over 4
536:
537: Input: $cache, $classlist, $courseID, $ChartDB, $c
538:
539: $cache: A hash pointer to store the data
540:
541: $classlist: The hash of data collected about a student from
1.3 stredwic 542: &DownloadClasslist(). The hash contains a list of students, a pointer
1.23 stredwic 543: to a hash of student information for each student, and each students section
1.1 stredwic 544: number.
545:
546: $courseID: The course ID
547:
548: $ChartDB: The name of the cache database file.
549:
550: $c: The connection class used to determine if an abort has been sent to the
551: browser
552:
553: Output: @names
554:
555: @names: An array of students whose information has been processed, and are to
556: be considered in an arbitrary order.
557:
558: =back
559:
560: =cut
561:
1.3 stredwic 562: sub ProcessClasslist {
563: my ($cache,$classlist,$courseID,$c)=@_;
1.1 stredwic 564: my @names=();
565:
1.3 stredwic 566: $cache->{'ClasslistTimeStamp'}=$classlist->{'lastDownloadTime'};
567: if($classlist->{'UpToDate'} eq 'true') {
568: return split(/:::/,$cache->{'NamesOfStudents'});;
569: }
570:
1.1 stredwic 571: foreach my $name (keys(%$classlist)) {
572: if($name =~ /\:section/ || $name =~ /\:studentInformation/ ||
1.3 stredwic 573: $name eq '' || $name eq 'UpToDate' || $name eq 'lastDownloadTime') {
1.1 stredwic 574: next;
575: }
576: if($c->aborted()) {
1.3 stredwic 577: return ();
1.1 stredwic 578: }
1.3 stredwic 579: my $studentInformation = $classlist->{$name.':studentInformation'},
580: my $sectionData = $classlist->{$name.':sections'},
581: my $date = $classlist->{$name},
582: my ($studentName,$studentDomain) = split(/\:/,$name);
583:
584: $cache->{$name.':username'}=$studentName;
585: $cache->{$name.':domain'}=$studentDomain;
1.10 stredwic 586: # Initialize timestamp for student
1.3 stredwic 587: if(!defined($cache->{$name.':lastDownloadTime'})) {
588: $cache->{$name.':lastDownloadTime'}='Not downloaded';
1.6 stredwic 589: $cache->{$name.':updateTime'}=' Not updated';
1.3 stredwic 590: }
591:
1.20 stredwic 592: my $error = 0;
593: foreach(keys(%$studentInformation)) {
594: if(/^(con_lost|error|no_such_host)/i) {
595: $cache->{$name.':error'}=
596: 'Could not download student environment data.';
597: $cache->{$name.':fullname'}='';
598: $cache->{$name.':id'}='';
599: $error = 1;
600: }
601: }
602: next if($error);
603: push(@names,$name);
604: $cache->{$name.':fullname'}=&ProcessFullName(
1.3 stredwic 605: $studentInformation->{'lastname'},
606: $studentInformation->{'generation'},
607: $studentInformation->{'firstname'},
608: $studentInformation->{'middlename'});
1.20 stredwic 609: $cache->{$name.':id'}=$studentInformation->{'id'};
1.3 stredwic 610:
611: my ($end, $start)=split(':',$date);
612: $courseID=~s/\_/\//g;
613: $courseID=~s/^(\w)/\/$1/;
614:
615: my $sec='';
616: foreach my $key (keys (%$sectionData)) {
617: my $value = $sectionData->{$key};
618: if ($key=~/^$courseID(?:\/)*(\w+)*\_st$/) {
619: my $tempsection=$1;
620: if($key eq $courseID.'_st') {
621: $tempsection='';
622: }
623: my ($dummy,$roleend,$rolestart)=split(/\_/,$value);
624: if($roleend eq $end && $rolestart eq $start) {
625: $sec = $tempsection;
626: last;
627: }
628: }
629: }
630:
631: my $status='Expired';
632: if(((!$end) || time < $end) && ((!$start) || (time > $start))) {
633: $status='Active';
634: }
635: $cache->{$name.':Status'}=$status;
636: $cache->{$name.':section'}=$sec;
1.7 stredwic 637:
638: if($sec eq '' || !defined($sec) || $sec eq ' ') {
639: $sec = 'none';
640: }
641: if(defined($cache->{'sectionList'})) {
642: if($cache->{'sectionList'} !~ /(^$sec:|^$sec$|:$sec$|:$sec:)/) {
643: $cache->{'sectionList'} .= ':'.$sec;
644: }
645: } else {
646: $cache->{'sectionList'} = $sec;
647: }
1.1 stredwic 648: }
649:
1.3 stredwic 650: $cache->{'ClasslistTimestamp'}=time;
651: $cache->{'NamesOfStudents'}=join(':::',@names);
1.1 stredwic 652:
653: return @names;
654: }
655:
656: =pod
657:
658: =item &ProcessStudentData()
659:
660: Takes the course data downloaded for a student in
1.4 stredwic 661: &DownloadCourseInformation() and breaks it up into key value pairs
1.1 stredwic 662: to be stored in the cached data. The keys are comprised of the
663: $username:$domain:$keyFromCourseDatabase. The student username:domain is
1.23 stredwic 664: stored away signifying that the students information has been downloaded and
1.1 stredwic 665: can be reused from cached data.
666:
667: =over 4
668:
669: Input: $cache, $courseData, $name
670:
671: $cache: A hash pointer to store data
672:
673: $courseData: A hash pointer that points to the course data downloaded for a
674: student.
675:
676: $name: username:domain
677:
678: Output: None
679:
680: *NOTE: There is no output, but an error message is stored away in the cache
681: data. This is checked in &FormatStudentData(). The key username:domain:error
682: will only exist if an error occured. The error is an error from
1.4 stredwic 683: &DownloadCourseInformation().
1.1 stredwic 684:
685: =back
686:
687: =cut
688:
689: sub ProcessStudentData {
690: my ($cache,$courseData,$name)=@_;
691:
1.13 stredwic 692: if(!&CheckDateStampError($courseData, $cache, $name)) {
693: return;
694: }
695:
1.26 stredwic 696: if(defined($cache->{$name.':keys'})) {
697: foreach (split(':::', $cache->{$name.':keys'})) {
698: delete $cache->{$name.':'.$_};
699: }
700: }
701:
702: my %courseKeys;
1.22 stredwic 703: # user name:domain was prepended earlier in DownloadCourseInformation
1.13 stredwic 704: foreach (keys %$courseData) {
1.26 stredwic 705: my $currentKey =~ s/^$name//;
706: $courseKeys{$currentKey}++;
1.13 stredwic 707: $cache->{$_}=$courseData->{$_};
708: }
709:
1.26 stredwic 710: $cache->{$name.':keys'} = join(':::', keys(%courseKeys));
711:
1.13 stredwic 712: return;
713: }
714:
1.22 stredwic 715: =pod
716:
717: =item &ExtractStudentData()
718:
719: HISTORY: This function originally existed in every statistics module,
720: and performed different tasks, the had some overlap. Due to the need
721: for the data from the different modules, they were combined into
722: a single function.
723:
724: This function now extracts all the necessary course data for a student
725: from what was downloaded from their homeserver. There is some extra
726: time overhead compared to the ProcessStudentInformation function, but
727: it would have had to occurred at some point anyways. This is now
728: typically called while downloading the data it will process. It is
729: the brother function to ProcessStudentInformation.
730:
731: =over 4
732:
733: Input: $input, $output, $data, $name
734:
735: $input: A hash that contains the input data to be processed
736:
737: $output: A hash to contain the processed data
738:
739: $data: A hash containing the information on what is to be
740: processed and how (basically).
741:
742: $name: username:domain
743:
744: The input is slightly different here, but is quite simple.
745: It is currently used where the $input, $output, and $data
746: can and are often the same hashes, but they do not need
747: to be.
748:
749: Output: None
750:
751: *NOTE: There is no output, but an error message is stored away in the cache
752: data. This is checked in &FormatStudentData(). The key username:domain:error
753: will only exist if an error occured. The error is an error from
754: &DownloadCourseInformation().
755:
756: =back
757:
758: =cut
759:
1.13 stredwic 760: sub ExtractStudentData {
761: my ($input, $output, $data, $name)=@_;
762:
763: if(!&CheckDateStampError($input, $data, $name)) {
1.3 stredwic 764: return;
765: }
766:
1.26 stredwic 767: my %allkeys;
768: if(defined($output->{$name.':keys'})) {
769: foreach (split(':::', $output->{$name.':keys'})) {
770: delete $output->{$name.':'.$_};
771: }
772: }
773:
1.13 stredwic 774: my ($username,$domain)=split(':',$name);
775:
776: my $Version;
777: my $problemsCorrect = 0;
778: my $totalProblems = 0;
779: my $problemsSolved = 0;
780: my $numberOfParts = 0;
1.14 stredwic 781: my $totalAwarded = 0;
1.13 stredwic 782: foreach my $sequence (split(':', $data->{'orderedSequences'})) {
783: foreach my $problemID (split(':', $data->{$sequence.':problems'})) {
784: my $problem = $data->{$problemID.':problem'};
785: my $LatestVersion = $input->{$name.':version:'.$problem};
786:
787: # Output dashes for all the parts of this problem if there
788: # is no version information about the current problem.
1.27 ! stredwic 789: $output->{$name.':'.$problemID.':NoVersion'} = 'false';
! 790: $allkeys{$name.':'.$problemID.':NoVersion'}++;
1.13 stredwic 791: if(!$LatestVersion) {
792: foreach my $part (split(/\:/,$data->{$sequence.':'.
793: $problemID.
794: ':parts'})) {
1.15 stredwic 795: $output->{$name.':'.$problemID.':'.$part.':tries'} = 0;
796: $output->{$name.':'.$problemID.':'.$part.':awarded'} = 0;
797: $output->{$name.':'.$problemID.':'.$part.':code'} = ' ';
1.26 stredwic 798: $allkeys{$name.':'.$problemID.':'.$part.':tries'}++;
799: $allkeys{$name.':'.$problemID.':'.$part.':awarded'}++;
800: $allkeys{$name.':'.$problemID.':'.$part.':code'}++;
1.13 stredwic 801: $totalProblems++;
802: }
803: $output->{$name.':'.$problemID.':NoVersion'} = 'true';
804: next;
805: }
806:
807: my %partData=undef;
808: # Initialize part data, display skips correctly
809: # Skip refers to when a student made no submissions on that
810: # part/problem.
811: foreach my $part (split(/\:/,$data->{$sequence.':'.
812: $problemID.
813: ':parts'})) {
814: $partData{$part.':tries'}=0;
815: $partData{$part.':code'}=' ';
816: $partData{$part.':awarded'}=0;
817: $partData{$part.':timestamp'}=0;
818: foreach my $response (split(':', $data->{$sequence.':'.
819: $problemID.':'.
820: $part.':responseIDs'})) {
821: $partData{$part.':'.$response.':submission'}='';
822: }
823: }
824:
825: # Looping through all the versions of each part, starting with the
826: # oldest version. Basically, it gets the most recent
827: # set of grade data for each part.
828: my @submissions = ();
829: for(my $Version=1; $Version<=$LatestVersion; $Version++) {
830: foreach my $part (split(/\:/,$data->{$sequence.':'.
831: $problemID.
832: ':parts'})) {
833:
834: if(!defined($input->{"$name:$Version:$problem".
835: ":resource.$part.solved"})) {
836: # No grade for this submission, so skip
837: next;
838: }
839:
840: my $tries=0;
841: my $code=' ';
842: my $awarded=0;
843:
844: $tries = $input->{$name.':'.$Version.':'.$problem.
845: ':resource.'.$part.'.tries'};
846: $awarded = $input->{$name.':'.$Version.':'.$problem.
847: ':resource.'.$part.'.awarded'};
848:
849: $partData{$part.':awarded'}=($awarded) ? $awarded : 0;
850: $partData{$part.':tries'}=($tries) ? $tries : 0;
851:
852: $partData{$part.':timestamp'}=$input->{$name.':'.$Version.':'.
853: $problem.
854: ':timestamp'};
855: if(!$input->{$name.':'.$Version.':'.$problem.':resource.'.$part.
856: '.previous'}) {
857: foreach my $response (split(':',
858: $data->{$sequence.':'.
859: $problemID.':'.
860: $part.':responseIDs'})) {
861: @submissions=($input->{$name.':'.$Version.':'.
862: $problem.
863: ':resource.'.$part.'.'.
864: $response.'.submission'},
865: @submissions);
866: }
867: }
868:
869: my $val = $input->{$name.':'.$Version.':'.$problem.
870: ':resource.'.$part.'.solved'};
871: if ($val eq 'correct_by_student') {$code = '*';}
872: elsif ($val eq 'correct_by_override') {$code = '+';}
873: elsif ($val eq 'incorrect_attempted') {$code = '.';}
874: elsif ($val eq 'incorrect_by_override'){$code = '-';}
875: elsif ($val eq 'excused') {$code = 'x';}
876: elsif ($val eq 'ungraded_attempted') {$code = '#';}
877: else {$code = ' ';}
878: $partData{$part.':code'}=$code;
879: }
880: }
881:
882: foreach my $part (split(/\:/,$data->{$sequence.':'.$problemID.
883: ':parts'})) {
884: $output->{$name.':'.$problemID.':'.$part.':wrong'} =
885: $partData{$part.':tries'};
1.26 stredwic 886: $allkeys{$name.':'.$problemID.':'.$part.':wrong'}++;
1.13 stredwic 887:
888: if($partData{$part.':code'} eq '*') {
889: $output->{$name.':'.$problemID.':'.$part.':wrong'}--;
890: $problemsCorrect++;
891: } elsif($partData{$part.':code'} eq '+') {
892: $output->{$name.':'.$problemID.':'.$part.':wrong'}--;
893: $problemsCorrect++;
894: }
895:
896: $output->{$name.':'.$problemID.':'.$part.':tries'} =
897: $partData{$part.':tries'};
898: $output->{$name.':'.$problemID.':'.$part.':code'} =
899: $partData{$part.':code'};
900: $output->{$name.':'.$problemID.':'.$part.':awarded'} =
901: $partData{$part.':awarded'};
1.26 stredwic 902: $allkeys{$name.':'.$problemID.':'.$part.':tries'}++;
903: $allkeys{$name.':'.$problemID.':'.$part.':code'}++;
904: $allkeys{$name.':'.$problemID.':'.$part.':awarded'}++;
905:
1.14 stredwic 906: $totalAwarded += $partData{$part.':awarded'};
1.13 stredwic 907: $output->{$name.':'.$problemID.':'.$part.':timestamp'} =
908: $partData{$part.':timestamp'};
1.26 stredwic 909: $allkeys{$name.':'.$problemID.':'.$part.':timestamp'}++;
910:
1.13 stredwic 911: foreach my $response (split(':', $data->{$sequence.':'.
912: $problemID.':'.
913: $part.':responseIDs'})) {
914: $output->{$name.':'.$problemID.':'.$part.':'.$response.
915: ':submission'}=join(':::',@submissions);
1.26 stredwic 916: $allkeys{$name.':'.$problemID.':'.$part.':'.$response.
917: ':submission'}++;
1.13 stredwic 918: }
1.3 stredwic 919:
1.13 stredwic 920: if($partData{$part.':code'} ne 'x') {
921: $totalProblems++;
922: }
923: }
1.1 stredwic 924: }
1.13 stredwic 925:
926: $output->{$name.':'.$sequence.':problemsCorrect'} = $problemsCorrect;
1.26 stredwic 927: $allkeys{$name.':'.$sequence.':problemsCorrect'}++;
1.13 stredwic 928: $problemsSolved += $problemsCorrect;
929: $problemsCorrect=0;
1.3 stredwic 930: }
931:
1.13 stredwic 932: $output->{$name.':problemsSolved'} = $problemsSolved;
933: $output->{$name.':totalProblems'} = $totalProblems;
1.14 stredwic 934: $output->{$name.':totalAwarded'} = $totalAwarded;
1.26 stredwic 935: $allkeys{$name.':problemsSolved'}++;
936: $allkeys{$name.':totalProblems'}++;
937: $allkeys{$name.':totalAwarded'}++;
938:
939: $output->{$name.':keys'} = join(':::', keys(%allkeys));
1.1 stredwic 940:
941: return;
1.4 stredwic 942: }
943:
944: sub LoadDiscussion {
1.13 stredwic 945: my ($courseID)=@_;
1.5 minaeibi 946: my %Discuss=();
947: my %contrib=&Apache::lonnet::dump(
948: $courseID,
949: $ENV{'course.'.$courseID.'.domain'},
950: $ENV{'course.'.$courseID.'.num'});
951:
952: #my %contrib=&DownloadCourseInformation($name, $courseID, 0);
953:
1.4 stredwic 954: foreach my $temp(keys %contrib) {
955: if ($temp=~/^version/) {
956: my $ver=$contrib{$temp};
957: my ($dummy,$prb)=split(':',$temp);
958: for (my $idx=1; $idx<=$ver; $idx++ ) {
959: my $name=$contrib{"$idx:$prb:sendername"};
1.5 minaeibi 960: $Discuss{"$name:$prb"}=$idx;
1.4 stredwic 961: }
962: }
963: }
1.5 minaeibi 964:
965: return \%Discuss;
1.1 stredwic 966: }
967:
968: # ----- END PROCESSING FUNCTIONS ---------------------------------------
969:
970: =pod
971:
972: =head1 HELPER FUNCTIONS
973:
974: These are just a couple of functions do various odd and end
1.22 stredwic 975: jobs. There was also a couple of bulk functions added. These are
976: &DownloadStudentCourseData(), &DownloadStudentCourseDataSeparate(), and
977: &CheckForResidualDownload(). These functions now act as the interface
978: for downloading student course data. The statistical modules should
979: no longer make the calls to dump and download and process etc. They
980: make calls to these bulk functions to get their data.
1.1 stredwic 981:
982: =cut
983:
984: # ----- HELPER FUNCTIONS -----------------------------------------------
985:
1.13 stredwic 986: sub CheckDateStampError {
987: my ($courseData, $cache, $name)=@_;
988: if($courseData->{$name.':UpToDate'} eq 'true') {
989: $cache->{$name.':lastDownloadTime'} =
990: $courseData->{$name.':lastDownloadTime'};
991: if($courseData->{$name.':lastDownloadTime'} eq 'Not downloaded') {
992: $cache->{$name.':updateTime'} = ' Not updated';
993: } else {
994: $cache->{$name.':updateTime'}=
995: localtime($courseData->{$name.':lastDownloadTime'});
996: }
997: return 0;
998: }
999:
1000: $cache->{$name.':lastDownloadTime'}=$courseData->{$name.':lastDownloadTime'};
1001: if($courseData->{$name.':lastDownloadTime'} eq 'Not downloaded') {
1002: $cache->{$name.':updateTime'} = ' Not updated';
1003: } else {
1004: $cache->{$name.':updateTime'}=
1005: localtime($courseData->{$name.':lastDownloadTime'});
1006: }
1007:
1008: if(defined($courseData->{$name.':error'})) {
1009: $cache->{$name.':error'}=$courseData->{$name.':error'};
1010: return 0;
1011: }
1012:
1013: return 1;
1014: }
1015:
1.1 stredwic 1016: =pod
1017:
1018: =item &ProcessFullName()
1019:
1020: Takes lastname, generation, firstname, and middlename (or some partial
1021: set of this data) and returns the full name version as a string. Format
1022: is Lastname generation, firstname middlename or a subset of this.
1023:
1024: =cut
1025:
1026: sub ProcessFullName {
1027: my ($lastname, $generation, $firstname, $middlename)=@_;
1028: my $Str = '';
1029:
1030: if($lastname ne '') {
1031: $Str .= $lastname.' ';
1032: if($generation ne '') {
1033: $Str .= $generation;
1034: } else {
1035: chop($Str);
1036: }
1037: $Str .= ', ';
1038: if($firstname ne '') {
1039: $Str .= $firstname.' ';
1040: }
1041: if($middlename ne '') {
1042: $Str .= $middlename;
1043: } else {
1044: chop($Str);
1045: if($firstname eq '') {
1046: chop($Str);
1047: }
1048: }
1049: } else {
1050: if($firstname ne '') {
1051: $Str .= $firstname.' ';
1052: }
1053: if($middlename ne '') {
1054: $Str .= $middlename.' ';
1055: }
1056: if($generation ne '') {
1057: $Str .= $generation;
1058: } else {
1059: chop($Str);
1060: }
1061: }
1062:
1063: return $Str;
1064: }
1065:
1066: =pod
1067:
1068: =item &TestCacheData()
1069:
1070: Determine if the cache database can be accessed with a tie. It waits up to
1071: ten seconds before returning failure. This function exists to help with
1072: the problems with stopping the data download. When an abort occurs and the
1073: user quickly presses a form button and httpd child is created. This
1074: child needs to wait for the other to finish (hopefully within ten seconds).
1075:
1076: =over 4
1077:
1078: Input: $ChartDB
1079:
1080: $ChartDB: The name of the cache database to be opened
1081:
1082: Output: -1, 0, 1
1083:
1.23 stredwic 1084: -1: Could not tie database
1.1 stredwic 1085: 0: Use cached data
1086: 1: New cache database created, use that.
1087:
1088: =back
1089:
1090: =cut
1091:
1092: sub TestCacheData {
1093: my ($ChartDB,$isRecalculate,$totalDelay)=@_;
1094: my $isCached=-1;
1095: my %testData;
1096: my $tieTries=0;
1097:
1098: if(!defined($totalDelay)) {
1099: $totalDelay = 10;
1100: }
1101:
1102: if ((-e "$ChartDB") && (!$isRecalculate)) {
1103: $isCached = 1;
1104: } else {
1105: $isCached = 0;
1106: }
1107:
1108: while($tieTries < $totalDelay) {
1109: my $result=0;
1110: if($isCached) {
1.10 stredwic 1111: $result=tie(%testData,'GDBM_File',$ChartDB,&GDBM_READER(),0640);
1.1 stredwic 1112: } else {
1.10 stredwic 1113: $result=tie(%testData,'GDBM_File',$ChartDB,&GDBM_NEWDB(),0640);
1.1 stredwic 1114: }
1115: if($result) {
1116: last;
1117: }
1118: $tieTries++;
1119: sleep 1;
1120: }
1121: if($tieTries >= $totalDelay) {
1122: return -1;
1123: }
1124:
1125: untie(%testData);
1126:
1127: return $isCached;
1128: }
1.2 stredwic 1129:
1.13 stredwic 1130: sub DownloadStudentCourseData {
1131: my ($students,$checkDate,$cacheDB,$extract,$status,$courseID,$r,$c)=@_;
1132:
1133: my $title = 'LON-CAPA Statistics';
1134: my $heading = 'Download and Process Course Data';
1135: my $studentCount = scalar(@$students);
1.18 stredwic 1136:
1.13 stredwic 1137: my $WhatIWant;
1.20 stredwic 1138: $WhatIWant = '(^version:|';
1.18 stredwic 1139: $WhatIWant .= '^\d+:.+?:(resource\.\d+\.';
1.13 stredwic 1140: $WhatIWant .= '(solved|tries|previous|awarded|(\d+\.submission))\s*$';
1141: $WhatIWant .= '|timestamp)';
1142: $WhatIWant .= ')';
1.20 stredwic 1143: # $WhatIWant = '.';
1.13 stredwic 1144:
1145: if($status eq 'true') {
1146: &Apache::lonhtmlcommon::Create_PrgWin($r, $title, $heading);
1147: }
1.17 stredwic 1148:
1149: my $displayString;
1150: my $count=0;
1.13 stredwic 1151: foreach (@$students) {
1.24 stredwic 1152: my %cache;
1153:
1.13 stredwic 1154: if($c->aborted()) { return 'Aborted'; }
1155:
1156: if($status eq 'true') {
1.17 stredwic 1157: $count++;
1.13 stredwic 1158: my $displayString = $count.'/'.$studentCount.': '.$_;
1159: &Apache::lonhtmlcommon::Update_PrgWin($displayString, $r);
1160: }
1161:
1162: my $downloadTime='Not downloaded';
1163: if($checkDate eq 'true' &&
1164: tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1165: $downloadTime = $cache{$_.':lastDownloadTime'};
1166: untie(%cache);
1167: }
1168:
1169: if($c->aborted()) { return 'Aborted'; }
1170:
1.25 stredwic 1171: #if($downloadTime ne 'Not downloaded') {
1172: # next;
1173: #}
1.24 stredwic 1174: my $courseData =
1175: &DownloadCourseInformation($_, $courseID, $downloadTime,
1176: $WhatIWant);
1177: if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
1178: foreach my $key (keys(%$courseData)) {
1179: if($key =~ /^(con_lost|error|no_such_host)/i) {
1180: $courseData->{$_.':error'} = 'No course data for '.$_;
1181: last;
1182: }
1183: }
1184: if($extract eq 'true') {
1185: &ExtractStudentData($courseData, \%cache, \%cache, $_);
1186: } else {
1187: &ProcessStudentData(\%cache, $courseData, $_);
1188: }
1189: untie(%cache);
1190: } else {
1191: next;
1192: }
1.13 stredwic 1193: }
1194: if($status eq 'true') { &Apache::lonhtmlcommon::Close_PrgWin($r); }
1195:
1196: return 'OK';
1197: }
1198:
1199: sub DownloadStudentCourseDataSeparate {
1200: my ($students,$checkDate,$cacheDB,$extract,$status,$courseID,$r,$c)=@_;
1201: my $residualFile = '/home/httpd/perl/tmp/'.$courseID.'DownloadFile.db';
1202: my $title = 'LON-CAPA Statistics';
1203: my $heading = 'Download Course Data';
1204:
1205: my $WhatIWant;
1.20 stredwic 1206: $WhatIWant = '(^version:|';
1.18 stredwic 1207: $WhatIWant .= '^\d+:.+?:(resource\.\d+\.';
1.13 stredwic 1208: $WhatIWant .= '(solved|tries|previous|awarded|(\d+\.submission))\s*$';
1209: $WhatIWant .= '|timestamp)';
1210: $WhatIWant .= ')';
1211:
1212: &CheckForResidualDownload($courseID, $cacheDB, $students, $c);
1213:
1214: my $studentCount = scalar(@$students);
1215: if($status eq 'true') {
1216: &Apache::lonhtmlcommon::Create_PrgWin($r, $title, $heading);
1217: }
1.17 stredwic 1218: my $count=0;
1219: my $displayString='';
1.13 stredwic 1220: foreach (@$students) {
1221: if($c->aborted()) {
1222: return 'Aborted';
1223: }
1224:
1225: if($status eq 'true') {
1.17 stredwic 1226: $count++;
1227: $displayString = $count.'/'.$studentCount.': '.$_;
1.13 stredwic 1228: &Apache::lonhtmlcommon::Update_PrgWin($displayString, $r);
1229: }
1230:
1.24 stredwic 1231: my %cache;
1.13 stredwic 1232: my $downloadTime='Not downloaded';
1233: if($checkDate eq 'true' &&
1234: tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1235: $downloadTime = $cache{$_.':lastDownloadTime'};
1236: untie(%cache);
1237: }
1238:
1239: if($c->aborted()) {
1240: return 'Aborted';
1241: }
1242:
1.25 stredwic 1243: #if($downloadTime eq 'Not downloaded') {
1.13 stredwic 1244: my $error = 0;
1245: my $courseData =
1246: &DownloadCourseInformation($_, $courseID, $downloadTime,
1247: $WhatIWant);
1.18 stredwic 1248: my %downloadData;
1249: unless(tie(%downloadData,'GDBM_File',$residualFile,
1250: &GDBM_WRCREAT(),0640)) {
1251: return 'Failed to tie temporary download hash.';
1252: }
1.13 stredwic 1253: foreach my $key (keys(%$courseData)) {
1254: $downloadData{$key} = $courseData->{$key};
1255: if($key =~ /^(con_lost|error|no_such_host)/i) {
1256: $error = 1;
1257: last;
1258: }
1259: }
1260: if($error) {
1261: foreach my $deleteKey (keys(%$courseData)) {
1262: delete $downloadData{$deleteKey};
1263: }
1264: $downloadData{$_.':error'} = 'No course data for '.$_;
1265: }
1.18 stredwic 1266: untie(%downloadData);
1.25 stredwic 1267: #}
1.13 stredwic 1268: }
1269: if($status eq 'true') { &Apache::lonhtmlcommon::Close_PrgWin($r); }
1270:
1271: return &CheckForResidualDownload($cacheDB, 'true', 'true',
1272: $courseID, $r, $c);
1273: }
1274:
1275: sub CheckForResidualDownload {
1276: my ($cacheDB,$extract,$status,$courseID,$r,$c)=@_;
1277:
1278: my $residualFile = '/home/httpd/perl/tmp/'.$courseID.'DownloadFile.db';
1279: if(!-e $residualFile) {
1.18 stredwic 1280: return 'OK';
1.13 stredwic 1281: }
1282:
1283: my %downloadData;
1284: my %cache;
1.17 stredwic 1285: unless(tie(%downloadData,'GDBM_File',$residualFile,&GDBM_READER(),0640)) {
1286: return 'Can not tie database for check for residual download: tempDB';
1287: }
1288: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
1289: untie(%downloadData);
1290: return 'Can not tie database for check for residual download: cacheDB';
1.13 stredwic 1291: }
1292:
1293: my @students=();
1294: my %checkStudent;
1.18 stredwic 1295: my $key;
1296: while(($key, undef) = each %downloadData) {
1297: my @temp = split(':', $key);
1.13 stredwic 1298: my $student = $temp[0].':'.$temp[1];
1299: if(!defined($checkStudent{$student})) {
1300: $checkStudent{$student}++;
1301: push(@students, $student);
1302: }
1303: }
1304:
1305: my $heading = 'Process Course Data';
1306: my $title = 'LON-CAPA Statistics';
1307: my $studentCount = scalar(@students);
1308: if($status eq 'true') {
1309: &Apache::lonhtmlcommon::Create_PrgWin($r, $title, $heading);
1310: }
1311:
1.20 stredwic 1312: my $count=1;
1.13 stredwic 1313: foreach my $name (@students) {
1314: last if($c->aborted());
1315:
1316: if($status eq 'true') {
1.19 stredwic 1317: my $displayString = $count.'/'.$studentCount.': '.$name;
1.13 stredwic 1318: &Apache::lonhtmlcommon::Update_PrgWin($displayString, $r);
1319: }
1320:
1321: if($extract eq 'true') {
1322: &ExtractStudentData(\%downloadData, \%cache, \%cache, $name);
1323: } else {
1324: &ProcessStudentData(\%cache, \%downloadData, $name);
1325: }
1326: $count++;
1327: }
1328:
1329: if($status eq 'true') { &Apache::lonhtmlcommon::Close_PrgWin($r); }
1330:
1331: untie(%cache);
1332: untie(%downloadData);
1333:
1334: if(!$c->aborted()) {
1335: my @files = ($residualFile);
1336: unlink(@files);
1337: }
1338:
1339: return 'OK';
1.3 stredwic 1340: }
1.1 stredwic 1341:
1342: # ----- END HELPER FUNCTIONS --------------------------------------------
1343:
1344: 1;
1345: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>