Annotation of capa/capa51/GUITools/manager.funct.c, revision 1.3
1.2 albertel 1: /*
2: * grader.funct.c
3: * Copyright Guy Albertelli II 1996-1999
4: * Portions Copyright Issac Tsai
5: */
6: #include <stdio.h>
7: #include <tk.h>
8: #include <Capa/capaCommon.h>
9: #include <manager.h>
10:
11: int capaCTcreateSummary (ClientData clientdata, Tcl_Interp *interp, int argc, char *argv[])
12: {
13: int section, set;
14: int studentCount,currentStudent;
15: int setScores, termScores, validScores, termValids;
16: int setIndex, maxSet=0;
17: int whatSection;
18: char fmt[64];
19: char grades[4], sectionChar[4], *answersPtr, buf[BUFFER_SIZE], *who,*which,*sortOne,*sortTwo;
20: T_student *studentPtr, *currentStudentPtr;
21: FILE *outputFile;
22:
23: sprintf(buf,"summary.section.%s",argv[2]);
24: section = atoi(Tcl_GetVar2(interp,"gCT",buf,TCL_GLOBAL_ONLY));
25: sprintf(buf,"summary.set.%s",argv[2]);
26: set = atoi(Tcl_GetVar2(interp,"gCT",buf,TCL_GLOBAL_ONLY));
27: sprintf(buf,"summary.who.%s",argv[2]);
28: who=Tcl_GetVar2(interp,"gCT",buf,TCL_GLOBAL_ONLY);
29: sprintf(buf,"summary.which.%s",argv[2]);
30: which=Tcl_GetVar2(interp,"gCT",buf,TCL_GLOBAL_ONLY);
31: sprintf(buf,"summary.first.%s",argv[2]);
32: sortOne=Tcl_GetVar2(interp,"gCT",buf,TCL_GLOBAL_ONLY);
33: sprintf(buf,"summary.second.%s",argv[2]);
34: sortTwo=Tcl_GetVar2(interp,"gCT",buf,TCL_GLOBAL_ONLY);
1.3 ! albertel 35: maxSet=howManySetDBFile();
1.2 albertel 36: if (((strcmp(which,"upto") == 0) && ((set <= 0) || (set >= NUM_SET_LIMIT))) || (set > maxSet)) {
37: sprintf(buf,"displayError \"The set number (%d) doesn't exist.\"",set);
38: Tcl_Eval(interp,buf);
39: Tcl_ResetResult(interp);
40: Tcl_AppendResult(interp,"Error",NULL);
41: return TCL_ERROR;
42: }
43: outputFile=fopen(argv[1],"w");
44: if ( strcmp(who,"all") == 0 ) {
45: whatSection = GET_ALL_SECTIONS;
46: } else {
47: whatSection = section;
48: }
49: studentCount = capa_get_section(&studentPtr, whatSection);
50:
51: sprintf(buf,"updateStatusMessage \"Creating primary sort key\" %s",argv[2]);
52: if (Tcl_Eval(interp,buf) != TCL_OK) {
53: free_students(studentPtr);
54: fclose(outputFile);
55: return TCL_ERROR;
56: }
57:
58: if( studentCount > 0 ) {
59: switch (sortOne[1])
60: {
61: case 'a': /*BY_NAME*/
62: for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
63: currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
64: sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
65: argv[2]);
66: Tcl_Eval(interp,buf);
67: sprintf(currentStudentPtr->s_key,"%s",currentStudentPtr->s_nm);
68: }
69: break;
70: case 'u': /*BY_NUMBER*/
71: for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
72: currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
73: sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
74: argv[2]);
75: Tcl_Eval(interp,buf);
76: sprintf(currentStudentPtr->s_key,"%s",currentStudentPtr->s_sn);
77: }
78: break;
79: case 'e': /*BY_SECTION*/
80: for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
81: currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
82: sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
83: argv[2]);
84: Tcl_Eval(interp,buf);
85: sprintf(currentStudentPtr->s_key,"%03d",currentStudentPtr->s_sec);
86: }
87: break;
88: case 'r': /*BY_GRADE*/
89: if(strcmp(which,"specific") == 0 ) {
90: for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
91: currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
92: sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
93: argv[2]);
94: Tcl_Eval(interp,buf);
95: if( (setScores = capa_get_score(currentStudentPtr->s_sn,set,
96: &validScores,&answersPtr)) == -2 )
97: break;
98: if( setScores < 0 ) {
99: sprintf(currentStudentPtr->s_key,"-");
100: } else {
101: sprintf(currentStudentPtr->s_key,"%03d",setScores);
102: }
103: capa_mfree(answersPtr);
104: }
105: } else {
106: for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
107: currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
108: sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
109: argv[2]);
110: Tcl_Eval(interp,buf);
111: for(termScores=0, termValids=0, setIndex=1; setIndex <= set; setIndex++) {
112: if( (setScores = capa_get_score(currentStudentPtr->s_sn,setIndex,
113: &validScores,&answersPtr)) >= 0 ) {
114: termScores += setScores;
115: }
116: capa_mfree(answersPtr);
117: termValids += validScores;
118: }
119: sprintf(currentStudentPtr->s_key,"%03d",termScores);
120: }
121: }
122: break;
123: }
124:
125: sprintf(buf,"updateStatusMessage \"Creating secondary sort key\" %s",argv[2]);
126: if (Tcl_Eval(interp,buf) != TCL_OK) {
127: free_students(studentPtr);
128: fclose(outputFile);
129: return TCL_ERROR;
130: }
131: switch (sortTwo[1])
132: {
133: case 'a':/*BY_NAME*/
134: for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
135: currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
136: sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
137: argv[2]);
138: Tcl_Eval(interp,buf);
139: strcat(currentStudentPtr->s_key,currentStudentPtr->s_nm);
140: }
141: break;
142: case 'u':/*BY_NUMBER*/
143: for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
144: currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
145: sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
146: argv[2]);
147: Tcl_Eval(interp,buf);
148: strcat(currentStudentPtr->s_key,currentStudentPtr->s_sn);
149: }
150: break;
151: case 'e':/*BY_SECTION*/
152: for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
153: currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
154: sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
155: argv[2]);
156: Tcl_Eval(interp,buf);
157: sprintf(sectionChar,"%03d",currentStudentPtr->s_sec);
158: strcat(currentStudentPtr->s_key,sectionChar);
159: }
160: break;
161: case 'r':/*BY_GRADE*/
162: if(strcmp(which,"specific") == 0 ) {
163: for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
164: currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
165: sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
166: argv[2]);
167: Tcl_Eval(interp,buf);
168: if( (setScores = capa_get_score(currentStudentPtr->s_sn,set,&validScores,
169: &answersPtr) ) == -2 ) {
170: break;
171: }
172: if( setScores < 0 ) {
173: strcat(currentStudentPtr->s_key,"-");
174: } else {
175: sprintf(grades,"%03d",setScores);
176: strcat(currentStudentPtr->s_key,grades);
177: }
178: capa_mfree(answersPtr);
179: }
180: } else {
181: for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
182: currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
183: sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
184: argv[2]);
185: Tcl_Eval(interp,buf);
186: for (termScores=0, termValids=0, setIndex=1;setIndex<=set;setIndex++) {
187: if( (setScores = capa_get_score(currentStudentPtr->s_sn,setIndex,
188: &validScores,&answersPtr) ) >= 0 ) {
189: termScores += setScores;
190: }
191: capa_mfree(answersPtr);
192: termValids += validScores;
193: }
194: sprintf(grades,"%03d",termScores);
195: strcat(currentStudentPtr->s_key,grades);
196: }
197: }
198: break;
199: }
200: sprintf(buf,"updateStatusMessage \"Sorting\" %s",argv[2]);
201: if (Tcl_Eval(interp,buf) != TCL_OK) {
202: free_students(studentPtr);
203: fclose(outputFile);
204: return TCL_ERROR;
205: }
206: msort_main(&studentPtr);
207: Tcl_ResetResult(interp);
208:
209: sprintf(fmt,"%%-%ds\t%%-%ds %%2d\t", MAX_NAME_CHAR,MAX_STUDENT_NUMBER);
210: sprintf(buf,"updateStatusMessage \"Creating Report\" %s",argv[2]);
211: if (Tcl_Eval(interp,buf) != TCL_OK) {
212: free_students(studentPtr);
213: fclose(outputFile);
214: return TCL_ERROR;
215: }
216: for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
217: currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
218:
219: sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
220: argv[2]);
221: Tcl_Eval(interp,buf);
222: fprintf(outputFile,fmt,currentStudentPtr->s_nm,currentStudentPtr->s_sn,
223: currentStudentPtr->s_sec);
224: if( strcmp(which,"specific") == 0) {
225: setScores = 0; validScores = 0;
226: if( (setScores = capa_get_score(currentStudentPtr->s_sn,set,&validScores,&answersPtr) ) == -2 ) {
227: break;
228: }
229: if( setScores < 0 ) {
230: fprintf(outputFile, " -\t%3d\n", validScores);
231: } else {
232: fprintf(outputFile, "%3d\t%3d\n",setScores, validScores);
233: }
234: capa_mfree(answersPtr);
235: } else {
236: for( setScores=0, validScores=0, termScores = 0, termValids = 0, setIndex = 1;
237: setIndex <= set; setIndex++) {
238: if( (setScores = capa_get_score(currentStudentPtr->s_sn,setIndex,
239: &validScores,&answersPtr) ) >= 0 ) {
240: termScores += setScores;
241: }
242: capa_mfree(answersPtr);
243: termValids += validScores;
244: if( setScores >= 0 ) {
245: fprintf(outputFile, "%3d ",setScores);
246: } else {
247: fprintf(outputFile, " - ");
248: }
249: }
250: fprintf(outputFile, "\t %3d\t%3d\n",termScores,termValids);
251: }
252: }
253: free_students(studentPtr);
254: }
255: fclose(outputFile);
256: return TCL_OK;
257: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>