Transform: IMatrix;
Transform: Prognoz.Platform.Interop.Matrix.IMatrix;
The Transform method transforms matrix transformer data to matrix.
To transform data from matrix transformer to matrix, add or remove time dimensions from the collection by means of the IMatrixTransformerDimensions.Add or IMatrixTransformerDimensions.Remove methods.
Executing the example requires that the repository contains a calendar dictionary with the D_CALENDAR identifier.
Add links to the Dimension, Matrix, Metabase system assemblies.
Sub UserProc;
Var
MB: IMetabase;
DimA: IDimInstance;
Mfactory: IMatrixFactory;
DimSel: IDimSelectionSet;
Dfactory: IDimSelectionSetFactory;
Matrix, NewMat: IMatrix;
i1, i, element: integer;
Coord: IMatrixCoord;
elements: IDimElements;
Selection: IDimSelection;
Iterator: IMatrixIterator;
trf: IMatrixTransformer;
mtd: IMatrixTransformerDimension;
Begin
// Get repository
MB := MetabaseClass.Active;
// Get dictionary data
DimA := MB.ItemById("D_CALENDAR").Open(Null) As IDimInstance;
// Create selection
Dfactory := New DimSelectionSetFactory.Create;
DimSel := Dfactory.CreateDimSelectionSet;
DimSel.Add(DimA);
// Create matrix and fill it
Mfactory := New MatrixFactory.Create As IMatrixFactory;
Matrix := Mfactory.CreateMatrix(DimSel);
Coord := Matrix.CreateCoord;
For i1 := 0 To DimSel.Item(0).Dimension.Elements.Count - 1 Do
Coord.Item(0) := i1;
Matrix.Item(Coord) := Math.RandBetweenI(0, 12);
End For;
// Display coordinates to the console window
For i := 0 To DimSel.Count - 1 Do
elements := DimSel.Item(i).Dimension.Elements;
element := coord.Item(i);
If element <> -1 Then
Debug.WriteLine(element.ToString + " = (" + elements.Name(element) + ") -- ");
End If;
End For;
// Display obtained matrix to the console window
Debug.WriteLine("Matrix: ");
Selection := DimSel.Item(0);
For Each Selection In Matrix.Dimensions Do
// Display dimensions and their keys
Debug.WriteLine(" Dimension - " + selection.Dimension.Name + "; Key = " + selection.Dimension.Key.ToString);
// Display dimension elements
Debug.WriteLine(" Elements: ");
For i := 0 To Selection.Dimension.Elements.Count - 1 Do
Debug.WriteLine(" " + selection.Dimension.Elements.Name(i));
End For;
End For;
// Display values
Debug.WriteLine("Matrix values: ");
Iterator := matrix.CreateIterator;
Coord := matrix.CreateCoord;
Iterator.Move(IteratorDirection.First);
While Iterator.Valid Do
Iterator.PutCurrentPos(Coord);
Debug.WriteLine(" Value = " + Iterator.Value As String);
Iterator.Move(IteratorDirection.Next);
End While;
// Create matrix transformer
trf := New MatrixTransformer.Create;
trf.Source := Matrix;
// Add two new time dimensions
trf.Dimensions.Add(0, 3);
trf.Dimensions.Add(0, 2);
// Get a new matrix
NewMat := trf.Transform;
Debug.WriteLine("Number of values in new matrix = " + NewMat.ValueCount.ToString);
// Get time dimensions
For i := 0 To trf.Dimensions.Count - 1 Do
mtd := trf.Dimensions.Item(i);
If Not mtd.MatchCase Then
mtd.MatchCase := True;
End If;
// Display to the console window
Debug.WriteLine("Time dimension of new matrix: ");
Debug.WriteLine
("Dimension index - " + mtd.Index.ToString + "; " + "Dimension - " + mtd.Dimension.Name + "; " + "Element - " + mtd.Element.ToString);
End For;
End Sub UserProc;
After executing the example the console window displays:
Dimension, key, elements, values of matrix calendar dimension.
Number of values in the new obtained matrix.
Data of time dimensions of the new matrix.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.MathFin;
Imports Prognoz.Platform.Interop.Matrix;
…
Public Shared Sub Main(Params: StartParams);
Var
MB: IMetabase;
DimA: IDimInstance;
MatrixFactory: MatrixFactory = New MatrixFactoryClass();
Mfactory: IMatrixFactory;
DimSel: IDimSelectionSet;
Dfactory: DimSelectionSetFactory = New DimSelectionSetFactoryClass();
Matrix, NewMat: IMatrix;
Math: MathClass = New MathClass();
i1, i, element: integer;
Coord: IMatrixCoord;
elements: IDimElements;
Selection: IDimSelection;
Iterator: IMatrixIterator;
trf: MatrixTransformer = New MatrixTransformerClass();
mtd: IMatrixTransformerDimension;
Begin
// Get repository
MB := Params.Metabase;
// Get dictionary data
DimA := MB.ItemById["D_CALENDAR"].Open(Null) As IDimInstance;
// Create selection
DimSel := Dfactory.CreateDimSelectionSet();
DimSel.Add(DimA);
// Create matrix and fill it
Mfactory := MatrixFactory As IMatrixFactory;
Matrix := Mfactory.CreateMatrix(DimSel);
Coord := Matrix.CreateCoord();
For i1 := 0 To DimSel.Item[0].Dimension.Elements.Count - 1 Do
Coord.Item[0] := i1;
Matrix.Item[Coord] := Math.RandBetweenI(0, 12);
End For;
// Display coordinates to the console window
For i := 0 To DimSel.Count - 1 Do
elements := DimSel.Item[i].Dimension.Elements;
element := coord.Item[i];
If element <> -1 Then
System.Diagnostics.Debug.WriteLine(element.ToString() + " = (" + elements.Name[element As uinteger] + ") -- ");
End If;
End For;
// Display obtained matrix to the console window
System.Diagnostics.Debug.WriteLine("Matrix: ");
Selection := DimSel.Item[0];
For Each Selection In Matrix.Dimensions Do
// Display dimensions and their keys
System.Diagnostics.Debug.WriteLine
(" Dimension - " + selection.Dimension.Name + "; Key = " + selection.Dimension.Key.ToString());
// Display dimension elements
System.Diagnostics.Debug.WriteLine(" Elements: ");
For i := 0 To Selection.Dimension.Elements.Count - 1 Do
System.Diagnostics.Debug.WriteLine(" " + selection.Dimension.Elements.Name[i As uinteger]);
End For;
End For;
// Display values
System.Diagnostics.Debug.WriteLine("Matrix values: ");
Iterator := matrix.CreateIterator();
Coord := matrix.CreateCoord();
Iterator.Move(IteratorDirection.itdFirst);
While Iterator.Valid Do
Iterator.PutCurrentPos(Coord);
System.Diagnostics.Debug.WriteLine(" Value = " + Iterator.Value As String);
Iterator.Move(IteratorDirection.itdNext);
End While;
// Create matrix transformer
trf.Source := Matrix;
// Add two new time dimensions
trf.Dimensions.Add(0, 3);
trf.Dimensions.Add(0, 2);
// Get a new matrix
NewMat := trf.Transform();
System.Diagnostics.Debug.WriteLine("Number of values in new matrix = " + NewMat.ValueCount.ToString());
// Get time dimensions
For i := 0 To trf.Dimensions.Count - 1 Do
mtd := trf.Dimensions.Item[i];
If Not mtd.MatchCase Then
mtd.MatchCase := True;
End If;
// Display to the console window
System.Diagnostics.Debug.WriteLine("Time dimension of new matrix: ");
System.Diagnostics.Debug.WriteLine
("Dimension index - " + mtd.Index.ToString() + "; " + "Dimension - " + mtd.Dimension.Name + "; " + "Element - " + mtd.Element.ToString());
End For;
End Sub;
See also: