Skip to content

Commit

Permalink
Merge pull request #53 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
updating master
  • Loading branch information
Vitalis95 authored May 1, 2022
2 parents bd324a6 + 565d540 commit ee34797
Show file tree
Hide file tree
Showing 35 changed files with 1,921 additions and 1,084 deletions.
53 changes: 33 additions & 20 deletions instat/Model/DataFrame/clsColumnMetaData.vb
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,30 @@
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Imports RDotNet

''' <summary>
''' Holds Column Meta Data for a single dataframe
''' </summary>
Public Class clsColumnMetaData
Private _strName As String
Private _strDataFrameName As String
Private _RLink As RLink
Private _clsDataFrame As DataFrame
Private Property _clsColsMetadataDataFrame As DataFrame
Private _hasChanged As Boolean

''' <summary>
''' holds the metadata change audit id
''' </summary>
Public Property MetadataChangeAuditId As Integer

''' <summary>
''' Returns data for a given cell within the Column Meta data table
''' </summary>
''' <param name="row"></param>
''' <param name="column"></param>
''' <param name="iRowIndex"></param>
''' <param name="iColumnIndex"></param>
''' <returns></returns>
Public ReadOnly Property Data(row As Integer, column As Integer) As Object
Public ReadOnly Property Data(iRowIndex As Integer, iColumnIndex As Integer) As Object
Get
Return _clsDataFrame(row, column)
Return _clsColsMetadataDataFrame.Item(iRowIndex, iColumnIndex)
End Get
End Property

Expand All @@ -43,7 +49,7 @@ Public Class clsColumnMetaData
''' <returns></returns>
Public ReadOnly Property strRowName(row As Integer) As String
Get
Return _clsDataFrame.RowNames(row)
Return _clsColsMetadataDataFrame.RowNames(row)
End Get
End Property

Expand All @@ -53,7 +59,7 @@ Public Class clsColumnMetaData
''' <returns></returns>
Public ReadOnly Property iRowCount As Integer
Get
Return _clsDataFrame.RowCount
Return _clsColsMetadataDataFrame.RowCount
End Get
End Property

Expand All @@ -64,7 +70,7 @@ Public Class clsColumnMetaData
''' <returns></returns>
Public ReadOnly Property strColumnName(column As Integer) As String
Get
Return _clsDataFrame.ColumnNames(column)
Return _clsColsMetadataDataFrame.ColumnNames(column)
End Get
End Property

Expand All @@ -74,7 +80,7 @@ Public Class clsColumnMetaData
''' <returns></returns>
Public ReadOnly Property iColumnCount As Integer
Get
Return _clsDataFrame.ColumnCount
Return _clsColsMetadataDataFrame.ColumnCount
End Get
End Property

Expand All @@ -87,7 +93,7 @@ Public Class clsColumnMetaData
Get
Return _hasChanged
End Get
Set(ByVal value As Boolean)
Set(value As Boolean)
_hasChanged = value
End Set
End Property
Expand All @@ -99,15 +105,15 @@ Public Class clsColumnMetaData
''' <param name="strName"></param>
Public Sub New(rLink As RLink, strName As String)
_RLink = rLink
_strName = strName
_strDataFrameName = strName
_hasChanged = True
End Sub

Private Function HasDataChanged() As Boolean
Dim clsVariablesMetadataChanged As New RFunction
Dim expTemp As SymbolicExpression
clsVariablesMetadataChanged.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_variables_metadata_changed")
clsVariablesMetadataChanged.AddParameter("data_name", Chr(34) & _strName & Chr(34))
clsVariablesMetadataChanged.AddParameter("data_name", Chr(34) & _strDataFrameName & Chr(34))
expTemp = _RLink.RunInternalScriptGetValue(clsVariablesMetadataChanged.ToScript())
If expTemp IsNot Nothing AndAlso expTemp.Type <> Internals.SymbolicExpressionType.Null Then
Return expTemp.AsLogical(0)
Expand All @@ -121,19 +127,26 @@ Public Class clsColumnMetaData
''' </summary>
Public Sub RefreshData()
'Need to check to see if dataframe exists due to the column meta data not changing when sheets are un-hidden
If _clsDataFrame Is Nothing Or HasDataChanged() Then
_clsDataFrame = GetDataFrameFromRCommand()
ResetDataFramesChanged()
If _clsColsMetadataDataFrame Is Nothing OrElse HasDataChanged() Then
_clsColsMetadataDataFrame = GetColsMetadataFromRCommand()
SetColsMetadataToNotChangedInR()

