Substitute.pm

DENIS Sébastien, 12/08/2019 07:35 pm

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