1 | # Copyright (C) 2012-2022 Alexis Bienvenüe <paamc@passoire.fr>
|
2 | #
|
3 | # This file is part of Auto-Multiple-Choice
|
4 | #
|
5 | # Auto-Multiple-Choice is free software: you can redistribute it
|
6 | # and/or modify it under the terms of the GNU General Public License
|
7 | # as published by the Free Software Foundation, either version 2 of
|
8 | # the License, or (at your option) any later version.
|
9 | #
|
10 | # Auto-Multiple-Choice is distributed in the hope that it will be
|
11 | # useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
12 | # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 | # General Public License for more details.
|
14 | #
|
15 | # You should have received a copy of the GNU General Public License
|
16 | # along with Auto-Multiple-Choice. If not, see
|
17 | # <http://www.gnu.org/licenses/>.
|
18 |
|
19 | use warnings;
|
20 | use 5.012;
|
21 |
|
22 | package AMC::Substitute;
|
23 |
|
24 | use AMC::Basic;
|
25 |
|
26 | use utf8; # A RAJOUTER
|
27 |
|
28 | sub new {
|
29 | my (%o) = @_;
|
30 | my $self = {
|
31 | names => '',
|
32 | scoring => '',
|
33 | assoc => '',
|
34 | name => '',
|
35 | chsign => 4,
|
36 | lk => '',
|
37 | anonymous => '',
|
38 | };
|
39 |
|
40 | for ( keys %o ) {
|
41 | $self->{$_} = $o{$_} if ( defined( $self->{$_} ) );
|
42 | }
|
43 |
|
44 | bless $self;
|
45 | return ($self);
|
46 | }
|
47 |
|
48 | sub format_note {
|
49 | my ( $self, $mark ) = @_;
|
50 |
|
51 | if ( $self->{chsign} ) {
|
52 | $mark = sprintf( "%.*g", $self->{chsign}, $mark );
|
53 | }
|
54 | return ($mark);
|
55 | }
|
56 |
|
57 | #ON COPIE DE ICI...
|
58 |
|
59 | # Affiche le niveau acquis pour chaque compétence entrée comme groupe
|
60 | # <30%: élémentaire - <70%: apprenti - <100%: confirmé - =100%: expert
|
61 | sub format_skills {
|
62 | my ($self,$student,$copy)=@_;
|
63 | my $sth = $self->{scoring}->statement('studentSkillLevel');
|
64 | $sth->execute($student, $copy);
|
65 | my $stext = "";
|
66 | while(my @row=$sth->fetchrow_array) { # retrieve one row
|
67 | if (scalar(split '',$stext) > 6) {$stext = $stext . " — ";}
|
68 | $stext = $stext . @row[0] . " : ";
|
69 | if (@row[1]>1) {
|
70 |
|
71 | $stext = $stext . "Compétence non évaluée ";
|
72 |
|
73 | } elsif (@row[1]>=0.75) {
|
74 |
|
75 | $stext = $stext . "Très bonne maîtrise 😄";
|
76 |
|
77 | } elsif (@row[1]>=0.5) {
|
78 |
|
79 | $stext = $stext . "Maîtrise satisfaisante 😊";
|
80 |
|
81 | } elsif (@row[1]>=0.25) {
|
82 |
|
83 | $stext = $stext . "Maîtrise fragile 😕";
|
84 |
|
85 | } else {
|
86 |
|
87 | $stext = $stext . "Maîtrise insuffisante 😟";
|
88 |
|
89 | }
|
90 | }
|
91 | return($stext);
|
92 | }
|
93 |
|
94 | # Affiche les pourcentages de réussite par groupe, arrondi à l'entier, le minimum étant fixé à zéro
|
95 | sub format_knowledge {
|
96 | my ($self,$student,$copy)=@_;
|
97 | my $sth = $self->{scoring}->statement('studentSkillLevel');
|
98 | $sth->execute($student, $copy);
|
99 | my $stext = "\n";
|
100 | while(my @row=$sth->fetchrow_array) { # retrieve one row
|
101 | if (scalar(split '',$stext) > 6) {$stext = $stext . " — ";}
|
102 | my $knowledge=int(@row[1]*100+.5);
|
103 | $stext = $stext . @row[0] . " : " . (0, $knowledge)[$knowledge>0] . " %";
|
104 | }
|
105 | return($stext);
|
106 | }
|
107 |
|
108 | # Affiche le niveau acquis et le pourcentage de réussite pour chaque compétence entrée comme groupe
|
109 |
|
110 | sub format_skills_knowledge {
|
111 |
|
112 | my ($self,$student,$copy)=@_;
|
113 |
|
114 | my $sth = $self->{scoring}->statement('studentSkillLevel');
|
115 |
|
116 | $sth->execute($student, $copy);
|
117 |
|
118 | my $stext = "\t\t\t\t\t\t\t\t\t";
|
119 |
|
120 | while(my @row=$sth->fetchrow_array) { # retrieve one row
|
121 |
|
122 | if (scalar(split '',$stext) > 6) {$stext = $stext . "\n";}
|
123 |
|
124 | $stext = $stext . " ";
|
125 |
|
126 | $stext = $stext . @row[0] . " : ";
|
127 |
|
128 | if (@row[1]>1) {
|
129 |
|
130 | my $knowledge=int(@row[1]*100+.5);
|
131 |
|
132 | $stext = $stext . "Compétence non évaluée ";
|
133 |
|
134 | } elsif (@row[1]>=0.75) {
|
135 |
|
136 | my $knowledge=int(@row[1]*100+.5);
|
137 |
|
138 | $stext = $stext . (0, $knowledge)[$knowledge>0] . "% - ";
|
139 |
|
140 | $stext = $stext . "Très bonne maîtrise 😄";
|
141 |
|
142 | } elsif (@row[1]>=0.5) {
|
143 |
|
144 | my $knowledge=int(@row[1]*100+.5);
|
145 |
|
146 | $stext = $stext . (0, $knowledge)[$knowledge>0] . "% - ";
|
147 |
|
148 | $stext = $stext . "Maîtrise satisfaisante 😊";
|
149 |
|
150 | } elsif (@row[1]>=0.25) {
|
151 |
|
152 | my $knowledge=int(@row[1]*100+.5);
|
153 |
|
154 | $stext = $stext . (0, $knowledge)[$knowledge>0] . "% - ";
|
155 |
|
156 | $stext = $stext . "Maîtrise fragile 😕";
|
157 |
|
158 | } else {
|
159 |
|
160 | my $knowledge=int(@row[1]*100+.5);
|
161 |
|
162 | $stext = $stext . (0, $knowledge)[$knowledge>0] . "% - ";
|
163 |
|
164 | $stext = $stext . "Maîtrise insuffisante 😟";
|
165 |
|
166 | }
|
167 |
|
168 | }
|
169 |
|
170 | return($stext);
|
171 | }
|
172 |
|
173 | #A ICI...
|
174 | #A ICI...
|
175 | #A ICI...
|
176 |
|
177 |
|
178 | sub substitute {
|
179 | my ( $self, $text, $student, $copy ) = @_;
|
180 |
|
181 | if ( $self->{scoring} ) {
|
182 | my $student_mark = $self->{scoring}->student_global( $student, $copy );
|
183 |
|
184 | if ($student_mark) {
|
185 | $text =~ s/\%[S]/$self->format_note($student_mark->{total})/ge;
|
186 | $text =~ s/\%[M]/$self->format_note($student_mark->{max})/ge;
|
187 | $text =~ s/\%[s]/$self->format_note($student_mark->{mark})/ge;
|
188 | $text =~
|
189 | s/\%[m]/$self->format_note($self->{scoring}->variable('mark_max'))/ge;
|
190 | $text =~ s/\%[C]/$self->format_skills($student, $copy)/ge;
|
191 | $text =~ s/\%[c]/$self->format_knowledge($student, $copy)/ge;
|
192 | $text =~ s/\%[Z]/$self->format_skills_knowledge($student, $copy)/ge; } else {
|
193 | debug "No marks found ! Copy="
|
194 | . studentids_string( $student, $copy );
|
195 | }
|
196 | }
|
197 |
|
198 | $text =~ s/\%[n]/$self->{name}/ge;
|
199 |
|
200 | if ( $self->{assoc} && $self->{anonymous} && $text =~ /\%\(aID\)/ ) {
|
201 | my $aid =
|
202 | $self->{assoc}->anonymized( $student, $copy, $self->{anonymous} );
|
203 | $text =~ s/\%\(aID\)/$aid/g;
|
204 | }
|
205 |
|
206 | if ( $self->{assoc} && $self->{names} ) {
|
207 | $self->{lk} = $self->{assoc}->variable('key_in_list')
|
208 | if ( !$self->{lk} );
|
209 |
|
210 | my $i = $self->{assoc}->get_real( $student, $copy );
|
211 | my $n;
|
212 |
|
213 | if ( defined($i) ) {
|
214 | debug "Association -> ID=$i";
|
215 |
|
216 | ($n) = $self->{names}->data( $self->{lk}, $i, test_numeric => 1 );
|
217 | if ($n) {
|
218 | $text = $self->{names}->substitute( $n, $text, prefix => '%' );
|
219 | }
|
220 | } else {
|
221 | debug "Not associated";
|
222 | }
|
223 | }
|
224 |
|
225 | return ($text);
|
226 | }
|
227 |
|
228 | 1;
|