Substitute.pm

DENIS Sébastien, 01/08/2020 10:28 pm

Download (5.3 kB)

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