1 | #! /usr/bin/perl
|
2 | #
|
3 | # Copyright (C) 2012-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 | package AMC::Substitute;
|
25 |
|
26 | use AMC::Basic;
|
27 |
|
28 | # A RAJOUTER 1 sur 3
|
29 | use utf8;
|
30 | # FIN A RAJOUTER 1 sur 3
|
31 |
|
32 | sub new {
|
33 | my (%o) = @_;
|
34 | my $self = {
|
35 | names => '',
|
36 | scoring => '',
|
37 | assoc => '',
|
38 | name => '',
|
39 | chsign => 4,
|
40 | lk => '',
|
41 | };
|
42 |
|
43 | for ( keys %o ) {
|
44 | $self->{$_} = $o{$_} if ( defined( $self->{$_} ) );
|
45 | }
|
46 |
|
47 | bless $self;
|
48 | return ($self);
|
49 | }
|
50 |
|
51 | sub format_note {
|
52 | my ( $self, $mark ) = @_;
|
53 |
|
54 | if ( $self->{chsign} ) {
|
55 | $mark = sprintf( "%.*g", $self->{chsign}, $mark );
|
56 | }
|
57 | return ($mark);
|
58 | }
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | #
|
64 | ## A RAJOUTER 2 sur 3
|
65 | #
|
66 |
|
67 | # Affiche le niveau acquis pour chaque compétence entrée comme groupe
|
68 | # <30%: élémentaire - <70%: apprenti - <100%: confirmé - =100%: expert
|
69 | sub format_skills {
|
70 | my ($self,$student,$copy)=@_;
|
71 | my $sth = $self->{scoring}->statement('studentSkillLevel');
|
72 | $sth->execute($student, $copy);
|
73 | my $stext = "";
|
74 | while(my @row=$sth->fetchrow_array) { # retrieve one row
|
75 | if (scalar(split '',$stext) > 6) {$stext = $stext . " — ";}
|
76 | $stext = $stext . @row[0] . " : ";
|
77 | if (@row[1]>1) {
|
78 |
|
79 | $stext = $stext . "Compétence non évaluée ";
|
80 |
|
81 | } elsif (@row[1]>=0.75) {
|
82 |
|
83 | $stext = $stext . "Très bonne maîtrise 😄";
|
84 |
|
85 | } elsif (@row[1]>=0.5) {
|
86 |
|
87 | $stext = $stext . "Maîtrise satisfaisante 😊";
|
88 |
|
89 | } elsif (@row[1]>=0.25) {
|
90 |
|
91 | $stext = $stext . "Maîtrise fragile 😕";
|
92 |
|
93 | } else {
|
94 |
|
95 | $stext = $stext . "Maîtrise insuffisante 😟";
|
96 |
|
97 | }
|
98 | }
|
99 | return($stext);
|
100 | }
|
101 |
|
102 | # Affiche les pourcentages de réussite par groupe, arrondi à l'entier, le minimum étant fixé à zéro
|
103 | sub format_knowledge {
|
104 | my ($self,$student,$copy)=@_;
|
105 | my $sth = $self->{scoring}->statement('studentSkillLevel');
|
106 | $sth->execute($student, $copy);
|
107 | my $stext = "\n";
|
108 | while(my @row=$sth->fetchrow_array) { # retrieve one row
|
109 | if (scalar(split '',$stext) > 6) {$stext = $stext . " — ";}
|
110 | my $knowledge=int(@row[1]*100+.5);
|
111 | $stext = $stext . @row[0] . " : " . (0, $knowledge)[$knowledge>0] . " %";
|
112 | }
|
113 | return($stext);
|
114 | }
|
115 |
|
116 | # Affiche le niveau acquis et le pourcentage de réussite pour chaque compétence entrée comme groupe
|
117 |
|
118 | sub format_skills_knowledge {
|
119 |
|
120 | my ($self,$student,$copy)=@_;
|
121 |
|
122 | my $sth = $self->{scoring}->statement('studentSkillLevel');
|
123 |
|
124 | $sth->execute($student, $copy);
|
125 |
|
126 | my $stext = "\t\t\t\t\t\t\t\t\t";
|
127 |
|
128 | while(my @row=$sth->fetchrow_array) { # retrieve one row
|
129 |
|
130 | if (scalar(split '',$stext) > 6) {$stext = $stext . "\n";}
|
131 |
|
132 | $stext = $stext . " ";
|
133 |
|
134 | $stext = $stext . @row[0] . " : ";
|
135 |
|
136 | if (@row[1]>1) {
|
137 |
|
138 | my $knowledge=int(@row[1]*100+.5);
|
139 |
|
140 | $stext = $stext . "Compétence non évaluée ";
|
141 |
|
142 | } elsif (@row[1]>=0.75) {
|
143 |
|
144 | my $knowledge=int(@row[1]*100+.5);
|
145 |
|
146 | $stext = $stext . (0, $knowledge)[$knowledge>0] . "% - ";
|
147 |
|
148 | $stext = $stext . "Très bonne maîtrise 😄";
|
149 |
|
150 | } elsif (@row[1]>=0.5) {
|
151 |
|
152 | my $knowledge=int(@row[1]*100+.5);
|
153 |
|
154 | $stext = $stext . (0, $knowledge)[$knowledge>0] . "% - ";
|
155 |
|
156 | $stext = $stext . "Maîtrise satisfaisante 😊";
|
157 |
|
158 | } elsif (@row[1]>=0.25) {
|
159 |
|
160 | my $knowledge=int(@row[1]*100+.5);
|
161 |
|
162 | $stext = $stext . (0, $knowledge)[$knowledge>0] . "% - ";
|
163 |
|
164 | $stext = $stext . "Maîtrise fragile 😕";
|
165 |
|
166 | } else {
|
167 |
|
168 | my $knowledge=int(@row[1]*100+.5);
|
169 |
|
170 | $stext = $stext . (0, $knowledge)[$knowledge>0] . "% - ";
|
171 |
|
172 | $stext = $stext . "Maîtrise insuffisante 😟";
|
173 |
|
174 | }
|
175 |
|
176 | }
|
177 |
|
178 | return($stext);
|
179 | }
|
180 | #
|
181 | ## FIN A RAJOUTER 2 sur 3
|
182 | #
|
183 |
|
184 |
|
185 |
|
186 | sub substitute {
|
187 | my ( $self, $text, $student, $copy ) = @_;
|
188 |
|
189 | if ( $self->{scoring} ) {
|
190 | my $student_mark = $self->{scoring}->student_global( $student, $copy );
|
191 |
|
192 | if ($student_mark) {
|
193 | $text =~ s/\%[S]/$self->format_note($student_mark->{total})/ge;
|
194 | $text =~ s/\%[M]/$self->format_note($student_mark->{max})/ge;
|
195 | $text =~ s/\%[s]/$self->format_note($student_mark->{mark})/ge;
|
196 | $text =~
|
197 | s/\%[m]/$self->format_note($self->{scoring}->variable('mark_max'))/ge;
|
198 | # A RAJOUTER 3 sur 3
|
199 | $text =~ s/\%[C]/$self->format_skills($student, $copy)/ge;
|
200 | $text =~ s/\%[c]/$self->format_knowledge($student, $copy)/ge;
|
201 | $text =~ s/\%[Z]/$self->format_skills_knowledge($student, $copy)/ge;
|
202 | # FIN A RAJOUTER 3 sur 3
|
203 | } else {
|
204 | debug "No marks found ! Copy="
|
205 | . studentids_string( $student, $copy );
|
206 | }
|
207 | }
|
208 |
|
209 | $text =~ s/\%[n]/$self->{name}/ge;
|
210 |
|
211 | if ( $self->{assoc} && $self->{names} ) {
|
212 | $self->{lk} = $self->{assoc}->variable('key_in_list')
|
213 | if ( !$self->{lk} );
|
214 |
|
215 | my $i = $self->{assoc}->get_real( $student, $copy );
|
216 | my $n;
|
217 |
|
218 | if ( defined($i) ) {
|
219 | debug "Association -> ID=$i";
|
220 |
|
221 | ($n) = $self->{names}->data( $self->{lk}, $i, test_numeric => 1 );
|
222 | if ($n) {
|
223 | $text = $self->{names}->substitute( $n, $text, prefix => '%' );
|
224 | }
|
225 | } else {
|
226 | debug "Not associated";
|
227 | }
|
228 | }
|
229 |
|
230 | return ($text);
|
231 | }
|
232 |
|
233 | 1;
|