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