Substitute.pm

DENIS Sébastien, 12/09/2018 03:27 pm

Download (3.7 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.9) {
76
77
      $stext = $stext . "maîtrise experte 😄";
78
79
    } elsif (@row[1]>0.5) {
80
81
      $stext = $stext . "maîtrise satisfaisante 😊";
82
83
    } elsif (@row[1]>0) {
84
85
      $stext = $stext . "maîtrise incomplète 😕";
86
87
    } else {
88
89
      $stext = $stext . "non maîtrisé 😟";
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
127
sub substitute {
128
  my ($self,$text,$student,$copy)=@_;
129
130
  if($self->{'scoring'}) {
131
    my $student_mark=$self->{'scoring'}->student_global($student,$copy);
132
133
    if($student_mark) {
134
135
      $text =~ s/\%[M]/$self->format_note($student_mark->{'max'})/ge;
136
      $text =~ s/\%[s]/$self->format_note($student_mark->{'mark'})/ge;
137
      $text =~ s/\%[m]/$self->format_note($self->{'scoring'}->variable('mark_max'))/ge;
138
      $text =~ s/\%[C]/$self->format_skills($student, $copy)/ge;
139
      $text =~ s/\%[c]/$self->format_knowledge($student, $copy)/ge;
140
    } else {
141
      debug "No marks found ! Copy=".studentids_string($student,$copy);
142
    }
143
  }
144
145
  $text =~ s/\%[n]/$self->{'name'}/ge;
146
147
  if($self->{'assoc'} && $self->{'names'}) {
148
    $self->{'lk'}=$self->{'assoc'}->variable('key_in_list')
149
      if(!$self->{'lk'});
150
151
    my $i=$self->{'assoc'}->get_real($student,$copy);
152
    my $n;
153
154
    debug "Association -> ID=$i";
155
156
    if(defined($i)) {
157
      ($n)=$self->{'names'}->data($self->{'lk'},$i,test_numeric=>1);
158
      if($n) {
159
	$text=$self->{'names'}->substitute($n,$text,'prefix'=>'%');
160
      }
161
    }
162
  }
163
164
  return($text);
165
}
166
167
1;