1 | #! /usr/bin/perl
|
2 | #
|
3 | # Copyright (C) 2012-2016 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 | use utf8;
|
26 |
|
27 | sub new {
|
28 | my (%o)=@_;
|
29 | my $self={'names'=>'',
|
30 | 'scoring'=>'',
|
31 | 'assoc'=>'',
|
32 | 'name'=>'','chsign'=>4,
|
33 | 'lk'=>'',
|
34 | };
|
35 |
|
36 | for (keys %o) {
|
37 | $self->{$_}=$o{$_} if(defined($self->{$_}));
|
38 | }
|
39 |
|
40 | bless $self;
|
41 | return($self);
|
42 | }
|
43 |
|
44 | sub format_note {
|
45 | my ($self,$mark)=@_;
|
46 |
|
47 | if($self->{'chsign'}) {
|
48 | $mark=sprintf("%.*g",$self->{'chsign'},$mark);
|
49 | }
|
50 | return($mark);
|
51 | }
|
52 |
|
53 | # Affiche le niveau acquis pour chaque compétence entrée comme groupe
|
54 | # <30%: non maîtrisé - <70%: maîtrise incomplète - <100%: maîtrise satisfaisante - =100%: maîtrise experte
|
55 | sub format_skills {
|
56 | my ($self,$student,$copy)=@_;
|
57 | my $sth = $self->{scoring}->statement('studentSkillLevel');
|
58 | $sth->execute($student, $copy);
|
59 | my $stext = "\t\t\t\t\t\t\t\t\t";
|
60 | while(my @row=$sth->fetchrow_array) { # retrieve one row
|
61 | if (scalar(split '',$stext) > 6) {$stext = $stext . "\n\t";}
|
62 | $stext = $stext . @row[0] . " : ";
|
63 | if (@row[1]>0.9) {
|
64 | $stext = $stext . "maîtrise experte 😄";
|
65 | } elsif (@row[1]>0.5) {
|
66 | $stext = $stext . "maîtrise satisfaisante 😊";
|
67 | } elsif (@row[1]>0) {
|
68 | $stext = $stext . "maîtrise incomplète 😕";
|
69 | } else {
|
70 | $stext = $stext . "non maîtrisé 😟";
|
71 | }
|
72 | }
|
73 | return($stext);
|
74 | }
|
75 |
|
76 | # Affiche les pourcentages de réussite par groupe, arrondi à l'entier, le minimum étant fixé à zéro
|
77 | sub format_knowledge {
|
78 | my ($self,$student,$copy)=@_;
|
79 | my $sth = $self->{scoring}->statement('studentSkillLevel');
|
80 | $sth->execute($student, $copy);
|
81 | my $stext = "\n";
|
82 | while(my @row=$sth->fetchrow_array) { # retrieve one row
|
83 | if (scalar(split '',$stext) > 6) {$stext = $stext . " — ";}
|
84 | my $knowledge=int(@row[1]*100+.5);
|
85 | $stext = $stext . @row[0] . " : " . (0, $knowledge)[$knowledge>0] . " %";
|
86 | }
|
87 | return($stext);
|
88 | }
|
89 |
|
90 | sub substitute {
|
91 | my ($self,$text,$student,$copy)=@_;
|
92 |
|
93 | if($self->{'scoring'}) {
|
94 | my $student_mark=$self->{'scoring'}->student_global($student,$copy);
|
95 |
|
96 | if($student_mark) {
|
97 | $text =~ s/\%[M]/$self->format_note($student_mark->{'max'})/ge;
|
98 | $text =~ s/\%[s]/$self->format_note($student_mark->{'mark'})/ge;
|
99 | $text =~ s/\%[m]/$self->format_note($self->{'scoring'}->variable('mark_max'))/ge;
|
100 | $text =~ s/\%[C]/$self->format_skills($student, $copy)/ge;
|
101 | $text =~ s/\%[c]/$self->format_knowledge($student, $copy)/ge;
|
102 | } else {
|
103 | debug "No marks found ! Copy=".studentids_string($student,$copy);
|
104 | }
|
105 | }
|
106 |
|
107 | $text =~ s/\%[n]/$self->{'name'}/ge;
|
108 |
|
109 | if($self->{'assoc'} && $self->{'names'}) {
|
110 | $self->{'lk'}=$self->{'assoc'}->variable('key_in_list')
|
111 | if(!$self->{'lk'});
|
112 |
|
113 | my $i=$self->{'assoc'}->get_real($student,$copy);
|
114 | my $n;
|
115 |
|
116 | debug "Association -> ID=$i";
|
117 |
|
118 | if(defined($i)) {
|
119 | ($n)=$self->{'names'}->data($self->{'lk'},$i,test_numeric=>1);
|
120 | if($n) {
|
121 | $text=$self->{'names'}->substitute($n,$text,'prefix'=>'%');
|
122 | }
|
123 | }
|
124 | }
|
125 |
|
126 | return($text);
|
127 | }
|
128 |
|
129 | 1;
|