Rev 11124 | 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 | { |
||
12200 | bpr | 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; |
||
10 | reyssat | 55 | } |
56 | |||
8899 | bpr | 57 | static |
7609 | bpr | 58 | void oneline(char *p, char *typ) |
10 | reyssat | 59 | { |
12200 | bpr | 60 | int i, j, sh, ex, t; |
61 | char *data[64]; |
||
62 | statexodata *tab; |
||
63 | char *pp, *pe; |
||
64 | for(i=0, pp=find_word_start(p); i<9 && *pp; pp=find_word_start(pe),i++) { |
||
65 | pe=find_word_end(pp); if(*pe) *pe++=0; |
||
66 | data[i]=pp; |
||
67 | } |
||
68 | if(i<6) return; |
||
69 | sh=atoi(data[2]); ex=atoi(data[3]); |
||
70 | if(sh<=0 || ex<=0 || ex>MAX_EXOS || strlen(data[1])>10) return; |
||
71 | if(data[0][0]=='E') { |
||
72 | tab=examdata; data[0]++; if(sh>MAX_EXAMS) return; |
||
73 | } |
||
74 | else { |
||
75 | tab=shdata; if(sh>MAX_SHEETS) return; |
||
76 | } |
||
77 | tab+=(sh-1)*MAX_EXOS+(ex-1); |
||
78 | t=str2time(data[0]); if(t==-1) return; |
||
79 | if(strstr(data[4],"new")!=NULL) { |
||
80 | if(strcmp(typ,"score")==0) |
||
81 | for (j = 6; j < i; ++j) if (strcmp(data[j],"noscore")==0) return; |
||
82 | if(strcmp(typ,"noscore")==0) |
||
83 | for (j = 7; j < i; ++j) if (strcmp(data[j],"noscore")==0) return; |
||
84 | snprintf(tab->lastnew,12,"%s",data[1]); |
||
85 | tab->newcnt++; tab->lasttime=t; |
||
86 | fcind++; |
||
87 | return; |
||
88 | } |
||
89 | if(strcmp(data[4],"score")==0) { |
||
90 | if(strcmp(tab->lastnew,data[1])!=0) return; |
||
91 | if(sccnt>=MAX_SCORE) return; |
||
92 | if(tab->lasttime==-1) return; |
||
93 | if(strcmp(typ,"score")==0 || strcmp(typ,"noscore")==0) |
||
94 | for (j = 7; j < i; ++j) |
||
95 | if (strcmp(data[j],"noscore")==0) return; |
||
96 | t-=tab->lasttime; tab->lasttime=-1; if(t<0) t+=24*3600; |
||
97 | if(t<0) t=0; |
||
98 | if(t>5*3600) t=5*3600; |
||
99 | scores[sccnt].dure=t; scores[sccnt].next=-1; |
||
100 | scores[sccnt].score=(double) atof(data[5])*100+0.5; |
||
101 | if(tab->scorecnt>0) scores[tab->lastscore].next=sccnt; |
||
102 | else tab->firstscore=sccnt; |
||
103 | tab->lastscore=sccnt; sccnt++; tab->scorecnt++; |
||
104 | } |
||
10 | reyssat | 105 | } |
106 | |||
7609 | bpr | 107 | void onefile(char *fname, char *typ) |
10 | reyssat | 108 | { |
12200 | bpr | 109 | FILE *f; |
110 | char *buf, *pp, *pe; |
||
111 | long int l; |
||
112 | f=fopen(fname,"r"); if(f==NULL) return; |
||
113 | fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET); |
||
114 | if(l<=0) {fclose(f); return;} |
||
115 | buf=xmalloc(l+16); (void)fread(buf,1,l,f); fclose(f); buf[l]=0; |
||
116 | fcind=0; |
||
117 | for(pp=buf; pp; pp=pe) { |
||
118 | pe=strchr(pp,'\n'); if(pe!=NULL) *pe++=0; |
||
119 | oneline(pp,typ); |
||
120 | } |
||
121 | free(buf); |
||
122 | if(fcind>0) filecnt++; |
||
10 | reyssat | 123 | } |
124 | |||
7609 | bpr | 125 | void onedir_ (char buf[MAX_LINELEN+1], char *typ) |
10 | reyssat | 126 | { |
7609 | bpr | 127 | char buf2[MAX_LINELEN+1]; |
128 | DIR *dir; |
||
129 | struct dirent *ff; |
||
130 | dir=opendir(buf); if(dir==NULL) return; |
||
12200 | bpr | 131 | while((ff=readdir(dir))!=NULL) { |
132 | if(!isalnum(ff->d_name[0]) || strcmp(ff->d_name,"supervisor")==0) continue; |
||
133 | snprintf(buf2,sizeof(buf2),"%s/%s",buf,ff->d_name); |
||
134 | onefile(buf2,typ); |
||
135 | } |
||
136 | closedir(dir); |
||
7609 | bpr | 137 | } |
138 | |||
139 | void onedir(char *dirname) |
||
140 | { |
||
12200 | bpr | 141 | char buf[MAX_LINELEN+1]; |
142 | char *t1, *t2, types[256]; |
||
143 | snprintf(types,sizeof(types),"%s",sdata); |
||
144 | for(t1=find_word_start(types); *t1; t1=find_word_start(t2)) { |
||
145 | t2=find_word_end(t1); if(*t2) *t2++=0; |
||
146 | snprintf(buf,sizeof(buf),"%s/%s/score",dirbase,dirname); |
||
147 | onedir_(buf,t1); |
||
148 | snprintf(buf,sizeof(buf),"%s/%s/noscore",dirbase,dirname); |
||
149 | onedir_(buf,t1); |
||
150 | } |
||
10 | reyssat | 151 | } |
152 | |||
7609 | bpr | 153 | void oneuser(char *dirname, char fname[64]) |
154 | { |
||
12200 | bpr | 155 | char buf[MAX_LINELEN+1], buf2[MAX_LINELEN+1]; |
156 | char *t1, *t2, types[256]; |
||
157 | snprintf(types,sizeof(types),"%s",sdata); |
||
158 | for(t1=find_word_start(types); *t1; t1=find_word_start(t2)) { |
||
159 | t2=find_word_end(t1); if(*t2) *t2++=0; |
||
160 | snprintf(buf,sizeof(buf),"%s/%s/score/%s",dirbase,dirname,fname); |
||
161 | onefile(buf,t1); |
||
162 | snprintf(buf2,sizeof(buf),"%s/%s/noscore/%s",dirbase,dirname,fname); |
||
163 | onefile(buf2,t1); |
||
164 | } |
||
7609 | bpr | 165 | } |
166 | |||
167 | void multiuser(char *dirname, char *user) |
||
168 | { |
||
12200 | bpr | 169 | char buf[MAX_LINELEN+1]; |
170 | char *u1, *u2; |
||
171 | snprintf(buf,sizeof(buf),"%s",user); |
||
172 | for(u1=find_word_start(buf); *u1; u1=find_word_start(u2)) { |
||
173 | u2=find_word_end(u1); if(*u2) *u2++=0; |
||
174 | oneuser(dirname, u1); |
||
7609 | bpr | 175 | } |
176 | } |
||
177 | |||
8254 | bpr | 178 | void stati(statexodata *dat) |
10 | reyssat | 179 | { |
12200 | bpr | 180 | int i,j; |
181 | double s,d; |
||
182 | scsum=scavg=scdeviat=dursum=duravg=durdeviat=cid=0; |
||
183 | scmin=10; scmax=0; durmin=24*3600; durmax=0; |
||
184 | {int k; for(k=0; k<10; k++) best[k]=0 ;} |
||
185 | for(i=0,j=dat->firstscore; i<dat->scorecnt; i++) { |
||
186 | s=(double) scores[j].score/100; d=(double) scores[j].dure/60; |
||
187 | scsum+=s; dursum+=d; |
||
188 | if(scmin>s) scmin=s; |
||
189 | if(scmax<s) scmax=s; |
||
190 | if(durmin>d) durmin=d; |
||
191 | if(durmax<d) durmax=d; |
||
192 | { |
||
193 | int k, l = 0; |
||
194 | for (k = 0; k < 10; k++) if (best[k] < best[l]) l = k; |
||
195 | if (best[l] < s) best[l] = s; |
||
196 | } |
||
197 | j=scores[j].next; |
||
198 | } |
||
199 | if(i<=0) {scmin=durmin=0; return;} |
||
200 | scavg=scsum/i; duravg=dursum/i; |
||
201 | if(scsum>1) cid=min(4*sqrt(dursum*dat->newcnt)/scsum,99); |
||
202 | else cid=0; |
||
203 | if(i>=2) { |
||
10 | reyssat | 204 | for(i=0,j=dat->firstscore; i<dat->scorecnt; i++) { |
7158 | bpr | 205 | s=(double) scores[j].score/100; d=(double) scores[j].dure/60; |
12200 | bpr | 206 | scdeviat+=(s-scavg)*(s-scavg); durdeviat+=(d-duravg)*(d-duravg); |
7158 | bpr | 207 | j=scores[j].next; |
10 | reyssat | 208 | } |
12200 | bpr | 209 | scdeviat=sqrt(scdeviat/i); durdeviat=sqrt(durdeviat/i); |
210 | } |
||
10 | reyssat | 211 | } |
212 | |||
7571 | bpr | 213 | /* Output line format: |
214 | * type sh exo newcnt scorecnt scsum dursum scavg duravg scmin durmin scmax durmax scdeviat durdeviat cid |
||
215 | */ |
||
7609 | bpr | 216 | |
217 | void outsheetexo (int i, int flag) |
||
10 | reyssat | 218 | { |
7609 | bpr | 219 | if(shdata[i].newcnt<=0) return; |
220 | stati(shdata+i); |
||
221 | switch(flag) { |
||
222 | case 0: printf(":S %2d %2d %4d %4d \ |
||
10 | reyssat | 223 | %4.0f %4.0f %5.2f %5.2f \ |
224 | %5.2f %4.1f %5.2f %5.1f \ |
||
225 | %5.2f %5.2f %4.1f\n", |
||
8254 | bpr | 226 | i/MAX_EXOS+1,i%MAX_EXOS+1, |
7158 | bpr | 227 | shdata[i].newcnt, shdata[i].scorecnt, |
228 | scsum, dursum, |
||
229 | scavg, duravg, |
||
230 | scmin,durmin,scmax,durmax, |
||
231 | scdeviat, durdeviat, |
||
7609 | bpr | 232 | cid); break; |
233 | case 1: printf("%d_%d=%d,%d,\ |
||
234 | %.0f,%.0f,%.2f,%.2f,\ |
||
235 | %.2f,%.1f,%.2f,%.1f,\ |
||
236 | %.2f,%.2f,%.1f;", |
||
8254 | bpr | 237 | i/MAX_EXOS+1,i%MAX_EXOS+1, |
7609 | bpr | 238 | shdata[i].newcnt, shdata[i].scorecnt, |
239 | scsum, dursum, |
||
240 | scavg, duravg, |
||
241 | scmin,durmin,scmax,durmax, |
||
242 | scdeviat, durdeviat, |
||
7158 | bpr | 243 | cid); |
7609 | bpr | 244 | int k; for (k=0; k<10; k++) printf("%.2f,", best[k]); |
245 | printf("\n"); |
||
246 | break; |
||
12200 | bpr | 247 | } |
7609 | bpr | 248 | } |
249 | |||
250 | void outexamexo (int i) |
||
251 | { |
||
12200 | bpr | 252 | if(examdata[i].newcnt<=0) return; |
253 | stati(examdata+i); |
||
254 | printf(":E %2d %2d %4d %4d \ |
||
10 | reyssat | 255 | %4.0f %4.0f %5.2f %5.2f \ |
256 | %5.2f %4.1f %5.2f %5.1f \ |
||
257 | %5.2f %5.2f %4.1f\n", |
||
8254 | bpr | 258 | i/MAX_EXOS+1,i%MAX_EXOS+1, |
7158 | bpr | 259 | examdata[i].newcnt, examdata[i].scorecnt, |
260 | scsum, dursum, |
||
261 | scavg, duravg, |
||
262 | scmin,durmin,scmax,durmax, |
||
263 | scdeviat, durdeviat, |
||
264 | cid); |
||
10 | reyssat | 265 | } |
266 | |||
7609 | bpr | 267 | void output(void) |
268 | { |
||
12200 | bpr | 269 | int i; |
270 | for(i=0;i<MAX_SHEETS*MAX_EXOS;i++) { outsheetexo(i, 0);} |
||
271 | for(i=0;i<MAX_EXAMS*MAX_EXOS;i++) { outexamexo(i);} |
||
7609 | bpr | 272 | } |
273 | |||
10 | reyssat | 274 | int main() |
275 | { |
||
12200 | bpr | 276 | char cla[MAX_LINELEN+1], user[256]; |
277 | char *c1, *c2; |
||
278 | char *cdata, *udata, *sh; |
||
7158 | bpr | 279 | |
12200 | bpr | 280 | memset(shdata,0,sizeof(shdata)); memset(examdata,0,sizeof(examdata)); |
281 | dirbase=getenv("exostat_dirbase"); |
||
282 | if(dirbase==NULL || *dirbase==0) dirbase="../log/classes"; |
||
283 | sdata=getenv("exostat_types"); |
||
284 | if(sdata==NULL || *sdata==0) sdata="score noscore"; |
||
285 | cdata=getenv("exostat_classes"); |
||
286 | if(cdata==NULL || *cdata==0) cdata=getenv("w_wims_class"); |
||
287 | if(cdata==NULL || *cdata==0) return -1; |
||
288 | snprintf(cla,sizeof(cla),"%s",cdata); |
||
289 | udata=getenv("exostat_user"); |
||
290 | if(udata==NULL || *udata==0) { |
||
291 | for(c1=cla; *c1; c1++) if(!isalnum(*c1) && *c1!='/') *c1=' '; |
||
292 | for(c1=find_word_start(cla); *c1; c1=find_word_start(c2)) { |
||
293 | c2=find_word_end(c1); if(*c2) *c2++=0; |
||
294 | onedir(c1); |
||
295 | } |
||
296 | output(); |
||
297 | } else { |
||
298 | snprintf(user,sizeof(user),"%s",udata); |
||
299 | multiuser(cla, user); |
||
300 | sh=getenv("exostat_sheet"); |
||
301 | if( sh==NULL || *sh==0 ) output(); |
||
302 | else { |
||
303 | int s=atoi(sh); |
||
304 | s=(s-1)*MAX_EXOS; |
||
305 | int i; |
||
306 | for(i=s;i < s + MAX_EXOS;i++) { |
||
307 | outsheetexo(i, 1); |
||
7609 | bpr | 308 | } |
12200 | bpr | 309 | }; |
310 | } |
||
311 | return 0; |
||
10 | reyssat | 312 | } |