Subversion Repositories wimsdev

Rev

Rev 12224 | Rev 12276 | 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. /* Routines treating user scores. */
  19. #include "wims.h"
  20.  
  21. double oldfactor=0.85;     /* quality factor, should remain stable. */
  22.  
  23. enum {sr_require, sr_weight, sr_score, sr_mean, sr_remain,
  24.   sr_last, sr_try, sr_best, sr_level, sr_new};
  25. char scorebuf[MAX_CLASSEXOS*sizeof(scoreresult)+32];
  26. struct scoreresult *rscore;
  27. int scorecnt;
  28. double scoresum[MAX_SHEETS];
  29. int sheetstart[MAX_SHEETS], shexocnt[MAX_SHEETS];
  30. int examstart, examcnt;
  31. char rscore_class[MAX_CLASSLEN+1];
  32. char rscore_user[MAX_NAMELEN+1];
  33.  
  34. int totsheets=0;
  35. int score_ispublic=0;
  36. int score_status=-1;          /* save of score status */
  37. int score_statussheet=-1;
  38. int score_statusisexam=-1;
  39. double scorerecfactor=0.9;
  40.  
  41. /* gather user score, core routine.
  42.   rscore data is created (table of structures).
  43.   according to the value of wims_sheet or wims_exo
  44. */
  45. int getscoreuser(char *classe, char *user)
  46. {
  47.   int i, j, osh, sh;
  48.   double s;
  49.   char *nowuser, *nowsheet, *nowexo, *nowscore;
  50.   char *pp;
  51.   if(user==NULL || *user==0) {
  52.     user=getvar("wims_user");
  53.     if(user==NULL || *user==0) return -1;
  54.   }
  55.   if(strcmp(classe,rscore_class)==0 && strcmp(user,rscore_user)==0) return 0;
  56.   nowsheet=nowexo=nowscore="";
  57.   nowuser=getvar("wims_user"); if(nowuser!=NULL && strcmp(user,nowuser)==0) {
  58.     nowscore=getvar("module_score");
  59.     if(nowscore!=NULL && *nowscore!=0) {
  60.       nowsheet=getvar("wims_sheet");
  61.       if(nowsheet==NULL) nowsheet="";
  62.       nowexo=getvar("wims_exo");
  63.       if(nowexo==NULL) nowexo="";
  64.     }
  65.     else nowscore="";
  66.   }
  67.   snprintf(scorebuf+sizeof(int),sizeof(scorebuf)-sizeof(int),
  68.        "-c%s -u%s getscore %s %s %s",
  69.        classe,user,nowsheet,nowexo,nowscore);
  70.   i=kerneld(scorebuf,sizeof(scorebuf));
  71.   if(i<0)  internal_error("getscoreuser(): daemon failure.");
  72.   if(memcmp(scorebuf+sizeof(int),"OK",2)!=0) {
  73.     if(memcmp(scorebuf+sizeof(int),"ERROR",5)==0) {
  74.       module_error(find_word_start(scorebuf+sizeof(int)+8));
  75.     }
  76.     else internal_error("getscoreuser(): communication error with wimslogd.");
  77.   }
  78. /* 3 is here the length of "OK " */
  79.   pp=scorebuf+sizeof(int)+3; rscore=(struct scoreresult *) pp;
  80.   scorecnt=(i-sizeof(int)-3)/sizeof(scoreresult);
  81.   if(scorecnt>MAX_CLASSEXOS) module_error("too_many_exercises");
  82.   s=0; for(i=osh=0;i<scorecnt;i++) {
  83.     sh=(rscore[i].num>>8)+1;
  84.     if(sh<1 || sh>MAX_SHEETS) break;
  85.     if(osh>0 && osh<sh) {scoresum[osh-1]=s; s=0;}
  86.     for(;osh<sh && osh<MAX_SHEETS;osh++) sheetstart[osh]=i;
  87.     s+=rscore[i].require*rscore[i].weight;
  88.   }
  89.   if(osh>0) scoresum[osh-1]=s;
  90.   totsheets=osh;
  91.   for(j=0;j<totsheets-1;j++) shexocnt[j]=sheetstart[j+1]-sheetstart[j];
  92.   shexocnt[totsheets-1]=i-sheetstart[totsheets-1];
  93.   examstart=i; examcnt=scorecnt-examstart;
  94.   mystrncpy(rscore_class,classe,sizeof(rscore_class));
  95.   mystrncpy(rscore_user,user,sizeof(rscore_user));
  96.   return 0;
  97. }
  98. /* work : exo */
  99. char *scorepname[]={
  100.   "class","user","sheet","work","exam"
  101. };
  102. #define scorepname_no (sizeof(scorepname)/sizeof(scorepname[0]))
  103. char score_class[MAX_CLASSLEN+1];
  104. int score_sheet,score_exo,score_isexam;
  105. char score_user[256];
  106.  
  107. /* Uniformed treatment of score command parameters
  108.  * format: class=? user=? sheet=? work=?
  109.  * all are optional.
  110.  */
  111. void _scoreparm(char *p)
  112. {
  113.     int i;
  114.     char *pn, *pe, *pd, *pf;
  115.     char sav;
  116.  
  117.     score_sheet=score_exo=score_isexam=score_ispublic=0; *score_class=0;
  118.     score_user[0]=0;
  119.     for(i=0;i<scorepname_no;i++) {
  120.      pf=p;
  121.      ahead:
  122.      pn=strstr(pf,scorepname[i]); pf=pn+1;
  123.      if(pn==NULL) continue;
  124.      if(pn>p && !isspace(*(pn-1))) goto ahead;
  125.      pe=find_word_start(pn+strlen(scorepname[i]));
  126.      if(*pe!='=') goto ahead;
  127.      pd=find_word_start(pe+1);
  128.      pf=find_word_end(pd);
  129.      if(pf<=pd) continue;
  130.      sav=*pf; *pf=0;
  131.      switch(i) {
  132.          case 0: /* class */
  133.            mystrncpy(score_class,pd,sizeof(score_class)); break;
  134.          case 1: /* user */
  135.            mystrncpy(score_user,pd,sizeof(score_user)); break;
  136.          case 2: { /* sheet */
  137.           if(*pd=='P') {pd++; score_ispublic=1;}
  138.           score_sheet=atoi(pd);
  139.           break;
  140.          }
  141.          case 3: /* work=exo */
  142.            score_exo=atoi(pd); break;
  143.          case 4: /* exam */
  144.            score_isexam=1; break;
  145.      }
  146.      *pf=sav; ovlstrcpy(pn, pf);
  147.     }
  148.     *p=0;
  149.     if((*score_class!=0 || score_user[0]!=0) && !trusted_module()) {
  150.      module_error("not_trusted"); return;
  151.     }
  152.     if(*score_class==0) {
  153.      char *classe;
  154.      classe=getvar("wims_class");
  155.      if(classe==NULL || *classe==0) return;
  156.      else mystrncpy(score_class,classe,sizeof(score_class));
  157.     }
  158.     if(score_user[0]==0) {
  159.      char *user;
  160.      user=getvar("wims_user");
  161.      if(user!=NULL) mystrncpy(score_user,user,sizeof(score_user));
  162.     }
  163. }
  164.  
  165. /* gather score: relatif to some of the
  166.  *  user class work sheet exam
  167.  *  dtype can be require weight score mean remain best last level try
  168.  */
  169.  
  170. void _getscore(char *p,int dtype)
  171. {
  172.   int i,sh,ex,osh;
  173.   float d;
  174.   char *p1;
  175.  
  176.   _scoreparm(p);
  177.   if(*score_class==0 || *score_user==0) return;
  178.   if(getscoreuser(score_class,score_user)<0) return;
  179. /*  2^8 no_sheet + no_exo_in_the_sheet so limit no_exo to 2^8 */
  180.   for(i=osh=0,p1=p;i<scorecnt && p1-p<MAX_LINELEN-32;i++) {
  181.     sh=(rscore[i].num>>8)+1; if(sh<1 || sh>MAX_SHEETS) break;
  182.     if(score_sheet!=0) {
  183.       if(sh<score_sheet) continue;
  184.       if(sh>score_sheet || sh>MAX_SHEETS) break;
  185.     }
  186.     ex=((rscore[i].num)&255)+1;
  187.     if(score_exo!=0 && ex!=score_exo) continue;
  188.     if(osh!=0 && sh!=osh) *p1++='\n';
  189.     switch(dtype) {
  190.       case sr_require: {d=rscore[i].require; break;}
  191.       case sr_weight: {d=rscore[i].weight; break;}
  192.       case sr_score: {d=rscore[i].score; break;}
  193.       case sr_mean: {d=rscore[i].mean; break;}
  194.       case sr_remain: {d=rscore[i].require-rscore[i].score; break;}
  195.       case sr_last: {d=rscore[i].last; break;}
  196.       case sr_try: {d=rscore[i].try; break;}
  197.       case sr_new: {d=rscore[i].new; break;}
  198.       case sr_best: {d=rscore[i].best; break;}
  199.       case sr_level: {d=rscore[i].level ;break;}
  200.       default: {d=0; break;}
  201.     }
  202.      p1=moneyprint(p1,d); *p1++=' ';
  203.     osh=sh;
  204.   }
  205.   *p1++='\n'; *p1=0;
  206. }
  207.  
  208. /* gather user score. */
  209. void calc_getscore(char *p)
  210. {
  211.   _getscore(p,sr_score);
  212. }
  213.  
  214. /* gather user score average. */
  215. void calc_getscoremean(char *p)
  216. {
  217.   _getscore(p,sr_mean);
  218. }
  219.  
  220. /* gather remaining of score to get for user. */
  221. void calc_getscoreremain(char *p)
  222. {
  223.   _getscore(p,sr_remain);
  224. }
  225.  
  226. /* Require score table. */
  227. void calc_getscorerequire(char *p)
  228. {
  229.   _getscore(p,sr_require);
  230. }
  231.  
  232. /* Score weight table. */
  233. void calc_getscoreweight(char *p)
  234. {
  235.   _getscore(p,sr_weight);
  236. }
  237. /* user last score*/
  238. void calc_getscorelast(char *p)
  239. {
  240.   _getscore(p,sr_last);
  241. }
  242. /* gather user score try numbers with score activated. */
  243. void calc_getscoretry(char *p)
  244. {
  245.   _getscore(p,sr_try);
  246. }
  247. /* gather all user try numbers (terminated or not, but with notation activated)*/
  248. void calc_getscorealltries(char *p)
  249. {
  250.   _getscore(p,sr_new);
  251. }
  252.  
  253. /* if the required points are 10* N, gather N user best scores */
  254. void calc_getscorebest(char *p)
  255. {
  256.   _getscore(p,sr_best);
  257. }
  258.  
  259. /* gather user score average. */
  260. void calc_getscorelevel(char *p)
  261. {
  262.   _getscore(p,sr_level);
  263. }
  264.  
  265. /* percentage of work done for each sheet:
  266.  * score mean best level
  267.  * as follows
  268.  * score=100*cumulative_points/required_points) (< 100)
  269.  * mean=quality (<10)
  270.  * best=10*(required/10 best_scores)/required_points (< 100)
  271.  * level=minimum of the required/10 best_scores (< 10)
  272.  */
  273.  
  274.  void calc_getscorepercent(char *p)
  275. {
  276.   int i,j,jend;
  277.   double tot, mean, totb, totl, totw, d;
  278.   char *p1;
  279.  
  280.   _scoreparm(p);
  281.   if(*score_class==0 || *score_user==0) return;
  282.   if(getscoreuser(score_class,score_user)<0) return;
  283.   for(p1=p,i=0;i<totsheets && p1-p<MAX_LINELEN-32;i++) {
  284.     if(scoresum[i]==0) {
  285.       ovlstrcpy(p1,"0 0 0 0\n"); p1+=strlen(p1); continue;
  286.     }
  287.     if(score_sheet!=0 && i!=score_sheet-1) continue;
  288.     if(scoresum[i]<=0) *p1++='\n';
  289.     tot=mean=totb=totl=totw=0; jend=sheetstart[i]+shexocnt[i];
  290.     for(j=sheetstart[i];j<jend;j++) {
  291. /* if mean<1 then ignore score.
  292.  * if mean<2 then half score.
  293.  */
  294.       if(rscore[j].mean>=1) {
  295.         double dt=rscore[j].score;
  296.         float db=rscore[j].best;
  297.         float dl=rscore[j].level;
  298.         if(rscore[j].mean<2) {dt=dt/2; db=db/2; dl=dl/2;}
  299.         d=dt*rscore[j].weight;
  300. /* quality */
  301.         mean+=rscore[j].mean*d;
  302. /* cumulative score */
  303.         tot+=d;
  304. /* best */
  305.         totb+=db*rscore[j].weight;
  306. /* level */
  307.         totl+=dl*rscore[j].weight;
  308.         totw+=rscore[j].weight;
  309.       }
  310.     }
  311.     if(tot>0) {d=mean/tot;} else d=0;
  312. /* cumulative score */
  313.     p1=moneyprint(p1,rint(100*tot/scoresum[i])); *p1++=' ';
  314. /* quality */
  315.     p1=moneyprint(p1,d); *p1++=' ';
  316. /* best */
  317.     p1=moneyprint(p1,rint(100*totb/scoresum[i])); *p1++=' ';
  318. /* level */
  319.     p1=moneyprint(p1,rint(10*totl/totw));
  320.  
  321.    *p1++='\n';
  322.   }
  323.   *p1=0;
  324. }
  325.  
  326. /* Returns the status of a sheet, or -1 if error */
  327. int getsheetstatus(char *classe, int sheet)
  328. {
  329.   char *p, *st, buf[MAX_LINELEN+1], namebuf[MAX_FNAME+1];
  330.   int i;
  331.  
  332.   if(isexam || score_isexam) st="exam"; else st="sheet";
  333.   mkfname(namebuf,"%s/%s/%ss/.%ss",class_base,classe,st,st);
  334.   direct_datafile=1;datafile_fnd_record(namebuf,sheet,buf);direct_datafile=0;
  335.   p=find_word_start(buf); if(*p==0) return -1;
  336.   i=*p-'0'; if(i>5 || i<0) i=-1;
  337.   if((isexam || score_isexam) && i==0) {
  338.     p=getvar("wims_user"); if(p!=NULL && strcmp(p,"supervisor")==0) i=1;
  339.   }
  340.   return i;
  341. }
  342.  
  343. /* return 1 if a word of bf2 is a substring of host.
  344.  * Content of bf2 is destroyed.
  345.  */
  346. int _subword(char bf2[],char *ftbuf)
  347. {
  348.   char *p1, *p2;
  349.   for(p1=strchr(bf2,'\\'); p1!=NULL; p1=strchr(p1+1,'\\')) {
  350.     char buf[MAX_LINELEN+1], buf2[MAX_LINELEN+1], fbuf[MAX_FNAME+1];
  351.     char *classp, *classp2, *userp, *scp;
  352.     classp=getvar("wims_class"); userp=getvar("wims_user");
  353.     if(classp==NULL || userp==NULL || *classp==0 || *userp==0) break;
  354.     scp=getvar("wims_superclass");
  355.     if(scp!=NULL && *scp!=0) classp2=scp; else classp2=classp;
  356.     if(p1>bf2 && !isspace(*(p1-1))) continue;
  357.     if(!isalnum(*(p1+1))) continue;
  358.     p2=find_word_end(p1); if(p2>=p1+MAX_NAMELEN) continue;
  359.     memmove(buf2, p1+1, p2-p1-1); buf2[p2-p1-1]=0;
  360.     /* get value of technical variable */
  361.     snprintf(buf,sizeof(buf),"user_techvar_%s",buf2);
  362.     if(strcmp(userp,"supervisor")==0)
  363.       mkfname(fbuf,"%s/%s/supervisor",class_base,classp);
  364.     else
  365.       mkfname(fbuf,"%s/%s/.users/%s",class_base,classp2,userp);
  366.     getdef(fbuf,buf,buf2);
  367.     if(buf2[0]==0) ovlstrcpy(buf2,"EMPTY"); /* in case of no value defined for the user*/
  368.     /* get time restriction for this value */
  369.     snprintf(buf,sizeof(buf),"techvar_%s",buf2);
  370.     /*mkfname(fbuf,"%s/%s/.E%s",class_base,classp,sheet);*/
  371. /* read time restriction corresponding to the value of
  372.   technical variable in the file of the sheet or exam
  373.  */
  374.     getdef(ftbuf,buf,buf2);
  375.     if(buf2[0]==0) ovlstrcpy(buf2,"none");
  376.     /*string_modify(bf2,p1,p2,buf2);*/
  377.     bf2=buf2;
  378.     p1+=strlen(buf2);
  379.   }
  380.   if((isexam || score_isexam) && bf2[0]=='#') return 1;
  381.   if(wordchr(bf2,"none")!=NULL) return 0;
  382.   if(wordchr(bf2,"all")!=NULL) return 1;
  383.   p1=find_word_start(bf2); if(*p1==0) return 1;
  384.   return checkhostt(p1);
  385. }
  386.  
  387. /* Returns 1 if score registration is open, 0 otherwise. */
  388. int _getscorestatus(char *classe, int sheet)
  389. {
  390.   char nbuf[MAX_LINELEN+1], gbuf[MAX_LINELEN+1];
  391.   char ftbuf[MAX_FNAME+1]="";
  392.   char *es;
  393.  
  394.   if(classe==NULL || *classe==0 || sheet<=0) return 1;
  395.   if(getsheetstatus(classe,sheet)!=1) return 0;
  396.   if(*remote_addr==0) return 0;
  397.   if(isexam || score_isexam) {     /* exam simulation */
  398.     accessfile(nbuf,"r","%s/%s/.E%d",class_base,classe,sheet);
  399.     if(nbuf[0]=='#') return 1;
  400.   }
  401. /* Global restriction data */
  402.   accessfile(nbuf,"r","%s/%s/.security",class_base,classe);
  403.   if(nbuf[0]) {
  404.     _getdef(nbuf,"allow",gbuf);
  405.     if(*find_word_start(gbuf)!=0 && _subword(gbuf,ftbuf)==0)
  406.       return 0;
  407.     _getdef(nbuf,"except",gbuf);
  408.     if(*find_word_start(gbuf)!=0 && _subword(gbuf,ftbuf)==1)
  409.       return 0;
  410.   }
  411.  
  412. /* Sheet restriction data */
  413.   if(isexam || score_isexam) es="E"; else es="";
  414.   accessfile(nbuf,"r","%s/%s/.%s%d",class_base,classe,es,sheet);
  415.   if(*find_word_start(nbuf)==0) return 1;
  416. /* preparing score restriction file name :*/
  417.   mkfname(ftbuf,"%s/%s/.%s%d",class_base,classe,es,sheet);
  418.   return _subword(nbuf,ftbuf);
  419. }
  420.  
  421. /* Returns 1 if score registration is open, 0 otherwise. */
  422. int getscorestatus(char *classe, int sheet)
  423. {
  424.   if(score_status<0 || score_statussheet!=sheet
  425.      || score_statusisexam!=isexam) {
  426.     score_statussheet=sheet; score_statusisexam=isexam;
  427.     score_status=_getscorestatus(classe,sheet); score_isexam=0;
  428.     if(score_status==1 && (cmd_type==cmd_new || cmd_type==cmd_renew
  429.                || isexam)) {
  430.       char *p;
  431.       p=getvar("wims_scorereg");
  432.       if(p==NULL || strcmp(p,"suspend")!=0)
  433.          setvar("wims_scoring","pending");
  434.       else setvar("wims_scoring","");
  435.     }
  436.   }
  437.   if(isexam && score_status==0) {
  438.     char *p;
  439.     p=getvar("wims_user"); if(p==NULL || strcmp(p,"supervisor")!=0)
  440.                  user_error("exam_closed");
  441.   }
  442.   return score_status;
  443. }
  444.  
  445. /* Whether score registering is open */
  446. void calc_getscorestatus(char *p)
  447. {
  448.   _scoreparm(p);
  449.   if(*score_class==0 || score_sheet==0 || *score_user==0) {
  450.     *p=0; return;
  451.   }
  452.   if(getscorestatus(score_class, score_sheet))
  453.     ovlstrcpy(p,"yes");
  454.   else ovlstrcpy(p,"no");
  455. }
  456. /* whether there are too much tries for the exo is too much */
  457.  
  458. void calc_getscoremaxexotry(char *p)
  459. {
  460.   _scoreparm(p);
  461.   if(*score_class==0 || *score_user==0 || score_sheet==0 || score_exo==0) return;
  462.   if(gettrycheck(score_class, score_user, score_sheet, score_exo)==1)
  463.     ovlstrcpy(p,"yes");
  464.   else ovlstrcpy(p,"no");
  465. }
  466.  
  467. double exam_scoredata[MAX_EXOS];
  468.  
  469. /* get current exam score */
  470. void exam_currscore(int esh)
  471. {
  472.   char *p, *bf, pb[MAX_FNAME+1];
  473.   char *s, *p1, *p2, *e1, *e2;
  474.   int i;
  475.   for(i=0;i<MAX_EXOS;i++) exam_scoredata[i]=-1000;
  476. /* session_prefix is not yet defined here */
  477.   s=getvar("wims_session"); if(s==NULL || *s==0) return;
  478.   mystrncpy(pb,s,sizeof(pb));
  479.   p=strchr(pb,'_'); if(p!=NULL) *p=0;
  480.   bf=readfile(mkfname(NULL,"%s/%s/examscore.%d",session_dir,pb,esh),NULL,WORKFILE_LIMIT);
  481.   if(bf==NULL) return;
  482.   for(p1=bf;*p1;p1=p2) {
  483.     p2=strchr(p1,'\n'); if(*p2) *p2++=0;
  484.     else p2=p1+strlen(p1);
  485.     p1=find_word_start(find_word_end(find_word_start(p1)));
  486.     e1=find_word_end(p1); if(*e1) *e1++=0;
  487.     e1=find_word_start(e1); e2=find_word_start(find_word_end(e1));
  488.     *find_word_end(e1)=0;
  489.     i=atoi(p1);
  490.     if(i>=1 && i<=MAX_EXOS &&
  491.        exam_scoredata[i-1]==-1000 && strcmp(e1,"score")==0) {
  492.       *find_word_end(e2)=0;
  493.       exam_scoredata[i-1]=atof(e2);
  494.     }
  495.   }
  496.   free(bf);
  497. }
  498.  
  499. /* Gather exam score. */
  500. void calc_examscore(char *p)
  501. {
  502.   char *p1;
  503.   int i;
  504.   char *withoutip;
  505.  
  506.   _scoreparm(p); *p=0;
  507.   withoutip=getvar("wims_examscore_withoutip");
  508.  
  509.   if(*score_class==0 || *score_user==0) return;
  510.   if(getscoreuser(score_class,score_user)<0) return;
  511.   p1=p;
  512.   if(withoutip!=NULL && strcmp(withoutip,"yes")==0) {
  513.     for(i=0; i<examcnt && p1-p<MAX_LINELEN-32; i++) {
  514.     p1=moneyprint(p1,rscore[examstart+i].best); *p1++=' ';
  515.     }
  516.   } else {
  517.     for(i=0; i<examcnt && p1-p<MAX_LINELEN-32; i++) {
  518.       p1=moneyprint(p1,rscore[examstart+i].score); *p1++=' ';
  519.     }
  520.   }
  521.   *p1++='\n';
  522.   for(i=0; i<examcnt && p1-p<MAX_LINELEN-32; i++) {
  523.     p1=moneyprint(p1,rscore[examstart+i].require); *p1++=' ';
  524.     p1=moneyprint(p1,floor(rscore[examstart+i].mean/2)); *p1++=' ';
  525.     p1=moneyprint(p1,(int) rscore[examstart+i].mean%2); *p1++='\n';
  526.   }
  527.   *p1=0;
  528. }
  529.  
  530. /* check score dependency.
  531.  * returns 1 if requirements are met.
  532.  */
  533. int _depcheck(char *ds, struct scoreresult *rs, int ecnt)
  534. {
  535.   char *p1, *p2, *p3, *p4, *pp;
  536.   int perc, t, sum;
  537.   double tgot, ttot, tmean;
  538.  
  539.   for(p1=ds; *p1; p1=p3) {
  540.     p2=strchr(p1,':'); if(p2==NULL) break;
  541.     *p2++=0; p2=find_word_start(p2);
  542.     for(p3=p2; myisdigit(*p3); p3++);
  543.     if(p3<=p2) break;
  544.     *p3++=0; perc=atoi(p2);
  545.     if(perc<=0 || perc>100) break;
  546.     for(pp=p1; *pp; pp++) if(!myisdigit(*pp)) *pp=' ';
  547.     tgot=ttot=tmean=0; sum=0;
  548.     for(pp=find_word_start(p1); *pp; pp=find_word_start(p4)) {
  549.       p4=find_word_end(pp); if(*p4) *p4++=0;
  550.       t=atoi(pp); if(t<=0 || t>ecnt) goto lend;
  551.       t--;
  552.       ttot+=rs[t].require; tgot+=rs[t].score; tmean+=rs[t].mean;
  553.       sum++;
  554.     }
  555.     if(ttot<10) continue;
  556.     if(tgot/ttot*sqrt(tmean/(sum*10))*100<perc) {
  557.       for(pp=p1;pp<p2-1;pp++) if(!*pp) *pp=',';
  558.       *pp=0; setvar("dep_list",p1);
  559.       return 0;
  560.     }
  561.   lend: ;
  562.   }
  563.   return 1;
  564. }
  565.  
  566. int depcheck(char *sh, int exo, char *deps)
  567. {
  568.   char buf[MAX_LINELEN+1];
  569.   char *s, sbuf[64];
  570.   int i, is;
  571.  
  572.   s=getvar("wims_session");
  573.   if(s==NULL || *s==0 || strstr(s,"robot")!=NULL) return 0;
  574.   mystrncpy(sbuf,s,sizeof(sbuf));
  575.   s=strchr(sbuf,'_'); if(s) *s=0;
  576.   accessfile(buf,"r","../sessions/%s/exodep.%s",sbuf,sh);
  577.   if(buf[0]==0) {     /* no dep file found */
  578.     is=atoi(sh); if(is<=0 || is>totsheets) return 0;
  579.     s=getvar("wims_class"); if(s==NULL || *s==0) return 0;
  580.     getscoreuser(s,"");
  581.     return _depcheck(deps,rscore+sheetstart[is-1],shexocnt[is-1]);
  582.   }
  583.   for(i=1,s=strchr(buf,':'); s && i<exo; i++, s=strchr(s+1,':'));
  584.   if(s==NULL) return 0;     /* bad file or exo number */
  585.   if(myisdigit(*++s)) return 0; else return 1;
  586. }
  587.  
  588. int exam_depcheck(char *deps, int exam)
  589. {
  590.   struct scoreresult esc[MAX_EXOS];
  591.   int i;
  592.   exam_currscore(exam);
  593.   for(i=0;i<MAX_EXOS;i++) {
  594.     esc[i].require=esc[i].mean=10;
  595.     if(exam_scoredata[i]==-1000) esc[i].score=0;
  596.     else esc[i].score=exam_scoredata[i];
  597.   }
  598.   return _depcheck(deps,esc,MAX_EXOS);
  599. }
  600.  
  601. int gettrycheck(char *classe, char *user, int she, int exo) {
  602.   char *s;
  603.   int sh, ex, i;
  604.   if(strcmp(user,"supervisor")==0) return 0;
  605.   s=getvar("exotrymax");
  606.   if(s==NULL || *s==0) return 0;
  607.   getscoreuser(classe,user);
  608.   for(i=0;i<scorecnt;i++) {
  609.     sh=(rscore[i].num>>8)+1;
  610.     if (she!=sh) continue;
  611.     ex=((rscore[i].num)&255)+1;
  612.     if(exo!=ex) continue;
  613.     if(rscore[i].new > atoi(s)) return 1;
  614.   };
  615.   return 0;
  616. }
  617.