Skip to content

Commit

Permalink
Merge pull request #66 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
fetching latest copy
  • Loading branch information
maxwellfundi authored Jun 24, 2016
2 parents c495ba7 + 55c0052 commit 0457168
Show file tree
Hide file tree
Showing 62 changed files with 1,895 additions and 715 deletions.
14 changes: 11 additions & 3 deletions instat/clsGridLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Public Class clsGridLink
lstDataNames = frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_data_names()").AsList
For i = 0 To lstDataNames.Length - 1
strDataName = lstDataNames.AsCharacter(i)
If (bGrdDataExists And frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_data_changed(data_name = " & Chr(34) & strDataName & Chr(34) & ")").AsLogical(0)) Then
If (bGrdDataExists AndAlso frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_data_changed(data_name = " & Chr(34) & strDataName & Chr(34) & ")").AsLogical(0)) Then
frmMain.clsRLink.clsEngine.Evaluate(strDataName & "<-" & frmMain.clsRLink.strInstatDataObject & "$get_data_frame(" & Chr(34) & strDataName & Chr(34) & ", convert_to_character = TRUE, include_hidden_columns = FALSE, use_current_filter = TRUE)")
dfTemp = frmMain.clsRLink.clsEngine.GetSymbol(strDataName).AsCharacterMatrix()
If frmMain.clsRLink.RunInternalScriptGetValue(frmMain.clsRLink.strInstatDataObject & "$filter_applied(data_name = " & Chr(34) & strDataName & Chr(34) & ")").AsLogical(0) Then
Expand All @@ -74,8 +74,8 @@ Public Class clsGridLink
End If
frmEditor.SetColumnNames(strDataName, dfTemp.ColumnNames())
frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$set_data_frames_changed(" & Chr(34) & strDataName & Chr(34) & ", FALSE)")
End If
If (bGrdVariablesMetadataExists And frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_variables_metadata_changed(" & Chr(34) & strDataName & Chr(34) & ")").AsLogical(0)) Then
End If
If (bGrdVariablesMetadataExists And frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_variables_metadata_changed(" & Chr(34) & strDataName & Chr(34) & ")").AsLogical(0)) Then
dfTemp = frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_variables_metadata(" & Chr(34) & strDataName & Chr(34) & ", convert_to_character = TRUE)").AsCharacterMatrix()
FillSheet(dfTemp, strDataName, grdVariablesMetadata)
frmMain.clsRLink.clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$set_variables_metadata_changed(" & Chr(34) & strDataName & Chr(34) & ", FALSE)")
Expand Down Expand Up @@ -288,4 +288,12 @@ Public Class clsGridLink
UpdateGrids()
End Sub

Public Sub FormatDataVIew(fntNew As Font, clrNew As Color)
Dim tmpSheets As Worksheet
For Each tmpSheets In frmMain.clsGrids.grdData.Worksheets
tmpSheets.SetRangeStyles(RangePosition.EntireRange, New WorksheetRangeStyle() With {
.Flag = PlainStyleFlag.TextColor Or PlainStyleFlag.FontSize Or PlainStyleFlag.FontName, .TextColor = clrNew, .FontSize = fntNew.Size, .FontName = fntNew.Name})

Next
End Sub
End Class
18 changes: 16 additions & 2 deletions instat/clsInstatOptions.vb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Imports System.Threading
Imports System.Globalization
Imports unvell.ReoGrid
Public Class InstatOptions
Public bIncludeRDefaultParameters As Boolean
Public fntOutput, fntScript, fntComment As Font
Public clrOutput, clrScript, clrComment As Color
Public fntOutput, fntScript, fntComment, fntEditor As Font
Public clrOutput, clrScript, clrComment, clrEditor As Color
Public strComment, strLanguageCultureCode As String
Public iPreviewRows As Integer
Public iMaxRows As Integer
Expand Down Expand Up @@ -31,6 +32,19 @@ Public Class InstatOptions
frmMain.clsRLink.setFormatComment(fntComment, clrComment)
End Sub

Public Sub SetEditorFormat(fntNew As Font, clrNew As Color)
fntEditor = fntNew
clrEditor = clrNew
'
frmMain.clsRLink.SetFormatDataView(fntEditor, clrEditor)
Dim tmpSheets As Worksheet
For Each tmpSheets In frmEditor.grdData.Worksheets
tmpSheets.SetRangeStyles(RangePosition.EntireRange, New WorksheetRangeStyle() With {
.Flag = PlainStyleFlag.TextColor Or PlainStyleFlag.FontSize Or PlainStyleFlag.FontName, .TextColor = clrNew, .FontSize = fntNew.Size, .FontName = fntNew.Name})

Next
End Sub

Public Sub SetPreviewRows(intlines As Integer)
iPreviewRows = intlines
dlgImportDataset.setLinesToRead(iPreviewRows)
Expand Down
10 changes: 7 additions & 3 deletions instat/clsRFunction.vb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Public Class RFunction
Public bToBeAssigned As Boolean = False
Public bIsAssigned As Boolean = False
Public bAssignToIsPrefix As Boolean = False
Public bAssignToColumnWithoutNames As Boolean = False

Public Sub New()
RaiseEvent ParametersChanged()
Expand All @@ -37,7 +38,7 @@ Public Class RFunction
bIsAssigned = False
End Sub

Public Sub SetAssignTo(strTemp As String, Optional strTempDataframe As String = "", Optional strTempColumn As String = "", Optional strTempModel As String = "", Optional strTempGraph As String = "", Optional bAssignToIsPrefix As Boolean = False)
Public Sub SetAssignTo(strTemp As String, Optional strTempDataframe As String = "", Optional strTempColumn As String = "", Optional strTempModel As String = "", Optional strTempGraph As String = "", Optional bAssignToIsPrefix As Boolean = False, Optional bAssignToColumnWithoutNames As Boolean = False)
strAssignTo = strTemp
If Not strTempDataframe = "" Then
strAssignToDataFrame = strTempDataframe
Expand All @@ -52,6 +53,7 @@ Public Class RFunction
strAssignToGraph = strTempGraph
End If
Me.bAssignToIsPrefix = bAssignToIsPrefix
Me.bAssignToColumnWithoutNames = bAssignToColumnWithoutNames
bToBeAssigned = True
bIsAssigned = False
End Sub
Expand Down Expand Up @@ -96,10 +98,12 @@ Public Class RFunction
frmMain.clsRLink.CreateNewInstatObject()
End If
strScript = strScript & strAssignTo & " <- " & strTemp & vbCrLf
If Not strAssignToDataFrame = "" And Not strAssignToColumn = "" Then
If Not strAssignToDataFrame = "" AndAlso (Not strAssignToColumn = "" OrElse bAssignToColumnWithoutNames) Then
clsAddColumns.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_columns_to_data")
clsAddColumns.AddParameter("data_name", Chr(34) & strAssignToDataFrame & Chr(34))
clsAddColumns.AddParameter("col_name", Chr(34) & strAssignToColumn & Chr(34))
If Not bAssignToColumnWithoutNames Then
clsAddColumns.AddParameter("col_name", Chr(34) & strAssignToColumn & Chr(34))
End If
clsAddColumns.AddParameter("col_data", strAssignTo)
If bAssignToIsPrefix Then
clsAddColumns.AddParameter("use_col_name_as_prefix", "TRUE")
Expand Down
76 changes: 49 additions & 27 deletions instat/clsRLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Public Class RLink
Public fComments As Font = New Font("Microsoft Sans Serif", 8, FontStyle.Regular)
Public clrComments As Color = Color.Green

Public fEditor As Font = New Font("Microsoft Sans Serif", 10, FontStyle.Regular)
Public clrEditor As Color = Color.Black

Public Sub New(Optional bWithInstatObj As Boolean = False, Optional bWithClimsoft As Boolean = False)
End Sub

Expand All @@ -63,6 +66,11 @@ Public Class RLink
bOutput = True
End Sub

Public Sub SetFormatDataView(tempFont As Font, tempColor As Color)
fEditor = tempFont
clrEditor = tempColor
End Sub

Public Sub SetLog(tempLog As TextBox)
txtLog = tempLog
bLog = True
Expand Down Expand Up @@ -148,14 +156,19 @@ Public Class RLink
Dim strNextDefault As String = ""
Dim clsGetDefault As New RFunction
Dim strExistingNames As String
Dim expPrefix As SymbolicExpression

clsGetDefault.SetRCommand("next_default_item")
clsGetDefault.AddParameter("prefix", Chr(34) & strPrefix & Chr(34))
strExistingNames = GetListAsRString(lstItems)
If strExistingNames <> "" Then
clsGetDefault.AddParameter("existing_names", GetListAsRString(lstItems))
End If
Return RunInternalScriptGetValue(clsGetDefault.ToScript()).AsCharacter(0)
expPrefix = RunInternalScriptGetValue(clsGetDefault.ToScript())
If Not expPrefix.Type = Internals.SymbolicExpressionType.Null Then
strNextDefault = expPrefix.AsCharacter(0)
End If
Return strNextDefault
End Function

Public Sub RunScript(strScript As String, Optional bReturnOutput As Integer = 0, Optional strComment As String = "")
Expand Down Expand Up @@ -222,6 +235,7 @@ Public Class RLink
AppendText(txtOutput, clrOutput, fOutput, strOutput)
End If
frmMain.clsGrids.UpdateGrids()
frmMain.clsGrids.FormatDataVIew(fEditor, clrEditor)
End Sub

Private Sub AppendText(box As RichTextBox, color As Color, font As Font, text As String)
Expand Down Expand Up @@ -425,14 +439,13 @@ Public Class RLink
End If
End Sub

Public Sub SelectColumnsWithMetadataProperty(lstView As ListView, strDataFrameName As String, strProperty As String, strValues As String())
Public Sub SelectColumnsWithMetadataProperty(ucrCurrentReceiver As ucrReceiverMultiple, strDataFrameName As String, strProperty As String, strValues As String())
Dim vecColumns As GenericVector
Dim chrCurrColumns As CharacterVector
Dim i, j, iTemp As Integer
Dim i As Integer
Dim clsGetItems As New RFunction
Dim clsIncludeList As New RFunction
Dim kvpInclude As KeyValuePair(Of String, String())
Dim lviTemp As ListViewItem

kvpInclude = New KeyValuePair(Of String, String())(strProperty, strValues)

Expand All @@ -446,19 +459,10 @@ Public Class RLink
clsIncludeList.AddParameter(kvpInclude.Key, GetListAsRString(kvpInclude.Value.ToList(), bWithQuotes:=False))
clsGetItems.AddParameter("include", clsRFunctionParameter:=clsIncludeList)
vecColumns = RunInternalScriptGetValue(clsGetItems.ToScript()).AsList

ucrCurrentReceiver.Clear()
For i = 0 To vecColumns.Count - 1
chrCurrColumns = vecColumns(i).AsCharacter
lstView.BeginUpdate()
For j = 0 To chrCurrColumns.Count - 1
For Each lviTemp In lstView.Items
If lviTemp.Text = chrCurrColumns(j) Then
lviTemp.Selected = True
Exit For
End If
Next
Next
lstView.EndUpdate()
ucrCurrentReceiver.Add(chrCurrColumns.ToArray())
Next
End If
End Sub
Expand Down Expand Up @@ -507,26 +511,40 @@ Public Class RLink
Return intColumnCount
End Function

Public Function GetModelNames() As List(Of String)
Public Function GetModelNames(Optional strDataFrameName As String = "") As List(Of String)
Dim chrModelNames As CharacterVector
Dim lstModelNames As New List(Of String)
chrModelNames = clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_model_names()").AsCharacter
If chrModelNames IsNot Nothing Then
lstModelNames.AddRange(chrModelNames)
Dim clsGetModelNames As New RFunction
Dim expModelNames As SymbolicExpression

clsGetModelNames.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_model_names")
If strDataFrameName <> "" Then
clsGetModelNames.AddParameter("data_name", Chr(34) & strDataFrameName & Chr(34))
End If
expModelNames = RunInternalScriptGetValue(clsGetModelNames.ToScript())
If Not expModelNames.Type = Internals.SymbolicExpressionType.Null Then
chrModelNames = expModelNames.AsCharacter()
If chrModelNames.Length > 0 Then
lstModelNames.AddRange(chrModelNames)
End If
End If
Return lstModelNames
End Function

Public Function GetFilterNames(strDataFrameName As String) As List(Of String)
Dim expFilterNames As SymbolicExpression
Dim chrFilterNames As CharacterVector
Dim lstFilterNames As New List(Of String)
Dim clsGetFilterNames As New RFunction

clsGetFilterNames.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_filter_names")
clsGetFilterNames.AddParameter("data_name", Chr(34) & strDataFrameName & Chr(34))
chrFilterNames = RunInternalScriptGetValue(clsGetFilterNames.ToScript()).AsCharacter
If chrFilterNames IsNot Nothing Then
lstFilterNames.AddRange(chrFilterNames)
expFilterNames = RunInternalScriptGetValue(clsGetFilterNames.ToScript())
If Not expFilterNames.Type = Internals.SymbolicExpressionType.Null Then
chrFilterNames = expFilterNames.AsCharacter()
If chrFilterNames.Length > 0 Then
lstFilterNames.AddRange(chrFilterNames)
End If
End If
Return lstFilterNames
End Function
Expand All @@ -535,22 +553,26 @@ Public Class RLink
Dim chrGraphNames As CharacterVector
Dim lstGraphNames As New List(Of String)
Dim clsGetGraphNames As New RFunction
Dim expGraphNames As SymbolicExpression

clsGetGraphNames.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_graph_names")
If strDataFrameName <> "" Then
clsGetGraphNames.AddParameter("data_name", Chr(34) & strDataFrameName & Chr(34))
End If
chrGraphNames = RunInternalScriptGetValue(clsGetGraphNames.ToScript()).AsCharacter
If chrGraphNames IsNot Nothing Then
lstGraphNames.AddRange(chrGraphNames)
expGraphNames = RunInternalScriptGetValue(clsGetGraphNames.ToScript())
If Not expGraphNames.Type = Internals.SymbolicExpressionType.Null Then
chrGraphNames = expGraphNames.AsCharacter()
If chrGraphNames.Length > 0 Then
lstGraphNames.AddRange(chrGraphNames)
End If
End If
Return lstGraphNames
End Function

Public Function GetDataType(strDataFrameName As String, strColumnName As String) As String
Dim strDataType As CharacterVector
strDataType = clsEngine.Evaluate(frmMain.clsRLink.strInstatDataObject & "$get_data_type(data_name = " & Chr(34) & strDataFrameName & Chr(34) & ",col_name=" & Chr(34) & strColumnName & Chr(34) & ")").AsCharacter
strDataType = RunInternalScriptGetValue(frmMain.clsRLink.strInstatDataObject & "$get_data_type(data_name = " & Chr(34) & strDataFrameName & Chr(34) & ",col_name=" & Chr(34) & strColumnName & Chr(34) & ")").AsCharacter
Return strDataType(0)
End Function

End Class
End Class
24 changes: 17 additions & 7 deletions instat/clsROperator.vb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ Public Class ROperator
Public bIsAssigned As Boolean = False
Public bForceIncludeOperation As Boolean = True
Public bAssignToIsPrefix As Boolean = False
Public bAssignToColumnWithoutNames As Boolean = False

Public Sub SetOperation(strTemp As String, Optional bBracketsTemp As Boolean = True)
strOperation = strTemp
bBrackets = bBracketsTemp
bIsAssigned = False
End Sub

Public Sub SetAssignTo(strTemp As String, Optional strTempDataframe As String = "", Optional strTempColumn As String = "", Optional strTempModel As String = "", Optional strTempGraph As String = "", Optional bAssignToIsPrefix As Boolean = False)
Public Sub SetAssignTo(strTemp As String, Optional strTempDataframe As String = "", Optional strTempColumn As String = "", Optional strTempModel As String = "", Optional strTempGraph As String = "", Optional bAssignToIsPrefix As Boolean = False, Optional bAssignToColumnWithoutNames As Boolean = False)
strAssignTo = strTemp
If Not strTempDataframe = "" Then
strAssignToDataFrame = strTempDataframe
Expand All @@ -61,6 +62,8 @@ Public Class ROperator
End If
bToBeAssigned = True
bIsAssigned = False
Me.bAssignToIsPrefix = bAssignToIsPrefix
Me.bAssignToColumnWithoutNames = bAssignToColumnWithoutNames
End Sub

Public Sub RemoveAssignTo()
Expand Down Expand Up @@ -128,10 +131,12 @@ Public Class ROperator
frmMain.clsRLink.CreateNewInstatObject()
End If
strScript = strScript & strAssignTo & " <- " & strTemp & vbCrLf
If Not strAssignToDataFrame = "" And Not strAssignToColumn = "" Then
If Not strAssignToDataFrame = "" AndAlso (Not strAssignToColumn = "" OrElse bAssignToColumnWithoutNames) Then
clsAddColumns.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_columns_to_data")
clsAddColumns.AddParameter("data_name", Chr(34) & strAssignToDataFrame & Chr(34))
clsAddColumns.AddParameter("col_name", Chr(34) & strAssignToColumn & Chr(34))
If bAssignToColumnWithoutNames Then
clsAddColumns.AddParameter("col_name", Chr(34) & strAssignToColumn & Chr(34))
End If
clsAddColumns.AddParameter("col_data", strAssignTo)
If bAssignToIsPrefix Then
clsAddColumns.AddParameter("use_col_name_as_prefix", "TRUE")
Expand Down Expand Up @@ -322,10 +327,15 @@ Public Class ROperator
clsTempROperator.bForceIncludeOperation = bForceIncludeOperation
clsTempROperator.bAssignToIsPrefix = bAssignToIsPrefix

clsTempROperator.clsLeftFunction = clsLeftFunction.Clone
clsTempROperator.clsLeftOperator = clsLeftOperator.Clone
clsTempROperator.clsLeftParameter = clsLeftParameter.Clone

If clsLeftFunction IsNot Nothing Then
clsTempROperator.clsLeftFunction = clsLeftFunction.Clone
End If
If clsLeftOperator IsNot Nothing Then
clsTempROperator.clsLeftOperator = clsLeftOperator.Clone
End If
If clsLeftParameter IsNot Nothing Then
clsTempROperator.clsLeftParameter = clsLeftParameter.Clone
End If
For Each clsAdditionalParams In clsAdditionalParameters
clsTempROperator.AddAdditionalParameter(clsAdditionalParams.Clone)
Next
Expand Down
Loading

0 comments on commit 0457168

Please sign in to comment.