Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
232 | bpr | 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); |
||
9358 | bpr | 24 | my (%exobyday,%scorebyday, %goodbyday)=((),(),()); |
25 | my (%exobyday1, %scorebyday1, %goodbyday1)=((),(),()); |
||
26 | my (%exobydaysh, %scorebydaysh, %goodbydaysh)=((),(),()); |
||
9365 | bpr | 27 | my %seconds=(); |
232 | bpr | 28 | for my $sh (1..$SHEET) { |
7159 | bpr | 29 | $lastdate{$sh}=''; |
30 | $score{$sh} = 0; |
||
232 | bpr | 31 | } |
9358 | bpr | 32 | my ($session,$nbsessions)=(' ',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]; |
||
232 | bpr | 42 | if ($_[4] eq 'score' || (!$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])/; |
9365 | bpr | 47 | $seconds{$date}=timelocal(0,0,0,$3,$2-1,$1); |
9353 | bpr | 48 | if (($_[2]=~ /$SH/ || !($SH)) && ($_[4] eq 'score')) { |
49 | $exobyday{$date} ++ ; |
||
9355 | bpr | 50 | $exobydaysh{$_[2]}->{$date} ++ ; |
9358 | bpr | 51 | if ($_[5] >= $LIMIT){ |
52 | $scorebyday{$date} ++ ; |
||
53 | $goodbyday{$date} .= (($goodbyday{$date})? ',':'') . $exobyday{$date}; |
||
54 | $scorebydaysh{$_[2]}->{$date} ++; |
||
55 | $goodbydaysh{$_[2]}->{$date} .= (($goodbydaysh{$_[2]}{$date})? ',':'') . $exobydaysh{$_[2]}->{$date}; |
||
56 | } |
||
9353 | bpr | 57 | ## n'a de sens que s'il y a une seule sheet |
9355 | bpr | 58 | if ($_[2]=~ /$SH0/){ |
59 | $exobyday1{$_[3]}->{$date} ++; |
||
9358 | bpr | 60 | if ($_[5] >= $LIMIT){ |
61 | $scorebyday1{$_[3]}->{$date} ++; |
||
62 | $goodbyday1{$_[3]}->{$date} .= (($goodbyday1{$_[3]}{$date})? ',':'') . $exobyday1{$_[3]}->{$date}; |
||
63 | } |
||
9353 | bpr | 64 | } |
65 | } |
||
66 | my ($annee, $mois, $jour)=($1,$2,$3); |
||
232 | bpr | 67 | $date=converttime($time,$date); |
9353 | bpr | 68 | |
232 | bpr | 69 | if(!$lastdate{$_[2]} && $_[4] eq 'new'){#on initialise s'il n'avait jamais fait cette feuille : |
7159 | bpr | 70 | $lastdate{$_[2]}=$date; |
71 | $duree{$_[2]}= 0; |
||
72 | next; |
||
232 | bpr | 73 | } else { |
74 | #on juge que s'il y a moins de 15mn entre deux dates consecutives, le bonhomme a travaille pendant ce temps |
||
9358 | bpr | 75 | if ($lastdate{$_[2]} && $date-$lastdate{$_[2]}<900){ |
9353 | bpr | 76 | $duree{$_[2]} += ($date-$lastdate{$_[2]}); |
7159 | bpr | 77 | } else { } |
78 | $lastdate{$_[2]}=$date; |
||
232 | bpr | 79 | } |
7159 | bpr | 80 | if ($_[4] eq 'score') {; |
81 | $score{$_[2]} ++; |
||
9358 | bpr | 82 | }; |
7159 | bpr | 83 | }; |
232 | bpr | 84 | } |
85 | |||
7159 | bpr | 86 | my ($text,$score_global,$duree_globale,$nombresessions_globale)= (' ',0,0,0); |
9353 | bpr | 87 | for my $sh (1..$SHEET) { |
7159 | bpr | 88 | $text .= $score{$sh} . ',' . converttime2($duree{$sh}) . ','; |
9358 | bpr | 89 | $score_global += $score{$sh}; if ($duree{$sh}) { $duree_globale += $duree{$sh}}; |
232 | bpr | 90 | } |
91 | #dernière connexion,nb_sessions,nb exos abordés total, nb exos par feuille, temps par feuille |
||
9369 | bpr | 92 | exit if !($dattime); |
232 | bpr | 93 | |
9369 | bpr | 94 | print $dattime . ',' . $nbsessions . ',' . $score_global . ',' |
95 | . converttime2($duree_globale) . ',' . $text; |
||
96 | |||
9353 | bpr | 97 | if ($OPTION eq 'exobyday'){ |
9358 | bpr | 98 | for my $date (sort keys %exobyday ) { |
99 | if (!$exobyday{$date}) {$exobyday{$date}=0;} |
||
100 | if (!$scorebyday{$date}) {$scorebyday{$date}=0;} |
||
101 | if (!$goodbyday{$date}) {$goodbyday{$date}='';} |
||
102 | } |
||
103 | |||
9365 | bpr | 104 | my ($xcoord, $ycoord, $zcoord, $good, $tmp, $day, $init, $t, $wday)=('','','','','','','','') ; |
9353 | bpr | 105 | for my $date ( sort keys %exobyday ) { |
9365 | bpr | 106 | if ($xcoord) {$tmp=',' ;} else { |
107 | $init=$seconds{$date} ; |
||
108 | my @wday = localtime($date); $wday=$wday[6]} |
||
9353 | bpr | 109 | $xcoord .= "$tmp$date"; |
9365 | bpr | 110 | $t = ($seconds{$date}-$init) % 86400; $t=$wday+($seconds{$date}-$init-$t)/ 86400; |
111 | $day .= $tmp . $t; |
||
9358 | bpr | 112 | $ycoord .= $tmp . $exobyday{$date}; |
113 | $zcoord .= $tmp . $scorebyday{$date}; |
||
114 | $good .= "$tmp" . '[' . $goodbyday{$date} .']'; |
||
115 | } |
||
116 | ###liste de dates, liste du nombre d'exos faits à cette date, liste des nombres de reussite, |
||
117 | ###liste des listes de positions des reussites |
||
9353 | bpr | 118 | |
9365 | bpr | 119 | print "\n[$xcoord],[$day],[$ycoord],[$zcoord],[$good]"; |
9358 | bpr | 120 | |
9355 | bpr | 121 | if (!($SH0=~ /,/)) { |
9363 | bpr | 122 | for my $ex (sort {$a <=> $b} keys %exobyday1){ |
9358 | bpr | 123 | my ($xcoord,$ycoord,$zcoord,$good,$tmp)=('','','','',''); |
9353 | bpr | 124 | for my $date ( sort keys %exobyday ) { |
9358 | bpr | 125 | if (!$exobyday1{$ex}->{$date}) { $exobyday1{$ex}->{$date}=0;} |
126 | if (!$scorebyday1{$ex}->{$date}) {$scorebyday1{$ex}->{$date} = 0;} |
||
127 | if (!$goodbyday1{$ex}->{$date}) { $goodbyday1{$ex}->{$date}='';} |
||
128 | if ($xcoord) {$tmp=',' }; |
||
9355 | bpr | 129 | $xcoord .= "$tmp$date"; |
9358 | bpr | 130 | $ycoord .= $tmp . $exobyday1{$ex}->{$date}; |
131 | $zcoord .= $tmp . $scorebyday1{$ex}->{$date}; |
||
132 | $good .= $tmp . '[' . $goodbyday1{$ex}->{$date} . ']'; |
||
133 | } |
||
134 | ###pour les exercices d'une feuille |
||
135 | ###numero exo, liste de dates, liste du nombre d'exos faits à cette date, liste des nombres de reussite, |
||
136 | ###liste des listes de positions des reussites |
||
137 | print "\n$ex,[$xcoord],[$ycoord],[$zcoord],[$good]"; |
||
9353 | bpr | 138 | } |
9355 | bpr | 139 | } |
140 | else { |
||
9363 | bpr | 141 | for my $sh (sort {$a <=> $b} keys %exobydaysh){ |
9358 | bpr | 142 | my ($xcoord,$ycoord,$zcoord,$good,$tmp)=('','','','',''); |
9363 | bpr | 143 | for my $date ( sort ( keys %exobyday) ) { |
9358 | bpr | 144 | if ($xcoord) {$tmp=',' }; |
9355 | bpr | 145 | $xcoord .= "$tmp$date"; |
9358 | bpr | 146 | if (!$exobydaysh{$sh}->{$date}) { $exobydaysh{$sh}->{$date}=0;} |
147 | if (!$scorebydaysh{$sh}->{$date}) {$scorebydaysh{$sh}->{$date} = 0;} |
||
148 | if (!$goodbydaysh{$sh}->{$date}) { $goodbydaysh{$sh}->{$date}='';} |
||
149 | $ycoord .= $tmp . $exobydaysh{$sh}->{$date}; |
||
150 | $zcoord .= $tmp . $scorebydaysh{$sh}->{$date}; |
||
151 | $good .= $tmp . '[' . $goodbydaysh{$sh}->{$date} . ']'; |
||
9355 | bpr | 152 | } |
9358 | bpr | 153 | ###pour les feuilles d'une liste de feuilles |
154 | ###numero feuille, liste de dates, liste du nombre d'exos faits à cette date, liste des nombres de reussite, |
||
155 | ###liste des listes de positions des reussites |
||
156 | print "\n$sh,[$xcoord],[$ycoord],[$zcoord],[$good]"; |
||
9355 | bpr | 157 | } |
158 | } |
||
9353 | bpr | 159 | } |
232 | bpr | 160 | sub converttime { |
161 | my $heure=shift; |
||
162 | my $date=shift; |
||
163 | $heure =~/([0-9]+):([0-9]+):([0-9]+)/; |
||
164 | $heure= 3600*$1+60*$2+$3; |
||
165 | $date =~/([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])/; |
||
166 | my $annee=$1; |
||
167 | my $mois=$2; |
||
168 | my $jour=$3; |
||
169 | return timelocal(0,0,0,$jour,$mois - 1,$annee) + $heure; |
||
170 | } |
||
171 | |||
172 | sub converttime2 { |
||
3906 | bpr | 173 | my $duree=shift; |
9358 | bpr | 174 | return "0:0:0" if !($duree); |
3906 | bpr | 175 | my $secondes = $duree% 60; |
232 | bpr | 176 | $duree = ($duree-$secondes)/ 60; |
3906 | bpr | 177 | my $minutes = $duree% 60; |
232 | bpr | 178 | $duree = ($duree-$minutes)/ 60; |
3906 | bpr | 179 | my $heures = $duree; |
232 | bpr | 180 | "$heures:$minutes:$secondes"; |
7159 | bpr | 181 | } |