LazStats: Minor improvements in XVsMultYUnit and PlotXYUnit. Input validation in SmoothDataUnit. Add hyperlinks to Analysis topic in chm file.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7380 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-04-13 21:59:05 +00:00
parent fd0dd2bac7
commit 00155466f5
6 changed files with 100 additions and 58 deletions

View File

@ -50,7 +50,7 @@ type
private private
{ private declarations } { private declarations }
FAutoSized: Boolean; FAutoSized: Boolean;
procedure plotxy(VAR Xpoints : DblDyneVec; procedure PlotXY(VAR Xpoints : DblDyneVec;
VAR Ypoints : DblDyneVec; VAR Ypoints : DblDyneVec;
VAR UpConf : DblDyneVec; VAR UpConf : DblDyneVec;
VAR LowConf : DblDyneVec; VAR LowConf : DblDyneVec;
@ -112,40 +112,46 @@ var
index: integer; index: integer;
begin begin
index := VarList.ItemIndex; index := VarList.ItemIndex;
if index > -1 then if (index > -1) and (XEdit.Text = '') then
begin begin
XEdit.Text := VarList.Items[index]; XEdit.Text := VarList.Items[index];
VarList.Items.Delete(index); VarList.Items.Delete(index);
end;
UpdateBtnStates; UpdateBtnStates;
end; end;
end;
procedure TPlotXYFrm.XOutBtnClick(Sender: TObject); procedure TPlotXYFrm.XOutBtnClick(Sender: TObject);
begin
if XEdit.Text <> '' then
begin begin
VarList.Items.Add(XEdit.Text); VarList.Items.Add(XEdit.Text);
XEdit.Text := ''; XEdit.Text := '';
UpdateBtnStates; UpdateBtnStates;
end; end;
end;
procedure TPlotXYFrm.YInBtnClick(Sender: TObject); procedure TPlotXYFrm.YInBtnClick(Sender: TObject);
var var
index: integer; index: integer;
begin begin
index := VarList.ItemIndex; index := VarList.ItemIndex;
if index > -1 then if (index > -1) and (YEdit.Text = '') then
begin begin
YEdit.Text := VarList.Items[index]; YEdit.Text := VarList.Items[index];
VarList.Items.Delete(index); VarList.Items.Delete(index);
end;
UpdateBtnStates; UpdateBtnStates;
end; end;
end;
procedure TPlotXYFrm.YOutBtnClick(Sender: TObject); procedure TPlotXYFrm.YOutBtnClick(Sender: TObject);
begin
if YEdit.Text <> '' then
begin begin
VarList.Items.Add(YEdit.Text); VarList.Items.Add(YEdit.Text);
YEdit.Text := ''; YEdit.Text := '';
UpdateBtnStates; UpdateBtnStates;
end; end;
end;
procedure TPlotXYFrm.FormShow(Sender: TObject); procedure TPlotXYFrm.FormShow(Sender: TObject);
begin begin
@ -454,7 +460,7 @@ begin
BlankFrm.Image1.Canvas.MoveTo(xpos,ypos); BlankFrm.Image1.Canvas.MoveTo(xpos,ypos);
ypos := ypos + 10; ypos := ypos + 10;
BlankFrm.Image1.Canvas.LineTo(xpos,ypos); BlankFrm.Image1.Canvas.LineTo(xpos,ypos);
Title := format('%6.2f',[Xvalue]); Title := format('%.2f',[Xvalue]);
offset := BlankFrm.Image1.Canvas.TextWidth(Title) div 2; offset := BlankFrm.Image1.Canvas.TextWidth(Title) div 2;
xpos := xpos - offset; xpos := xpos - offset;
BlankFrm.Image1.Canvas.Pen.Color := clBlack; BlankFrm.Image1.Canvas.Pen.Color := clBlack;

View File

@ -160,12 +160,12 @@ object DataSmoothingForm: TDataSmoothingForm
Left = 8 Left = 8
Height = 19 Height = 19
Top = 316 Top = 316
Width = 188 Width = 122
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
BorderSpacing.Left = 8 BorderSpacing.Left = 8
BorderSpacing.Top = 8 BorderSpacing.Top = 8
BorderSpacing.Bottom = 4 BorderSpacing.Bottom = 4
Caption = 'Repeat Smoothing No. Times = ' Caption = 'Execute smoothing'
TabOrder = 7 TabOrder = 7
end end
object RepeatEdit: TEdit object RepeatEdit: TEdit
@ -173,7 +173,7 @@ object DataSmoothingForm: TDataSmoothingForm
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = RepeatChk AnchorSideTop.Control = RepeatChk
AnchorSideTop.Side = asrCenter AnchorSideTop.Side = asrCenter
Left = 204 Left = 138
Height = 23 Height = 23
Top = 314 Top = 314
Width = 32 Width = 32
@ -212,4 +212,17 @@ object DataSmoothingForm: TDataSmoothingForm
ParentColor = False ParentColor = False
WordWrap = True WordWrap = True
end end
object Label3: TLabel
AnchorSideLeft.Control = RepeatEdit
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = RepeatEdit
AnchorSideTop.Side = asrCenter
Left = 178
Height = 15
Top = 318
Width = 29
BorderSpacing.Left = 8
Caption = 'times'
ParentColor = False
end
end end

View File

@ -15,6 +15,7 @@ type
TDataSmoothingForm = class(TForm) TDataSmoothingForm = class(TForm)
Bevel1: TBevel; Bevel1: TBevel;
Label3: TLabel;
Memo1: TLabel; Memo1: TLabel;
RepeatEdit: TEdit; RepeatEdit: TEdit;
RepeatChk: TCheckBox; RepeatChk: TCheckBox;
@ -67,22 +68,39 @@ end;
procedure TDataSmoothingForm.ComputeBtnClick(Sender: TObject); procedure TDataSmoothingForm.ComputeBtnClick(Sender: TObject);
var var
DataPts, OutPts: DblDyneVec; DataPts, OutPts: DblDyneVec;
avalue, avg : double;
N, Reps, i, j, VarCol: integer; N, Reps, i, j, VarCol: integer;
VarLabel, strvalue : string; VarLabel, strValue: string;
begin begin
if SelectedEdit.Text = '' then
begin
MessageDlg('No variable selected.', mtError, [mbOk], 0);
exit;
end;
if RepeatChk.Checked then
begin
if RepeatEdit.Text = '' then
begin
MessageDlg('Repeat count not specified.', mtError, [mbOK], 0);
exit;
end;
if not TryStrToInt(RepeatEdit.Text, Reps) and (Reps < 1) then
begin
MessageDlg('Repeat count must be >= 1.', mtError, [mbOK], 0);
exit;
end;
end else
Reps := 1;
N := NoCases; N := NoCases;
SetLength(DataPts,N); SetLength(DataPts,N);
SetLength(OutPts,N); SetLength(OutPts,N);
Reps := StrToInt(RepeatEdit.Text);
Varlabel := SelectedEdit.Text; Varlabel := SelectedEdit.Text;
for i := 1 to NoVariables do for i := 1 to NoVariables do
if VarLabel = OS3MainFrm.DataGrid.Cells[i,0] then VarCol := i; if VarLabel = OS3MainFrm.DataGrid.Cells[i,0] then VarCol := i;
for i := 0 to N - 1 do for i := 0 to N - 1 do
begin DataPts[i] := StrToFloat(OS3MainFrm.DataGrid.Cells[VarCol,i+1]);
avalue := StrToFloat(OS3MainFrm.DataGrid.Cells[VarCol,i+1]);
DataPts[i] := avalue;
end;
// repeat smoothing for number of times elected // repeat smoothing for number of times elected
OutPts[0] := DataPts[0]; OutPts[0] := DataPts[0];
@ -90,23 +108,21 @@ begin
for j := 1 to Reps do for j := 1 to Reps do
begin begin
for i := 1 to N - 2 do for i := 1 to N - 2 do
begin OutPts[i] := (DataPts[i-1] + DataPts[i] + DataPts[i+1]) / 3.0;
avg := (DataPts[i-1] + DataPts[i] + DataPts[i+1]) / 3.0;
OutPts[i] := avg;
end;
if j < reps then if j < reps then
for i := 0 to N - 1 do DataPts[i] := OutPts[i]; for i := 0 to N - 1 do DataPts[i] := OutPts[i];
end; end;
// create a new variable and copy smoothed data into it // create a new variable and copy smoothed data into it
strvalue := 'Smoothed' + VarLabel; if Reps = 1 then
strvalue := Format('%s_Smoothed', [VarLabel])
else
strvalue := Format('%s_Smoothed_%dx', [VarLabel, Reps]);
DictionaryFrm.NewVar(NoVariables+1); DictionaryFrm.NewVar(NoVariables+1);
DictionaryFrm.DictGrid.Cells[1,NoVariables] := strvalue; DictionaryFrm.DictGrid.Cells[1,NoVariables] := strvalue;
OS3MainFrm.DataGrid.Cells[NoVariables,0] := strvalue; OS3MainFrm.DataGrid.Cells[NoVariables,0] := strvalue;
for i := 0 to N - 1 do for i := 0 to N - 1 do
begin OS3MainFrm.DataGrid.Cells[NoVariables,i+1] := Format('%0.3f', [OutPts[i]]);
strvalue := format('%9.3f',[OutPts[i]]);
OS3MainFrm.DataGrid.Cells[NoVariables,i+1] := strvalue;
end;
// clean up // clean up
OutPts := nil; OutPts := nil;

View File

@ -64,7 +64,7 @@ var
implementation implementation
uses uses
Math; Math, Utils;
{ TXvsMultYForm } { TXvsMultYForm }
@ -439,7 +439,14 @@ begin
end; end;
procedure TXvsMultYForm.UpdateBtnStates; procedure TXvsMultYForm.UpdateBtnStates;
var
lSelected: Boolean;
begin begin
lSelected := AnySelected(VarList);
XInBtn.Enabled := lSelected and (XEdit.Text = '');
YInBtn.Enabled := lSelected;
xOutBtn.Enabled := (XEdit.Text <> '');
YOutBtn.Enabled := AnySelected(YBox);
end; end;
initialization initialization