'this change number should eventually come from R
'once that is done;
'HasDataChanged() should be re-implemeted
'HasChanged property can be deleted
'SetColsMetadataToNotChangedInR() can be deleted
MetadataChangeAuditId += 1
End If
End Sub

Private Function GetDataFrameFromRCommand() As DataFrame
Private Function GetColsMetadataFromRCommand() As DataFrame
Dim clsGetVariablesMetadata As New RFunction
Dim expTemp As SymbolicExpression
_hasChanged = True
clsGetVariablesMetadata.SetRCommand(_RLink.strInstatDataObject & "$get_variables_metadata")
clsGetVariablesMetadata.AddParameter("convert_to_character", "TRUE")
clsGetVariablesMetadata.AddParameter("data_name", Chr(34) & _strName & Chr(34))
clsGetVariablesMetadata.AddParameter("data_name", Chr(34) & _strDataFrameName & Chr(34))
expTemp = _RLink.RunInternalScriptGetValue(clsGetVariablesMetadata.ToScript(), bSilent:=True)
If expTemp IsNot Nothing AndAlso expTemp.Type <> Internals.SymbolicExpressionType.Null Then
Return expTemp.AsDataFrame
Expand All @@ -142,10 +155,10 @@ Public Class clsColumnMetaData
End If
End Function

Private Sub ResetDataFramesChanged()
Private Sub SetColsMetadataToNotChangedInR()
Dim clsSetVariablesMetadataChanged As New RFunction
clsSetVariablesMetadataChanged.SetRCommand(_RLink.strInstatDataObject & "$set_variables_metadata_changed")
clsSetVariablesMetadataChanged.AddParameter("data_name", Chr(34) & _strName & Chr(34))
clsSetVariablesMetadataChanged.AddParameter("data_name", Chr(34) & _strDataFrameName & Chr(34))
clsSetVariablesMetadataChanged.AddParameter("new_val", "FALSE")
_RLink.RunInternalScript(clsSetVariablesMetadataChanged.ToScript(), bSilent:=True)
End Sub
Expand Down
6 changes: 5 additions & 1 deletion instat/UserControls/DataGrid/Linux/ucrLinuxGrid.vb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ Public MustInherit Class ucrLinuxGrid
Private _rowContextMenuStrip As ContextMenuStrip
Private _tabContextMenuStrip As ContextMenuStrip

''' <summary>
''' Gets current worksheet adapter
''' </summary>
''' <returns>Worksheet adapter if a tab is selected, else nothing</returns>
Public Property CurrentWorksheet As clsWorksheetAdapter Implements IGrid.CurrentWorksheet
Get
Return New clsWorksheetAdapter(tcTabs.SelectedTab)
Return If(tcTabs.SelectedTab Is Nothing, Nothing, New clsWorksheetAdapter(tcTabs.SelectedTab))
End Get
Set(value As clsWorksheetAdapter)
For Each tabPage As TabPage In tcTabs.TabPages
Expand Down
6 changes: 5 additions & 1 deletion instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ Public MustInherit Class ucrReoGrid

Protected _clsDataBook As clsDataBook

''' <summary>
''' Gets current worksheet adapter
''' </summary>
''' <returns>Worksheet adapter if a worksheet is selected, else nothing</returns>
Public Property CurrentWorksheet As clsWorksheetAdapter Implements IGrid.CurrentWorksheet
Get
Return New clsWorksheetAdapter(grdData.CurrentWorksheet)
Return If(grdData.CurrentWorksheet Is Nothing, Nothing, New clsWorksheetAdapter(grdData.CurrentWorksheet))
End Get
Set(value As clsWorksheetAdapter)
grdData.CurrentWorksheet = grdData.Worksheets.Where(Function(x) x.Name = value.Name).FirstOrDefault
Expand Down
74 changes: 0 additions & 74 deletions instat/clsRLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -635,80 +635,6 @@ Public Class RLink
Return lstCurrColumns
End Function

