LazStats: Inherit form of SpearmanUnit from TBasicStatsReportForm.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7808 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-10-26 11:56:26 +00:00
parent e8845a74d3
commit 42b9a85a01
2 changed files with 300 additions and 359 deletions

View File

@ -1,248 +1,185 @@
object SpearmanFrm: TSpearmanFrm
inherited SpearmanFrm: TSpearmanFrm
Left = 531
Height = 317
Height = 347
Top = 246
Width = 347
Width = 679
HelpType = htKeyword
HelpKeyword = 'html/SpearmanRankCorrelation.htm'
AutoSize = True
Caption = 'Spearman Rank Correlation'
ClientHeight = 317
ClientWidth = 347
OnActivate = FormActivate
OnCreate = FormCreate
OnShow = FormShow
Position = poMainFormCenter
LCLVersion = '2.1.0.0'
object Label1: TLabel
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
Left = 8
ClientHeight = 347
ClientWidth = 679
inherited ParamsPanel: TPanel
Height = 331
ClientHeight = 331
inherited CloseBtn: TButton
Top = 306
end
inherited ComputeBtn: TButton
Top = 306
end
inherited ResetBtn: TButton
Top = 306
end
inherited HelpBtn: TButton
Top = 306
end
inherited ButtonBevel: TBevel
Top = 290
end
object Label1: TLabel[5]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = ParamsPanel
Left = 0
Height = 15
Top = 8
Top = 0
Width = 97
BorderSpacing.Left = 8
BorderSpacing.Top = 8
Caption = 'Variables Available'
ParentColor = False
end
object Label2: TLabel
object Label2: TLabel[6]
AnchorSideLeft.Control = XEdit
AnchorSideBottom.Control = XEdit
Left = 233
Left = 166
Height = 15
Top = 33
Top = 21
Width = 51
Anchors = [akLeft, akBottom]
BorderSpacing.Bottom = 2
Caption = 'X Variable'
ParentColor = False
end
object Label3: TLabel
object Label3: TLabel[7]
AnchorSideLeft.Control = YEdit
AnchorSideBottom.Control = YEdit
Left = 233
Left = 166
Height = 15
Top = 125
Top = 109
Width = 51
Anchors = [akLeft, akBottom]
BorderSpacing.Bottom = 2
Caption = 'Y Variable'
ParentColor = False
end
object VarList: TListBox
AnchorSideLeft.Control = Owner
object VarList: TListBox[8]
AnchorSideLeft.Control = ParamsPanel
AnchorSideTop.Control = Label1
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = XIn
AnchorSideBottom.Control = Bevel1
AnchorSideBottom.Control = ButtonBevel
AnchorSideBottom.Side = asrBottom
Left = 8
Height = 243
Top = 25
Width = 181
Left = 0
Height = 273
Top = 17
Width = 126
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Top = 2
BorderSpacing.Right = 8
BorderSpacing.Right = 6
BorderSpacing.Bottom = 8
Constraints.MinHeight = 200
ItemHeight = 0
OnDblClick = VarListDblClick
OnSelectionChange = VarListSelectionChange
TabOrder = 0
TabOrder = 4
end
object XIn: TBitBtn
AnchorSideLeft.Control = Bevel2
AnchorSideLeft.Side = asrBottom
object XIn: TBitBtn[9]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = VarList
Left = 197
Height = 28
Top = 25
Width = 28
Left = 132
Height = 26
Top = 17
Width = 26
Images = MainDataModule.ImageList
ImageIndex = 1
OnClick = XInClick
Spacing = 0
TabOrder = 1
TabOrder = 5
end
object XOut: TBitBtn
AnchorSideLeft.Control = Bevel2
AnchorSideLeft.Side = asrBottom
object XOut: TBitBtn[10]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = XIn
AnchorSideTop.Side = asrBottom
Left = 197
Height = 28
Top = 57
Width = 28
Left = 132
Height = 26
Top = 47
Width = 26
BorderSpacing.Top = 4
Images = MainDataModule.ImageList
ImageIndex = 0
OnClick = XOutClick
Spacing = 0
TabOrder = 2
TabOrder = 6
end
object YIn: TBitBtn
AnchorSideLeft.Control = Bevel2
AnchorSideLeft.Side = asrBottom
object YIn: TBitBtn[11]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = XOut
AnchorSideTop.Side = asrBottom
Left = 197
Height = 28
Top = 117
Width = 28
Left = 132
Height = 26
Top = 105
Width = 26
BorderSpacing.Top = 32
Images = MainDataModule.ImageList
ImageIndex = 1
OnClick = YInClick
Spacing = 0
TabOrder = 3
TabOrder = 7
end
object YOut: TBitBtn
AnchorSideLeft.Control = Bevel2
AnchorSideLeft.Side = asrBottom
object YOut: TBitBtn[12]
AnchorSideLeft.Control = ParamsPanel
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = YIn
AnchorSideTop.Side = asrBottom
Left = 197
Height = 28
Top = 149
Width = 28
Left = 132
Height = 26
Top = 135
Width = 26
BorderSpacing.Top = 4
Images = MainDataModule.ImageList
ImageIndex = 0
OnClick = YOutClick
Spacing = 0
TabOrder = 4
TabOrder = 8
end
object XEdit: TEdit
object XEdit: TEdit[13]
AnchorSideLeft.Control = XIn
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = XOut
AnchorSideBottom.Side = asrBottom
Left = 233
Left = 166
Height = 23
Top = 50
Width = 106
Top = 38
Width = 125
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 12
ReadOnly = True
TabOrder = 5
TabOrder = 9
Text = 'XEdit'
end
object YEdit: TEdit
object YEdit: TEdit[14]
AnchorSideLeft.Control = YOut
AnchorSideLeft.Side = asrBottom
AnchorSideRight.Control = Owner
AnchorSideRight.Control = ParamsPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = YOut
AnchorSideBottom.Side = asrBottom
Left = 233
Left = 166
Height = 23
Top = 142
Width = 106
Top = 126
Width = 125
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 12
ReadOnly = True
TabOrder = 6
TabOrder = 10
Text = 'YEdit'
end
object ResetBtn: TButton
AnchorSideRight.Control = ComputeBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 138
Height = 25
Top = 284
Width = 54
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Reset'
OnClick = ResetBtnClick
TabOrder = 7
end
object ComputeBtn: TButton
AnchorSideRight.Control = CloseBtn
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 200
Height = 25
Top = 284
Width = 76
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Compute'
OnClick = ComputeBtnClick
TabOrder = 8
end
object CloseBtn: TButton
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 284
Height = 25
Top = 284
Width = 55
Anchors = [akRight, akBottom]
AutoSize = True
BorderSpacing.Top = 8
BorderSpacing.Right = 8
BorderSpacing.Bottom = 8
Caption = 'Close'
ModalResult = 11
TabOrder = 9
end
object Bevel1: TBevel
AnchorSideLeft.Control = Owner
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ComputeBtn
Left = 0
Height = 8
Top = 268
Width = 347
Anchors = [akLeft, akRight, akBottom]
Shape = bsBottomLine
end
object Bevel2: TBevel
AnchorSideLeft.Control = Owner
AnchorSideLeft.Side = asrCenter
Left = 150
Height = 11
Top = 3
Width = 47
Shape = bsSpacer
inherited ParamsSplitter: TSplitter
Height = 347
end
end

