AMC-annotate.pl

Frédéric Bréal, 12/17/2021 05:40 pm

Download (9.1 kB)

 
1
#! /usr/bin/env perl
2
#
3
# Copyright (C) 2013-2021 Alexis Bienvenüe <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 5.012;
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 $progress    = 1;
50
my $progress_id = '';
51
52
my $text_color             = 'red';
53
my $line_width             = 2;
54
my $font_name              = 'Linux Libertine O 12';
55
my @o_symbols              = ();
56
my $annotate_indicatives   = '';
57
my $position               = 'marges';
58
my $dist_to_box            = '1cm';
59
my $dist_margin            = '5mm';
60
my $dist_margin_globaltext = '3mm';
61
62
my $significant_digits = 4;
63
64
my $verdict                    = 'TOTAL : %S/%M => %s/%m';
65
my $verdict_question_cancelled = '"X"';
66
my $verdict_question           = "\"%" . "s/%" . "m\"";
67
68
my $rtl = '';
69
70
my $names_file      = '';
71
my $names_encoding  = 'utf-8';
72
my $association_key = '';
73
my $csv_build_name  = '';
74
my $anonymous       = '';
75
my $header_only     = '';
76
77
my $embedded_max_size     = "";
78
my $embedded_jpeg_quality = 80;
79
my $embedded_format       = "jpeg";
80
81
my $changes_only = '';
82
83
my $compose         = 0;
84
my $latex_engine    = 'pdflatex';
85
my $src_file        = '';
86
my $filter          = '';
87
my $filtered_source = '';
88
my $n_copies        = 0;
89
90
# key is "to be ticked"-"ticked"
91
my %symboles = (
92
    '0-0' => {qw/type none/},
93
    '0-1' => {qw/type circle color red/},
94
    '1-0' => {qw/type mark color red/},
95
    '1-1' => {qw/type mark color blue/},
96
);
97
98
unpack_args();
99
100
GetOptions(
101
    "cr=s" => \$cr_dir,
102
    "project=s",      \$project_dir,
103
    "projects-dir=s", \$projects_dir,
104
    "data=s"                       => \$data_dir,
105
    "subject=s"                    => \$pdf_subject,
106
    "pdf-dir=s"                    => \$pdf_dir,
107
    "darkness-threshold=s"         => \$darkness_threshold,
108
    "darkness-threshold-up=s"      => \$darkness_threshold_up,
109
    "filename-model=s"             => \$filename_model,
110
    "force-ascii!"                 => \$force_ascii,
111
    "single-output=s"              => \$single_output,
112
    "sort=s"                       => \$sort,
113
    "id-file=s"                    => \$id_file,
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
    "anonymous=s"                  => \$anonymous,
134
    "header-only!"                 => \$header_only,
135
    "rtl!"                         => \$rtl,
136
    "changes-only!"                => \$changes_only,
137
    "sort=s"                       => \$sort,
138
    "compose=s"                    => \$compose,
139
    "corrected=s"                  => \$pdf_corrected,
140
    "n-copies=s"                   => \$n_copies,
141
    "src=s"                        => \$src_file,
142
    "with=s"                       => \$latex_engine,
143
    "filter=s"                     => \$filter,
144
    "filtered-source=s"            => \$filtered_source,
145
    "embedded-max-size=s"          => \$embedded_max_size,
146
    "embedded-format=s"            => \$embedded_format,
147
    "embedded-jpeg-quality=s"      => \$embedded_jpeg_quality,
148
);
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
if ( !-d $pdf_dir ) {
180
    attention("No PDF directory: $pdf_dir");
181
    die "No PDF directory: $pdf_dir";
182
}
183
184
my $commandes = AMC::Exec::new('AMC-annotate');
185
$commandes->signalise();
186
187
# prepare the corrected answer sheet for all students. This file is
188
# used when option --compose is 2, to take sheets when there are no
189
# answer boxes on it. This can be very useful to produce a complete
190
# annotated answer sheet with subject *and* answers when separate
191
# answer sheet layout is used.
192
193
if ( $compose == 2 ) {
194
    if ( !-f $pdf_corrected ) {
195
196
        debug "Building individual corrected sheet...";
197
        print "Building individual corrected sheet...\n";
198
199
        $commandes->execute(
200
            "auto-multiple-choice",
201
            "prepare",
202
            pack_args(
203
                "--n-copies",          $n_copies,
204
                "--with",              $latex_engine,
205
                "--filter",            $filter,
206
                "--filtered-source",   $filtered_source,
207
                "--mode",              "k",
208
                "--out-corrige-indiv", $pdf_corrected,
209
                "--debug",             debug_file(),
210
                $src_file
211
            )
212
        );
213
    }
214
}
215
216
my $annotate = AMC::Annotate::new(
217
    data_dir                   => $data_dir,
218
    project_dir                => $project_dir,
219
    projects_dir               => $projects_dir,
220
    pdf_dir                    => $pdf_dir,
221
    single_output              => $single_output,
222
    filename_model             => $filename_model,
223
    force_ascii                => $force_ascii,
224
    pdf_subject                => $pdf_subject,
225
    names_file                 => $names_file,
226
    names_encoding             => $names_encoding,
227
    association_key            => $association_key,
228
    csv_build_name             => $csv_build_name,
229
    anonymous                  => $anonymous,
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
    header_only                => $header_only,
237
    position                   => $position,
238
    text_color                 => $text_color,
239
    line_width                 => $line_width,
240
    font_name                  => $font_name,
241
    dist_to_box                => $dist_to_box,
242
    dist_margin                => $dist_margin,
243
    dist_margin_globaltext     => $dist_margin_globaltext,
244
    symbols                    => \%symboles,
245
    verdict                    => $verdict,
246
    verdict_question           => $verdict_question,
247
    verdict_question_cancelled => $verdict_question_cancelled,
248
    progress                   => $progress,
249
    progress_id                => $progress_id,
250
    compose                    => $compose,
251
    pdf_corrected              => $pdf_corrected,
252
    changes_only               => $changes_only,
253
    embedded_max_size          => $embedded_max_size,
254
    embedded_format            => $embedded_format,
255
    embedded_jpeg_quality      => $embedded_jpeg_quality,
256
    rtl                        => $rtl,
257
);
258
259
$annotate->go();
260
$annotate->quit();
261