'''--------------------------------------------------------------------------------------------
''' <summary> Fills the data frame control combo box with the specified data frame names and
''' sets the combo box index.
''' The data frames to include, and the source of the index are set by the
''' parameters below.</summary>
'''
''' <param name="cboDataFrames"> [in,out] The combobox data frames control. </param>
''' <param name="bSetDefault"> (Optional) If true then sets the combo box
''' index to the index of the current worksheet.
''' If false then sets the index to the index of
''' the current data frame. </param>
''' <param name="bIncludeOverall"> (Optional) If true then adds an extra item
''' in the combo box for '[Overall]' i.e. items
''' not at data frame level. </param>
''' <param name="strCurrentDataFrame"> (Optional) The current data frame. </param>
''' <param name="bOnlyLinkedToPrimaryDataFrames"> (Optional) If true then only fill the
''' combo box with data frame names linked to
''' <paramref name="strPrimaryDataFrame"/>. </param>
''' <param name="strPrimaryDataFrame"> (Optional) The primary data frame. </param>
''' <param name="bIncludePrimaryDataFrameAsLinked"> (Optional) If true then also include the
''' <paramref name="strPrimaryDataFrame"/> in
''' the list of data frames.
''' This parameter is only used if
''' <paramref name="bOnlyLinkedToPrimaryDataFrames"/>
''' is true.</param>
'''--------------------------------------------------------------------------------------------
Public Sub FillComboDataFrames(ByRef cboDataFrames As ComboBox, Optional bSetDefault As Boolean = True, Optional bIncludeOverall As Boolean = False, Optional strCurrentDataFrame As String = "", Optional bOnlyLinkedToPrimaryDataFrames As Boolean = False, Optional strPrimaryDataFrame As String = "", Optional bIncludePrimaryDataFrameAsLinked As Boolean = True)
If bInstatObjectExists Then
If bIncludeOverall Then
cboDataFrames.Items.Add("[Overall]") 'TODO legacy - Task/question: explain this.
End If
If bOnlyLinkedToPrimaryDataFrames Then
cboDataFrames.Items.AddRange(GetLinkedToDataFrameNames(strPrimaryDataFrame, bIncludePrimaryDataFrameAsLinked).ToArray)
Else
cboDataFrames.Items.AddRange(GetDataFrameNames().ToArray)
End If
AdjustComboBoxWidth(cboDataFrames)
'TODO Legacy - Task/Question: From what I understood, if bSetDefault is true or if the strCurrentDataFrame (given as an argument) is actually not in cboDataFrames (is this case generic or should it never happen ?), then the selected Index should be the current worksheet.
If (bSetDefault OrElse cboDataFrames.Items.IndexOf(strCurrentDataFrame) = -1) AndAlso (grdDataView IsNot Nothing) AndAlso (grdDataView.CurrentWorksheet IsNot Nothing) Then
cboDataFrames.SelectedIndex = cboDataFrames.Items.IndexOf(grdDataView.CurrentWorksheet.Name)
ElseIf cboDataFrames.Items.IndexOf(strCurrentDataFrame) <> -1 Then
cboDataFrames.SelectedIndex = cboDataFrames.Items.IndexOf(strCurrentDataFrame)
End If
End If
End Sub

'''--------------------------------------------------------------------------------------------
''' <summary> Adjust combo box width. </summary>
'''
''' <param name="cboCurrent"> The combo box to adjust. </param>
'''--------------------------------------------------------------------------------------------
Public Shared Sub AdjustComboBoxWidth(cboCurrent As ComboBox)
'TODO Legacy - This is used above but will not be once ucrDataFrame uses proper controls
' Then this can be removed
' TODO SJL 20/04/20 This is only used by the function above. Make private?
Dim iWidth As Integer = cboCurrent.DropDownWidth
Dim graTemp As System.Drawing.Graphics = cboCurrent.CreateGraphics()
Dim font As Font = cboCurrent.Font
Dim iScrollBarWidth As Integer
Dim iNewWidth As Integer

If cboCurrent.Items.Count > cboCurrent.MaxDropDownItems Then
iScrollBarWidth = SystemInformation.VerticalScrollBarWidth
Else
iScrollBarWidth = 0
End If

For Each strItem As String In cboCurrent.Items
iNewWidth = CInt(graTemp.MeasureString(strItem, font).Width) + iScrollBarWidth
iWidth = Math.Max(iWidth, iNewWidth)
Next
cboCurrent.DropDownWidth = iWidth
End Sub

'''--------------------------------------------------------------------------------------------
''' <summary> Fills the <paramref name="cboColumns"/> combo box with the <paramref name="strDataFrame"/>
''' data frame's column names. </summary>
Expand Down
Loading

0 comments on commit ee34797

Please sign in to comment.