Skip to content

Commit

Permalink
Merge pull request #22 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
Update master
  • Loading branch information
MeSophie authored Nov 28, 2022
2 parents 1007475 + 7e409f5 commit 2bcd5ce
Show file tree
Hide file tree
Showing 105 changed files with 6,454 additions and 3,776 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,13 @@ installer/Output/
/instat/dlgFrequency.resx
/instat/dlgFrequency.Designer.vb

# PR #7853 adds a feature to display html in the output window.
# This requires the cef packages. These packages are more than 0.4 GB.
# We want to prevent these packages from being stored in the R-Instat GitHub repository.
/packages/cef.redist.*/
/packages/CefSharp.Common.*/
/packages/CefSharp.WinForms.*/

# Package used by script window
/packages/jacobslusser.ScintillaNET.*/

426 changes: 242 additions & 184 deletions instat/DlgDefineClimaticData.Designer.vb

Large diffs are not rendered by default.

44 changes: 26 additions & 18 deletions instat/DlgDefineClimaticData.vb
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,25 @@ Public Class DlgDefineClimaticData
Dim kvpDate As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("date", {"date", "record"}.ToList())
Dim kvpStation As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("station", {"station", "id", "name"}.ToList())
Dim kvpCloudCover As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("cloud_cover", {"cloud"}.ToList())
Dim kvpTempMax As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("temp_max", {"tmax", "tx", "max", "tempmax"}.ToList())
Dim kvpTempMin As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("temp_min", {"tmin", "tn", "min", "tempmin"}.ToList())
Dim kvpTempMax As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("temp_max", {"tmax", "tx", "tempmax", "tmp_max"}.ToList())
Dim kvpTempMin As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("temp_min", {"tmin", "tn", "tempmin", "tmp_min"}.ToList())
Dim kvpRadiation As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("radiation", {"radiation", "rad"}.ToList())
Dim kvpSunshineHours As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("sunshine_hours", {"sunshine", "sunh"}.ToList())
Dim kvpSunshineHours As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("sunshine_hours", {"sunshine", "sunh", "sunhrs"}.ToList())
Dim kvpWindDirection As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("wind_direction", {"winddirection"}.ToList())
Dim kvpWindSpeed As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("wind_speed", {"windspeed"}.ToList())
Dim kvpYear As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("year", {"year"}.ToList())
Dim kvpMonth As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("month", {"month"}.ToList())
Dim kvpDay As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("day", {"day"}.ToList())
Dim kvpDOY As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("doy", {"doy", "doy_366"}.ToList())
Dim kvpMinRH As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("hum_min", {"minhum", "hmin", "hn"}.ToList())
Dim kvpMaxRH As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("hum_max", {"maxhum", "hmax", "hx"}.ToList())

lstRecognisedTypes.AddRange({kvpRain, kvpStation, kvpCloudCover, kvpTempMax, kvpTempMin, kvpRadiation, kvpSunshineHours, kvpWindDirection, kvpWindSpeed, kvpYear, kvpMonth, kvpDay, kvpDOY, kvpDate})
lstReceivers.AddRange({ucrReceiverCloudCover, ucrReceiverDay, ucrReceiverMaxTemp, ucrReceiverMinTemp, ucrReceiverMonth, ucrReceiverRadiation, ucrReceiverRain, ucrReceiverStationName, ucrReceiverSunshine, ucrReceiverWindDirection, ucrReceiverWindSpeed, ucrReceiverYear, ucrReceiverDOY, ucrReceiverDate})

lstRecognisedTypes.AddRange({kvpRain, kvpStation, kvpCloudCover, kvpTempMax, kvpTempMin, kvpRadiation, kvpSunshineHours,
kvpWindDirection, kvpWindSpeed, kvpYear, kvpMonth, kvpDay, kvpDOY, kvpDate, kvpMinRH, kvpMaxRH})
lstReceivers.AddRange({ucrReceiverCloudCover, ucrReceiverDay, ucrReceiverMaxTemp, ucrReceiverMinTemp, ucrReceiverMonth, ucrReceiverRadiation,
ucrReceiverRain, ucrReceiverStationName, ucrReceiverSunshine, ucrReceiverWindDirection, ucrReceiverWindSpeed,
ucrReceiverYear, ucrReceiverDOY, ucrReceiverDate, ucrReceiverMinRH, ucrReceiverMaxRH})

