Subversion Repositories wimsdev

Rev

Rev 7158 | Rev 7609 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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.  
  18. /* This is an internal program,
  19.  * used to show statistics of frequentation, module by module.
  20. */
  21.  
  22. #include "../Lib/libwims.h"
  23.  
  24. #define MAX_EXO        64
  25. #define MAX_SHEET      64
  26. #define MAX_EXAM       32
  27. #define MAX_SCORE      512*1024
  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;
  45.  
  46. int filecnt=0, fcind;
  47. char *dirbase, *sdata;
  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.  
  59. void oneline(char *p)
  60. {
  61.     int i, sh, ex, t;
  62.     char *data[64];
  63.     exodata *tab;
  64.     char *pp, *pe;
  65.  
  66.     for(i=0, pp=find_word_start(p); i<8 && *pp; pp=find_word_start(pe),i++) {
  67.       pe=find_word_end(pp); if(*pe) *pe++=0;
  68.       data[i]=pp;
  69.     }
  70.     if(i<6) return;
  71.     sh=atoi(data[2]); ex=atoi(data[3]);
  72.     if(sh<=0 || ex<=0 || ex>MAX_EXO || strlen(data[1])>10) return;
  73.     if(data[0][0]=='E') {
  74.       tab=examdata; data[0]++; if(sh>MAX_EXAM) return;
  75.     }
  76.     else {
  77.       tab=shdata; if(sh>MAX_SHEET) return;
  78.     }
  79.     tab+=(sh-1)*MAX_EXO+(ex-1);
  80.     t=str2time(data[0]); if(t==-1) return;
  81.     if(strstr(data[4],"new")!=NULL) {
  82.       snprintf(tab->lastnew,12,"%s",data[1]);
  83.       tab->newcnt++; tab->lasttime=t;
  84.       fcind++;
  85.       return;
  86.     }
  87.     if(strcmp(data[4],"score")==0) {
  88.       if(strcmp(tab->lastnew,data[1])!=0) return;
  89.       if(sccnt>=MAX_SCORE) return;
  90.       if(tab->lasttime==-1) return;
  91.       t-=tab->lasttime; tab->lasttime=-1; if(t<0) t+=24*3600;
  92.       if(t<0) t=0; if(t>5*3600) t=5*3600;
  93.       scores[sccnt].dure=t; scores[sccnt].next=-1;
  94.       scores[sccnt].score=(double) atof(data[5])*100+0.5;
  95.       if(tab->scorecnt>0) scores[tab->lastscore].next=sccnt;
  96.       else tab->firstscore=sccnt;
  97.       tab->lastscore=sccnt; sccnt++; tab->scorecnt++;
  98.     }
  99. }
  100.  
  101. void onefile(char *fname)
  102. {
  103.     FILE *f;
  104.     char *buf, *pp, *pe;
  105.     long int l;
  106.     f=fopen(fname,"r"); if(f==NULL) return;
  107.     fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET);
  108.     if(l<=0) {fclose(f); return;}
  109.     buf=xmalloc(l+16); (void)fread(buf,1,l,f); fclose(f); buf[l]=0;
  110.     fcind=0;
  111.     for(pp=buf; pp; pp=pe) {
  112.       pe=strchr(pp,'\n'); if(pe!=NULL) *pe++=0;
  113.       oneline(pp);
  114.     }
  115.     free(buf);
  116.     if(fcind>0) filecnt++;
  117. }
  118.  
  119. void onedir(char *dirname)
  120. {
  121.     char buf[MAX_LINELEN+1], buf2[MAX_LINELEN+1];
  122.     DIR *dir;
  123.     struct dirent *ff;
  124.     char *t1, *t2, types[256];
  125.     snprintf(types,sizeof(types),"%s",sdata);
  126.     for(t1=find_word_start(types); *t1; t1=find_word_start(t2)) {
  127.       t2=find_word_end(t1); if(*t2) *t2++=0;
  128.       snprintf(buf,sizeof(buf),"%s/%s/%s",dirbase,dirname,t1);
  129.       dir=opendir(buf); if(dir==NULL) return;
  130.       while((ff=readdir(dir))!=NULL) {
  131.           if(!isalnum(ff->d_name[0]) ||
  132.              strcmp(ff->d_name,"supervisor")==0) continue;
  133.           snprintf(buf2,sizeof(buf2),"%s/%s",buf,ff->d_name);
  134.           onefile(buf2);
  135.       }
  136.       closedir(dir);
  137.     }
  138. }
  139.  
  140. void stati(exodata *dat)
  141. {
  142.     int i,j;
  143.     double s,d;
  144.  
  145.     scsum=scavg=scdeviat=dursum=duravg=durdeviat=cid=0;
  146.     scmin=10; scmax=0; durmin=24*3600; durmax=0;
  147.     for(i=0,j=dat->firstscore; i<dat->scorecnt; i++) {
  148.       s=(double) scores[j].score/100; d=(double) scores[j].dure/60;
  149.       scsum+=s; dursum+=d;
  150.       if(scmin>s) scmin=s; if(scmax<s) scmax=s;
  151.       if(durmin>d) durmin=d; if(durmax<d) durmax=d;
  152.       j=scores[j].next;
  153.     }
  154.     if(i<=0) {scmin=durmin=0; return;}
  155.     scavg=scsum/i; duravg=dursum/i;
  156.     if(scsum>1) cid=min(4*sqrt(dursum*dat->newcnt)/scsum,99);
  157.     else cid=0;
  158.     if(i>=2) {
  159.       for(i=0,j=dat->firstscore; i<dat->scorecnt; i++) {
  160.           s=(double) scores[j].score/100; d=(double) scores[j].dure/60;
  161.           scdeviat+=(s-scavg)*(s-scavg); durdeviat+=(d-duravg)*(d-duravg);
  162.           j=scores[j].next;
  163.       }
  164.       scdeviat=sqrt(scdeviat/i); durdeviat=sqrt(durdeviat/i);
  165.     }
  166. }
  167.  
  168. /* Output line format:
  169.  * type sh exo newcnt scorecnt scsum dursum scavg duravg scmin durmin scmax durmax scdeviat durdeviat cid
  170.  */
  171. void output(void)
  172. {
  173.     int i;
  174.     for(i=0;i<MAX_SHEET*MAX_EXO;i++) {
  175.       if(shdata[i].newcnt<=0) continue;
  176.       stati(shdata+i);
  177.       printf(":S %2d %2d %4d %4d \
  178. %4.0f %4.0f %5.2f %5.2f \
  179. %5.2f %4.1f %5.2f %5.1f \
  180. %5.2f %5.2f %4.1f\n",
  181.              i/MAX_EXO+1,i%MAX_EXO+1,
  182.              shdata[i].newcnt, shdata[i].scorecnt,
  183.              scsum, dursum,
  184.              scavg, duravg,
  185.              scmin,durmin,scmax,durmax,
  186.              scdeviat, durdeviat,
  187.              cid);
  188.     }
  189.     for(i=0;i<MAX_EXAM*MAX_EXO;i++) {
  190.       if(examdata[i].newcnt<=0) continue;
  191.       stati(examdata+i);
  192.       printf(":E %2d %2d %4d %4d \
  193. %4.0f %4.0f %5.2f %5.2f \
  194. %5.2f %4.1f %5.2f %5.1f \
  195. %5.2f %5.2f %4.1f\n",
  196.              i/MAX_EXO+1,i%MAX_EXO+1,
  197.              examdata[i].newcnt, examdata[i].scorecnt,
  198.              scsum, dursum,
  199.              scavg, duravg,
  200.              scmin,durmin,scmax,durmax,
  201.              scdeviat, durdeviat,
  202.              cid);
  203.     }
  204. }
  205.  
  206. int main()
  207. {
  208.     char cla[MAX_LINELEN+1];
  209.     char *c1, *c2;
  210.     char *cdata;
  211.  
  212.     memset(shdata,0,sizeof(shdata)); memset(examdata,0,sizeof(examdata));
  213.     dirbase=getenv("exostat_dirbase");
  214.     if(dirbase==NULL || *dirbase==0) dirbase="../log/classes";
  215.     sdata=getenv("exostat_types");
  216.     if(sdata==NULL || *sdata==0) sdata="score noscore";
  217.     cdata=getenv("exostat_classes");
  218.     if(cdata==NULL || *cdata==0) cdata=getenv("w_wims_class");
  219.     if(cdata==NULL || *cdata==0) return -1;
  220.     snprintf(cla,sizeof(cla),"%s",cdata);
  221.     for(c1=cla; *c1; c1++) if(!isalnum(*c1) && *c1!='/') *c1=' ';
  222.     for(c1=find_word_start(cla); *c1; c1=find_word_start(c2)) {
  223.       c2=find_word_end(c1); if(*c2) *c2++=0;
  224.       onedir(c1);
  225.     }
  226.     output();
  227.     return 0;
  228. }
  229.