home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / EXTENDED / UQUALI.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  4.1 KB  |  161 lines

  1. {*********************************************}
  2. {  TeeChart Pro 4 example                     }
  3. {  Copyright (c) 1995-1998 by David Berneda   }
  4. {  All rights reserved                        }
  5. {*********************************************}
  6. unit uquali;
  7.  
  8. interface
  9.  
  10. uses
  11.   Wintypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls,
  12.   Forms, Dialogs,  Series, ExtCtrls, TeeProcs, TeEngine, Chart, StdCtrls,
  13.   TeeComma;
  14.  
  15. type
  16.   TFormQuality = class(TForm)
  17.     Chart1: TChart;
  18.     Good: TLineSeries;
  19.     Bad: TLineSeries;
  20.     Upper: TFastLineSeries;
  21.     Lower: TFastLineSeries;
  22.     Memo1: TMemo;
  23.     Button1: TButton;
  24.     Label1: TLabel;
  25.     Label2: TLabel;
  26.     UpperEdit: TEdit;
  27.     LowerEdit: TEdit;
  28.     Button2: TButton;
  29.     TeeCommander1: TTeeCommander;
  30.     procedure FormCreate(Sender: TObject);
  31.     procedure Button1Click(Sender: TObject);
  32.     procedure UpperEditChange(Sender: TObject);
  33.     procedure LowerEditChange(Sender: TObject);
  34.     procedure Button2Click(Sender: TObject);
  35.   private
  36.     { Private declarations }
  37.   public
  38.     { Public declarations }
  39.     UpperLim,
  40.     LowerLim:Double;
  41.     Procedure CalculateSPC(GoodSeries,BadSeries:TChartSeries);
  42.   end;
  43.  
  44. var
  45.   FormQuality: TFormQuality;
  46.  
  47. implementation
  48.  
  49. {$R *.DFM}
  50. Uses EditChar;
  51.  
  52. { Calculate the upper and lower limits }
  53. Procedure TFormQuality.CalculateSPC(GoodSeries,BadSeries:TChartSeries);
  54. Var Sum,SumN,
  55.     tmp,Aux,LCP,LCN,NumTotal,
  56.     Percent:Double;
  57.     t,N:Longint;
  58. Begin
  59.   UpperLim:=0;
  60.   LowerLim:=0;
  61.   Sum:=0;
  62.   SumN:=0;
  63.   N:=0;
  64.   for t:=0 to GoodSeries.Count-1 do
  65.   begin
  66.     Percent:=(BadSeries.YValues[t]*GoodSeries.YValues[t]/100.0);
  67.     NumTotal:=GoodSeries.YValues[t]+Percent;
  68.     if NumTotal>0 then
  69.     Begin
  70.       Sum:=Sum+Percent/NumTotal;
  71.       SumN:=SumN+NumTotal;
  72.       inc(n);
  73.     end;
  74.   end;
  75.   LCP:=Sum/n;
  76.   LCN:=SumN/n;
  77.   tmp:=(LCP*(1-LCP))/LCN;
  78.   if tmp>0 then
  79.   Begin
  80.     Aux:=3*Sqrt(tmp); { <-- 3 by square root }
  81.     UpperLim:=100.0*(LCP+Aux);
  82.     LowerLim:=100.0*(LCP-Aux);
  83.   end;
  84. End;
  85.  
  86. procedure TFormQuality.FormCreate(Sender: TObject);
  87. var t:Integer;
  88. begin
  89.   Good.Clear;
  90.   for t:=0 to 19 do Good.Add(800+Random(200),'',clTeeColor);
  91.  
  92.   Bad.Clear;
  93.   for t:=0 to 19 do Bad.Add(4+Random(4),'',clTeeColor);
  94.  
  95.   CalculateSPC(Good,Bad);
  96.  
  97.   UpperEdit.Text:=FloatToStr(UpperLim);
  98.   LowerEdit.Text:=FloatToStr(LowerLim);
  99.  
  100.   Chart1.LeftAxis.SetMinMax(0,1100);
  101.   Chart1.RightAxis.SetMinMax(0,10);
  102. end;
  103.  
  104. procedure TFormQuality.Button1Click(Sender: TObject);
  105. begin
  106.   Close;
  107. end;
  108.  
  109. procedure TFormQuality.UpperEditChange(Sender: TObject);
  110. var tmp:Double;
  111. begin
  112.   try
  113.     tmp:=StrToFloat(UpperEdit.Text);
  114.   except
  115.     on exception do exit;
  116.   end;
  117.   Upper.Clear;
  118.   Upper.AddXY(0,tmp,'',clTeeColor);
  119.   Upper.AddXY(19,tmp,'',clTeeColor);
  120. end;
  121.  
  122. procedure TFormQuality.LowerEditChange(Sender: TObject);
  123. var tmp:Double;
  124. begin
  125.   try
  126.     tmp:=StrToFloat(LowerEdit.Text);
  127.   except
  128.     on exception do exit;
  129.   end;
  130.   Lower.Clear;
  131.   Lower.AddXY(0,tmp,'',clTeeColor);
  132.   Lower.AddXY(19,tmp,'',clTeeColor);
  133. end;
  134.  
  135. procedure TFormQuality.Button2Click(Sender: TObject);
  136. begin
  137.   ShowMessage( 'Calculating and charting the Upper and'+#13+
  138.                'Lower limits of an SPC Quality Control'+#13+
  139.                'series.'+#13+
  140.                '--------------------------------------------'+#13+
  141.                ''+#13+
  142.                'This example includes formulae to calculate'+#13+
  143.                'the SPC upper and lower limits.'+#13+
  144.                ''+#13+
  145.                'The Chart displays 2 series, one with'+#13+
  146.                'the number of "good" parts and another with'+#13+
  147.                'the percent of "bad" parts.'+#13+
  148.                ''+#13+
  149.                'With these two Series, the example calculates'+#13+
  150.                'two values: the upper and lower limits.'+#13+
  151.                ''+#13+
  152.                'These limits are displayed using another two'+#13+
  153.                'series.'+#13+
  154.                ''+#13+
  155.                'Disclaimer:'+#13+
  156.                'Correctness of calculation depends very much'+#13+
  157.                'on your particular country rules.');
  158. end;
  159.  
  160. end.
  161.