home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 11 / develop 11 code / The NetWork Project / Examples (Sources) / NetSim / statistics.impl.p < prev    next >
Encoding:
Text File  |  1992-07-15  |  2.6 KB  |  102 lines  |  [TEXT/MPS ]

  1. { statistics.impl.p     © Copyright G. Sawitzki, 1988-1991}
  2.  
  3.  
  4. procedure sResume;
  5. {reset time to resume sNoteResult after a user-controlled delay}
  6. begin
  7.     sLastTicks:=tickCount;
  8. end;
  9.  
  10.     {********* trying to clean up -- center statistics here. tag char is "s" *******}
  11. { For evaluation of mean and sum of deviation squares
  12.  this procedure executes one single iteration
  13.  obeying a provisional mean algorithm.
  14.  At "w" the actual value is expected,
  15.  at "stat" mean,SSQ and number of the preceding ones
  16.  according the statlab-convention.}
  17.  
  18. var DefineStat,CoreStat,UpdateStat:tStatType;
  19.     TotalTurnAroundStat:tStatType; {gross job turn around time}
  20.     LocalTurnAroundStat:tStatType; {local job turn around time}
  21. procedure initAllStats;
  22. begin
  23.     initStat(DefineStat,'define');
  24.     initStat(CoreStat,'core');
  25.     initStat(UpdateStat,'update');
  26.     initStat(TotalTurnAroundStat,'total job');
  27.     initStat(LocalTurnAroundStat,'local job');
  28.     sResume;
  29. end;
  30.  
  31. procedure WriteStat(Stat:tStatType);
  32. const sep=chr(9);
  33. var varianz:extended;
  34. begin
  35.     if gProtocolOn then with stat do 
  36.     begin
  37.         Write(OutFile,count:6,sep,mean:8:3,sep,ssq:8:3);
  38.         if count>1 then begin
  39.             varianz:=ssq/(count-1);
  40.             writeln(OutFile,sep,sqrt(varianz):8:3,sep,sqrt(varianz/count):8:3);
  41.         end else writeln(OutFile);
  42.     end;
  43. end;
  44.  
  45.  
  46.     {initialize all statistics}
  47. procedure sInit;
  48. begin
  49.     sLastTicks:=tickCount;
  50.     sMeanTicks:=100;    {a random number to start off-  we are using provisional means}
  51.     initAllStats;
  52. end;
  53.  
  54.  
  55. {update all statistics to account for a new result}
  56. procedure sNoteResult(isLocal:boolean);
  57. var tempticks,deltaticks:longint;
  58.     s:str255;x:integer;
  59. begin
  60.     tempticks:=sLastTicks;
  61.     sLastTicks:=tickCount;
  62.     deltaticks:=sLastTicks-tempticks;
  63.     {sMeanTicks:=(19*sMeanTicks+(deltaticks))*0.05;}{moving average over 20}
  64.     sMeanTicks:=(9*sMeanTicks+(deltaticks))*0.1;    {moving average over 10}
  65.     numtostring(deltaticks,s);
  66.     logstring(concat ('ticksPTask Δ',chr(9),s));
  67.     NrResults:=NrResults+1;
  68.     
  69.     
  70.     AddStat(deltaTicks,TotalTurnAroundStat);
  71.     sResume;
  72. end;
  73.  
  74.  
  75. { saves time and number of iterations}
  76. PROCEDURE ResetMeasurement;
  77. VAR
  78.     myTime: longint;
  79.     q: extended;
  80.     s: Str255;
  81. BEGIN
  82.     {save old results}
  83.     if gProtocolOn then begin    
  84.         Repeat Until ReadDateTime(myTime)=NoErr;
  85.         q:=(myTime-goldTime);
  86.         NumToString(round(q),s);
  87.         numtostring(gnrResults,gsOldResults);
  88.         gsOldResults2:=concat(s,' ',gsOldResults);
  89.         gsOldResults:=concat('Zeit: ',s,' s #:',gsOldResults);
  90.         writeln(OutFile,gsoldResults2);
  91.  
  92.         {set new values}
  93.  
  94.         gnrResults:=0;
  95.         nrResults:=0;
  96.         repeat until ReadDateTime(oldTime)=noErr;
  97.         repeat repeat until ReadDateTime(goldTime)=noErr; until goldTime>oldTime;
  98.         oldTime:=goldtime;
  99.     end;
  100. end;
  101. {*************** end clean up of statistics *****************************}
  102.