From 5d63dd7120287f33df84558b47b09373ed6536c7 Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Mon, 28 Oct 2024 12:36:06 +0100 Subject: [PATCH 1/9] Added Filled in column in End Of Season Dialog. --- instat/dlgEndOfRainsSeason.vb | 93 +++++++++++++++++++++++++++++++++-- instat/sdgDoyRange.vb | 7 ++- 2 files changed, 94 insertions(+), 6 deletions(-) diff --git a/instat/dlgEndOfRainsSeason.vb b/instat/dlgEndOfRainsSeason.vb index 8bf2b645f9b..cd3d0a4de27 100644 --- a/instat/dlgEndOfRainsSeason.vb +++ b/instat/dlgEndOfRainsSeason.vb @@ -26,10 +26,11 @@ Public Class dlgEndOfRainsSeason Private strEvapReplaceNA As String = "evap_NA_as_value" Private strCurrDataName As String = "" Private iCapacityDefault As Integer = 60 + Private strYearType As String = "year_type" #Region "general_code_structures" ' General - Private clsRunCalculation, clsListCalFunction, clsDummyFunction As New RFunction + Private clsVectorFunction, clsGetlinkeddataFunction, clsConvertColumnType1Function, clsConvertColumnType2Function, clsGetColumnDataTypeFunction, clsConvertColumnTypeFunction, clsRunCalculation, clsListCalFunction, clsDummyFunction As New RFunction Private clsFirstOrLastFunction As New RFunction ' Group by @@ -139,7 +140,9 @@ Public Class dlgEndOfRainsSeason ' Doy summary Private clsEndSeasonFirstDoySummaryCalc As New RFunction + Private clsEndSeasonFirstDoySummaryCalcFilledFunction As New RFunction Private clsIfElseFirstDoyFunction As New RFunction + Public clsIfElseFirstDoyFilledFunction As New RFunction Private clsIsNaFirstWB As New RFunction Private clsFirstDoyFunction As New RFunction Private clsFirstWBFunction As New RFunction @@ -354,18 +357,25 @@ Public Class dlgEndOfRainsSeason Dim strEndRainsStatus As String = "end_rains_status" Dim strEndRainsDate As String = "end_rains_date" Dim strEndSeason As String = "end_season" + Dim strEndSeasonFilled As String = "end_season_filled" Dim strEndSeasonStatus As String = "end_season_status" Dim strEndSeasonDate As String = "end_season_date" Dim strDoyFilter As String = "doy_filter" Dim strEndofRains As String = "end_of_rains_combined" Dim strEndofSeason As String = "end_of_season_combined" + clsGetlinkeddataFunction = New RFunction + clsVectorFunction = New RFunction + #Region "clear_code_structures" ' General clsRunCalculation.Clear() clsListCalFunction.Clear() clsFirstOrLastFunction.Clear() - + clsConvertColumnTypeFunction.Clear() + clsConvertColumnType2Function.Clear() + clsGetColumnDataTypeFunction.Clear() + clsConvertColumnType1Function.Clear() ' Group by clsGroupByStationYearCalc.Clear() clsGroupByStationCalc.Clear() @@ -471,7 +481,9 @@ Public Class dlgEndOfRainsSeason ' Doy summary clsEndSeasonFirstDoySummaryCalc.Clear() + clsEndSeasonFirstDoySummaryCalcFilledFunction.Clear() clsIfElseFirstDoyFunction.Clear() + clsIfElseFirstDoyFilledFunction.Clear() clsIsNaFirstWB.Clear() clsFirstDoyFunction.Clear() clsFirstWBFunction.Clear() @@ -653,8 +665,8 @@ Public Class dlgEndOfRainsSeason clsListCalFunction.AddParameter("drop", "FALSE", iPosition:=0) clsRunCalculation.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$run_instat_calculation") - clsRunCalculation.AddParameter("display", "FALSE") - clsRunCalculation.AddParameter("calc", clsRFunctionParameter:=clsEndRainsCombinationCalc) + clsRunCalculation.AddParameter("display", "FALSE", iPosition:=0) + clsRunCalculation.AddParameter("calc", clsRFunctionParameter:=clsEndRainsCombinationCalc, iPosition:=1) clsRunCalculation.AddParameter("param_list", clsRFunctionParameter:=clsListCalFunction, iPosition:=2) ucrBase.clsRsyntax.SetBaseRFunction(clsRunCalculation) @@ -865,12 +877,25 @@ Public Class dlgEndOfRainsSeason clsEndSeasonFirstDoySummaryCalc.AddParameter("save", "2", iPosition:=6) clsEndSeasonFirstDoySummaryCalc.SetAssignTo(strEndSeason) + clsEndSeasonFirstDoySummaryCalcFilledFunction.SetRCommand("instat_calculation$new") + clsEndSeasonFirstDoySummaryCalcFilledFunction.AddParameter("type", Chr(34) & "summary" & Chr(34), iPosition:=0) + clsEndSeasonFirstDoySummaryCalcFilledFunction.AddParameter("function_exp", clsRFunctionParameter:=clsIfElseFirstDoyFilledFunction, iPosition:=1) + clsEndSeasonFirstDoySummaryCalcFilledFunction.AddParameter("result_name", Chr(34) & strEndSeasonFilled & Chr(34), iPosition:=2) + clsEndSeasonFirstDoySummaryCalcFilledFunction.AddParameter("save", "2", iPosition:=6) + clsEndSeasonFirstDoySummaryCalcFilledFunction.SetAssignTo(strEndSeasonFilled) + clsIfElseFirstDoyFunction.bToScriptAsRString = True clsIfElseFirstDoyFunction.SetRCommand("ifelse") clsIfElseFirstDoyFunction.AddParameter("test", clsRFunctionParameter:=clsIsNaFirstWB, iPosition:=0) clsIfElseFirstDoyFunction.AddParameter("yes", "NA", iPosition:=1) clsIfElseFirstDoyFunction.AddParameter("no", clsRFunctionParameter:=clsFirstDoyFunction, iPosition:=2) + clsIfElseFirstDoyFilledFunction.bToScriptAsRString = True + clsIfElseFirstDoyFilledFunction.SetRCommand("ifelse") + clsIfElseFirstDoyFilledFunction.AddParameter("test", clsRFunctionParameter:=clsIsNaFirstWB, iPosition:=0) + clsIfElseFirstDoyFilledFunction.AddParameter("yes", "366", iPosition:=1) + clsIfElseFirstDoyFilledFunction.AddParameter("no", clsRFunctionParameter:=clsFirstDoyFunction, iPosition:=2) + clsIsNaFirstWB.SetRCommand("is.na") clsIsNaFirstWB.AddParameter("x", clsRFunctionParameter:=clsFirstWBFunction, iPosition:=0) @@ -921,7 +946,31 @@ Public Class dlgEndOfRainsSeason clsEndSeasonCombinationSubCalcList.SetRCommand("list") clsEndSeasonCombinationSubCalcList.AddParameter("sub1", clsRFunctionParameter:=clsEndSeasonFirstDoySummaryCalc, bIncludeArgumentName:=False, iPosition:=0) + + clsGetColumnDataTypeFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_column_data_types") + clsGetColumnDataTypeFunction.SetAssignTo(strYearType) + + clsConvertColumnTypeFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_column_to_type") + clsConvertColumnTypeFunction.AddParameter("to_type", Chr(34) & "factor" & Chr(34), iPosition:=2) + + clsGetlinkeddataFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_linked_to_data_name") + clsGetlinkeddataFunction.SetAssignTo("linked_data_name") + + clsVectorFunction.SetRCommand("c") + + clsConvertColumnType2Function.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_column_to_type") + clsConvertColumnType2Function.AddParameter("data_name", "linked_data_name", iPosition:=0) + clsConvertColumnType2Function.AddParameter("to_type", "year_type", iPosition:=2) + + clsConvertColumnType1Function.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_column_to_type") + clsConvertColumnType1Function.AddParameter("to_type", "year_type", iPosition:=2) + #End Region + ucrBase.clsRsyntax.AddToBeforeCodes(clsGetColumnDataTypeFunction, iPosition:=0) + ucrBase.clsRsyntax.AddToBeforeCodes(clsConvertColumnTypeFunction, iPosition:=1) + ucrBase.clsRsyntax.AddToAfterCodes(clsGetlinkeddataFunction, iPosition:=0) + ucrBase.clsRsyntax.AddToAfterCodes(clsConvertColumnType1Function, iPosition:=1) + ucrBase.clsRsyntax.AddToAfterCodes(clsConvertColumnType2Function, iPosition:=2) clsFirstOrLastFunction = clsLastDoyFunction End Sub @@ -1011,7 +1060,7 @@ Public Class dlgEndOfRainsSeason End Sub Private Sub cmdDoyRange_Click(sender As Object, e As EventArgs) Handles cmdDoyRange.Click - sdgDoyRange.Setup(clsNewDoyFilterCalc:=clsDoyFilterCalc, clsNewDayFromOperator:=clsDayFromOperator, clsNewDayToOperator:=clsDayToOperator, clsNewCalcFromList:=clsDoyFilterCalcFromList, strNewMainDataFrame:=ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text, strNewDoyColumn:=ucrReceiverDOY.GetVariableNames(False)) + sdgDoyRange.Setup(clsNewDoyFilterCalc:=clsDoyFilterCalc, clsNewDayFromOperator:=clsDayFromOperator, clsNewIfElseFirstDoyFilledFunction:=clsIfElseFirstDoyFilledFunction, clsNewDayToOperator:=clsDayToOperator, clsNewCalcFromList:=clsDoyFilterCalcFromList, strNewMainDataFrame:=ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text, strNewDoyColumn:=ucrReceiverDOY.GetVariableNames(False)) sdgDoyRange.ShowDialog() UpdateDayFilterPreview() End Sub @@ -1046,6 +1095,7 @@ Public Class dlgEndOfRainsSeason clsEndRainsLastDoySummaryCalc.AddParameter("calculated_from", "list(" & strCurrDataName & "=" & ucrReceiverDOY.GetVariableNames() & ")", iPosition:=3) clsEndSeasonFirstDoySummaryCalc.AddParameter("calculated_from", "list(" & strCurrDataName & "=" & ucrReceiverDOY.GetVariableNames() & ")", iPosition:=3) clsEndRainsLastDateSummaryCalc.AddParameter("calculated_from", "list(" & strCurrDataName & "=" & ucrReceiverDate.GetVariableNames() & ")", iPosition:=3) + clsEndSeasonFirstDoySummaryCalcFilledFunction.AddParameter("calculated_from", "list(" & strCurrDataName & "=" & ucrReceiverDOY.GetVariableNames() & ")", iPosition:=3) End Sub Private Sub RainfallChange() @@ -1054,8 +1104,35 @@ Public Class dlgEndOfRainsSeason clsEndSeasonRainMaxCalc.AddParameter("calculated_from", "list(" & strCurrDataName & "=" & ucrReceiverRainfall.GetVariableNames & ")", iPosition:=3) End Sub + Private Sub YearStationVariable() + If Not ucrReceiverYear.IsEmpty Then + clsVectorFunction.AddParameter("x", ucrReceiverYear.GetVariableNames(), iPosition:=0, bIncludeArgumentName:=False) + If Not ucrReceiverStation.IsEmpty Then + clsVectorFunction.AddParameter("y", ucrReceiverStation.GetVariableNames(), iPosition:=1, bIncludeArgumentName:=False) + Else + clsVectorFunction.RemoveParameterByName("y") + End If + clsGetlinkeddataFunction.AddParameter("link_cols", clsRFunctionParameter:=clsVectorFunction, iPosition:=1) + Else + clsGetlinkeddataFunction.RemoveParameterByName("link_cols") + clsVectorFunction.RemoveParameterByName("x") + End If + End Sub + Private Sub ucrReceiverStationYear_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverYear.ControlValueChanged, ucrReceiverStation.ControlValueChanged GroupingBy() + YearStationVariable() + If Not ucrReceiverYear.IsEmpty Then + clsGetColumnDataTypeFunction.AddParameter("columns", ucrReceiverYear.GetVariableNames(), iPosition:=1) + clsConvertColumnTypeFunction.AddParameter("col_names", ucrReceiverYear.GetVariableNames(), iPosition:=1) + clsConvertColumnType1Function.AddParameter("col_names", ucrReceiverYear.GetVariableNames(), iPosition:=1) + clsConvertColumnType2Function.AddParameter("col_names", ucrReceiverYear.GetVariableNames(), iPosition:=1) + Else + clsConvertColumnType1Function.RemoveParameterByName("col_names") + clsConvertColumnType2Function.RemoveParameterByName("col_names") + clsGetColumnDataTypeFunction.RemoveParameterByName("columns") + clsConvertColumnTypeFunction.RemoveParameterByName("col_names") + End If End Sub Private Sub ucrReceiverDOY_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverDOY.ControlValueChanged, ucrSelectorForWaterBalance.ControlValueChanged @@ -1076,6 +1153,10 @@ Public Class dlgEndOfRainsSeason Private Sub ucrSelectorForWaterBalance_DataFrameChanged() Handles ucrSelectorForWaterBalance.DataFrameChanged clsDoyFilterCalcFromList.ClearParameters() + clsGetColumnDataTypeFunction.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) + clsConvertColumnTypeFunction.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) + clsConvertColumnType1Function.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) + clsGetlinkeddataFunction.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0, bIncludeArgumentName:=False) End Sub Private Sub ucrPnlEvaporation_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlEvaporation.ControlValueChanged, ucrReceiverEvaporation.ControlValueChanged, ucrInputEvaporation.ControlValueChanged @@ -1173,8 +1254,10 @@ Public Class dlgEndOfRainsSeason Private Sub ucrChkEndofSeasonDoy_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkEndofSeasonDoy.ControlValueChanged If ucrChkEndofSeasonDoy.Checked Then clsEndSeasonCombinationSubCalcList.AddParameter("sub1", clsRFunctionParameter:=clsEndSeasonFirstDoySummaryCalc, bIncludeArgumentName:=False, iPosition:=0) + clsEndSeasonCombinationSubCalcList.AddParameter("sub4", clsRFunctionParameter:=clsEndSeasonFirstDoySummaryCalcFilledFunction, bIncludeArgumentName:=False, iPosition:=3) Else clsEndSeasonCombinationSubCalcList.RemoveParameterByName("sub1") + clsEndSeasonCombinationSubCalcList.RemoveParameterByName("sub4") End If End Sub diff --git a/instat/sdgDoyRange.vb b/instat/sdgDoyRange.vb index a8a2d55b020..cab5c87e4e7 100644 --- a/instat/sdgDoyRange.vb +++ b/instat/sdgDoyRange.vb @@ -21,6 +21,7 @@ Public Class sdgDoyRange Private clsDoyFilterCalc As RFunction Private clsCalcFromList As RFunction Private clsCalcFromMainDataFrame As RFunction + Public clsIfElseFirstDoyFilledFunction As RFunction Private clsDayFromOperator As ROperator Private clsDayToOperator As ROperator Private bControlsInitialised As Boolean = False @@ -32,7 +33,7 @@ Public Class sdgDoyRange autoTranslate(Me) End Sub - Public Sub Setup(clsNewDoyFilterCalc As RFunction, clsNewDayFromOperator As ROperator, clsNewDayToOperator As ROperator, clsNewCalcFromList As RFunction, strNewMainDataFrame As String, strNewDoyColumn As String) + Public Sub Setup(clsNewDoyFilterCalc As RFunction, clsNewDayFromOperator As ROperator, clsNewDayToOperator As ROperator, clsNewCalcFromList As RFunction, strNewMainDataFrame As String, strNewDoyColumn As String, Optional clsNewIfElseFirstDoyFilledFunction As RFunction = Nothing) Dim iFrom As Integer Dim iTo As Integer Dim iDiff As Integer @@ -55,6 +56,7 @@ Public Class sdgDoyRange End If clsDoyFilterCalc = clsNewDoyFilterCalc clsCalcFromList = clsNewCalcFromList + clsIfElseFirstDoyFilledFunction = clsNewIfElseFirstDoyFilledFunction strMainDataFrame = strNewMainDataFrame strDoyColumn = strNewDoyColumn @@ -217,8 +219,10 @@ Public Class sdgDoyRange If bUpdate Then If rdoToFixed.Checked Then clsDayToOperator.AddParameter("to", strParameterValue:=ucrDoyTo.GetValue(), iPosition:=1) + clsIfElseFirstDoyFilledFunction.AddParameter("yes", strParameterValue:=ucrDoyTo.GetValue(), iPosition:=1) ElseIf rdoToVariable.Checked Then clsDayToOperator.AddParameter("to", strParameterValue:=ucrReceiverTo.GetVariableNames(False), iPosition:=1) + clsIfElseFirstDoyFilledFunction.AddParameter("yes", strParameterValue:=ucrReceiverTo.GetVariableNames(False), iPosition:=1) ElseIf rdoLength.Checked Then clsFixedDiffOp.SetOperation("+") If clsDayFromOperator.ContainsParameter("from") Then @@ -226,6 +230,7 @@ Public Class sdgDoyRange clsFixedDiffOp.AddParameter("diff", strParameterValue:=ucrNudToDiff.Value, iPosition:=1) clsFixedDiffOp.bBrackets = True clsDayToOperator.AddParameter("to", clsROperatorParameter:=clsFixedDiffOp, iPosition:=1) + clsIfElseFirstDoyFilledFunction.AddParameter("yes", clsROperatorParameter:=clsFixedDiffOp, iPosition:=1) End If End If UpdateCalculatedFrom() From c58fca3bfdd4f0a29faadebb2c3ca8e015014692 Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Thu, 31 Oct 2024 09:11:25 +0100 Subject: [PATCH 2/9] Change made --- instat/dlgEndOfRainsSeason.vb | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/instat/dlgEndOfRainsSeason.vb b/instat/dlgEndOfRainsSeason.vb index cd3d0a4de27..0bf92d90214 100644 --- a/instat/dlgEndOfRainsSeason.vb +++ b/instat/dlgEndOfRainsSeason.vb @@ -153,7 +153,7 @@ Public Class dlgEndOfRainsSeason Private clsFirstDateFunction As New RFunction ' Status summary - Private clsEndSeasonStatusSummaryCalc As New RFunction + Private clsEndSeasonStatusSummaryCalc, clsIsNAStatusFunction, clsFirstStatusFunction, clsIfelseStatusFunction, clsIfelseStatus1Function As New RFunction ' Combination Private clsEndSeasonCombinationCalc As New RFunction @@ -414,6 +414,10 @@ Public Class dlgEndOfRainsSeason ' Status summary clsEndRainsStatusSummaryCalc.Clear() + clsIfelseStatusFunction.Clear() + clsIfelseStatus1Function.Clear() + clsFirstStatusFunction.Clear() + clsIsNAStatusFunction.Clear() ' Combination clsEndRainsCombinationCalc.Clear() @@ -669,7 +673,6 @@ Public Class dlgEndOfRainsSeason clsRunCalculation.AddParameter("calc", clsRFunctionParameter:=clsEndRainsCombinationCalc, iPosition:=1) clsRunCalculation.AddParameter("param_list", clsRFunctionParameter:=clsListCalFunction, iPosition:=2) - ucrBase.clsRsyntax.SetBaseRFunction(clsRunCalculation) #End Region #Region "end_of_season" @@ -927,11 +930,30 @@ Public Class dlgEndOfRainsSeason ' Status summary clsEndSeasonStatusSummaryCalc.SetRCommand("instat_calculation$new") clsEndSeasonStatusSummaryCalc.AddParameter("type", Chr(34) & "summary" & Chr(34), iPosition:=0) - clsEndSeasonStatusSummaryCalc.AddParameter("function_exp", Chr(34) & "n() > 0" & Chr(34), iPosition:=1) + clsEndSeasonStatusSummaryCalc.AddParameter("function_exp", clsRFunctionParameter:=clsIfelseStatusFunction, iPosition:=1) clsEndSeasonStatusSummaryCalc.AddParameter("result_name", Chr(34) & strEndSeasonStatus & Chr(34), iPosition:=3) clsEndSeasonStatusSummaryCalc.AddParameter("save", 2, iPosition:=4) clsEndSeasonStatusSummaryCalc.SetAssignTo(strEndSeasonStatus) + + clsIfelseStatusFunction.SetRCommand("ifelse") + clsIfelseStatusFunction.bToScriptAsRString = True + clsIfelseStatusFunction.AddParameter("x", "n() > 0", iPosition:=0, bIncludeArgumentName:=False) + clsIfelseStatusFunction.AddParameter("y", clsRFunctionParameter:=clsIfelseStatus1Function, iPosition:=1, bIncludeArgumentName:=False) + clsIfelseStatusFunction.AddParameter("z", "FALSE", iPosition:=2, bIncludeArgumentName:=False) + + clsIfelseStatus1Function.SetRCommand("ifelse") + clsIfelseStatus1Function.AddParameter("yes", clsRFunctionParameter:=clsFirstStatusFunction, iPosition:=0, bIncludeArgumentName:=False) + clsIfelseStatus1Function.AddParameter("test", "NA", iPosition:=1, bIncludeArgumentName:=False) + clsIfelseStatus1Function.AddParameter("no", "TRUE", iPosition:=2, bIncludeArgumentName:=False) + + clsFirstStatusFunction.SetPackageName("dplyr") + clsFirstStatusFunction.SetRCommand("first") + clsFirstStatusFunction.AddParameter("x", clsRFunctionParameter:=clsIsNAStatusFunction, iPosition:=0, bIncludeArgumentName:=False) + + clsIsNAStatusFunction.SetRCommand("is.na") + clsIsNAStatusFunction.AddParameter("x", strWB, iPosition:=0, bIncludeArgumentName:=False) + ' Combined clsEndSeasonCombinationCalc.SetRCommand("instat_calculation$new") clsEndSeasonCombinationCalc.AddParameter("type", Chr(34) & "combination" & Chr(34), iPosition:=0) @@ -946,6 +968,9 @@ Public Class dlgEndOfRainsSeason clsEndSeasonCombinationSubCalcList.SetRCommand("list") clsEndSeasonCombinationSubCalcList.AddParameter("sub1", clsRFunctionParameter:=clsEndSeasonFirstDoySummaryCalc, bIncludeArgumentName:=False, iPosition:=0) + clsEndSeasonCombinationSubCalcList.AddParameter("sub2", clsRFunctionParameter:=clsEndSeasonFirstDateSummaryCalc, bIncludeArgumentName:=False, iPosition:=1) + clsEndSeasonCombinationSubCalcList.AddParameter("sub3", clsRFunctionParameter:=clsEndRainsStatusSummaryCalc, bIncludeArgumentName:=False, iPosition:=2) + clsEndSeasonCombinationSubCalcList.AddParameter("sub4", clsRFunctionParameter:=clsEndSeasonFirstDoySummaryCalcFilledFunction, bIncludeArgumentName:=False, iPosition:=3) clsGetColumnDataTypeFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_column_data_types") clsGetColumnDataTypeFunction.SetAssignTo(strYearType) @@ -966,11 +991,14 @@ Public Class dlgEndOfRainsSeason clsConvertColumnType1Function.AddParameter("to_type", "year_type", iPosition:=2) #End Region + ucrBase.clsRsyntax.ClearCodes() + ucrBase.clsRsyntax.AddToBeforeCodes(clsGetColumnDataTypeFunction, iPosition:=0) ucrBase.clsRsyntax.AddToBeforeCodes(clsConvertColumnTypeFunction, iPosition:=1) ucrBase.clsRsyntax.AddToAfterCodes(clsGetlinkeddataFunction, iPosition:=0) ucrBase.clsRsyntax.AddToAfterCodes(clsConvertColumnType1Function, iPosition:=1) ucrBase.clsRsyntax.AddToAfterCodes(clsConvertColumnType2Function, iPosition:=2) + ucrBase.clsRsyntax.SetBaseRFunction(clsRunCalculation) clsFirstOrLastFunction = clsLastDoyFunction End Sub From 978e5781249b86f385c96d62f9aa5b062008435c Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Fri, 1 Nov 2024 13:06:46 +0100 Subject: [PATCH 3/9] Added Filled boxe --- instat/dlgEndOfRainsSeason.Designer.vb | 34 +++++++++++++++++++++++--- instat/dlgEndOfRainsSeason.vb | 29 ++++++++++++++++++---- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/instat/dlgEndOfRainsSeason.Designer.vb b/instat/dlgEndOfRainsSeason.Designer.vb index 8b4b8203617..e877a70e9b1 100644 --- a/instat/dlgEndOfRainsSeason.Designer.vb +++ b/instat/dlgEndOfRainsSeason.Designer.vb @@ -52,6 +52,8 @@ Partial Class dlgEndOfRainsSeason Me.rdoVariableEvaporation = New System.Windows.Forms.RadioButton() Me.rdoValueEvaporation = New System.Windows.Forms.RadioButton() Me.grpEndofSeason = New System.Windows.Forms.GroupBox() + Me.ucrInputFilled = New instat.ucrInputTextBox() + Me.ucrChkFilled = New instat.ucrCheck() Me.ucrInputEndofSeasonOccurence = New instat.ucrInputTextBox() Me.ucrInputSeasonDoy = New instat.ucrInputTextBox() Me.ucrInputEndofSeasonDate = New instat.ucrInputTextBox() @@ -214,19 +216,43 @@ Partial Class dlgEndOfRainsSeason ' 'grpEndofSeason ' + Me.grpEndofSeason.Controls.Add(Me.ucrInputFilled) + Me.grpEndofSeason.Controls.Add(Me.ucrChkFilled) Me.grpEndofSeason.Controls.Add(Me.ucrInputEndofSeasonOccurence) Me.grpEndofSeason.Controls.Add(Me.ucrInputSeasonDoy) Me.grpEndofSeason.Controls.Add(Me.ucrInputEndofSeasonDate) Me.grpEndofSeason.Controls.Add(Me.ucrChkEndofSeasonOccurence) Me.grpEndofSeason.Controls.Add(Me.ucrChkEndofSeasonDate) Me.grpEndofSeason.Controls.Add(Me.ucrChkEndofSeasonDoy) - Me.grpEndofSeason.Location = New System.Drawing.Point(3, 426) + Me.grpEndofSeason.Location = New System.Drawing.Point(3, 403) Me.grpEndofSeason.Name = "grpEndofSeason" - Me.grpEndofSeason.Size = New System.Drawing.Size(472, 41) + Me.grpEndofSeason.Size = New System.Drawing.Size(472, 83) Me.grpEndofSeason.TabIndex = 32 Me.grpEndofSeason.TabStop = False Me.grpEndofSeason.Text = "End of Season" ' + 'ucrInputFilled + ' + Me.ucrInputFilled.AddQuotesIfUnrecognised = True + Me.ucrInputFilled.AutoSize = True + Me.ucrInputFilled.IsMultiline = False + Me.ucrInputFilled.IsReadOnly = False + Me.ucrInputFilled.Location = New System.Drawing.Point(121, 53) + Me.ucrInputFilled.Margin = New System.Windows.Forms.Padding(9) + Me.ucrInputFilled.Name = "ucrInputFilled" + Me.ucrInputFilled.Size = New System.Drawing.Size(104, 21) + Me.ucrInputFilled.TabIndex = 49 + ' + 'ucrChkFilled + ' + Me.ucrChkFilled.AutoSize = True + Me.ucrChkFilled.Checked = False + Me.ucrChkFilled.Location = New System.Drawing.Point(4, 53) + Me.ucrChkFilled.Margin = New System.Windows.Forms.Padding(6) + Me.ucrChkFilled.Name = "ucrChkFilled" + Me.ucrChkFilled.Size = New System.Drawing.Size(105, 25) + Me.ucrChkFilled.TabIndex = 50 + ' 'ucrInputEndofSeasonOccurence ' Me.ucrInputEndofSeasonOccurence.AddQuotesIfUnrecognised = True @@ -598,7 +624,7 @@ Partial Class dlgEndOfRainsSeason ' Me.ucrBase.AutoSize = True Me.ucrBase.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink - Me.ucrBase.Location = New System.Drawing.Point(3, 472) + Me.ucrBase.Location = New System.Drawing.Point(3, 493) Me.ucrBase.Margin = New System.Windows.Forms.Padding(4) Me.ucrBase.Name = "ucrBase" Me.ucrBase.Size = New System.Drawing.Size(408, 52) @@ -732,4 +758,6 @@ Partial Class dlgEndOfRainsSeason Friend WithEvents ucrInputEvaporation As ucrInputTextBox Friend WithEvents ucrNudWB As ucrNud Friend WithEvents ucrChkWB As ucrCheck + Friend WithEvents ucrInputFilled As ucrInputTextBox + Friend WithEvents ucrChkFilled As ucrCheck End Class \ No newline at end of file diff --git a/instat/dlgEndOfRainsSeason.vb b/instat/dlgEndOfRainsSeason.vb index 0bf92d90214..beee2592dd6 100644 --- a/instat/dlgEndOfRainsSeason.vb +++ b/instat/dlgEndOfRainsSeason.vb @@ -307,6 +307,15 @@ Public Class dlgEndOfRainsSeason ucrInputEndofSeasonOccurence.SetDataFrameSelector(ucrSelectorForWaterBalance.ucrAvailableDataFrames) ucrInputEndofSeasonOccurence.SetValidationTypeAsRVariable() + ucrChkFilled.AddParameterValuesCondition(True, "sub4", "True") + ucrChkFilled.AddParameterValuesCondition(False, "sub4", "False") + ucrChkFilled.SetText("Filled") + + ucrInputFilled.SetParameter(New RParameter("result_name", 2)) + ucrInputFilled.SetDataFrameSelector(ucrSelectorForWaterBalance.ucrAvailableDataFrames) + ucrInputFilled.SetValidationTypeAsRVariable() + + ucrChkWB.AddParameterPresentCondition(True, "WB_evap", True) ucrChkWB.AddParameterPresentCondition(False, "WB_evap", False) ucrChkWB.SetText("Reducing") @@ -322,6 +331,7 @@ Public Class dlgEndOfRainsSeason ucrChkEndofSeasonOccurence.AddToLinkedControls(ucrInputEndofSeasonOccurence, {True}, bNewLinkedHideIfParameterMissing:=True) ucrChkEndofSeasonDate.AddToLinkedControls(ucrInputEndofSeasonDate, {True}, bNewLinkedHideIfParameterMissing:=True) ucrChkEndofSeasonDoy.AddToLinkedControls(ucrInputSeasonDoy, {True}, bNewLinkedHideIfParameterMissing:=True) + ucrChkFilled.AddToLinkedControls(ucrInputFilled, {True}, bNewLinkedHideIfParameterMissing:=True) ucrChkWB.AddToLinkedControls(ucrNudWB, {True}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:=0.5) ucrPnlEvaporation.AddToLinkedControls(ucrInputEvaporation, {rdoValueEvaporation}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedChangeToDefaultState:=True, objNewDefaultState:=5) ucrPnlEvaporation.AddToLinkedControls(ucrReceiverEvaporation, {rdoVariableEvaporation}, bNewLinkedHideIfParameterMissing:=True) @@ -331,7 +341,7 @@ Public Class dlgEndOfRainsSeason ucrPnlEndOfRainsAndSeasons.AddToLinkedControls({ucrNudCapacity, ucrNudWBLessThan, ucrChkEndofSeasonDoy}, {rdoEndOfSeasons}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlEndOfRainsAndSeasons.AddToLinkedControls({ucrPnlEvaporation}, {rdoEndOfSeasons}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlEndOfRainsAndSeasons.AddToLinkedControls({ucrChkWB}, {rdoEndOfSeasons}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) - ucrPnlEndOfRainsAndSeasons.AddToLinkedControls({ucrChkEndofSeasonDate, ucrChkEndofSeasonDoy, ucrChkEndofSeasonOccurence}, {rdoEndOfSeasons}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) + ucrPnlEndOfRainsAndSeasons.AddToLinkedControls({ucrChkEndofSeasonDate, ucrChkEndofSeasonDoy, ucrChkEndofSeasonOccurence, ucrChkFilled}, {rdoEndOfSeasons}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlEndOfRainsAndSeasons.AddToLinkedControls({ucrChkEndofRainsDate, ucrChkEndofRainsDoy, ucrChkEndofRainsOccurence}, {rdoEndOfRains}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrChkEndofRainsDoy.SetLinkedDisplayControl(grpEndofRains) @@ -970,7 +980,7 @@ Public Class dlgEndOfRainsSeason clsEndSeasonCombinationSubCalcList.AddParameter("sub1", clsRFunctionParameter:=clsEndSeasonFirstDoySummaryCalc, bIncludeArgumentName:=False, iPosition:=0) clsEndSeasonCombinationSubCalcList.AddParameter("sub2", clsRFunctionParameter:=clsEndSeasonFirstDateSummaryCalc, bIncludeArgumentName:=False, iPosition:=1) clsEndSeasonCombinationSubCalcList.AddParameter("sub3", clsRFunctionParameter:=clsEndRainsStatusSummaryCalc, bIncludeArgumentName:=False, iPosition:=2) - clsEndSeasonCombinationSubCalcList.AddParameter("sub4", clsRFunctionParameter:=clsEndSeasonFirstDoySummaryCalcFilledFunction, bIncludeArgumentName:=False, iPosition:=3) + 'clsEndSeasonCombinationSubCalcList.AddParameter("sub4", clsRFunctionParameter:=clsEndSeasonFirstDoySummaryCalcFilledFunction, bIncludeArgumentName:=False, iPosition:=3) clsGetColumnDataTypeFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_column_data_types") clsGetColumnDataTypeFunction.SetAssignTo(strYearType) @@ -1023,6 +1033,7 @@ Public Class dlgEndOfRainsSeason ucrInputSeasonDoy.SetRCode(clsEndSeasonFirstDoySummaryCalc, bReset) ucrInputEndofSeasonDate.SetRCode(clsEndSeasonFirstDateSummaryCalc, bReset) ucrInputEndofSeasonOccurence.SetRCode(clsEndSeasonStatusSummaryCalc, bReset) + ucrInputFilled.SetRCode(clsEndSeasonFirstDoySummaryCalcFilledFunction, bReset) ucrReceiverDate.SetRCode(clsLastDateFunction, bReset) @@ -1035,6 +1046,7 @@ Public Class dlgEndOfRainsSeason ucrNudWB.SetRCode(clsWBEvaporationMinFunction, bReset) ucrPnlEvaporation.SetRCode(clsWBMinEvapOperator, bReset) ucrReceiverEvaporation.SetRCode(clsWBMinTailFunction1, bReset) + ucrChkFilled.SetRCode(clsEndSeasonCombinationSubCalcList, bReset) End If ucrChkEndofSeasonDoy.SetRCode(clsEndSeasonCombinationSubCalcList, bReset) @@ -1076,6 +1088,8 @@ Public Class dlgEndOfRainsSeason bOkEnabled = False ElseIf ucrChkEndofSeasonOccurence.Checked AndAlso ucrInputEndofSeasonOccurence.IsEmpty Then bOkEnabled = False + ElseIf ucrChkFilled.Checked AndAlso ucrInputFilled.IsEmpty Then + bOkEnabled = False ElseIf rdoValueEvaporation.Checked AndAlso ucrInputEvaporation.IsEmpty Then bOkEnabled = False ElseIf rdoVariableEvaporation.Checked AndAlso ucrReceiverEvaporation.IsEmpty Then @@ -1282,10 +1296,8 @@ Public Class dlgEndOfRainsSeason Private Sub ucrChkEndofSeasonDoy_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkEndofSeasonDoy.ControlValueChanged If ucrChkEndofSeasonDoy.Checked Then clsEndSeasonCombinationSubCalcList.AddParameter("sub1", clsRFunctionParameter:=clsEndSeasonFirstDoySummaryCalc, bIncludeArgumentName:=False, iPosition:=0) - clsEndSeasonCombinationSubCalcList.AddParameter("sub4", clsRFunctionParameter:=clsEndSeasonFirstDoySummaryCalcFilledFunction, bIncludeArgumentName:=False, iPosition:=3) Else clsEndSeasonCombinationSubCalcList.RemoveParameterByName("sub1") - clsEndSeasonCombinationSubCalcList.RemoveParameterByName("sub4") End If End Sub @@ -1323,6 +1335,13 @@ Public Class dlgEndOfRainsSeason Else clsEndSeasonWBConditionOperator.RemoveParameterByName("1") End If - 'Evaporation() + End Sub + + Private Sub ucrChkFilled_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkFilled.ControlValueChanged + If ucrChkFilled.Checked Then + clsEndSeasonCombinationSubCalcList.AddParameter("sub4", clsRFunctionParameter:=clsEndSeasonFirstDoySummaryCalcFilledFunction, bIncludeArgumentName:=False, iPosition:=3) + Else + clsEndSeasonCombinationSubCalcList.RemoveParameterByName("sub4") + End If End Sub End Class \ No newline at end of file From 26d92e980eebff5053a2f5c7e1b75f0e083a9587 Mon Sep 17 00:00:00 2001 From: lilyclements Date: Fri, 1 Nov 2024 15:54:44 +0000 Subject: [PATCH 4/9] Update calculations.R --- .../R/Backend_Components/calculations.R | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/instat/static/InstatObject/R/Backend_Components/calculations.R b/instat/static/InstatObject/R/Backend_Components/calculations.R index 2f3191c2142..ae35cccbf70 100644 --- a/instat/static/InstatObject/R/Backend_Components/calculations.R +++ b/instat/static/InstatObject/R/Backend_Components/calculations.R @@ -448,8 +448,29 @@ DataBook$set("public", "apply_instat_calculation", function(calc, curr_data_list if(length(by) == 0) { stop("Cannot find linking columns to merge output from sub calculations with data for calculated_from.") } - if(join_into_overall) curr_data_list[[c_data_label]] <- dplyr::full_join(curr_data_list[[c_data_label]], self$get_data_frame(data_frame_name, use_current_filter = FALSE), by = by) - else { + if(join_into_overall){ + new_data_list <- self$get_data_frame(data_frame_name, use_current_filter = FALSE) + by_col_attributes <- list() + for(i in seq_along(by)) { + # Collect column attributes + by_col_attributes[[by[[i]]]] <- get_column_attributes(new_data_list[[by[[i]]]]) + + # Check and align the data types for each "by" column + if (class(new_data_list[[by[[i]]]]) != class(curr_data_list[[c_data_label]][[by[[i]]]])) { + warning(paste0("Type is different for ", by[[i]], " in the two data frames. Setting as numeric in both data frames.")) + + # Convert factors to numeric if necessary + if (class(new_data_list[[by[[i]]]]) == "factor") { + new_data_list[[by[[i]]]] <- as.numeric(as.character(new_data_list[[by[[i]]]])) + } else if (class(curr_data_list[[c_data_label]][[by[[i]]]]) == "factor") { + curr_data_list[[c_data_label]][[by[[i]]]] <- as.numeric(as.character(curr_data_list[[c_data_label]][[by[[i]]]])) + } else { + stop(paste0("Type is different for ", by[[i]], " in the two data frames and cannot be coerced.")) + } + } + } + curr_data_list[[c_data_label]] <- dplyr::full_join(curr_data_list[[c_data_label]], self$get_data_frame(data_frame_name, use_current_filter = FALSE), by = by) + } else { curr_groups <- dplyr::groups(curr_data_list[[c_data_label]]) curr_data_list[[c_data_label]] <- dplyr::full_join(self$get_data_frame(data_frame_name, use_current_filter = FALSE), curr_data_list[[c_data_label]], by = by) #TODO investigate better way to do this @@ -846,4 +867,4 @@ find_df_from_calc_from <- function(x, column) { if(column %in% x[[i]]) return(names(x)[i]) } return("") -} \ No newline at end of file +} From 9f902b2dd5e4a86fcbf3407a11bb272e25a73ea7 Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Mon, 11 Nov 2024 17:10:14 +0100 Subject: [PATCH 5/9] Change made --- instat/dlgEndOfRainsSeason.vb | 53 +++++++++++++++---- .../InstatObject/R/stand_alone_functions.R | 12 +++++ 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/instat/dlgEndOfRainsSeason.vb b/instat/dlgEndOfRainsSeason.vb index beee2592dd6..3cfe16b13b9 100644 --- a/instat/dlgEndOfRainsSeason.vb +++ b/instat/dlgEndOfRainsSeason.vb @@ -81,8 +81,8 @@ Public Class dlgEndOfRainsSeason #Region "end_of_season_code_structures" - Private clsEndSeasonIsNaRain As New RFunction - + Private clsEndSeasonIsNaRain, clsConvertLinkedFunction, clsGetLinkBetweenFunction, clsGetlinkeddata1Function As New RFunction + Private clsGetLinkBetweenOpreator As New ROperator ' Rain min Private clsEndSeasonRainMinCalc As New RFunction Private clsIfElseRainMinFunction As New RFunction @@ -375,7 +375,11 @@ Public Class dlgEndOfRainsSeason Dim strEndofSeason As String = "end_of_season_combined" clsGetlinkeddataFunction = New RFunction + clsGetlinkeddata1Function = New RFunction + clsGetLinkBetweenFunction = New RFunction clsVectorFunction = New RFunction + clsGetLinkBetweenOpreator = New ROperator + clsConvertLinkedFunction = New RFunction #Region "clear_code_structures" ' General @@ -674,6 +678,8 @@ Public Class dlgEndOfRainsSeason clsEndRainsCombinationSubCalcList.SetRCommand("list") clsEndRainsCombinationSubCalcList.AddParameter("sub1", clsRFunctionParameter:=clsEndRainsLastDoySummaryCalc, bIncludeArgumentName:=False, iPosition:=0) + clsEndRainsCombinationSubCalcList.AddParameter("sub2", clsRFunctionParameter:=clsEndRainsLastDateSummaryCalc, bIncludeArgumentName:=False, iPosition:=1) + clsEndRainsCombinationSubCalcList.AddParameter("sub3", clsRFunctionParameter:=clsEndRainsStatusSummaryCalc, bIncludeArgumentName:=False, iPosition:=2) clsListCalFunction.SetRCommand("list") clsListCalFunction.AddParameter("drop", "FALSE", iPosition:=0) @@ -979,8 +985,7 @@ Public Class dlgEndOfRainsSeason clsEndSeasonCombinationSubCalcList.SetRCommand("list") clsEndSeasonCombinationSubCalcList.AddParameter("sub1", clsRFunctionParameter:=clsEndSeasonFirstDoySummaryCalc, bIncludeArgumentName:=False, iPosition:=0) clsEndSeasonCombinationSubCalcList.AddParameter("sub2", clsRFunctionParameter:=clsEndSeasonFirstDateSummaryCalc, bIncludeArgumentName:=False, iPosition:=1) - clsEndSeasonCombinationSubCalcList.AddParameter("sub3", clsRFunctionParameter:=clsEndRainsStatusSummaryCalc, bIncludeArgumentName:=False, iPosition:=2) - 'clsEndSeasonCombinationSubCalcList.AddParameter("sub4", clsRFunctionParameter:=clsEndSeasonFirstDoySummaryCalcFilledFunction, bIncludeArgumentName:=False, iPosition:=3) + clsEndSeasonCombinationSubCalcList.AddParameter("sub3", clsRFunctionParameter:=clsEndSeasonStatusSummaryCalc, bIncludeArgumentName:=False, iPosition:=2) clsGetColumnDataTypeFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_column_data_types") clsGetColumnDataTypeFunction.SetAssignTo(strYearType) @@ -988,9 +993,25 @@ Public Class dlgEndOfRainsSeason clsConvertColumnTypeFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_column_to_type") clsConvertColumnTypeFunction.AddParameter("to_type", Chr(34) & "factor" & Chr(34), iPosition:=2) + clsConvertLinkedFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_column_to_type") + clsConvertLinkedFunction.AddParameter("data_name", "linked_data_name", iPosition:=0) + clsConvertLinkedFunction.AddParameter("col_names", "linked_variable_name", iPosition:=1) + clsConvertLinkedFunction.AddParameter("to_type", Chr(34) & "factor" & Chr(34), iPosition:=2) + clsGetlinkeddataFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_linked_to_data_name") clsGetlinkeddataFunction.SetAssignTo("linked_data_name") + clsGetlinkeddata1Function.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_linked_to_data_name") + clsGetlinkeddata1Function.SetAssignTo("linked_data_name") + + clsGetLinkBetweenFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_link_between") + clsGetLinkBetweenFunction.AddParameter("x", "linked_data_name", iPosition:=1, bIncludeArgumentName:=False) + + clsGetLinkBetweenOpreator.SetOperation("$") + clsGetLinkBetweenOpreator.AddParameter("left", clsRFunctionParameter:=clsGetLinkBetweenFunction, iPosition:=0, bIncludeArgumentName:=False) + clsGetLinkBetweenOpreator.AddParameter("right", "link_columns", iPosition:=1, bIncludeArgumentName:=False) + clsGetLinkBetweenOpreator.SetAssignTo("linked_variable_name") + clsVectorFunction.SetRCommand("c") clsConvertColumnType2Function.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_column_to_type") @@ -1047,17 +1068,16 @@ Public Class dlgEndOfRainsSeason ucrPnlEvaporation.SetRCode(clsWBMinEvapOperator, bReset) ucrReceiverEvaporation.SetRCode(clsWBMinTailFunction1, bReset) ucrChkFilled.SetRCode(clsEndSeasonCombinationSubCalcList, bReset) + ucrChkEndofRainsDoy.SetRCode(clsEndRainsCombinationSubCalcList, bReset) + ucrChkEndofRainsDate.SetRCode(clsDummyFunction, bReset) + ucrChkEndofRainsOccurence.SetRCode(clsDummyFunction, bReset) + ucrChkEndofSeasonDoy.SetRCode(clsEndSeasonCombinationSubCalcList, bReset) + ucrChkEndofSeasonDate.SetRCode(clsDummyFunction, bReset) + ucrChkEndofSeasonOccurence.SetRCode(clsDummyFunction, bReset) End If - ucrChkEndofSeasonDoy.SetRCode(clsEndSeasonCombinationSubCalcList, bReset) - ucrChkEndofSeasonDate.SetRCode(clsDummyFunction, bReset) - ucrChkEndofSeasonOccurence.SetRCode(clsDummyFunction, bReset) - ucrNudAmount.SetRCode(clsEndRainsRollSumRainConditionOperator, bReset) ucrNudTotalOverDays.SetRCode(clsRollSumRainFunction, bReset) - ucrChkEndofRainsDoy.SetRCode(clsEndRainsCombinationSubCalcList, bReset) - ucrChkEndofRainsDate.SetRCode(clsDummyFunction, bReset) - ucrChkEndofRainsOccurence.SetRCode(clsDummyFunction, bReset) ucrPnlEndOfRainsAndSeasons.SetRCode(clsFirstOrLastFunction, bReset) End Sub @@ -1155,8 +1175,11 @@ Public Class dlgEndOfRainsSeason clsVectorFunction.RemoveParameterByName("y") End If clsGetlinkeddataFunction.AddParameter("link_cols", clsRFunctionParameter:=clsVectorFunction, iPosition:=1) + clsGetlinkeddata1Function.AddParameter("link_cols", clsRFunctionParameter:=clsVectorFunction, iPosition:=1) + Else clsGetlinkeddataFunction.RemoveParameterByName("link_cols") + clsGetlinkeddata1Function.RemoveParameterByName("link_cols") clsVectorFunction.RemoveParameterByName("x") End If End Sub @@ -1199,6 +1222,8 @@ Public Class dlgEndOfRainsSeason clsConvertColumnTypeFunction.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) clsConvertColumnType1Function.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) clsGetlinkeddataFunction.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0, bIncludeArgumentName:=False) + clsGetlinkeddata1Function.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0, bIncludeArgumentName:=False) + clsGetLinkBetweenFunction.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0, bIncludeArgumentName:=False) End Sub Private Sub ucrPnlEvaporation_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlEvaporation.ControlValueChanged, ucrReceiverEvaporation.ControlValueChanged, ucrInputEvaporation.ControlValueChanged @@ -1262,7 +1287,13 @@ Public Class dlgEndOfRainsSeason If rdoEndOfRains.Checked Then clsRunCalculation.AddParameter("calc", clsRFunctionParameter:=clsEndRainsCombinationCalc) clsFirstOrLastFunction = clsLastDoyFunction + ucrBase.clsRsyntax.RemoveFromBeforeCodes(clsGetlinkeddata1Function) + ucrBase.clsRsyntax.RemoveFromBeforeCodes(clsGetLinkBetweenOpreator) + ucrBase.clsRsyntax.RemoveFromBeforeCodes(clsConvertLinkedFunction) Else + ucrBase.clsRsyntax.AddToBeforeCodes(clsGetlinkeddata1Function, iPosition:=2) + ucrBase.clsRsyntax.AddToBeforeCodes(clsGetLinkBetweenOpreator, iPosition:=3) + ucrBase.clsRsyntax.AddToBeforeCodes(clsConvertLinkedFunction, iPosition:=4) clsRunCalculation.AddParameter("calc", clsRFunctionParameter:=clsEndSeasonCombinationCalc) clsFirstOrLastFunction = clsFirstDoyFunction Evaporation() diff --git a/instat/static/InstatObject/R/stand_alone_functions.R b/instat/static/InstatObject/R/stand_alone_functions.R index ef7ae16ee90..e4fc155a3a9 100644 --- a/instat/static/InstatObject/R/stand_alone_functions.R +++ b/instat/static/InstatObject/R/stand_alone_functions.R @@ -3429,4 +3429,16 @@ monitor_memory <- function() { time_operation <- function(expr) { timing <- system.time(expr) print(timing) +} + +# preliminary function, but needs testing -- e.g., looping through multiple variables +convert_linked_variable <- function(data, variables){ +linked_data_name <- data_book$get_linked_to_data_name(data, link_cols=c(variables)) +if (!is.null(linked_data_name)){ +linked_variable_name <- data_book$get_link_between(data, linked_data_name )$link_columns + +# TODO: loop through all columns given in variable argument +variable_type <- data_book$get_column_data_types(data_name = data, columns=variables) +data_book$convert_column_to_type(data_name=linked_data_name, col_names=linked_variable_name, to_type="factor") +} } \ No newline at end of file From 04b86758883fe3c2a39a1e159977abc924a2df34 Mon Sep 17 00:00:00 2001 From: lilyclements Date: Wed, 13 Nov 2024 15:18:26 +0000 Subject: [PATCH 6/9] Adding function in link to convert variables in a to data frame to be the same class as that of the from data frame --- .../InstatObject/R/Backend_Components/link.R | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/instat/static/InstatObject/R/Backend_Components/link.R b/instat/static/InstatObject/R/Backend_Components/link.R index ccd14b356e7..4b2ada7bc20 100644 --- a/instat/static/InstatObject/R/Backend_Components/link.R +++ b/instat/static/InstatObject/R/Backend_Components/link.R @@ -379,4 +379,23 @@ DataBook$set("public", "view_link", function(link_name) { paste("Link columns:", paste(names(temp_link$link_columns), "=", temp_link$link_columns, collapse = ", ")), sep = "\n")) } } +) + +# A function to convert the variables in the linked "to data frame"" to be the same class as that of the "from data frame"". +DataBook$set("public", "convert_linked_variable", function(from_data_frame, link_cols) { + to_data_name <- self$get_linked_to_data_name(from_data_frame, link_cols=c(link_cols)) + if (!is.null(to_data_name)){ + linked_variable_name <- self$get_link_between(from_data_frame, to_data_name)$link_columns[[1]] + + # loop through all columns given in variable argument + for (i in seq_along(linked_variable_name)){ + variable_type <- self$get_column_data_types(data_name = from_data_frame, columns = link_cols[i]) + linked_variable_type <- self$get_column_data_types(data_name = to_data_name, columns=linked_variable_name[i]) + + if (variable_type != linked_variable_type){ + self$convert_column_to_type(data_name=to_data_name, col_names=linked_variable_name[i], to_type=variable_type) + } + } + } +} ) \ No newline at end of file From c2f3385154b2ca80326c135c1c85c626ec274876 Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Wed, 13 Nov 2024 19:37:40 +0100 Subject: [PATCH 7/9] Change made --- instat/dlgEndOfRainsSeason.vb | 68 +++++-------------- .../InstatObject/R/stand_alone_functions.R | 12 ---- 2 files changed, 16 insertions(+), 64 deletions(-) diff --git a/instat/dlgEndOfRainsSeason.vb b/instat/dlgEndOfRainsSeason.vb index 3cfe16b13b9..e8cf327bad1 100644 --- a/instat/dlgEndOfRainsSeason.vb +++ b/instat/dlgEndOfRainsSeason.vb @@ -30,7 +30,7 @@ Public Class dlgEndOfRainsSeason #Region "general_code_structures" ' General - Private clsVectorFunction, clsGetlinkeddataFunction, clsConvertColumnType1Function, clsConvertColumnType2Function, clsGetColumnDataTypeFunction, clsConvertColumnTypeFunction, clsRunCalculation, clsListCalFunction, clsDummyFunction As New RFunction + Private clsVectorFunction, clsConvertlinkedvariable1Function, clsConvertlinkedvariableFunction, clsConvertColumnType1Function, clsGetColumnDataTypeFunction, clsConvertColumnTypeFunction, clsRunCalculation, clsListCalFunction, clsDummyFunction As New RFunction Private clsFirstOrLastFunction As New RFunction ' Group by @@ -81,8 +81,7 @@ Public Class dlgEndOfRainsSeason #Region "end_of_season_code_structures" - Private clsEndSeasonIsNaRain, clsConvertLinkedFunction, clsGetLinkBetweenFunction, clsGetlinkeddata1Function As New RFunction - Private clsGetLinkBetweenOpreator As New ROperator + Private clsEndSeasonIsNaRain As New RFunction ' Rain min Private clsEndSeasonRainMinCalc As New RFunction Private clsIfElseRainMinFunction As New RFunction @@ -374,12 +373,9 @@ Public Class dlgEndOfRainsSeason Dim strEndofRains As String = "end_of_rains_combined" Dim strEndofSeason As String = "end_of_season_combined" - clsGetlinkeddataFunction = New RFunction - clsGetlinkeddata1Function = New RFunction - clsGetLinkBetweenFunction = New RFunction clsVectorFunction = New RFunction - clsGetLinkBetweenOpreator = New ROperator - clsConvertLinkedFunction = New RFunction + clsConvertlinkedvariableFunction = New RFunction + clsConvertlinkedvariable1Function = New RFunction #Region "clear_code_structures" ' General @@ -387,7 +383,6 @@ Public Class dlgEndOfRainsSeason clsListCalFunction.Clear() clsFirstOrLastFunction.Clear() clsConvertColumnTypeFunction.Clear() - clsConvertColumnType2Function.Clear() clsGetColumnDataTypeFunction.Clear() clsConvertColumnType1Function.Clear() ' Group by @@ -951,7 +946,6 @@ Public Class dlgEndOfRainsSeason clsEndSeasonStatusSummaryCalc.AddParameter("save", 2, iPosition:=4) clsEndSeasonStatusSummaryCalc.SetAssignTo(strEndSeasonStatus) - clsIfelseStatusFunction.SetRCommand("ifelse") clsIfelseStatusFunction.bToScriptAsRString = True clsIfelseStatusFunction.AddParameter("x", "n() > 0", iPosition:=0, bIncludeArgumentName:=False) @@ -993,42 +987,22 @@ Public Class dlgEndOfRainsSeason clsConvertColumnTypeFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_column_to_type") clsConvertColumnTypeFunction.AddParameter("to_type", Chr(34) & "factor" & Chr(34), iPosition:=2) - clsConvertLinkedFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_column_to_type") - clsConvertLinkedFunction.AddParameter("data_name", "linked_data_name", iPosition:=0) - clsConvertLinkedFunction.AddParameter("col_names", "linked_variable_name", iPosition:=1) - clsConvertLinkedFunction.AddParameter("to_type", Chr(34) & "factor" & Chr(34), iPosition:=2) - - clsGetlinkeddataFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_linked_to_data_name") - clsGetlinkeddataFunction.SetAssignTo("linked_data_name") - - clsGetlinkeddata1Function.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_linked_to_data_name") - clsGetlinkeddata1Function.SetAssignTo("linked_data_name") - - clsGetLinkBetweenFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_link_between") - clsGetLinkBetweenFunction.AddParameter("x", "linked_data_name", iPosition:=1, bIncludeArgumentName:=False) - - clsGetLinkBetweenOpreator.SetOperation("$") - clsGetLinkBetweenOpreator.AddParameter("left", clsRFunctionParameter:=clsGetLinkBetweenFunction, iPosition:=0, bIncludeArgumentName:=False) - clsGetLinkBetweenOpreator.AddParameter("right", "link_columns", iPosition:=1, bIncludeArgumentName:=False) - clsGetLinkBetweenOpreator.SetAssignTo("linked_variable_name") - clsVectorFunction.SetRCommand("c") - clsConvertColumnType2Function.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_column_to_type") - clsConvertColumnType2Function.AddParameter("data_name", "linked_data_name", iPosition:=0) - clsConvertColumnType2Function.AddParameter("to_type", "year_type", iPosition:=2) - clsConvertColumnType1Function.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_column_to_type") clsConvertColumnType1Function.AddParameter("to_type", "year_type", iPosition:=2) + clsConvertlinkedvariableFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_linked_variable") + + clsConvertlinkedvariable1Function.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_linked_variable") #End Region ucrBase.clsRsyntax.ClearCodes() ucrBase.clsRsyntax.AddToBeforeCodes(clsGetColumnDataTypeFunction, iPosition:=0) ucrBase.clsRsyntax.AddToBeforeCodes(clsConvertColumnTypeFunction, iPosition:=1) - ucrBase.clsRsyntax.AddToAfterCodes(clsGetlinkeddataFunction, iPosition:=0) - ucrBase.clsRsyntax.AddToAfterCodes(clsConvertColumnType1Function, iPosition:=1) - ucrBase.clsRsyntax.AddToAfterCodes(clsConvertColumnType2Function, iPosition:=2) + ucrBase.clsRsyntax.AddToBeforeCodes(clsConvertlinkedvariableFunction, iPosition:=2) + ucrBase.clsRsyntax.AddToAfterCodes(clsConvertColumnType1Function, iPosition:=0) + ucrBase.clsRsyntax.AddToAfterCodes(clsConvertlinkedvariable1Function, iPosition:=1) ucrBase.clsRsyntax.SetBaseRFunction(clsRunCalculation) clsFirstOrLastFunction = clsLastDoyFunction @@ -1174,12 +1148,11 @@ Public Class dlgEndOfRainsSeason Else clsVectorFunction.RemoveParameterByName("y") End If - clsGetlinkeddataFunction.AddParameter("link_cols", clsRFunctionParameter:=clsVectorFunction, iPosition:=1) - clsGetlinkeddata1Function.AddParameter("link_cols", clsRFunctionParameter:=clsVectorFunction, iPosition:=1) - + clsConvertlinkedvariableFunction.AddParameter("link_cols", clsRFunctionParameter:=clsVectorFunction, iPosition:=1) + clsConvertlinkedvariable1Function.AddParameter("link_cols", clsRFunctionParameter:=clsVectorFunction, iPosition:=1) Else - clsGetlinkeddataFunction.RemoveParameterByName("link_cols") - clsGetlinkeddata1Function.RemoveParameterByName("link_cols") + clsConvertlinkedvariableFunction.RemoveParameterByName("link_cols") + clsConvertlinkedvariable1Function.RemoveParameterByName("link_cols") clsVectorFunction.RemoveParameterByName("x") End If End Sub @@ -1191,10 +1164,8 @@ Public Class dlgEndOfRainsSeason clsGetColumnDataTypeFunction.AddParameter("columns", ucrReceiverYear.GetVariableNames(), iPosition:=1) clsConvertColumnTypeFunction.AddParameter("col_names", ucrReceiverYear.GetVariableNames(), iPosition:=1) clsConvertColumnType1Function.AddParameter("col_names", ucrReceiverYear.GetVariableNames(), iPosition:=1) - clsConvertColumnType2Function.AddParameter("col_names", ucrReceiverYear.GetVariableNames(), iPosition:=1) Else clsConvertColumnType1Function.RemoveParameterByName("col_names") - clsConvertColumnType2Function.RemoveParameterByName("col_names") clsGetColumnDataTypeFunction.RemoveParameterByName("columns") clsConvertColumnTypeFunction.RemoveParameterByName("col_names") End If @@ -1221,9 +1192,8 @@ Public Class dlgEndOfRainsSeason clsGetColumnDataTypeFunction.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) clsConvertColumnTypeFunction.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) clsConvertColumnType1Function.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) - clsGetlinkeddataFunction.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0, bIncludeArgumentName:=False) - clsGetlinkeddata1Function.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0, bIncludeArgumentName:=False) - clsGetLinkBetweenFunction.AddParameter("data_name", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0, bIncludeArgumentName:=False) + clsConvertlinkedvariableFunction.AddParameter("from_data_frame", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) + clsConvertlinkedvariable1Function.AddParameter("from_data_frame", Chr(34) & ucrSelectorForWaterBalance.ucrAvailableDataFrames.cboAvailableDataFrames.Text & Chr(34), iPosition:=0) End Sub Private Sub ucrPnlEvaporation_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlEvaporation.ControlValueChanged, ucrReceiverEvaporation.ControlValueChanged, ucrInputEvaporation.ControlValueChanged @@ -1287,13 +1257,7 @@ Public Class dlgEndOfRainsSeason If rdoEndOfRains.Checked Then clsRunCalculation.AddParameter("calc", clsRFunctionParameter:=clsEndRainsCombinationCalc) clsFirstOrLastFunction = clsLastDoyFunction - ucrBase.clsRsyntax.RemoveFromBeforeCodes(clsGetlinkeddata1Function) - ucrBase.clsRsyntax.RemoveFromBeforeCodes(clsGetLinkBetweenOpreator) - ucrBase.clsRsyntax.RemoveFromBeforeCodes(clsConvertLinkedFunction) Else - ucrBase.clsRsyntax.AddToBeforeCodes(clsGetlinkeddata1Function, iPosition:=2) - ucrBase.clsRsyntax.AddToBeforeCodes(clsGetLinkBetweenOpreator, iPosition:=3) - ucrBase.clsRsyntax.AddToBeforeCodes(clsConvertLinkedFunction, iPosition:=4) clsRunCalculation.AddParameter("calc", clsRFunctionParameter:=clsEndSeasonCombinationCalc) clsFirstOrLastFunction = clsFirstDoyFunction Evaporation() diff --git a/instat/static/InstatObject/R/stand_alone_functions.R b/instat/static/InstatObject/R/stand_alone_functions.R index e4fc155a3a9..ef7ae16ee90 100644 --- a/instat/static/InstatObject/R/stand_alone_functions.R +++ b/instat/static/InstatObject/R/stand_alone_functions.R @@ -3429,16 +3429,4 @@ monitor_memory <- function() { time_operation <- function(expr) { timing <- system.time(expr) print(timing) -} - -# preliminary function, but needs testing -- e.g., looping through multiple variables -convert_linked_variable <- function(data, variables){ -linked_data_name <- data_book$get_linked_to_data_name(data, link_cols=c(variables)) -if (!is.null(linked_data_name)){ -linked_variable_name <- data_book$get_link_between(data, linked_data_name )$link_columns - -# TODO: loop through all columns given in variable argument -variable_type <- data_book$get_column_data_types(data_name = data, columns=variables) -data_book$convert_column_to_type(data_name=linked_data_name, col_names=linked_variable_name, to_type="factor") -} } \ No newline at end of file From 25d5d59e87fb61d34e44e96620e90f6fd30e0d29 Mon Sep 17 00:00:00 2001 From: lilyclements Date: Fri, 15 Nov 2024 13:19:37 +0000 Subject: [PATCH 8/9] Update link.R --- instat/static/InstatObject/R/Backend_Components/link.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instat/static/InstatObject/R/Backend_Components/link.R b/instat/static/InstatObject/R/Backend_Components/link.R index 4b2ada7bc20..47219b1b139 100644 --- a/instat/static/InstatObject/R/Backend_Components/link.R +++ b/instat/static/InstatObject/R/Backend_Components/link.R @@ -389,7 +389,7 @@ DataBook$set("public", "convert_linked_variable", function(from_data_frame, link # loop through all columns given in variable argument for (i in seq_along(linked_variable_name)){ - variable_type <- self$get_column_data_types(data_name = from_data_frame, columns = link_cols[i]) + variable_type <- self$get_column_data_types(data_name = from_data_frame, columns = names(linked_variable_name[i])) linked_variable_type <- self$get_column_data_types(data_name = to_data_name, columns=linked_variable_name[i]) if (variable_type != linked_variable_type){ @@ -398,4 +398,4 @@ DataBook$set("public", "convert_linked_variable", function(from_data_frame, link } } } -) \ No newline at end of file +) From 608e49a561c44f9f400e9b3d31ec0063dc5b6755 Mon Sep 17 00:00:00 2001 From: Sophie Malla Tatchum Date: Fri, 15 Nov 2024 19:52:28 +0100 Subject: [PATCH 9/9] Change made --- instat/dlgEndOfRainsSeason.vb | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/instat/dlgEndOfRainsSeason.vb b/instat/dlgEndOfRainsSeason.vb index e8cf327bad1..bcd0b5ed832 100644 --- a/instat/dlgEndOfRainsSeason.vb +++ b/instat/dlgEndOfRainsSeason.vb @@ -142,6 +142,7 @@ Public Class dlgEndOfRainsSeason Private clsEndSeasonFirstDoySummaryCalcFilledFunction As New RFunction Private clsIfElseFirstDoyFunction As New RFunction Public clsIfElseFirstDoyFilledFunction As New RFunction + Private clsIfElseFirstDoyFilled1Function, clsFirstFilledFunction, clsFirstFilled1Function, clsIsNafilledFunction As New RFunction Private clsIsNaFirstWB As New RFunction Private clsFirstDoyFunction As New RFunction Private clsFirstWBFunction As New RFunction @@ -376,6 +377,10 @@ Public Class dlgEndOfRainsSeason clsVectorFunction = New RFunction clsConvertlinkedvariableFunction = New RFunction clsConvertlinkedvariable1Function = New RFunction + clsIfElseFirstDoyFilled1Function = New RFunction + clsFirstFilledFunction = New RFunction + clsIsNafilledFunction = New RFunction + clsFirstFilled1Function = New RFunction #Region "clear_code_structures" ' General @@ -906,9 +911,25 @@ Public Class dlgEndOfRainsSeason clsIfElseFirstDoyFilledFunction.bToScriptAsRString = True clsIfElseFirstDoyFilledFunction.SetRCommand("ifelse") - clsIfElseFirstDoyFilledFunction.AddParameter("test", clsRFunctionParameter:=clsIsNaFirstWB, iPosition:=0) - clsIfElseFirstDoyFilledFunction.AddParameter("yes", "366", iPosition:=1) - clsIfElseFirstDoyFilledFunction.AddParameter("no", clsRFunctionParameter:=clsFirstDoyFunction, iPosition:=2) + clsIfElseFirstDoyFilledFunction.AddParameter("x", "n() > 0", iPosition:=0, bIncludeArgumentName:=False) + clsIfElseFirstDoyFilledFunction.AddParameter("y", clsRFunctionParameter:=clsIfElseFirstDoyFilled1Function, iPosition:=1, bIncludeArgumentName:=False) + clsIfElseFirstDoyFilledFunction.AddParameter("yes", "366", iPosition:=2, bIncludeArgumentName:=False) + + clsIfElseFirstDoyFilled1Function.SetRCommand("ifelse") + clsIfElseFirstDoyFilled1Function.AddParameter("x", clsRFunctionParameter:=clsFirstFilledFunction, iPosition:=0, bIncludeArgumentName:=False) + clsIfElseFirstDoyFilled1Function.AddParameter("y", "NA", iPosition:=1, bIncludeArgumentName:=False) + clsIfElseFirstDoyFilled1Function.AddParameter("z", clsRFunctionParameter:=clsFirstFilled1Function, iPosition:=2, bIncludeArgumentName:=False) + + clsFirstFilled1Function.SetPackageName("dplyr") + clsFirstFilled1Function.SetRCommand("first") + clsFirstFilled1Function.AddParameter("x", clsRFunctionParameter:=clsIsNafilledFunction, iPosition:=0) + + clsFirstFilledFunction.SetPackageName("dplyr") + clsFirstFilledFunction.SetRCommand("first") + clsFirstFilledFunction.AddParameter("x", clsRFunctionParameter:=clsIsNafilledFunction, iPosition:=0, bIncludeArgumentName:=False) + + clsIsNafilledFunction.SetRCommand("is.na") + clsIsNafilledFunction.AddParameter("x", strWB, iPosition:=0, bIncludeArgumentName:=False) clsIsNaFirstWB.SetRCommand("is.na") clsIsNaFirstWB.AddParameter("x", clsRFunctionParameter:=clsFirstWBFunction, iPosition:=0) @@ -995,6 +1016,7 @@ Public Class dlgEndOfRainsSeason clsConvertlinkedvariableFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_linked_variable") clsConvertlinkedvariable1Function.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$convert_linked_variable") + #End Region ucrBase.clsRsyntax.ClearCodes() @@ -1012,6 +1034,7 @@ Public Class dlgEndOfRainsSeason ucrReceiverDOY.AddAdditionalCodeParameterPair(clsDayFromOperator, New RParameter("doy", 0), iAdditionalPairNo:=1) ucrReceiverDOY.AddAdditionalCodeParameterPair(clsLastDoyFunction, New RParameter("x", 0), iAdditionalPairNo:=2) ucrReceiverDOY.AddAdditionalCodeParameterPair(clsFirstDoyFunction, New RParameter("x", 0), iAdditionalPairNo:=3) + ucrReceiverDOY.AddAdditionalCodeParameterPair(clsFirstFilled1Function, New RParameter("x", 0), iAdditionalPairNo:=4) ucrReceiverRainfall.AddAdditionalCodeParameterPair(clsEndSeasonIsNaRain, New RParameter("x", 0), iAdditionalPairNo:=1) ucrReceiverRainfall.AddAdditionalCodeParameterPair(clsIfElseRainMinFunction, New RParameter("no", 2), iAdditionalPairNo:=2) ucrReceiverRainfall.AddAdditionalCodeParameterPair(clsIfElseRainMaxFunction, New RParameter("no", 2), iAdditionalPairNo:=3)