Rev 8899 | Rev 12200 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10 | reyssat | 1 | /* Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis |
2 | * |
||
3 | * This program is free software; you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation; either version 2 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program; if not, write to the Free Software |
||
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
||
16 | */ |
||
17 | |||
7158 | bpr | 18 | /* This is an internal program, |
7571 | bpr | 19 | * used to show statistics of frequentation, module by module. |
7158 | bpr | 20 | */ |
10 | reyssat | 21 | |
22 | #include "../Lib/libwims.h" |
||
8254 | bpr | 23 | #include "../wimsdef.h" |
10 | reyssat | 24 | |
7158 | bpr | 25 | #define MAX_SCORE 512*1024 |
10 | reyssat | 26 | |
27 | typedef struct { |
||
28 | short int dure,score; |
||
29 | long int next; |
||
8254 | bpr | 30 | } statscoredata; |
31 | statscoredata scores[MAX_SCORE]; |
||
10 | reyssat | 32 | int sccnt=0; |
33 | |||
34 | typedef struct { |
||
35 | int newcnt,scorecnt,lasttime,firstscore,lastscore; |
||
36 | char lastnew[12]; |
||
8254 | bpr | 37 | } statexodata; |
38 | statexodata shdata[MAX_SHEETS*MAX_EXOS],examdata[MAX_EXAMS*MAX_EXOS]; |
||
10 | reyssat | 39 | |
40 | /* cid: combined index of difficulty */ |
||
41 | double scsum, scavg, scdeviat, scmin, scmax, cid; |
||
42 | double dursum, duravg, durdeviat, durmin, durmax; |
||
7609 | bpr | 43 | double best[10]; |
10 | reyssat | 44 | int filecnt=0, fcind; |
7609 | bpr | 45 | char *dirbase, *sdata, user[256]; |
10 | reyssat | 46 | |
47 | int str2time(char *p) |
||
48 | { |
||
49 | int sec,min,hr; |
||
50 | sec=atoi(p+15); p[14]=0; |
||
51 | min=atoi(p+12); p[11]=0; |
||
52 | hr=atoi(p+9); |
||
53 | if(sec<0 || min<0 || hr<0 || sec>59 || min>59 || hr>23) return -1; |
||
54 | return hr*3600+min*60+sec; |
||
55 | } |
||
56 | |||
8899 | bpr | 57 | static |
7609 | bpr | 58 | void oneline(char *p, char *typ) |
10 | reyssat | 59 | { |
60 | int i, sh, ex, t; |
||
61 | char *data[64]; |
||
8254 | bpr | 62 | statexodata *tab; |
10 | reyssat | 63 | char *pp, *pe; |
7609 | bpr | 64 | for(i=0, pp=find_word_start(p); i<9 && *pp; pp=find_word_start(pe),i++) { |
7158 | bpr | 65 | pe=find_word_end(pp); if(*pe) *pe++=0; |
66 | data[i]=pp; |
||
10 | reyssat | 67 | } |
68 | if(i<6) return; |
||
69 | sh=atoi(data[2]); ex=atoi(data[3]); |
||
8254 | bpr | 70 | if(sh<=0 || ex<=0 || ex>MAX_EXOS || strlen(data[1])>10) return; |
10 | reyssat | 71 | if(data[0][0]=='E') { |
8254 | bpr | 72 | tab=examdata; data[0]++; if(sh>MAX_EXAMS) return; |
10 | reyssat | 73 | } |
74 | else { |
||
8254 | bpr | 75 | tab=shdata; if(sh>MAX_SHEETS) return; |
10 | reyssat | 76 | } |
8254 | bpr | 77 | tab+=(sh-1)*MAX_EXOS+(ex-1); |
10 | reyssat | 78 | t=str2time(data[0]); if(t==-1) return; |
79 | if(strstr(data[4],"new")!=NULL) { |
||
7621 | bpr | 80 | if(strcmp(typ,"score")==0 && |
7642 | bpr | 81 | ((i > 6 && strcmp(data[6],"noscore")==0) || (i > 7 && strcmp(data[7],"noscore")==0) |
7621 | bpr | 82 | || (i > 8 && strcmp(data[8],"noscore")==0))){ return; } |
83 | if(strcmp(typ,"noscore")==0 && |
||
7620 | bpr | 84 | (i < 7 || ( i>7 && strcmp(data[7],typ)!=0) |
7621 | bpr | 85 | || (i > 8 && strcmp(data[8], typ)!=0) |
86 | )) { return; } |
||
7158 | bpr | 87 | snprintf(tab->lastnew,12,"%s",data[1]); |
88 | tab->newcnt++; tab->lasttime=t; |
||
89 | fcind++; |
||
90 | return; |
||
10 | reyssat | 91 | } |
92 | if(strcmp(data[4],"score")==0) { |
||
7158 | bpr | 93 | if(strcmp(tab->lastnew,data[1])!=0) return; |
94 | if(sccnt>=MAX_SCORE) return; |
||
95 | if(tab->lasttime==-1) return; |
||
7620 | bpr | 96 | if(strcmp(typ,"score")==0 && ( |
97 | (i > 7 && strcmp(data[7],"noscore")==0) |
||
98 | || (i > 8 && strcmp(data[8],"noscore")==0)) |
||
99 | ) { return; } |
||
100 | if(strcmp(typ,"noscore")==0 && ( |
||
101 | ( i < 7 || ( i > 7 && strcmp(data[7],"noscore")!=0) |
||
102 | || (i > 8 && strcmp(data[8], typ)!=0)) |
||
7621 | bpr | 103 | )){ return; } |
7158 | bpr | 104 | t-=tab->lasttime; tab->lasttime=-1; if(t<0) t+=24*3600; |
11124 | georgesk | 105 | if(t<0) t=0; |
106 | if(t>5*3600) t=5*3600; |
||
7158 | bpr | 107 | scores[sccnt].dure=t; scores[sccnt].next=-1; |
108 | scores[sccnt].score=(double) atof(data[5])*100+0.5; |
||
109 | if(tab->scorecnt>0) scores[tab->lastscore].next=sccnt; |
||
110 | else tab->firstscore=sccnt; |
||
111 | tab->lastscore=sccnt; sccnt++; tab->scorecnt++; |
||
10 | reyssat | 112 | } |
113 | } |
||
114 | |||
7609 | bpr | 115 | void onefile(char *fname, char *typ) |
10 | reyssat | 116 | { |
117 | FILE *f; |
||
118 | char *buf, *pp, *pe; |
||
119 | long int l; |
||
120 | f=fopen(fname,"r"); if(f==NULL) return; |
||
121 | fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET); |
||
122 | if(l<=0) {fclose(f); return;} |
||
3840 | kbelabas | 123 | buf=xmalloc(l+16); (void)fread(buf,1,l,f); fclose(f); buf[l]=0; |
10 | reyssat | 124 | fcind=0; |
125 | for(pp=buf; pp; pp=pe) { |
||
7158 | bpr | 126 | pe=strchr(pp,'\n'); if(pe!=NULL) *pe++=0; |
7609 | bpr | 127 | oneline(pp,typ); |
10 | reyssat | 128 | } |
129 | free(buf); |
||
130 | if(fcind>0) filecnt++; |
||
131 | } |
||
132 | |||
7609 | bpr | 133 | void onedir_ (char buf[MAX_LINELEN+1], char *typ) |
10 | reyssat | 134 | { |
7609 | bpr | 135 | char buf2[MAX_LINELEN+1]; |
136 | DIR *dir; |
||
137 | struct dirent *ff; |
||
138 | dir=opendir(buf); if(dir==NULL) return; |
||
7158 | bpr | 139 | while((ff=readdir(dir))!=NULL) { |
140 | if(!isalnum(ff->d_name[0]) || |
||
141 | strcmp(ff->d_name,"supervisor")==0) continue; |
||
142 | snprintf(buf2,sizeof(buf2),"%s/%s",buf,ff->d_name); |
||
7609 | bpr | 143 | onefile(buf2,typ); |
7158 | bpr | 144 | } |
145 | closedir(dir); |
||
7609 | bpr | 146 | } |
147 | |||
148 | void onedir(char *dirname) |
||
149 | { |
||
150 | char buf[MAX_LINELEN+1]; |
||
151 | char *t1, *t2, types[256]; |
||
152 | snprintf(types,sizeof(types),"%s",sdata); |
||
153 | for(t1=find_word_start(types); *t1; t1=find_word_start(t2)) { |
||
154 | t2=find_word_end(t1); if(*t2) *t2++=0; |
||
155 | snprintf(buf,sizeof(buf),"%s/%s/score",dirbase,dirname); |
||
156 | onedir_(buf,t1); |
||
157 | snprintf(buf,sizeof(buf),"%s/%s/noscore",dirbase,dirname); |
||
158 | onedir_(buf,t1); |
||
10 | reyssat | 159 | } |
160 | } |
||
161 | |||
7609 | bpr | 162 | void oneuser(char *dirname, char fname[64]) |
163 | { |
||
164 | char buf[MAX_LINELEN+1], buf2[MAX_LINELEN+1]; |
||
165 | char *t1, *t2, types[256]; |
||
166 | snprintf(types,sizeof(types),"%s",sdata); |
||
167 | for(t1=find_word_start(types); *t1; t1=find_word_start(t2)) { |
||
168 | t2=find_word_end(t1); if(*t2) *t2++=0; |
||
169 | snprintf(buf,sizeof(buf),"%s/%s/score/%s",dirbase,dirname,fname); |
||
170 | onefile(buf,t1); |
||
171 | snprintf(buf2,sizeof(buf),"%s/%s/noscore/%s",dirbase,dirname,fname); |
||
172 | onefile(buf2,t1); |
||
173 | } |
||
174 | } |
||
175 | |||
176 | void multiuser(char *dirname, char *user) |
||
177 | { |
||
178 | char buf[MAX_LINELEN+1]; |
||
179 | char *u1, *u2; |
||
180 | snprintf(buf,sizeof(buf),"%s",user); |
||
181 | for(u1=find_word_start(buf); *u1; u1=find_word_start(u2)) { |
||
182 | u2=find_word_end(u1); if(*u2) *u2++=0; |
||
183 | oneuser(dirname, u1); |
||
184 | } |
||
185 | } |
||
186 | |||
8254 | bpr | 187 | void stati(statexodata *dat) |
10 | reyssat | 188 | { |
189 | int i,j; |
||
190 | double s,d; |
||
7158 | bpr | 191 | |
10 | reyssat | 192 | scsum=scavg=scdeviat=dursum=duravg=durdeviat=cid=0; |
193 | scmin=10; scmax=0; durmin=24*3600; durmax=0; |
||
7609 | bpr | 194 | {int k; for(k=0; k<10; k++) best[k]=0 ;} |
10 | reyssat | 195 | for(i=0,j=dat->firstscore; i<dat->scorecnt; i++) { |
7158 | bpr | 196 | s=(double) scores[j].score/100; d=(double) scores[j].dure/60; |
197 | scsum+=s; dursum+=d; |
||
11124 | georgesk | 198 | if(scmin>s) scmin=s; |
199 | if(scmax<s) scmax=s; |
||
200 | if(durmin>d) durmin=d; |
||
201 | if(durmax<d) durmax=d; |
||
7609 | bpr | 202 | { |
203 | int k, l = 0; |
||
204 | for (k = 0; k < 10; k++) if (best[k] < best[l]) l = k; |
||
205 | if (best[l] < s) best[l] = s; |
||
206 | } |
||
7158 | bpr | 207 | j=scores[j].next; |
10 | reyssat | 208 | } |
209 | if(i<=0) {scmin=durmin=0; return;} |
||
210 | scavg=scsum/i; duravg=dursum/i; |
||
211 | if(scsum>1) cid=min(4*sqrt(dursum*dat->newcnt)/scsum,99); |
||
212 | else cid=0; |
||
213 | if(i>=2) { |
||
7158 | bpr | 214 | for(i=0,j=dat->firstscore; i<dat->scorecnt; i++) { |
215 | s=(double) scores[j].score/100; d=(double) scores[j].dure/60; |
||
216 | scdeviat+=(s-scavg)*(s-scavg); durdeviat+=(d-duravg)*(d-duravg); |
||
217 | j=scores[j].next; |
||
218 | } |
||
219 | scdeviat=sqrt(scdeviat/i); durdeviat=sqrt(durdeviat/i); |
||
10 | reyssat | 220 | } |
221 | } |
||
222 | |||
7571 | bpr | 223 | /* Output line format: |
224 | * type sh exo newcnt scorecnt scsum dursum scavg duravg scmin durmin scmax durmax scdeviat durdeviat cid |
||
225 | */ |
||
7609 | bpr | 226 | |
227 | void outsheetexo (int i, int flag) |
||
10 | reyssat | 228 | { |
7609 | bpr | 229 | if(shdata[i].newcnt<=0) return; |
230 | stati(shdata+i); |
||
231 | switch(flag) { |
||
232 | case 0: printf(":S %2d %2d %4d %4d \ |
||
10 | reyssat | 233 | %4.0f %4.0f %5.2f %5.2f \ |
234 | %5.2f %4.1f %5.2f %5.1f \ |
||
235 | %5.2f %5.2f %4.1f\n", |
||
8254 | bpr | 236 | i/MAX_EXOS+1,i%MAX_EXOS+1, |
7158 | bpr | 237 | shdata[i].newcnt, shdata[i].scorecnt, |
238 | scsum, dursum, |
||
239 | scavg, duravg, |
||
240 | scmin,durmin,scmax,durmax, |
||
241 | scdeviat, durdeviat, |
||
7609 | bpr | 242 | cid); break; |
243 | case 1: printf("%d_%d=%d,%d,\ |
||
244 | %.0f,%.0f,%.2f,%.2f,\ |
||
245 | %.2f,%.1f,%.2f,%.1f,\ |
||
246 | %.2f,%.2f,%.1f;", |
||
8254 | bpr | 247 | i/MAX_EXOS+1,i%MAX_EXOS+1, |
7609 | bpr | 248 | shdata[i].newcnt, shdata[i].scorecnt, |
249 | scsum, dursum, |
||
250 | scavg, duravg, |
||
251 | scmin,durmin,scmax,durmax, |
||
252 | scdeviat, durdeviat, |
||
7158 | bpr | 253 | cid); |
7609 | bpr | 254 | int k; for (k=0; k<10; k++) printf("%.2f,", best[k]); |
255 | printf("\n"); |
||
256 | break; |
||
257 | } |
||
258 | } |
||
259 | |||
260 | void outexamexo (int i) |
||
261 | { |
||
262 | if(examdata[i].newcnt<=0) return; |
||
7158 | bpr | 263 | stati(examdata+i); |
264 | printf(":E %2d %2d %4d %4d \ |
||
10 | reyssat | 265 | %4.0f %4.0f %5.2f %5.2f \ |
266 | %5.2f %4.1f %5.2f %5.1f \ |
||
267 | %5.2f %5.2f %4.1f\n", |
||
8254 | bpr | 268 | i/MAX_EXOS+1,i%MAX_EXOS+1, |
7158 | bpr | 269 | examdata[i].newcnt, examdata[i].scorecnt, |
270 | scsum, dursum, |
||
271 | scavg, duravg, |
||
272 | scmin,durmin,scmax,durmax, |
||
273 | scdeviat, durdeviat, |
||
274 | cid); |
||
10 | reyssat | 275 | } |
276 | |||
7609 | bpr | 277 | void output(void) |
278 | { |
||
279 | int i; |
||
8254 | bpr | 280 | for(i=0;i<MAX_SHEETS*MAX_EXOS;i++) { outsheetexo(i, 0);} |
281 | for(i=0;i<MAX_EXAMS*MAX_EXOS;i++) { outexamexo(i);} |
||
7609 | bpr | 282 | } |
283 | |||
10 | reyssat | 284 | int main() |
285 | { |
||
7609 | bpr | 286 | char cla[MAX_LINELEN+1], user[256]; |
10 | reyssat | 287 | char *c1, *c2; |
7609 | bpr | 288 | char *cdata, *udata, *sh; |
7158 | bpr | 289 | |
10 | reyssat | 290 | memset(shdata,0,sizeof(shdata)); memset(examdata,0,sizeof(examdata)); |
291 | dirbase=getenv("exostat_dirbase"); |
||
292 | if(dirbase==NULL || *dirbase==0) dirbase="../log/classes"; |
||
293 | sdata=getenv("exostat_types"); |
||
294 | if(sdata==NULL || *sdata==0) sdata="score noscore"; |
||
295 | cdata=getenv("exostat_classes"); |
||
296 | if(cdata==NULL || *cdata==0) cdata=getenv("w_wims_class"); |
||
297 | if(cdata==NULL || *cdata==0) return -1; |
||
298 | snprintf(cla,sizeof(cla),"%s",cdata); |
||
7609 | bpr | 299 | udata=getenv("exostat_user"); |
300 | if(udata==NULL || *udata==0) { |
||
301 | for(c1=cla; *c1; c1++) if(!isalnum(*c1) && *c1!='/') *c1=' '; |
||
302 | for(c1=find_word_start(cla); *c1; c1=find_word_start(c2)) { |
||
303 | c2=find_word_end(c1); if(*c2) *c2++=0; |
||
304 | onedir(c1); |
||
305 | } |
||
306 | output(); |
||
307 | } else { |
||
308 | snprintf(user,sizeof(user),"%s",udata); |
||
309 | multiuser(cla, user); |
||
310 | sh=getenv("exostat_sheet"); |
||
311 | if( sh==NULL || *sh==0 ) { output(); } |
||
312 | else { |
||
313 | int s=atoi(sh); |
||
8254 | bpr | 314 | s=(s-1)*MAX_EXOS; |
7609 | bpr | 315 | int i; |
8254 | bpr | 316 | for(i=s;i < s + MAX_EXOS;i++) { |
7609 | bpr | 317 | outsheetexo(i, 1); |
318 | } |
||
319 | }; |
||
10 | reyssat | 320 | } |
321 | return 0; |
||
322 | } |