Rev 7609 | Rev 7621 | 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" |
||
23 | |||
7158 | bpr | 24 | #define MAX_EXO 64 |
25 | #define MAX_SHEET 64 |
||
26 | #define MAX_EXAM 32 |
||
27 | #define MAX_SCORE 512*1024 |
||
10 | reyssat | 28 | |
29 | typedef struct { |
||
30 | short int dure,score; |
||
31 | long int next; |
||
32 | } scoredata; |
||
33 | scoredata scores[MAX_SCORE]; |
||
34 | int sccnt=0; |
||
35 | |||
36 | typedef struct { |
||
37 | int newcnt,scorecnt,lasttime,firstscore,lastscore; |
||
38 | char lastnew[12]; |
||
39 | } exodata; |
||
40 | exodata shdata[MAX_SHEET*MAX_EXO],examdata[MAX_EXAM*MAX_EXO]; |
||
41 | |||
42 | /* cid: combined index of difficulty */ |
||
43 | double scsum, scavg, scdeviat, scmin, scmax, cid; |
||
44 | double dursum, duravg, durdeviat, durmin, durmax; |
||
7609 | bpr | 45 | double best[10]; |
10 | reyssat | 46 | int filecnt=0, fcind; |
7609 | bpr | 47 | char *dirbase, *sdata, user[256]; |
10 | reyssat | 48 | |
49 | int str2time(char *p) |
||
50 | { |
||
51 | int sec,min,hr; |
||
52 | sec=atoi(p+15); p[14]=0; |
||
53 | min=atoi(p+12); p[11]=0; |
||
54 | hr=atoi(p+9); |
||
55 | if(sec<0 || min<0 || hr<0 || sec>59 || min>59 || hr>23) return -1; |
||
56 | return hr*3600+min*60+sec; |
||
57 | } |
||
58 | |||
7609 | bpr | 59 | void oneline(char *p, char *typ) |
10 | reyssat | 60 | { |
61 | int i, sh, ex, t; |
||
62 | char *data[64]; |
||
63 | exodata *tab; |
||
64 | char *pp, *pe; |
||
7609 | bpr | 65 | for(i=0, pp=find_word_start(p); i<9 && *pp; pp=find_word_start(pe),i++) { |
7158 | bpr | 66 | pe=find_word_end(pp); if(*pe) *pe++=0; |
67 | data[i]=pp; |
||
10 | reyssat | 68 | } |
69 | if(i<6) return; |
||
70 | sh=atoi(data[2]); ex=atoi(data[3]); |
||
71 | if(sh<=0 || ex<=0 || ex>MAX_EXO || strlen(data[1])>10) return; |
||
72 | if(data[0][0]=='E') { |
||
7158 | bpr | 73 | tab=examdata; data[0]++; if(sh>MAX_EXAM) return; |
10 | reyssat | 74 | } |
75 | else { |
||
7158 | bpr | 76 | tab=shdata; if(sh>MAX_SHEET) return; |
10 | reyssat | 77 | } |
78 | tab+=(sh-1)*MAX_EXO+(ex-1); |
||
79 | t=str2time(data[0]); if(t==-1) return; |
||
80 | if(strstr(data[4],"new")!=NULL) { |
||
7620 | bpr | 81 | if(strcmp(typ,"score")==0 && ( |
82 | (strcmp(data[6],"noscore")==0 || (i > 7 && strcmp(data[7],"noscore")==0) |
||
83 | || (i > 8 && strcmp(data[8],"noscore")==0))) { return; } |
||
84 | if(strcmp(typ,"noscore")==0 && ( |
||
85 | (i < 7 || ( i>7 && strcmp(data[7],typ)!=0) |
||
86 | || (i > 8 && strcmp(data[8], typ)!=0)) |
||
87 | ) { return; } |
||
7609 | bpr | 88 | } |
7158 | bpr | 89 | snprintf(tab->lastnew,12,"%s",data[1]); |
90 | tab->newcnt++; tab->lasttime=t; |
||
91 | fcind++; |
||
92 | return; |
||
10 | reyssat | 93 | } |
94 | if(strcmp(data[4],"score")==0) { |
||
7158 | bpr | 95 | if(strcmp(tab->lastnew,data[1])!=0) return; |
96 | if(sccnt>=MAX_SCORE) return; |
||
97 | if(tab->lasttime==-1) return; |
||
7620 | bpr | 98 | if(strcmp(typ,"score")==0 && ( |
99 | (i > 7 && strcmp(data[7],"noscore")==0) |
||
100 | || (i > 8 && strcmp(data[8],"noscore")==0)) |
||
101 | ) { return; } |
||
102 | if(strcmp(typ,"noscore")==0 && ( |
||
103 | ( i < 7 || ( i > 7 && strcmp(data[7],"noscore")!=0) |
||
104 | || (i > 8 && strcmp(data[8], typ)!=0)) |
||
105 | ) { return; } |
||
106 | } |
||
7158 | bpr | 107 | t-=tab->lasttime; tab->lasttime=-1; if(t<0) t+=24*3600; |
108 | if(t<0) t=0; if(t>5*3600) t=5*3600; |
||
109 | scores[sccnt].dure=t; scores[sccnt].next=-1; |
||
110 | scores[sccnt].score=(double) atof(data[5])*100+0.5; |
||
111 | if(tab->scorecnt>0) scores[tab->lastscore].next=sccnt; |
||
112 | else tab->firstscore=sccnt; |
||
113 | tab->lastscore=sccnt; sccnt++; tab->scorecnt++; |
||
10 | reyssat | 114 | } |
115 | } |
||
116 | |||
7609 | bpr | 117 | void onefile(char *fname, char *typ) |
10 | reyssat | 118 | { |
119 | FILE *f; |
||
120 | char *buf, *pp, *pe; |
||
121 | long int l; |
||
122 | f=fopen(fname,"r"); if(f==NULL) return; |
||
123 | fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET); |
||
124 | if(l<=0) {fclose(f); return;} |
||
3840 | kbelabas | 125 | buf=xmalloc(l+16); (void)fread(buf,1,l,f); fclose(f); buf[l]=0; |
10 | reyssat | 126 | fcind=0; |
127 | for(pp=buf; pp; pp=pe) { |
||
7158 | bpr | 128 | pe=strchr(pp,'\n'); if(pe!=NULL) *pe++=0; |
7609 | bpr | 129 | oneline(pp,typ); |
10 | reyssat | 130 | } |
131 | free(buf); |
||
132 | if(fcind>0) filecnt++; |
||
133 | } |
||
134 | |||
7609 | bpr | 135 | void onedir_ (char buf[MAX_LINELEN+1], char *typ) |
10 | reyssat | 136 | { |
7609 | bpr | 137 | char buf2[MAX_LINELEN+1]; |
138 | DIR *dir; |
||
139 | struct dirent *ff; |
||
140 | dir=opendir(buf); if(dir==NULL) return; |
||
7158 | bpr | 141 | while((ff=readdir(dir))!=NULL) { |
142 | if(!isalnum(ff->d_name[0]) || |
||
143 | strcmp(ff->d_name,"supervisor")==0) continue; |
||
144 | snprintf(buf2,sizeof(buf2),"%s/%s",buf,ff->d_name); |
||
7609 | bpr | 145 | onefile(buf2,typ); |
7158 | bpr | 146 | } |
147 | closedir(dir); |
||
7609 | bpr | 148 | } |
149 | |||
150 | void onedir(char *dirname) |
||
151 | { |
||
152 | char buf[MAX_LINELEN+1]; |
||
153 | char *t1, *t2, types[256]; |
||
154 | snprintf(types,sizeof(types),"%s",sdata); |
||
155 | for(t1=find_word_start(types); *t1; t1=find_word_start(t2)) { |
||
156 | t2=find_word_end(t1); if(*t2) *t2++=0; |
||
157 | snprintf(buf,sizeof(buf),"%s/%s/score",dirbase,dirname); |
||
158 | onedir_(buf,t1); |
||
159 | snprintf(buf,sizeof(buf),"%s/%s/noscore",dirbase,dirname); |
||
160 | onedir_(buf,t1); |
||
10 | reyssat | 161 | } |
162 | } |
||
163 | |||
7609 | bpr | 164 | void oneuser(char *dirname, char fname[64]) |
165 | { |
||
166 | char buf[MAX_LINELEN+1], buf2[MAX_LINELEN+1]; |
||
167 | char *t1, *t2, types[256]; |
||
168 | snprintf(types,sizeof(types),"%s",sdata); |
||
169 | for(t1=find_word_start(types); *t1; t1=find_word_start(t2)) { |
||
170 | t2=find_word_end(t1); if(*t2) *t2++=0; |
||
171 | snprintf(buf,sizeof(buf),"%s/%s/score/%s",dirbase,dirname,fname); |
||
172 | onefile(buf,t1); |
||
173 | snprintf(buf2,sizeof(buf),"%s/%s/noscore/%s",dirbase,dirname,fname); |
||
174 | onefile(buf2,t1); |
||
175 | } |
||
176 | } |
||
177 | |||
178 | void multiuser(char *dirname, char *user) |
||
179 | { |
||
180 | char buf[MAX_LINELEN+1]; |
||
181 | char *u1, *u2; |
||
182 | snprintf(buf,sizeof(buf),"%s",user); |
||
183 | for(u1=find_word_start(buf); *u1; u1=find_word_start(u2)) { |
||
184 | u2=find_word_end(u1); if(*u2) *u2++=0; |
||
185 | oneuser(dirname, u1); |
||
186 | } |
||
187 | } |
||
188 | |||
10 | reyssat | 189 | void stati(exodata *dat) |
190 | { |
||
191 | int i,j; |
||
192 | double s,d; |
||
7158 | bpr | 193 | |
10 | reyssat | 194 | scsum=scavg=scdeviat=dursum=duravg=durdeviat=cid=0; |
195 | scmin=10; scmax=0; durmin=24*3600; durmax=0; |
||
7609 | bpr | 196 | {int k; for(k=0; k<10; k++) best[k]=0 ;} |
10 | reyssat | 197 | for(i=0,j=dat->firstscore; i<dat->scorecnt; i++) { |
7158 | bpr | 198 | s=(double) scores[j].score/100; d=(double) scores[j].dure/60; |
199 | scsum+=s; dursum+=d; |
||
200 | if(scmin>s) scmin=s; if(scmax<s) scmax=s; |
||
201 | if(durmin>d) durmin=d; 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", |
||
7158 | bpr | 236 | i/MAX_EXO+1,i%MAX_EXO+1, |
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;", |
||
247 | i/MAX_EXO+1,i%MAX_EXO+1, |
||
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", |
||
7158 | bpr | 268 | i/MAX_EXO+1,i%MAX_EXO+1, |
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; |
||
280 | for(i=0;i<MAX_SHEET*MAX_EXO;i++) { outsheetexo(i, 0);} |
||
281 | for(i=0;i<MAX_EXAM*MAX_EXO;i++) { outexamexo(i);} |
||
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); |
||
314 | s=(s-1)*MAX_EXO; |
||
315 | int i; |
||
316 | for(i=s;i < s + MAX_EXO;i++) { |
||
317 | outsheetexo(i, 1); |
||
318 | } |
||
319 | }; |
||
10 | reyssat | 320 | } |
321 | return 0; |
||
322 | } |