IDmMethod.Execute

Fore Syntax

Execute: IDmReports;

Fore.NET Syntax

Execute(): Prognoz.Platform.Interop.Ms:IDmReports;

Description

The Execute method calculates data mining method.

Comments

Calculated method parameters are returned by the IDmMethod.Details property.

Fore Example

Executing the example requires that the repository contains a table containing data for analysis with the DM_TABLE identifier. A regular report with the DM_REPORT_RES identifier where analysis results will be loaded must also be present.

Add links to the Metabase, Ms, Report, Stat, Tab, Ui system assemblies.

Sub UserKeyInf;
Var
    mb: IMetabase;
    TableDS: IDmTableDataSource;
    ReportDS: IDmReportDataSource;
    Method: IDmMethod;
    Report: IPrxReport;
    Shs: IPrxSheets;
    Sheet: ITabSheet;
    KeyInf: IDmKeyInfluences;
    Binning: IDmField;
    i: Integer;
    Attrs: Array 
Of Integer;
    Target: IUiCommandTarget;
    Reports: IDmReports;
    DmReport: IDmReport;
Begin
    mb := MetabaseClass.Active;
    
// Create table data source
    TableDS := (New TableDataSource.Create) As IDmTableDataSource;
    
// Determine source table
    TableDS.Table := mb.ItemByID("DM_TABLE").Bind;
    
// Determine that data is located in table columns
    TableDS.DataInColumns := True;
    
// Create data source which is a regular report
    ReportDS := (New ReportDataSource.Create) As IDmReportDataSource;
    
// Get regular report
    Report := mb.ItemByID("DM_REPORT_RES").Edit As IPrxReport;
    Shs := Report.Sheets;
    Shs.Clear;
    
// Create page to load results
    Sheet := (Shs.Add("", PrxSheetType.Table) As IPrxTable).TabSheet;
    
// Determine page to which data will be loaded    
    ReportDS.TabSheet := Sheet;
    
// Determine data range
    ReportDS.Range := Sheet.Cell(00);
    ReportDS.AddResultColumn(
"Category");
    
// Create calculation method
    Method := (New DataMiningMethod.Create) As IDmMethod;
    
// Determine method type
    Method.Kind := DmMethodKind.KeyInfluences;
    
// Set entry data source
    Method.InputDataSource := TableDS;
    
// Set data consumer
    Method.OutputDataSource := ReportDS;
    
// Set up calculation method parameters
    KeyInf := Method.Details As IDmKeyInfluences;
    
// Determine column for analysis
    KeyInf.Target := TableDS.FieldCount - 1;
    Debug.WriteLine(
"Column for key impact factors analysis:");
    Debug.WriteLine(
" - " + TableDS.Field(KeyInf.Target).Name);
    
// Set factors impacting analysis
    Attrs := New Integer[TableDS.FieldCount - 2];
    Debug.WriteLine(
"Factors that impact analysis:");
    
For i := 0 To Attrs.Length - 1 Do
        Attrs[i] := i + 
1;
        Binning := TableDS.Field(i + 
1);
        Debug.WriteLine(Binning.Index.ToString + 
". " + Binning.Name);
        Debug.Indent;
        
// Set parameters of the Binning procedure
        If Binning.IsNumerical Then
            Binning.BinningType := BinningMethod.EqualDepth;
            Binning.CategoriesCount := 
4;
            Binning.TreatNanAsCategory := 
False;
            Debug.WriteLine(
"number of non empty values: " + Binning.NonEmptyCount.ToString);
        
End If;
        
Select Case Binning.FieldType
            
Case DmFieldType.Date: Debug.WriteLine("data type: date");
            
Case DmFieldType.Integer: Debug.WriteLine("data type: integer");
            
Case DmFieldType.Numeric: Debug.WriteLine("data type: numeric");
            
Case DmFieldType.String: Debug.WriteLine("data type: string");
        
End Select;
        Debug.WriteLine(
"data source: " + Binning.DataSource.Caption);
        Debug.Unindent;
    
End For;
    KeyInf.Attributes := Attrs;
    
// Perform analysis and load results
    Reports := Method.Execute;
    DmReport := reports.FindByType(DmReportType.KeyInfluences);
    ReportDS := DmReport.Generate;
    Debug.WriteLine(
"Report title: " + DmReport.Caption);
    Debug.WriteLine(
"Analysis type: " + KeyInf.DisplayName);
    Debug.WriteLine(
"Analysis method: " + KeyInf.StatMethod.DisplayName);
    ReportDS.TabSheet.View.Selection.SelectAll;
    ReportDS.TabSheet.View.Selection.Copy;
    Sheet.Table.Paste;
    Sheet.Columns(
01).AdjustWidth;
    Sheet.Rows(
01).AdjustHeight;
    Report.Sheets.Item(
0).Name := ReportDS.Caption;
    (Report 
As IMetabaseObject).Save;
    
// Open regular report containing analysis results
    Target := WinApplication.Instance.GetObjectTarget(Report As IMetabaseObject);
    Target.Execute(
"Object.Open"Null);
End Sub UserKeyInf;

