Rev 12947 | Go to most recent revision | 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])/; |
9365 | bpr | 49 | $seconds{$date}=timelocal(0,0,0,$3,$2-1,$1); |
9389 | bpr | 50 | if (($_[2]=~ /\b($SH)\b/ || !($SH)) && ($_[4] eq 'score')) { |
9353 | bpr | 51 | $exobyday{$date} ++ ; |
9405 | bpr | 52 | $nbnew --; |
9355 | bpr | 53 | $exobydaysh{$_[2]}->{$date} ++ ; |
9358 | bpr | 54 | if ($_[5] >= $LIMIT){ |
55 | $scorebyday{$date} ++ ; |
||
56 | $goodbyday{$date} .= (($goodbyday{$date})? ',':'') . $exobyday{$date}; |
||
57 | $scorebydaysh{$_[2]}->{$date} ++; |
||
58 | $goodbydaysh{$_[2]}->{$date} .= (($goodbydaysh{$_[2]}{$date})? ',':'') . $exobydaysh{$_[2]}->{$date}; |
||
59 | } |
||
9353 | bpr | 60 | ## n'a de sens que s'il y a une seule sheet |
9389 | bpr | 61 | if ($_[2]=~ /\b$SH0\b/){ |
9405 | bpr | 62 | $exobydayex{$_[3]}->{$date} ++; |
9358 | bpr | 63 | if ($_[5] >= $LIMIT){ |
9405 | bpr | 64 | $scorebydayex{$_[3]}->{$date} ++; |
65 | $goodbydayex{$_[3]}->{$date} .= (($goodbydayex{$_[3]}{$date})? ',':'') . $exobydayex{$_[3]}->{$date}; |
||
9358 | bpr | 66 | } |
9353 | bpr | 67 | } |
68 | } |
||
69 | my ($annee, $mois, $jour)=($1,$2,$3); |
||
232 | bpr | 70 | $date=converttime($time,$date); |
17437 | guerimand | 71 | if ($_[4] =~ /new|resume/) { |
72 | $nbnew ++; |
||
73 | $lastdate{$_[2]}=$date; |
||
74 | if (($_[2]=~ /\b($SH)\b/ || !($SH))) { $newbydaysh{$_[2]}->{$date} ++ ; $newbyday{$date} ++} |
||
75 | ## n'a de sens que s'il y a une seule sheet |
||
76 | if ($_[2]=~ /\b$SH0\b/){ $newbydayex{$_[3]}->{$date} ++;} |
||
77 | if ( !$duree{$_[2]} ) {$duree{$_[2]}= 0;}; |
||
78 | next}; |
||
9353 | bpr | 79 | |
232 | bpr | 80 | if(!$lastdate{$_[2]} && $_[4] eq 'new'){#on initialise s'il n'avait jamais fait cette feuille : |
17437 | guerimand | 81 | # en fait on passe jamais ici car le cmd=new est detecté avant et il y a une sortie donc à supprimer |
7159 | bpr | 82 | $lastdate{$_[2]}=$date; |
83 | $duree{$_[2]}= 0; |
||
84 | next; |
||
232 | bpr | 85 | } else { |
17437 | guerimand | 86 | #on juge que s'il y a moins de $latency entre deux dates consecutives, le bonhomme a travaille pendant ce temps |
87 | if ($lastdate{$_[2]} && $date-$lastdate{$_[2]}<$latency){ |
||
9353 | bpr | 88 | $duree{$_[2]} += ($date-$lastdate{$_[2]}); |
17437 | guerimand | 89 | } else |
90 | { |
||
91 | $duree{$_[2]} += $latency; |
||
92 | } |
||
7159 | bpr | 93 | $lastdate{$_[2]}=$date; |
17437 | guerimand | 94 | # |
232 | bpr | 95 | } |
7159 | bpr | 96 | if ($_[4] eq 'score') {; |
97 | $score{$_[2]} ++; |
||
9358 | bpr | 98 | }; |
7159 | bpr | 99 | }; |
232 | bpr | 100 | } |
101 | |||
7159 | bpr | 102 | my ($text,$score_global,$duree_globale,$nombresessions_globale)= (' ',0,0,0); |
9353 | bpr | 103 | for my $sh (1..$SHEET) { |
7159 | bpr | 104 | $text .= $score{$sh} . ',' . converttime2($duree{$sh}) . ','; |
9358 | bpr | 105 | $score_global += $score{$sh}; if ($duree{$sh}) { $duree_globale += $duree{$sh}}; |
232 | bpr | 106 | } |
9405 | bpr | 107 | #dernière connexion,nb_sessions,nb exos abordés total, nb exos par feuille, temps par feuille,nb exos non aboutis |
9369 | bpr | 108 | exit if !($dattime); |
232 | bpr | 109 | |
9369 | bpr | 110 | print $dattime . ',' . $nbsessions . ',' . $score_global . ',' |
9405 | bpr | 111 | . converttime2($duree_globale) . ',' . $text . $nbnew; |
9369 | bpr | 112 | |
9353 | bpr | 113 | if ($OPTION eq 'exobyday'){ |
9405 | bpr | 114 | for my $date (sort keys %exobyday ) { |
9358 | bpr | 115 | if (!$exobyday{$date}) {$exobyday{$date}=0;} |
116 | if (!$scorebyday{$date}) {$scorebyday{$date}=0;} |
||
117 | if (!$goodbyday{$date}) {$goodbyday{$date}='';} |
||
9405 | bpr | 118 | if (!$newbyday{$date}) {$newbyday{$date}=0;} else {$newbyday{$date} -=$exobyday{$date}} |
119 | } |
||
9358 | bpr | 120 | |
9405 | bpr | 121 | my ($xcoord, $ycoord, $zcoord, $good, $tmp, $day, $init, $t, $wday, $new)=('','','','','','','','','','') ; |
122 | for my $date ( sort keys %exobyday ) { |
||
9365 | bpr | 123 | if ($xcoord) {$tmp=',' ;} else { |
124 | $init=$seconds{$date} ; |
||
125 | my @wday = localtime($date); $wday=$wday[6]} |
||
9405 | bpr | 126 | $xcoord .= $tmp . $date; |
9365 | bpr | 127 | $t = ($seconds{$date}-$init) % 86400; $t=$wday+($seconds{$date}-$init-$t)/ 86400; |
128 | $day .= $tmp . $t; |
||
9358 | bpr | 129 | $ycoord .= $tmp . $exobyday{$date}; |
130 | $zcoord .= $tmp . $scorebyday{$date}; |
||
9405 | bpr | 131 | $good .= $tmp . '[' . $goodbyday{$date} .']'; |
132 | $new .= $tmp . $newbyday{$date} |
||
9358 | bpr | 133 | } |
134 | ###liste de dates, liste du nombre d'exos faits à cette date, liste des nombres de reussite, |
||
135 | ###liste des listes de positions des reussites |
||
9353 | bpr | 136 | |
9405 | bpr | 137 | print "\n[$xcoord],[$day],[$ycoord],[$zcoord],[$good],[$new]"; |
9358 | bpr | 138 | |
9355 | bpr | 139 | if (!($SH0=~ /,/)) { |
9405 | bpr | 140 | for my $ex (sort {$a <=> $b} keys %exobydayex){ |
141 | my ($xcoord,$ycoord,$zcoord,$good,$tmp,$new)=('','','','','',''); |
||
9353 | bpr | 142 | for my $date ( sort keys %exobyday ) { |
9405 | bpr | 143 | if (!$exobydayex{$ex}->{$date}) { $exobydayex{$ex}->{$date}=0;} |
144 | if (!$scorebydayex{$ex}->{$date}) {$scorebydayex{$ex}->{$date} = 0;} |
||
145 | if (!$goodbydayex{$ex}->{$date}) { $goodbydayex{$ex}->{$date}='';} |
||
146 | if (!$newbydayex{$ex}->{$date}) {$newbydayex{$ex}->{$date}=0;} else { $newbydayex{$ex}->{$date} -=$exobydayex{$ex}->{$date} } |
||
9358 | bpr | 147 | if ($xcoord) {$tmp=',' }; |
9405 | bpr | 148 | $xcoord .= $tmp . $date; |
149 | $ycoord .= $tmp . $exobydayex{$ex}->{$date}; |
||
150 | $zcoord .= $tmp . $scorebydayex{$ex}->{$date}; |
||
151 | $good .= $tmp . '[' . $goodbydayex{$ex}->{$date} . ']'; |
||
152 | $new .= $tmp . $newbydayex{$ex}->{$date}; |
||
9358 | bpr | 153 | } |
154 | ###pour les exercices d'une feuille |
||
155 | ###numero exo, liste de dates, liste du nombre d'exos faits à cette date, liste des nombres de reussite, |
||
156 | ###liste des listes de positions des reussites |
||
9405 | bpr | 157 | print "\n$ex,[$xcoord],[$ycoord],[$zcoord],[$good],[$new]"; |
9353 | bpr | 158 | } |
9355 | bpr | 159 | } |
160 | else { |
||
9363 | bpr | 161 | for my $sh (sort {$a <=> $b} keys %exobydaysh){ |
9405 | bpr | 162 | my ($xcoord,$ycoord,$zcoord,$good,$tmp,$new)=('','','','','',''); |
9363 | bpr | 163 | for my $date ( sort ( keys %exobyday) ) { |
9358 | bpr | 164 | if ($xcoord) {$tmp=',' }; |
9405 | bpr | 165 | $xcoord .= $tmp . $date; |
9358 | bpr | 166 | if (!$exobydaysh{$sh}->{$date}) { $exobydaysh{$sh}->{$date}=0;} |
167 | if (!$scorebydaysh{$sh}->{$date}) {$scorebydaysh{$sh}->{$date} = 0;} |
||
168 | if (!$goodbydaysh{$sh}->{$date}) { $goodbydaysh{$sh}->{$date}='';} |
||
9405 | bpr | 169 | if (!$newbydaysh{$sh}->{$date}) { $newbydaysh{$sh}->{$date}=0;} |
170 | else { $newbydaysh{$sh}->{$date} -=$exobydaysh{$sh}->{$date} } |
||
9358 | bpr | 171 | $ycoord .= $tmp . $exobydaysh{$sh}->{$date}; |
172 | $zcoord .= $tmp . $scorebydaysh{$sh}->{$date}; |
||
173 | $good .= $tmp . '[' . $goodbydaysh{$sh}->{$date} . ']'; |
||
9405 | bpr | 174 | $new .= $tmp . $newbydaysh{$sh}->{$date}; |
9355 | bpr | 175 | } |
9358 | bpr | 176 | ###pour les feuilles d'une liste de feuilles |
177 | ###numero feuille, liste de dates, liste du nombre d'exos faits à cette date, liste des nombres de reussite, |
||
178 | ###liste des listes de positions des reussites |
||
9405 | bpr | 179 | print "\n$sh,[$xcoord],[$ycoord],[$zcoord],[$good],[$new]"; |
9355 | bpr | 180 | } |
181 | } |
||
9353 | bpr | 182 | } |
232 | bpr | 183 | sub converttime { |
184 | my $heure=shift; |
||
185 | my $date=shift; |
||
186 | $heure =~/([0-9]+):([0-9]+):([0-9]+)/; |
||
187 | $heure= 3600*$1+60*$2+$3; |
||
188 | $date =~/([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])/; |
||
189 | my $annee=$1; |
||
190 | my $mois=$2; |
||
191 | my $jour=$3; |
||
192 | return timelocal(0,0,0,$jour,$mois - 1,$annee) + $heure; |
||
193 | } |
||
194 | |||
195 | sub converttime2 { |
||
3906 | bpr | 196 | my $duree=shift; |
9358 | bpr | 197 | return "0:0:0" if !($duree); |
3906 | bpr | 198 | my $secondes = $duree% 60; |
232 | bpr | 199 | $duree = ($duree-$secondes)/ 60; |
3906 | bpr | 200 | my $minutes = $duree% 60; |
232 | bpr | 201 | $duree = ($duree-$minutes)/ 60; |
3906 | bpr | 202 | my $heures = $duree; |
232 | bpr | 203 | "$heures:$minutes:$secondes"; |
7159 | bpr | 204 | } |