ucrSelectorDefineClimaticData.SetParameter(New RParameter("data_name", 0))
ucrSelectorDefineClimaticData.SetParameterIsString()
Expand All @@ -79,6 +85,8 @@ Public Class DlgDefineClimaticData
ucrReceiverMonth.Tag = "month"
ucrReceiverDay.Tag = "day"
ucrReceiverDOY.Tag = "doy"
ucrReceiverMinRH.Tag = "hum_min"
ucrReceiverMaxRH.Tag = "hum_max"
ucrInputCheckInput.IsReadOnly = True

ucrReceiverDate.SetIncludedDataTypes({"Date"})
Expand Down Expand Up @@ -204,16 +212,16 @@ Public Class DlgDefineClimaticData
Private Sub cmdCheckUnique_Click(sender As Object, e As EventArgs) Handles cmdCheckUnique.Click
Dim iAnyDuplicated As Integer

Try
iAnyDuplicated = frmMain.clsRLink.RunInternalScriptGetValue(clsAnyDuplicatesFunction.ToScript()).AsInteger(0)
Catch ex As Exception
iAnyDuplicated = -1
Try
iAnyDuplicated = frmMain.clsRLink.RunInternalScriptGetValue(clsAnyDuplicatesFunction.ToScript()).AsInteger(0)
Catch ex As Exception
iAnyDuplicated = -1
End Try

If iAnyDuplicated = -1 Then
ucrInputCheckInput.SetName("Developer error! Could not check uniqueness.")
If iAnyDuplicated = -1 Then
ucrInputCheckInput.SetName("Developer error! Could not check uniqueness.")
ucrInputCheckInput.txtInput.BackColor = Color.Yellow
bIsUnique = False
bIsUnique = False
ElseIf iAnyDuplicated > 0 Then
ucrInputCheckInput.SetName("")
ucrInputCheckInput.txtInput.BackColor = Color.LightCoral
Expand All @@ -226,18 +234,18 @@ Public Class DlgDefineClimaticData
MsgBox("You have multiple rows with the same dates for one or more stations. Use the Climatic > Tidy and Examine > Duplicates dialog to investigate these issues.", MsgBoxStyle.Information, Title:="Duplicates")
End If
Else
ucrInputCheckInput.SetName("No duplicate dates.")
ucrInputCheckInput.SetName("No duplicate dates.")
ucrInputCheckInput.txtInput.BackColor = Color.LightGreen
bIsUnique = True
bIsUnique = True
End If
TestOKEnabled()
End Sub

Private Sub EnableDisableCheckUniqueBtn()
If ucrReceiverDate.IsEmpty Then
cmdCheckUnique.Enabled = False
Else
cmdCheckUnique.Enabled = True
If ucrReceiverDate.IsEmpty Then
cmdCheckUnique.Enabled = False
Else
cmdCheckUnique.Enabled = True
End If
ucrInputCheckInput.SetName("")
ucrInputCheckInput.txtInput.BackColor = SystemColors.Window
Expand Down
8 changes: 5 additions & 3 deletions instat/Enum/OutputType.vb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Public Enum OutputType
Public Enum OutputType
Script = 1
TextOutput = 2
ImageOutput = 4
End Enum
HtmlOutput = 8
'the other reserved numbers are for for bitwise operations
'todo. add the <Flags()> attribute?
End Enum
12 changes: 12 additions & 0 deletions instat/Enum/RObjectFormat.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
''' <summary>
''' represents display formats for R objects that are internally supported by R-Instat
''' at both R and .Net level
''' </summary>
Public Structure RObjectFormat
'-------------------
'note an Enum would have been ideal, but VB.Net does not support String Enums
'------------------
Public Const Image As String = "image"
Public Const Text As String = "text" 'e.g objects of type "table"
Public Const Html As String = "html" 'e.g objects of type "htmlwidget", "sjTable", "gt_tbl"
End Structure
17 changes: 17 additions & 0 deletions instat/Enum/RObjectTypeLabel.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
''' <summary>
''' Represents R object types that are internally supported by R-Instat
''' at both R and .Net level.
''' They correspond to the object labels at R level
''' </summary>
Public Structure RObjectTypeLabel
'-------------------
'note an Enum would have been ideal, but VB.Net does not support String Enums
'------------------
Public Const Dataframe As String = "dataframe"
Public Const Column As String = "column"
Public Const Graph As String = "graph"
Public Const Table As String = "table"
Public Const Model As String = "model"
Public Const StructureLabel As String = "structure" ' e.g Survival objects
Public Const Summary As String = "summary" ' e.g objects of text formats
End Structure
79 changes: 53 additions & 26 deletions instat/Model/Output/clsOutputElement.vb
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,37 @@
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Imports RScript

''' <summary>
''' Output element for a r command, the output element could be just the script or the script with
''' an image or output text
''' </summary>
Public Class clsOutputElement
Private _formattedRScript As List(Of clsRScriptElement)
Private _id As Integer
Private _lstBmpImage As List(Of Bitmap)
Private _lstStringOutput As List(Of String)
'hold the script elements that form the R script that produced the output
Private _lstRScriptElements As New List(Of clsRScriptElement)

Private _outputType As OutputType

''' <summary>
''' Constructor
''' </summary>
Public Sub New()
_formattedRScript = New List(Of clsRScriptElement)
_lstStringOutput = New List(Of String)
_lstBmpImage = New List(Of Bitmap)
End Sub
'todo. deprecate this list with _lstTextOutput ?
Private _lstStringOutput As New List(Of String)

