Annotation of capa/capa51/GUITools/manager.funct.c, revision 1.4

1.4     ! albertel    1: /* C interfaces to CAPA for manager
        !             2:    Copyright (C) 1992-2000 Michigan State University
        !             3: 
        !             4:    The CAPA system is free software; you can redistribute it and/or
        !             5:    modify it under the terms of the GNU Library General Public License as
        !             6:    published by the Free Software Foundation; either version 2 of the
        !             7:    License, or (at your option) any later version.
        !             8: 
        !             9:    The CAPA system is distributed in the hope that it will be useful,
        !            10:    but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            11:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
        !            12:    Library General Public License for more details.
        !            13: 
        !            14:    You should have received a copy of the GNU Library General Public
        !            15:    License along with the CAPA system; see the file COPYING.  If not,
        !            16:    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
        !            17:    Boston, MA 02111-1307, USA.
        !            18: 
        !            19:    As a special exception, you have permission to link this program
        !            20:    with the TtH/TtM library and distribute executables, as long as you
        !            21:    follow the requirements of the GNU GPL in regard to all of the
        !            22:    software in the executable aside from TtH/TtM.
        !            23: */
        !            24: 
1.2       albertel   25: /*
1.4     ! albertel   26:  * manager.funct.c
        !            27:  * Guy Albertelli II 1996-1999
1.2       albertel   28:  */
                     29: #include <stdio.h>
                     30: #include <tk.h>
                     31: #include <Capa/capaCommon.h>
                     32: #include <manager.h>
                     33: 
                     34: int capaCTcreateSummary (ClientData clientdata, Tcl_Interp *interp, int argc, char *argv[])
                     35: {    
                     36:   int          section, set;
                     37:   int          studentCount,currentStudent;
                     38:   int          setScores, termScores, validScores, termValids;
                     39:   int          setIndex, maxSet=0;
                     40:   int          whatSection;
                     41:   char         fmt[64];
                     42:   char         grades[4], sectionChar[4], *answersPtr, buf[BUFFER_SIZE], *who,*which,*sortOne,*sortTwo;
                     43:   T_student   *studentPtr, *currentStudentPtr;
                     44:   FILE        *outputFile;
                     45: 
                     46:       sprintf(buf,"summary.section.%s",argv[2]);
                     47:   section = atoi(Tcl_GetVar2(interp,"gCT",buf,TCL_GLOBAL_ONLY));
                     48:       sprintf(buf,"summary.set.%s",argv[2]);
                     49:   set = atoi(Tcl_GetVar2(interp,"gCT",buf,TCL_GLOBAL_ONLY)); 
                     50:       sprintf(buf,"summary.who.%s",argv[2]);
                     51:   who=Tcl_GetVar2(interp,"gCT",buf,TCL_GLOBAL_ONLY);
                     52:       sprintf(buf,"summary.which.%s",argv[2]);
                     53:   which=Tcl_GetVar2(interp,"gCT",buf,TCL_GLOBAL_ONLY);
                     54:       sprintf(buf,"summary.first.%s",argv[2]);
                     55:   sortOne=Tcl_GetVar2(interp,"gCT",buf,TCL_GLOBAL_ONLY);
                     56:       sprintf(buf,"summary.second.%s",argv[2]);
                     57:   sortTwo=Tcl_GetVar2(interp,"gCT",buf,TCL_GLOBAL_ONLY);
1.3       albertel   58:   maxSet=howManySetDBFile();
1.2       albertel   59:   if (((strcmp(which,"upto") == 0) && ((set <= 0) || (set >= NUM_SET_LIMIT))) || (set > maxSet)) {
                     60:     sprintf(buf,"displayError \"The set number (%d) doesn't exist.\"",set);
                     61:     Tcl_Eval(interp,buf);
                     62:     Tcl_ResetResult(interp);
                     63:     Tcl_AppendResult(interp,"Error",NULL);
                     64:     return TCL_ERROR;
                     65:   }
                     66:   outputFile=fopen(argv[1],"w");
                     67:   if ( strcmp(who,"all") == 0 ) {
                     68:     whatSection = GET_ALL_SECTIONS;
                     69:   } else {
                     70:     whatSection = section;
                     71:   }
                     72:   studentCount = capa_get_section(&studentPtr, whatSection);
                     73: 
                     74:   sprintf(buf,"updateStatusMessage \"Creating primary sort key\" %s",argv[2]);
                     75:   if (Tcl_Eval(interp,buf) != TCL_OK) {
                     76:     free_students(studentPtr);
                     77:     fclose(outputFile);
                     78:     return TCL_ERROR;
                     79:   }
                     80: 
                     81:   if( studentCount > 0 ) {
                     82:     switch (sortOne[1]) 
                     83:       {
                     84:       case 'a': /*BY_NAME*/   
                     85: 	for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
                     86: 	    currentStudentPtr=currentStudentPtr->s_next,currentStudent++)  {
                     87: 	  sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
                     88: 		  argv[2]);
                     89: 	  Tcl_Eval(interp,buf);
                     90: 	  sprintf(currentStudentPtr->s_key,"%s",currentStudentPtr->s_nm);
                     91: 	}
                     92: 	break;
                     93:       case 'u': /*BY_NUMBER*/  
                     94: 	for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
                     95: 	    currentStudentPtr=currentStudentPtr->s_next,currentStudent++)  {
                     96: 	  sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
                     97: 		  argv[2]);
                     98: 	  Tcl_Eval(interp,buf);
                     99: 	  sprintf(currentStudentPtr->s_key,"%s",currentStudentPtr->s_sn);
                    100: 	}
                    101: 	break;
                    102:       case 'e': /*BY_SECTION*/ 
                    103: 	for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
                    104: 	    currentStudentPtr=currentStudentPtr->s_next,currentStudent++)  {
                    105: 	  sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
                    106: 		  argv[2]);
                    107: 	  Tcl_Eval(interp,buf);
                    108: 	  sprintf(currentStudentPtr->s_key,"%03d",currentStudentPtr->s_sec);
                    109: 	}
                    110: 	break;
                    111:       case 'r': /*BY_GRADE*/
                    112: 	if(strcmp(which,"specific") == 0 ) {
                    113: 	  for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
                    114: 	      currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
                    115: 	   sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
                    116: 		  argv[2]);
                    117: 	    Tcl_Eval(interp,buf);
                    118: 	    if( (setScores = capa_get_score(currentStudentPtr->s_sn,set,
                    119: 					    &validScores,&answersPtr)) == -2 ) 
                    120: 	      break;
                    121: 	    if( setScores < 0 ) {
                    122: 	      sprintf(currentStudentPtr->s_key,"-");
                    123: 	    } else {
                    124: 	      sprintf(currentStudentPtr->s_key,"%03d",setScores);
                    125: 	    }
                    126: 	    capa_mfree(answersPtr);
                    127: 	  } 
                    128: 	} else {
                    129: 	  for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
                    130: 	      currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
                    131: 	   sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
                    132: 		  argv[2]);
                    133: 	    Tcl_Eval(interp,buf);
                    134: 	    for(termScores=0, termValids=0, setIndex=1; setIndex <= set; setIndex++) {
                    135: 	      if( (setScores = capa_get_score(currentStudentPtr->s_sn,setIndex,
                    136: 					      &validScores,&answersPtr)) >= 0 ) {
                    137: 		termScores += setScores;
                    138: 	      }
                    139: 	      capa_mfree(answersPtr);
                    140: 	      termValids += validScores; 
                    141: 	    }
                    142: 	    sprintf(currentStudentPtr->s_key,"%03d",termScores);
                    143: 	  }
                    144: 	}
                    145: 	break;
                    146:       }
                    147: 
                    148:     sprintf(buf,"updateStatusMessage \"Creating secondary sort key\" %s",argv[2]);
                    149:     if (Tcl_Eval(interp,buf) != TCL_OK) {
                    150:       free_students(studentPtr);
                    151:       fclose(outputFile);
                    152:       return TCL_ERROR;
                    153:     }
                    154:     switch (sortTwo[1]) 
                    155:       {
                    156:       case 'a':/*BY_NAME*/    
                    157: 	for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
                    158: 	    currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
                    159: 	  sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
                    160: 		  argv[2]);
                    161: 	  Tcl_Eval(interp,buf);
                    162: 	  strcat(currentStudentPtr->s_key,currentStudentPtr->s_nm);
                    163: 	}
                    164: 	break;
                    165:       case 'u':/*BY_NUMBER*/  
                    166: 	for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
                    167: 	    currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
                    168: 	  sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
                    169: 		  argv[2]);
                    170: 	  Tcl_Eval(interp,buf);
                    171: 	  strcat(currentStudentPtr->s_key,currentStudentPtr->s_sn);
                    172: 	}
                    173: 	break;
                    174:       case 'e':/*BY_SECTION*/ 
                    175: 	for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
                    176: 	    currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
                    177: 	  sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
                    178: 		  argv[2]);
                    179: 	  Tcl_Eval(interp,buf);
                    180: 	  sprintf(sectionChar,"%03d",currentStudentPtr->s_sec); 
                    181: 	  strcat(currentStudentPtr->s_key,sectionChar);
                    182: 	}
                    183: 	break;
                    184:       case 'r':/*BY_GRADE*/
                    185: 	if(strcmp(which,"specific") == 0 ) {
                    186: 	  for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
                    187: 	      currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
                    188: 	   sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
                    189: 		  argv[2]);
                    190: 	    Tcl_Eval(interp,buf);
                    191: 	    if( (setScores = capa_get_score(currentStudentPtr->s_sn,set,&validScores,
                    192: 					    &answersPtr) ) == -2 ) {
                    193: 	      break;
                    194: 	    }
                    195: 	    if( setScores < 0 ) {
                    196: 	      strcat(currentStudentPtr->s_key,"-");
                    197: 	    } else {
                    198: 	      sprintf(grades,"%03d",setScores);
                    199: 	      strcat(currentStudentPtr->s_key,grades);
                    200: 	    }
                    201: 	    capa_mfree(answersPtr);
                    202: 	  } 
                    203: 	} else {
                    204: 	  for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
                    205: 	      currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
                    206: 	   sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
                    207: 		  argv[2]);
                    208: 	    Tcl_Eval(interp,buf);
                    209: 	    for (termScores=0, termValids=0, setIndex=1;setIndex<=set;setIndex++) {
                    210: 	      if( (setScores = capa_get_score(currentStudentPtr->s_sn,setIndex,
                    211: 					      &validScores,&answersPtr) ) >= 0 ) {
                    212: 		termScores += setScores;
                    213: 	      }
                    214: 	      capa_mfree(answersPtr);
                    215: 	      termValids += validScores; 
                    216: 	    }
                    217: 	    sprintf(grades,"%03d",termScores);
                    218: 	    strcat(currentStudentPtr->s_key,grades);
                    219: 	  }
                    220: 	}
                    221: 	break;
                    222:       }
                    223:     sprintf(buf,"updateStatusMessage \"Sorting\" %s",argv[2]);
                    224:     if (Tcl_Eval(interp,buf) != TCL_OK) {
                    225:       free_students(studentPtr);
                    226:       fclose(outputFile);
                    227:       return TCL_ERROR;
                    228:     }
                    229:     msort_main(&studentPtr);
                    230:     Tcl_ResetResult(interp);
                    231:     
                    232:     sprintf(fmt,"%%-%ds\t%%-%ds %%2d\t", MAX_NAME_CHAR,MAX_STUDENT_NUMBER);
                    233:     sprintf(buf,"updateStatusMessage \"Creating Report\" %s",argv[2]);
                    234:     if (Tcl_Eval(interp,buf) != TCL_OK) {
                    235:       free_students(studentPtr);
                    236:       fclose(outputFile);
                    237:       return TCL_ERROR;
                    238:     }
                    239:     for(currentStudentPtr=studentPtr,currentStudent=1;currentStudentPtr;
                    240: 	currentStudentPtr=currentStudentPtr->s_next,currentStudent++) {
                    241:       
                    242:       sprintf(buf,"updateStatusBar %f %s",(float)currentStudent/(float)studentCount,
                    243: 	      argv[2]);
                    244:       Tcl_Eval(interp,buf);
                    245:       fprintf(outputFile,fmt,currentStudentPtr->s_nm,currentStudentPtr->s_sn,
                    246: 	      currentStudentPtr->s_sec);
                    247:       if( strcmp(which,"specific") == 0) {
                    248: 	setScores = 0; validScores = 0;
                    249: 	if( (setScores = capa_get_score(currentStudentPtr->s_sn,set,&validScores,&answersPtr) ) == -2 ) {
                    250: 	  break;
                    251: 	}
                    252: 	if( setScores < 0 ) {
                    253: 	  fprintf(outputFile, "  -\t%3d\n", validScores);
                    254: 	} else {
                    255: 	  fprintf(outputFile, "%3d\t%3d\n",setScores, validScores);
                    256: 	}
                    257: 	capa_mfree(answersPtr);
                    258:       } else {
                    259: 	for( setScores=0, validScores=0, termScores = 0, termValids = 0, setIndex = 1; 
                    260: 	     setIndex <= set; setIndex++) {
                    261: 	  if( (setScores = capa_get_score(currentStudentPtr->s_sn,setIndex,
                    262: 					  &validScores,&answersPtr) ) >= 0 ) {
                    263: 	    termScores += setScores;
                    264: 	  }
                    265: 	  capa_mfree(answersPtr);
                    266: 	  termValids += validScores;
                    267: 	  if( setScores >= 0 ) {
                    268: 	    fprintf(outputFile, "%3d ",setScores);
                    269: 	  } else {
                    270: 	    fprintf(outputFile, "  - ");
                    271: 	  }
                    272: 	}
                    273: 	fprintf(outputFile, "\t %3d\t%3d\n",termScores,termValids);
                    274:       }
                    275:     }
                    276:     free_students(studentPtr);
                    277:   }
                    278:   fclose(outputFile);
                    279:   return TCL_OK;
                    280: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>