countpoints.pl
| 1 | #!/usr/bin/perl -w |
|---|---|
| 2 | # count questions and points for mc and open questions. |
| 3 | # The script makes specific assumptions about the |
| 4 | # directory layout of a project, fitting the fontys venlo way of working. |
| 5 | # %% <CourseDir> |
| 6 | # %% ├── builds |
| 7 | # %% │ ├── <ExamInstance>, e.g. 20120628 |
| 8 | # %% │ |
| 9 | # %% └── questions, and resources e.g. |
| 10 | # %% ├── figures |
| 11 | # %% ├── q1h01 |
| 12 | |
| 13 | my ($quest,$opencount,$openpoints,$mccount,$mcpoints); |
| 14 | |
| 15 | sub countCat($$$); |
| 16 | my $defpoints=2; |
| 17 | countCat("questions.tex",'mc',$defpoints);
|
| 18 | my $defpoints=5; |
| 19 | countCat("openquestions.tex",'mc',$defpoints);
|
| 20 | exit 0; |
| 21 | |
| 22 | sub countCat($$$) {
|
| 23 | my ($qfile,$cat) = @_; |
| 24 | if (open(QUESTIONS,"<$qfile")) {
|
| 25 | while (<QUESTIONS>) {
|
| 26 | chomp; |
| 27 | s/\\element{general}{//;
|
| 28 | s/}}//; |
| 29 | s/\\inputQ{/..\/..\/questions\//;
|
| 30 | $quest=$_; |
| 31 | if (open(QUEST,"<$quest")) {
|
| 32 | $delta = $defpoints; |
| 33 | while (<QUEST>) {
|
| 34 | if (m/\%\%maxpoints=(\d+)/) {
|
| 35 | $delta =$1; |
| 36 | } |
| 37 | } |
| 38 | $mccount++; |
| 39 | $mcpoints +=$delta; |
| 40 | close(QUEST); |
| 41 | } else {
|
| 42 | print STDERR "WARNING: cannot open question file $quest\n"; |
| 43 | } |
| 44 | } |
| 45 | close(QUESTIONS); |
| 46 | |
| 47 | qq(\\def\\${cat}count{$mccount}\n).
|
| 48 | qq(\\def\\${cat}count{$mcpoints}\n);
|
| 49 | } else {
|
| 50 | print STDERR "WARNING: could not open file $qfile\n"; |
| 51 | } |
| 52 | } # end of countCat. |