'holds the file paths to the text outputs
Private _lstTextOutput As New List(Of String)

'holds the file paths to the image outputs
Private _lstImageOutput As New List(Of String)

'holds the file paths to the html outputs
Private _lstHtmlOutput As New List(Of String)

''' <summary>
''' Holds formated R Script, split into R Script Elements
''' </summary>
''' <returns></returns>
Public ReadOnly Property FormatedRScript As List(Of clsRScriptElement)
Public ReadOnly Property FormattedRScript As List(Of clsRScriptElement)
Get
Return _formattedRScript
Return _lstRScriptElements
End Get
End Property

Expand All @@ -59,13 +60,25 @@ Public Class clsOutputElement
End Set
End Property

Public ReadOnly Property TextOutput As String
Get
Return _lstTextOutput.FirstOrDefault()
End Get
End Property

''' <summary>
''' Holds image if outputType is image
''' Holds image file path if outputType is image file
''' </summary>
''' <returns></returns>
Public ReadOnly Property ImageOutput As Bitmap
Public ReadOnly Property ImageOutput As String
Get
Return _lstImageOutput.FirstOrDefault()
End Get
End Property

Public ReadOnly Property HtmlOutput As String
Get
Return _lstBmpImage.FirstOrDefault()
Return _lstHtmlOutput.FirstOrDefault()
End Get
End Property

Expand All @@ -89,20 +102,35 @@ Public Class clsOutputElement
End Get
End Property

'this does a shallow clone
'todo. add a deep clone implementation
Public Function Clone() As clsOutputElement
Return Me.MemberwiseClone
End Function

Public Sub AddTextOutput(strFileName As String, script As List(Of clsRScriptElement))
_lstTextOutput.Add(strFileName)
_lstRScriptElements = script
_outputType = OutputType.TextOutput
End Sub

''' <summary>
''' When adding Output the script must always be added too
''' </summary>
''' <param name="image"></param>
Public Sub AddImageOutputFromR(image As Bitmap, script As List(Of clsRScriptElement))
_lstBmpImage.Add(image)
_formattedRScript = script
''' <param name="strFileName"></param>
''' <param name="script"></param>
Public Sub AddImageOutput(strFileName As String, script As List(Of clsRScriptElement))
_lstImageOutput.Add(strFileName)
_lstRScriptElements = script
_outputType = OutputType.ImageOutput
End Sub

Public Sub AddHtmlOutput(strFileName As String, script As List(Of clsRScriptElement))
_lstHtmlOutput.Add(strFileName)
_lstRScriptElements = script
_outputType = OutputType.HtmlOutput
End Sub

''' <summary>
''' Adds script and passes through RScript to split into elements
''' </summary>
Expand All @@ -111,10 +139,9 @@ Public Class clsOutputElement
Try
Dim rScript As New clsRScript(strScript)
Dim lstTokens As List(Of clsRToken) = rScript.GetLstTokens(rScript.GetLstLexemes(strScript)) 'rScript.lstTokens

If lstTokens IsNot Nothing Then
For Each rToken In lstTokens
_formattedRScript.Add(New clsRScriptElement With
_lstRScriptElements.Add(New clsRScriptElement With
{
.Text = rToken.strTxt,
.Type = rToken.enuToken
Expand All @@ -135,9 +162,9 @@ Public Class clsOutputElement
''' When adding Output the script must always be added too
''' </summary>
''' <param name="strOutput"></param>
Public Sub AddStringOutputFromR(strOutput As String, script As List(Of clsRScriptElement))
Public Sub AddStringOutput(strOutput As String, script As List(Of clsRScriptElement))
_lstStringOutput.Add(strOutput)
_formattedRScript = script
_lstRScriptElements = script
_outputType = OutputType.TextOutput
End Sub

Expand Down
Loading

0 comments on commit 2bcd5ce

Please sign in to comment.