View File

@ -5,134 +5,81 @@ unit SpearmanUnit;
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, Buttons, ExtCtrls,
MainUnit, OutputUnit, FunctionsLib, Globals, DataProcs;
MainUnit, FunctionsLib, Globals, DataProcs, BasicStatsReportFormUnit;
type
{ TSpearmanFrm }
TSpearmanFrm = class(TForm)
TSpearmanFrm = class(TBasicStatsReportForm)
Bevel1: TBevel;
Bevel2: TBevel;
XIn: TBitBtn;
XOut: TBitBtn;
YIn: TBitBtn;
YOut: TBitBtn;
ResetBtn: TButton;
ComputeBtn: TButton;
CloseBtn: TButton;
XEdit: TEdit;
YEdit: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
VarList: TListBox;
procedure ComputeBtnClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ResetBtnClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; User: boolean);
procedure VarListDblClick(Sender: TObject);
procedure VarListSelectionChange(Sender: TObject; {%H-}User: boolean);
procedure XInClick(Sender: TObject);
procedure XOutClick(Sender: TObject);
procedure YInClick(Sender: TObject);
procedure YOutClick(Sender: TObject);
private
{ private declarations }
FAutoSized: Boolean;
procedure UpdateBtnStates;
protected
procedure AdjustConstraints; override;
procedure Compute; override;
procedure UpdateBtnStates; override;
public
{ public declarations }
procedure Reset; override;
end;
var
SpearmanFrm: TSpearmanFrm;
implementation
{$R *.lfm}
uses
Math, MathUnit;
{ TSpearmanFrm }
procedure TSpearmanFrm.ResetBtnClick(Sender: TObject);
procedure TSpearmanFrm.AdjustConstraints;
begin
inherited;
ParamsPanel.Constraints.MinWidth := 4*CloseBtn.Width + 3*CloseBtn.BorderSpacing.Left;
ParamsPanel.Constraints.MinHeight := YOut.Top + YOut.Height +
VarList.BorderSpacing.Bottom + ButtonBevel.Height +
CloseBtn.BorderSpacing.Top + CloseBtn.Height;
end;
procedure TSpearmanFrm.Compute;
var
i: integer;
begin
XEdit.Text := '';
YEdit.Text := '';
VarList.Items.Clear;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
UpdateBtnStates;
end;
procedure TSpearmanFrm.XInClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if (index > -1) and (XEdit.Text = '') then
begin
XEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end;
procedure TSpearmanFrm.XOutClick(Sender: TObject);
begin
if XEdit.Text <> '' then
begin
VarList.Items.Add(XEdit.Text);
XEdit.Text := '';
end;
UpdateBtnStates;
end;
procedure TSpearmanFrm.YInClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if (index > -1) and (YEdit.Text = '') then
begin
YEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end;
procedure TSpearmanFrm.YOutClick(Sender: TObject);
begin
if YEdit.Text <> '' then
begin
VarList.Items.Add(YEdit.Text);
YEdit.Text := '';
end;
UpdateBtnStates;
end;
procedure TSpearmanFrm.FormShow(Sender: TObject);
begin
ResetBtnClick(self);
end;
procedure TSpearmanFrm.ComputeBtnClick(Sender: TObject);
var
i, j, itemp, NoTies, NoSelected : integer;
col1, col2, NCases : integer;
index : IntDyneMat;
Probability, sumsqrx, sumsqry, Temp, TieSum, Avg, t, SumT, r : double;
z, sumdsqr, df : double;
Ranks, X : DblDyneMat;
d : DblDyneVec;
index: IntDyneMat = nil;
Ranks: DblDyneMat = nil;
X: DblDyneMat;
d: DblDyneVec = nil;
ColNoSelected: IntDyneVec = nil;
ColLabels: StrDyneVec = nil;
i, j, itemp, NoTies, NoSelected: integer;
col1, col2, NCases: integer;
Probability, sumsqrx, sumsqry, Temp, TieSum, Avg, t, SumT, r: double;
z, sumdsqr, df: double;
cellstring: string;
ColNoSelected : IntDyneVec;
ColLabels : StrDyneVec;
VarX, VarY, SDX, SDY, MeanX, MeanY, Rxy : double;
VarX, VarY, SDX, SDY, MeanX, MeanY, Rxy: double;
lReport: TStrings;
begin
if (XEdit.Text = '') then begin
@ -413,58 +360,115 @@ begin
lReport.Add('Mean X Variance X Std.Dev. X Mean Y Variance Y Std.Dev. Y');
lReport.Add('%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f', [MeanX, VarX, SDX, MeanY, VarY, SDY]);
DisplayReport(lReport);
FReportFrame.DisplayReport(lReport);
finally
lReport.Free;
ColLabels := nil;
d := nil;
X := nil;
Ranks := nil;
index := nil;
ColNoSelected := nil;
end;
end;
procedure TSpearmanFrm.FormActivate(Sender: TObject);
procedure TSpearmanFrm.Reset;
var
w: Integer;
i: integer;
begin
if FAutoSized then
exit;
inherited;
w := MaxValue([ResetBtn.Width, ComputeBtn.Width, CloseBtn.Width]);
ResetBtn.Constraints.MinWidth := w;
ComputeBtn.Constraints.MinWidth := w;
CloseBtn.Constraints.MinWidth := w;
XEdit.Text := '';
YEdit.Text := '';
VarList.Items.Clear;
for i := 1 to NoVariables do
VarList.Items.Add(OS3MainFrm.DataGrid.Cells[i,0]);
Constraints.MinWidth := 4*w;
Constraints.MinHeight := Height;
FAutoSized := true;
UpdateBtnStates;
end;
procedure TSpearmanFrm.FormCreate(Sender: TObject);
begin
Assert(OS3MainFrm <> nil);
end;
procedure TSpearmanFrm.UpdateBtnStates;
begin
inherited;
XIn.Enabled := (VarList.Count > 0) and (XEdit.Text = '');
YIn.Enabled := (Varlist.Count > 0) and (YEdit.Text = '');
XOut.Enabled := XEdit.Text <> '';
YOut.Enabled := YEdit.Text <> '';
end;
procedure TSpearmanFrm.VarListSelectionChange(Sender: TObject; User: boolean);
begin
UpdateBtnStates;
end;
initialization
{$I spearmanunit.lrs}
procedure TSpearmanFrm.VarListDblClick(Sender: TObject);
var
index: Integer;
s: String;
begin
index := VarList.ItemIndex;
if index > -1 then
begin
s := VarList.Items[index];
if XEdit.Text = '' then
XEdit.Text := s
else if YEdit.Text = '' then
YEdit.Text := s;
VarList.Items.Delete(index);
UpdateBtnStates;
end;
end;
procedure TSpearmanFrm.XInClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if (index > -1) and (XEdit.Text = '') then
begin
XEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end;
procedure TSpearmanFrm.XOutClick(Sender: TObject);
begin
if XEdit.Text <> '' then
begin
VarList.Items.Add(XEdit.Text);
XEdit.Text := '';
end;
UpdateBtnStates;
end;
procedure TSpearmanFrm.YInClick(Sender: TObject);
var
index: integer;
begin
index := VarList.ItemIndex;
if (index > -1) and (YEdit.Text = '') then
begin
YEdit.Text := VarList.Items[index];
VarList.Items.Delete(index);
end;
UpdateBtnStates;
end;
procedure TSpearmanFrm.YOutClick(Sender: TObject);
begin
if YEdit.Text <> '' then
begin
VarList.Items.Add(YEdit.Text);
YEdit.Text := '';
end;
UpdateBtnStates;
end;
end.