const
DT_NameWidth = 50; { maximum length of col/row names }
DT_MaxColOrRows = 2000000000 div (DT_NameWidth+1);
{$IFDEF PAIDVERS}
SDLVersionInfo = 'datatable_r900_full';
IsLightEd = false;
{$ELSE}
SDLVersionInfo = 'datatable_r900_lighted';
IsLightEd = true;
{$ENDIF}
Release = 900;
csNAN = $01; { cell states: not a number }
csUndefined = $02; { undefined or empty cell }
csUser1 = $04; { user defined cell type }
csUser2 = $08; { user defined cell type }
csUser3 = $10; { user defined cell type }
csUser4 = $20; { user defined cell type }
csMarkedA = $40; { cell is marked, type 1 }
csMarkedB = $80; { cell is marked, type 2 }
csReset = $00; { cell is not marked at all }
csNone = $00; { cell is not marked at all }
csAll = $FF; { any kind of mark }
type
TDTNameStr = string[DT_NameWidth]; { col/row header type }
ESDLDataTableError = class(ESDLError); { exception type to indicate errors }
TDataTableResizeEvent = procedure (Sender: TObject; OldColumns, OldRows,
NewColumns, NewRows: longint) of object;
TDataTable = class(TComponent)
private
FOnChange : TNotifyEvent;
FOnResize : TDataTableResizeEvent;
FComment : string; { comment on data }
FRowAtt : array of byte; { class information on objects }
FColAtt : array of byte; { class information on features }
FCState : array of array of byte; { array of cell states }
FColName : array of TDTNameStr; { column names }
FRowName : array of TDTNameStr; { row names }
FNrOfCols : longint; { number of columns of data matrix }
FNrOfRows : longint; { number of columns of data matrix }
{$IFDEF PAIDVERS}
FVNState : TQuotedStrState; { state of var parser }
FVNName : string; { intermediary name for var. parsing }
{$ENDIF}
FSortIncludeHd : boolean; { flag to indicate sorting mode }
FOnSortExchange : TSortExchgEvent;
FExtMatAssigned : boolean;
procedure ExchangeDuringSort (Sender: TObject; ExchgWhat: byte;
index1, index2, first, last: longint);
function GetRowAttrib (RowNr: longint): byte;
function GetCellState (ACol, ARow: longint): byte;
function GetColAttrib (ColNr: longint): byte;
function GetColName (ColNr: longint): TDTNameStr;
function GetElem (ACol, ARow: longint): double;
function GetRowName (RowNr: longint): TDTNameStr;
procedure FDataHasChanged (Sender: TObject);
procedure SetRowAttrib (RowNr: longint; Attrib: byte);
procedure SetCellState (ACol, ARow: longint; const Value: byte);
procedure SetColAttrib (ColNr: longint; Attrib: byte);
procedure SetColName (ColNr: longint; HLine: TDTNameStr);
procedure SetElem (ACol, ARow: longint; const Value: double);
procedure SetFComment (cmt: string);
procedure SetNrCols (NrCols: longint);
procedure SetNrRows (NrRows: longint);
procedure SetRowName (RowNr: longint; HLine: TDTNameStr);
protected
public
NumericData : TMatrix; { data matrix }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure AssignAnotherDataMatrix (NewDMat: TMatrix);
procedure Changed;
procedure Clear;
procedure ExportAsASC (FName: string; Precision: integer); overload;
procedure ExportAsASC (OutStream: TStream;
Precision: integer); overload;
function ImportASC (FName: string): integer; overload;
function ImportASC (InStream: TStream): integer; overload;
function ImportASC (ClipBd: TClipBoard): integer; overload;
property Elem[ACol, ARow: longint]: double
read GetElem write SetElem; default;
property CellState[ACol, ARow: longint]: byte
read GetCellState write SetCellState;
procedure Resize (NrCols, NrRows: longint);
property RowAttrib [ix: longint]: byte
read GetRowAttrib write SetRowAttrib;
property ColAttrib [ix: longint]: byte
read GetColAttrib write SetColAttrib;
function CountMarkedCellsInColumn (Col: integer;
StateMask: byte): integer;
function CountMarkedCellsInRow (Row: integer;
StateMask: byte): integer;
function IfColHasCellState (col: longint; CellState: byte): boolean;
function IfRowHasCellState (row: longint; CellState: byte): boolean;
property ColName[ix: longint]: TDTNameStr
read GetColName write SetColName;
procedure CopyContentsFrom (ExtTab: TDataTable);
function CountNumCells (LowCol, LowRow, HighCol,
HighRow: integer): integer;
function GeometricMeanOfNumCells (LowCol, LowRow, HighCol,
HighRow: integer; var NumData: integer): double;
function HarmonicMeanOfNumCells (LowCol, LowRow, HighCol,
HighRow: integer; var NumData: integer): double;
function MeanVarOfNumCells (LowCol, LowRow, HighCol,
HighRow: integer; var Mean, Variance: double): integer;
function MinMaxOfNumCells (LowCol, LowRow, HighCol,
HighRow: integer; var Minimum, Maximum: double): integer;
function PercentileOfNumCells (prob: double; LowCol, LowRow, HighCol,
HighRow: integer; var NumData: integer): double;
function QuartilesOfNumCells (LowCol, LowRow, HighCol,
HighRow: integer; var Q1, Q2, Q3: double;
var NumData: integer): boolean;
procedure StandardizeNumCellColumns (Means, StdDevs: TVector);
procedure StandardizeNumCellRows (Means, StdDevs: TVector);
function SumOfNumCells (LowCol,LowRow,HighCol,HighRow: integer;
var NumData: integer): double;
property RowName[ix: longint]: TDTNameStr
read GetRowName write SetRowName;
procedure SortCols (SortRowIx: integer; Ascending: boolean;
LowCol, LowRow, HighCol, HighRow: integer;
IncludeHeaders: boolean);
procedure SortRows (SortColIx: integer; Ascending: boolean;
LowCol, LowRow, HighCol, HighRow: integer;
IncludeHeaders: boolean);
procedure SetAllCellStates (CellState: byte);
function FindColIndex (ColID: TDTNameStr): integer;
function FindRowIndex (RowID: TDTNameStr): integer;
function ReadFromASC (FName: string; PosX, PosY: longint;
ReplaceIDs: boolean): integer; overload;
function ReadFromASC (InStream: TStream; PosX, PosY: longint;
ReplaceIDs: boolean): integer; overload;
published
property Comment: string
read FComment write SetFComment;
property NrOfColumns: longint
read FNrOfCols write SetNrCols;
property NrOfRows: longint
read FNrOfRows write SetNrRows;
property OnChange: TNotifyEvent
read FOnChange write FOnChange;
property OnResize: TDataTableResizeEvent
read FOnResize write FOnResize;
property OnSortExchange: TSortExchgEvent
read FOnSortExchange write FOnSortExchange;
end;
|