Subversion Repositories wimsdev

Rev

Rev 3840 | Rev 7571 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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