Skip to content

Commit

Permalink
Merge pull request #510 from IDEMSInternational/master
Browse files Browse the repository at this point in the history
updated my master
  • Loading branch information
Patowhiz authored Dec 19, 2024
2 parents ebe5593 + c1c4ed4 commit f4ed1f0
Show file tree
Hide file tree
Showing 25 changed files with 1,726 additions and 1,052 deletions.
365 changes: 200 additions & 165 deletions instat/DlgDefineClimaticData.Designer.vb

Large diffs are not rendered by default.

45 changes: 36 additions & 9 deletions instat/DlgDefineClimaticData.vb
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ Public Class DlgDefineClimaticData
Dim kvpLongitude As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("lon", {"lon", "lont", "longitude"}.ToList())
Dim kvpLatitude As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("lat", {"lat", "latitude"}.ToList())
Dim kvpCloudCover As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("cloud_cover", {"cloud", "cldtot"}.ToList())
Dim kvpTempMax As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("temp_max", {"tmax", "tx", "tempmax", "tmp_max", "tmpmax"}.ToList())
Dim kvpTempMin As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("temp_min", {"tmin", "tn", "tempmin", "tmp_min", "tmpmin"}.ToList())
Dim kvpTempMax As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("temp_max", {"temp_max", "tmax", "tx", "tempmax", "tmp_max", "tmpmax"}.ToList())
Dim kvpTempMin As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("temp_min", {"temp_min", "tmin", "tn", "tempmin", "tmp_min", "tmpmin"}.ToList())
Dim kvpRadiation As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("radiation", {"radiation", "rad", "radgls", "radsky", "radres", "radnaw", "raddwn", "radup", "raddsl"}.ToList())
Dim kvpSunshineHours As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("sunshine_hours", {"sunshine", "sunh", "sunhrs", "sun"}.ToList())
Dim kvpWindDirection As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("wind_direction", {"winddirection", "pkgstd"}.ToList())
Dim kvpWindSpeed As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("wind_speed", {"windspeed", "wndspd", "pkgust", "pkgstd", "wndmil"}.ToList())
Dim kvpSunshineHours As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("sunshine_hours", {"sunshine_hours", "sunshine", "sunh", "sunhrs", "sun"}.ToList())
Dim kvpWindDirection As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("wind_direction", {"wind_direction", "winddirection", "pkgstd"}.ToList())
Dim kvpWindSpeed As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("wind_speed", {"wind_speed", "windspeed", "wndspd", "pkgust", "pkgstd", "wndmil"}.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", "rhmin"}.ToList())
Dim kvpMaxRH As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("hum_max", {"maxhum", "hmax", "hx", "rhmax"}.ToList())
Dim kvpMinRH As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("hum_min", {"hum_min", "minhum", "hmin", "hn", "rhmin"}.ToList())
Dim kvpMaxRH As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("hum_max", {"hum_max", "maxhum", "hmax", "hx", "rhmax"}.ToList())

lstRecognisedTypes.AddRange({kvpRain, kvpDistrict, kvpCloudCover, kvpTempMax, kvpTempMin, kvpRadiation, kvpSunshineHours, kvpStation, kvpAltitude, kvpLatitude, kvpLongitude,
kvpWindDirection, kvpWindSpeed, kvpYear, kvpMonth, kvpDay, kvpDOY, kvpDate, kvpMinRH, kvpMaxRH})
Expand Down Expand Up @@ -237,8 +237,9 @@ Public Class DlgDefineClimaticData

If lstRecognisedValues.Count > 0 Then
For Each lviTempVariable As ListViewItem In ucrSelectorDefineClimaticData.lstAvailableVariable.Items
Dim strClimaticType As String = GetClimaticTypeFromRCommand(lviTempVariable.Text)
For Each strValue As String In lstRecognisedValues
If Regex.Replace(lviTempVariable.Text.ToLower(), "[^\w]|_", String.Empty).Contains(strValue) Then
If Regex.Replace(lviTempVariable.Text.ToLower(), "[^\w]|_", String.Empty).Contains(strValue) OrElse (strClimaticType IsNot Nothing AndAlso strClimaticType.Contains(strValue)) Then
ucrTempReceiver.Add(lviTempVariable.Text, ucrSelectorDefineClimaticData.ucrAvailableDataFrames.cboAvailableDataFrames.Text)
bFound = True
Exit For
Expand Down Expand Up @@ -270,8 +271,9 @@ Public Class DlgDefineClimaticData

If lstRecognisedValues.Count > 0 Then
For Each lviTempVariable As ListViewItem In ucrSelectorLinkedDataFrame.lstAvailableVariable.Items
Dim strClimaticType As String = GetClimaticTypeFromRCommand(lviTempVariable.Text)
For Each strValue As String In lstRecognisedValues
If Regex.Replace(lviTempVariable.Text.ToLower(), "[^\w]|_", String.Empty).Contains(strValue) Then
If Regex.Replace(lviTempVariable.Text.ToLower(), "[^\w]|_", String.Empty).Contains(strValue) OrElse (strClimaticType IsNot Nothing AndAlso strClimaticType.Contains(strValue)) Then
ucrTempReceiver.Add(lviTempVariable.Text, ucrSelectorLinkedDataFrame.ucrAvailableDataFrames.cboAvailableDataFrames.Text)
bFound = True
Exit For
Expand All @@ -290,6 +292,31 @@ Public Class DlgDefineClimaticData
End If
End Sub

Private Function GetClimaticTypeFromRCommand(strName As String) As String
Try
Dim clsGetClimaticTypeFunction As New RFunction

clsGetClimaticTypeFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_column_climatic_type")
clsGetClimaticTypeFunction.AddParameter("attr_name", Chr(34) & "Climatic_Type" & Chr(34))
clsGetClimaticTypeFunction.AddParameter("col_name", Chr(34) & strName & Chr(34))
clsGetClimaticTypeFunction.AddParameter("data_name", Chr(34) & ucrSelectorLinkedDataFrame.strCurrentDataFrame & Chr(34))

Dim result As SymbolicExpression
result = frmMain.clsRLink.RunInternalScriptGetValue(clsGetClimaticTypeFunction.ToScript())

' Check if result is Nothing or has no values before trying to access
If result IsNot Nothing AndAlso result.Type <> Internals.SymbolicExpressionType.Null Then
Dim strClimaticType As String = result.AsCharacter(0)
If Not String.IsNullOrEmpty(strClimaticType) Then
Return strClimaticType
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return String.Empty
End Function

Private Function GetRecognisedValues(strVariable As String) As List(Of String)
Dim lstValues As New List(Of String)

Expand Down
12 changes: 12 additions & 0 deletions instat/UserControls/DataGrid/ReoGrid/ucrDataViewReoGrid.vb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ Public Class ucrDataViewReoGrid
Dim strData As String = dataFrame.DisplayedData(i, j)
If strData IsNot Nothing AndAlso grdData.CurrentWorksheet.ColumnHeaders.Item(j).Text.Contains("(LT)") Then
strData = GetTransformedLTColumnContents(strData)
ElseIf strData IsNot Nothing AndAlso grdData.CurrentWorksheet.ColumnHeaders.Item(j).Text.Contains("(G)") Then
strData = ShortenString(strData)
grdData.CurrentWorksheet.GetCell(row:=i, col:=j).IsReadOnly = True
End If
grdData.CurrentWorksheet(row:=i, col:=j) = strData
Next
Expand All @@ -111,6 +114,15 @@ Public Class ucrDataViewReoGrid
grdData.CurrentWorksheet.RowHeaderWidth = TextRenderer.MeasureText(strLongestRowHeaderText, Me.Font).Width
End Sub

Private Function ShortenString(strText As String) As String
Dim maxLength As Integer = 30
If strText.Length > maxLength Then
' Trim the string to the specified length and add ellipsis
Return strText.Substring(0, maxLength) & "..."
End If
Return strText
End Function

''' <summary>
''' Transforms contents of LT column(s) that have structured R-like data into a more readable and user-friendly format that is consistent with R Viewer.
''' For example, content like list(Birmingham = list(IATA = c("BHM", NA, NA, NA), Hartford = list(IATA = "BDL", ICAO = "KBDL"))
Expand Down
17 changes: 17 additions & 0 deletions instat/clsInstatOptions.vb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Imports RDotNet
Public bIncludeRDefaultParameters As Nullable(Of Boolean)
Public iPreviewRows As Nullable(Of Integer)
Public iMaxRows As Nullable(Of Integer)
Public iMaxWidth As Nullable(Of Integer)
Public iMaxCols As Nullable(Of Integer)
Public iUndoColLimit As Nullable(Of Integer)
Public iUndoRowLimit As Nullable(Of Integer)
Expand Down Expand Up @@ -78,6 +79,7 @@ Imports RDotNet
clrEditor = clsInstatOptionsDefaults.DEFAULTclrEditor
iPreviewRows = clsInstatOptionsDefaults.DEFAULTiPreviewRows
iMaxRows = clsInstatOptionsDefaults.DEFAULTiMaxRows
iMaxWidth = clsInstatOptionsDefaults.DEFAULTiMaxWidth
iMaxCols = clsInstatOptionsDefaults.DEFAULTiMaxCols
iUndoColLimit = clsInstatOptionsDefaults.DEFAULTiUndoColLimit
iUndoRowLimit = clsInstatOptionsDefaults.DEFAULTiUndoRowLimit
Expand Down Expand Up @@ -145,6 +147,12 @@ Imports RDotNet
SetMaxRows(clsInstatOptionsDefaults.DEFAULTiMaxRows)
End If

If iMaxWidth.HasValue Then
SetMaxWidth(iMaxWidth)
Else
SetMaxWidth(clsInstatOptionsDefaults.DEFAULTiMaxWidth)
End If

If iMaxCols.HasValue Then
SetMaxCols(iMaxCols)
Else
Expand Down Expand Up @@ -348,6 +356,11 @@ Imports RDotNet
clsOptionsFunction.AddParameter("dplyr.summarise.inform", "FALSE")
End If

strROption = GetROption("width")
If strROption Is Nothing OrElse strROption <> iMaxWidth.ToString Then
clsOptionsFunction.AddParameter("width", iMaxWidth)
End If

'add "R.commands.displayed.in.the.output.window" as options parameter of its been changed
If frmMain.mnuShowRCommand.Checked Then
clsOptionsFunction.AddParameter("R.commands.displayed.in.the.output.window", "TRUE")
Expand Down Expand Up @@ -394,6 +407,10 @@ Imports RDotNet
frmMain.UpdateAllGrids()
End Sub

Public Sub SetMaxWidth(iNewMaxWidth As Integer)
iMaxWidth = iNewMaxWidth
'frmMain.UpdateAllGrids()
End Sub
Public Sub SetMaxCols(iCols As Integer)
iMaxCols = iCols
frmMain.UpdateAllGrids()
Expand Down
1 change: 1 addition & 0 deletions instat/clsInstatOptionsDefaults.vb
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ Public Class clsInstatOptionsDefaults
Public Shared ReadOnly DEFAULTstrClimsoftPort As String = "3308"
Public Shared ReadOnly DEFAULTstrClimsoftUsername As String = "root"
Public Shared ReadOnly DEFAULTiMaxOutputsHeight As Integer = 500
Public Shared ReadOnly DEFAULTiMaxWidth As Integer = 80
Public Shared ReadOnly DEFAULTbRemindLaterOption As Boolean = False
End Class
46 changes: 45 additions & 1 deletion instat/dlgClimograph.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f4ed1f0

Please sign in to comment.