Substitute.pm

DENIS Sébastien, 12/22/2022 04:41 pm

Download (5.8 kB)

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