Rev 7079 | Rev 8149 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7079 | Rev 8100 | ||
---|---|---|---|
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 |
|
18 | /* Computes class connection count (unit: student-minutes) */ |
19 | 19 | ||
20 | #include "../wimsdef.h" |
20 | #include "../wimsdef.h" |
21 | #include "../includes.h" |
21 | #include "../includes.h" |
22 | #include "../Lib/ |
22 | #include "../Lib/libwims.h" |
23 | 23 | ||
24 | /* The maximal number of sessions within one day */ |
24 | /* The maximal number of sessions within one day */ |
25 | #define MAX_SESSIONS (128*1024) |
25 | #define MAX_SESSIONS (128*1024) |
26 | /* The maximal number of classes within one day */ |
26 | /* The maximal number of classes within one day */ |
27 | #define MAX_CLASSES 8192 |
27 | #define MAX_CLASSES 8192 |
Line 43... | Line 43... | ||
43 | struct cls { |
43 | struct cls { |
44 | int cl, cnt; |
44 | int cl, cnt; |
45 | } cls[MAX_CLASSES]; |
45 | } cls[MAX_CLASSES]; |
46 | int clscnt; |
46 | int clscnt; |
47 | 47 | ||
- | 48 | /* |
|
48 | void *xmalloc(size_t n) |
49 | void *xmalloc(size_t n) |
49 | { |
50 | { |
50 | void *p; |
51 | void *p; |
51 | p=malloc(n); |
52 | p=malloc(n); |
52 | if(p==NULL) { |
53 | if(p==NULL) { |
53 | fprintf(stderr,"Malloc failure."); exit(1); |
54 | fprintf(stderr,"Malloc failure."); exit(1); |
54 | } |
55 | } |
55 | return p; |
56 | return p; |
56 | } |
57 | } |
57 | 58 | */ |
|
58 | /* Points to the end of the word */ |
59 | /* Points to the end of the word */ |
- | 60 | /* |
|
59 | char *find_word_end(char *p) |
61 | char *find_word_end(char *p) |
60 | { |
62 | { |
61 | int i; |
63 | int i; |
62 | for(i=0;!isspace(*p) && *p!=0 && i<MAX_LINELEN; p++,i++); |
64 | for(i=0;!isspace(*p) && *p!=0 && i<MAX_LINELEN; p++,i++); |
63 | return p; |
65 | return p; |
64 | } |
66 | } |
65 | 67 | */ |
|
66 | /* Strips leading spaces */ |
68 | /* Strips leading spaces */ |
- | 69 | /* |
|
67 | char *find_word_start(char *p) |
70 | char *find_word_start(char *p) |
68 | { |
71 | { |
69 | int i; |
72 | int i; |
70 | for(i=0; isspace(*p) && i<MAX_LINELEN; p++,i++); |
73 | for(i=0; isspace(*p) && i<MAX_LINELEN; p++,i++); |
71 | return p; |
74 | return p; |
72 | } |
75 | } |
73 | 76 | */ |
|
74 | /* Read/write to a file with variable parms to print filename */ |
77 | /* Read/write to a file with variable parms to print filename */ |
75 | void accessfile(char *content, char *type, char *s,...) |
78 | void accessfile(char *content, char *type, char *s,...) |
76 | { |
79 | { |
77 | va_list vp; |
80 | va_list vp; |
78 | char buf[MAX_LINELEN+1]; |
81 | char buf[MAX_LINELEN+1]; |
79 | FILE *f; |
82 | FILE *f; |
80 | int l; |
83 | int l; |
81 | 84 | ||
82 | va_start(vp,s); |
85 | va_start(vp,s); |
83 | vsnprintf(buf,sizeof(buf),s,vp); |
86 | vsnprintf(buf,sizeof(buf),s,vp); |
84 | va_end(vp); |
87 | va_end(vp); |
85 | f=fopen(buf,type); if(f==NULL) { |
88 | f=fopen(buf,type); if(f==NULL) { |
86 | if(*type=='r') content[0]=0; return; |
89 | if(*type=='r') content[0]=0; return; |
Line 101... | Line 104... | ||
101 | } |
104 | } |
102 | } |
105 | } |
103 | fclose(f); |
106 | fclose(f); |
104 | } |
107 | } |
105 | 108 | ||
106 |
|
109 | /* returns -1 if error */ |
- | 110 | /* |
|
107 | long int filelength(char *fn,...) |
111 | long int filelength(char *fn,...) |
108 | { |
112 | { |
109 | char buf[4096]; |
113 | char buf[4096]; |
110 | va_list vp; |
114 | va_list vp; |
111 | struct stat st; |
115 | struct stat st; |
Line 114... | Line 118... | ||
114 | va_start(vp,fn); |
118 | va_start(vp,fn); |
115 | vsnprintf(buf,sizeof(buf),fn,vp); va_end(vp); |
119 | vsnprintf(buf,sizeof(buf),fn,vp); va_end(vp); |
116 | l=stat(buf,&st); if(l) return -1; |
120 | l=stat(buf,&st); if(l) return -1; |
117 | return st.st_size; |
121 | return st.st_size; |
118 | } |
122 | } |
119 | 123 | */ |
|
120 | /* recursively generate a directory structure */ |
124 | /* recursively generate a directory structure */ |
121 | void |
125 | void mkdirs2(char *s) |
122 | { |
126 | { |
123 | struct stat st; |
127 | struct stat st; |
124 | char *buf; |
128 | char *buf; |
125 | if(stat(s,&st)==-1) { |
129 | if(stat(s,&st)==-1) { |
126 | if(strrchr(s,'/')!=NULL) { |
130 | if(strrchr(s,'/')!=NULL) { |
127 | buf=xmalloc(strlen(s)+1); |
131 | buf=xmalloc(strlen(s)+1); |
128 | ovlstrcpy(buf,s); *strrchr(buf,'/')=0; |
132 | ovlstrcpy(buf,s); *strrchr(buf,'/')=0; |
129 |
|
133 | mkdirs2(buf); free(buf); |
130 | } |
134 | } |
131 | mkdir(s,-1); |
135 | mkdir(s,-1); |
132 | } |
136 | } |
133 | } |
137 | } |
134 | 138 | ||
Line 205... | Line 209... | ||
205 | char *p, buf[1024], dbuf[1024]; |
209 | char *p, buf[1024], dbuf[1024]; |
206 | int i,t; |
210 | int i,t; |
207 | p=getenv("ccsum_outdir"); if(p==NULL || *p==0) return; |
211 | p=getenv("ccsum_outdir"); if(p==NULL || *p==0) return; |
208 | for(i=0;i<sescnt;i++) { |
212 | for(i=0;i<sescnt;i++) { |
209 | snprintf(dbuf,sizeof(dbuf),"%s/%d",p,ses[i].cl); |
213 | snprintf(dbuf,sizeof(dbuf),"%s/%d",p,ses[i].cl); |
210 |
|
214 | mkdirs2(dbuf); |
211 | snprintf(buf,sizeof(buf),"%s.%02d:%02d %d\n", |
215 | snprintf(buf,sizeof(buf),"%s.%02d:%02d %d\n", |
212 | datestr,ses[i].start/60,ses[i].start%60,ses[i].cnt); |
216 | datestr,ses[i].start/60,ses[i].start%60,ses[i].cnt); |
213 | accessfile(buf,"a","%s/%s",dbuf,ses[i].u); |
217 | accessfile(buf,"a","%s/%s",dbuf,ses[i].u); |
214 | } |
218 | } |
215 | snprintf(dbuf,sizeof(dbuf),"%s/bydate/%.4s",p,datestr); |
219 | snprintf(dbuf,sizeof(dbuf),"%s/bydate/%.4s",p,datestr); |
216 |
|
220 | mkdirs2(dbuf); |
217 | snprintf(dbuf+strlen(dbuf),sizeof(dbuf)-strlen(dbuf),"/%.2s",datestr+4); |
221 | snprintf(dbuf+strlen(dbuf),sizeof(dbuf)-strlen(dbuf),"/%.2s",datestr+4); |
218 | t=0; |
222 | t=0; |
219 | qsort(cls,clscnt,sizeof(cls[0]),clscmp); |
223 | qsort(cls,clscnt,sizeof(cls[0]),clscmp); |
220 | for(i=0;i<clscnt;i++) { |
224 | for(i=0;i<clscnt;i++) { |
221 | snprintf(buf,sizeof(buf),"%s %d\n",datestr,cls[i].cnt); |
225 | snprintf(buf,sizeof(buf),"%s %d\n",datestr,cls[i].cnt); |