Rev 17437 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
11275 | schaersvoo | 1 | #!/usr/bin/perl |
9358 | bpr | 2 | use strict; use warnings; |
232 | bpr | 3 | |
17437 | guerimand | 4 | # latency in second (calcul of worktime is min(latency,timescore-timenew) |
5 | my $latency='900'; |
||
232 | bpr | 6 | use Time::Local; |
9355 | bpr | 7 | my ($OUT, $SHEET); |
8 | my $SH='';my $OPTION=''; |
||
9358 | bpr | 9 | my $LIMIT='9'; |
7159 | bpr | 10 | push (@ARGV,split(' ', $ENV{'wims_exec_parm'})) if ($ENV{'wims_exec_parm'}); |
232 | bpr | 11 | while ($_ = shift (@ARGV)) |
12 | { |
||
13 | last if (!/^--/); |
||
14 | if (/^--file=(.*)$/) { $OUT = $1; } # fichier de sortie |
||
15 | if (/^--sheet=(.*)$/) {$SHEET = $1; } # nombre de feuilles |
||
9353 | bpr | 16 | if (/^--option=(.*):(.*)$/) {$OPTION = $1; $SH=$2} # option exobyday |
9358 | bpr | 17 | if (/^--limit=(\d+)$/) {$LIMIT=$1} # limite de notes |
7159 | bpr | 18 | }; |
232 | bpr | 19 | #fichier à lire |
9355 | bpr | 20 | #my $FILE = "/" . $_; |
9353 | bpr | 21 | my $FILE = $_; |
9355 | bpr | 22 | |
23 | my $SH0=$SH; |
||
9353 | bpr | 24 | $SH =~ s/,/|/g; |
25 | my (%lastdate, %score, %duree, $dattime); |
||
9405 | bpr | 26 | my (%exobyday,%scorebyday, %goodbyday,%newbyday)=((),(),()); |
27 | my (%exobydayex, %scorebydayex, %goodbydayex,%newbydayex)=((),(),(),()); |
||
28 | my (%exobydaysh, %scorebydaysh, %goodbydaysh,%newbydaysh)=((),(),(),()); |
||
29 | my (%seconds)=(); |
||
232 | bpr | 30 | for my $sh (1..$SHEET) { |
7159 | bpr | 31 | $lastdate{$sh}=''; |
32 | $score{$sh} = 0; |
||
232 | bpr | 33 | } |
9405 | bpr | 34 | my ($session,$nbsessions,$nbnew)=(' ',0,0); |
232 | bpr | 35 | #le fichier est récupéré ordonné par dates croissantes |
7159 | bpr | 36 | open(IN, $FILE); |
37 | while(<IN>){ |
||
232 | bpr | 38 | #extraction de l'info de la ligne |
39 | #20070914.23:52:03 6BA720BDC3 1 1 score 10 82.238.218.220 |
||
40 | #next si ligne d'examen |
||
41 | next if (/^E/); |
||
7159 | bpr | 42 | @_ = split(/ +/); |
43 | $dattime=$_[0]; |
||
9405 | bpr | 44 | if ($_[4] eq 'score' || $_[4] =~ /new|resume/ || (!$lastdate{$_[2]}) ) { |
9358 | bpr | 45 | if (!($session eq $_[1])){ $nbsessions ++; $session=$_[1]; }; |
7159 | bpr | 46 | $dattime=~/([0-9]+)\.([0-9:]+)/; |
9353 | bpr | 47 | my ($date, $time) = ($1,$2); |
232 | bpr | 48 | $date =~/([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])/; |
17741 | bpr | 49 | if ($_[4] =~ /new|resume/) { |
50 | $nbnew ++; |
||
51 | if (($_[2]=~ /\b($SH)\b/ || !($SH))) { $newbydaysh{$_[2]}->{$date} ++ ; $newbyday{$date} ++} |
||
52 | ## n'a de sens que s'il y a une seule sheet |
||
53 | if ($_[2]=~ /\b$SH0\b/){ $newbydayex{$_[3]}->{$date} ++; |
||
54 | if ( !$duree{$_[2]} ) {$duree{$_[2]}= 0;};} |
||
55 | next}; |
||
9365 | bpr | 56 | $seconds{$date}=timelocal(0,0,0,$3,$2-1,$1); |
9389 | bpr | 57 | if (($_[2]=~ /\b($SH)\b/ || !($SH)) && ($_[4] eq 'score')) { |
9353 | bpr | 58 | $exobyday{$date} ++ ; |
9405 | bpr | 59 | $nbnew --; |
9355 | bpr | 60 | $exobydaysh{$_[2]}->{$date} ++ ; |
9358 | bpr | 61 | if ($_[5] >= $LIMIT){ |
62 | $scorebyday{$date} ++ ; |
||
63 | $goodbyday{$date} .= (($goodbyday{$date})? ',':'') . $exobyday{$date}; |
||
64 | $scorebydaysh{$_[2]}->{$date} ++; |
||
65 | $goodbydaysh{$_[2]}->{$date} .= (($goodbydaysh{$_[2]}{$date})? ',':'') . $exobydaysh{$_[2]}->{$date}; |
||
66 | } |
||
9353 | bpr | 67 | ## n'a de sens que s'il y a une seule sheet |
9389 | bpr | 68 | if ($_[2]=~ /\b$SH0\b/){ |
9405 | bpr | 69 | $exobydayex{$_[3]}->{$date} ++; |
9358 | bpr | 70 | if ($_[5] >= $LIMIT){ |
9405 | bpr | 71 | $scorebydayex{$_[3]}->{$date} ++; |
72 | $goodbydayex{$_[3]}->{$date} .= (($goodbydayex{$_[3]}{$date})? ',':'') . $exobydayex{$_[3]}->{$date}; |
||
9358 | bpr | 73 | } |
9353 | bpr | 74 | } |
75 | } |
||
76 | my ($annee, $mois, $jour)=($1,$2,$3); |
||
232 | bpr | 77 | $date=converttime($time,$date); |
9353 | bpr | 78 | |
232 | bpr | 79 | if(!$lastdate{$_[2]} && $_[4] eq 'new'){#on initialise s'il n'avait jamais fait cette feuille : |
17741 | bpr | 80 | # ??? en fait on passe jamais ici car le cmd=new est detecté avant et il y a une sortie donc à supprimer |
7159 | bpr | 81 | $lastdate{$_[2]}=$date; |
82 | $duree{$_[2]}= 0; |
||
83 | next; |
||
232 | bpr | 84 | } else { |
17437 | guerimand | 85 | #on juge que s'il y a moins de $latency entre deux dates consecutives, le bonhomme a travaille pendant ce temps |
86 | if ($lastdate{$_[2]} && $date-$lastdate{$_[2]}<$latency){ |
||
9353 | bpr | 87 | $duree{$_[2]} += ($date-$lastdate{$_[2]}); |
17741 | bpr | 88 | } else |
17437 | guerimand | 89 | { |
90 | $duree{$_[2]} += $latency; |
||
91 | } |
||
17741 | bpr | 92 | $lastdate{$_[2]}=$date; |
93 | # |
||
94 | } |
||
7159 | bpr | 95 | if ($_[4] eq 'score') {; |
96 | $score{$_[2]} ++; |
||
9358 | bpr | 97 | }; |
17741 | bpr | 98 | }; |
232 | bpr | 99 | } |
100 | |||
7159 | bpr | 101 | my ($text,$score_global,$duree_globale,$nombresessions_globale)= (' ',0,0,0); |
9353 | bpr | 102 | for my $sh (1..$SHEET) { |
7159 | bpr | 103 | $text .= $score{$sh} . ',' . converttime2($duree{$sh}) . ','; |
9358 | bpr | 104 | $score_global += $score{$sh}; if ($duree{$sh}) { $duree_globale += $duree{$sh}}; |
232 | bpr | 105 | } |
9405 | bpr | 106 | #dernière connexion,nb_sessions,nb exos abordés total, nb exos par feuille, temps par feuille,nb exos non aboutis |
9369 | bpr | 107 | exit if !($dattime); |
232 | bpr | 108 | |
9369 | bpr | 109 | print $dattime . ',' . $nbsessions . ',' . $score_global . ',' |
9405 | bpr | 110 | . converttime2($duree_globale) . ',' . $text . $nbnew; |
9369 | bpr | 111 | |
9353 | bpr | 112 | if ($OPTION eq 'exobyday'){ |
9405 | bpr | 113 | for my $date (sort keys %exobyday ) { |
9358 | bpr | 114 | if (!$exobyday{$date}) {$exobyday{$date}=0;} |
115 | if (!$scorebyday{$date}) {$scorebyday{$date}=0;} |
||
116 | if (!$goodbyday{$date}) {$goodbyday{$date}='';} |
||
9405 | bpr | 117 | if (!$newbyday{$date}) {$newbyday{$date}=0;} else {$newbyday{$date} -=$exobyday{$date}} |
118 | } |
||
9358 | bpr | 119 | |
9405 | bpr | 120 | my ($xcoord, $ycoord, $zcoord, $good, $tmp, $day, $init, $t, $wday, $new)=('','','','','','','','','','') ; |
121 | for my $date ( sort keys %exobyday ) { |
||
9365 | bpr | 122 | if ($xcoord) {$tmp=',' ;} else { |
123 | $init=$seconds{$date} ; |
||
124 | my @wday = localtime($date); $wday=$wday[6]} |
||
9405 | bpr | 125 | $xcoord .= $tmp . $date; |
9365 | bpr | 126 | $t = ($seconds{$date}-$init) % 86400; $t=$wday+($seconds{$date}-$init-$t)/ 86400; |
127 | $day .= $tmp . $t; |
||
9358 | bpr | 128 | $ycoord .= $tmp . $exobyday{$date}; |
129 | $zcoord .= $tmp . $scorebyday{$date}; |
||
9405 | bpr | 130 | $good .= $tmp . '[' . $goodbyday{$date} .']'; |
131 | $new .= $tmp . $newbyday{$date} |
||
9358 | bpr | 132 | } |
133 | ###liste de dates, liste du nombre d'exos faits à cette date, liste des nombres de reussite, |
||
134 | ###liste des listes de positions des reussites |
||
9353 | bpr | 135 | |
9405 | bpr | 136 | print "\n[$xcoord],[$day],[$ycoord],[$zcoord],[$good],[$new]"; |
9358 | bpr | 137 | |
9355 | bpr | 138 | if (!($SH0=~ /,/)) { |
9405 | bpr | 139 | for my $ex (sort {$a <=> $b} keys %exobydayex){ |
140 | my ($xcoord,$ycoord,$zcoord,$good,$tmp,$new)=('','','','','',''); |
||
9353 | bpr | 141 | for my $date ( sort keys %exobyday ) { |
9405 | bpr | 142 | if (!$exobydayex{$ex}->{$date}) { $exobydayex{$ex}->{$date}=0;} |
143 | if (!$scorebydayex{$ex}->{$date}) {$scorebydayex{$ex}->{$date} = 0;} |
||
144 | if (!$goodbydayex{$ex}->{$date}) { $goodbydayex{$ex}->{$date}='';} |
||
145 | if (!$newbydayex{$ex}->{$date}) {$newbydayex{$ex}->{$date}=0;} else { $newbydayex{$ex}->{$date} -=$exobydayex{$ex}->{$date} } |
||
9358 | bpr | 146 | if ($xcoord) {$tmp=',' }; |
9405 | bpr | 147 | $xcoord .= $tmp . $date; |
148 | $ycoord .= $tmp . $exobydayex{$ex}->{$date}; |
||
149 | $zcoord .= $tmp . $scorebydayex{$ex}->{$date}; |
||
150 | $good .= $tmp . '[' . $goodbydayex{$ex}->{$date} . ']'; |
||
151 | $new .= $tmp . $newbydayex{$ex}->{$date}; |
||
9358 | bpr | 152 | } |
153 | ###pour les exercices d'une feuille |
||
154 | ###numero exo, liste de dates, liste du nombre d'exos faits à cette date, liste des nombres de reussite, |
||
155 | ###liste des listes de positions des reussites |
||
9405 | bpr | 156 | print "\n$ex,[$xcoord],[$ycoord],[$zcoord],[$good],[$new]"; |
9353 | bpr | 157 | } |
9355 | bpr | 158 | } |
159 | else { |
||
9363 | bpr | 160 | for my $sh (sort {$a <=> $b} keys %exobydaysh){ |
9405 | bpr | 161 | my ($xcoord,$ycoord,$zcoord,$good,$tmp,$new)=('','','','','',''); |
9363 | bpr | 162 | for my $date ( sort ( keys %exobyday) ) { |
9358 | bpr | 163 | if ($xcoord) {$tmp=',' }; |
9405 | bpr | 164 | $xcoord .= $tmp . $date; |
9358 | bpr | 165 | if (!$exobydaysh{$sh}->{$date}) { $exobydaysh{$sh}->{$date}=0;} |
166 | if (!$scorebydaysh{$sh}->{$date}) {$scorebydaysh{$sh}->{$date} = 0;} |
||
167 | if (!$goodbydaysh{$sh}->{$date}) { $goodbydaysh{$sh}->{$date}='';} |
||
9405 | bpr | 168 | if (!$newbydaysh{$sh}->{$date}) { $newbydaysh{$sh}->{$date}=0;} |
169 | else { $newbydaysh{$sh}->{$date} -=$exobydaysh{$sh}->{$date} } |
||
9358 | bpr | 170 | $ycoord .= $tmp . $exobydaysh{$sh}->{$date}; |
171 | $zcoord .= $tmp . $scorebydaysh{$sh}->{$date}; |
||
172 | $good .= $tmp . '[' . $goodbydaysh{$sh}->{$date} . ']'; |
||
9405 | bpr | 173 | $new .= $tmp . $newbydaysh{$sh}->{$date}; |
9355 | bpr | 174 | } |
9358 | bpr | 175 | ###pour les feuilles d'une liste de feuilles |
176 | ###numero feuille, liste de dates, liste du nombre d'exos faits à cette date, liste des nombres de reussite, |
||
177 | ###liste des listes de positions des reussites |
||
9405 | bpr | 178 | print "\n$sh,[$xcoord],[$ycoord],[$zcoord],[$good],[$new]"; |
9355 | bpr | 179 | } |
180 | } |
||
9353 | bpr | 181 | } |
232 | bpr | 182 | sub converttime { |
183 | my $heure=shift; |
||
184 | my $date=shift; |
||
185 | $heure =~/([0-9]+):([0-9]+):([0-9]+)/; |
||
186 | $heure= 3600*$1+60*$2+$3; |
||
187 | $date =~/([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])/; |
||
188 | my $annee=$1; |
||
189 | my $mois=$2; |
||
190 | my $jour=$3; |
||
191 | return timelocal(0,0,0,$jour,$mois - 1,$annee) + $heure; |
||
192 | } |
||
193 | |||
194 | sub converttime2 { |
||
3906 | bpr | 195 | my $duree=shift; |
9358 | bpr | 196 | return "0:0:0" if !($duree); |
3906 | bpr | 197 | my $secondes = $duree% 60; |
232 | bpr | 198 | $duree = ($duree-$secondes)/ 60; |
3906 | bpr | 199 | my $minutes = $duree% 60; |
232 | bpr | 200 | $duree = ($duree-$minutes)/ 60; |
3906 | bpr | 201 | my $heures = $duree; |
232 | bpr | 202 | "$heures:$minutes:$secondes"; |
7159 | bpr | 203 | } |