Procedure execution result: for the data from the DM_TABLE table the Key Factors data mining method is executed using the Binning procedure for numeric data, analysis parameters are displayed in the console window, analysis results are loaded to the DM_REPORT_RES report.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Report;
Imports Prognoz.Platform.Interop.Stat;
Imports Prognoz.Platform.Interop.Tab;
Imports Prognoz.Platform.Interop.Ui;

Public Shared Sub Main(Params: StartParams);
Var
    mb: IMetabase;
    TableDS: IDmTableDataSource;
    ReportDS: IDmReportDataSource;
    Method: IDmMethod;
    Report: IPrxReport;
    Shs: IPrxSheets;
    Sheet: TabSheet;
    KeyInf: IDmKeyInfluences;
    Binning: IDmField;
    i: Integer;
    Attrs: Array Of Integer;
    Target: IUiCommandTarget;
    Reports: IDmReports;
    DmReport: IDmReport;
    WinApplication: WinApplicationClassClass = New WinApplicationClassClass();
Begin
    mb := Params.Metabase;
    // Create table data source
    TableDS := (New TableDataSource.Create()) As IDmTableDataSource;
    // Determine source table
    TableDS.Table := mb.ItemByID["DM_TABLE"].Bind();
    // Determine that data is located in table columns
    TableDS.DataInColumns := True;
    // Create a data source that is a regular report
    ReportDS := (New ReportDataSource.Create()) As IDmReportDataSource;
    // Get regular report
    Report := mb.ItemByID["DM_REPORT_RES"].Edit() As IPrxReport;
    Shs := Report.Sheets;
    Shs.Clear();
    // Create a page to output results to
    Sheet := (Shs.Add("", PrxSheetType.pstTable) As IPrxTable).TabSheet;
    // Determine page where data will be loaded    
    ReportDS.TabSheet := Sheet;
    // Specify data range
    ReportDS.Range := Sheet.Cell[00];
    ReportDS.AddResultColumn("Category");
    // Create calculation method
    Method := (New DataMiningMethod.Create()) As IDmMethod;
    // Specify method type
    Method.Kind := DmMethodKind.dmmkKeyInfluences;
    // Set input data source
    Method.InputDataSource := TableDS;
    // Set data consumer
    Method.OutputDataSource := ReportDS;
    // Set up calculation method parameters
    KeyInf := Method.Details As IDmKeyInfluences;
    // Determine column for analysis
    KeyInf.Target := TableDS.FieldCount - 1;
    System.Diagnostics.Debug.WriteLine("Column for key impact factors analysis:");
    System.Diagnostics.Debug.WriteLine(" - " + TableDS.Field[KeyInf.Target].Name);
    // Set factors that influence analysis
    Attrs := New Integer[TableDS.FieldCount - 2];
    System.Diagnostics.Debug.WriteLine("Factors impacting analysis:");
    For i := 0 To Attrs.Length - 1 Do
        Attrs[i] := i + 1;
        Binning := TableDS.Field[i + 1];
        System.Diagnostics.Debug.WriteLine(Binning.Index.ToString() + ". " + Binning.Name);
        System.Diagnostics.Debug.Indent();
        // Set the Binning procedure parameters
        If Binning.IsNumerical Then
            Binning.BinningType := BinningMethod.bmEqualDepth;
            Binning.CategoriesCount := 4;
            Binning.TreatNanAsCategory := False;
            System.Diagnostics.Debug.WriteLine("number of non empty values: " + Binning.NonEmptyCount.ToString());
        End If;
        Select Case Binning.FieldType
            Case DmFieldType.dftDate: System.Diagnostics.Debug.WriteLine("data type: date");
            Case DmFieldType.dftInteger: System.Diagnostics.Debug.WriteLine("data type: integer");
            Case DmFieldType.dftNumeric: System.Diagnostics.Debug.WriteLine("data type: numeric");
            Case DmFieldType.dftString: System.Diagnostics.Debug.WriteLine("data type: string");
        End Select;
        System.Diagnostics.Debug.WriteLine("data source: " + Binning.DataSource.Caption);
        System.Diagnostics.Debug.Unindent();
    End For;
    KeyInf.Attributes := Attrs;
    // Perform analysis and output results
    Reports := Method.Execute();
    DmReport := reports.FindByType[DmReportType.drtKeyInfluences];
    ReportDS := DmReport.Generate();
    System.Diagnostics.Debug.WriteLine("Report title: " + DmReport.Caption);
    System.Diagnostics.Debug.WriteLine("Analysis type: " + KeyInf.DisplayName);
    System.Diagnostics.Debug.WriteLine("Analysis method: " + KeyInf.StatMethod.DisplayName);
    ReportDS.TabSheet.View.Selection.SelectAll();
    ReportDS.TabSheet.View.Selection.Copy();
    Sheet.Table.Paste();
    Sheet.Columns[01].AdjustWidth(-1, -1);
    Sheet.Rows[01].AdjustHeight(-1, -1);
    Report.Sheets.Item[0].Name := ReportDS.Caption;
    (Report As IMetabaseObject).Save();
    // Open regular report that contains analysis results
    Target := WinApplication.Instance[Null].GetObjectTarget(Report As IMetabaseObject);
    Target.Execute("Object.Open"NullNull);
End Sub;

See also:

IDmMethod