AMC-annotate.pl

Frédéric Bréal, 10/13/2019 02:33 pm

Download (9 kB)

 
1
#! /usr/bin/perl
2
#
3
# Copyright (C) 2013-2019 Alexis Bienvenue <paamc@passoire.fr>
4
#
5
# This file is part of Auto-Multiple-Choice
6
#
7
# Auto-Multiple-Choice is free software: you can redistribute it
8
# and/or modify it under the terms of the GNU General Public License
9
# as published by the Free Software Foundation, either version 2 of
10
# the License, or (at your option) any later version.
11
#
12
# Auto-Multiple-Choice is distributed in the hope that it will be
13
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
# General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Auto-Multiple-Choice.  If not, see
19
# <http://www.gnu.org/licenses/>.
20
21
use warnings;
22
use strict;
23
24
use Getopt::Long;
25
26
use AMC::Basic;
27
use AMC::Annotate;
28
use AMC::Exec;
29
30
my $single_output  = '';
31
my $sort           = '';
32
my $filename_model = '(N)-(ID)';
33
my $force_ascii    = 0;
34
35
my $pdf_subject   = '';
36
my $pdf_corrected = '';
37
my $pdf_dir       = '';
38
my $cr_dir        = "";
39
my $project_dir   = '';
40
my $projects_dir  = '';
41
42
my $id_file = '';
43
44
my $darkness_threshold    = '';
45
my $darkness_threshold_up = '';
46
47
my $data_dir = '';
48
49
my $debug = '';
50
51
my $progress    = 1;
52
my $progress_id = '';
53
54
my $text_color             = 'red';
55
my $line_width             = 2;
56
my $font_name              = 'Linux Libertine O 12';
57
my @o_symbols              = ();
58
my $annotate_indicatives   = '';
59
my $position               = 'marges';
60
my $dist_to_box            = '1cm';
61
my $dist_margin            = '5mm';
62
my $dist_margin_globaltext = '3mm';
63
64
my $significant_digits = 4;
65
66
my $verdict                    = 'TOTAL : %S/%M => %s/%m';
67
my $verdict_question_cancelled = '"X"';
68
my $verdict_question           = "\"%" . "s/%" . "m\"";
69
70
my $rtl = '';
71
72
my $names_file      = '';
73
my $names_encoding  = 'utf-8';
74
my $association_key = '', my $csv_build_name = '';
75
76
my $embedded_max_size     = "";
77
my $embedded_jpeg_quality = 80;
78
my $embedded_format       = "jpeg";
79
80
my $changes_only = '';
81
82
my $compose         = '';
83
my $latex_engine    = 'pdflatex';
84
my $src_file        = '';
85
my $filter          = '';
86
my $filtered_source = '';
87
my $n_copies        = 0;
88
89
# key is "to be ticked"-"ticked"
90
my %symboles = (
91
    '0-0' => {qw/type none/},
92
    '0-1' => {qw/type circle color red/},
93
    '1-0' => {qw/type mark color red/},
94
    '1-1' => {qw/type mark color blue/},
95
);
96
97
@ARGV = unpack_args(@ARGV);
98
99
GetOptions(
100
    "cr=s" => \$cr_dir,
101
    "project=s",      \$project_dir,
102
    "projects-dir=s", \$projects_dir,
103
    "data=s"                       => \$data_dir,
104
    "subject=s"                    => \$pdf_subject,
105
    "pdf-dir=s"                    => \$pdf_dir,
106
    "darkness-threshold=s"         => \$darkness_threshold,
107
    "darkness-threshold-up=s"      => \$darkness_threshold_up,
108
    "filename-model=s"             => \$filename_model,
109
    "force-ascii!"                 => \$force_ascii,
110
    "single-output=s"              => \$single_output,
111
    "sort=s"                       => \$sort,
112
    "id-file=s"                    => \$id_file,
113
    "debug=s"                      => \$debug,
114
    "progression=s"                => \$progress,
115
    "progression-id=s"             => \$progress_id,
116
    "line-width=s"                 => \$line_width,
117
    "font-name=s"                  => \$font_name,
118
    "text-color=s"                 => \$text_color,
119
    "symbols=s"                    => \@o_symbols,
120
    "indicatives!"                 => \$annotate_indicatives,
121
    "position=s"                   => \$position,
122
    "dist-to-box=s"                => \$dist_to_box,
123
    "dist-margin=s"                => \$dist_margin,
124
    "dist-margin-global=s"         => \$dist_margin_globaltext,
125
    "n-digits=s"                   => \$significant_digits,
126
    "verdict=s"                    => \$verdict,
127
    "verdict-question=s"           => \$verdict_question,
128
    "verdict-question-cancelled=s" => \$verdict_question_cancelled,
129
    "names-file=s"                 => \$names_file,
130
    "names-encoding=s"             => \$names_encoding,
131
    "association-key=s"            => \$association_key,
132
    "csv-build-name=s"             => \$csv_build_name,
133
    "rtl!"                         => \$rtl,
134
    "changes-only!"                => \$changes_only,
135
    "sort=s"                       => \$sort,
136
    "compose=s"                    => \$compose,
137
    "corrected=s"                  => \$pdf_corrected,
138
    "n-copies=s"                   => \$n_copies,
139
    "src=s"                        => \$src_file,
140
    "with=s"                       => \$latex_engine,
141
    "filter=s"                     => \$filter,
142
    "filtered-source=s"            => \$filtered_source,
143
    "embedded-max-size=s"          => \$embedded_max_size,
144
    "embedded-format=s"            => \$embedded_format,
145
    "embedded-jpeg-quality=s"      => \$embedded_jpeg_quality,
146
);
147
148
set_debug($debug);
149
150
for ( split( /,/, join( ',', @o_symbols ) ) ) {
151
    if (/^([01]-[01]):(none|circle|mark|box)(?:[\/:]([\#a-z0-9]+))?$/) {
152
        $symboles{$1} = { type => $2, color => $3 };
153
    } else {
154
        die "Bad symbol syntax: $_";
155
    }
156
}
157
158
# try to set sensible values when these directories are not set by the
159
# user:
160
161
$projects_dir = $ENV{HOME} . '/' . __("MC-Projects") if ( !$projects_dir );
162
$project_dir   = $projects_dir . '/' . $project_dir if ( $project_dir !~ /\// );
163
$pdf_subject   = "DOC-sujet.pdf"                    if ( !$pdf_subject );
164
$pdf_subject   = $project_dir . '/' . $pdf_subject  if ( $pdf_subject !~ /\// );
165
$pdf_corrected = "DOC-indiv-solution.pdf"           if ( !$pdf_corrected );
166
$pdf_corrected = $project_dir . '/' . $pdf_corrected
167
  if ( $pdf_corrected !~ /\// );
168
169
$cr_dir   = $project_dir . "/cr"         if ( !$cr_dir );
170
$data_dir = $project_dir . "/data"       if ( !$data_dir );
171
$pdf_dir  = $cr_dir . "/corrections/pdf" if ( !$pdf_dir );
172
173
# single output should be a file name, not a path
174
175
$single_output =~ s:.*/::;
176
177
# We need a destination directory!
178
179
utf8::downgrade($pdf_dir);
180
if ( !-d $pdf_dir ) {
181
    attention("No PDF directory: $pdf_dir");
182
    die "No PDF directory: $pdf_dir";
183
}
184
185
my $commandes = AMC::Exec::new('AMC-annotate');
186
$commandes->signalise();
187
188
# prepare the corrected answer sheet for all students. This file is
189
# used when option --compose is 2, to take sheets when there are no
190
# answer boxes on it. This can be very useful to produce a complete
191
# annotated answer sheet with subject *and* answers when separate
192
# answer sheet layout is used.
193
194
if ( $compose == 2 ) {
195
    if ( !-f $pdf_corrected ) {
196
197
        debug "Building individual corrected sheet...";
198
        print "Building individual corrected sheet...\n";
199
200
        $commandes->execute(
201
            "auto-multiple-choice",
202
            "prepare",
203
            pack_args(
204
                "--n-copies",          $n_copies,
205
                "--with",              $latex_engine,
206
                "--filter",            $filter,
207
                "--filtered-source",   $filtered_source,
208
                "--mode",              "k",
209
                "--out-corrige-indiv", $pdf_corrected,
210
                "--debug",             debug_file(),
211
                $src_file
212
            )
213
        );
214
    }
215
}
216
217
my $annotate = AMC::Annotate::new(
218
    data_dir                   => $data_dir,
219
    project_dir                => $project_dir,
220
    projects_dir               => $projects_dir,
221
    pdf_dir                    => $pdf_dir,
222
    single_output              => $single_output,
223
    filename_model             => $filename_model,
224
    force_ascii                => $force_ascii,
225
    pdf_subject                => $pdf_subject,
226
    names_file                 => $names_file,
227
    names_encoding             => $names_encoding,
228
    association_key            => $association_key,
229
    csv_build_name             => $csv_build_name,
230
    significant_digits         => $significant_digits,
231
    darkness_threshold         => $darkness_threshold,
232
    darkness_threshold_up      => $darkness_threshold_up,
233
    id_file                    => $id_file,
234
    sort                       => $sort,
235
    annotate_indicatives       => $annotate_indicatives,
236
    position                   => $position,
237
    text_color                 => $text_color,
238
    line_width                 => $line_width,
239
    font_name                  => $font_name,
240
    dist_to_box                => $dist_to_box,
241
    dist_margin                => $dist_margin,
242
    dist_margin_globaltext     => $dist_margin_globaltext,
243
    symbols                    => \%symboles,
244
    verdict                    => $verdict,
245
    verdict_question           => $verdict_question,
246
    verdict_question_cancelled => $verdict_question_cancelled,
247
    progress                   => $progress,
248
    progress_id                => $progress_id,
249
    compose                    => $compose,
250
    pdf_corrected              => $pdf_corrected,
251
    changes_only               => $changes_only,
252
    embedded_max_size          => $embedded_max_size,
253
    embedded_format            => $embedded_format,
254
    embedded_jpeg_quality      => $embedded_jpeg_quality,
255
    rtl                        => $rtl,
256
);
257
258
$annotate->go();
259
$annotate->quit();
260